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

198 lines
5.3 KiB

  1. package notice
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. "applet/app/utils/cache"
  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. data.IsShow = utils.StrToInt(req.IsShow)
  103. db.Db.Where("id=?", data.Id).Update(data)
  104. e.OutSuc(c, "success", nil)
  105. return
  106. }
  107. func AliyunSmsDel(c *gin.Context) {
  108. var req *md.NoticeDelReq
  109. if err := c.ShouldBindJSON(&req); err != nil {
  110. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  111. return
  112. }
  113. db.Db.In("id", req.Id).Delete(&model.AliyunSmsNotice{})
  114. e.OutSuc(c, "success", nil)
  115. return
  116. }
  117. func AliyunSmsSaleBase(c *gin.Context) {
  118. redisConn := cache.GetPool().Get()
  119. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  120. aliyunSmsNotice := sysCfgDb.SysCfgGetWithDb("aliyun_sms_sale_code")
  121. res := map[string]string{
  122. "aliyun_sms_sale_code": aliyunSmsNotice,
  123. }
  124. e.OutSuc(c, res, nil)
  125. return
  126. }
  127. func AliyunSmsSaleSave(c *gin.Context) {
  128. var req map[string]string
  129. if err := c.ShouldBindJSON(&req); err != nil {
  130. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  131. return
  132. }
  133. redisConn := cache.GetPool().Get()
  134. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  135. sysCfgDb.SysCfgUpdate("aliyun_sms_sale_code", req["aliyun_sms_sale_code"])
  136. e.OutSuc(c, "success", nil)
  137. return
  138. }
  139. func AliyunSmsPushList(c *gin.Context) {
  140. var req *md.NoticeAliyunSmsListReq
  141. if err := c.ShouldBindJSON(&req); err != nil {
  142. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  143. return
  144. }
  145. var resp md.NoticeAliyunSmsPushListResp
  146. noticeList := make([]md.NoticeAliyunSmsPushList, 0)
  147. resp.TargetData = []map[string]string{
  148. {"name": "全部会员", "value": "0"},
  149. {"name": "指定会员", "value": "1"},
  150. {"name": "指定等级", "value": "2"},
  151. }
  152. NewAliyunSmsRecordDb := implement.NewAliyunSmsRecordDb(db.Db)
  153. notice, total, _ := NewAliyunSmsRecordDb.FindAliyunSmsRecordAndTotal(req.Page, req.Limit, "")
  154. resp.Total = total
  155. if notice != nil {
  156. for _, v := range *notice {
  157. tmp := md.NoticeAliyunSmsPushList{
  158. Id: utils.IntToStr(v.Id),
  159. Title: v.Title,
  160. Content: v.Content,
  161. Target: v.Target,
  162. State: utils.IntToStr(v.State),
  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. Level: utils.StrToInt(req.Level),
  184. Title: req.Title,
  185. Content: req.Content,
  186. CreateAt: time.Now(),
  187. UpdateAt: time.Now(),
  188. }
  189. db.Db.Insert(data)
  190. }
  191. e.OutSuc(c, "success", nil)
  192. return
  193. }