蛋蛋星球 后台端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

svc_notice.go 4.7 KiB

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