package handler import ( "context" "errors" "fmt" "server/call" "server/common" "server/db" "server/modules/web/app" "server/modules/web/values" "server/util" "strings" "time" "github.com/gin-gonic/gin" "github.com/go-redis/redis/v8" "github.com/liangdas/mqant/log" "github.com/olivere/elastic/v7" ) func FirstPage(c *gin.Context) { a := app.NewApp(c) defer func() { a.Response() }() req := new(values.FirstPageReq) if !a.S(req) { return } uuid := a.UUID cid := a.Channel if len(uuid) > 0 { // 处理一下新增安装 util.Go(func() { q := elastic.NewBoolQuery() q.Filter(elastic.NewTermsQuery("UUID.keyword", uuid)) q.Filter(elastic.NewTermQuery("Channel", cid)) if db.ES().Count(common.ESIndexBackOpenRecord, q) > 0 { return } id := fmt.Sprintf("%v_%v", cid, uuid) db.ES().InsertToESByIDGO(common.ESIndexBackOpenRecord, id, &common.ESOpenRecord{Time: time.Now().Unix(), UUID: uuid, Channel: cid}) }) } resp := &values.FirstPageResp{} a.Data = resp a.GetUID() resp.Activitys = call.GetConfigBanner(a.UID) resp.GameTypes = call.GetConfigGameTypes() resp.GameMarks = call.GetConfigGameMarks() resp.Providers = call.GetConfigGameProviderAllOpen() games := call.GetConfigFirstPageGames() for _, v := range games { one := values.OneFisrtPageGame{ ConfigFirstPageGames: v, List: make([]*common.ConfigGameList, 0), } if v.Name == "Recent" { one.List = append(one.List, call.GetGameRecord(a.UID)...) } else if v.Name == "Favorite" { one.List = append(one.List, call.GetPlayerFavoriteList(a.UID)...) } else { if v.JumpType == 1 { one.List = call.GetConfigGameList(req.GameNum, v.JumpID) } else { one.List = call.GetConfigGameList(req.GameNum, 0, v.JumpID) } } call.GetGameInfo(one.List) resp.Games = append(resp.Games, one) } for i := common.CurrencyTypeZero + 1; i < common.CurrencyAll; i++ { if i == common.CurrencyUSDT { continue } resp.Currencys = append(resp.Currencys, values.OneCurrency{ ID: i, Name: strings.ToUpper(i.GetCurrencyName()), }) } list := call.GetConfigGameListByType(common.GameTypeSportBook) if len(list) > 0 { resp.Esport = list[0] } // task := call.GetConfigTaskByTaskType(common.TaskTypeDownload) // if len(task) > 0 { // resp.DownloadAppReward = task[0].Reward // } resp.ShowData = GetFirstShowData() } // GetFirstShowData 首页展示数据 func GetFirstShowData() values.ShowInfo { ctx := context.Background() // step: 平均提现时长 now := time.Now() currentHour := now.Format("2006-01-02-15") // 年-月-日-小时 rdb := db.Redis().GetRedis() pipeline := db.Redis().GetRedis().Pipeline() keyPrefix := "firstpage:showdata:" // 使用哈希存储平均提现时长 key := keyPrefix + "average_withdrawal_time:" + currentHour averageWithdrawalTime, err := rdb.HGet(ctx, key, "value").Int64() if errors.Is(err, redis.Nil) { averageWithdrawalTime = util.RandBetween64(15, 30) // 15-30之间 pipeline.HSet(ctx, key, "value", averageWithdrawalTime) pipeline.Expire(ctx, key, time.Hour) // 设置过期时间为1小时 } // step: 今日平台提现总额 withdrawalKey := keyPrefix + "withdrawal_info" startTime, err := rdb.HGet(ctx, withdrawalKey, "start_time").Time() withdrawal := int64(999*10 + 1000) if err != nil || now.Day() != startTime.Day() { startTime = now pipeline.HSet(ctx, withdrawalKey, "start_time", startTime) pipeline.HSet(ctx, withdrawalKey, "total_withdrawal", withdrawal) } else { elapsed := int(now.Sub(startTime).Hours()) withdrawal += int64(elapsed * (999*10 + 1000)) pipeline.HSet(ctx, withdrawalKey, "total_withdrawal", withdrawal) } // step: 当前累计奖金 bonusKey := keyPrefix + "bonus_info" totalBonus, err := rdb.HGet(ctx, bonusKey, "total_bonus").Int64() if errors.Is(err, redis.Nil) { totalBonus = 1549661 pipeline.HSet(ctx, bonusKey, "total_bonus", totalBonus) pipeline.HSet(ctx, bonusKey, "last_bonus_update_time", now) } else { lastUpdate, _ := rdb.HGet(ctx, bonusKey, "last_bonus_update_time").Time() intervals := (now.Unix() - lastUpdate.Unix()) / 10 totalBonus += util.RandBetween64(10, 2000) * intervals pipeline.HSet(ctx, bonusKey, "total_bonus", totalBonus) pipeline.HSet(ctx, bonusKey, "last_bonus_update_time", now) } // step: 下注总额 maxBetKey := keyPrefix + "max_bet_info" maxBetStartTime, err := rdb.HGet(ctx, maxBetKey, "start_time").Time() maxBet := int64(500) if err != nil || now.Sub(maxBetStartTime) > 24*time.Hour { maxBetStartTime = now pipeline.HSet(ctx, maxBetKey, "start_time", maxBetStartTime) pipeline.HSet(ctx, maxBetKey, "max_bet_amount", maxBet) } else { elapsed := now.Sub(startTime).Minutes() / 10 maxBet += int64(500 * elapsed * 3) pipeline.HSet(ctx, maxBetKey, "max_bet_amount", maxBet) } // 执行Pipeline _, err = pipeline.Exec(ctx) if err != nil { log.Error("Pipeline exec error: %v", err) } // 返回结果 return values.ShowInfo{ AverWithdraw: averageWithdrawalTime, WithdrawCount: withdrawal, Reward: totalBonus * 100, MaxBet: maxBet * 100, } }