蛋蛋星球 后台端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

svc_notice.go 4.7 KiB

3 semanas atrás
3 semanas atrás
3 semanas atrás
3 semanas atrás
3 semanas atrás
3 semanas atrás
3 semanas atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. }