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" "encoding/json" "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 AliyunSmsBase(c *gin.Context) { SelectData := []map[string]string{ {"name": "签到提醒", "value": "sign", "temple_id": "", "is_show": "1"}, {"name": "注销提醒", "value": "user_delete", "temple_id": "", "is_show": "1"}, {"name": "提现到账提醒", "value": "withdraw", "temple_id": "", "is_show": "1"}, {"name": "X天未登录提醒", "value": "login", "temple_id": "", "is_show": "1"}, {"name": "升级提醒", "value": "update", "temple_id": "", "is_show": "1"}, } redisConn := cache.GetPool().Get() sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) aliyunSmsNotice := sysCfgDb.SysCfgGetWithDb("aliyun_sms_notice") notice := make([]map[string]string, 0) json.Unmarshal([]byte(aliyunSmsNotice), ¬ice) for k, v := range SelectData { for _, v1 := range notice { if v1["value"] == v["value"] { SelectData[k]["temple_id"] = v1["temple_id"] SelectData[k]["temple_id"] = v1["is_show"] } } } e.OutSuc(c, SelectData, nil) return } func AliyunSmsSave(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_notice", utils.SerializeStr(req)) 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 }