package handler import ( "github.com/gin-gonic/gin" "github.com/liangdas/mqant/log" "server/call" "server/common" "server/db" "server/modules/web/app" "server/modules/web/values" "server/util" "sort" "time" ) func PopUpList(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := new(values.PopUpListReq) if !a.S(req) { return } var ( isLoading bool popScene = 2 uid = a.UID channelId = a.Channel ) if loadingValue, exists := c.Get("loading"); exists { isLoading = loadingValue.(bool) } if isLoading { popScene = 1 } if req.Scene == 0 { req.Scene = 1 } resp := &values.PopUpListResp{} popUpList := call.GetConfigPopUp(popScene, channelId) rechargeInfo := call.GetRechargeInfo(uid) playerData := call.GetPlayerData(uid) for _, popUp := range popUpList { if popUp.PopScene == 1 { // 登陆前场景 resp.List = append(resp.List, *popUp) } else { // 登陆后 pass := true switch popUp.UserTag { case 0: // 全部用户 case 1: // 充值用户 if rechargeInfo.TotalRecharge <= 0 { pass = false } case 2: // 充值额度大于x用户 if rechargeInfo.TotalRecharge < int64(popUp.UserTagValueInt) { pass = false } default: log.Error("unknown popUp user-tag, %+v", *popUp) pass = false } if !pass { continue } switch popUp.PopRule { case 1: // 每日首次登陆 now := time.Now() if util.IsSameDayTimeStamp(now.Unix(), playerData.LastPopUp) { pass = false } else { err := db.Mysql().Update(&common.PlayerData{UID: uid}, map[string]interface{}{"last_pop_up": now.Unix()}) if err != nil { log.Error("update last_pop_up err, %s", err.Error()) } } case 2: // 每次启动应用 if req.Scene != 1 { pass = false } case 3: // 强制更新 case 4: // 每次返回游戏大厅 if req.Scene != 2 { pass = false } default: pass = false log.Error("unknown popUp rule, %+v", *popUp) } if !pass { continue } resp.List = append(resp.List, *popUp) } } if len(resp.List) > 0 { sort.Slice(resp.List, func(i, j int) bool { return resp.List[i].Sort > resp.List[j].Sort }) } for index, v := range resp.List { _ = index if v.Action == 10000 && v.JumpUrl != "" { // todo } } a.Data = resp }