|
- 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"
- "fmt"
- "github.com/gin-gonic/gin"
- "strings"
- )
-
- func List(c *gin.Context) {
- var req *md.AdvertisingListReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var resp md.AdvertisingListResp
- noticeList := make([]md.AdvertisingList, 0)
- resp.AdvData = []map[string]string{
- {"name": "开屏广告", "value": "1"},
- {"name": "插屏广告", "value": "2"},
- {"name": "激励视频", "value": "3"},
- {"name": "信息流广告", "value": "4"},
- {"name": "全屏视频", "value": "5"},
- }
- resp.SelectData = md.AdvertisingPlatform
- NewJpushNoticeDb := implement.NewAdvertisingSpaceDb(db.Db)
- notice, total, _ := NewJpushNoticeDb.FindUserFeedbackCateAndTotal(req.Page, req.Limit, req.Name, req.Kind)
- resp.Total = total
- if notice != nil {
- for _, v := range *notice {
- tmp := md.AdvertisingList{
- Id: utils.IntToStr(v.Id),
- CountingDown: utils.IntToStr(v.CountingDown),
- Kind: utils.IntToStr(v.Kind),
- Info: v.Info,
- Name: v.Name,
- }
- noticeList = append(noticeList, tmp)
- }
- }
- resp.List = noticeList
- e.OutSuc(c, resp, nil)
- return
- }
- func VisitList(c *gin.Context) {
- var req *md.AdvertisingVisitListReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var resp md.AdvertisingVisitListResp
- noticeList := make([]md.AdvertisingVisitList, 0)
- resp.TypeData = md.AdvertisingType
- resp.PlatformData = md.AdvertisingPlatform
- uid := req.Uid
- if req.Phone != "" {
- userDb := implement.NewUserDb(db.Db)
- user, err := userDb.UserGetOneByParams(map[string]interface{}{
- "key": "phone",
- "value": req.Phone,
- })
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if user != nil {
- uid = utils.Int64ToStr(user.Id)
- }
- }
- req.Platform = strings.ReplaceAll(req.Platform, " ", "")
- req.Type = strings.ReplaceAll(req.Type, " ", "")
- notice := FindAdvertisingCallback(req.Page, req.Limit, req.Amount, uid, req.StartTime, req.EndTime, req.Platform, req.Type)
- resp.Total = FindAdvertisingCallbackAndTotal(req.Page, req.Limit, req.Amount, uid, req.StartTime, req.EndTime, req.Platform, req.Type)
- if notice != nil {
- for _, v := range notice {
- userDb := implement.NewUserDb(db.Db)
- users, _ := userDb.UserGetOneByParams(map[string]interface{}{
- "key": "id",
- "value": v["uid"],
- })
- phone := ""
- if users != nil {
- phone = users.Phone
- }
- tmp := md.AdvertisingVisitList{
- Id: v["id"],
- Uid: v["uid"],
- Phone: phone,
- Ecpm: v["amount"],
- CustomEcpm: v["custom_ecpm"],
- Integral: v["integral"],
- Platform: v["platform"],
- PhonePlatform: v["phone_platform"],
- Type: v["type"],
- Time: v["create_at"],
- }
- noticeList = append(noticeList, tmp)
- }
- }
- resp.List = noticeList
- e.OutSuc(c, resp, nil)
- return
- }
- func FindAdvertisingCallback(page, limit, amount, uid, startTime, endTime, platform, types string) []map[string]string {
- sql := `SELECT * FROM advertising_callback where %s order by id desc %s`
- where := "1=1"
- if amount != "" {
- where += " and CONVERT(amount, FLOAT)<=" + amount
- }
- if uid != "" {
- where += " and uid=" + uid
- }
- if platform != "" {
- where += " and platform='" + platform + "'"
- }
- if types != "" {
- where += " and type='" + types + "'"
- }
- if startTime != "" {
- where += " and create_at>='" + startTime + "'"
- }
- if endTime != "" {
- where += " and create_at<='" + endTime + "'"
- }
- start := (utils.StrToInt(page) - 1) * utils.StrToInt(limit)
- limits := " limit " + utils.IntToStr(start) + "," + limit
- sql = fmt.Sprintf(sql, where, limits)
- nativeString, _ := db.QueryNativeString(db.Db, sql)
- return nativeString
- }
- func FindAdvertisingCallbackAndTotal(page, limit, amount, uid, startTime, endTime, platform, types string) int64 {
- sql := `SELECT COUNT(*) as count FROM advertising_callback where %s`
- where := "1=1"
- if amount != "" {
- where += " and CONVERT(amount, FLOAT)<=" + amount
- }
- if uid != "" {
- where += " and uid=" + uid
- }
- if platform != "" {
- where += " and platform='" + platform + "'"
- }
- if types != "" {
- where += " and type='" + types + "'"
- }
- if startTime != "" {
- where += " and create_at>='" + startTime + "'"
- }
- if endTime != "" {
- where += " and create_at<='" + endTime + "'"
- }
- sql = fmt.Sprintf(sql, where)
- nativeString, _ := db.QueryNativeString(db.Db, sql)
- count := "0"
- if len(nativeString) > 0 {
- count = nativeString[0]["count"]
- }
- return utils.StrToInt64(count)
- }
- func Del(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.AdvertisingSpace{})
- e.OutSuc(c, "success", nil)
- return
- }
- func Save(c *gin.Context) {
- var req *md.AdvertisingSaveReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var data = new(model.AdvertisingSpace)
- if utils.StrToInt(req.Id) > 0 {
- NewAdvertisingSpaceDb := implement.NewAdvertisingSpaceDb(db.Db)
- space, _ := NewAdvertisingSpaceDb.GetAdvertisingSpace(req.Id)
- if space == nil {
- e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
- return
- }
- data = space
- } else {
- db.Db.Insert(data)
- }
- data.Name = req.Name
- data.Info = req.Info
- data.Kind = utils.StrToInt(req.Kind)
- data.CountingDown = utils.StrToInt(req.CountingDown)
- db.Db.Where("id=?", data.Id).Update(data)
- e.OutSuc(c, "success", nil)
- return
- }
|