支付修改

dev
mofangmin 1 year ago
parent 89adb1779f
commit d51ee18677
  1. 55
      call/redis.go
  2. 4
      cmd/build.sh
  3. 1
      common/config.go
  4. 10
      common/redis_keys.go
  5. 2
      modules/pay/base/callback.go
  6. 68
      modules/pay/values/values.go
  7. 46
      modules/web/handler/recharge.go

@ -0,0 +1,55 @@
package call
import (
"context"
"fmt"
"server/db"
"time"
)
// AddChannel 添加渠道
func AddChannel(channelID int, isSuccess bool) {
ctx := context.Background()
client := db.Redis().GetRedis()
totalKey := fmt.Sprintf("channel_total_%v", channelID)
successKey := fmt.Sprintf("channel_success_%v", channelID)
// 增加总订单数
client.Incr(ctx, totalKey)
// 如果订单成功,增加成功订单数
if isSuccess {
client.Incr(ctx, successKey)
}
// 设置过期时间为10分钟
client.Expire(ctx, totalKey, 10*time.Minute)
client.Expire(ctx, successKey, 10*time.Minute)
}
// GetChannelStatus 获取渠道状态
func GetChannelStatus(channelID int) int {
ctx := context.Background()
client := db.Redis().GetRedis()
totalKey := fmt.Sprintf("channel_total_%v", channelID)
successKey := fmt.Sprintf("channel_success_%v", channelID)
totalOrders, _ := client.Get(ctx, totalKey).Int64()
successOrders, _ := client.Get(ctx, successKey).Int64()
// 如果总订单数小于10,状态为绿色
if totalOrders < 10 {
return 1
}
// 根据成功订单数判断渠道状态
if successOrders >= 5 {
return 1
} else if successOrders >= 3 {
return 2
} else {
return 3
}
}

@ -8,5 +8,5 @@ cd pb/proto
# go generate # go generate
cd ../.. cd ../..
#go build main.go #go build main.go
#CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o indiaprovider main.go CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o indiaprovider main.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gameserver main.go #CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gameserver main.go

@ -243,6 +243,7 @@ type ConfigPayChannels struct {
PayUp int64 `gorm:"column:pay_up;type:bigint(20);default:1;comment:代收上限" json:"PayUp" web:"pay_up"` PayUp int64 `gorm:"column:pay_up;type:bigint(20);default:1;comment:代收上限" json:"PayUp" web:"pay_up"`
CurrencyType CurrencyType `gorm:"column:currency_type;type:bigint(20);default:1;uniqueIndex:channel_id;comment:货币类型" json:"CurrencyType" web:"currency_type"` CurrencyType CurrencyType `gorm:"column:currency_type;type:bigint(20);default:1;uniqueIndex:channel_id;comment:货币类型" json:"CurrencyType" web:"currency_type"`
Kind int64 `gorm:"column:kind;type:bigint(20);default:1;comment:协议类型" json:"Kind" web:"kind"` Kind int64 `gorm:"column:kind;type:bigint(20);default:1;comment:协议类型" json:"Kind" web:"kind"`
PayStatus int `gorm:"-"` // 渠道状态 1 好 2 中等 3 差
} }
func (c *ConfigPayChannels) TableName() string { func (c *ConfigPayChannels) TableName() string {

@ -45,7 +45,8 @@ const (
// RedisKeyPlayerPay = "playerPay" // 玩家10分钟内付费拉起的渠道记录 // RedisKeyPlayerPay = "playerPay" // 玩家10分钟内付费拉起的渠道记录
RedisKeyPlayerPayInterval = "playerPayInterval" // 玩家拉单间隔限制 RedisKeyPlayerPayInterval = "playerPayInterval" // 玩家拉单间隔限制
RedisKeyGameCurrency = "gameCurrency" // 玩家进入游戏时选择的币种 RedisKeyGameCurrency = "gameCurrency" // 玩家进入游戏时选择的币种
RedisKeyPlayerRTP = "playerRtp" RedisKeyPlayerRTP = "playerRtp" // 玩家RTP
RedisKeyChannelOrder = "channelOrder" //
) )
const ( const (
@ -58,8 +59,11 @@ func GetRedisKeyGameCurrency(uid int) string {
return fmt.Sprintf("%v:%v", RedisKeyGameCurrency, uid) return fmt.Sprintf("%v:%v", RedisKeyGameCurrency, uid)
} }
func GetRedisKeyPlayerPayInterval(uid int) string { func GetRedisKeyPlayerPayCount(uid int) string {
return fmt.Sprintf("%v:%v", RedisKeyPlayerPayInterval, uid) return fmt.Sprintf("%v:%v:%v", RedisKeyPlayerPayInterval, uid)
}
func GetRedisKeyPlayerChannelPayInterval(channel, uid int) string {
return fmt.Sprintf("%v:%v:%v", RedisKeyPlayerPayInterval, uid, channel)
} }
// func GetRedisKeyPlayerPay(uid int) string { // func GetRedisKeyPlayerPay(uid int) string {

@ -49,7 +49,7 @@ func (b *Base) PayCallback(c *gin.Context) {
return return
} }
if success { if success {
values.PayCallback(b.Channel) values.PaySuccess(b.Channel)
} }
} }

