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

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