蛋蛋星球 后台端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

170 строки
4.7 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": "X小时未签到提醒", "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. Day: utils.IntToStr(v.Day),
  42. NoticeDay: utils.IntToStr(v.NoticeDay),
  43. JpushOpen: utils.IntToStr(v.JpushOpen),
  44. SmsOpen: utils.IntToStr(v.SmsOpen),
  45. SmsCode: v.SmsCode,
  46. Title: v.Title,
  47. Content: v.Content,
  48. Type: v.Type,
  49. }
  50. noticeList = append(noticeList, tmp)
  51. }
  52. }
  53. resp.List = noticeList
  54. e.OutSuc(c, resp, nil)
  55. return
  56. }
  57. func Save(c *gin.Context) {
  58. var req *md.NoticeSaveReq
  59. if err := c.ShouldBindJSON(&req); err != nil {
  60. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  61. return
  62. }
  63. var data = new(model.JpushNotice)
  64. if utils.StrToInt(req.Id) > 0 {
  65. NewJpushNoticeDb := implement.NewJpushNoticeDb(db.Db)
  66. notice, _ := NewJpushNoticeDb.GetJpushNotice(req.Id)
  67. if notice == nil {
  68. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  69. return
  70. }
  71. data = notice
  72. } else {
  73. data.CreateAt = time.Now()
  74. db.Db.Insert(data)
  75. }
  76. data.UpdateAt = time.Now()
  77. data.Content = req.Content
  78. data.Type = req.Type
  79. data.Title = req.Title
  80. data.Day = utils.StrToInt(req.Day)
  81. data.NoticeDay = utils.StrToInt(req.NoticeDay)
  82. db.Db.Where("id=?", data.Id).Update(data)
  83. e.OutSuc(c, "success", nil)
  84. return
  85. }
  86. func Del(c *gin.Context) {
  87. var req *md.NoticeDelReq
  88. if err := c.ShouldBindJSON(&req); err != nil {
  89. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  90. return
  91. }
  92. db.Db.In("id", req.Id).Delete(&model.JpushNotice{})
  93. e.OutSuc(c, "success", nil)
  94. return
  95. }
  96. func PushList(c *gin.Context) {
  97. var req *md.NoticeListReq
  98. if err := c.ShouldBindJSON(&req); err != nil {
  99. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  100. return
  101. }
  102. var resp md.NoticePushListResp
  103. noticeList := make([]md.NoticePushList, 0)
  104. resp.PlatformData = []map[string]string{
  105. {"name": "全平台", "value": "all"},
  106. {"name": "安卓", "value": "android"},
  107. {"name": "iOS", "value": "ios"},
  108. }
  109. resp.TargetData = []map[string]string{
  110. {"name": "全部会员", "value": "0"},
  111. {"name": "指定会员", "value": "1"},
  112. {"name": "指定等级", "value": "2"},
  113. }
  114. NewJpushRecordDb := implement.NewJpushRecordDb(db.Db)
  115. notice, total, _ := NewJpushRecordDb.FindJpushRecordAndTotal(req.Page, req.Limit, "")
  116. resp.Total = total
  117. if notice != nil {
  118. for _, v := range *notice {
  119. tmp := md.NoticePushList{
  120. Id: utils.IntToStr(v.Id),
  121. Title: v.Title,
  122. Content: v.Content,
  123. Platform: v.Platform,
  124. Target: v.Target,
  125. SendType: utils.IntToStr(v.SendType),
  126. State: utils.IntToStr(v.State),
  127. }
  128. if v.SendStartTime.IsZero() == false {
  129. tmp.SendStartTime = v.SendStartTime.Format("2006-01-02 15:04:05")
  130. }
  131. if v.SendEndTime.IsZero() == false {
  132. tmp.SendEndTime = v.SendEndTime.Format("2006-01-02 15:04:05")
  133. }
  134. noticeList = append(noticeList, tmp)
  135. }
  136. }
  137. resp.List = noticeList
  138. e.OutSuc(c, resp, nil)
  139. return
  140. }
  141. func PushSave(c *gin.Context) {
  142. var req *md.NoticePushSaveReq
  143. if err := c.ShouldBindJSON(&req); err != nil {
  144. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  145. return
  146. }
  147. if utils.StrToInt(req.Id) > 0 {
  148. } else {
  149. data := &model.JpushRecord{
  150. Platform: req.Platform,
  151. Target: req.Target,
  152. UserId: utils.SerializeStr(req.UserList),
  153. Level: utils.StrToInt(req.Level),
  154. Title: req.Title,
  155. Content: req.Content,
  156. SendType: utils.StrToInt(req.SendType),
  157. SendStartTime: utils.TimeParseStd(req.SendStartTime),
  158. SendEndTime: utils.TimeParseStd(req.SendStartTime),
  159. CreateAt: time.Now(),
  160. UpdateAt: time.Now(),
  161. }
  162. db.Db.Insert(data)
  163. }
  164. e.OutSuc(c, "success", nil)
  165. return
  166. }