You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
489 lines
14 KiB
489 lines
14 KiB
package handler |
|
|
|
import ( |
|
"fmt" |
|
"server/call" |
|
"server/common" |
|
"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" |
|
"gorm.io/gorm" |
|
) |
|
|
|
// func ShareInfo(c *gin.Context) { |
|
// a := app.NewApp(c) |
|
// defer func() { |
|
// a.Response() |
|
// }() |
|
// shareInfo := &common.ShareInfo{} |
|
// resp := &values.ShareInfoResp{ |
|
// ShareConfig: call.GetConfigShare(), |
|
// } |
|
// a.Data = resp |
|
// a.GetUID() |
|
// if a.UID > 0 { |
|
// shareInfo = call.GetShareInfo(a.UID) |
|
// resp.Today = values.ShareRecord{ |
|
// Regist: shareInfo.TodayAgents, |
|
// Real: shareInfo.TodayRealAgents, |
|
// Bet: shareInfo.TodayAgentsBet, |
|
// Reward: shareInfo.TodayReward, |
|
// } |
|
// resp.Total = values.ShareRecord{ |
|
// Regist: shareInfo.TotalAgents, |
|
// Real: shareInfo.TotalRealAgents, |
|
// Bet: shareInfo.TotalAgentsBet, |
|
// Reward: shareInfo.TotalReward, |
|
// } |
|
// resp.Rewards = values.RewardRecord{ |
|
// Level: shareInfo.Level, |
|
// TotalWithdraw: shareInfo.TotalReward - shareInfo.AvailableReward, |
|
// Available: shareInfo.AvailableReward, |
|
// } |
|
// } |
|
|
|
// channel := call.GetChannelByID(a.Channel) |
|
// if channel != nil { |
|
// resp.ShareLink = channel.URL + "?code=" + shareInfo.Share |
|
// if a.Prefix != "" { |
|
// resp.ShareLink = a.Prefix + "." + resp.ShareLink |
|
// } else { |
|
// resp.ShareLink = "www." + resp.ShareLink |
|
// } |
|
// if shareInfo.Share == "" { |
|
// resp.ShareLink += "xxxxxx" |
|
// } |
|
// } |
|
// con := call.GetConfigShareSys() |
|
// if con != nil { |
|
// resp.Rewards.WithdrawLimit = con.WithdrawLimit |
|
// } |
|
// } |
|
|
|
func ShareInfo(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
resp := &values.ShareInfoResp{ |
|
InviteRecharge: call.GetConfigShareSys().ShareRecharge, |
|
PlatformInviteReward: values.ShareTotalInviteReward + call.GetConfigShareSys().FakeInviteReward, |
|
PlatformBetReward: values.ShareTotalBetReward + call.GetConfigShareSys().FakeBetReward, |
|
Rank: values.ShareRank, |
|
} |
|
a.Data = resp |
|
resp.PlatformTotalReward = resp.PlatformInviteReward + resp.PlatformBetReward |
|
for _, v := range call.GetConfigShare() { |
|
resp.BetPer = append(resp.BetPer, util.FormatFloat(float64(v.Per)/10, 2)+"%") |
|
} |
|
channel := call.GetChannelByID(a.Channel) |
|
if channel != nil { |
|
resp.ShareLink = channel.ShareUrl |
|
} |
|
a.GetUID() |
|
if a.UID <= 0 { |
|
return |
|
} |
|
shareInfo := call.GetShareInfo(a.UID) |
|
resp.InviteReward = shareInfo.InviteReward |
|
resp.BetReward = shareInfo.BetReward |
|
resp.Invites = shareInfo.Invites |
|
resp.InvalidInvites = shareInfo.InvaidInvites |
|
resp.TotalReward = resp.InviteReward + resp.BetReward |
|
resp.AvailableReward = shareInfo.AvailableReward |
|
resp.RechargeCount = call.GetUserShareRecharges(a.UID, 1) |
|
resp.TotalRecharge = call.GetUserShareRechargeAmount(a.UID, 1) |
|
resp.ShareCode = shareInfo.Share |
|
|
|
num := 0 |
|
if resp.AvailableReward > 0 { |
|
num = 1 |
|
} |
|
if num > 0 { |
|
call.PushRed(a.UID, pb.RedPointModule_RedPointShare, uint32(num)) |
|
} |
|
} |
|
|
|
func ShareList(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.ShareListReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
resp := &values.ShareListResp{} |
|
a.Data = resp |
|
type TempData struct { |
|
Uid int `gorm:"column:UID"` |
|
Amount int64 `gorm:"column:total_reward"` |
|
RechargeAmount int64 `gorm:"column:total_recharge"` |
|
} |
|
var ret []TempData |
|
if req.Type == 1 { |
|
err := db.Mysql().QueryCountBySql(fmt.Sprintf("select count(*) from (SELECT count(*) FROM share_detail WHERE FROM_UNIXTIME(Time, '%%Y-%%m-%%d') = CURDATE() and up = %d GROUP BY UID ORDER BY SUM(reward) DESC)a", a.UID), &resp.Count) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
} |
|
err = db.Mysql().QueryBySql(fmt.Sprintf("SELECT UID, SUM(reward) AS total_reward, SUM(recharge_amount) AS total_recharge FROM share_detail WHERE up = %d and FROM_UNIXTIME(Time, '%%Y-%%m-%%d') = CURDATE() GROUP BY UID ORDER BY total_reward DESC limit %d,%d", a.UID, req.Page, req.Size), &ret) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
} |
|
for _, item := range ret { |
|
resp.TodayRewardList = append(resp.TodayRewardList, values.RewardInfo{ |
|
UID: item.Uid, |
|
Amount: item.Amount, |
|
}) |
|
} |
|
} else if req.Type == 2 { |
|
err := db.Mysql().QueryCountBySql(fmt.Sprintf("select count(*) from (SELECT count(*) FROM share_detail where up = %d GROUP BY UID ORDER BY SUM(reward) DESC)a", a.UID), &resp.Count) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
} |
|
err = db.Mysql().QueryBySql(fmt.Sprintf("SELECT UID, SUM(reward) AS total_reward, SUM(recharge_amount) AS total_recharge FROM share_detail where up = %d GROUP BY UID ORDER BY total_reward DESC limit %d,%d", a.UID, req.Page, req.Size), &ret) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
} |
|
for _, item := range ret { |
|
resp.RewardList = append(resp.RewardList, values.RewardInfo{ |
|
UID: item.Uid, |
|
Amount: item.Amount, |
|
}) |
|
} |
|
} else if req.Type == 3 { |
|
err := db.Mysql().QueryCountBySql(fmt.Sprintf("select count(*) from (SELECT count(*) FROM share_detail where up = %d GROUP BY UID ORDER BY SUM(recharge_amount) DESC)a", a.UID), &resp.Count) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
} |
|
err = db.Mysql().QueryBySql(fmt.Sprintf("SELECT UID, SUM(reward) AS total_reward, SUM(recharge_amount) AS total_recharge FROM share_detail where up = %d GROUP BY UID ORDER BY total_recharge DESC limit %d,%d", a.UID, req.Page, req.Size), &ret) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
} |
|
for _, item := range ret { |
|
user, _ := call.GetUserXInfo(item.Uid, "birth") |
|
resp.InviteList = append(resp.InviteList, values.InviteInfo{ |
|
UID: item.Uid, |
|
RechargeAmount: item.RechargeAmount, |
|
RegisterTime: user.Birth, |
|
}) |
|
} |
|
} |
|
} |
|
|
|
func GetActivityCode(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.GetActivityCodeReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
resp := &values.GetActivityCodeResp{} |
|
a.Data = resp |
|
channel := call.GetChannelByID(a.Channel) |
|
if channel != nil { |
|
resp.ShareLink += channel.URL + "?code=" + "xxxxxx" |
|
} |
|
a.GetUID() |
|
if a.UID <= 0 { |
|
return |
|
} |
|
code, err := call.GetActivityShareCode(a.UID, req.ActivityId) |
|
if err != nil { |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
if channel != nil { |
|
resp.ShareLink = channel.URL + "?code=" + code |
|
if a.Prefix != "" { |
|
resp.ShareLink = a.Prefix + "." + resp.ShareLink |
|
} else { |
|
resp.ShareLink = "www." + resp.ShareLink |
|
} |
|
} |
|
} |
|
|
|
func SharePlatformInfo(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
resp := &values.SharePlatformResp{ |
|
InviteReward: values.ShareTotalInviteReward, |
|
BetReward: values.ShareTotalBetReward, |
|
} |
|
a.Data = resp |
|
|
|
resp.TotalReward = resp.InviteReward + resp.BetReward |
|
resp.Rank = values.ShareRank |
|
} |
|
|
|
func ShareWithdraw(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.ShareWithdrawReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
if req.Opt < 1 || req.Opt > 2 { |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
con := call.GetConfigShareSys() |
|
log.Debug("player %d ShareWithdraw,con:%+v", a.UID, con) |
|
if con == nil { |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
shareInfo := call.GetShareInfo(a.UID) |
|
if shareInfo.ID <= 0 { |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
availableReward := shareInfo.AvailableReward |
|
if availableReward < con.WithdrawLimit { |
|
a.Code = values.CodeParam |
|
a.Msg = fmt.Sprintf("Minimum withdrawal requirement is %d.", con.WithdrawLimit/common.DecimalDigits) |
|
return |
|
} |
|
if req.Amount > availableReward { |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
|
|
// 直接到余额 |
|
if req.Opt == 1 { |
|
rows, err := db.Mysql().UpdateResW(&common.ShareInfo{}, map[string]interface{}{"available_reward": gorm.Expr("available_reward - ?", req.Amount)}, |
|
fmt.Sprintf("available_reward = %d and uid = %d", availableReward, a.UID)) |
|
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, |
|
Type: common.CurrencyINR, |
|
ChannelID: a.Channel, |
|
Value: req.Amount, |
|
Event: common.CurrencyEventShareWithdraw, |
|
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceShare, req.Amount), |
|
}, |
|
}) |
|
return |
|
} |
|
|
|
ip := a.GetRemoteIP() |
|
payInfo, code := NewWithdraw(&values.WithdrawReq{PayAccount: req.PayAccount}, a.UID, ip, a.UUID) |
|
if code != values.CodeOK { |
|
a.Code = code |
|
a.Msg = payInfo |
|
return |
|
} |
|
|
|
if len(payInfo) > 500 { |
|
a.Code = values.CodeParam |
|
a.Msg = "Withdrawal information too long." |
|
return |
|
} |
|
|
|
re := call.GetRechargeInfo(a.UID) |
|
now := time.Now().Unix() |
|
if re.ID == 0 { |
|
re.LastWithdraw = now |
|
if err := db.Mysql().Create(re); err != nil { |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
} else { |
|
u := map[string]interface{}{"last_withdraw": now} |
|
if !util.IsSameDayTimeStamp(now, re.LastWithdraw) { |
|
u["withdraw_count"] = 0 |
|
u["day_withdraw"] = 0 |
|
} |
|
rows, err := db.Mysql().UpdateRes(&common.RechargeInfo{UID: a.UID, LastWithdraw: re.LastWithdraw}, u) |
|
if err != nil || rows == 0 { |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
} |
|
|
|
orderID := util.NewOrderID(a.UID) |
|
|
|
vipCon := call.GetVipCon(a.UID) |
|
realAmount := req.Amount // 实际打款 |
|
if con != nil && vipCon.Fee > 0 { |
|
realAmount = common.RoundCurrency(common.CurrencyINR, (1000-int64(vipCon.Fee))*realAmount/1000) |
|
} |
|
rows, err := db.Mysql().UpdateResW(&common.ShareInfo{}, map[string]interface{}{"available_reward": gorm.Expr("available_reward - ?", req.Amount)}, |
|
fmt.Sprintf("available_reward = %d and uid = %d", availableReward, a.UID)) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
if rows == 0 { |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
|
|
order := &common.WithdrawOrder{ |
|
UID: int(a.UID), |
|
OrderID: orderID, |
|
APIPayID: "", |
|
// ProductID: one.ID, |
|
Extra: "share", |
|
CreateTime: time.Now().Unix(), |
|
Amount: realAmount, |
|
WithdrawCash: req.Amount, |
|
Status: uint8(common.StatusROrderCreate), |
|
PaySource: common.PaySourceModulePay, |
|
Event: int(common.CurrencyEventWithDraw), |
|
CurrencyType: common.CurrencyINR, |
|
PayAccount: payInfo, |
|
ChannelID: a.Channel, |
|
UPI: -1, |
|
OrderType: common.WithdrawOrderTypeShare, |
|
} |
|
if err := db.Mysql().Create(order); err != nil { |
|
log.Error("player %v create withdraw order fail err:%v", a.UID, err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
u := map[string]interface{}{} |
|
u["withdrawing_cash"] = gorm.Expr("withdrawing_cash + ?", req.Amount) |
|
u["withdraw_count"] = gorm.Expr("withdraw_count + ?", 1) |
|
u["total_withdrawing"] = gorm.Expr("total_withdrawing + ?", realAmount) |
|
u["day_withdraw"] = gorm.Expr("day_withdraw + ?", realAmount) |
|
db.Mysql().Update(&common.RechargeInfo{UID: a.UID}, u) |
|
|
|
a.Data = values.ShareWithdrawResp{Available: availableReward - req.Amount} |
|
|
|
call.PushRed(a.UID, pb.RedPointModule_RedPointShare, uint32(0)) |
|
|
|
} |
|
|
|
// func ShareReference(c *gin.Context) { |
|
// a := app.NewApp(c) |
|
// defer func() { |
|
// a.Response() |
|
// }() |
|
// req := new(values.ShareReferenceReq) |
|
// if !a.S(req) { |
|
// return |
|
// } |
|
// if req.Num > 100 { |
|
// req.Num = 100 |
|
// } |
|
// resp := &values.ShareReferenceResp{} |
|
// a.Data = resp |
|
|
|
// a.GetUID() |
|
// if a.UID == 0 { |
|
// return |
|
// } |
|
// q := elastic.NewBoolQuery() |
|
// if req.Start > 0 { |
|
// q.Filter(elastic.NewRangeQuery("Time").Gte(req.Start)) |
|
// } |
|
// if req.End > 0 { |
|
// q.Filter(elastic.NewRangeQuery("Time").Lt(req.End)) |
|
// } |
|
// q.Filter(elastic.NewTermQuery("Up", a.UID)) |
|
// db.ES().QueryList(common.ESIndexShareProfitRecord, req.Page, req.Num, q, &resp.List) |
|
// resp.TotalBet = db.ES().SumByInt64(common.ESIndexShareProfitRecord, "DownBet", q) + db.ES().SumByInt64(common.ESIndexShareProfitRecord, "Bet", q) |
|
// resp.TotalReward = db.ES().SumByInt64(common.ESIndexShareProfitRecord, "Reward", q) |
|
// } |
|
|
|
// func ShareReport(c *gin.Context) { |
|
// a := app.NewApp(c) |
|
// defer func() { |
|
// a.Response() |
|
// }() |
|
// req := new(values.ShareReportReq) |
|
// if !a.S(req) { |
|
// return |
|
// } |
|
// if req.Num > 100 { |
|
// req.Num = 100 |
|
// } |
|
// resp := &values.ShareReportResp{} |
|
// a.Data = resp |
|
|
|
// a.GetUID() |
|
// if a.UID == 0 { |
|
// return |
|
// } |
|
// q := elastic.NewBoolQuery() |
|
// if req.Start > 0 { |
|
// q.Filter(elastic.NewRangeQuery("Time").Gte(req.Start)) |
|
// } |
|
// if req.End > 0 { |
|
// q.Filter(elastic.NewRangeQuery("Time").Lt(req.End)) |
|
// } |
|
// q.Filter(elastic.NewTermQuery("UID", a.UID)) |
|
// db.ES().QueryList(common.ESIndexShareProfitReport, req.Page, req.Num, q, &resp.List, "Time", false) |
|
// today := &common.ShareInfo{UID: a.UID} |
|
// db.Mysql().Get(today) |
|
// if today.TodayAgents > 0 { |
|
// resp.List = append([]common.ESShareProfitReport{{ |
|
// UID: a.UID, |
|
// Regist: today.TodayAgents, |
|
// Bet: today.TodayAgentsBet, |
|
// Level: today.Level, |
|
// Reward: today.TodayReward, |
|
// Date: time.Now().Format("20060102"), |
|
// Time: time.Now().Unix(), |
|
// }}, resp.List...) |
|
// } |
|
// } |
|
|
|
// func ShareTransfer(c *gin.Context) { |
|
// a := app.NewApp(c) |
|
// defer func() { |
|
// a.Response() |
|
// }() |
|
// req := new(values.ShareTransferReq) |
|
// if !a.S(req) { |
|
// return |
|
// } |
|
// if req.Num > 100 { |
|
// req.Num = 100 |
|
// } |
|
|
|
// resp := &values.ShareTransferResp{} |
|
// a.Data = resp |
|
|
|
// a.GetUID() |
|
// if a.UID == 0 { |
|
// return |
|
// } |
|
|
|
// sql := fmt.Sprintf("uid = %d", a.UID) |
|
// // q := elastic.NewBoolQuery() |
|
// if req.Start > 0 { |
|
// // q.Filter(elastic.NewRangeQuery("Time").Gte(req.Start)) |
|
// sql += fmt.Sprintf(" and create_time>=%d", req.Start) |
|
// } |
|
// if req.End > 0 { |
|
// sql += fmt.Sprintf(" and create_time<%d", req.End) |
|
// // q.Filter(elastic.NewRangeQuery("Time").Lt(req.End)) |
|
// } |
|
// // q.Filter(elastic.NewTermQuery("UID", a.UID)) |
|
// db.Mysql().QueryListW(req.Page, req.Num, "create_time desc", &common.ShareOrder{}, &resp.List, sql) |
|
// // db.ES().QueryList(common.ESIndexShareProfitTransfer, req.Page, req.Num, q, &resp.List) |
|
// }
|
|
|