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