|
|
package handler |
|
|
|
|
|
import ( |
|
|
"fmt" |
|
|
"math/rand" |
|
|
"server/call" |
|
|
"server/common" |
|
|
"server/config" |
|
|
"server/db" |
|
|
"server/modules/web/app" |
|
|
"server/modules/web/values" |
|
|
"server/util" |
|
|
"time" |
|
|
|
|
|
"github.com/gin-gonic/gin" |
|
|
"github.com/liangdas/mqant/log" |
|
|
"github.com/olivere/elastic/v7" |
|
|
"gorm.io/gorm" |
|
|
) |
|
|
|
|
|
func GetPromotions(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
ret := &values.GetPromotionsResp{} |
|
|
a.Data = ret |
|
|
a.GetUID() |
|
|
ret.ActivityList = call.GetConfigActivityActiveAll(a.UID) |
|
|
ret.TaskList = a.GetUserTaskStatus() |
|
|
} |
|
|
|
|
|
func UploadActivityData(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
req := new(values.UploadActivityReq) |
|
|
if !a.S(req) { |
|
|
return |
|
|
} |
|
|
call.UploadActivityData(a.UID, req.ActivityID, common.ActivityDataClick, 0) |
|
|
} |
|
|
|
|
|
func GetAllActivity(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
ret := values.GetAllActivityResp{ |
|
|
List: call.GetConfigActivityActiveAll(a.UID), |
|
|
} |
|
|
a.Data = ret |
|
|
} |
|
|
|
|
|
func GetActivityAppSpinInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDAppSpin) { |
|
|
return |
|
|
} |
|
|
resp := &values.ActivityAppSpinInfoResp{} |
|
|
a.Data = resp |
|
|
resp.List = call.GetConfigAppSpin() |
|
|
} |
|
|
|
|
|
func DrawActivityAppSpin(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDAppSpin) { |
|
|
return |
|
|
} |
|
|
pd := call.GetPlayerData(a.UID) |
|
|
if pd.LastAppSpinDraw > 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
total := 0 |
|
|
list := call.GetConfigAppSpin() |
|
|
for _, v := range list { |
|
|
total += v.Weight |
|
|
} |
|
|
weight := rand.Intn(total) |
|
|
per := 0 |
|
|
var win *common.ConfigAppSpin |
|
|
for _, v := range list { |
|
|
per += v.Weight |
|
|
if weight < per { |
|
|
win = v |
|
|
break |
|
|
} |
|
|
} |
|
|
if win == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
rows, err := db.Mysql().UpdateResW(&common.PlayerData{}, map[string]interface{}{"last_app_spin_draw": time.Now().Unix()}, fmt.Sprintf("uid = %v and last_app_spin_draw = 0", a.UID)) |
|
|
if err != nil || rows == 0 { |
|
|
log.Error("err:%v", err) |
|
|
return |
|
|
} |
|
|
call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
ChannelID: a.Channel, |
|
|
Type: win.CurrencyType, |
|
|
Value: win.Amount, |
|
|
Event: common.CurrencyEventActivityAppSpin, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, win.Amount), |
|
|
}, |
|
|
}) |
|
|
call.UploadActivityData(a.UID, common.ActivityIDAppSpin, common.ActivityDataJoin, win.Amount) |
|
|
a.Data = values.ActivityAppSpinDrawResp{ID: win.ID} |
|
|
} |
|
|
|
|
|
func ActivityPddInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDPDD) { |
|
|
return |
|
|
} |
|
|
con := call.GetConfigActivityPdd() |
|
|
if con == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
resp := &values.ActivityPddInfoResp{WithdrawAmount: con.WithdrawAmount, Spin: 1} |
|
|
a.GetUID() |
|
|
pddData := &common.PddData{UID: a.UID} |
|
|
if pddData.UID > 0 { |
|
|
pddData = call.GetAcitivityPddData(pddData.UID) |
|
|
if pddData == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
resp.Spin = pddData.Spin |
|
|
resp.Amount = pddData.Amount |
|
|
channel := call.GetChannelByID(a.Channel) |
|
|
if channel != nil { |
|
|
resp.ShareLink = channel.URL + "?code=" + call.GetShareInfo(a.UID).Share |
|
|
} |
|
|
resp.Expire = con.Expire*60 + pddData.Time - time.Now().Unix() |
|
|
resp.NewPddShare = call.HasNewAcitivityPddShare(a.UID) |
|
|
} |
|
|
|
|
|
list := call.GetConfigActivityPddSpinByAmount(pddData.Amount) |
|
|
for _, v := range list { |
|
|
resp.Items = append(resp.Items, values.OnePddSpinItem{ |
|
|
ID: v.ID, |
|
|
Type: v.Type, |
|
|
Amount: v.Amount, |
|
|
Sort: v.Sort, |
|
|
}) |
|
|
} |
|
|
a.Data = resp |
|
|
} |
|
|
|
|
|
func ActivityPddSpin(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDPDD) { |
|
|
return |
|
|
} |
|
|
con := call.GetConfigActivityPdd() |
|
|
if con == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
pddData := call.GetAcitivityPddData(a.UID) |
|
|
if pddData == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
now := time.Now().Unix() |
|
|
todaySpin := util.IsSameDayTimeStamp(now, pddData.FreeSpinTime) |
|
|
if pddData.Spin <= 0 { |
|
|
a.Code = values.CodeParam |
|
|
return |
|
|
} |
|
|
if pddData.Amount >= con.WithdrawAmount { |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "You can withdraw now." |
|
|
return |
|
|
} |
|
|
items := call.GetConfigActivityPddSpinByAmount(pddData.Amount) |
|
|
var bingo *common.ConfigActivityPddSpin |
|
|
var amount int64 |
|
|
if pddData.Amount == 0 { // 第一次转 |
|
|
for _, v := range items { |
|
|
if v.Type == common.ActivityPddItemTypeRandomCash { |
|
|
bingo = v |
|
|
break |
|
|
} |
|
|
} |
|
|
|
|
|
if bingo == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
|
|
|
diff := con.AmountUp - con.AmountDown |
|
|
if diff > 0 { |
|
|
amount = rand.Int63n(con.AmountUp-con.AmountDown) + con.AmountDown |
|
|
} |
|
|
} else { |
|
|
totalWeight := 0 |
|
|
for _, v := range items { |
|
|
totalWeight += v.Weight |
|
|
} |
|
|
if totalWeight == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
|
|
|
thisWeight := 0 |
|
|
rans := rand.Intn(totalWeight) |
|
|
for _, v := range items { |
|
|
thisWeight += v.Weight |
|
|
if rans < thisWeight { |
|
|
bingo = v |
|
|
break |
|
|
} |
|
|
} |
|
|
if bingo == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
|
|
|
amount = bingo.Amount |
|
|
if bingo.Type == common.ActivityPddItemTypeRandomCash { |
|
|
diff := bingo.CashUp - bingo.CashDown |
|
|
if diff > 0 { |
|
|
amount = rand.Int63n(diff) + bingo.CashDown |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if amount == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
|
|
|
update := map[string]interface{}{} |
|
|
sql := "" |
|
|
// 今天旋转过则扣除已有旋转次数 |
|
|
if todaySpin { |
|
|
update["spin"] = gorm.Expr("spin - 1") |
|
|
sql = fmt.Sprintf("uid = %d and spin >= 1 and amount = %d", a.UID, pddData.Amount) |
|
|
} else { |
|
|
update["free_spin_time"] = now |
|
|
sql = fmt.Sprintf("uid = %d and free_spin_time = %d ", a.UID, pddData.FreeSpinTime) |
|
|
} |
|
|
|
|
|
// ok |
|
|
switch bingo.Type { |
|
|
case common.ActivityPddItemTypeFinish: |
|
|
update["amount"] = con.WithdrawAmount |
|
|
case common.ActivityPddItemTypeCash: |
|
|
if pddData.Amount+amount > con.WithdrawAmount { |
|
|
update["amount"] = con.WithdrawAmount |
|
|
} else { |
|
|
update["amount"] = gorm.Expr("amount + ?", amount) |
|
|
} |
|
|
case common.ActivityPddItemTypeRandomCash: |
|
|
if pddData.Amount+amount > con.WithdrawAmount { |
|
|
update["amount"] = con.WithdrawAmount |
|
|
} else { |
|
|
update["amount"] = gorm.Expr("amount + ?", amount) |
|
|
} |
|
|
} |
|
|
|
|
|
rows, err := db.Mysql().UpdateResW(&common.PddData{}, update, sql) |
|
|
if err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
if rows == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
resp := &values.ActivityPddSpinResp{ |
|
|
ID: bingo.Sort, |
|
|
Amount: amount, |
|
|
} |
|
|
a.Data = resp |
|
|
} |
|
|
|
|
|
func ActivityPddWithdraw(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDPDD) { |
|
|
return |
|
|
} |
|
|
con := call.GetConfigActivityPdd() |
|
|
if con == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
pddData := call.GetAcitivityPddData(a.UID) |
|
|
if pddData == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
if pddData.Amount < con.WithdrawAmount { |
|
|
a.Code = values.CodeParam |
|
|
return |
|
|
} |
|
|
// 转走并重置玩家pdd活动 |
|
|
spinCount := 1 |
|
|
if !config.GetBase().Release { |
|
|
spinCount = 100 |
|
|
} |
|
|
rows, err := db.Mysql().UpdateResW(&common.PddData{}, map[string]interface{}{"amount": 0, "spin": spinCount, "time": time.Now().Unix(), "free_spin_time": 0}, |
|
|
fmt.Sprintf("uid = %d and amount >= %d", a.UID, con.WithdrawAmount)) |
|
|
if err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
if rows == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
Value: con.WithdrawAmount, |
|
|
Type: common.CurrencyINR, |
|
|
Event: common.CurrencyEventActivityPdd, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, con.WithdrawAmount), |
|
|
}, |
|
|
}) |
|
|
call.UploadActivityData(a.UID, common.ActivityIDPDD, common.ActivityDataJoin, con.WithdrawAmount) |
|
|
a.Data = values.ActivityPddWithdrawResp{ExpireTime: con.Expire * 60} |
|
|
} |
|
|
|
|
|
func ActivityPddNewReference(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDPDD) { |
|
|
return |
|
|
} |
|
|
con := call.GetConfigActivityPdd() |
|
|
if con == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
resp := &values.ActivityPddNewReferenceResp{} |
|
|
a.Data = resp |
|
|
pddData := call.GetAcitivityPddData(a.UID) |
|
|
if pddData == nil { |
|
|
return |
|
|
} |
|
|
list := []common.ESPddRecord{} |
|
|
q := elastic.NewBoolQuery() |
|
|
t := pddData.Time |
|
|
if pddData.NewRecordTime > 0 { |
|
|
t = pddData.NewRecordTime |
|
|
} |
|
|
q.Filter(elastic.NewTermQuery("Referer", a.UID)) |
|
|
q.Filter(elastic.NewRangeQuery("Time").Gte(t)) |
|
|
db.ES().QueryList(common.ESIndexBackPddRecord, 0, 5000, q, &list, "Time", false) |
|
|
for _, v := range list { |
|
|
resp.List = append(resp.List, values.OnePddRecord{ |
|
|
UID: v.UID, |
|
|
Avatar: v.Avatar, |
|
|
Nick: v.Nick, |
|
|
Time: v.Time, |
|
|
SpinCount: 1, |
|
|
}) |
|
|
} |
|
|
resp.NewCount = len(list) |
|
|
resp.NewSpinCount = len(list) |
|
|
resp.SpinLeft = pddData.Spin |
|
|
db.Mysql().Update(&common.PddData{UID: a.UID}, map[string]interface{}{"new_record_time": time.Now().Unix()}) |
|
|
} |
|
|
|
|
|
func ActivityPddReference(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDPDD) { |
|
|
return |
|
|
} |
|
|
req := new(values.ActivityPddReferenceReq) |
|
|
if !a.S(req) { |
|
|
return |
|
|
} |
|
|
resp := &values.ActivityPddReferenceResp{} |
|
|
a.Data = resp |
|
|
pddData := call.GetAcitivityPddData(a.UID) |
|
|
if pddData == nil { |
|
|
return |
|
|
} |
|
|
list := []common.ESPddRecord{} |
|
|
q := elastic.NewBoolQuery() |
|
|
q.Filter(elastic.NewRangeQuery("Time").Gte(pddData.Time)) |
|
|
db.ES().QueryList(common.ESIndexBackPddRecord, req.Page, req.Num, q, &list, "Time", false) |
|
|
for _, v := range list { |
|
|
resp.List = append(resp.List, values.OnePddRecord{ |
|
|
UID: v.UID, |
|
|
Avatar: v.Avatar, |
|
|
Nick: v.Nick, |
|
|
Time: v.Time, |
|
|
SpinCount: 1, |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
func ActivityFreeSpinInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDFreeSpin) { |
|
|
return |
|
|
} |
|
|
con := call.GetConfigActivityFreeSpin() |
|
|
if con == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
resp := &values.ActivityFreeSpinInfoResp{ |
|
|
List: con, |
|
|
NewReward: config.GetConfig().Web.FreeSpinFirst, |
|
|
} |
|
|
a.Data = resp |
|
|
a.GetUID() |
|
|
if a.UID > 0 { |
|
|
freeSpin := call.GetUserFreeSpinData(a.UID) |
|
|
if freeSpin.LastSpin == 0 && freeSpin.SpinNum == 0 { |
|
|
now := time.Now().Unix() |
|
|
p, _ := call.GetUserXInfo(a.UID, "birth") |
|
|
data := &common.ActivityFreeSpinData{UID: a.UID, SpinNum: common.DefaultFreeSpinNum} |
|
|
if !util.IsSameDayTimeStamp(now, p.Birth) { |
|
|
resp.Count = data.SpinNum |
|
|
} |
|
|
// } else { |
|
|
// data.LastSpin = now |
|
|
// } |
|
|
db.Mysql().Create(data) |
|
|
resp.Count = data.SpinNum |
|
|
} else if !util.IsSameDayTimeStamp(time.Now().Unix(), freeSpin.LastSpin) { |
|
|
resp.Count = common.DefaultFreeSpinNum |
|
|
_, err := db.Mysql().UpdateRes(&common.ActivityFreeSpinData{UID: a.UID, LastSpin: freeSpin.LastSpin}, |
|
|
map[string]interface{}{"spin_num": common.DefaultFreeSpinNum}) |
|
|
if err != nil { |
|
|
log.Error("ActivityFreeSpinInfo err:%v", err) |
|
|
} |
|
|
} else { |
|
|
resp.Count = freeSpin.SpinNum |
|
|
} |
|
|
} else { |
|
|
resp.Count = common.DefaultFreeSpinNum |
|
|
} |
|
|
} |
|
|
|
|
|
func ActivityFreeSpinDraw(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDFreeSpin) { |
|
|
return |
|
|
} |
|
|
freeSpin := call.GetUserFreeSpinData(a.UID) |
|
|
if freeSpin.SpinNum <= 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
|
|
|
resp := &values.ActivityFreeSpinDrawResp{} |
|
|
a.Data = resp |
|
|
|
|
|
// 首次旋转,给予固定奖励 |
|
|
// if freeSpin.LastSpin == 0 { |
|
|
// items := call.GetConfigActivityFreeSpinByType(common.ActivityFreeSpinItemRandomCash) |
|
|
// if len(items) == 0 { |
|
|
// a.Code = values.CodeRetry |
|
|
// return |
|
|
// } |
|
|
// err := db.Mysql().Create(&common.ActivityFreeSpinData{UID: a.UID, LastSpin: time.Now().Unix()}) |
|
|
// if err != nil { |
|
|
// a.Code = values.CodeRetry |
|
|
// return |
|
|
// } |
|
|
// resp.Reward = config.GetConfig().Web.FreeSpinFirst |
|
|
// if resp.Reward == 0 { |
|
|
// resp.Reward = 5 * common.DecimalDigits |
|
|
// } |
|
|
// _, err = call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
// CurrencyBalance: &common.CurrencyBalance{ |
|
|
// Type: common.CurrencyINR, |
|
|
// UID: a.UID, |
|
|
// Event: common.CurrencyEventActivityFreeSpin, |
|
|
// Value: resp.Reward, |
|
|
// ChannelID: a.Channel, |
|
|
// NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, resp.Reward), |
|
|
// }, |
|
|
// }) |
|
|
// if err != nil { |
|
|
// a.Code = values.CodeRetry |
|
|
// return |
|
|
// } |
|
|
// ran := rand.Intn(len(items)) |
|
|
// resp.ID = items[ran].ID |
|
|
// call.UploadActivityData(a.UID, common.ActivityIDFreeSpin, common.ActivityDataJoin, resp.Reward) |
|
|
// return |
|
|
// } |
|
|
|
|
|
con := call.GetConfigActivityFreeSpin() |
|
|
if con == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
total := 0 |
|
|
for _, v := range con { |
|
|
total += v.Weight |
|
|
} |
|
|
ran := rand.Intn(total) |
|
|
rans := 0 |
|
|
for _, v := range con { |
|
|
rans += v.Weight |
|
|
if ran < rans { |
|
|
resp.ID = v.ID |
|
|
resp.Reward = v.Amount |
|
|
if v.Type == common.ActivityFreeSpinItemRandomCash { |
|
|
resp.Reward = rand.Int63n(v.CashUp-v.CashDown) + v.CashDown |
|
|
} |
|
|
rows, err := db.Mysql().UpdateRes(&common.ActivityFreeSpinData{UID: a.UID, LastSpin: freeSpin.LastSpin}, |
|
|
map[string]interface{}{"last_spin": time.Now().Unix(), "spin_num": gorm.Expr("spin_num - ?", 1)}) |
|
|
if rows == 0 || err != nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
if v.Type == common.ActivityFreeSpinItemNone { |
|
|
return |
|
|
} |
|
|
_, err = call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
Type: common.CurrencyINR, |
|
|
UID: a.UID, |
|
|
Event: common.CurrencyEventActivityFreeSpin, |
|
|
Value: resp.Reward, |
|
|
ChannelID: a.Channel, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, resp.Reward), |
|
|
}, |
|
|
}) |
|
|
if err != nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
break |
|
|
} |
|
|
} |
|
|
call.UploadActivityData(a.UID, common.ActivityIDFreeSpin, common.ActivityDataJoin, resp.Reward) |
|
|
} |
|
|
|
|
|
func ActivityFirstRechargeBackInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDFirstRechargeBack) { |
|
|
return |
|
|
} |
|
|
resp := &values.ActivityFirstRechargeBackInfoResp{} |
|
|
a.Data = resp |
|
|
data := call.GetUserFirstRechargeBackData(a.UID) |
|
|
diff := time.Now().Unix() - data.RechargeTime |
|
|
log.Debug("ActivityFirstRechargeBackInfo:%+v", data) |
|
|
if data.RechargeTime == 0 { |
|
|
resp.CanRecharge = true |
|
|
} else { |
|
|
if diff > common.ActivityFirstRechargeBackTime*2 { |
|
|
a.Code = values.CodeActivityExpire |
|
|
return |
|
|
} |
|
|
resp.CanRecharge = diff < common.ActivityFirstRechargeBackTime |
|
|
} |
|
|
resp.Recharge = data.Amount |
|
|
if data.Amount < call.GetConfigActivityFirstRechargeBack().MinRecharge { |
|
|
return |
|
|
} |
|
|
val := data.Amount - call.GetUserCurrencyTotal(a.UID, common.CurrencyINR) |
|
|
if val < 0 { |
|
|
val = 0 |
|
|
} |
|
|
max := call.GetConfigActivityFirstRechargeBack().MaxBack |
|
|
if max > 0 && val > max { |
|
|
val = max |
|
|
} |
|
|
if val > data.Amount { |
|
|
val = data.Amount |
|
|
} |
|
|
resp.Back = val |
|
|
} |
|
|
|
|
|
func ActivityFirstRechargeBackDraw(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDFirstRechargeBack) { |
|
|
return |
|
|
} |
|
|
data := call.GetUserFirstRechargeBackData(a.UID) |
|
|
val := data.Amount - call.GetUserCurrencyTotal(a.UID, common.CurrencyINR) |
|
|
if val <= 0 { |
|
|
return |
|
|
} |
|
|
if time.Now().Unix()-data.RechargeTime < common.ActivityFirstRechargeBackTime { |
|
|
log.Error("not ActivityFirstRechargeBackDraw time:%+v", data) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
if time.Now().Unix()-data.RechargeTime > common.ActivityFirstRechargeBackTime*2 { |
|
|
a.Code = values.CodeActivityExpire |
|
|
return |
|
|
} |
|
|
rows, err := db.Mysql().UpdateRes(&common.ActivityFirstRechargeBackData{UID: a.UID}, map[string]interface{}{"lost": 0}) |
|
|
if err != nil || rows == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
max := call.GetConfigActivityFirstRechargeBack().MaxBack |
|
|
if max > 0 || val > max { |
|
|
val = max |
|
|
} |
|
|
if val > data.Amount { |
|
|
val = data.Amount |
|
|
} |
|
|
_, err = call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
ChannelID: a.Channel, |
|
|
Type: common.CurrencyINR, |
|
|
Value: val, |
|
|
Event: common.CurrencyEventActivityFirstRechargeBack, |
|
|
}, |
|
|
}) |
|
|
if err != nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
call.UploadActivityData(a.UID, common.ActivityIDFirstRechargeBack, common.ActivityDataJoin, val) |
|
|
} |
|
|
|
|
|
// 幸运码活动 |
|
|
func ActivityLuckyCodeInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
req := new(values.ActivityLuckyCodeInfoReq) |
|
|
if !a.S(req) { |
|
|
return |
|
|
} |
|
|
|
|
|
if !a.CheckActivityExpire(common.ActivityIDLuckyCode) { |
|
|
return |
|
|
} |
|
|
t := req.Type |
|
|
if t == 0 { |
|
|
t = common.LuckyCodeTypeNormal |
|
|
} else { |
|
|
t = common.LuckyCodeTypeVip |
|
|
} |
|
|
resp := &values.ActivityLuckyCodeInfoResp{ |
|
|
TelegramChannel: config.GetBase().Server.TelegramChannel, |
|
|
} |
|
|
a.Data = resp |
|
|
con := call.GetConfigAcitivityLuckyCode(t) |
|
|
total := call.GetConfigAcitivityLuckyCodeTotalWeight(t) |
|
|
for _, v := range con { |
|
|
resp.List = append(resp.List, values.OneActivityLuckyCodeConfig{ |
|
|
ID: v.ID, |
|
|
Reward: v.Reward, |
|
|
Per: util.FormatFloat(float64(v.Per*100)/float64(total), 2) + "%", |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
func ActivityLuckyCodeDraw(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
|
|
|
if !a.CheckActivityExpire(common.ActivityIDLuckyCode) { |
|
|
return |
|
|
} |
|
|
|
|
|
req := new(values.ActivityLuckyCodeDrawReq) |
|
|
if !a.S(req) { |
|
|
return |
|
|
} |
|
|
now := time.Now() |
|
|
luckyCode := &common.ActivityLuckyCode{Code: req.LuckyCode, Date: now.Format("20060102")} |
|
|
if !a.MGet(luckyCode) { |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "आपके द्वारा दर्ज किया गया कोड ग़लत है" |
|
|
return |
|
|
} |
|
|
resp := &values.ActivityLuckyCodeDrawResp{} |
|
|
a.Data = resp |
|
|
|
|
|
codeType := luckyCode.Type |
|
|
data := &common.ActivityLuckyCodeData{UID: a.UID} |
|
|
db.Mysql().Get(data) |
|
|
if (codeType == common.LuckyCodeTypeNormal && util.IsSameDayTimeStamp(now.Unix(), data.LastDraw)) || |
|
|
(codeType == common.LuckyCodeTypeVip && util.IsSameDayTimeStamp(now.Unix(), data.LastVipDraw)) { |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "इस कोड का पहले ही उपयोग किया जा चुका है" |
|
|
return |
|
|
} |
|
|
// 开始发奖 |
|
|
con := call.GetConfigAcitivityLuckyCode(codeType) |
|
|
total := call.GetConfigAcitivityLuckyCodeTotalWeight(codeType) |
|
|
if total == 0 { |
|
|
log.Error("con:%+v invalid,uid:%d", con, a.UID) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
if data.ID == 0 { |
|
|
codeData := &common.ActivityLuckyCodeData{UID: a.UID, Type: codeType} |
|
|
if codeType == common.LuckyCodeTypeNormal { |
|
|
codeData.LastDraw = now.Unix() |
|
|
} else if codeType == common.LuckyCodeTypeVip { |
|
|
codeData.LastVipDraw = now.Unix() |
|
|
} |
|
|
err := db.Mysql().Create(codeData) |
|
|
if err != nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
} else { |
|
|
updates := map[string]interface{}{} |
|
|
if codeType == common.LuckyCodeTypeNormal { |
|
|
updates["last_draw"] = now.Unix() |
|
|
} else if codeType == common.LuckyCodeTypeVip { |
|
|
updates["last_vip_draw"] = now.Unix() |
|
|
} |
|
|
rows, err := db.Mysql().UpdateRes(&common.ActivityLuckyCodeData{UID: a.UID, LastDraw: data.LastDraw}, updates) |
|
|
if rows == 0 || err != nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
ran := rand.Int63n(total) |
|
|
var rans, reward int64 |
|
|
id := 0 |
|
|
for _, v := range con { |
|
|
rans += v.Per |
|
|
if ran < rans { |
|
|
id = v.ID |
|
|
reward = v.Reward |
|
|
break |
|
|
} |
|
|
} |
|
|
|
|
|
_, err := call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
Type: common.CurrencyINR, |
|
|
Value: reward, |
|
|
Event: common.CurrencyEventTask, |
|
|
Exs1: fmt.Sprintf("%d", codeType), |
|
|
Exi1: req.LuckyCode, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, reward), |
|
|
}, |
|
|
}) |
|
|
if err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
call.UploadActivityData(a.UID, common.ActivityIDLuckyCode, common.ActivityDataJoin, reward) |
|
|
resp.ID = id |
|
|
} |
|
|
|
|
|
// day 二进制从0位开始,实际签到日期需减1 |
|
|
func CanSign(sign, day int) bool { |
|
|
tmp := sign >> (day - 1) |
|
|
return tmp&1 == 0 |
|
|
} |
|
|
|
|
|
func Sign(day int) int { |
|
|
ret := 0 |
|
|
for i := 0; i < day; i++ { |
|
|
ret <<= 1 |
|
|
ret |= 1 |
|
|
} |
|
|
return ret |
|
|
} |
|
|
|
|
|
// GetSignDay 获取签到天数 |
|
|
func GetSignDay(sign int) (day int) { |
|
|
for i := 0; i < 7; i++ { |
|
|
if sign&1 == 1 { |
|
|
day++ |
|
|
} |
|
|
sign >>= 1 |
|
|
} |
|
|
return |
|
|
} |
|
|
|
|
|
// CanSignDays 返回可以签到的天数 |
|
|
func CanSignDays(sign, day int) (ret []int) { |
|
|
for i := 0; i < day; i++ { |
|
|
if sign&1 == 0 { |
|
|
ret = append(ret, i+1) |
|
|
} |
|
|
sign >>= 1 |
|
|
} |
|
|
return |
|
|
} |
|
|
|
|
|
func GetSignInfo(uid int) (resp *values.ActivitySignInfoResp) { |
|
|
if !call.IsActivityValid(common.ActivityIDSign) { |
|
|
return |
|
|
} |
|
|
list := call.GetConfigActivitySign() |
|
|
if len(list) == 0 { |
|
|
return |
|
|
} |
|
|
resp = &values.ActivitySignInfoResp{List: list} |
|
|
if uid == 0 { |
|
|
resp.Day = 1 |
|
|
resp.CanSign = true |
|
|
return |
|
|
} |
|
|
data := &common.ActivitySignData{UID: uid} |
|
|
db.Mysql().Get(data) |
|
|
if data.ID == 0 { |
|
|
user, _ := call.GetUserXInfo(uid, "birth") |
|
|
db.Mysql().Create(&common.ActivitySignData{UID: uid, Time: user.Birth}) |
|
|
data.Time = user.Birth |
|
|
} |
|
|
resp.Sign = data.Sign |
|
|
first := util.GetZeroTime(time.Unix(data.Time, 0)).Unix() |
|
|
today := util.GetZeroTime(time.Now()).Unix() |
|
|
day := (today - first) / common.OneDay |
|
|
resp.Day = int(day) + 1 |
|
|
|
|
|
if resp.Day > list[len(list)-1].Day { |
|
|
resp.Day = list[len(list)-1].Day |
|
|
return |
|
|
} |
|
|
|
|
|
// 说明已签到过,不需要再判断 |
|
|
if !CanSign(resp.Sign, resp.Day) { |
|
|
return |
|
|
} |
|
|
resp.CanSign = true |
|
|
for _, v := range resp.List { |
|
|
if v.Day == resp.Day { |
|
|
if v.Recharge > 0 { |
|
|
re := call.GetRechargeInfo(uid) |
|
|
if re.DayRecharge < v.Recharge { |
|
|
resp.CanSign = false |
|
|
} |
|
|
} |
|
|
break |
|
|
} |
|
|
} |
|
|
return |
|
|
} |
|
|
|
|
|
func ActivitySignInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDSign) { |
|
|
return |
|
|
} |
|
|
a.GetUID() |
|
|
resp := GetSignInfo(a.UID) |
|
|
if resp == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
a.Data = resp |
|
|
} |
|
|
|
|
|
func ActivitySignDraw(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDSign) { |
|
|
return |
|
|
} |
|
|
list := call.GetConfigActivitySign() |
|
|
if len(list) == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
data := &common.ActivitySignData{UID: a.UID} |
|
|
db.Mysql().Get(data) |
|
|
if data.ID == 0 { |
|
|
user, _ := call.GetUserXInfo(a.UID, "birth") |
|
|
db.Mysql().Create(&common.ActivitySignData{UID: a.UID, Time: user.Birth}) |
|
|
data.Time = user.Birth |
|
|
} |
|
|
first := util.GetZeroTime(time.Unix(data.Time, 0)).Unix() |
|
|
today := util.GetZeroTime(time.Now()).Unix() |
|
|
day := int((today-first)/common.OneDay) + 1 |
|
|
// 最大签到天数 |
|
|
if day > list[len(list)-1].Day { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
|
|
|
// if !CanSign(data.Sign, day) { |
|
|
// a.Code = values.CodeParam |
|
|
// return |
|
|
// } |
|
|
days := CanSignDays(data.Sign, day) |
|
|
log.Debug("uid:%v,data.Sign:%v,day:%v,days:%v", a.UID, data.Sign, day, days) |
|
|
if len(days) == 0 { |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "Check-in repetido." |
|
|
return |
|
|
} |
|
|
var reward int64 |
|
|
for _, v := range list { |
|
|
if util.SliceContain(days, v.Day) { |
|
|
reward += v.Reward |
|
|
if v.Day == day { |
|
|
if v.Recharge > 0 { |
|
|
re := call.GetRechargeInfo(a.UID) |
|
|
if re.DayRecharge < v.Recharge { |
|
|
a.Code = values.CodeParam |
|
|
return |
|
|
} |
|
|
} |
|
|
break |
|
|
} |
|
|
} |
|
|
} |
|
|
if reward == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
// ok |
|
|
newSign := Sign(day) |
|
|
rows, err := db.Mysql().UpdateRes(&common.ActivitySignData{UID: a.UID, Sign: data.Sign}, map[string]interface{}{"sign": newSign}) |
|
|
if rows == 0 || err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
_, err = call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
Type: common.CurrencyINR, |
|
|
ChannelID: a.Channel, |
|
|
Value: reward, |
|
|
Event: common.CurrencyEventActivitySign, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, reward), |
|
|
}, |
|
|
}) |
|
|
if err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
a.Data = values.ActivitySignDrawResp{Reward: reward, Day: day, Sign: newSign} |
|
|
call.UploadActivityData(a.UID, common.ActivityIDSign, common.ActivityDataJoin, reward) |
|
|
} |
|
|
|
|
|
func GetSignNewInfo(uid int) (resp *values.ActivitySignInfoResp) { |
|
|
if !call.IsActivityValid(common.ActivityIDSign) { |
|
|
return |
|
|
} |
|
|
data := &common.ActivitySignData{UID: uid} |
|
|
if uid > 0 { |
|
|
db.Mysql().Get(data) |
|
|
if data.ID == 0 { |
|
|
user, _ := call.GetUserXInfo(uid, "birth") |
|
|
db.Mysql().Create(&common.ActivitySignData{UID: uid, Time: user.Birth}) |
|
|
data.Time = user.Birth |
|
|
} |
|
|
} else { |
|
|
data.Wheel = 1 |
|
|
} |
|
|
|
|
|
list := call.GetConfigActivitySignByWheel(data.Wheel) |
|
|
if len(list) == 0 { |
|
|
return |
|
|
} |
|
|
resp = &values.ActivitySignInfoResp{List: list} |
|
|
if uid == 0 { |
|
|
resp.Day = 1 |
|
|
resp.CanSign = true |
|
|
return |
|
|
} |
|
|
re := call.GetRechargeInfo(uid) |
|
|
playerData := call.GetPlayerData(uid) |
|
|
resp.RewardCount = data.Reward |
|
|
resp.LatestSignTime = data.SignTime |
|
|
resp.Recharge = re.DayRecharge |
|
|
resp.Bet = playerData.DayBet |
|
|
signDay := GetSignDay(data.Sign) |
|
|
resp.Sign = 7*(data.Wheel-1) + signDay |
|
|
resp.Day = signDay + 1 |
|
|
now := time.Now() |
|
|
if data.Finish || util.IsSameDayTimeStamp(now.Unix(), data.SignTime) { |
|
|
for _, v := range resp.List { |
|
|
if v.Day == signDay && data.Wheel >= v.WheelStart && data.Wheel <= v.WheelEnd { |
|
|
resp.Recharge = v.Recharge |
|
|
resp.Bet = v.Bet |
|
|
break |
|
|
} |
|
|
} |
|
|
} |
|
|
if util.IsSameDayTimeStamp(now.Unix(), data.SignTime) { |
|
|
return |
|
|
} |
|
|
resp.CanSign = true |
|
|
if !data.Finish { |
|
|
for _, v := range resp.List { |
|
|
if v.Day == resp.Day && data.Wheel >= v.WheelStart && data.Wheel <= v.WheelEnd { |
|
|
if re.DayRecharge < v.Recharge || playerData.DayBet < v.Bet { |
|
|
resp.CanSign = false |
|
|
} |
|
|
// 更新状态 |
|
|
if err := db.Mysql().Update(&common.ActivitySignData{UID: data.UID}, map[string]interface{}{"finish": true}); err != nil { |
|
|
log.Error("err:%v", err) |
|
|
resp.CanSign = false |
|
|
} |
|
|
break |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
return |
|
|
} |
|
|
|
|
|
func ActivitySignNewInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDSign) { |
|
|
return |
|
|
} |
|
|
a.GetUID() |
|
|
resp := GetSignNewInfo(a.UID) |
|
|
if resp == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
a.Data = resp |
|
|
} |
|
|
|
|
|
func ActivitySignNewDraw(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDSign) { |
|
|
return |
|
|
} |
|
|
|
|
|
data := &common.ActivitySignData{UID: a.UID} |
|
|
db.Mysql().Get(data) |
|
|
if data.ID == 0 { |
|
|
user, _ := call.GetUserXInfo(a.UID, "birth") |
|
|
db.Mysql().Create(&common.ActivitySignData{UID: a.UID, Time: user.Birth}) |
|
|
data.Time = user.Birth |
|
|
} |
|
|
list := call.GetConfigActivitySignByWheel(data.Wheel) |
|
|
if len(list) == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
now := time.Now() |
|
|
if util.IsSameDayTimeStamp(now.Unix(), data.SignTime) { |
|
|
// 已经签到 |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "आज में हस्ताक्षर किए" |
|
|
return |
|
|
} |
|
|
|
|
|
// 获取签到了几天 |
|
|
day := GetSignDay(data.Sign) + 1 |
|
|
var reward int64 |
|
|
for _, v := range list { |
|
|
if v.Day == day && data.Wheel >= v.WheelStart && data.Wheel <= v.WheelEnd { |
|
|
reward = v.Reward |
|
|
re := call.GetRechargeInfo(a.UID) |
|
|
playerData := call.GetPlayerData(a.UID) |
|
|
if re.DayRecharge < v.Recharge || playerData.DayBet < v.Bet { |
|
|
a.Code = values.CodeParam |
|
|
return |
|
|
} |
|
|
break |
|
|
|
|
|
} |
|
|
} |
|
|
if reward == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
|
|
|
// 如果签到了7天就重置 |
|
|
if day > 7 { |
|
|
rows, err := db.Mysql().UpdateRes(&common.ActivitySignData{UID: a.UID, Sign: data.Sign}, map[string]interface{}{"sign": 0, "wheel": gorm.Expr("wheel + ?", 1)}) |
|
|
if rows == 0 || err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
} |
|
|
// ok |
|
|
newSign := Sign(day) |
|
|
rows, err := db.Mysql().UpdateRes(&common.ActivitySignData{UID: a.UID, Sign: data.Sign}, map[string]interface{}{"sign": newSign, "finish": false, "reward": gorm.Expr("reward + ?", reward), "sign_time": now.Unix()}) |
|
|
if rows == 0 || err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
_, err = call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
Type: common.CurrencyINR, |
|
|
ChannelID: a.Channel, |
|
|
Value: reward, |
|
|
Event: common.CurrencyEventActivitySign, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, reward), |
|
|
}, |
|
|
}) |
|
|
if err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
a.Data = values.ActivitySignDrawResp{Reward: reward, Day: day, Sign: newSign} |
|
|
call.UploadActivityData(a.UID, common.ActivityIDSign, common.ActivityDataJoin, reward) |
|
|
} |
|
|
|
|
|
// 破产礼包活动 |
|
|
func ActivityBreakGiftInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDBreakGift) { |
|
|
return |
|
|
} |
|
|
resp := &values.ActivityBreakGiftInfoResp{} |
|
|
limit := config.GetConfig().Web.BreakLimit |
|
|
if limit <= 0 { |
|
|
limit = 1 * common.DecimalDigits |
|
|
} |
|
|
if call.GetUserCurrency(a.UID, common.CurrencyINR) > limit { |
|
|
return |
|
|
} |
|
|
payData := call.GetPlayerPayData(a.UID) |
|
|
re := call.GetRechargeInfo(a.UID) |
|
|
con := call.GetConfigActivityBreakGiftByRecharge(re.TotalRecharge, payData) |
|
|
log.Debug("con:%+v,total:%v", con, re.TotalRecharge) |
|
|
if con == nil { |
|
|
return |
|
|
} |
|
|
if util.SliceContain(payData.SubBreakGift, con.Level) { |
|
|
return |
|
|
} |
|
|
|
|
|
product := call.GetConfigPayProductByID(con.ProductID) |
|
|
log.Debug("product:%+v", product) |
|
|
if product == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
resp.Amount = product.Amount |
|
|
resp.Reward = product.Value |
|
|
resp.ProductID = con.ProductID |
|
|
resp.CountDown = con.CountDown |
|
|
a.Data = resp |
|
|
} |
|
|
|
|
|
func ActivityWeekCardInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDWeekCard) { |
|
|
return |
|
|
} |
|
|
cons := call.GetConfigActivityWeekCard() |
|
|
list := call.GetUserWeekCards(a.UID) |
|
|
resp := &values.ActivityWeekCardInfoResp{} |
|
|
a.Data = resp |
|
|
for _, v := range cons { |
|
|
product := call.GetConfigPayProductByID(v.ProductID) |
|
|
if product == nil { |
|
|
continue |
|
|
} |
|
|
one := values.OneWeekCard{ |
|
|
Level: v.Level, |
|
|
Rebate: fmt.Sprintf("%d", v.Rebate) + "%", |
|
|
OriginPrice: v.OriginPrice, |
|
|
Price: product.Amount, |
|
|
Reward: product.Value, |
|
|
DayReward: v.DayReward, |
|
|
DayCount: v.Day, |
|
|
Discount: fmt.Sprintf("%d", 100-v.Discount), |
|
|
Next: -1, |
|
|
ProductID: v.ProductID, |
|
|
TotalReward: v.DayReward*int64(v.Day) + product.Value, |
|
|
} |
|
|
for _, k := range list { |
|
|
if k.Level == v.Level && k.Day > 0 { |
|
|
one.DayReward = k.DayReward |
|
|
one.Day = k.Day |
|
|
if !util.IsSameDayTimeStamp(k.LastDraw, time.Now().Unix()) { |
|
|
one.Next = 0 |
|
|
} else { |
|
|
one.Next = util.GetZeroTime(time.Now().AddDate(0, 0, 1)).Unix() - k.LastDraw |
|
|
} |
|
|
break |
|
|
} |
|
|
} |
|
|
resp.List = append(resp.List, one) |
|
|
} |
|
|
} |
|
|
|
|
|
func ActivityWeekCardDraw(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDWeekCard) { |
|
|
return |
|
|
} |
|
|
req := new(values.ActivityWeekCardDrawReq) |
|
|
if !a.S(req) { |
|
|
return |
|
|
} |
|
|
card := call.GetUserWeekCard(a.UID, req.Level) |
|
|
if card.ID == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
if card.Day <= 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
now := time.Now().Unix() |
|
|
if util.IsSameDayTimeStamp(now, card.LastDraw) { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
rows, err := db.Mysql().UpdateRes(&common.ActivityWeekCardData{UID: a.UID, Level: req.Level, Day: card.Day}, |
|
|
map[string]interface{}{"day": gorm.Expr("day - 1"), "last_draw": now}) |
|
|
if rows == 0 || err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
resp := &values.ActivityWeekCardDrawResp{ |
|
|
Reward: card.DayReward, |
|
|
} |
|
|
a.Data = resp |
|
|
call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
Type: common.CurrencyINR, |
|
|
Value: card.DayReward, |
|
|
Event: common.CurrencyEventActivityWeekCard, |
|
|
ChannelID: a.Channel, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, card.DayReward), |
|
|
}, |
|
|
}) |
|
|
con := call.GetConfigActivityWeekCardByLevel(card.Level) |
|
|
if con != nil { |
|
|
// 最后一天必得一次 |
|
|
if card.Day == 1 { |
|
|
call.AddUserDiscountTicket(a.UID, con.Discount) |
|
|
resp.DiscountTicket = fmt.Sprintf("%d", 100-con.Discount) |
|
|
} else if card.GetDiscount == 0 { // 未领取过则随机一次 |
|
|
ran := rand.Intn(card.Day) |
|
|
if ran == 0 { |
|
|
db.Mysql().Update(&common.ActivityWeekCardData{UID: a.UID, Level: req.Level}, map[string]interface{}{"get_discount": 1}) |
|
|
call.AddUserDiscountTicket(a.UID, con.Discount) |
|
|
resp.DiscountTicket = fmt.Sprintf("%d", 100-con.Discount) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
func ActivitySlotsInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDSlots) { |
|
|
return |
|
|
} |
|
|
resp := &values.ActivitySlotsResp{ActivityID: common.ActivityIDSlots} |
|
|
a.Data = resp |
|
|
isSingle := call.IsActivitySingleDay(common.ActivityIDSlots) |
|
|
for _, v := range values.ActivitySlotsRank { |
|
|
one := &values.OneActivitySlotsRank{ |
|
|
UID: v.UID, |
|
|
Avatar: v.Avatar, |
|
|
Nick: v.Nick, |
|
|
} |
|
|
if v.Avatar == "" || v.Nick == "" { |
|
|
p, _ := call.GetUserXInfo(v.UID, "mobile", "avatar") |
|
|
v.Avatar = p.Avatar |
|
|
v.Nick = p.Mobile |
|
|
} |
|
|
one.Nick = "*******" + v.Nick[len(v.Nick)-3:] |
|
|
if isSingle { |
|
|
one.Number = v.BestNumber1 |
|
|
} else { |
|
|
one.Number = v.BestNumber2 |
|
|
} |
|
|
resp.RankList = append(resp.RankList, one) |
|
|
} |
|
|
|
|
|
a.GetUID() |
|
|
if a.UID == 0 { |
|
|
return |
|
|
} |
|
|
|
|
|
data := call.GetUserActivitySlotsData(a.UID) |
|
|
resp.Spin = data.Spin |
|
|
if isSingle { |
|
|
if data.Time1 >= util.GetZeroTime(time.Now()).Unix() { |
|
|
resp.BestNumber = data.BestNumber1 |
|
|
} |
|
|
} else { |
|
|
if data.Time2 >= util.GetZeroTime(time.Now()).Unix() { |
|
|
resp.BestNumber = data.BestNumber2 |
|
|
} |
|
|
} |
|
|
lastDate := time.Now().AddDate(0, 0, -1).Format("20060102") |
|
|
record := &common.ActivitySlotsRecord{UID: a.UID, Date: lastDate} |
|
|
db.Mysql().Get(record) |
|
|
if record.ID > 0 { |
|
|
if record.Settle == 0 { |
|
|
resp.LastReward = &values.OneActivitySlotsLastReward{ |
|
|
Rank: record.Rank, |
|
|
Number: record.MyNumber, |
|
|
Reward: record.Reward, |
|
|
Draw: record.Settle == 1, |
|
|
} |
|
|
} |
|
|
} else { |
|
|
// 查询昨天是否参与 |
|
|
t := data.Time1 |
|
|
number := data.BestNumber1 |
|
|
if isSingle { |
|
|
t = data.Time2 |
|
|
number = data.BestNumber2 |
|
|
} |
|
|
if util.IsSameDayTimeStamp(t, time.Now().AddDate(0, 0, -1).Unix()) { |
|
|
resp.LastReward = &values.OneActivitySlotsLastReward{ |
|
|
Number: number, |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
// 商品 |
|
|
product := call.GetConfigPayProductByActivityID(common.ActivityIDSlots) |
|
|
if len(product) > 0 { |
|
|
resp.Product = values.OneActivitySlotsProduct{ |
|
|
ProductID: product[0].ProductID, |
|
|
OriginAmount: product[0].OriginAmount, |
|
|
Amount: product[0].Amount, |
|
|
Reward: product[0].Value, |
|
|
SpinCount: product[0].Exi, |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
func ActivitySlotsDraw(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDSlots) { |
|
|
return |
|
|
} |
|
|
data := call.GetUserActivitySlotsData(a.UID) |
|
|
if data.Spin <= 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
resp := &values.ActivitySlotsDrawResp{} |
|
|
a.Data = resp |
|
|
/* |
|
|
真人玩家若充值大于200则每次抽奖会有75%的概率抽取到900-910之间的数字,25%的概率抽取到850—900以下的数字 |
|
|
真人玩家若充值大于50则每次抽奖会有75%的概率抽取到850-900之间的数字,25%的概率抽取到850以下的数字 |
|
|
充值小于50的真人玩家抽取到的数字只能小于850(暂定数字),随机选取 |
|
|
*/ |
|
|
re := call.GetRechargeInfo(a.UID) |
|
|
ran := rand.Intn(100) |
|
|
if re.DayRecharge >= 20000000000 { |
|
|
if ran < 75 { |
|
|
resp.Number = rand.Intn(11) + 900 |
|
|
} else { |
|
|
resp.Number = rand.Intn(50) + 850 |
|
|
} |
|
|
} else if re.DayRecharge >= 5000000000 { |
|
|
if ran < 75 { |
|
|
resp.Number = rand.Intn(50) + 850 |
|
|
} else { |
|
|
resp.Number = rand.Intn(850) |
|
|
} |
|
|
} else { |
|
|
resp.Number = rand.Intn(850) |
|
|
} |
|
|
now := time.Now().Unix() |
|
|
|
|
|
t := data.Time2 |
|
|
number := data.BestNumber2 |
|
|
str := "best_number2" |
|
|
tstr := "time2" |
|
|
if call.IsActivitySingleDay(common.ActivityIDSlots) { |
|
|
t = data.Time1 |
|
|
number = data.BestNumber1 |
|
|
str = "best_number1" |
|
|
tstr = "time1" |
|
|
} |
|
|
u := map[string]interface{}{"spin": gorm.Expr("spin - 1"), tstr: now} |
|
|
|
|
|
if resp.Number > number || !util.IsSameDayTimeStamp(now, t) { |
|
|
u[str] = resp.Number |
|
|
} |
|
|
rows, err := db.Mysql().UpdateResW(&common.ActivitySlotsData{UID: a.UID}, u, fmt.Sprintf("uid = %d and %s = %d", a.UID, tstr, t)) |
|
|
if err != nil || rows == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
log.Error("err:%v", err) |
|
|
return |
|
|
} |
|
|
call.UploadActivityData(a.UID, common.ActivityIDSlots, 2, 0) |
|
|
} |
|
|
|
|
|
func ActivitySlotsDrawLast(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
lastDate := time.Now().AddDate(0, 0, -1).Format("20060102") |
|
|
record := &common.ActivitySlotsRecord{UID: a.UID, Date: lastDate} |
|
|
db.Mysql().Get(record) |
|
|
resp := &values.ActivitySlotsDrawLastResp{} |
|
|
a.Data = resp |
|
|
if record.ID == 0 || record.Settle == 1 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
rows, err := db.Mysql().UpdateResW(&common.ActivitySlotsRecord{}, map[string]interface{}{"settle": 1}, fmt.Sprintf("uid = %d and date = '%s' and settle = 0", a.UID, lastDate)) |
|
|
if err != nil || rows == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
if record.Reward == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
Time: time.Now().Unix(), |
|
|
Value: record.Reward, |
|
|
Type: common.CurrencyINR, |
|
|
Event: common.CurrencyEventActivitySlots, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, record.Reward), |
|
|
}, |
|
|
}) |
|
|
resp.Reward = record.Reward |
|
|
call.UploadActivityData(a.UID, common.ActivityIDSlots, 2, record.Reward) |
|
|
} |
|
|
|
|
|
func ActivityLuckyShopInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDLuckyShop) { |
|
|
return |
|
|
} |
|
|
resp := &values.ActivityLuckyShopResp{} |
|
|
a.Data = resp |
|
|
data := call.GetShowActivityLuckShopData(a.UID) |
|
|
if data == nil { |
|
|
return |
|
|
} |
|
|
if data.ProductID == 0 { |
|
|
return |
|
|
} |
|
|
product := call.GetConfigPayProductByID(data.ProductID) |
|
|
if product == nil { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
if data.ID == 0 { |
|
|
db.Mysql().Create(data) |
|
|
} |
|
|
resp.Recharge = product.Amount |
|
|
resp.Value = product.Value |
|
|
resp.ProductID = product.ProductID |
|
|
resp.CountDown = common.ActivityLuckyShopExpire + data.Push - time.Now().Unix() |
|
|
} |
|
|
|
|
|
func ActivitySevenDayBoxInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDSevenDayBox) { |
|
|
return |
|
|
} |
|
|
resp := &values.ActivitySevenDayBoxInfoResp{} |
|
|
a.Data = resp |
|
|
re := call.GetRechargeInfo(a.UID) |
|
|
con := call.GetConfigActivitySevenDayBoxByRechargeAndType(re.TotalRecharge, common.ActivitySevenDayBoxTypeCash) |
|
|
if len(con) == 0 { |
|
|
return |
|
|
} |
|
|
var least int64 = -1 |
|
|
var max int64 = -1 |
|
|
for _, v := range con { |
|
|
if len(v.SubCashRange) == 2 { |
|
|
if v.SubCashRange[0] < least || least < 0 { |
|
|
least = v.SubCashRange[0] |
|
|
} |
|
|
if v.SubCashRange[1] > max { |
|
|
max = v.SubCashRange[1] |
|
|
} |
|
|
} |
|
|
} |
|
|
resp.ProductID = con[0].ProductID |
|
|
resp.RewardRange = []int64{least, max} |
|
|
data := &common.ActivitySevenDayBoxData{UID: a.UID} |
|
|
db.Mysql().Get(data) |
|
|
resp.Buy = !util.IsSameDayTimeStamp(data.Time, time.Now().Unix()) |
|
|
resp.Open = data.Count > 0 |
|
|
|
|
|
product := call.GetConfigPayProductByID(resp.ProductID) |
|
|
if product != nil { |
|
|
resp.Recharge = product.Amount |
|
|
} |
|
|
} |
|
|
|
|
|
func ActivitySevenDayBoxDraw(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
resp := &values.ActivitySevenDayBoxDrawResp{} |
|
|
a.Data = resp |
|
|
|
|
|
re := call.GetRechargeInfo(a.UID) |
|
|
cashCon := call.GetConfigActivitySevenDayBoxByRechargeAndType(re.TotalRecharge, common.ActivitySevenDayBoxTypeCash) |
|
|
discountCon := call.GetConfigActivitySevenDayBoxByRechargeAndType(re.TotalRecharge, common.ActivitySevenDayBoxTypeDiscountTicket) |
|
|
|
|
|
if len(cashCon) == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
|
|
|
if len(discountCon) == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
|
|
|
oneCash := cashCon[util.RandomOneEleFromSlice(cashCon, "Per")] |
|
|
oneDiscount := discountCon[util.RandomOneEleFromSlice(discountCon, "Per")] |
|
|
|
|
|
if len(oneCash.SubCashRange) != 2 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
|
|
|
data := &common.ActivitySevenDayBoxData{UID: a.UID} |
|
|
db.Mysql().Get(data) |
|
|
if data.Count <= 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
rows, err := db.Mysql().UpdateResW(&common.ActivitySevenDayBoxData{}, map[string]interface{}{"count": gorm.Expr("count - 1")}, |
|
|
fmt.Sprintf("uid = %d and count = %d", a.UID, data.Count)) |
|
|
if rows == 0 || err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
|
|
|
var reward int64 |
|
|
diff := oneCash.SubCashRange[1] - oneCash.SubCashRange[0] |
|
|
if diff <= 0 { |
|
|
reward = oneCash.SubCashRange[0] |
|
|
} else { |
|
|
diff /= common.DecimalDigits |
|
|
reward = rand.Int63n(diff)*common.DecimalDigits + oneCash.SubCashRange[0] |
|
|
} |
|
|
if reward > 0 { |
|
|
call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
Event: common.CurrencyEventActivityAppSpin, |
|
|
Type: common.CurrencyINR, |
|
|
Value: reward, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, reward), |
|
|
}, |
|
|
}) |
|
|
resp.Reward = reward |
|
|
call.UploadActivityData(a.UID, common.ActivityIDSevenDayBox, common.ActivityDataJoin, reward) |
|
|
} |
|
|
if oneDiscount.Discount > 0 { |
|
|
call.AddUserDiscountTicket(a.UID, oneDiscount.Discount) |
|
|
resp.Discount = oneDiscount.Discount |
|
|
} |
|
|
} |
|
|
|
|
|
func ActivitySuperInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDSuper) { |
|
|
return |
|
|
} |
|
|
resp := &values.ActivitySuperInfoResp{} |
|
|
a.Data = resp |
|
|
data := call.GetUserActivitySuperData(a.UID) |
|
|
con := call.GetConfigActivitySuperByType(data.Type) |
|
|
resp.Buy = data.CanBuy |
|
|
if len(con) > 0 { |
|
|
product := call.GetConfigPayProductByID(con[0].ProductID) |
|
|
if product != nil { |
|
|
resp.Recharge = product.Amount |
|
|
resp.ProductID = con[0].ProductID |
|
|
} |
|
|
} |
|
|
|
|
|
for i := 1; i <= 3; i++ { |
|
|
one := values.OneActivitySuperBox{ |
|
|
Index: i, |
|
|
} |
|
|
if data.CanBuy { // 说明未付费 |
|
|
one.Status = 0 |
|
|
} else { |
|
|
tmp := data.Open >> (i - 1) |
|
|
if tmp&1 == 0 { |
|
|
one.Status = 1 |
|
|
} else { |
|
|
one.Status = 2 |
|
|
} |
|
|
} |
|
|
for _, v := range con { |
|
|
if v.Index != i { |
|
|
continue |
|
|
} |
|
|
one.Rewards = append(one.Rewards, values.ActivitySuperOneReward{ |
|
|
RewardType: v.RewardType, |
|
|
Reward: v.Reward, |
|
|
}) |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
func ActivitySuperDraw(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDSuper) { |
|
|
return |
|
|
} |
|
|
req := new(values.ActivitySuperDrawReq) |
|
|
if !a.S(req) { |
|
|
return |
|
|
} |
|
|
if req.Index > 3 || req.Index < 1 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
data := call.GetUserActivitySuperData(a.UID) |
|
|
if data.Time == 0 { // 未购买 |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
tmp := data.Open >> (req.Index - 1) |
|
|
if tmp&1 == 1 { |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "Coleta repetida." |
|
|
return |
|
|
} |
|
|
cons := call.GetConfigActivitySuperByTypeAndIndex(data.Type, req.Index) |
|
|
index := util.RandomOneEleFromSlice(cons, "Per") |
|
|
|
|
|
reward := cons[index] |
|
|
|
|
|
open := 1 << (req.Index - 1) & data.Open |
|
|
rows, err := db.Mysql().UpdateResW(&common.ActivitySuperData{}, map[string]interface{}{"open": open}, fmt.Sprintf("uid = %d and open = %d", a.UID, data.Open)) |
|
|
if rows == 0 || err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
// 发奖 |
|
|
if reward.RewardType == 1 { |
|
|
call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
Event: common.CurrencyEventActivitySuper, |
|
|
Value: reward.Reward, |
|
|
Type: common.CurrencyINR, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, reward.Reward), |
|
|
}, |
|
|
}) |
|
|
call.UploadActivityData(a.UID, common.ActivityIDSuper, 2, reward.Reward) |
|
|
} else { |
|
|
call.AddUserDiscountTicket(a.UID, int(reward.Reward)) |
|
|
} |
|
|
a.Data = &values.ActivitySuperDrawResp{ |
|
|
Reward: values.ActivitySuperOneReward{ |
|
|
RewardType: reward.RewardType, |
|
|
Reward: reward.Reward, |
|
|
}, |
|
|
} |
|
|
} |
|
|
|
|
|
func ActivityBetDrawInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDBetDraw) { |
|
|
return |
|
|
} |
|
|
a.GetUID() |
|
|
drawInfo := &common.ActivityBetDrawData{UID: a.UID} |
|
|
if a.UID > 0 { |
|
|
db.Mysql().Get(drawInfo) |
|
|
if drawInfo.ID == 0 { |
|
|
db.Mysql().Create(drawInfo) |
|
|
} |
|
|
} |
|
|
a.Data = &values.ActivityBetDrawInfoResp{ |
|
|
List: call.GetConfigBetDraw(), |
|
|
Lucky: drawInfo.Lucky, |
|
|
} |
|
|
call.UploadActivityData(a.UID, common.ActivityIDBetDraw, common.ActivityDataClick, 0) |
|
|
} |
|
|
|
|
|
func ActivityBetDrawDraw(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
req := values.ActivityBetDrawDrawReq{} |
|
|
if !a.S(&req) { |
|
|
return |
|
|
} |
|
|
if !a.CheckActivityExpire(common.ActivityIDBetDraw) { |
|
|
return |
|
|
} |
|
|
configList, weightList := call.GetConfigBetDrawByType(req.WheelType) |
|
|
if len(configList) == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
conf := configList[0] |
|
|
drawInfo := common.ActivityBetDrawData{UID: a.UID} |
|
|
db.Mysql().Get(&drawInfo) |
|
|
if drawInfo.Lucky < conf.Cost { |
|
|
a.Code = values.CodeRetry |
|
|
a.Msg = "lucky not enough" |
|
|
return |
|
|
} |
|
|
// 计算权重 |
|
|
idx := util.RandWeight(weightList) |
|
|
if idx < 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
rewardConf := configList[idx] |
|
|
reward := rewardConf.Reward |
|
|
err := db.Mysql().Update(&drawInfo, map[string]interface{}{ |
|
|
"lucky": gorm.Expr("lucky - ?", conf.Cost), |
|
|
}) |
|
|
if err != nil { |
|
|
a.Code = values.CodeRetry |
|
|
log.Error("ActivityBetDrawDraw err:%v", err) |
|
|
return |
|
|
} |
|
|
if reward > 0 { |
|
|
_, _ = call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
Event: common.CurrencyEventActivityAppSpin, |
|
|
Type: common.CurrencyINR, |
|
|
Value: reward, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, reward), |
|
|
}, |
|
|
}) |
|
|
} |
|
|
|
|
|
call.UploadActivityData(a.UID, common.ActivityIDBetDraw, common.ActivityDataJoin, reward) |
|
|
db.ES().InsertToESGO(common.ESIndexBackBetDraw, common.ESActivityBetDraw{ |
|
|
UID: a.UID, |
|
|
Time: time.Now().Unix(), |
|
|
Reward: reward, |
|
|
Type: req.WheelType, |
|
|
}) |
|
|
a.Data = &values.ActivityBetDrawDrawResp{ |
|
|
Reward: reward, |
|
|
} |
|
|
} |
|
|
|
|
|
func ActivityBetDrawHistory(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
req := values.ActivityBetDrawRecordReq{} |
|
|
if !a.S(&req) { |
|
|
return |
|
|
} |
|
|
resp := new(values.ActivityBetDrawRecordResp) |
|
|
if !a.CheckActivityExpire(common.ActivityIDBetDraw) { |
|
|
return |
|
|
} |
|
|
q := elastic.NewBoolQuery() |
|
|
q.Filter(elastic.NewTermQuery("Type", req.WheelType)) |
|
|
_, _ = db.ES().QueryList(common.ESIndexBackBetDraw, req.Page-1, req.Num, q, &resp.RecordList, "Time", false) |
|
|
q.Filter(elastic.NewTermQuery("UID", a.UID)) |
|
|
_, _ = db.ES().QueryList(common.ESIndexBackBetDraw, 0, 5000, q, &resp.SelfList, "Time", false) |
|
|
a.Data = resp |
|
|
}
|
|
|
|