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

160 lines
4.4 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. "encoding/json"
  11. "github.com/360EntSecGroup-Skylar/excelize"
  12. "github.com/gin-gonic/gin"
  13. "time"
  14. )
  15. func AliyunSmsFilePhone(c *gin.Context) {
  16. file, _, err := c.Request.FormFile("file")
  17. if err != nil {
  18. e.OutErr(c, 400, e.NewErr(400, "上传文件错误"))
  19. return
  20. }
  21. // 打开上传的文件
  22. xlsx, err := excelize.OpenReader(file)
  23. if err != nil {
  24. e.OutErr(c, 400, e.NewErr(400, "打开文件失败"))
  25. return
  26. }
  27. rows := xlsx.GetRows(xlsx.GetSheetName(xlsx.GetActiveSheetIndex()))
  28. phone := make([]string, 0)
  29. for i, row := range rows {
  30. // 去掉第一行是excel表头部分
  31. if i == 0 {
  32. continue
  33. }
  34. phone = append(phone, row[0])
  35. }
  36. res := map[string]interface{}{
  37. "phone": phone,
  38. }
  39. e.OutSuc(c, res, nil)
  40. return
  41. }
  42. func AliyunSmsBase(c *gin.Context) {
  43. SelectData := []map[string]string{
  44. {"name": "签到提醒", "value": "sign", "temple_id": "", "is_show": "1"},
  45. {"name": "注销提醒", "value": "user_delete", "temple_id": "", "is_show": "1"},
  46. {"name": "提现到账提醒", "value": "withdraw", "temple_id": "", "is_show": "1"},
  47. {"name": "X天未登录提醒", "value": "login", "temple_id": "", "is_show": "1"},
  48. {"name": "升级提醒", "value": "update", "temple_id": "", "is_show": "1"},
  49. }
  50. redisConn := cache.GetPool().Get()
  51. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  52. aliyunSmsNotice := sysCfgDb.SysCfgGetWithDb("aliyun_sms_notice")
  53. notice := make([]map[string]string, 0)
  54. json.Unmarshal([]byte(aliyunSmsNotice), &notice)
  55. for k, v := range SelectData {
  56. for _, v1 := range notice {
  57. if v1["value"] == v["value"] {
  58. SelectData[k]["temple_id"] = v1["temple_id"]
  59. SelectData[k]["temple_id"] = v1["is_show"]
  60. }
  61. }
  62. }
  63. e.OutSuc(c, SelectData, nil)
  64. return
  65. }
  66. func AliyunSmsSave(c *gin.Context) {
  67. var req []map[string]string
  68. if err := c.ShouldBindJSON(&req); err != nil {
  69. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  70. return
  71. }
  72. redisConn := cache.GetPool().Get()
  73. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  74. sysCfgDb.SysCfgUpdate("aliyun_sms_notice", utils.SerializeStr(req))
  75. e.OutSuc(c, "success", nil)
  76. return
  77. }
  78. func AliyunSmsSaleBase(c *gin.Context) {
  79. redisConn := cache.GetPool().Get()
  80. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  81. aliyunSmsNotice := sysCfgDb.SysCfgGetWithDb("aliyun_sms_sale_code")
  82. res := map[string]string{
  83. "aliyun_sms_sale_code": aliyunSmsNotice,
  84. }
  85. e.OutSuc(c, res, nil)
  86. return
  87. }
  88. func AliyunSmsSaleSave(c *gin.Context) {
  89. var req map[string]string
  90. if err := c.ShouldBindJSON(&req); err != nil {
  91. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  92. return
  93. }
  94. redisConn := cache.GetPool().Get()
  95. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  96. sysCfgDb.SysCfgUpdate("aliyun_sms_sale_code", req["aliyun_sms_sale_code"])
  97. e.OutSuc(c, "success", nil)
  98. return
  99. }
  100. func AliyunSmsPushList(c *gin.Context) {
  101. var req *md.NoticeAliyunSmsListReq
  102. if err := c.ShouldBindJSON(&req); err != nil {
  103. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  104. return
  105. }
  106. var resp md.NoticeAliyunSmsPushListResp
  107. noticeList := make([]md.NoticeAliyunSmsPushList, 0)
  108. resp.TargetData = []map[string]string{
  109. {"name": "全部会员", "value": "0"},
  110. {"name": "指定会员", "value": "1"},
  111. {"name": "指定等级", "value": "2"},
  112. }
  113. NewAliyunSmsRecordDb := implement.NewAliyunSmsRecordDb(db.Db)
  114. notice, total, _ := NewAliyunSmsRecordDb.FindAliyunSmsRecordAndTotal(req.Page, req.Limit, "")
  115. resp.Total = total
  116. if notice != nil {
  117. for _, v := range *notice {
  118. tmp := md.NoticeAliyunSmsPushList{
  119. Id: utils.IntToStr(v.Id),
  120. Title: v.Title,
  121. Content: v.Content,
  122. Target: v.Target,
  123. State: utils.IntToStr(v.State),
  124. }
  125. noticeList = append(noticeList, tmp)
  126. }
  127. }
  128. resp.List = noticeList
  129. e.OutSuc(c, resp, nil)
  130. return
  131. }
  132. func AliyunSmsPushSave(c *gin.Context) {
  133. var req *md.NoticeAliyunSmsPushSaveReq
  134. if err := c.ShouldBindJSON(&req); err != nil {
  135. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  136. return
  137. }
  138. if utils.StrToInt(req.Id) > 0 {
  139. } else {
  140. data := &model.AliyunSmsRecord{
  141. Platform: "all",
  142. Target: req.Target,
  143. Phone: utils.SerializeStr(req.PhoneList),
  144. Level: utils.StrToInt(req.Level),
  145. Title: req.Title,
  146. Content: req.Content,
  147. CreateAt: time.Now(),
  148. UpdateAt: time.Now(),
  149. }
  150. db.Db.Insert(data)
  151. }
  152. e.OutSuc(c, "success", nil)
  153. return
  154. }