|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package advertising
-
- 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"
- )
-
- func FunctionList(c *gin.Context) {
- var req *md.AdvertisingFunctionListReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var resp md.AdvertisingFunctionListResp
- noticeList := make([]md.AdvertisingFunctionList, 0)
- resp.SelectData = []map[string]string{
- {"name": "首页砸蛋", "value": "egg"},
- {"name": "首页签到", "value": "egg_sign"},
- }
- NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db)
- adv, _, _ := NewAdvertisingSpaceDb.FindUserFeedbackCateAndTotal("1", "1000", "", "3")
- advList := make([]map[string]string, 0)
- if adv != nil {
- for _, v := range *adv {
- tmp := map[string]string{
- "name": v.Name,
- "value": utils.IntToStr(v.Id),
- }
- advList = append(advList, tmp)
- }
- }
- resp.AdvData = advList
- NewJpushNoticeDb := implement.NewAdvertisingFunctionDb(db.Db)
- notice, total, _ := NewJpushNoticeDb.FindUserFeedbackFunctionAndTotal(req.Page, req.Limit)
- resp.Total = total
- if notice != nil {
- for _, v := range *notice {
- tmp := md.AdvertisingFunctionList{
- Id: utils.Int64ToStr(v.Id),
- AdId: utils.IntToStr(v.AdId),
- Type: v.Type,
- }
- noticeList = append(noticeList, tmp)
- }
- }
- resp.List = noticeList
- e.OutSuc(c, resp, nil)
- return
- }
- func FunctionDel(c *gin.Context) {
- var req *md.ArticleCateDelReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- db.Db.In("id", req.Id).Delete(&model.AdvertisingFunction{})
- e.OutSuc(c, "success", nil)
- return
- }
- func FunctionSave(c *gin.Context) {
- var req *md.AdvertisingFunctionList
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var data = new(model.AdvertisingFunction)
- if utils.StrToInt(req.Id) > 0 {
- NewAdvertisingSpaceDb := implement.NewAdvertisingFunctionDb(db.Db)
- space, _ := NewAdvertisingSpaceDb.GetAdvertisingFunction(req.Id)
- if space == nil {
- e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
- return
- }
- data = space
- } else {
- db.Db.Insert(data)
- }
- data.Type = req.Type
- data.AdId = utils.StrToInt(req.AdId)
- db.Db.Where("id=?", data.Id).Update(data)
- e.OutSuc(c, "success", nil)
- return
- }
|