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

svc_aliyun_sms.go 5.3 KiB

1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
4 days ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. 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. redisConn := cache.GetPool().Get()
  118. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  119. aliyunSmsNotice := sysCfgDb.SysCfgGetWithDb("aliyun_sms_sale_code")
  120. res := map[string]string{
  121. "aliyun_sms_sale_code": aliyunSmsNotice,
  122. }
  123. e.OutSuc(c, res, nil)
  124. return
  125. }
  126. func AliyunSmsSaleSave(c *gin.Context) {
  127. var req map[string]string
  128. if err := c.ShouldBindJSON(&req); err != nil {
  129. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  130. return
  131. }
  132. redisConn := cache.GetPool().Get()
  133. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  134. sysCfgDb.SysCfgUpdate("aliyun_sms_sale_code", req["aliyun_sms_sale_code"])
  135. e.OutSuc(c, "success", nil)
  136. return
  137. }
  138. func AliyunSmsPushList(c *gin.Context) {
  139. var req *md.NoticeAliyunSmsListReq
  140. if err := c.ShouldBindJSON(&req); err != nil {
  141. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  142. return
  143. }
  144. var resp md.NoticeAliyunSmsPushListResp
  145. noticeList := make([]md.NoticeAliyunSmsPushList, 0)
  146. resp.TargetData = []map[string]string{
  147. {"name": "全部会员", "value": "0"},
  148. {"name": "指定会员", "value": "1"},
  149. {"name": "指定等级", "value": "2"},
  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. 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. }