Compare commits

..

2 Commits

Author SHA1 Message Date
mofangmin eef18c22d3 支付需求开发 1 year ago
mofangmin d51ee18677 支付修改 1 year ago
  1. 14
      call/config.go
  2. 2
      call/pay.go
  3. 60
      call/redis.go
  4. 1
      common/config.go
  5. 11
      common/redis_keys.go
  6. 2
      modules/pay/base/callback.go
  7. 4
      modules/pay/gopay/values.go
  8. 72
      modules/pay/values/values.go
  9. 13
      modules/web/handler/firstpage.go
  10. 16
      modules/web/handler/game.go
  11. 47
      modules/web/handler/recharge.go

@ -732,7 +732,21 @@ func GetConfigGameList(num int, cond ...int) []*common.ConfigGameList {
if v.GameProvider == common.ProviderPG2 || v.GameProvider == common.ProviderJiLi2 {
continue
}
provider := -1
if v.GameProvider == common.ProviderJili {
provider = common.ProviderJiLi2
} else if v.GameProvider == common.ProviderPGSoft {
provider = common.ProviderPG2
}
if provider != -1 {
game := GetConfigGameListByGameID(provider, v.GameID)
if game != nil {
ret = append(ret, v)
continue
}
} else {
ret = append(ret, v)
}
}
sort.Slice(ret, func(i, j int) bool {
return ret[i].Sort > ret[j].Sort

@ -259,7 +259,7 @@ func RechargeCallback(r *common.RechargeOrder, success bool, payAccount, extra s
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))
SendMailWithContent(uid, SystemTitle, fmt.Sprintf(EmailDiscount, nextTicket.DiscountAmount/common.DecimalDigits, nextTicket.RechargeAmount/common.DecimalDigits))
}
}
}

@ -0,0 +1,60 @@
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)
// 检查键是否存在,如果不存在则设置过期时间
if client.Exists(ctx, totalKey).Val() == 0 {
client.Set(ctx, totalKey, 0, 10*time.Minute)
}
if client.Exists(ctx, successKey).Val() == 0 {
client.Set(ctx, successKey, 0, 10*time.Minute)
}
// 增加总订单数
client.Incr(ctx, totalKey)
// 如果订单成功,增加成功订单数
if isSuccess {
client.Incr(ctx, successKey)
}
}
// 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
}
}

@ -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 {

@ -44,8 +44,10 @@ const (
RedisKeyRealMail = "realMail" // 给玩家发真实邮件控制
// RedisKeyPlayerPay = "playerPay" // 玩家10分钟内付费拉起的渠道记录
RedisKeyPlayerPayInterval = "playerPayInterval" // 玩家拉单间隔限制
RedisKeyPlayerPayCount = "playerPayIntervalCount"
RedisKeyGameCurrency = "gameCurrency" // 玩家进入游戏时选择的币种
RedisKeyPlayerRTP = "playerRtp"
RedisKeyPlayerRTP = "playerRtp" // 玩家RTP
RedisKeyChannelOrder = "channelOrder" //
)
const (
@ -58,8 +60,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", RedisKeyPlayerPayCount, 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)
}
}

@ -1,8 +1,8 @@
package gopay
const (
payURL = "https://gooopay.online/api/recharge/create"
withdrawURL = "https://gooopay.online/api/deposit/create"
payURL = "https://rummylotus.online/api/recharge/create"
withdrawURL = "https://rummylotus.online/api/deposit/create"
mid = "2024100038"
key = "326eb5a2f78a4dacb4780104ba16030c"
)

@ -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)
}
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)
// 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 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)
}
// 获取支付回调路径

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"math/rand"
"server/call"
"server/common"
"server/db"
@ -65,16 +66,20 @@ func FirstPage(c *gin.Context) {
gameNum := req.GameNum
if strings.ToLower(v.Name) == "hot" {
gameNum = 100
}
if v.JumpType == 1 {
one.List = call.GetConfigGameList(gameNum, v.JumpID)
} else {
one.List = call.GetConfigGameList(gameNum, 0, v.JumpID)
}
} else {
one.List = call.GetConfigGameList(0, 0)
rand.Shuffle(len(one.List), func(i, j int) {
one.List[i], one.List[j] = one.List[j], one.List[i]
})
}
if gameNum != req.GameNum {
// rand.Shuffle(len(one.List), func(i, j int) {
// one.List[i], one.List[j] = one.List[j], one.List[i]
// })
if len(one.List) > req.GameNum {
one.List = one.List[:req.GameNum]
}

@ -2,6 +2,7 @@ package handler
import (
"fmt"
"math/rand"
"server/call"
"server/common"
"server/db"
@ -29,16 +30,31 @@ func GameList(c *gin.Context) {
resp := &values.GameListResp{Provider: req.Provider}
a.Data = resp
var list, tmp []*common.ConfigGameList
var randFlag bool
if req.Provider == -1 {
req.Provider = 0
}
if req.Mark == -1 {
req.Mark = 0
} else {
req.Mark = 0
randFlag = true
}
if req.Type == -1 || req.Type == 1 {
req.Type = 0
}
// if req.Provider == -1 {
// req.Provider = 0
// randFlag = true
// }
tmp = call.GetConfigGameList(0, req.Provider, req.Mark, req.Type)
if randFlag {
rand.Shuffle(len(tmp), func(i, j int) {
tmp[i], tmp[j] = tmp[j], tmp[i]
})
}
if len(req.Name) > 0 {
reqName := strings.ToLower(req.Name)
for _, v := range tmp {

@ -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,6 @@ func PlayerRecharge(c *gin.Context) {
return
}
log.Debug("player %v recharge:%+v", a.UID, *req)
if req.CurrencyType == 0 {
req.CurrencyType = common.CurrencyINR
}
@ -162,30 +164,15 @@ 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
}
call.AddChannel(req.PayChannel, false)
// if req.UserPhone == "" {
// req.UserPhone = util.CheckPhone(req.UserPhone)
// }
@ -210,14 +197,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