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

199 lines
5.3 KiB

  1. package notice
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/svc/sys_cfg"
  7. "applet/app/utils"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  10. "github.com/360EntSecGroup-Skylar/excelize"
  11. "github.com/gin-gonic/gin"
  12. "time"
  13. )
  14. func AliyunSmsFilePhone(c *gin.Context) {
  15. file, _, err := c.Request.FormFile("file")
  16. if err != nil {
  17. e.OutErr(c, 400, e.NewErr(400, "上传文件错误"))
  18. return
  19. }
  20. // 打开上传的文件
  21. xlsx, err := excelize.OpenReader(file)
  22. if err != nil {
  23. e.OutErr(c, 400, e.NewErr(400, "打开文件失败"))
  24. return
  25. }
  26. rows := xlsx.GetRows(xlsx.GetSheetName(xlsx.GetActiveSheetIndex()))
  27. phone := make([]string, 0)
  28. for i, row := range rows {
  29. // 去掉第一行是excel表头部分
  30. if i == 0 {
  31. continue
  32. }
  33. phone = append(phone, row[0])
  34. }
  35. res := map[string]interface{}{
  36. "phone": phone,
  37. }
  38. e.OutSuc(c, res, nil)
  39. return
  40. }
  41. func AliyunSmsList(c *gin.Context) {
  42. var req *md.NoticeAliyunSmsListReq
  43. if err := c.ShouldBindJSON(&req); err != nil {
  44. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  45. return
  46. }
  47. var resp md.NoticeAliyunSmsListResp
  48. noticeList := make([]md.NoticeAliyunSmsList, 0)
  49. NewJpushNoticeDb := implement.NewAliyunSmsNoticeDb(db.Db)
  50. notice, total, _ := NewJpushNoticeDb.FindAliyunSmsNoticeAndTotal(req.Page, req.Limit, "")
  51. resp.Total = total
  52. resp.SelectData = []map[string]string{
  53. {"name": "X小时未签到提醒", "value": "sign"},
  54. {"name": "注销提醒", "value": "user_delete"},
  55. {"name": "提现到账提醒", "value": "withdraw"},
  56. {"name": "X小时未登录提醒", "value": "login"},
  57. {"name": "升级提醒", "value": "update"},
  58. }
  59. if notice != nil {
  60. for _, v := range *notice {
  61. tmp := md.NoticeAliyunSmsList{
  62. Id: utils.IntToStr(v.Id),
  63. Title: v.Title,
  64. Day: utils.IntToStr(v.Day),
  65. NoticeDay: utils.IntToStr(v.NoticeDay),
  66. Content: v.Content,
  67. Type: v.Type,
  68. IsShow: utils.IntToStr(v.IsShow),
  69. }
  70. noticeList = append(noticeList, tmp)
  71. }
  72. }
  73. resp.List = noticeList
  74. e.OutSuc(c, resp, nil)
  75. return
  76. }
  77. func AliyunSmsSave(c *gin.Context) {
  78. var req *md.NoticeAliyunSmsSaveReq
  79. if err := c.ShouldBindJSON(&req); err != nil {
  80. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  81. return
  82. }
  83. var data = new(model.JpushNotice)
  84. if utils.StrToInt(req.Id) > 0 {
  85. NewJpushNoticeDb := implement.NewJpushNoticeDb(db.Db)
  86. notice, _ := NewJpushNoticeDb.GetJpushNotice(req.Id)
  87. if notice == nil {
  88. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  89. return
  90. }
  91. data = notice
  92. } else {
  93. data.CreateAt = time.Now()
  94. db.Db.Insert(data)
  95. }
  96. data.UpdateAt = time.Now()
  97. data.Content = req.Content
  98. data.Type = req.Type
  99. data.Title = req.Title
  100. data.Day = utils.StrToInt(req.Day)
  101. data.NoticeDay = utils.StrToInt(req.NoticeDay)
  102. db.Db.Where("id=?", data.Id).Update(data)
  103. e.OutSuc(c, "success", nil)
  104. return
  105. }
  106. func AliyunSmsDel(c *gin.Context) {
  107. var req *md.NoticeDelReq
  108. if err := c.ShouldBindJSON(&req); err != nil {
  109. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  110. return
  111. }
  112. db.Db.In("id", req.Id).Delete(&model.AliyunSmsNotice{})
  113. e.OutSuc(c, "success", nil)
  114. return
  115. }
  116. func AliyunSmsSaleBase(c *gin.Context) {
  117. sysCfgDb := sys_cfg.NewSysCfgDb(db.Db)
  118. aliyunSmsNotice := sysCfgDb.SysCfgGetWithDb("aliyun_sms_sale_code")
  119. res := map[string]string{
  120. "aliyun_sms_sale_code": aliyunSmsNotice,
  121. }
  122. e.OutSuc(c, res, nil)
  123. return
  124. }
  125. func AliyunSmsSaleSave(c *gin.Context) {
  126. var req map[string]string
  127. if err := c.ShouldBindJSON(&req); err != nil {
  128. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  129. return
  130. }
  131. sysCfgDb := sys_cfg.NewSysCfgDb(db.Db)
  132. sysCfgDb.SysCfgUpdate("aliyun_sms_sale_code", req["aliyun_sms_sale_code"])
  133. e.OutSuc(c, "success", nil)
  134. return
  135. }
  136. func AliyunSmsPushList(c *gin.Context) {
  137. var req *md.NoticeAliyunSmsListReq
  138. if err := c.ShouldBindJSON(&req); err != nil {
  139. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  140. return
  141. }
  142. var resp md.NoticeAliyunSmsPushListResp
  143. noticeList := make([]md.NoticeAliyunSmsPushList, 0)
  144. resp.TargetData = []map[string]string{
  145. {"name": "全部会员", "value": "0"},
  146. {"name": "指定会员", "value": "1"},
  147. {"name": "指定等级", "value": "2"},
  148. {"name": "指定标签", "value": "3"},
  149. {"name": "站外手机", "value": "4"},
  150. }
  151. NewAliyunSmsRecordDb := implement.NewAliyunSmsRecordDb(db.Db)
  152. notice, total, _ := NewAliyunSmsRecordDb.FindAliyunSmsRecordAndTotal(req.Page, req.Limit, "")
  153. resp.Total = total
  154. if notice != nil {
  155. for _, v := range *notice {
  156. tmp := md.NoticeAliyunSmsPushList{
  157. Id: utils.IntToStr(v.Id),
  158. Title: v.Title,
  159. Content: v.Content,
  160. Target: v.Target,
  161. State: utils.IntToStr(v.State),
  162. CreateAt: v.CreateAt.Format("2006-01-02 15:04:05"),
  163. }
  164. noticeList = append(noticeList, tmp)
  165. }
  166. }
  167. resp.List = noticeList
  168. e.OutSuc(c, resp, nil)
  169. return
  170. }
  171. func AliyunSmsPushSave(c *gin.Context) {
  172. var req *md.NoticeAliyunSmsPushSaveReq
  173. if err := c.ShouldBindJSON(&req); err != nil {
  174. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  175. return
  176. }
  177. if utils.StrToInt(req.Id) > 0 {
  178. } else {
  179. data := &model.AliyunSmsRecord{
  180. Platform: "all",
  181. Target: req.Target,
  182. Phone: utils.SerializeStr(req.PhoneList),
  183. TagId: utils.SerializeStr(req.TagList),
  184. Level: utils.SerializeStr(req.Level),
  185. Title: req.Title,
  186. Content: req.Content,
  187. CreateAt: time.Now(),
  188. UpdateAt: time.Now(),
  189. }
  190. db.Db.Insert(data)
  191. }
  192. e.OutSuc(c, "success", nil)
  193. return
  194. }