蛋蛋星球 后台端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

205 líneas
5.5 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. SmsCode: v.SmsCode,
  162. State: utils.IntToStr(v.State),
  163. CreateAt: v.CreateAt.Format("2006-01-02 15:04:05"),
  164. }
  165. noticeList = append(noticeList, tmp)
  166. }
  167. }
  168. resp.List = noticeList
  169. e.OutSuc(c, resp, nil)
  170. return
  171. }
  172. func AliyunSmsPushSave(c *gin.Context) {
  173. var req *md.NoticeAliyunSmsPushSaveReq
  174. if err := c.ShouldBindJSON(&req); err != nil {
  175. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  176. return
  177. }
  178. if req.SmsCode == "" {
  179. e.OutErr(c, 400, e.NewErr(400, "请到阿里云获取营销短信模板id"))
  180. return
  181. }
  182. if utils.StrToInt(req.Id) > 0 {
  183. } else {
  184. data := &model.AliyunSmsRecord{
  185. Platform: "all",
  186. Target: req.Target,
  187. Phone: utils.SerializeStr(req.PhoneList),
  188. TagId: utils.SerializeStr(req.TagList),
  189. Level: utils.SerializeStr(req.Level),
  190. Title: req.Title,
  191. Content: req.Content,
  192. SmsCode: req.SmsCode,
  193. CreateAt: time.Now(),
  194. UpdateAt: time.Now(),
  195. }
  196. db.Db.Insert(data)
  197. }
  198. e.OutSuc(c, "success", nil)
  199. return
  200. }