支付修改

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
cd ../..
#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 gameserver 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

@ -243,6 +243,7 @@ type ConfigPayChannels struct {
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"`
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 {

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

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

@ -202,41 +202,43 @@ func WithdrawSuccess(w PayWay) {
}
func PayFail(w PayWay) {
failWeight := config.GetConfig().Pay.PayFailWeight
if failWeight <= 0 {
return
}
PayWeightLock.Lock()
for _, v := range call.ConfigPayChannels {
if v.ChannelID == int(w) {
v.PayPer -= failWeight
break
}
}
sort.Slice(call.ConfigPayChannels, func(i, j int) bool {
return call.ConfigPayChannels[i].PayPer > call.ConfigPayChannels[j].PayPer
})
PayWeightLock.Unlock()
AddPayChannel(int(w), -failWeight)
// failWeight := config.GetConfig().Pay.PayFailWeight
// if failWeight <= 0 {
// return
// }
// PayWeightLock.Lock()
// for _, v := range call.ConfigPayChannels {
// if v.ChannelID == int(w) {
// v.PayPer -= failWeight
// break
// }
// }
// sort.Slice(call.ConfigPayChannels, func(i, j int) bool {
// return call.ConfigPayChannels[i].PayPer > call.ConfigPayChannels[j].PayPer
// })
// PayWeightLock.Unlock()
// AddPayChannel(int(w), -failWeight)
// call.AddChannel(int(w), false)
}
func PayCallback(w PayWay) {
successWeight := config.GetConfig().Pay.PaySuccessWeight
if successWeight <= 0 {
return
}
PayWeightLock.Lock()
for _, v := range call.ConfigPayChannels {
if v.ChannelID == int(w) {
v.PayPer += successWeight
break
}
}
sort.Slice(call.ConfigPayChannels, func(i, j int) bool {
return call.ConfigPayChannels[i].PayPer > call.ConfigPayChannels[j].PayPer
})
PayWeightLock.Unlock()
AddPayChannel(int(w), successWeight)
func PaySuccess(w PayWay) {
// successWeight := config.GetConfig().Pay.PaySuccessWeight
// if successWeight <= 0 {
// return
// }
// PayWeightLock.Lock()
// for _, v := range call.ConfigPayChannels {
// if v.ChannelID == int(w) {
// v.PayPer += successWeight
// break
// }
// }
// sort.Slice(call.ConfigPayChannels, func(i, j int) bool {
// return call.ConfigPayChannels[i].PayPer > call.ConfigPayChannels[j].PayPer
// })
// PayWeightLock.Unlock()
// 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) {
@ -148,7 +151,7 @@ func PlayerRecharge(c *gin.Context) {
return
}
log.Debug("player %v recharge:%+v", a.UID, *req)
call.AddChannel(req.PayChannel, false)
if req.CurrencyType == 0 {
req.CurrencyType = common.CurrencyINR
}
@ -162,28 +165,11 @@ func PlayerRecharge(c *gin.Context) {
} else {
req.Amount = common.RoundCurrency(req.CurrencyType, req.Amount)
}
// product := call.GetConfigPayProductByID(req.ProductID)
// if product == nil {
// 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)) {
payCount, _ := db.Redis().GetInt(common.GetRedisKeyPlayerPayCount(a.UID))
// 判断充值间隔 同渠道限制3秒拉一单 30秒限制4单
if db.Redis().Exist(common.GetRedisKeyPlayerChannelPayInterval(req.PayChannel, a.UID)) && payCount >= 4 {
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
}
// if req.UserPhone == "" {
@ -210,14 +196,18 @@ func PlayerRecharge(c *gin.Context) {
uid := a.UID
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 {
util.Go(func() {
call.RechargeCallback(payImp.Order, true, "", "")
})
}
// if !config.GetBase().Release && req.PayChannel == config.GetConfig().Web.TestPay {
// util.Go(func() {
// call.RechargeCallback(payImp.Order, true, "", "")
// })
// }
}
func NewRechargeImp(req *values.RechargeReq, uid, cid int, ip string) *RechargeImp {

Loading…
Cancel
Save