|
|
|
|
@ -14,6 +14,7 @@ import ( |
|
|
|
|
"server/natsClient" |
|
|
|
|
"server/pb" |
|
|
|
|
"server/util" |
|
|
|
|
"sort" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/gogo/protobuf/proto" |
|
|
|
|
@ -40,7 +41,7 @@ func GetRechargeInfo(uid int) *common.RechargeInfo { |
|
|
|
|
|
|
|
|
|
// Recharge 内部充值调用
|
|
|
|
|
func Recharge(data *pb.InnerRechargeReq) (*pb.InnerRechargeResp, error) { |
|
|
|
|
to, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
|
|
|
|
to, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
|
|
|
|
defer cancel() |
|
|
|
|
module := "pay" |
|
|
|
|
if data.PaySource == common.PaySourceBlockPay { |
|
|
|
|
@ -173,10 +174,13 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s |
|
|
|
|
// 第三步,给玩家发货
|
|
|
|
|
// 正常商城充值
|
|
|
|
|
var bonus = r.Bonus |
|
|
|
|
discountOriginAmount := r.Amount // 折扣前的价格
|
|
|
|
|
if r.ProductID == 0 { |
|
|
|
|
amount := PayExtra(r) // 判断特殊购买,如优惠券
|
|
|
|
|
if amount == 0 { |
|
|
|
|
amount = r.Amount |
|
|
|
|
} else { |
|
|
|
|
discountOriginAmount = amount |
|
|
|
|
} |
|
|
|
|
t := common.CurrencyResourceRecharge |
|
|
|
|
if notCharge && bonus > 0 { // 首充
|
|
|
|
|
@ -213,28 +217,34 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s |
|
|
|
|
UploadActivityData(uid, common.ActivityIDRecharge, common.ActivityDataJoin, bonus) |
|
|
|
|
} |
|
|
|
|
if r.ProductID == 0 { |
|
|
|
|
ticket := GetConfigDiscountTicketByAmount(r.Amount) |
|
|
|
|
ticket := GetConfigDiscountTicketByAmount(discountOriginAmount) |
|
|
|
|
log.Info("ticket:%v", ticket) |
|
|
|
|
if ticket.Id > 0 { |
|
|
|
|
// 赠送优惠券
|
|
|
|
|
products := GetConfigPayProductByActivityID(0) |
|
|
|
|
nextProduct := &common.ConfigPayProduct{} |
|
|
|
|
for _, product := range products { |
|
|
|
|
if product.Amount > r.Amount && nextProduct.Amount < product.Amount { |
|
|
|
|
nextProduct = product |
|
|
|
|
tickets := GetConfigDiscountTicket() |
|
|
|
|
sort.Slice(tickets, func(i, j int) bool { |
|
|
|
|
return tickets[i].RechargeAmount < tickets[j].RechargeAmount |
|
|
|
|
}) |
|
|
|
|
// 获取下一档
|
|
|
|
|
nextIdx := -1 |
|
|
|
|
for idx, product := range tickets { |
|
|
|
|
if product.RechargeAmount == discountOriginAmount { |
|
|
|
|
nextIdx = idx + 1 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
var nextTicket common.ConfigDiscountTicket |
|
|
|
|
if nextProduct != nil { |
|
|
|
|
nextTicket = GetConfigDiscountTicketByAmount(nextProduct.Amount) |
|
|
|
|
var nextTicket = ticket |
|
|
|
|
if len(tickets) > nextIdx && nextIdx != -1 { |
|
|
|
|
nextTicket = tickets[nextIdx] |
|
|
|
|
} |
|
|
|
|
log.Info("nextTicket:%v", nextTicket) |
|
|
|
|
count := ticket.CurProb + ticket.NextProb |
|
|
|
|
val := rand.Intn(count) |
|
|
|
|
log.Info("val:%v", val) |
|
|
|
|
if val <= ticket.CurProb { |
|
|
|
|
AddUserDiscountTicket(uid, ticket.RechargeAmount, ticket.DiscountAmount, -1) |
|
|
|
|
AddUserDiscountTicket(uid, ticket.DiscountAmount, ticket.RechargeAmount, -1) |
|
|
|
|
SendMailWithContent(uid, SystemTitle, fmt.Sprintf(EmailDiscount, ticket.RechargeAmount/common.DecimalDigits, ticket.DiscountAmount/common.DecimalDigits)) |
|
|
|
|
} else if nextTicket.Id > 0 { |
|
|
|
|
AddUserDiscountTicket(uid, nextTicket.RechargeAmount, nextTicket.DiscountAmount, -1) |
|
|
|
|
AddUserDiscountTicket(uid, ticket.DiscountAmount, ticket.RechargeAmount, -1) |
|
|
|
|
SendMailWithContent(uid, SystemTitle, fmt.Sprintf(EmailDiscount, ticket.RechargeAmount/common.DecimalDigits, ticket.DiscountAmount/common.DecimalDigits)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|