蛋蛋星球 后台端
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

163 righe
4.4 KiB

  1. package notice
  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. "github.com/gin-gonic/gin"
  10. "time"
  11. )
  12. func List(c *gin.Context) {
  13. var req *md.NoticeListReq
  14. if err := c.ShouldBindJSON(&req); err != nil {
  15. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  16. return
  17. }
  18. var resp md.NoticeListResp
  19. noticeList := make([]md.NoticeList, 0)
  20. NewJpushNoticeDb := implement.NewJpushNoticeDb(db.Db)
  21. notice, total, _ := NewJpushNoticeDb.FindJpushNoticeAndTotal(req.Page, req.Limit, "")
  22. resp.Total = total
  23. resp.ChangeData = []map[string]string{
  24. {"name": "昵称", "value": "{昵称}"},
  25. {"name": "手机号", "value": "{手机号}"},
  26. {"name": "金额", "value": "{金额}"},
  27. {"name": "时间", "value": "{时间}"},
  28. {"name": "未登陆天数", "value": "{未登陆天数}"},
  29. {"name": "升级后等级", "value": "{升级后等级}"},
  30. }
  31. resp.SelectData = []map[string]string{
  32. {"name": "签到提醒", "value": "sign"},
  33. {"name": "提现到账提醒", "value": "withdraw"},
  34. {"name": "X天未登录提醒", "value": "login"},
  35. {"name": "升级提醒", "value": "update"},
  36. }
  37. if notice != nil {
  38. for _, v := range *notice {
  39. tmp := md.NoticeList{
  40. Id: utils.IntToStr(v.Id),
  41. Title: v.Title,
  42. Content: v.Content,
  43. Type: v.Type,
  44. }
  45. noticeList = append(noticeList, tmp)
  46. }
  47. }
  48. resp.List = noticeList
  49. e.OutSuc(c, resp, nil)
  50. return
  51. }
  52. func Save(c *gin.Context) {
  53. var req *md.NoticeSaveReq
  54. if err := c.ShouldBindJSON(&req); err != nil {
  55. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  56. return
  57. }
  58. var data = new(model.JpushNotice)
  59. if utils.StrToInt(req.Id) > 0 {
  60. NewJpushNoticeDb := implement.NewJpushNoticeDb(db.Db)
  61. notice, _ := NewJpushNoticeDb.GetJpushNotice(req.Id)
  62. if notice == nil {
  63. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  64. return
  65. }
  66. data = notice
  67. } else {
  68. data.CreateAt = time.Now()
  69. db.Db.Insert(data)
  70. }
  71. data.UpdateAt = time.Now()
  72. data.Content = req.Content
  73. data.Type = req.Type
  74. data.Title = req.Title
  75. db.Db.Where("id=?", data.Id).Update(data)
  76. e.OutSuc(c, "success", nil)
  77. return
  78. }
  79. func Del(c *gin.Context) {
  80. var req *md.NoticeDelReq
  81. if err := c.ShouldBindJSON(&req); err != nil {
  82. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  83. return
  84. }
  85. db.Db.In("id", req.Id).Delete(&model.JpushNotice{})
  86. e.OutSuc(c, "success", nil)
  87. return
  88. }
  89. func PushList(c *gin.Context) {
  90. var req *md.NoticeListReq
  91. if err := c.ShouldBindJSON(&req); err != nil {
  92. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  93. return
  94. }
  95. var resp md.NoticePushListResp
  96. noticeList := make([]md.NoticePushList, 0)
  97. resp.PlatformData = []map[string]string{
  98. {"name": "全平台", "value": "all"},
  99. {"name": "安卓", "value": "android"},
  100. {"name": "iOS", "value": "ios"},
  101. }
  102. resp.TargetData = []map[string]string{
  103. {"name": "全部会员", "value": "0"},
  104. {"name": "指定会员", "value": "1"},
  105. {"name": "指定等级", "value": "2"},
  106. }
  107. NewJpushRecordDb := implement.NewJpushRecordDb(db.Db)
  108. notice, total, _ := NewJpushRecordDb.FindJpushRecordAndTotal(req.Page, req.Limit, "")
  109. resp.Total = total
  110. if notice != nil {
  111. for _, v := range *notice {
  112. tmp := md.NoticePushList{
  113. Id: utils.IntToStr(v.Id),
  114. Title: v.Title,
  115. Content: v.Content,
  116. Platform: v.Platform,
  117. Target: v.Target,
  118. SendType: utils.IntToStr(v.SendType),
  119. State: utils.IntToStr(v.State),
  120. }
  121. if v.SendStartTime.IsZero() == false {
  122. tmp.SendStartTime = v.SendStartTime.Format("2006-01-02 15:04:05")
  123. }
  124. if v.SendEndTime.IsZero() == false {
  125. tmp.SendEndTime = v.SendEndTime.Format("2006-01-02 15:04:05")
  126. }
  127. noticeList = append(noticeList, tmp)
  128. }
  129. }
  130. resp.List = noticeList
  131. e.OutSuc(c, resp, nil)
  132. return
  133. }
  134. func PushSave(c *gin.Context) {
  135. var req *md.NoticePushSaveReq
  136. if err := c.ShouldBindJSON(&req); err != nil {
  137. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  138. return
  139. }
  140. if utils.StrToInt(req.Id) > 0 {
  141. } else {
  142. data := &model.JpushRecord{
  143. Platform: req.Platform,
  144. Target: req.Target,
  145. UserId: utils.SerializeStr(req.UserList),
  146. Level: utils.StrToInt(req.Level),
  147. Title: req.Title,
  148. Content: req.Content,
  149. SendType: utils.StrToInt(req.SendType),
  150. SendStartTime: utils.TimeParseStd(req.SendStartTime),
  151. SendEndTime: utils.TimeParseStd(req.SendStartTime),
  152. CreateAt: time.Now(),
  153. UpdateAt: time.Now(),
  154. }
  155. db.Db.Insert(data)
  156. }
  157. e.OutSuc(c, "success", nil)
  158. return
  159. }