@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"server/common"
"server/config"
@ -99,11 +100,6 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s
log . Error ( "get recharage info err:%v,uid:%v" , err , r . UID )
return err
}
// product := GetConfigPayProductByID(r.ProductID)
// if product == nil {
// log.Error("unkonwn product:%d", r.ProductID)
// return errors.New("unkonwn product")
// }
amount := r . Amount
notCharge := re . TotalRecharge == 0
@ -115,31 +111,9 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s
dayR = true
re . DayRecharge += amount
}
// if util.IsSameWeek(re.LastRecharge, now) || re.LastRecharge == 0 {
// weekR = true
// re.WeekRecharge += amount
// }
re . LastRecharge = now
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 ( )
defer func ( ) {
if err == nil {
@ -165,27 +139,6 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s
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
payData := & common . ESPlayerPayData { UID : uid , Channel : r . ChannelID , Type : 1 , CurrencyType : r . CurrencyType }
if re . ID == 0 {
@ -204,19 +157,13 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s
"total_recharge_count" : gorm . Expr ( "total_recharge_count + 1" ) ,
"total_recharge" : gorm . Expr ( "total_recharge + ?" , amount ) ,
"last_recharge" : now ,
// "product_paycount": re.ProductPayCount,
// "product_firstpay": re.ProductFirstPay,
}
if dayR {
updates [ "day_recharge" ] = gorm . Expr ( "day_recharge + ?" , amount )
} else {
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
}
if err != nil {
@ -231,27 +178,6 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s
if amount == 0 {
amount = r . 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
if notCharge && bonus > 0 { // 首充
t = common . CurrencyResourceFirstRecharge
@ -286,6 +212,32 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s
if bonus > 0 {
UploadActivityData ( uid , common . ActivityIDRecharge , common . ActivityDataJoin , bonus )
}
if r . ProductID == 0 {
ticket := GetConfigDiscountTicketByAmount ( r . Amount )
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
}
}
var nextTicket common . ConfigDiscountTicket
if nextProduct != nil {
nextTicket = GetConfigDiscountTicketByAmount ( nextProduct . Amount )
}
count := ticket . CurProb + ticket . NextProb
val := rand . Intn ( count )
if val <= ticket . CurProb {
AddUserDiscountTicket ( uid , ticket . RechargeAmount , ticket . DiscountAmount , - 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 )
SendMailWithContent ( uid , SystemTitle , fmt . Sprintf ( EmailDiscount , ticket . RechargeAmount / common . DecimalDigits , ticket . DiscountAmount / common . DecimalDigits ) )
}
}
}
user , _ := GetUserInfo ( uid )
PayActivity ( r , notCharge , user )
if r . Event != int ( common . CurrencyEventGMRecharge ) {