蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

176 line
4.6 KiB

  1. package user_feedback
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/svc"
  7. "applet/app/utils"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  10. "encoding/json"
  11. "github.com/gin-gonic/gin"
  12. "github.com/tidwall/gjson"
  13. "strings"
  14. "time"
  15. )
  16. func List(c *gin.Context) {
  17. var req *md.UserFeedbackListReq
  18. if err := c.ShouldBindJSON(&req); err != nil {
  19. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  20. return
  21. }
  22. var resp md.UserFeedbackListResp
  23. noticeList := make([]md.UserFeedbackList, 0)
  24. NewUserFeedbackDb := implement.NewUserFeedbackDb(db.Db)
  25. uid := ""
  26. if req.Uid != "" {
  27. uid = req.Uid
  28. }
  29. if req.Phone != "" {
  30. uid = "-1"
  31. NewUserDb := implement.NewUserDb(db.Db)
  32. user, _ := NewUserDb.UserGetOneByParams(map[string]interface{}{
  33. "key": "phone",
  34. "value": req.Phone,
  35. })
  36. if user != nil {
  37. uid = utils.Int64ToStr(user.Id)
  38. }
  39. }
  40. notice, total, _ := NewUserFeedbackDb.FindUserFeedbackAndTotal(req.Page, req.Limit, uid, req.Cid, "")
  41. resp.Total = total
  42. resp.SelectData = make([]map[string]interface{}, 0)
  43. NewUserFeedbackCateDb := implement.NewUserFeedbackCateDb(db.Db)
  44. pid, _ := NewUserFeedbackCateDb.FindUserFeedbackCate("1", "100")
  45. if pid != nil {
  46. for _, v := range *pid {
  47. tmp := map[string]interface{}{
  48. "name": v.Name, "value": utils.IntToStr(v.Id),
  49. }
  50. resp.SelectData = append(resp.SelectData, tmp)
  51. }
  52. }
  53. if notice != nil {
  54. platformMap := map[string]string{
  55. "android": "安卓",
  56. "iOS": "iOS",
  57. "wx_applet": "小程序",
  58. }
  59. for _, v := range *notice {
  60. v.Extra = strings.ToLower(v.Extra)
  61. platform := gjson.Get(v.Extra, "platform").String()
  62. img := make([]string, 0)
  63. json.Unmarshal([]byte(v.Img), &img)
  64. if v.Phone == "" {
  65. NewUserDb := implement.NewUserDb(db.Db)
  66. user, _ := NewUserDb.UserGetOneByParams(map[string]interface{}{
  67. "key": "id",
  68. "value": v.Uid,
  69. })
  70. if user != nil {
  71. v.Phone = user.Phone
  72. }
  73. }
  74. tmp := md.UserFeedbackList{
  75. Id: utils.IntToStr(v.Id),
  76. Phone: v.Phone,
  77. Title: v.Title,
  78. Platform: platformMap[platform],
  79. Version: gjson.Get(v.Extra, "devicemodel").String() + " " + gjson.Get(v.Extra, "osversion").String() + " " + gjson.Get(v.Extra, "appversionname").String(),
  80. Type: v.Type,
  81. Img: img,
  82. Content: v.Content,
  83. CreateAt: v.CreateAt.Format("2006-01-02 15:04:05"),
  84. State: utils.IntToStr(v.State),
  85. }
  86. noticeList = append(noticeList, tmp)
  87. }
  88. }
  89. resp.List = noticeList
  90. e.OutSuc(c, resp, nil)
  91. return
  92. }
  93. func RecordList(c *gin.Context) {
  94. eg := db.Db
  95. var req md.UserFeedbackRecordListReq
  96. err := c.ShouldBindJSON(&req)
  97. if err != nil {
  98. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  99. return
  100. }
  101. NewUserFeedbackRecordDb := implement.NewUserFeedbackRecordDb(eg)
  102. article, _ := NewUserFeedbackRecordDb.FindUserFeedback(req.Page, "1000", req.Id)
  103. data := make([]md.UserFeedbackRecordListResp, 0)
  104. if article != nil {
  105. for _, v := range *article {
  106. tmp := md.UserFeedbackRecordListResp{
  107. Content: v.Content,
  108. CreateAt: v.CreateAt.Format("2006-01-02"),
  109. Type: "official",
  110. }
  111. if v.Uid > 0 {
  112. NewUserDb := implement.NewUserDb(eg)
  113. user, _ := NewUserDb.GetUser(int64(v.Uid))
  114. if user != nil {
  115. tmp.Nickname = user.Nickname
  116. tmp.HeadImg = svc.GetOssUrl(user.Avatar)
  117. }
  118. tmp.Type = "user"
  119. } else {
  120. tmp.Nickname = svc.GetSysCfgStr("app_name")
  121. tmp.HeadImg = svc.GetOssUrl(svc.GetSysCfgStr("app_logo"))
  122. }
  123. data = append(data, tmp)
  124. }
  125. }
  126. e.OutSuc(c, data, nil)
  127. return
  128. }
  129. func Say(c *gin.Context) {
  130. var req *md.UserFeedbackSayReq
  131. if err := c.ShouldBindJSON(&req); err != nil {
  132. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  133. return
  134. }
  135. data := model.UserFeedbackRecord{
  136. Lid: utils.StrToInt(req.Id),
  137. Content: req.Content,
  138. CreateAt: time.Now(),
  139. }
  140. db.Db.Insert(&data)
  141. e.OutSuc(c, "success", nil)
  142. return
  143. }
  144. func ChangeState(c *gin.Context) {
  145. var req *md.UserFeedbackChangeStateReq
  146. if err := c.ShouldBindJSON(&req); err != nil {
  147. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  148. return
  149. }
  150. NewUserFeedbackDb := implement.NewUserFeedbackDb(db.Db)
  151. notice, _ := NewUserFeedbackDb.GetUserFeedback(req.Id)
  152. if notice == nil {
  153. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  154. return
  155. }
  156. notice.State = utils.StrToInt(req.State)
  157. db.Db.Where("id=?", notice.Id).Cols("state").Update(notice)
  158. e.OutSuc(c, "success", nil)
  159. return
  160. }
  161. func Del(c *gin.Context) {
  162. var req *md.UserFeedbackDelReq
  163. if err := c.ShouldBindJSON(&req); err != nil {
  164. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  165. return
  166. }
  167. db.Db.In("id", req.Id).Delete(&model.UserFeedback{})
  168. db.Db.In("lid", req.Id).Delete(&model.UserFeedbackRecord{})
  169. e.OutSuc(c, "success", nil)
  170. return
  171. }