转盘活动

dev
mofangmin 1 year ago
parent 9cc17ff8df
commit 701b9a2068
  1. 12
      call/config.go
  2. 1
      cmd/build.sh
  3. 33
      common/activity.go
  4. 3
      common/config.go
  5. 1
      modules/web/app/response.go
  6. 62
      modules/web/handler/activity.go
  7. 2
      modules/web/values/activity.go

@ -358,6 +358,18 @@ func LoadConfigPayChannels() (err error) {
return nil 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 获取代收渠道配置 // GetConfigPayChannels 获取代收渠道配置
func GetConfigPayChannels() []*common.ConfigPayChannels { func GetConfigPayChannels() []*common.ConfigPayChannels {
ret := []*common.ConfigPayChannels{} ret := []*common.ConfigPayChannels{}

@ -8,4 +8,5 @@ cd pb/proto
# go generate # go generate
cd ../.. cd ../..
#go build main.go #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 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o indiaprovider main.go

@ -1,6 +1,9 @@
package common package common
import ( import (
"database/sql/driver"
"encoding/json"
"errors"
"time" "time"
) )
@ -493,10 +496,40 @@ func (c *ActivitySuperData) TableName() string {
return "activity_super_data" 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 { type ActivityBetDrawData struct {
ID int `gorm:"primarykey"` ID int `gorm:"primarykey"`
UID int `gorm:"column:uid;not null;type:int(11);uniqueIndex:uid"` 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"` 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 { func (c *ActivityBetDrawData) TableName() string {

@ -584,6 +584,9 @@ type ConfigActivityBetDraw struct {
Cost int64 `gorm:"column:cost;type:int(11);default:0;comment:消耗幸运值" web:"cost"` Cost int64 `gorm:"column:cost;type:int(11);default:0;comment:消耗幸运值" web:"cost"`
Reward int64 `gorm:"column:reward;type:bigint(20);comment:奖励" web:"reward"` Reward int64 `gorm:"column:reward;type:bigint(20);comment:奖励" web:"reward"`
Weight int64 `gorm:"column:weight;type:bigint(20);comment:权重" web:"weight"` 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 { func (c *ConfigActivityBetDraw) TableName() string {

@ -88,7 +88,6 @@ func (g *Gin) ResponseB() {
// Response setting gin.JSON // Response setting gin.JSON
func (g *Gin) Response() { func (g *Gin) Response() {
if g.R.Code == values.CodeRetry { if g.R.Code == values.CodeRetry {
g.R.Msg = "inner error"
} else if g.R.Code == values.CodeToken { } else if g.R.Code == values.CodeToken {
g.R.Msg = "login expired" g.R.Msg = "login expired"
} }

@ -675,6 +675,7 @@ func ActivityFirstRechargeBackInfo(c *gin.Context) {
resp.ProductList = call.GetConfigPayProductByActivityID(common.ActivityIDFirstRechargeBack) resp.ProductList = call.GetConfigPayProductByActivityID(common.ActivityIDFirstRechargeBack)
resp.Recharge = data.Amount resp.Recharge = data.Amount
resp.BackPer = conf.MaxBack resp.BackPer = conf.MaxBack
resp.ChannelList = call.GetConfigPayChannelsByID(common.CurrencyINR)
if data.RechargeTime == 0 { if data.RechargeTime == 0 {
resp.CanRecharge = true resp.CanRecharge = true
return return
@ -1855,16 +1856,47 @@ func ActivityBetDrawInfo(c *gin.Context) {
db.Mysql().Create(drawInfo) db.Mysql().Create(drawInfo)
} }
} }
vipInfo := call.GetVIP(a.UID)
confList := call.GetConfigBetDraw()
resp := &values.ActivityBetDrawInfoResp{ resp := &values.ActivityBetDrawInfoResp{
List: call.GetConfigBetDraw(), List: confList,
Lucky: drawInfo.Lucky, Lucky: drawInfo.Lucky,
} }
a.Data = resp a.Data = resp
var types []int
var confs []*common.ConfigActivityBetDraw
for _, item := range resp.List { 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)) call.PushRed(a.UID, pb.RedPointModule_RedPointFreeSpin, uint32(1))
break 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) call.UploadActivityData(a.UID, common.ActivityIDBetDraw, common.ActivityDataClick, 0)
} }
@ -1881,6 +1913,7 @@ func ActivityBetDrawDraw(c *gin.Context) {
if !a.CheckActivityExpire(common.ActivityIDBetDraw) { if !a.CheckActivityExpire(common.ActivityIDBetDraw) {
return return
} }
configList, weightList := call.GetConfigBetDrawByType(req.WheelType) configList, weightList := call.GetConfigBetDrawByType(req.WheelType)
if len(configList) == 0 { if len(configList) == 0 {
a.Code = values.CodeRetry a.Code = values.CodeRetry
@ -1889,6 +1922,23 @@ func ActivityBetDrawDraw(c *gin.Context) {
conf := configList[0] conf := configList[0]
drawInfo := common.ActivityBetDrawData{UID: a.UID} drawInfo := common.ActivityBetDrawData{UID: a.UID}
db.Mysql().Get(&drawInfo) 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 { if drawInfo.Lucky < conf.Cost {
a.Code = values.CodeRetry a.Code = values.CodeRetry
a.Msg = "lucky not enough" a.Msg = "lucky not enough"
@ -1902,8 +1952,14 @@ func ActivityBetDrawDraw(c *gin.Context) {
} }
rewardConf := configList[idx] rewardConf := configList[idx]
reward := rewardConf.Reward reward := rewardConf.Reward
err := db.Mysql().Update(&drawInfo, map[string]interface{}{ 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), "lucky": gorm.Expr("lucky - ?", conf.Cost),
"spin_info": drawInfo.SpinInfo,
}) })
if err != nil { if err != nil {
a.Code = values.CodeRetry a.Code = values.CodeRetry

@ -51,6 +51,7 @@ type ActivityFirstRechargeBackInfoResp struct {
PayAmount int64 // 支付金额 PayAmount int64 // 支付金额
DrawTime int64 // 领取时间 DrawTime int64 // 领取时间
Draw bool // 是否领取 Draw bool // 是否领取
ChannelList []*common.ConfigPayChannels
ProductList []*common.ConfigPayProduct ProductList []*common.ConfigPayProduct
} }
@ -264,6 +265,7 @@ type ActivitySuperDrawResp struct {
type ActivityBetDrawInfoResp struct { type ActivityBetDrawInfoResp struct {
List []*common.ConfigActivityBetDraw // 配置 List []*common.ConfigActivityBetDraw // 配置
Lucky int64 // 幸运值 Lucky int64 // 幸运值
SpinInfo []*common.LuckyData
} }
type ActivityBetDrawDrawReq struct { type ActivityBetDrawDrawReq struct {

Loading…
Cancel
Save