diff --git a/call/config.go b/call/config.go index 6948aea..21d8a82 100644 --- a/call/config.go +++ b/call/config.go @@ -358,6 +358,18 @@ func LoadConfigPayChannels() (err error) { return nil } +// GetConfigPayChannelsByID 获取支付渠道配置 +func GetConfigPayChannelsByID(currencyType common.CurrencyType) []*common.ConfigPayChannels { + ret := []*common.ConfigPayChannels{} + for i, v := range ConfigPayChannels { + if v.PayPer <= 0 || v.CurrencyType != currencyType { + continue + } + ret = append(ret, ConfigPayChannels[i]) + } + return ret +} + // GetConfigPayChannels 获取代收渠道配置 func GetConfigPayChannels() []*common.ConfigPayChannels { ret := []*common.ConfigPayChannels{} diff --git a/cmd/build.sh b/cmd/build.sh index 4b29610..f3a9daa 100644 --- a/cmd/build.sh +++ b/cmd/build.sh @@ -8,4 +8,5 @@ cd pb/proto # go generate cd ../.. #go build main.go +#CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gameserver main.go CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o indiaprovider main.go \ No newline at end of file diff --git a/common/activity.go b/common/activity.go index 9254991..a3aaaa7 100644 --- a/common/activity.go +++ b/common/activity.go @@ -1,6 +1,9 @@ package common import ( + "database/sql/driver" + "encoding/json" + "errors" "time" ) @@ -493,10 +496,40 @@ func (c *ActivitySuperData) TableName() string { return "activity_super_data" } +type LuckyData struct { + LastSpinTime int64 + SpinNum int + NextSpinTIme int64 +} + +type SpinInfo map[int]*LuckyData + +func (m SpinInfo) Value() (driver.Value, error) { + return json.Marshal(m) +} + +func (m *SpinInfo) Scan(value interface{}) error { + if value == nil { + *m = SpinInfo{} + return nil + } + // 将数据库中的 JSON 字符串解析为 map + bytes, ok := value.([]byte) + if !ok { + return errors.New("type assertion to []byte failed") + } + if len(bytes) == 0 { + *m = SpinInfo{} + return nil + } + return json.Unmarshal(bytes, &m) +} + type ActivityBetDrawData struct { - ID int `gorm:"primarykey"` - UID int `gorm:"column:uid;not null;type:int(11);uniqueIndex:uid"` - Lucky int64 `gorm:"column:lucky;;not null;type:bigint(20);comment:幸运值" web:"lucky"` + ID int `gorm:"primarykey"` + UID int `gorm:"column:uid;not null;type:int(11);uniqueIndex:uid"` + Lucky int64 `gorm:"column:lucky;;not null;type:bigint(20);comment:幸运值" web:"lucky"` + SpinInfo SpinInfo `gorm:"column:spin_info;;not null;type:varchar(256);comment:转盘信息" web:"spinInfo"` } func (c *ActivityBetDrawData) TableName() string { diff --git a/common/config.go b/common/config.go index dde4b84..c8bb998 100644 --- a/common/config.go +++ b/common/config.go @@ -579,11 +579,14 @@ func (c *ConfigTgRobot) TableName() string { } type ConfigActivityBetDraw struct { - ID int `gorm:"primarykey"` - Type int `gorm:"column:type;type:int(11);default:0;comment:转盘类型" web:"type"` - Cost int64 `gorm:"column:cost;type:int(11);default:0;comment:消耗幸运值" web:"cost"` - Reward int64 `gorm:"column:reward;type:bigint(20);comment:奖励" web:"reward"` - Weight int64 `gorm:"column:weight;type:bigint(20);comment:权重" web:"weight"` + ID int `gorm:"primarykey"` + Type int `gorm:"column:type;type:int(11);default:0;comment:转盘类型" web:"type"` + Cost int64 `gorm:"column:cost;type:int(11);default:0;comment:消耗幸运值" web:"cost"` + Reward int64 `gorm:"column:reward;type:bigint(20);comment:奖励" web:"reward"` + Weight int64 `gorm:"column:weight;type:bigint(20);comment:权重" web:"weight"` + VipUnlock int `gorm:"column:vip_unlock;type:int(11);comment:vip解锁等级" web:"vipUnlock"` + Cd int64 `gorm:"column:cd;type:bigint(20);comment:冷却时间" web:"cd"` + LimitNum int `gorm:"column:limit_num;type:int(11);comment:每日领取次数" web:"limitNum"` } func (c *ConfigActivityBetDraw) TableName() string { diff --git a/modules/web/app/response.go b/modules/web/app/response.go index 2a3aa3a..778de1b 100644 --- a/modules/web/app/response.go +++ b/modules/web/app/response.go @@ -88,7 +88,6 @@ func (g *Gin) ResponseB() { // Response setting gin.JSON func (g *Gin) Response() { if g.R.Code == values.CodeRetry { - g.R.Msg = "inner error" } else if g.R.Code == values.CodeToken { g.R.Msg = "login expired" } diff --git a/modules/web/handler/activity.go b/modules/web/handler/activity.go index c045b7d..b68cf3b 100644 --- a/modules/web/handler/activity.go +++ b/modules/web/handler/activity.go @@ -675,6 +675,7 @@ func ActivityFirstRechargeBackInfo(c *gin.Context) { resp.ProductList = call.GetConfigPayProductByActivityID(common.ActivityIDFirstRechargeBack) resp.Recharge = data.Amount resp.BackPer = conf.MaxBack + resp.ChannelList = call.GetConfigPayChannelsByID(common.CurrencyINR) if data.RechargeTime == 0 { resp.CanRecharge = true return @@ -1855,16 +1856,47 @@ func ActivityBetDrawInfo(c *gin.Context) { db.Mysql().Create(drawInfo) } } + vipInfo := call.GetVIP(a.UID) + confList := call.GetConfigBetDraw() resp := &values.ActivityBetDrawInfoResp{ - List: call.GetConfigBetDraw(), + List: confList, Lucky: drawInfo.Lucky, } a.Data = resp + var types []int + var confs []*common.ConfigActivityBetDraw for _, item := range resp.List { - if resp.Lucky >= item.Cost { + if resp.Lucky >= item.Cost && vipInfo.Level >= item.VipUnlock { call.PushRed(a.UID, pb.RedPointModule_RedPointFreeSpin, uint32(1)) break } + if !util.SliceContain(types, item.Type) { + types = append(types, item.Type) + confs = append(confs, item) + } + } + now := time.Now() + update := false + for _, item := range confs { + typ := item.Type + spinInfo := drawInfo.SpinInfo[typ] + if spinInfo == nil { + drawInfo.SpinInfo[typ] = &common.LuckyData{} + spinInfo = drawInfo.SpinInfo[typ] + } + if !util.IsSameDayTimeStamp(spinInfo.LastSpinTime, now.Unix()) { + spinInfo.SpinNum = 0 + update = true + } + resp.SpinInfo = append(resp.SpinInfo, &common.LuckyData{ + SpinNum: spinInfo.SpinNum, + NextSpinTIme: spinInfo.NextSpinTIme, + }) + } + if update && a.UID > 0 { + db.Mysql().Update(&common.ActivityBetDrawData{UID: a.UID}, map[string]interface{}{ + "spin_info": drawInfo.SpinInfo, + }) } call.UploadActivityData(a.UID, common.ActivityIDBetDraw, common.ActivityDataClick, 0) } @@ -1881,6 +1913,7 @@ func ActivityBetDrawDraw(c *gin.Context) { if !a.CheckActivityExpire(common.ActivityIDBetDraw) { return } + configList, weightList := call.GetConfigBetDrawByType(req.WheelType) if len(configList) == 0 { a.Code = values.CodeRetry @@ -1889,6 +1922,23 @@ func ActivityBetDrawDraw(c *gin.Context) { conf := configList[0] drawInfo := common.ActivityBetDrawData{UID: a.UID} db.Mysql().Get(&drawInfo) + now := time.Now() + spinInfo, ok := drawInfo.SpinInfo[req.WheelType] + if !ok { + drawInfo.SpinInfo[req.WheelType] = &common.LuckyData{} + spinInfo = drawInfo.SpinInfo[req.WheelType] + } + // step:判断cd + if spinInfo.LastSpinTime != 0 && now.Unix()-spinInfo.LastSpinTime < conf.Cd { + a.Code = values.CodeRetry + a.Msg = "Unarrived spin time" + return + } + if spinInfo.SpinNum >= conf.LimitNum { + a.Code = values.CodeRetry + a.Msg = "No spin times" + return + } if drawInfo.Lucky < conf.Cost { a.Code = values.CodeRetry a.Msg = "lucky not enough" @@ -1902,8 +1952,14 @@ func ActivityBetDrawDraw(c *gin.Context) { } rewardConf := configList[idx] reward := rewardConf.Reward - err := db.Mysql().Update(&drawInfo, map[string]interface{}{ - "lucky": gorm.Expr("lucky - ?", conf.Cost), + spinInfo.LastSpinTime = time.Now().Unix() + spinInfo.SpinNum += 1 + spinInfo.NextSpinTIme = spinInfo.LastSpinTime + conf.Cd + err := db.Mysql().Update(&common.ActivityBetDrawData{ + UID: a.UID, + }, map[string]interface{}{ + "lucky": gorm.Expr("lucky - ?", conf.Cost), + "spin_info": drawInfo.SpinInfo, }) if err != nil { a.Code = values.CodeRetry diff --git a/modules/web/values/activity.go b/modules/web/values/activity.go index 02021a4..14262ba 100644 --- a/modules/web/values/activity.go +++ b/modules/web/values/activity.go @@ -51,6 +51,7 @@ type ActivityFirstRechargeBackInfoResp struct { PayAmount int64 // 支付金额 DrawTime int64 // 领取时间 Draw bool // 是否领取 + ChannelList []*common.ConfigPayChannels ProductList []*common.ConfigPayProduct } @@ -262,8 +263,9 @@ type ActivitySuperDrawResp struct { } type ActivityBetDrawInfoResp struct { - List []*common.ConfigActivityBetDraw // 配置 - Lucky int64 // 幸运值 + List []*common.ConfigActivityBetDraw // 配置 + Lucky int64 // 幸运值 + SpinInfo []*common.LuckyData } type ActivityBetDrawDrawReq struct {