|
|
package handler |
|
|
|
|
|
import ( |
|
|
"fmt" |
|
|
"math/rand" |
|
|
"server/call" |
|
|
"server/common" |
|
|
"server/config" |
|
|
"server/db" |
|
|
"server/modules/web/app" |
|
|
"server/modules/web/values" |
|
|
"server/pb" |
|
|
"server/util" |
|
|
"sort" |
|
|
"strconv" |
|
|
"strings" |
|
|
"time" |
|
|
|
|
|
"github.com/gin-gonic/gin" |
|
|
"github.com/liangdas/mqant/log" |
|
|
"github.com/olivere/elastic/v7" |
|
|
"gorm.io/gorm" |
|
|
) |
|
|
|
|
|
// GetUserTaskStatus 获取任务状态 |
|
|
func GetUserTaskStatus(a *app.Gin) (ret []*values.OneTask) { |
|
|
tasks := call.GetConfigTask() |
|
|
for _, v := range tasks { |
|
|
one := &values.OneTask{ |
|
|
ID: v.ID, |
|
|
TaskID: v.TaskID, |
|
|
Target: v.Target, |
|
|
Reward: v.Reward, |
|
|
Kind: v.Kind, |
|
|
Type: int(v.Type), |
|
|
Icon: v.Icon, |
|
|
Title: common.GetTaskTitle(v), |
|
|
Action: v.Action, |
|
|
} |
|
|
// 非次数任务,需转换目标数值 |
|
|
// if !common.IsNumTaskType(v.Type) { |
|
|
// one.Target /= common.DecimalDigits |
|
|
// } |
|
|
ret = append(ret, one) |
|
|
} |
|
|
if a.UID <= 0 { |
|
|
return |
|
|
} |
|
|
|
|
|
now := time.Now() |
|
|
task := call.GetUserTaskData(a.UID) |
|
|
for _, v := range ret { |
|
|
for _, k := range task { |
|
|
if v.TaskID == k.TaskID { |
|
|
v.Progess = k.Progress |
|
|
taskTime := time.Unix(k.Time, 0) |
|
|
// 跨天清空数据 |
|
|
if !util.IsSameDay(now, taskTime) && v.Kind == common.TaskKindDayOne { |
|
|
v.Status = 0 |
|
|
v.Progess = 0 |
|
|
err := db.Mysql().Update(&k, map[string]interface{}{ |
|
|
"progress": 0, |
|
|
"time": now.Unix(), |
|
|
}) |
|
|
if err != nil { |
|
|
log.Error("GetUserTaskStatus err:%v", err) |
|
|
} |
|
|
} |
|
|
break |
|
|
} |
|
|
} |
|
|
if v.Type == int(common.TaskTypeDownload) && v.Progess != -1 { // 已下载直接标记为完成 |
|
|
if a.DeviceType == common.DeviceTypeWebview || a.DeviceType == common.DeviceTypePWA { |
|
|
// 直接领取下载奖励 |
|
|
taskId := call.CheckTask(call.Task{Uid: a.UID, Value: 0, Types: []common.TaskType{common.TaskTypeDownload}}) |
|
|
TaskComplete(a, &DrawTaskReq{TaskID: taskId}) |
|
|
a.Code = values.CodeOK |
|
|
a.Msg = "" |
|
|
} |
|
|
} |
|
|
// 非次数任务,需转换目标数值 |
|
|
// if !common.IsNumTaskType(v.Type) && v.Progess > 0 { |
|
|
// v.Progess /= common.DecimalDigits |
|
|
// } |
|
|
if v.Progess < 0 { |
|
|
v.Progess = v.Target |
|
|
v.Status = 2 |
|
|
} else if v.Progess >= v.Target { |
|
|
v.Progess = v.Target |
|
|
v.Status = 1 |
|
|
} |
|
|
} |
|
|
sort.SliceStable(ret, func(i, j int) bool { |
|
|
return ret[i].Status > ret[j].Status |
|
|
}) |
|
|
return |
|
|
} |
|
|
|
|
|
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 = GetUserTaskStatus(a) |
|
|
num := 0 |
|
|
for _, task := range ret.TaskList { |
|
|
if task.Status == 1 { |
|
|
num++ |
|
|
} |
|
|
} |
|
|
if num > 0 { |
|
|
call.PushRed(a.UID, pb.RedPointModule_RedPointTask, uint32(num)) |
|
|
} |
|
|
} |
|
|
|
|
|
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 |
|
|
} |
|
|
if resp.Count > 0 { |
|
|
// call.PushRed(a.UID, pb.RedPointModule_RedPointSign, 1) |
|
|
} |
|
|
} |
|
|
|
|
|
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 |
|
|
|
|
|
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() |
|
|
}() |
|
|
a.GetUID() |
|
|
if !a.CheckActivityExpire(common.ActivityIDFirstRechargeBack) { |
|
|
return |
|
|
} |
|
|
resp := &values.ActivityFirstRechargeBackInfoResp{} |
|
|
conf := call.GetConfigActivityFirstRechargeBack() |
|
|
a.Data = resp |
|
|
data := call.GetUserFirstRechargeBackData(a.UID) |
|
|
resp.NeedRechargeAmount = conf.MinRecharge / common.DecimalDigits |
|
|
resp.ProductList = call.GetConfigPayProductByActivityID(common.ActivityIDFirstRechargeBack) |
|
|
resp.Recharge = data.Amount |
|
|
resp.PayAmount = data.Amount |
|
|
resp.BackPer = conf.MaxBack |
|
|
resp.ChannelList = call.GetConfigPayChannelsByID(common.CurrencyINR) |
|
|
p, _ := call.GetUserXInfo(a.UID, "birth") |
|
|
resp.DrawTime = p.Birth + conf.CD |
|
|
rechargeInfo := call.GetRechargeInfo(a.UID) |
|
|
if data.RechargeTime == 0 { |
|
|
resp.CanRecharge = true |
|
|
return |
|
|
} |
|
|
if data.Reward == 0 { |
|
|
val := data.Amount - call.GetUserCurrencyTotal(a.UID, common.CurrencyINR) - rechargeInfo.WithdrawingCash |
|
|
if val < 0 { |
|
|
val = 0 |
|
|
} |
|
|
val = val * conf.MaxBack / 100 |
|
|
now := time.Now().Unix() |
|
|
if now >= p.Birth+conf.CD && data.Reward == 0 && data.RechargeTime == 0 { |
|
|
update := map[string]interface{}{ |
|
|
"reward": val, |
|
|
} |
|
|
if val == 0 { |
|
|
data.RechargeTime = now |
|
|
update["reward_time"] = now |
|
|
} |
|
|
db.Mysql().Update(&common.ActivityFirstRechargeBackData{UID: a.UID}, update) |
|
|
} |
|
|
data.Reward = val |
|
|
} |
|
|
if data.RewardTime > 0 { |
|
|
resp.Draw = true |
|
|
} |
|
|
resp.Back = data.Reward |
|
|
if !resp.Draw { |
|
|
call.PushRed(a.UID, pb.RedPointModule_RedPointFirstRecharge, 1) |
|
|
} |
|
|
} |
|
|
|
|
|
func ActivityFirstRechargeBackDraw(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
if !a.CheckActivityExpire(common.ActivityIDFirstRechargeBack) { |
|
|
return |
|
|
} |
|
|
resp := new(values.ActivityFirstRechargeBackDrawResp) |
|
|
a.Data = resp |
|
|
conf := call.GetConfigActivityFirstRechargeBack() |
|
|
data := call.GetUserFirstRechargeBackData(a.UID) |
|
|
p, _ := call.GetUserXInfo(a.UID, "birth") |
|
|
if time.Now().Unix()-p.Birth < conf.CD { |
|
|
log.Error("not ActivityFirstRechargeBackDraw time:%+v", data) |
|
|
a.Code = values.CodeRetry |
|
|
a.Msg = "Unarrived time" |
|
|
return |
|
|
} |
|
|
if data.RewardTime > 0 { |
|
|
a.Code = values.CodeRetry |
|
|
a.Msg = "Award claimed" |
|
|
return |
|
|
} |
|
|
rows, err := db.Mysql().UpdateRes(&common.ActivityFirstRechargeBackData{UID: a.UID}, map[string]interface{}{"reward_time": time.Now().Unix()}) |
|
|
if err != nil || rows == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
val := data.Reward |
|
|
_, 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 |
|
|
} |
|
|
resp.Reward = val |
|
|
call.UploadActivityData(a.UID, common.ActivityIDFirstRechargeBack, common.ActivityDataJoin, val) |
|
|
call.PushRed(a.UID, pb.RedPointModule_RedPointFirstRecharge, 0) |
|
|
} |
|
|
|
|
|
// 幸运码活动 |
|
|
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 |
|
|
} |
|
|
resp := &values.ActivityLuckyCodeDrawResp{} |
|
|
a.Data = resp |
|
|
code, _ := strconv.Atoi(req.LuckyCode) |
|
|
var reward int64 |
|
|
|
|
|
// 判断是否为分享吗 |
|
|
upShareInfo := call.GetShareInfoByCode(req.LuckyCode) |
|
|
if upShareInfo.ID > 0 { |
|
|
if upShareInfo.UID == a.UID { |
|
|
a.Code = values.CodeRetry |
|
|
a.Msg = "code error" |
|
|
return |
|
|
} |
|
|
shareInfo := call.GetShareInfo(a.UID) |
|
|
if shareInfo.UP1 > 0 { |
|
|
a.Code = values.CodeRetry |
|
|
a.Msg = "has binding" |
|
|
return |
|
|
} |
|
|
call.ShareBind(req.LuckyCode, true, a.UID, a.Channel) |
|
|
reward = call.GetConfigPlatform().ShareBindReward |
|
|
_, err := call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
Type: common.CurrencyINR, |
|
|
Value: reward, |
|
|
Event: common.CurrencyEventTask, |
|
|
Exi1: code, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, reward), |
|
|
}, |
|
|
}) |
|
|
if err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
a.Msg = "code error" |
|
|
return |
|
|
} |
|
|
} else { |
|
|
now := time.Now() |
|
|
luckyCode := &common.ActivityLuckyCode{Code: code, Date: now.Format("20060102")} |
|
|
if !a.MGet(luckyCode) { |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "The code you entered is incorrect" |
|
|
return |
|
|
} |
|
|
|
|
|
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 = "This code has already been used" |
|
|
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.CodeParam |
|
|
a.Msg = "code error" |
|
|
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 int64 |
|
|
for _, v := range con { |
|
|
rans += v.Per |
|
|
if ran < rans { |
|
|
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: code, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, reward), |
|
|
}, |
|
|
}) |
|
|
if err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
a.Msg = "code error" |
|
|
return |
|
|
} |
|
|
call.UploadActivityData(a.UID, common.ActivityIDLuckyCode, common.ActivityDataJoin, reward) |
|
|
} |
|
|
|
|
|
resp.Reward = reward |
|
|
} |
|
|
|
|
|
// 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") |
|
|
data.Wheel = 1 |
|
|
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 |
|
|
} |
|
|
if resp.Day > 7 { |
|
|
if len(call.GetConfigActivitySignByWheel(data.Wheel+1)) > 0 { |
|
|
if err := db.Mysql().Update(&common.ActivitySignData{UID: data.UID}, map[string]interface{}{"sign": 0, "wheel": gorm.Expr("wheel + ?", 1)}); err != nil { |
|
|
log.Error("err:%v", err) |
|
|
resp.CanSign = false |
|
|
return |
|
|
} |
|
|
resp.Sign = 7 * (data.Wheel) |
|
|
resp.Day = 1 |
|
|
} |
|
|
} |
|
|
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 |
|
|
} else { |
|
|
// 更新状态 |
|
|
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 |
|
|
a.Msg = "पात्रता को पूरा न करें" |
|
|
return |
|
|
} |
|
|
call.UploadActivityData(a.UID, common.ActivityIDSign, common.ActivityDataClick, 0) |
|
|
num := 0 |
|
|
if resp.CanSign { |
|
|
num = 1 |
|
|
} |
|
|
if num > 0 { |
|
|
call.PushRed(a.UID, pb.RedPointModule_RedPointSign, uint32(num)) |
|
|
} |
|
|
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 |
|
|
a.Msg = "शर्तों को पूरा नहीं किया जाता है" |
|
|
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 { |
|
|
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 |
|
|
a.Msg = "शर्तों को पूरा नहीं किया जाता है" |
|
|
log.Error("uid:%v,conf:%v", a.UID, v) |
|
|
return |
|
|
} |
|
|
break |
|
|
} |
|
|
} |
|
|
if reward == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
log.Error("reward == 0") |
|
|
return |
|
|
} |
|
|
|
|
|
// ok |
|
|
newSign := Sign(day) |
|
|
updates := map[string]interface{}{"sign": newSign, "finish": false, "reward": gorm.Expr("reward + ?", reward)} |
|
|
updates["sign_time"] = now.Unix() |
|
|
rows, err := db.Mysql().UpdateRes(&common.ActivitySignData{UID: a.UID, Sign: data.Sign}, updates) |
|
|
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.CurrencyEventActivityBetDraw, |
|
|
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) |
|
|
call.PushRed(a.UID, pb.RedPointModule_RedPointSign, uint32(0)) |
|
|
} |
|
|
|
|
|
// 破产礼包活动 |
|
|
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() |
|
|
}() |
|
|
a.GetUID() |
|
|
if !a.CheckActivityExpire(common.ActivityIDWeekCard) { |
|
|
return |
|
|
} |
|
|
resp := &values.ActivityWeekCardInfoResp{} |
|
|
a.Data = resp |
|
|
cons := call.GetConfigActivityWeekCard() |
|
|
cardInfo := new(common.ActivityWeekCardData) |
|
|
if a.UID > 0 { |
|
|
cardInfo = call.GetUserWeekCard(a.UID) |
|
|
} |
|
|
var rewardList []int64 |
|
|
var err error |
|
|
rewardList, err = util.GenerateRandomSequence(cons.RewardAmount, cons.MiniLimit, 5) |
|
|
if err != nil { |
|
|
log.Error("err:%v", err) |
|
|
} |
|
|
rewardList = append([]int64{cons.DayOneReward}, rewardList...) |
|
|
rewardList = append(rewardList, 0) |
|
|
if cardInfo.ID <= 0 || len(cardInfo.Rewards) == 0 { |
|
|
cardInfo.Day = 0 |
|
|
rewardList, err = util.GenerateRandomSequence(cons.RewardAmount, cons.MiniLimit, 5) |
|
|
if err != nil { |
|
|
log.Error("err:%v", err) |
|
|
} |
|
|
rewardList = append([]int64{cons.DayOneReward}, rewardList...) |
|
|
rewardList = append(rewardList, 0) |
|
|
if cardInfo.ID <= 0 { |
|
|
cardInfo.Rewards = strings.Join(util.Int64SliceToStringSlice(rewardList), ",") |
|
|
if a.UID > 0 { |
|
|
db.Mysql().Create(cardInfo) |
|
|
} |
|
|
} else { |
|
|
cardInfo.Rewards = strings.Join(util.Int64SliceToStringSlice(rewardList), ",") |
|
|
db.Mysql().Update(&common.ActivityWeekCardData{UID: a.UID}, map[string]interface{}{ |
|
|
"rewards": cardInfo.Rewards, |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
if rewardList == nil { |
|
|
rewardList, _ = util.StringToInt64Slice(cardInfo.Rewards, ",") |
|
|
} |
|
|
if cardInfo.RechargeTime != 0 { |
|
|
resp.RechargeStatus = true |
|
|
} |
|
|
// step:签完7天就重置 |
|
|
if cardInfo.Day >= len(rewardList) { |
|
|
resp.RechargeStatus = false |
|
|
} |
|
|
for _, item := range rewardList { |
|
|
resp.RewardList = append(resp.RewardList, values.WeekCardInfo{ |
|
|
Min: cons.MiniLimit, |
|
|
Max: cons.RewardAmount - cons.MiniLimit*4, |
|
|
Val: item, |
|
|
}) |
|
|
} |
|
|
resp.Status = true |
|
|
if config.GetBase().Release { |
|
|
if util.IsSameDayTimeStamp(time.Now().Unix(), cardInfo.LastDraw) { |
|
|
resp.Status = false |
|
|
} |
|
|
} |
|
|
resp.RewardDay = cardInfo.Day |
|
|
resp.ChannelList = call.GetConfigPayChannelsByID(common.CurrencyINR) |
|
|
resp.ProductList = call.GetConfigPayProductByActivityID(common.ActivityIDWeekCard) |
|
|
if resp.Status && resp.RechargeStatus { |
|
|
call.PushRed(a.UID, pb.RedPointModule_RedPointWeekCard, 1) |
|
|
} |
|
|
call.UploadActivityData(a.UID, common.ActivityIDSign, common.ActivityDataClick, 0) |
|
|
} |
|
|
|
|
|
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 |
|
|
} |
|
|
resp := &values.ActivityWeekCardDrawResp{} |
|
|
a.Data = resp |
|
|
// conf := call.GetConfigActivityWeekCard() |
|
|
card := call.GetUserWeekCard(a.UID) |
|
|
if card.ID == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
now := time.Now().Unix() |
|
|
if config.GetBase().Release { |
|
|
if util.IsSameDayTimeStamp(now, card.LastDraw) { |
|
|
a.Code = values.CodeRetry |
|
|
a.Msg = "today has reward" |
|
|
return |
|
|
} |
|
|
} |
|
|
rewards, _ := util.StringToInt64Slice(card.Rewards, ",") |
|
|
if card.Day >= len(rewards) { |
|
|
a.Code = values.CodeRetry |
|
|
a.Msg = "The weekly card has been collected" |
|
|
return |
|
|
} |
|
|
rows, err := db.Mysql().UpdateRes(&common.ActivityWeekCardData{UID: a.UID}, |
|
|
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 |
|
|
} |
|
|
var reward int64 |
|
|
if card.Day < 6 { |
|
|
reward = rewards[card.Day] * common.DecimalDigits |
|
|
} else { |
|
|
// 第几天折扣券 |
|
|
// 用户画像一:6天内充值3笔及以上用户 |
|
|
// 推送当前最高额度向上一档充值满减卷 |
|
|
// 用户画像二:只解锁周卡,未充值的玩家 |
|
|
// 推送当前额度向下一档充值满减卷,最低300 |
|
|
var list []common.CurrencyBalance |
|
|
q := elastic.NewBoolQuery() |
|
|
q.Filter(elastic.NewRangeQuery("time").Gte(card.RechargeTime)) |
|
|
q.Filter(elastic.NewRangeQuery("time").Lte(now)) |
|
|
q.Filter(elastic.NewRangeQuery("event").Gte(common.CurrencyEventReCharge)) |
|
|
q.Must(elastic.NewTermsQuery("uid", a.UID)) |
|
|
db.ES().QueryList(common.ESIndexBalance, 0, 100, q, &list, "time", true) |
|
|
up := false |
|
|
maxAmount := card.RechargeAmount |
|
|
if len(list) >= 3 { |
|
|
up = true |
|
|
for _, item := range list { |
|
|
if item.Value > maxAmount { |
|
|
maxAmount = item.Value |
|
|
} |
|
|
} |
|
|
} |
|
|
log.Info("maxAmount:%v", maxAmount) |
|
|
ticket := call.GetConfigDiscountTicketByAmount(maxAmount) |
|
|
log.Info("ticket:%v", ticket) |
|
|
if ticket.Id > 0 { |
|
|
// 赠送优惠券 |
|
|
tickets := call.GetConfigDiscountTicket() |
|
|
sort.Slice(tickets, func(i, j int) bool { |
|
|
return tickets[i].RechargeAmount < tickets[j].RechargeAmount |
|
|
}) |
|
|
// 获取下一档 |
|
|
nextIdx := -1 |
|
|
for idx, item := range tickets { |
|
|
if item.RechargeAmount == maxAmount { |
|
|
if up { |
|
|
nextIdx = idx + 1 |
|
|
} else if item.RechargeAmount >= 300*common.DecimalDigits { |
|
|
nextIdx = idx - 1 |
|
|
} |
|
|
break |
|
|
} |
|
|
} |
|
|
var nextTicket = ticket |
|
|
if len(tickets) > nextIdx && nextIdx != -1 { |
|
|
nextTicket = tickets[nextIdx] |
|
|
} |
|
|
if up { |
|
|
call.AddUserDiscountTicket(a.UID, ticket.DiscountAmount, ticket.RechargeAmount, -1, 0, false) |
|
|
call.SendMailWithContent(a.UID, call.SystemTitle, fmt.Sprintf(call.EmailDiscount, ticket.DiscountAmount/common.DecimalDigits, ticket.RechargeAmount/common.DecimalDigits)) |
|
|
resp.DiscountTicket = ticket.DiscountAmount |
|
|
resp.Amount = ticket.RechargeAmount |
|
|
} else if nextTicket.Id > 0 { |
|
|
call.AddUserDiscountTicket(a.UID, nextTicket.DiscountAmount, nextTicket.RechargeAmount, -1, 1, false) |
|
|
call.SendMailWithContent(a.UID, call.SystemTitle, fmt.Sprintf(call.EmailDiscount, ticket.DiscountAmount/common.DecimalDigits, ticket.RechargeAmount/common.DecimalDigits)) |
|
|
resp.DiscountTicket = nextTicket.DiscountAmount |
|
|
resp.Amount = nextTicket.RechargeAmount |
|
|
} |
|
|
} |
|
|
} |
|
|
resource := common.CurrencyResourceWeekCard |
|
|
if card.Day > 0 { |
|
|
resource = common.CurrencyResourceBonus |
|
|
} |
|
|
resp.Reward = reward |
|
|
if reward > 0 { |
|
|
call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
Type: common.CurrencyINR, |
|
|
Value: reward, |
|
|
Event: common.CurrencyEventActivityWeekCard, |
|
|
ChannelID: a.Channel, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(resource, reward), |
|
|
}, |
|
|
}) |
|
|
} |
|
|
call.PushRed(a.UID, pb.RedPointModule_RedPointWeekCard, 0) |
|
|
call.UploadActivityData(a.UID, common.ActivityIDSign, common.ActivityDataJoin, reward) |
|
|
} |
|
|
|
|
|
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.EmailDiscount) |
|
|
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) |
|
|
} |
|
|
} |
|
|
vipInfo := call.GetVIP(a.UID) |
|
|
confList := call.GetConfigBetDraw() |
|
|
resp := &values.ActivityBetDrawInfoResp{ |
|
|
List: confList, |
|
|
Lucky: drawInfo.Lucky, |
|
|
} |
|
|
a.Data = resp |
|
|
now := time.Now() |
|
|
update := false |
|
|
if !util.IsSameDayTimeStamp(drawInfo.SpinInfo.LastSpinTime, now.Unix()) { |
|
|
drawInfo.SpinInfo.SpinNum = 0 |
|
|
update = true |
|
|
} |
|
|
if update && a.UID > 0 { |
|
|
db.Mysql().Update(&common.ActivityBetDrawData{UID: a.UID}, map[string]interface{}{ |
|
|
"spin_info": drawInfo.SpinInfo, |
|
|
}) |
|
|
} |
|
|
drawInfo.SpinInfo.SpinCount = confList[0].LimitNum |
|
|
resp.SpinInfo = append(resp.SpinInfo, drawInfo.SpinInfo) |
|
|
call.UploadActivityData(a.UID, common.ActivityIDBetDraw, common.ActivityDataClick, 0) |
|
|
for _, item := range resp.List { |
|
|
if resp.Lucky >= item.Cost && vipInfo.Level >= item.VipUnlock && |
|
|
drawInfo.SpinInfo.SpinNum < drawInfo.SpinInfo.SpinCount && |
|
|
now.Unix() >= drawInfo.SpinInfo.NextSpinTIme { |
|
|
call.PushRed(a.UID, pb.RedPointModule_RedPointFreeSpin, uint32(1)) |
|
|
break |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
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) |
|
|
now := time.Now() |
|
|
spinInfo := drawInfo.SpinInfo |
|
|
// step:判断cd |
|
|
if spinInfo.LastSpinTime != 0 && spinInfo.NextSpinTIme > now.Unix() { |
|
|
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" |
|
|
return |
|
|
} |
|
|
// 计算权重 |
|
|
idx := util.RandWeight(weightList) |
|
|
if idx < 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
rewardConf := configList[idx] |
|
|
reward := rewardConf.Reward |
|
|
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": spinInfo, |
|
|
}) |
|
|
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, |
|
|
} |
|
|
|
|
|
drawInfo = common.ActivityBetDrawData{UID: a.UID} |
|
|
db.Mysql().Get(&drawInfo) |
|
|
|
|
|
call.PushRed(a.UID, pb.RedPointModule_RedPointFreeSpin, uint32(0)) |
|
|
} |
|
|
|
|
|
func ActivityBetDrawHistory(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
a.GetUID() |
|
|
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 |
|
|
} |
|
|
|
|
|
func ActivityPopup(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
req := values.ActivityPopupReq{} |
|
|
if !a.S(&req) { |
|
|
return |
|
|
} |
|
|
resp := new(values.ActivityPopupResp) |
|
|
a.Data = resp |
|
|
if req.JumpType == 0 { |
|
|
resp.List = call.GetConfigActivityPopup() |
|
|
} else { |
|
|
resp.List = call.GetConfigActivityPopupByType(req.JumpType) |
|
|
} |
|
|
} |
|
|
|
|
|
func WeekCardInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
req := values.ActivityPopupReq{} |
|
|
if !a.S(&req) { |
|
|
return |
|
|
} |
|
|
resp := new(values.ActivityPopupResp) |
|
|
a.Data = resp |
|
|
if req.JumpType == 0 { |
|
|
resp.List = call.GetConfigActivityPopup() |
|
|
} else { |
|
|
resp.List = call.GetConfigActivityPopupByType(req.JumpType) |
|
|
} |
|
|
} |
|
|
|
|
|
func WeekCardDraw(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
req := values.ActivityPopupReq{} |
|
|
if !a.S(&req) { |
|
|
return |
|
|
} |
|
|
resp := new(values.ActivityPopupResp) |
|
|
a.Data = resp |
|
|
if req.JumpType == 0 { |
|
|
resp.List = call.GetConfigActivityPopup() |
|
|
} else { |
|
|
resp.List = call.GetConfigActivityPopupByType(req.JumpType) |
|
|
} |
|
|
} |
|
|
|
|
|
func DiscountTicketInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
resp := new(values.DiscountTicketResp) |
|
|
a.Data = resp |
|
|
list := call.GetUserValidItems(a.UID, common.ItemDiscountTicket) |
|
|
sort.Slice(list, func(i, j int) bool { |
|
|
return list[i].Exi2 > list[i].Exi2 |
|
|
}) |
|
|
currency := call.GetUserCurrency(a.UID, common.CurrencyINR) |
|
|
if len(list) > 0 && currency <= config.GetConfig().Web.BreakLimit { |
|
|
resp.Ticket = &values.DiscountTicketInfo{ |
|
|
Amount: list[0].Exi1, |
|
|
Discount: list[0].Exi2, |
|
|
Id: int64(list[0].ID), |
|
|
} |
|
|
} |
|
|
resp.ChannelList = call.GetConfigPayChannelsByID(common.CurrencyINR) |
|
|
}
|
|
|
|