|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- package notice
-
- import (
- "applet/app/db"
- "applet/app/e"
- "applet/app/md"
- "applet/app/utils"
- "applet/app/utils/cache"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "github.com/360EntSecGroup-Skylar/excelize"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- func AliyunSmsFilePhone(c *gin.Context) {
- file, _, err := c.Request.FormFile("file")
- if err != nil {
- e.OutErr(c, 400, e.NewErr(400, "上传文件错误"))
- return
- }
- // 打开上传的文件
- xlsx, err := excelize.OpenReader(file)
- if err != nil {
- e.OutErr(c, 400, e.NewErr(400, "打开文件失败"))
- return
- }
-
- rows := xlsx.GetRows(xlsx.GetSheetName(xlsx.GetActiveSheetIndex()))
- phone := make([]string, 0)
- for i, row := range rows {
- // 去掉第一行是excel表头部分
- if i == 0 {
- continue
- }
- phone = append(phone, row[0])
- }
- res := map[string]interface{}{
- "phone": phone,
- }
- e.OutSuc(c, res, nil)
- return
- }
- func AliyunSmsList(c *gin.Context) {
- var req *md.NoticeAliyunSmsListReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var resp md.NoticeAliyunSmsListResp
- noticeList := make([]md.NoticeAliyunSmsList, 0)
- NewJpushNoticeDb := implement.NewAliyunSmsNoticeDb(db.Db)
- notice, total, _ := NewJpushNoticeDb.FindAliyunSmsNoticeAndTotal(req.Page, req.Limit, "")
- resp.Total = total
- resp.SelectData = []map[string]string{
- {"name": "X小时未签到提醒", "value": "sign"},
- {"name": "注销提醒", "value": "user_delete"},
- {"name": "提现到账提醒", "value": "withdraw"},
- {"name": "X小时未登录提醒", "value": "login"},
- {"name": "升级提醒", "value": "update"},
- }
- if notice != nil {
- for _, v := range *notice {
- tmp := md.NoticeAliyunSmsList{
- Id: utils.IntToStr(v.Id),
- Title: v.Title,
- Day: utils.IntToStr(v.Day),
- NoticeDay: utils.IntToStr(v.NoticeDay),
- Content: v.Content,
- Type: v.Type,
- IsShow: utils.IntToStr(v.IsShow),
- }
- noticeList = append(noticeList, tmp)
- }
- }
- resp.List = noticeList
- e.OutSuc(c, resp, nil)
- return
- }
- func AliyunSmsSave(c *gin.Context) {
- var req *md.NoticeAliyunSmsSaveReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var data = new(model.JpushNotice)
- if utils.StrToInt(req.Id) > 0 {
- NewJpushNoticeDb := implement.NewJpushNoticeDb(db.Db)
- notice, _ := NewJpushNoticeDb.GetJpushNotice(req.Id)
- if notice == nil {
- e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
- return
- }
- data = notice
- } else {
- data.CreateAt = time.Now()
- db.Db.Insert(data)
- }
- data.UpdateAt = time.Now()
- data.Content = req.Content
- data.Type = req.Type
- data.Title = req.Title
- data.Day = utils.StrToInt(req.Day)
- data.NoticeDay = utils.StrToInt(req.NoticeDay)
- data.IsShow = utils.StrToInt(req.IsShow)
- db.Db.Where("id=?", data.Id).Update(data)
- e.OutSuc(c, "success", nil)
- return
- }
- func AliyunSmsDel(c *gin.Context) {
- var req *md.NoticeDelReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- db.Db.In("id", req.Id).Delete(&model.AliyunSmsNotice{})
- e.OutSuc(c, "success", nil)
- return
- }
- func AliyunSmsSaleBase(c *gin.Context) {
-
- redisConn := cache.GetPool().Get()
- sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
- aliyunSmsNotice := sysCfgDb.SysCfgGetWithDb("aliyun_sms_sale_code")
- res := map[string]string{
- "aliyun_sms_sale_code": aliyunSmsNotice,
- }
- e.OutSuc(c, res, nil)
- return
- }
- func AliyunSmsSaleSave(c *gin.Context) {
- var req map[string]string
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- redisConn := cache.GetPool().Get()
- sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
- sysCfgDb.SysCfgUpdate("aliyun_sms_sale_code", req["aliyun_sms_sale_code"])
- e.OutSuc(c, "success", nil)
- return
- }
- func AliyunSmsPushList(c *gin.Context) {
- var req *md.NoticeAliyunSmsListReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var resp md.NoticeAliyunSmsPushListResp
- noticeList := make([]md.NoticeAliyunSmsPushList, 0)
- resp.TargetData = []map[string]string{
- {"name": "全部会员", "value": "0"},
- {"name": "指定会员", "value": "1"},
- {"name": "指定等级", "value": "2"},
- }
- NewAliyunSmsRecordDb := implement.NewAliyunSmsRecordDb(db.Db)
- notice, total, _ := NewAliyunSmsRecordDb.FindAliyunSmsRecordAndTotal(req.Page, req.Limit, "")
- resp.Total = total
- if notice != nil {
- for _, v := range *notice {
- tmp := md.NoticeAliyunSmsPushList{
- Id: utils.IntToStr(v.Id),
- Title: v.Title,
- Content: v.Content,
- Target: v.Target,
- State: utils.IntToStr(v.State),
- }
- noticeList = append(noticeList, tmp)
- }
- }
- resp.List = noticeList
- e.OutSuc(c, resp, nil)
- return
- }
- func AliyunSmsPushSave(c *gin.Context) {
- var req *md.NoticeAliyunSmsPushSaveReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- if utils.StrToInt(req.Id) > 0 {
- } else {
- data := &model.AliyunSmsRecord{
- Platform: "all",
- Target: req.Target,
- Phone: utils.SerializeStr(req.PhoneList),
- Level: utils.StrToInt(req.Level),
- Title: req.Title,
- Content: req.Content,
- CreateAt: time.Now(),
- UpdateAt: time.Now(),
- }
- db.Db.Insert(data)
- }
- e.OutSuc(c, "success", nil)
- return
- }
|