@ -6,6 +6,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"math/rand"
"net/http"
"net/http"
"server/common"
"server/common"
"server/config"
"server/config"
@ -13,6 +14,7 @@ import (
"server/natsClient"
"server/natsClient"
"server/pb"
"server/pb"
"server/util"
"server/util"
"sort"
"time"
"time"
"github.com/gogo/protobuf/proto"
"github.com/gogo/protobuf/proto"
@ -39,7 +41,7 @@ func GetRechargeInfo(uid int) *common.RechargeInfo {
// Recharge 内部充值调用
// Recharge 内部充值调用
func Recharge ( data * pb . InnerRechargeReq ) ( * pb . InnerRechargeResp , error ) {
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 ( )
defer cancel ( )
module := "pay"
module := "pay"
if data . PaySource == common . PaySourceBlockPay {
if data . PaySource == common . PaySourceBlockPay {
@ -99,11 +101,6 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s
log . Error ( "get recharage info err:%v,uid:%v" , err , r . UID )
log . Error ( "get recharage info err:%v,uid:%v" , err , r . UID )
return err
return err
}
}
// product := GetConfigPayProductByID(r.ProductID)
// if product == nil {
// log.Error("unkonwn product:%d", r.ProductID)
// return errors.New("unkonwn product")
// }
amount := r . Amount
amount := r . Amount
notCharge := re . TotalRecharge == 0
notCharge := re . TotalRecharge == 0
@ -115,31 +112,9 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s
dayR = true
dayR = true
re . DayRecharge += amount
re . DayRecharge += amount
}
}
// if util.IsSameWeek(re.LastRecharge, now) || re.LastRecharge == 0 {
// weekR = true
// re.WeekRecharge += amount
// }
re . LastRecharge = now
re . LastRecharge = now
re . TotalRechargeCount ++
re . TotalRechargeCount ++
// re.ProductPayCount = common.AddProductPayCount(re.ProductPayCount, r.ProductID)
// if product.IsFirstPayProduct() {
// json.Unmarshal([]byte(re.ProductFirstPay), &re.ProductFirstPaySub)
// if util.SliceContain(re.ProductFirstPaySub, product.ProductID) { // 该商品已购买,替换为可多次购买的同价值商品
// product = GetConfigPayProductShopByAmount(product.Amount)
// if product == nil {
// return errors.New("product invalid")
// }
// } else {
// re.ProductFirstPaySub = append(re.ProductFirstPaySub, int(product.ProductID))
// str, _ := json.Marshal(re.ProductFirstPaySub)
// re.ProductFirstPay = string(str)
// }
// }
// var per int64 = 0
// level := GetConfigFirstPayLevelByAmount(r.Amount)
// playerPayData := GetPlayerPayData(uid)
tx := db . Mysql ( ) . Begin ( )
tx := db . Mysql ( ) . Begin ( )
defer func ( ) {
defer func ( ) {
if err == nil {
if err == nil {
@ -165,27 +140,6 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s
return nil
return nil
}
}
// 更新paydata
// if playerPayData.ID == 0 {
// err = tx.Model(playerPayData).Create(playerPayData).Error
// if err != nil {
// log.Error("err:%v", err)
// return
// }
// } else {
// playerPayData.SubFirstPay = append(playerPayData.SubFirstPay, level)
// updatePayData, _ := json.Marshal(playerPayData.SubFirstPay)
// res := tx.Model(playerPayData).Where("id = ? and first_pay = ?", playerPayData.ID, playerPayData.FirstPay).Updates(map[string]interface{}{"first_pay": string(updatePayData)})
// if res.RowsAffected == 0 {
// log.Error("err:%v", err)
// return errors.New("update payData fail")
// }
// if err != nil {
// log.Error("update payData err:%v", err)
// return err
// }
// }
// 第二步,更新recharge_info
// 第二步,更新recharge_info
payData := & common . ESPlayerPayData { UID : uid , Channel : r . ChannelID , Type : 1 , CurrencyType : r . CurrencyType }
payData := & common . ESPlayerPayData { UID : uid , Channel : r . ChannelID , Type : 1 , CurrencyType : r . CurrencyType }
if re . ID == 0 {
if re . ID == 0 {
@ -204,19 +158,13 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s
"total_recharge_count" : gorm . Expr ( "total_recharge_count + 1" ) ,
"total_recharge_count" : gorm . Expr ( "total_recharge_count + 1" ) ,
"total_recharge" : gorm . Expr ( "total_recharge + ?" , amount ) ,
"total_recharge" : gorm . Expr ( "total_recharge + ?" , amount ) ,
"last_recharge" : now ,
"last_recharge" : now ,
// "product_paycount": re.ProductPayCount,
// "product_firstpay": re.ProductFirstPay,
}
}
if dayR {
if dayR {
updates [ "day_recharge" ] = gorm . Expr ( "day_recharge + ?" , amount )
updates [ "day_recharge" ] = gorm . Expr ( "day_recharge + ?" , amount )
} else {
} else {
updates [ "day_recharge" ] = amount
updates [ "day_recharge" ] = amount
}
}
// if weekR {
// updates["week_recharge"] = gorm.Expr("week_recharge + ?", amount)
// } else {
// updates["week_recharge"] = amount
// }
err = tx . Model ( re ) . Where ( "uid=?" , re . UID ) . Updates ( updates ) . Error
err = tx . Model ( re ) . Where ( "uid=?" , re . UID ) . Updates ( updates ) . Error
}
}
if err != nil {
if err != nil {
@ -226,32 +174,14 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s
// 第三步,给玩家发货
// 第三步,给玩家发货
// 正常商城充值
// 正常商城充值
var bonus = r . Bonus
var bonus = r . Bonus
discountOriginAmount := r . Amount // 折扣前的价格
if r . ProductID == 0 {
if r . ProductID == 0 {
amount := PayExtra ( r ) // 判断特殊购买,如优惠券
amount := PayExtra ( r ) // 判断特殊购买,如优惠券
if amount == 0 {
if amount == 0 {
amount = r . Amount
amount = r . Amount
} else {
discountOriginAmount = amount
}
}
// cb := &common.CurrencyBalance{
// UID: r.UID,
// Type: r.CurrencyType,
// Value: amount,
// Event: common.CurrencyEvent(r.Event),
// Exs1: r.OrderID,
// Exi1: int(amount), // 充值金额传递
// Exi2: r.ProductID,
// NeedBet: GetConfigCurrencyResourceNeedBet(common.CurrencyResourceRecharge, amount),
// }
// err = UpdateCurrencyProReal(&common.UpdateCurrency{
// CurrencyBalance: cb,
// }).Err
// if err != nil {
// return
// }
// } else {
// per := GetConfigFirstPayPerByAmount(notCharge, amount)
// if per > 0 {
// bonus = amount * per / 100
// }
t := common . CurrencyResourceRecharge
t := common . CurrencyResourceRecharge
if notCharge && bonus > 0 { // 首充
if notCharge && bonus > 0 { // 首充
t = common . CurrencyResourceFirstRecharge
t = common . CurrencyResourceFirstRecharge
@ -282,10 +212,46 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s
// 以上逻辑为处理订单,更新玩家充值信息,给玩家加钱。
// 以上逻辑为处理订单,更新玩家充值信息,给玩家加钱。
// 下面逻辑处理活动,数据统计等,不影响以上效率,接下来逻辑并发执行
// 下面逻辑处理活动,数据统计等,不影响以上效率,接下来逻辑并发执行
util . Go ( func ( ) {
util . Go ( func ( ) {
SendNR ( r . UID , int ( pb . ServerCommonResp_CommonUserInfoResp ) , & pb . PlayerBalanceResp { } , "common" )
// 更新活动数据上传
// 更新活动数据上传
if bonus > 0 {
if bonus > 0 {
UploadActivityData ( uid , common . ActivityIDRecharge , common . ActivityDataJoin , bonus )
UploadActivityData ( uid , common . ActivityIDRecharge , common . ActivityDataJoin , bonus )
}
}
if r . ProductID == 0 {
ticket := GetConfigDiscountTicketByAmount ( discountOriginAmount )
log . Info ( "ticket:%v" , ticket )
if ticket . Id > 0 {
// 赠送优惠券
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 = ticket
if len ( tickets ) > nextIdx && nextIdx != - 1 {
nextTicket = tickets [ nextIdx ]
}
log . Info ( "nextTicket:%v" , nextTicket )
count := ticket . CurProb + ticket . NextProb
if count > 0 {
val := rand . Intn ( count )
log . Info ( "val:%v" , val )
if val <= ticket . CurProb {
AddUserDiscountTicket ( uid , ticket . DiscountAmount , ticket . RechargeAmount , - 1 , 0 , true )
SendMailWithContent ( uid , SystemTitle , fmt . Sprintf ( EmailDiscount , ticket . DiscountAmount / common . DecimalDigits , ticket . RechargeAmount / common . DecimalDigits ) )
} else if nextTicket . Id > 0 {
AddUserDiscountTicket ( uid , nextTicket . DiscountAmount , nextTicket . RechargeAmount , - 1 , 1 , true )
SendMailWithContent ( uid , SystemTitle , fmt . Sprintf ( EmailDiscount , ticket . DiscountAmount / common . DecimalDigits , ticket . RechargeAmount / common . DecimalDigits ) )
}
}
}
}
user , _ := GetUserInfo ( uid )
user , _ := GetUserInfo ( uid )
PayActivity ( r , notCharge , user )
PayActivity ( r , notCharge , user )
if r . Event != int ( common . CurrencyEventGMRecharge ) {
if r . Event != int ( common . CurrencyEventGMRecharge ) {