package base import ( "errors" "fmt" "server/call" "server/common" "server/db" "server/natsClient" "server/pb" "server/util" "github.com/gin-gonic/gin" "github.com/liangdas/mqant/log" ) const ( CodeOk = iota CodeNotEnoughAmount // 余额不足 CodeAccepted // 重复下注 CodeSettled // 已结算 CodeInnerError // 内部错误 CodeBetNotExist // 结算时,判断下注不存在 ) const ( SessionTypeBet = iota + 1 SessionTypeSettle SessionTypeActivity SessionTypeAdjustment // 调整玩家余额 SessionTypeJackpot SessionTypeBonus SessionTypeBuyIn // 直接扣钱操作 SessionTypeBuyOut // 直接加钱操作 SessionTypeFree // 免费游戏 ) const ( SessionSuccess = iota + 1 SessionFail SessionInvalid ) type Base struct { Provider *common.ConfigGameProvider SubInitRouter func(r *gin.RouterGroup) SettleWithoutBet bool // 如果为true,代表结算的时候settle值为玩家实际加减值,不需要扣除下注 Sub *EnterGameReq } type Sub interface { Init() EnterGame() string } type EnterGameReq struct { ProviderID int GameID int GameType int UID int Token string Lang string CurrencyType common.CurrencyType IsDemo bool SubID int IP string DeviceType int // 设备类型 ChannelID int } type BetReq struct { UID int CurrencyType common.CurrencyType SettleAmount int64 // 输赢 BetAmount int64 TurnOver int64 // 有效下注 Preserve int64 // 预扣款 SessionType int // 1下注 2结算 GameID int GameName string Provider *common.ConfigGameProvider BetID string // 注单唯一id SessionID string // 轮次id Time int64 VoidType int64 // 注单无效原因 // SettleWithoutBet bool // 如果为true,代表结算的时候settle值为玩家实际加减值,不需要扣除下注 } type BetResp struct { MyUUID int64 Balance int64 // 余额 BeforeBalance int64 // 余额 Code int } type SettleReq struct { UID int CurrencyType common.CurrencyType SettleAmount int64 // 输赢(玩家实际加减的值) BetAmount int64 TurnOver int64 // 有效下注 Preserve int64 // 预扣款 GameID int GameName string Provider *common.ConfigGameProvider BetID string // 注单唯一id SessionID string // 轮次id Time int64 VoidType int64 // 注单无效原因 } type SettleResp struct { MyUUID int64 Balance int64 // 余额 Code int } type VoidSettleReq struct { UID int Provider *common.ConfigGameProvider BetID string // 注单唯一id } type VoidSettleResp struct { MyUUID int64 Balance int64 // 余额 BeforeBalance int64 // 余额 Code int } type ReSettleReq struct { UID int SettleAmount int64 // 输赢(玩家实际加减的值) Provider *common.ConfigGameProvider BetID string // 注单唯一id } type ReSettleResp struct { Balance int64 // 余额 Code int } // type ActivityGiftReq struct { // UID int // CurrencyType common.CurrencyType // Amount int64 // 输赢(玩家实际奖励的值) // GameID int // Provider *common.ConfigGameProvider // BetID string // 注单唯一id // ActivityID string // Time int64 // GiftType int // } // type ActivityGiftResp struct { // MyUUID int64 // Balance int64 // 余额 // BeforeBalance int64 // Code int // } type AdjustmentReq struct { UID int CurrencyType common.CurrencyType Amount int64 // 玩家实际加减的值 GameID int Provider *common.ConfigGameProvider BetID string // 注单唯一id GameName string SessionID string // 回合id // ActivityID string Time int64 Ess string Type int } type AdjustmentResp struct { MyUUID int64 Balance int64 // 余额 BeforeBalance int64 Code int } type AdjustBetReq struct { UID int Provider *common.ConfigGameProvider BetID string // 注单唯一id AdjustAmount int64 } type AdjustBetResp struct { MyUUID int64 Balance int64 // 余额 BeforeBalance int64 Code int } type PushDetailReq struct { UID int CurrencyType common.CurrencyType SettleAmount int64 // 输赢 BetAmount int64 TurnOver int64 // 有效下注 Preserve int64 // 预扣款 SessionType int // 1下注 2结算 GameID int GameName string Provider *common.ConfigGameProvider BetID string // 注单唯一id SessionID string // 轮次id Time int64 } type PushDetailResp struct { MyUUID int64 Balance int64 // 余额 Code int } // slot类及时结算玩法,下注即刻结算 func Bet(req *BetReq) (resp BetResp) { betAmount := req.BetAmount uid := req.UID ct := req.CurrencyType amount := call.GetUserCurrency(uid, ct) if amount < betAmount { resp.Balance = amount resp.Code = CodeNotEnoughAmount return } provider := req.Provider record := &common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, UUID: req.BetID, } db.Mysql().Get(record) if record.ID > 0 { resp.MyUUID = record.MyUUID resp.Code = CodeAccepted return } settle := req.SettleAmount uuid := call.SnowNode().Generate().Int64() if err := db.Mysql().Create(&common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, Currency: ct.GetCurrencyName(), CurrencyType: ct, GameID: req.GameID, GameName: req.GameName, UUID: req.BetID, MyUUID: uuid, Time: req.Time, Amount: betAmount, Settle: settle, Esi: SessionSuccess, }); err != nil { log.Error("err:%v", err) resp.Code = CodeInnerError return } pro := call.MineCurrencyProReal( &common.UpdateCurrency{ CurrencyBalance: &common.CurrencyBalance{ UID: uid, Type: ct, Event: common.CurrencyEventGameBet, Value: -betAmount, Exi1: req.Provider.ProviderID, Exi2: req.GameID, Exs1: fmt.Sprintf("%d", uuid), Exs2: req.BetID, }, }, ) if pro.Err != nil { log.Error("err:%v", pro.Err) resp.Code = CodeInnerError if pro.Err == call.ErrNotEnoughBalance { resp.Code = CodeNotEnoughAmount } return } if settle > 0 { pro = call.MineCurrencyProReal( &common.UpdateCurrency{ CurrencyBalance: &common.CurrencyBalance{ UID: uid, Type: ct, Event: common.CurrencyEventGameSettle, Value: settle, Exi1: req.Provider.ProviderID, Exi2: req.GameID, Exs1: fmt.Sprintf("%d", uuid), Exs2: req.BetID, }, }, ) } util.IndexTryS(func() error { return call.Publish(natsClient.TopicInnerAfterSettle, &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), }) }) resp.MyUUID = uuid resp.Balance = pro.Balance return } // 一局下注逻辑(非slot类下注即刻结算) func SessionBet(req *BetReq) (resp BetResp) { betAmount := req.BetAmount + req.Preserve uid := req.UID ct := req.CurrencyType provider := req.Provider record := &common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, UUID: req.BetID, } db.Mysql().Get(record) if record.ID > 0 { resp.MyUUID = record.MyUUID resp.Code = CodeAccepted return } amount := call.GetUserCurrency(uid, ct) if amount < betAmount { resp.Balance = amount resp.Code = CodeNotEnoughAmount return } settle := req.SettleAmount uuid := call.SnowNode().Generate().Int64() if err := db.Mysql().Create(&common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, Currency: req.CurrencyType.GetCurrencyName(), CurrencyType: req.CurrencyType, GameID: req.GameID, GameName: req.GameName, UUID: req.BetID, MyUUID: uuid, Type: req.SessionType, Time: req.Time, Amount: betAmount, Settle: settle, SessionID: req.SessionID, TurnOver: req.TurnOver, Preserve: req.Preserve, Esi: SessionSuccess, }); err != nil { log.Error("err:%v", err) resp.Code = CodeInnerError return } if betAmount == 0 && req.SessionType == SessionTypeBet { resp.Balance = amount resp.MyUUID = uuid return } var pro *call.ProRes if betAmount > 0 { // 存储下注金额 pro = call.MineCurrencyProReal( &common.UpdateCurrency{ CurrencyBalance: &common.CurrencyBalance{ UID: uid, Type: ct, Event: common.CurrencyEventGameBet, Value: -betAmount, Exi1: req.Provider.ProviderID, Exi2: req.GameID, Exs1: fmt.Sprintf("%d", uuid), Exs2: req.BetID, Exs3: req.SessionID, Exs4: call.GetGameName(req.Provider.ProviderID, req.GameName) + " Bet", }, }, ) if pro.Err != nil { log.Error("err:%v", pro.Err) resp.Code = CodeInnerError if errors.Is(pro.Err, call.ErrNotEnoughBalance) { resp.Code = CodeNotEnoughAmount } } if req.SessionType == SessionTypeBet { // 下注回合的直接返回,等结算的再一起上报 resp.Balance = pro.Balance resp.MyUUID = uuid return } } if pro == nil { tmpRecord := &common.ProviderBetRecord{ UID: uid, SessionID: req.SessionID, Type: 1, } db.Mysql().Get(tmpRecord) if tmpRecord.ID == 0 { resp.Code = CodeBetNotExist return } betAmount = tmpRecord.Amount } setValue := settle + req.Preserve if setValue != 0 { cb := &common.CurrencyBalance{ UID: uid, Type: ct, Event: common.CurrencyEventGameSettle, Value: setValue, Exi1: req.Provider.ProviderID, Exi2: req.GameID, Exs1: fmt.Sprintf("%d", uuid), Exs2: req.BetID, Exs3: req.SessionID, Exs4: call.GetGameName(req.Provider.ProviderID, req.GameName) + " Settle", } pro = call.MineCurrencyProReal( &common.UpdateCurrency{ CurrencyBalance: cb, }, ) if pro.Err != nil { log.Error("err:%v", pro.Err) resp.Code = CodeInnerError 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 pro != nil { resp.Balance = pro.Balance } else { resp.Balance = call.GetUserCurrency(uid, ct) } resp.MyUUID = uuid return } // 一局取消下注逻辑(非slot类下注即刻结算,需对应唯一id去取消,若取消id不同,调用adjust方法回退金额) func CancelSessionBet(req *BetReq) (resp BetResp) { uid := req.UID provider := req.Provider record := &common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, UUID: req.BetID, Type: SessionTypeBet, } db.Mysql().Get(record) ct := record.CurrencyType if record.Esi == SessionFail { resp.MyUUID = record.MyUUID resp.Code = CodeAccepted resp.Balance = call.GetUserCurrency(uid, ct) return } betAmount := record.Amount preserve := record.Preserve uuid := call.SnowNode().Generate().Int64() // 说明已下注需要取消 if record.ID > 0 { res, err := db.Mysql().UpdateRes(&common.ProviderBetRecord{UID: uid, Provider: provider.ProviderID, UUID: req.BetID, Esi: SessionSuccess, Type: SessionTypeBet}, map[string]interface{}{"esi": SessionFail, "esi1": req.VoidType}) if err != nil { log.Error("res:%v,err:%v", res, err) resp.Code = CodeInnerError return } if res == 0 { resp.Code = CodeAccepted return } pro := call.UpdateCurrencyProReal(&common.UpdateCurrency{ CurrencyBalance: &common.CurrencyBalance{ UID: uid, Type: ct, Event: common.CurrencyEventGameCancelBet, Value: betAmount + preserve, Exi1: req.Provider.ProviderID, Exi2: req.GameID, Exs1: fmt.Sprintf("%d", uuid), Exs2: req.BetID, Exs3: req.SessionID, }, }) if pro.Err != nil { log.Error("err:%v", pro.Err) resp.Code = CodeInnerError } resp.Balance = pro.Balance resp.BeforeBalance = pro.Balance - (betAmount + preserve) resp.MyUUID = uuid return } // 该笔下注还未收到,先创建,后续收到时直接失败 currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid)) ct = common.CurrencyType(currency) if err != nil { lastRecord := &common.ProviderBetRecord{UID: uid} db.Mysql().GetLast(lastRecord) ct = lastRecord.CurrencyType } if !ct.IsValid() { ct = common.CurrencyINR } amount := call.GetUserCurrency(uid, ct) if err := db.Mysql().Create(&common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, Currency: req.CurrencyType.GetCurrencyName(), CurrencyType: req.CurrencyType, GameID: req.GameID, GameName: req.GameName, UUID: req.BetID, Type: req.SessionType, Time: req.Time, Amount: betAmount, SessionID: req.SessionID, MyUUID: uuid, Preserve: preserve, Esi: SessionFail, }); err != nil { log.Error("err:%v", err) resp.Code = CodeInnerError } resp.Balance = amount resp.BeforeBalance = amount resp.MyUUID = uuid return } // 结算逻辑 func Settle(req *SettleReq) (resp SettleResp) { uid := req.UID provider := req.Provider record := &common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, SessionID: req.SessionID, Type: SessionTypeBet, } db.Mysql().Get(record) if record.ID == 0 { resp.Code = CodeBetNotExist return } ct := req.CurrencyType betAmount := req.BetAmount preserve := req.Preserve uuid := call.SnowNode().Generate().Int64() if err := db.Mysql().Create(&common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, Currency: ct.GetCurrencyName(), CurrencyType: ct, GameID: req.GameID, GameName: req.GameName, UUID: req.BetID, Type: SessionTypeSettle, Time: req.Time, Amount: betAmount, SessionID: req.SessionID, MyUUID: uuid, Preserve: preserve, Settle: req.SettleAmount, Esi: SessionSuccess, }); err != nil { log.Error("err:%v", err) resp.Code = CodeAccepted } var balance int64 if req.SettleAmount != 0 { pro := call.UpdateCurrencyProReal( &common.UpdateCurrency{ CurrencyBalance: &common.CurrencyBalance{ UID: uid, Type: ct, Event: common.CurrencyEventGameSettle, Value: req.SettleAmount, Exi1: req.Provider.ProviderID, Exi2: req.GameID, Exs1: fmt.Sprintf("%d", uuid), Exs2: req.BetID, Exs3: req.SessionID, }, }, ) if pro.Err != nil { log.Error("err:%v", pro.Err) resp.Code = CodeInnerError return } balance = pro.Balance } else { balance = call.GetUserCurrency(uid, ct) } util.IndexTryS(func() error { return call.Publish(natsClient.TopicInnerAfterSettle, &pb.InnerAfterSettle{ UID: int64(uid), ProviderID: int64(provider.ProviderID), GameID: int64(req.GameID), UUID: req.BetID, CurrencyType: int64(ct), TotalBet: req.TurnOver, OriginSettle: req.SettleAmount, FinalSettle: req.SettleAmount, MyUUID: fmt.Sprintf("%d", uuid), }) }) resp.Balance = balance resp.MyUUID = uuid return } // 取消结算(根据id去取消结算,如果id不同,调用adjust回退金额) func VoidSettle(req *VoidSettleReq) (resp VoidSettleResp) { uid := req.UID provider := req.Provider record := &common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, Type: SessionTypeSettle, UUID: req.BetID, } db.Mysql().Get(record) if record.ID == 0 { resp.MyUUID = record.MyUUID resp.Code = CodeInnerError return } if record.Esi == SessionInvalid { resp.Code = CodeSettled return } res, err := db.Mysql().UpdateRes(&common.ProviderBetRecord{UID: uid, Provider: provider.ProviderID, UUID: req.BetID, Esi: SessionSuccess}, map[string]interface{}{"esi": SessionInvalid}) if err != nil || res == 0 { log.Error("res:%v,err:%v", res, err) resp.Code = CodeInnerError return } pro := call.UpdateCurrencyProReal(&common.UpdateCurrency{ CurrencyBalance: &common.CurrencyBalance{ UID: uid, Type: record.CurrencyType, Event: common.CurrencyEventGameVoidSettle, Value: -(record.Settle - record.Amount), Exi1: req.Provider.ProviderID, Exi2: record.GameID, Exs1: fmt.Sprintf("%d", record.MyUUID), Exs2: record.UUID, Exs3: record.SessionID, }, }) if pro.Err != nil { log.Error("err:%v", pro.Err) resp.Code = CodeInnerError } resp.Balance = pro.Balance resp.BeforeBalance = pro.Balance + record.Settle - record.Amount return } // 调整结算(根据id去调整结算,如果id不同,调用adjust回退金额) func Resettle(req *ReSettleReq) (resp ReSettleResp) { uid := req.UID provider := req.Provider record := &common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, Type: SessionTypeSettle, UUID: req.BetID, } db.Mysql().Get(record) if record.ID == 0 { resp.Code = CodeInnerError return } add := req.SettleAmount - record.Settle if add == 0 { return } res, err := db.Mysql().UpdateResW(&common.ProviderBetRecord{}, map[string]interface{}{"settle": req.SettleAmount}, fmt.Sprintf("uid = %v and provider = %v and uuid = '%v' and settle <> %v and type = %d", uid, provider.ProviderID, req.BetID, req.SettleAmount, SessionTypeSettle)) if err != nil || res == 0 { log.Error("res:%v,err:%v", res, err) resp.Code = CodeInnerError return } pro := call.UpdateCurrencyProReal(&common.UpdateCurrency{ CurrencyBalance: &common.CurrencyBalance{ UID: uid, Type: record.CurrencyType, Event: common.CurrencyEventGameReSettle, Value: add, Exi1: req.Provider.ProviderID, Exi2: record.GameID, Exs1: fmt.Sprintf("%d", record.MyUUID), Exs2: record.UUID, Exs3: record.SessionID, }, }) if pro.Err != nil { log.Error("err:%v", pro.Err) resp.Code = CodeInnerError } resp.Balance = pro.Balance return } // 活动奖励(或者是jackpot,bonus,回退) // func ActivityGive(req *ActivityGiftReq) (resp ActivityGiftResp) { // uid := req.UID // provider := req.Provider // record := &common.ProviderBetRecord{ // UID: uid, // Provider: provider.ProviderID, // Type: req.GiftType, // UUID: req.BetID, // } // db.Mysql().Get(record) // if record.ID > 0 { // resp.MyUUID = record.MyUUID // resp.Code = CodeAccepted // return // } // uuid := call.SnowNode().Generate().Int64() // if err := db.Mysql().Create(&common.ProviderBetRecord{ // UID: uid, // Provider: provider.ProviderID, // Currency: req.CurrencyType.GetCurrencyName(), // CurrencyType: req.CurrencyType, // GameID: req.GameID, // UUID: req.BetID, // Type: req.GiftType, // Settle: req.Amount, // Time: req.Time, // MyUUID: uuid, // Esi: SessionSuccess, // Ess: req.ActivityID, // }); err != nil { // log.Error("err:%v", err) // resp.Code = CodeInnerError // } // uc := &common.UpdateCurrency{ // CurrencyBalance: &common.CurrencyBalance{ // UID: uid, // Type: req.CurrencyType, // Event: common.CurrencyEventGameActivity, // Value: req.Amount, // Exs1: fmt.Sprintf("%d", uuid), // Exs2: req.BetID, // }, // } // if req.GiftType == SessionTypeJackpot { // uc.Event = common.CurrencyEventGameJackpot // } else if req.GiftType == SessionTypeBonus { // uc.Event = common.CurrencyEventGameBonus // } else if req.GiftType == SessionTypeBuyIn { // uc.Event = common.CurrencyEventGameBuyIn // } else if req.GiftType == SessionTypeBuyOut { // uc.Event = common.CurrencyEventGameBuyOut // } // if req.Amount != 0 { // pro := call.MineCurrencyProReal(uc) // if pro.Err != nil { // log.Error("err:%v", pro.Err) // resp.Code = CodeInnerError // if pro.Err == call.ErrNotEnoughBalance { // resp.Code = CodeNotEnoughAmount // } // } // resp.Balance = pro.Balance // resp.BeforeBalance = pro.Balance - req.Amount // } else { // resp.Balance = call.GetUserCurrency(req.UID, req.CurrencyType) // resp.BeforeBalance = resp.Balance // } // return // } // 直接调整玩家余额,可以是活动奖励(或者是jackpot,bonus,回退) func Adjustment(req *AdjustmentReq) (resp AdjustmentResp) { uid := req.UID if req.Amount < 0 { amount := call.GetUserCurrency(uid, req.CurrencyType) if amount < -req.Amount { resp.Balance = amount resp.Code = CodeNotEnoughAmount return } } provider := req.Provider record := &common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, Type: req.Type, UUID: req.BetID, } db.Mysql().Get(record) if record.ID > 0 { resp.MyUUID = record.MyUUID resp.Code = CodeAccepted return } uuid := call.SnowNode().Generate().Int64() if err := db.Mysql().Create(&common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, Currency: req.CurrencyType.GetCurrencyName(), CurrencyType: req.CurrencyType, GameID: req.GameID, GameName: req.GameName, UUID: req.BetID, SessionID: req.SessionID, Type: req.Type, Settle: req.Amount, Time: req.Time, MyUUID: uuid, Esi: SessionSuccess, Ess: req.Ess, }); err != nil { log.Error("err:%v", err) resp.Code = CodeInnerError } uc := &common.UpdateCurrency{ CurrencyBalance: &common.CurrencyBalance{ UID: uid, Type: req.CurrencyType, Exi1: provider.ProviderID, Exi2: req.GameID, // Event: common.CurrencyEventGameActivity, Value: req.Amount, Exs1: fmt.Sprintf("%d", uuid), Exs2: req.BetID, }, } if req.Type == SessionTypeActivity { uc.Event = common.CurrencyEventGameActivity } else if req.Type == SessionTypeAdjustment { uc.Event = common.CurrencyEventGameAdjustment } else if req.Type == SessionTypeJackpot { uc.Event = common.CurrencyEventGameJackpot } else if req.Type == SessionTypeBonus { uc.Event = common.CurrencyEventGameBonus } else if req.Type == SessionTypeBuyIn { uc.Event = common.CurrencyEventGameBuyIn } else if req.Type == SessionTypeBuyOut { uc.Event = common.CurrencyEventGameBuyOut } if req.Amount != 0 { pro := call.MineCurrencyProReal(uc) if pro.Err != nil { log.Error("err:%v", pro.Err) resp.Code = CodeInnerError if pro.Err == call.ErrNotEnoughBalance { resp.Code = CodeNotEnoughAmount } } resp.Balance = pro.Balance resp.BeforeBalance = pro.Balance - req.Amount } else { resp.Balance = call.GetUserCurrency(req.UID, req.CurrencyType) resp.BeforeBalance = resp.Balance } return } // 调整下注(根据id去调整下注,如果id不同,调用adjust回退金额) func AdjustBet(req *AdjustBetReq) (resp AdjustBetResp) { uid := req.UID provider := req.Provider record := &common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, Type: SessionTypeBet, UUID: req.BetID, } db.Mysql().Get(record) if record.ID == 0 { resp.MyUUID = record.MyUUID resp.Code = CodeInnerError return } originAmount := record.Amount if originAmount == req.AdjustAmount { resp.Code = CodeAccepted return } res, err := db.Mysql().UpdateRes(&common.ProviderBetRecord{UID: uid, Provider: provider.ProviderID, UUID: req.BetID, Type: SessionTypeBet, Amount: originAmount}, map[string]interface{}{"amount": req.AdjustAmount}) if err != nil { log.Error("res:%v,err:%v", res, err) resp.Code = CodeInnerError return } if res == 0 { resp.Code = CodeAccepted return } pro := call.MineCurrencyProReal(&common.UpdateCurrency{ CurrencyBalance: &common.CurrencyBalance{ UID: uid, Type: record.CurrencyType, Event: common.CurrencyEventGameAdjustBet, Value: originAmount - req.AdjustAmount, Exi1: req.Provider.ProviderID, Exi2: record.GameID, Exs1: fmt.Sprintf("%d", record.MyUUID), Exs2: record.UUID, Exs3: record.SessionID, }, }) if pro.Err != nil { log.Error("err:%v", pro.Err) resp.Code = CodeInnerError } resp.Balance = pro.Balance resp.BeforeBalance = pro.Balance + req.AdjustAmount - originAmount return } // 推送投注/结算细节 func PushDetail(req *PushDetailReq) (resp PushDetailResp) { uid := req.UID provider := req.Provider record := &common.ProviderBetRecord{ UID: uid, Provider: provider.ProviderID, UUID: req.BetID, } db.Mysql().Get(record) if record.ID == 0 { resp.MyUUID = record.MyUUID resp.Code = CodeInnerError return } update := map[string]interface{}{ "session_id": req.SessionID, "turnover": req.TurnOver, } if record.Type == SessionTypeBuyIn { update["type"] = SessionTypeBet update["amount"] = req.BetAmount } else { update["type"] = SessionTypeSettle update["settle"] = req.SettleAmount } db.Mysql().UpdateW(&common.ProviderBetRecord{}, update, fmt.Sprintf("uuid = '%s'", req.BetID)) resp.Balance = call.GetUserCurrency(uid, req.CurrencyType) resp.MyUUID = record.MyUUID return }