蛋蛋星球-客户端
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.
 
 
 
 
 
 

150 lines
3.6 KiB

  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. Extra: utils.SerializeStr(c.Request.Header),
  115. Content: req.Content,
  116. Img: utils.SerializeStr(req.Img),
  117. Idea: req.Idea,
  118. Phone: req.Phone,
  119. Cid: utils.StrToInt(req.Cid),
  120. Ip: c.ClientIP(),
  121. CreateAt: time.Now(),
  122. }
  123. eg.Insert(&data)
  124. e.OutSuc(c, "success", nil)
  125. return
  126. }
  127. func UserFeedbackSay(c *gin.Context) {
  128. eg := db.Db
  129. var req md.UserFeedbackSayReq
  130. err := c.ShouldBindJSON(&req)
  131. if err != nil {
  132. err = HandleValidateErr(err)
  133. err1 := err.(e.E)
  134. e.OutErr(c, err1.Code, err1.Error())
  135. return
  136. }
  137. user := GetUser(c)
  138. data := model.UserFeedbackRecord{
  139. Uid: int(user.Id),
  140. Lid: utils.StrToInt(req.Id),
  141. Content: req.Content,
  142. CreateAt: time.Now(),
  143. }
  144. eg.Insert(&data)
  145. e.OutSuc(c, "success", nil)
  146. return
  147. }