|
|
|
|
package call
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"server/common"
|
|
|
|
|
"server/db"
|
|
|
|
|
"server/util"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
|
|
|
"github.com/liangdas/mqant/log"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func UpdateJackpot(t, tid int, amount int64) {
|
|
|
|
|
if err := db.Mysql().C().Exec(fmt.Sprintf("call jackpot(%v,%v,%v)", t, tid, amount)).Error; err != nil {
|
|
|
|
|
log.Error("err:%v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetJackpot(t, tid int) int64 {
|
|
|
|
|
data := &common.Jackpot{Type: t, TypeID: tid}
|
|
|
|
|
db.Mysql().Get(data)
|
|
|
|
|
return data.Amount
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetJack(t, tid int) *common.Jackpot {
|
|
|
|
|
data := &common.Jackpot{Type: t, TypeID: tid}
|
|
|
|
|
db.Mysql().Get(data)
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func UpdateGameJackpot(t, tid int, amount, playerAmount int64) {
|
|
|
|
|
jack := GetJack(t, tid)
|
|
|
|
|
u := map[string]interface{}{"player_amount": gorm.Expr("player_amount + ?", playerAmount)}
|
|
|
|
|
if jack.Amount+amount >= jack.Max {
|
|
|
|
|
u["amnout"] = jack.Max
|
|
|
|
|
} else {
|
|
|
|
|
u["amount"] = gorm.Expr("amount + ?", amount)
|
|
|
|
|
}
|
|
|
|
|
db.Mysql().Update(&common.Jackpot{Type: t, TypeID: tid}, u)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func UpdateGameSort(provider, gameID int) {
|
|
|
|
|
util.Go(func() {
|
|
|
|
|
db.Mysql().Update(&common.ConfigGameList{GameProvider: provider, GameID: gameID}, map[string]interface{}{"sort": gorm.Expr("sort + 1")})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetGameInfo 获取游戏信息
|
|
|
|
|
func GetGameInfo(gameInfos []*common.ConfigGameList) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
rdb := db.Redis().GetRedis()
|
|
|
|
|
pipeline := rdb.Pipeline()
|
|
|
|
|
maxRewardField := "maxReward"
|
|
|
|
|
rtpField := "rtp"
|
|
|
|
|
maxRewardTimeField := "maxRewardTime"
|
|
|
|
|
for _, game := range gameInfos {
|
|
|
|
|
key := fmt.Sprintf("firstpage:games:%d_%d", game.GameProvider, game.GameID)
|
|
|
|
|
pipeline.HGet(ctx, key, maxRewardField)
|
|
|
|
|
pipeline.HGet(ctx, key, maxRewardTimeField)
|
|
|
|
|
pipeline.HGet(ctx, key, rtpField)
|
|
|
|
|
}
|
|
|
|
|
cmds, err := pipeline.Exec(ctx)
|
|
|
|
|
now := time.Now()
|
|
|
|
|
for i := 0; i < 2*len(gameInfos); i = i + 2 {
|
|
|
|
|
game := gameInfos[i/2]
|
|
|
|
|
maxRewardCmd := cmds[i]
|
|
|
|
|
maxRewardTimeCmd := cmds[i+1]
|
|
|
|
|
key := fmt.Sprintf("firstpage:games:%d_%d", game.GameProvider, game.GameID)
|
|
|
|
|
game.MaxReward, err = maxRewardCmd.(*redis.StringCmd).Int64()
|
|
|
|
|
if errors.Is(err, redis.Nil) {
|
|
|
|
|
val := util.RandBetween64(100, 9999)
|
|
|
|
|
rtp := util.RandBetween64(93, 104)
|
|
|
|
|
game.RTP = rtp
|
|
|
|
|
game.MaxReward = val
|
|
|
|
|
pipeline.HSet(ctx, key, maxRewardField, val, maxRewardTimeField, time.Now(), rtpField, rtp)
|
|
|
|
|
} else {
|
|
|
|
|
maxRewardTime, _ := maxRewardTimeCmd.(*redis.StringCmd).Time()
|
|
|
|
|
if now.Sub(maxRewardTime).Hours() >= 1 {
|
|
|
|
|
val := util.RandBetween64(game.MaxReward, 9999)
|
|
|
|
|
rtp := util.RandBetween64(93, 104)
|
|
|
|
|
game.RTP = rtp
|
|
|
|
|
game.MaxReward = val
|
|
|
|
|
pipeline.HSet(ctx, key, maxRewardField, val, maxRewardTimeField, time.Now(), rtpField, rtp)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_, err = pipeline.Exec(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error("GetGameInfo err:%v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|