@ -202,41 +202,43 @@ func WithdrawSuccess(w PayWay) {
} }
func PayFail(w PayWay) { func PayFail(w PayWay) {
failWeight := config.GetConfig().Pay.PayFailWeight // failWeight := config.GetConfig().Pay.PayFailWeight
if failWeight <= 0 { // if failWeight <= 0 {
return // return
} // }
PayWeightLock.Lock() // PayWeightLock.Lock()
for _, v := range call.ConfigPayChannels { // for _, v := range call.ConfigPayChannels {
if v.ChannelID == int(w) { // if v.ChannelID == int(w) {
v.PayPer -= failWeight // v.PayPer -= failWeight
break // break
} // }
} // }
sort.Slice(call.ConfigPayChannels, func(i, j int) bool { // sort.Slice(call.ConfigPayChannels, func(i, j int) bool {
return call.ConfigPayChannels[i].PayPer > call.ConfigPayChannels[j].PayPer // return call.ConfigPayChannels[i].PayPer > call.ConfigPayChannels[j].PayPer
}) // })
PayWeightLock.Unlock() // PayWeightLock.Unlock()
AddPayChannel(int(w), -failWeight) // AddPayChannel(int(w), -failWeight)
// call.AddChannel(int(w), false)
} }
func PayCallback(w PayWay) { func PaySuccess(w PayWay) {
successWeight := config.GetConfig().Pay.PaySuccessWeight // successWeight := config.GetConfig().Pay.PaySuccessWeight
if successWeight <= 0 { // if successWeight <= 0 {
return // return
} // }
PayWeightLock.Lock() // PayWeightLock.Lock()
for _, v := range call.ConfigPayChannels { // for _, v := range call.ConfigPayChannels {
if v.ChannelID == int(w) { // if v.ChannelID == int(w) {
v.PayPer += successWeight // v.PayPer += successWeight
break // break
} // }
} // }
sort.Slice(call.ConfigPayChannels, func(i, j int) bool { // sort.Slice(call.ConfigPayChannels, func(i, j int) bool {
return call.ConfigPayChannels[i].PayPer > call.ConfigPayChannels[j].PayPer // return call.ConfigPayChannels[i].PayPer > call.ConfigPayChannels[j].PayPer
}) // })
PayWeightLock.Unlock() // PayWeightLock.Unlock()
AddPayChannel(int(w), successWeight) // AddPayChannel(int(w), successWeight)
call.AddChannel(int(w), true)
} }
// 获取支付回调路径 // 获取支付回调路径

@ -107,6 +107,9 @@ func RechargeInfo(c *gin.Context) {
}) })
} }
} }
for _, channel := range resp.Channels {
channel.PayStatus = call.GetChannelStatus(channel.ChannelID)
}
} }
func RechargeHistory(c *gin.Context) { func RechargeHistory(c *gin.Context) {
@ -148,7 +151,7 @@ func PlayerRecharge(c *gin.Context) {
return return
} }
log.Debug("player %v recharge:%+v", a.UID, *req) log.Debug("player %v recharge:%+v", a.UID, *req)
call.AddChannel(req.PayChannel, false)
if req.CurrencyType == 0 { if req.CurrencyType == 0 {
req.CurrencyType = common.CurrencyINR req.CurrencyType = common.CurrencyINR
} }
@ -162,28 +165,11 @@ func PlayerRecharge(c *gin.Context) {
} else { } else {
req.Amount = common.RoundCurrency(req.CurrencyType, req.Amount) req.Amount = common.RoundCurrency(req.CurrencyType, req.Amount)
} }
payCount, _ := db.Redis().GetInt(common.GetRedisKeyPlayerPayCount(a.UID))
// product := call.GetConfigPayProductByID(req.ProductID) // 判断充值间隔 同渠道限制3秒拉一单 30秒限制4单
// if product == nil { if db.Redis().Exist(common.GetRedisKeyPlayerChannelPayInterval(req.PayChannel, a.UID)) && payCount >= 4 {
// log.Error("unknow product:%v", req.ProductID)
// a.Code = values.CodeParam
// a.Msg = "Activity is over"
// return
// }
// if !a.CanBuyProduct(product.ActivityID, product.ProductID) {
// return
// }
// paySource := req.PaySource
// if paySource >= common.PaySourceAll {
// a.Code = values.CodeParam
// log.Error("paysource err:%v", req.PaySource)
// return
// }
// 判断充值间隔
if db.Redis().Exist(common.GetRedisKeyPlayerPayInterval(a.UID)) {
a.Code = values.CodeParam a.Code = values.CodeParam
a.Msg = "You have an order to pay,please process first" a.Msg = "Requests are too frequent, please try again later"
return return
} }
// if req.UserPhone == "" { // if req.UserPhone == "" {
@ -210,14 +196,18 @@ func PlayerRecharge(c *gin.Context) {
uid := a.UID uid := a.UID
util.Go(func() { util.Go(func() {
db.Redis().SetData(common.GetRedisKeyPlayerPayInterval(uid), 1, 15*time.Second) db.Redis().SetData(common.GetRedisKeyPlayerChannelPayInterval(req.PayChannel, uid), 1, 3*time.Second)
db.Redis().Incr(common.GetRedisKeyPlayerPayCount(a.UID), 1)
if payCount == 0 {
db.Redis().Expire(common.GetRedisKeyPlayerPayCount(a.UID), 30*time.Second)
}
}) })
if !config.GetBase().Release && req.PayChannel == config.GetConfig().Web.TestPay { // if !config.GetBase().Release && req.PayChannel == config.GetConfig().Web.TestPay {
util.Go(func() { // util.Go(func() {
call.RechargeCallback(payImp.Order, true, "", "") // call.RechargeCallback(payImp.Order, true, "", "")
}) // })
} // }
} }
func NewRechargeImp(req *values.RechargeReq, uid, cid int, ip string) *RechargeImp { func NewRechargeImp(req *values.RechargeReq, uid, cid int, ip string) *RechargeImp {

Loading…
Cancel
Save