蛋蛋星球 后台端
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.
 
 
 
 

172 lines
4.8 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. }
  30. resp.SelectData = []map[string]string{
  31. {"name": "X小时未签到提醒", "value": "sign"},
  32. {"name": "X小时未登录提醒", "value": "login"},
  33. {"name": "提现到账提醒", "value": "withdraw"},
  34. {"name": "升级提醒", "value": "update"},
  35. }
  36. if notice != nil {
  37. for _, v := range *notice {
  38. tmp := md.NoticeList{
  39. Id: utils.IntToStr(v.Id),
  40. Day: utils.IntToStr(v.Day),
  41. NoticeDay: utils.IntToStr(v.NoticeDay),
  42. JpushOpen: utils.IntToStr(v.JpushOpen),
  43. SmsOpen: utils.IntToStr(v.SmsOpen),
  44. SmsCode: v.SmsCode,
  45. Title: v.Title,
  46. Content: v.Content,
  47. Type: v.Type,
  48. }
  49. noticeList = append(noticeList, tmp)
  50. }
  51. }
  52. resp.List = noticeList
  53. e.OutSuc(c, resp, nil)
  54. return
  55. }
  56. func Save(c *gin.Context) {
  57. var req *md.NoticeSaveReq
  58. if err := c.ShouldBindJSON(&req); err != nil {
  59. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  60. return
  61. }
  62. var data = new(model.JpushNotice)
  63. if utils.StrToInt(req.Id) > 0 {
  64. NewJpushNoticeDb := implement.NewJpushNoticeDb(db.Db)
  65. notice, _ := NewJpushNoticeDb.GetJpushNotice(req.Id)
  66. if notice == nil {
  67. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  68. return
  69. }
  70. data = notice
  71. } else {
  72. data.CreateAt = time.Now()
  73. db.Db.Insert(data)
  74. }
  75. data.UpdateAt = time.Now()
  76. data.Content = req.Content
  77. data.Type = req.Type
  78. data.SmsCode = req.SmsCode
  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. {"name": "指定标签", "value": "3"},
  114. }
  115. NewJpushRecordDb := implement.NewJpushRecordDb(db.Db)
  116. notice, total, _ := NewJpushRecordDb.FindJpushRecordAndTotal(req.Page, req.Limit, "")
  117. resp.Total = total
  118. if notice != nil {
  119. for _, v := range *notice {
  120. tmp := md.NoticePushList{
  121. Id: utils.IntToStr(v.Id),
  122. Title: v.Title,
  123. Content: v.Content,
  124. Platform: v.Platform,
  125. Target: v.Target,
  126. SendType: utils.IntToStr(v.SendType),
  127. State: utils.IntToStr(v.State),
  128. }
  129. if v.SendStartTime.IsZero() == false {
  130. tmp.SendStartTime = v.SendStartTime.Format("2006-01-02 15:04:05")
  131. }
  132. if v.SendEndTime.IsZero() == false {
  133. tmp.SendEndTime = v.SendEndTime.Format("2006-01-02 15:04:05")
  134. }
  135. noticeList = append(noticeList, tmp)
  136. }
  137. }
  138. resp.List = noticeList
  139. e.OutSuc(c, resp, nil)
  140. return
  141. }
  142. func PushSave(c *gin.Context) {
  143. var req *md.NoticePushSaveReq
  144. if err := c.ShouldBindJSON(&req); err != nil {
  145. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  146. return
  147. }
  148. if utils.StrToInt(req.Id) > 0 {
  149. } else {
  150. data := &model.JpushRecord{
  151. Platform: req.Platform,
  152. Target: req.Target,
  153. UserId: utils.SerializeStr(req.UserList),
  154. TagId: utils.SerializeStr(req.TagList),
  155. Level: utils.SerializeStr(req.Level),
  156. Title: req.Title,
  157. Content: req.Content,
  158. SendType: utils.StrToInt(req.SendType),
  159. SendStartTime: utils.TimeParseStd(req.SendStartTime),
  160. SendEndTime: utils.TimeParseStd(req.SendStartTime),
  161. CreateAt: time.Now(),
  162. UpdateAt: time.Now(),
  163. }
  164. db.Db.Insert(data)
  165. }
  166. e.OutSuc(c, "success", nil)
  167. return
  168. }