蛋蛋星球-客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

svc_user_feedback.go 3.7 KiB

1周前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  9. "encoding/json"
  10. "github.com/gin-gonic/gin"
  11. "time"
  12. )
  13. func UserFeedbackCate(c *gin.Context) {
  14. NewUserFeedbackCateDb := implement.NewUserFeedbackCateDb(db.Db)
  15. cate, _ := NewUserFeedbackCateDb.FindUserFeedbackCate("1", "100")
  16. data := make([]map[string]string, 0)
  17. if cate != nil {
  18. for _, v := range *cate {
  19. tmp := map[string]string{
  20. "id": utils.IntToStr(v.Id),
  21. "name": v.Name,
  22. }
  23. data = append(data, tmp)
  24. }
  25. }
  26. e.OutSuc(c, data, nil)
  27. return
  28. }
  29. func UserFeedbackList(c *gin.Context) {
  30. eg := db.Db
  31. var req md.UserFeedbackListReq
  32. err := c.ShouldBindJSON(&req)
  33. if err != nil {
  34. err = HandleValidateErr(err)
  35. err1 := err.(e.E)
  36. e.OutErr(c, err1.Code, err1.Error())
  37. return
  38. }
  39. user := GetUser(c)
  40. NewUserFeedbackDb := implement.NewUserFeedbackDb(eg)
  41. article, _ := NewUserFeedbackDb.FindUserFeedback(req.Page, req.Limit, utils.Int64ToStr(user.Id))
  42. data := make([]md.UserFeedbackListResp, 0)
  43. if article != nil {
  44. for _, v := range *article {
  45. img := make([]string, 0)
  46. json.Unmarshal([]byte(v.Img), &img)
  47. tmp := md.UserFeedbackListResp{
  48. Id: utils.IntToStr(v.Id),
  49. Type: v.Type,
  50. Title: v.Title,
  51. Img: img,
  52. Content: v.Content,
  53. State: "0",
  54. CreateAt: v.CreateAt.Format("2006-01-02"),
  55. }
  56. count, _ := eg.Where("uid=? and lid=?", 0, v.Id).Count(&model.UserFeedbackRecord{})
  57. if count > 0 {
  58. tmp.State = "1"
  59. }
  60. data = append(data, tmp)
  61. }
  62. }
  63. e.OutSuc(c, data, nil)
  64. return
  65. }
  66. func UserFeedbackRecord(c *gin.Context) {
  67. eg := db.Db
  68. var req md.UserFeedbackRecordReq
  69. err := c.ShouldBindJSON(&req)
  70. if err != nil {
  71. err = HandleValidateErr(err)
  72. err1 := err.(e.E)
  73. e.OutErr(c, err1.Code, err1.Error())
  74. return
  75. }
  76. user := GetUser(c)
  77. NewUserFeedbackRecordDb := implement.NewUserFeedbackRecordDb(eg)
  78. article, _ := NewUserFeedbackRecordDb.FindUserFeedback(req.Page, "1000", req.Id)
  79. data := make([]md.UserFeedbackRecordResp, 0)
  80. if article != nil {
  81. for _, v := range *article {
  82. tmp := md.UserFeedbackRecordResp{
  83. Content: v.Content,
  84. CreateAt: v.CreateAt.Format("2006-01-02"),
  85. Type: "official",
  86. }
  87. if v.Uid > 0 {
  88. tmp.Type = "user"
  89. tmp.Nickname = user.Nickname
  90. tmp.HeadImg = GetOssUrl(user.Avatar)
  91. } else {
  92. tmp.Nickname = GetSysCfgStr("app_name")
  93. tmp.HeadImg = GetOssUrl(GetSysCfgStr("app_logo"))
  94. }
  95. data = append(data, tmp)
  96. }
  97. }
  98. e.OutSuc(c, data, nil)
  99. return
  100. }
  101. func UserFeedbackSave(c *gin.Context) {
  102. eg := db.Db
  103. var req md.UserFeedbackSaveReq
  104. err := c.ShouldBindJSON(&req)
  105. if err != nil {
  106. err = HandleValidateErr(err)
  107. err1 := err.(e.E)
  108. e.OutErr(c, err1.Code, err1.Error())
  109. return
  110. }
  111. user := GetUser(c)
  112. data := model.UserFeedback{
  113. Uid: int(user.Id),
  114. Type: req.Type,
  115. Title: req.Title,
  116. Extra: utils.SerializeStr(c.Request.Header),
  117. Content: req.Content,
  118. Img: utils.SerializeStr(req.Img),
  119. Idea: req.Idea,
  120. Phone: req.Phone,
  121. Cid: utils.StrToInt(req.Cid),
  122. Ip: utils.GetIP(c.Request),
  123. CreateAt: time.Now(),
  124. }
  125. eg.Insert(&data)
  126. e.OutSuc(c, "success", nil)
  127. return
  128. }
  129. func UserFeedbackSay(c *gin.Context) {
  130. eg := db.Db
  131. var req md.UserFeedbackSayReq
  132. err := c.ShouldBindJSON(&req)
  133. if err != nil {
  134. err = HandleValidateErr(err)
  135. err1 := err.(e.E)
  136. e.OutErr(c, err1.Code, err1.Error())
  137. return
  138. }
  139. user := GetUser(c)
  140. data := model.UserFeedbackRecord{
  141. Uid: int(user.Id),
  142. Lid: utils.StrToInt(req.Id),
  143. Content: req.Content,
  144. CreateAt: time.Now(),
  145. }
  146. eg.Insert(&data)
  147. e.OutSuc(c, "success", nil)
  148. return
  149. }