|
- package notice
-
- import (
- "applet/app/db"
- "applet/app/e"
- "applet/app/md"
- "applet/app/utils"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- func List(c *gin.Context) {
- var req *md.NoticeListReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var resp md.NoticeListResp
- noticeList := make([]md.NoticeList, 0)
- NewJpushNoticeDb := implement.NewJpushNoticeDb(db.Db)
- notice, total, _ := NewJpushNoticeDb.FindJpushNoticeAndTotal(req.Page, req.Limit, "")
- resp.Total = total
- resp.ChangeData = []map[string]string{
- {"name": "昵称", "value": "{昵称}"},
- {"name": "手机号", "value": "{手机号}"},
- {"name": "金额", "value": "{金额}"},
- {"name": "小时", "value": "{小时}"},
- {"name": "升级后等级", "value": "{升级后等级}"},
- }
- resp.SelectData = []map[string]string{
- {"name": "X小时未签到提醒", "value": "sign"},
- {"name": "X小时未登录提醒", "value": "login"},
- {"name": "提现到账提醒", "value": "withdraw"},
- {"name": "升级提醒", "value": "update"},
- }
- if notice != nil {
- for _, v := range *notice {
- tmp := md.NoticeList{
- Id: utils.IntToStr(v.Id),
- Day: utils.IntToStr(v.Day),
- NoticeDay: utils.IntToStr(v.NoticeDay),
- JpushOpen: utils.IntToStr(v.JpushOpen),
- SmsOpen: utils.IntToStr(v.SmsOpen),
- SmsCode: v.SmsCode,
- Title: v.Title,
- Content: v.Content,
- Type: v.Type,
- }
- noticeList = append(noticeList, tmp)
- }
- }
- resp.List = noticeList
- e.OutSuc(c, resp, nil)
- return
- }
- func Save(c *gin.Context) {
- var req *md.NoticeSaveReq
- 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.SmsCode = req.SmsCode
- data.Title = req.Title
- data.Day = utils.StrToInt(req.Day)
- data.NoticeDay = utils.StrToInt(req.NoticeDay)
- db.Db.Where("id=?", data.Id).Update(data)
- e.OutSuc(c, "success", nil)
- return
- }
- func Del(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.JpushNotice{})
- e.OutSuc(c, "success", nil)
- return
- }
-
- func PushList(c *gin.Context) {
- var req *md.NoticeListReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var resp md.NoticePushListResp
- noticeList := make([]md.NoticePushList, 0)
- resp.PlatformData = []map[string]string{
- {"name": "全平台", "value": "all"},
- {"name": "安卓", "value": "android"},
- {"name": "iOS", "value": "ios"},
- }
- resp.TargetData = []map[string]string{
- {"name": "全部会员", "value": "0"},
- {"name": "指定会员", "value": "1"},
- {"name": "指定等级", "value": "2"},
- {"name": "指定标签", "value": "3"},
- }
- NewJpushRecordDb := implement.NewJpushRecordDb(db.Db)
- notice, total, _ := NewJpushRecordDb.FindJpushRecordAndTotal(req.Page, req.Limit, "")
- resp.Total = total
- if notice != nil {
- for _, v := range *notice {
- tmp := md.NoticePushList{
- Id: utils.IntToStr(v.Id),
- Title: v.Title,
- Content: v.Content,
- Platform: v.Platform,
- Target: v.Target,
- SendType: utils.IntToStr(v.SendType),
- State: utils.IntToStr(v.State),
- }
- if v.SendStartTime.IsZero() == false {
- tmp.SendStartTime = v.SendStartTime.Format("2006-01-02 15:04:05")
- }
- if v.SendEndTime.IsZero() == false {
- tmp.SendEndTime = v.SendEndTime.Format("2006-01-02 15:04:05")
- }
- noticeList = append(noticeList, tmp)
- }
- }
- resp.List = noticeList
- e.OutSuc(c, resp, nil)
- return
- }
- func PushSave(c *gin.Context) {
- var req *md.NoticePushSaveReq
- 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.JpushRecord{
- Platform: req.Platform,
- Target: req.Target,
- UserId: utils.SerializeStr(req.UserList),
- TagId: utils.SerializeStr(req.TagList),
- Level: utils.SerializeStr(req.Level),
- Title: req.Title,
- Content: req.Content,
- SendType: utils.StrToInt(req.SendType),
- SendStartTime: utils.TimeParseStd(req.SendStartTime),
- SendEndTime: utils.TimeParseStd(req.SendStartTime),
- CreateAt: time.Now(),
- UpdateAt: time.Now(),
- }
- db.Db.Insert(data)
- }
- e.OutSuc(c, "success", nil)
- return
- }
|