修复流水上报

dev_aagame_provider
zhora 1 month ago
parent 772b65fd19
commit cf3a7d8f8c
  1. 22
      modules/web/providers/base/base.go
  2. 3
      modules/web/providers/sn/handler.go

@ -3,6 +3,7 @@ package base
import ( import (
"errors" "errors"
"fmt" "fmt"
"gorm.io/gorm"
"server/call" "server/call"
"server/common" "server/common"
"server/db" "server/db"
@ -330,20 +331,21 @@ func SessionBet(req *BetReq) (resp BetResp) {
UUID: req.BetID, UUID: req.BetID,
} }
db.Mysql().Get(record) db.Mysql().Get(record)
if record.ID > 0 && req.SessionType == SessionTypeBet { if record.ID > 0 && req.SessionType == SessionTypeBet { // 下注订单校验
resp.MyUUID = record.MyUUID resp.MyUUID = record.MyUUID
resp.Code = CodeAccepted resp.Code = CodeAccepted
return return
} }
amount := call.GetUserCurrency(uid, ct) amount := call.GetUserCurrency(uid, ct)
if amount < betAmount { if amount < betAmount { // 余额校验
resp.Balance = amount resp.Balance = amount
resp.Code = CodeNotEnoughAmount resp.Code = CodeNotEnoughAmount
return return
} }
settle := req.SettleAmount settle := req.SettleAmount
realSettle := req.SettleAmount
uuid := call.SnowNode().Generate().Int64() uuid := call.SnowNode().Generate().Int64()
if req.SessionType == SessionTypeBet { if req.SessionType == SessionTypeBet { // 创建下注流水
if err := db.Mysql().Create(&common.ProviderBetRecord{ if err := db.Mysql().Create(&common.ProviderBetRecord{
UID: uid, UID: uid,
Provider: provider.ProviderID, Provider: provider.ProviderID,
@ -373,7 +375,7 @@ func SessionBet(req *BetReq) (resp BetResp) {
return return
} }
var pro *call.ProRes var pro *call.ProRes
if betAmount > 0 { // 存储下注金额 if betAmount > 0 { // 扣除下注金额
pro = call.MineCurrencyProReal( pro = call.MineCurrencyProReal(
&common.UpdateCurrency{ &common.UpdateCurrency{
CurrencyBalance: &common.CurrencyBalance{ CurrencyBalance: &common.CurrencyBalance{
@ -403,7 +405,7 @@ func SessionBet(req *BetReq) (resp BetResp) {
return return
} }
} }
if pro == nil { if pro == nil { // 不包含扣除的结算
tmpRecord := &common.ProviderBetRecord{ tmpRecord := &common.ProviderBetRecord{
UID: uid, UID: uid,
SessionID: req.SessionID, SessionID: req.SessionID,
@ -414,6 +416,10 @@ func SessionBet(req *BetReq) (resp BetResp) {
resp.Code = CodeBetNotExist resp.Code = CodeBetNotExist
return return
} }
db.Mysql().C().Model(&common.ProviderBetRecord{}).Where("id = ?", tmpRecord.ID).Updates(map[string]interface{}{
"settle": gorm.Expr("settle + ?", req.SettleAmount),
})
realSettle += tmpRecord.Settle
betAmount = tmpRecord.Amount betAmount = tmpRecord.Amount
} }
setValue := settle + req.Preserve setValue := settle + req.Preserve
@ -441,6 +447,7 @@ func SessionBet(req *BetReq) (resp BetResp) {
return return
} }
} }
if req.IsFinish == 0 || req.IsFinish == 2 {
util.IndexTryS(func() error { util.IndexTryS(func() error {
sendData := &pb.InnerAfterSettle{ sendData := &pb.InnerAfterSettle{
UID: int64(uid), UID: int64(uid),
@ -449,12 +456,13 @@ func SessionBet(req *BetReq) (resp BetResp) {
UUID: req.BetID, UUID: req.BetID,
CurrencyType: int64(ct), CurrencyType: int64(ct),
TotalBet: betAmount, TotalBet: betAmount,
OriginSettle: settle, OriginSettle: realSettle,
FinalSettle: settle, FinalSettle: realSettle,
MyUUID: fmt.Sprintf("%d", uuid), MyUUID: fmt.Sprintf("%d", uuid),
} }
return call.Publish(natsClient.TopicInnerAfterSettle, sendData) return call.Publish(natsClient.TopicInnerAfterSettle, sendData)
}) })
}
if pro != nil { if pro != nil {
resp.Balance = pro.Balance resp.Balance = pro.Balance
} else { } else {

@ -163,6 +163,7 @@ func GameBet(c *gin.Context) {
Time: now, Time: now,
BetAmount: int64(betAmount), BetAmount: int64(betAmount),
TurnOver: int64(betAmount), TurnOver: int64(betAmount),
IsFinish: 1,
} }
betResp := base.SessionBet(betReq) betResp := base.SessionBet(betReq)
if betResp.Code != base.CodeOk { if betResp.Code != base.CodeOk {
@ -174,7 +175,7 @@ func GameBet(c *gin.Context) {
} else { } else {
resp.Msg = "operation failed." resp.Msg = "operation failed."
} }
log.Error("GameBetResp err:%v", resp.Code) log.Error("sn gameBetResp err,%s:%v", account, resp.Code)
return return
} }
resp.Data.DeductionAmount = betAmount resp.Data.DeductionAmount = betAmount

Loading…
Cancel
Save