|
|
package handler |
|
|
|
|
|
import ( |
|
|
"fmt" |
|
|
"server/call" |
|
|
"server/common" |
|
|
"server/config" |
|
|
"server/db" |
|
|
"server/modules/web/app" |
|
|
"server/modules/web/values" |
|
|
"server/pb" |
|
|
"server/util" |
|
|
"time" |
|
|
|
|
|
"github.com/gin-gonic/gin" |
|
|
"github.com/liangdas/mqant/log" |
|
|
"github.com/olivere/elastic/v7" |
|
|
) |
|
|
|
|
|
func GetVipInfo(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
req := new(values.VipInfoReq) |
|
|
ok, _ := util.CheckRequestBody(c) |
|
|
if ok && !a.S(req) { |
|
|
return |
|
|
} |
|
|
if req.Num > 100 { |
|
|
req.Num = 100 |
|
|
} |
|
|
resp := &values.VipInfoResp{ |
|
|
List: call.GetConfigVIP(), |
|
|
} |
|
|
a.Data = resp |
|
|
a.GetUID() |
|
|
if a.UID == 0 { |
|
|
return |
|
|
} |
|
|
|
|
|
resp.Info = call.GetVIP(a.UID) |
|
|
con := call.GetConfigVIPByLevel(resp.Info.Level) |
|
|
if con == nil { |
|
|
return |
|
|
} |
|
|
if resp.Info.Profit < 0 { |
|
|
resp.Info.Profit = 0 |
|
|
} |
|
|
reset := false |
|
|
now := time.Now() |
|
|
if config.GetBase().Release { |
|
|
reset = !util.IsSameDayTimeStamp(now.Unix(), resp.Info.ProfitTime) |
|
|
if reset { |
|
|
if util.GetZeroTime(now).Unix()-resp.Info.ProfitTime > 24*3600 { // 超时未领取直接归零 |
|
|
db.Mysql().UpdateResW(&common.VipData{}, map[string]interface{}{"profit_time": now.Unix(), "cashback": 0, "profit": 0}, |
|
|
fmt.Sprintf("uid = %v and profit_time = %v", a.UID, resp.Info.ProfitTime)) |
|
|
resp.Info.Cashback = 0 |
|
|
resp.Info.Profit = 0 |
|
|
} else { |
|
|
cashback := resp.Info.Profit * con.Cashback / 1000 |
|
|
if cashback < 0 { |
|
|
cashback = 0 |
|
|
} |
|
|
resp.Info.Cashback = cashback |
|
|
db.Mysql().UpdateResW(&common.VipData{}, map[string]interface{}{"profit_time": now.Unix(), "cashback": cashback, "profit": 0}, |
|
|
fmt.Sprintf("uid = %v and profit_time = %v", a.UID, resp.Info.ProfitTime)) |
|
|
} |
|
|
} |
|
|
} else { |
|
|
reset = util.GetNext5MinUnix()-resp.Info.ProfitTime >= 5*60 |
|
|
if reset { |
|
|
if util.GetNext5MinUnix()-resp.Info.ProfitTime > 2*5*60 { // 超时未领取直接归零 |
|
|
db.Mysql().UpdateResW(&common.VipData{}, map[string]interface{}{"profit_time": now.Unix(), "cashback": 0, "profit": 0}, |
|
|
fmt.Sprintf("uid = %v and profit_time = %v", a.UID, resp.Info.ProfitTime)) |
|
|
resp.Info.Cashback = 0 |
|
|
resp.Info.Profit = 0 |
|
|
} else { |
|
|
cashback := resp.Info.Profit * con.Cashback / 1000 |
|
|
if cashback < 0 { |
|
|
cashback = 0 |
|
|
} |
|
|
resp.Info.Cashback = cashback |
|
|
db.Mysql().UpdateResW(&common.VipData{}, map[string]interface{}{"profit_time": now.Unix(), "cashback": cashback, "profit": 0}, |
|
|
fmt.Sprintf("uid = %v and profit_time = %v", a.UID, resp.Info.ProfitTime)) |
|
|
} |
|
|
} |
|
|
} |
|
|
if resp.Info.Cashback == 0 && resp.Info.Level > 0 { |
|
|
con := call.GetVipCon(a.UID) |
|
|
resp.Info.Cashback = resp.Info.Profit * con.Cashback / 1000 |
|
|
if config.GetBase().Release { |
|
|
resp.NextCashback = util.GetZeroTime(now.AddDate(0, 0, 1)).Unix() - now.Unix() |
|
|
} else { |
|
|
resp.NextCashback = util.GetNext5MinUnix() - now.Unix() |
|
|
} |
|
|
} |
|
|
if resp.Info.Cashback < 0 { |
|
|
resp.Info.Cashback = 0 |
|
|
} |
|
|
resp.CashbackList = []common.CurrencyBalance{} |
|
|
q := elastic.NewBoolQuery() |
|
|
q.Filter(elastic.NewTermQuery("uid", a.UID)) |
|
|
q.Filter(elastic.NewTermQuery("event", common.CurrencyEventVIPCashback)) |
|
|
resp.TotalCashback = db.ES().SumByInt64(common.ESIndexBalance, "value", q) |
|
|
// db.ES().QueryList(common.ESIndexBalance, req.Page, req.Num, q, &resp.CashbackList, "time", false) |
|
|
num := 0 |
|
|
if resp.Info.Cashback > 0 { |
|
|
num = 1 |
|
|
} |
|
|
if num > 0 { |
|
|
call.PushRed(a.UID, pb.RedPointModule_RedPointVipCashback, uint32(num)) |
|
|
} |
|
|
} |
|
|
|
|
|
func DrawVipBonus(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
req := new(values.DrawVipBonusReq) |
|
|
if !a.S(req) { |
|
|
return |
|
|
} |
|
|
cons := call.GetConfigVIP() |
|
|
if len(cons) == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
if req.Level < 0 || req.Level > cons[len(cons)-1].Level { |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "VIP level is insufficient" |
|
|
return |
|
|
} |
|
|
vip := call.GetVIP(a.UID) |
|
|
if vip.Level < req.Level { |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "VIP level is insufficient" |
|
|
return |
|
|
} |
|
|
flag := int64(1 << req.Level) |
|
|
if vip.Draws&int64(flag) > 0 { |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "reward has been claimed" |
|
|
return |
|
|
} |
|
|
con := call.GetConfigVIPByLevel(req.Level) |
|
|
if con == nil { |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "VIP level is insufficient" |
|
|
return |
|
|
} |
|
|
bonus := con.Bonus |
|
|
if bonus <= 0 { |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "इनाम अमान्य" |
|
|
return |
|
|
} |
|
|
newDraws := vip.Draws | flag |
|
|
rows, err := db.Mysql().UpdateResW(&common.VipData{}, map[string]interface{}{"draws": newDraws}, fmt.Sprintf("uid = %d and draws = %v", a.UID, vip.Draws)) |
|
|
if err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
if rows == 0 { |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
_, err = call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
Event: common.CurrencyEventVIPBonus, |
|
|
Type: common.CurrencyINR, |
|
|
ChannelID: a.Channel, |
|
|
Value: bonus, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, bonus), |
|
|
}, |
|
|
}) |
|
|
if err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
vip = call.GetVIP(a.UID) |
|
|
if vip.Draws == 0 { |
|
|
call.PushRed(a.UID, pb.RedPointModule_RedPointVipReward, uint32(0)) |
|
|
} |
|
|
} |
|
|
|
|
|
func DrawVipCashback(c *gin.Context) { |
|
|
a := app.NewApp(c) |
|
|
defer func() { |
|
|
a.Response() |
|
|
}() |
|
|
vip := call.GetVIP(a.UID) |
|
|
cashback := vip.Cashback |
|
|
con := call.GetConfigVIPByLevel(vip.Level) |
|
|
reset := false |
|
|
now := time.Now() |
|
|
update := map[string]interface{}{"cashback": 0} |
|
|
if config.GetBase().Release { |
|
|
reset = !util.IsSameDayTimeStamp(now.Unix(), vip.ProfitTime) |
|
|
if reset { |
|
|
if util.GetZeroTime(now).Unix()-vip.ProfitTime > 24*3600 { // 超时未领取直接归零 |
|
|
db.Mysql().UpdateResW(&common.VipData{}, map[string]interface{}{"profit_time": now.Unix(), "cashback": 0, "profit": 0}, |
|
|
fmt.Sprintf("uid = %v and profit_time = %v", a.UID, vip.ProfitTime)) |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "इनाम अमान्य" |
|
|
return |
|
|
} else { |
|
|
cashback = vip.Profit * con.Cashback / 1000 |
|
|
update["profit"] = 0 |
|
|
update["profit_time"] = time.Now().Unix() |
|
|
} |
|
|
} |
|
|
} else { |
|
|
reset = util.GetNext5MinUnix()-vip.ProfitTime >= 5*60 |
|
|
if reset { |
|
|
if util.GetNext5MinUnix()-vip.ProfitTime > 2*5*60 { // 超时未领取直接归零 |
|
|
db.Mysql().UpdateResW(&common.VipData{}, map[string]interface{}{"profit_time": now.Unix(), "cashback": 0, "profit": 0}, |
|
|
fmt.Sprintf("uid = %v and profit_time = %v", a.UID, vip.ProfitTime)) |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "इनाम अमान्य" |
|
|
return |
|
|
} else { |
|
|
cashback = vip.Profit * con.Cashback / 1000 |
|
|
update["profit"] = 0 |
|
|
update["profit_time"] = time.Now().Unix() |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if cashback <= 0 { |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "इनाम अमान्य" |
|
|
return |
|
|
} |
|
|
|
|
|
q := elastic.NewBoolQuery() |
|
|
q.Filter(elastic.NewTermQuery("uid", a.UID)) |
|
|
q.Filter(elastic.NewTermQuery("event", common.CurrencyEventVIPCashback)) |
|
|
totalCashback := db.ES().SumByInt64(common.ESIndexBalance, "value", q) |
|
|
|
|
|
rows, err := db.Mysql().UpdateResW(&common.VipData{}, update, fmt.Sprintf("uid = %v and cashback = %v", a.UID, vip.Cashback)) |
|
|
if err != nil || rows == 0 { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeParam |
|
|
a.Msg = "इनाम अमान्य" |
|
|
return |
|
|
} |
|
|
_, err = call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
|
CurrencyBalance: &common.CurrencyBalance{ |
|
|
UID: a.UID, |
|
|
Event: common.CurrencyEventVIPCashback, |
|
|
Type: common.CurrencyINR, |
|
|
ChannelID: a.Channel, |
|
|
Value: cashback, |
|
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, cashback), |
|
|
}, |
|
|
}) |
|
|
if err != nil { |
|
|
log.Error("err:%v", err) |
|
|
a.Code = values.CodeRetry |
|
|
return |
|
|
} |
|
|
resp := values.DrawCashbackResp{ |
|
|
TotalCashback: totalCashback + cashback, |
|
|
Balance: 0, |
|
|
} |
|
|
if config.GetBase().Release { |
|
|
resp.NextCashback = util.GetZeroTime(now.AddDate(0, 0, 1)).Unix() - now.Unix() |
|
|
} else { |
|
|
resp.NextCashback = util.GetNext5MinUnix() - now.Unix() |
|
|
} |
|
|
a.Data = resp |
|
|
call.PushRed(a.UID, pb.RedPointModule_RedPointVipCashback, uint32(0)) |
|
|
}
|
|
|
|