蛋蛋星球-客户端
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_user_feedback.go 3.6 KiB

2 週之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. Title: v.Type,
  50. Img: img,
  51. Content: v.Content,
  52. State: "0",
  53. CreateAt: v.CreateAt.Format("2006-01-02"),
  54. }
  55. count, _ := eg.Where("uid=? and lid=?", 0, v.Id).Count(&model.UserFeedbackRecord{})
  56. if count > 0 {
  57. tmp.State = "1"
  58. }
  59. data = append(data, tmp)
  60. }
  61. }
  62. e.OutSuc(c, data, nil)
  63. return
  64. }
  65. func UserFeedbackRecord(c *gin.Context) {
  66. eg := db.Db
  67. var req md.UserFeedbackRecordReq
  68. err := c.ShouldBindJSON(&req)
  69. if err != nil {
  70. err = HandleValidateErr(err)
  71. err1 := err.(e.E)
  72. e.OutErr(c, err1.Code, err1.Error())
  73. return
  74. }
  75. user := GetUser(c)
  76. NewUserFeedbackRecordDb := implement.NewUserFeedbackRecordDb(eg)
  77. article, _ := NewUserFeedbackRecordDb.FindUserFeedback(req.Page, "1000", req.Id)
  78. data := make([]md.UserFeedbackRecordResp, 0)
  79. if article != nil {
  80. for _, v := range *article {
  81. tmp := md.UserFeedbackRecordResp{
  82. Content: v.Content,
  83. CreateAt: v.CreateAt.Format("2006-01-02"),
  84. Type: "official",
  85. }
  86. if v.Uid > 0 {
  87. tmp.Type = "user"
  88. tmp.Nickname = user.Nickname
  89. tmp.HeadImg = GetOssUrl(user.Avatar)
  90. } else {
  91. tmp.Nickname = GetSysCfgStr("app_name")
  92. tmp.HeadImg = GetOssUrl(GetSysCfgStr("app_logo"))
  93. }
  94. data = append(data, tmp)
  95. }
  96. }
  97. e.OutSuc(c, data, nil)
  98. return
  99. }
  100. func UserFeedbackSave(c *gin.Context) {
  101. eg := db.Db
  102. var req md.UserFeedbackSaveReq
  103. err := c.ShouldBindJSON(&req)
  104. if err != nil {
  105. err = HandleValidateErr(err)
  106. err1 := err.(e.E)
  107. e.OutErr(c, err1.Code, err1.Error())
  108. return
  109. }
  110. user := GetUser(c)
  111. data := model.UserFeedback{
  112. Uid: int(user.Id),
  113. Type: req.Type,
  114. Title: req.Title,
  115. Extra: utils.SerializeStr(c.Request.Header),
  116. Content: req.Content,
  117. Img: utils.SerializeStr(req.Img),
  118. Idea: req.Idea,
  119. Phone: req.Phone,
  120. Cid: utils.StrToInt(req.Cid),
  121. Ip: c.ClientIP(),
  122. CreateAt: time.Now(),
  123. }
  124. eg.Insert(&data)
  125. e.OutSuc(c, "success", nil)
  126. return
  127. }
  128. func UserFeedbackSay(c *gin.Context) {
  129. eg := db.Db
  130. var req md.UserFeedbackSayReq
  131. err := c.ShouldBindJSON(&req)
  132. if err != nil {
  133. err = HandleValidateErr(err)
  134. err1 := err.(e.E)
  135. e.OutErr(c, err1.Code, err1.Error())
  136. return
  137. }
  138. user := GetUser(c)
  139. data := model.UserFeedbackRecord{
  140. Uid: int(user.Id),
  141. Lid: utils.StrToInt(req.Id),
  142. Content: req.Content,
  143. CreateAt: time.Now(),
  144. }
  145. eg.Insert(&data)
  146. e.OutSuc(c, "success", nil)
  147. return
  148. }