蛋蛋星球 后台端
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.

svc_list.go 4.7 KiB

3 days ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. for k1, v1 := range img {
  75. img[k1] = svc.GetOssUrl(v1)
  76. }
  77. tmp := md.UserFeedbackList{
  78. Id: utils.IntToStr(v.Id),
  79. Phone: v.Phone,
  80. Title: v.Title,
  81. Platform: platformMap[platform],
  82. Version: gjson.Get(v.Extra, "devicemodel").String() + " " + gjson.Get(v.Extra, "osversion").String() + " " + gjson.Get(v.Extra, "appversionname").String(),
  83. Type: v.Type,
  84. Img: img,
  85. Content: v.Content,
  86. CreateAt: v.CreateAt.Format("2006-01-02 15:04:05"),
  87. State: utils.IntToStr(v.State),
  88. }
  89. noticeList = append(noticeList, tmp)
  90. }
  91. }
  92. resp.List = noticeList
  93. e.OutSuc(c, resp, nil)
  94. return
  95. }
  96. func RecordList(c *gin.Context) {
  97. eg := db.Db
  98. var req md.UserFeedbackRecordListReq
  99. err := c.ShouldBindJSON(&req)
  100. if err != nil {
  101. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  102. return
  103. }
  104. NewUserFeedbackRecordDb := implement.NewUserFeedbackRecordDb(eg)
  105. article, _ := NewUserFeedbackRecordDb.FindUserFeedback(req.Page, "1000", req.Id)
  106. data := make([]md.UserFeedbackRecordListResp, 0)
  107. if article != nil {
  108. for _, v := range *article {
  109. tmp := md.UserFeedbackRecordListResp{
  110. Content: v.Content,
  111. CreateAt: v.CreateAt.Format("2006-01-02"),
  112. Type: "official",
  113. }
  114. if v.Uid > 0 {
  115. NewUserDb := implement.NewUserDb(eg)
  116. user, _ := NewUserDb.GetUser(int64(v.Uid))
  117. if user != nil {
  118. tmp.Nickname = user.Nickname
  119. tmp.HeadImg = svc.GetOssUrl(user.Avatar)
  120. }
  121. tmp.Type = "user"
  122. } else {
  123. tmp.Nickname = svc.GetSysCfgStr("app_name")
  124. tmp.HeadImg = svc.GetOssUrl(svc.GetSysCfgStr("app_logo"))
  125. }
  126. data = append(data, tmp)
  127. }
  128. }
  129. e.OutSuc(c, data, nil)
  130. return
  131. }
  132. func Say(c *gin.Context) {
  133. var req *md.UserFeedbackSayReq
  134. if err := c.ShouldBindJSON(&req); err != nil {
  135. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  136. return
  137. }
  138. data := model.UserFeedbackRecord{
  139. Lid: utils.StrToInt(req.Id),
  140. Content: req.Content,
  141. CreateAt: time.Now(),
  142. }
  143. db.Db.Insert(&data)
  144. e.OutSuc(c, "success", nil)
  145. return
  146. }
  147. func ChangeState(c *gin.Context) {
  148. var req *md.UserFeedbackChangeStateReq
  149. if err := c.ShouldBindJSON(&req); err != nil {
  150. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  151. return
  152. }
  153. NewUserFeedbackDb := implement.NewUserFeedbackDb(db.Db)
  154. notice, _ := NewUserFeedbackDb.GetUserFeedback(req.Id)
  155. if notice == nil {
  156. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  157. return
  158. }
  159. notice.State = utils.StrToInt(req.State)
  160. db.Db.Where("id=?", notice.Id).Cols("state").Update(notice)
  161. e.OutSuc(c, "success", nil)
  162. return
  163. }
  164. func Del(c *gin.Context) {
  165. var req *md.UserFeedbackDelReq
  166. if err := c.ShouldBindJSON(&req); err != nil {
  167. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  168. return
  169. }
  170. db.Db.In("id", req.Id).Delete(&model.UserFeedback{})
  171. db.Db.In("lid", req.Id).Delete(&model.UserFeedbackRecord{})
  172. e.OutSuc(c, "success", nil)
  173. return
  174. }