You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
779 lines
19 KiB
779 lines
19 KiB
|
1 year ago
|
package gs
|
||
|
|
|
||
|
|
import (
|
||
|
|
"server/call"
|
||
|
|
"server/common"
|
||
|
|
"server/db"
|
||
|
|
"server/modules/web/app"
|
||
|
|
"server/modules/web/providers/base"
|
||
|
|
"server/util"
|
||
|
|
"strconv"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
)
|
||
|
|
|
||
|
|
func GS(e *gin.RouterGroup) {
|
||
|
|
e.POST("/Seamless/GetBalance", GetBalance)
|
||
|
|
e.POST("/Seamless/PlaceBet", PlaceBet)
|
||
|
|
e.POST("/Seamless/GameResult", GameResult)
|
||
|
|
e.POST("/Seamless/Rollback", Rollback)
|
||
|
|
e.POST("/Seamless/CancelBet", CancelBet)
|
||
|
|
e.POST("/Seamless/Bonus", Bonus)
|
||
|
|
e.POST("/Seamless/Jackpot", Jackpot)
|
||
|
|
e.POST("/Seamless/MobileLogin", MobileLogin)
|
||
|
|
e.POST("/Seamless/BuyIn", BuyIn)
|
||
|
|
e.POST("/Seamless/BuyOut", BuyOut)
|
||
|
|
e.POST("/Seamless/PushBet", PushBet)
|
||
|
|
}
|
||
|
|
|
||
|
|
func VerifySign(operatorCode, reqTime, name, sign string) bool {
|
||
|
|
agent := GetAgentByCode(operatorCode)
|
||
|
|
if agent == nil {
|
||
|
|
return false
|
||
|
|
}
|
||
|
|
return util.CalculateMD5(agent.OperatorCode+reqTime+name+agent.SecretKey) == sign
|
||
|
|
}
|
||
|
|
|
||
|
|
func GetGameID(providerID int, gameCode string) int {
|
||
|
|
if providerID == common.ProviderEvolutionGaming || providerID == common.ProviderAllBet || providerID == common.ProviderBigGaming || providerID == common.ProviderSAGaming {
|
||
|
|
return 1
|
||
|
|
}
|
||
|
|
game := call.GetConfigGameListByCode(providerID, gameCode)
|
||
|
|
if game != nil {
|
||
|
|
return game.GameID
|
||
|
|
}
|
||
|
|
return 0
|
||
|
|
}
|
||
|
|
|
||
|
|
func GetBalance(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := &GetBalanceReq{}
|
||
|
|
resp := &CommonResp2{}
|
||
|
|
a.RetData = resp
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("GetBalance:%+v", req)
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "MemberName", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if !VerifySign(req.OperatorCode, req.RequestTime, "getbalance", req.Sign) {
|
||
|
|
resp.ErrorCode = CodeAPIInvalidSign
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
uid, err := strconv.Atoi(req.MemberName)
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
resp.ErrorCode = CodeInnerError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
resp.Balance = call.GetUserCurrencyFloat(uid, common.CurrencyType(currency), 4)
|
||
|
|
}
|
||
|
|
|
||
|
|
func PlaceBet(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := &CommonReq{}
|
||
|
|
resp := &CommonResp{}
|
||
|
|
a.RetData = resp
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("PlaceBet:%+v", req)
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "MemberName", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if !VerifySign(req.OperatorCode, req.RequestTime, "placebet", req.Sign) {
|
||
|
|
resp.ErrorCode = CodeAPIInvalidSign
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
uid, err := strconv.Atoi(req.MemberName)
|
||
|
|
if err != nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
now := time.Now().Unix()
|
||
|
|
for _, v := range req.Transactions {
|
||
|
|
// if v.TransactionAmount == 0 {
|
||
|
|
// resp.Balance = call.GetUserCurrencyFloat(uid, ct, 4)
|
||
|
|
// if resp.BeforeBalance == 0 {
|
||
|
|
// resp.BeforeBalance = resp.Balance
|
||
|
|
// }
|
||
|
|
// continue
|
||
|
|
// }
|
||
|
|
|
||
|
|
ct := CurrencyIDMap[v.CurrencyID]
|
||
|
|
if !ct.IsValid() {
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
ct = common.CurrencyType(currency)
|
||
|
|
}
|
||
|
|
providerID := ProviderIDMap[v.ProductID]
|
||
|
|
provider := call.GetConfigGameProvider(providerID)
|
||
|
|
if provider == nil {
|
||
|
|
resp.ErrorCode = CodeInnerError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
betReq := &base.BetReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: ct,
|
||
|
|
BetAmount: -common.CashFloat64ToInt64(v.TransactionAmount),
|
||
|
|
TurnOver: common.CashFloat64ToInt64(v.ValidBetAmount),
|
||
|
|
SessionType: common.SessionTypeBet,
|
||
|
|
GameID: GetGameID(providerID, v.GameID),
|
||
|
|
GameName: v.GameID,
|
||
|
|
Provider: provider,
|
||
|
|
BetID: v.TransactionID,
|
||
|
|
SessionID: v.GameRoundID,
|
||
|
|
Time: now,
|
||
|
|
}
|
||
|
|
betResp := base.SessionBet(betReq)
|
||
|
|
if betResp.Code != base.CodeOk {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
if betResp.Code == base.CodeAccepted {
|
||
|
|
resp.ErrorCode = CodeAPIDuplicateTransaction
|
||
|
|
} else if betResp.Code == base.CodeNotEnoughAmount {
|
||
|
|
resp.ErrorCode = CodeAPIMemberInsufficientBalance
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
resp.Balance = util.Decimal(float64(betResp.Balance)/common.DecimalDigits, 4)
|
||
|
|
if resp.BeforeBalance == 0 {
|
||
|
|
resp.BeforeBalance = util.Decimal(float64(betResp.Balance+betReq.BetAmount)/common.DecimalDigits, 4)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func GameResult(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := &CommonReq{}
|
||
|
|
resp := &CommonResp{}
|
||
|
|
a.RetData = resp
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("GameResult:%+v", req)
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "MemberName", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if !VerifySign(req.OperatorCode, req.RequestTime, "gameresult", req.Sign) {
|
||
|
|
resp.ErrorCode = CodeAPIInvalidSign
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
uid, err := strconv.Atoi(req.MemberName)
|
||
|
|
if err != nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
provider := call.GetConfigGameProvider(ProviderIDMap[int(req.ProductID)])
|
||
|
|
if provider == nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
now := time.Now().Unix()
|
||
|
|
|
||
|
|
for _, v := range req.Transactions {
|
||
|
|
ct := CurrencyIDMap[v.CurrencyID]
|
||
|
|
if !ct.IsValid() {
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
ct = common.CurrencyType(currency)
|
||
|
|
}
|
||
|
|
settleReq := &base.SettleReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: ct,
|
||
|
|
SettleAmount: common.CashFloat64ToInt64(v.TransactionAmount),
|
||
|
|
BetAmount: common.CashFloat64ToInt64(v.BetAmount),
|
||
|
|
TurnOver: common.CashFloat64ToInt64(v.ValidBetAmount),
|
||
|
|
GameID: GetGameID(provider.ProviderID, v.GameID),
|
||
|
|
GameName: v.GameID,
|
||
|
|
Provider: provider,
|
||
|
|
BetID: v.TransactionID,
|
||
|
|
SessionID: v.GameRoundID,
|
||
|
|
Time: now,
|
||
|
|
}
|
||
|
|
settleResp := base.Settle(settleReq)
|
||
|
|
if settleResp.Code != base.CodeOk {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
if settleResp.Code == base.CodeAccepted {
|
||
|
|
resp.ErrorCode = CodeAPIDuplicateTransaction
|
||
|
|
} else if settleResp.Code == base.CodeBetNotExist {
|
||
|
|
resp.ErrorCode = CodeAPIBetNotExist
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
resp.Balance = util.Decimal(float64(settleResp.Balance)/common.DecimalDigits, 4)
|
||
|
|
if resp.BeforeBalance == 0 {
|
||
|
|
resp.BeforeBalance = util.Decimal(float64(settleResp.Balance-settleReq.SettleAmount)/common.DecimalDigits, 4)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func Rollback(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := &CommonReq{}
|
||
|
|
resp := &CommonResp{}
|
||
|
|
a.RetData = resp
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("Rollback:%+v", req)
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "MemberName", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if !VerifySign(req.OperatorCode, req.RequestTime, "rollback", req.Sign) {
|
||
|
|
resp.ErrorCode = CodeAPIInvalidSign
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
uid, err := strconv.Atoi(req.MemberName)
|
||
|
|
if err != nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
provider := call.GetConfigGameProvider(ProviderIDMap[int(req.ProductID)])
|
||
|
|
if provider == nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
for _, v := range req.Transactions {
|
||
|
|
ct := CurrencyIDMap[v.CurrencyID]
|
||
|
|
if !ct.IsValid() {
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
ct = common.CurrencyType(currency)
|
||
|
|
}
|
||
|
|
adjustResp := base.Adjustment(&base.AdjustmentReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: ct,
|
||
|
|
Amount: common.CashFloat64ToInt64(v.TransactionAmount),
|
||
|
|
GameID: GetGameID(provider.ProviderID, v.GameID),
|
||
|
|
GameName: v.GameID,
|
||
|
|
Provider: provider,
|
||
|
|
BetID: v.TransactionID,
|
||
|
|
Time: time.Now().Unix(),
|
||
|
|
SessionID: v.GameRoundID,
|
||
|
|
Type: common.SessionTypeAdjustment,
|
||
|
|
})
|
||
|
|
if adjustResp.Code != base.CodeOk {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
if adjustResp.Code == base.CodeAccepted {
|
||
|
|
resp.ErrorCode = CodeAPIDuplicateTransaction
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
resp.Balance = util.Decimal(float64(adjustResp.Balance)/common.DecimalDigits, 4)
|
||
|
|
if resp.BeforeBalance == 0 {
|
||
|
|
resp.BeforeBalance = util.Decimal(float64(adjustResp.BeforeBalance)/common.DecimalDigits, 4)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func CancelBet(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := &CommonReq{}
|
||
|
|
resp := &CommonResp{}
|
||
|
|
a.RetData = resp
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("CancelBet:%+v", req)
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "MemberName", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if !VerifySign(req.OperatorCode, req.RequestTime, "cancelbet", req.Sign) {
|
||
|
|
resp.ErrorCode = CodeAPIInvalidSign
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
uid, err := strconv.Atoi(req.MemberName)
|
||
|
|
if err != nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
provider := call.GetConfigGameProvider(ProviderIDMap[int(req.ProductID)])
|
||
|
|
if provider == nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
for _, v := range req.Transactions {
|
||
|
|
ct := CurrencyIDMap[v.CurrencyID]
|
||
|
|
if !ct.IsValid() {
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
ct = common.CurrencyType(currency)
|
||
|
|
}
|
||
|
|
adjustResp := base.Adjustment(&base.AdjustmentReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: ct,
|
||
|
|
Amount: common.CashFloat64ToInt64(v.TransactionAmount),
|
||
|
|
GameID: GetGameID(provider.ProviderID, v.GameID),
|
||
|
|
GameName: v.GameID,
|
||
|
|
Provider: provider,
|
||
|
|
BetID: v.TransactionID,
|
||
|
|
SessionID: v.GameRoundID,
|
||
|
|
Time: time.Now().Unix(),
|
||
|
|
Type: common.SessionTypeAdjustment,
|
||
|
|
})
|
||
|
|
if adjustResp.Code != base.CodeOk {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
if adjustResp.Code == base.CodeAccepted {
|
||
|
|
resp.ErrorCode = CodeAPIDuplicateTransaction
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
resp.Balance = util.Decimal(float64(adjustResp.Balance)/common.DecimalDigits, 4)
|
||
|
|
if resp.BeforeBalance == 0 {
|
||
|
|
resp.BeforeBalance = util.Decimal(float64(adjustResp.BeforeBalance)/common.DecimalDigits, 4)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func Bonus(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := &CommonReq{}
|
||
|
|
resp := &CommonResp{}
|
||
|
|
a.RetData = resp
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("Bonus:%+v", req)
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "MemberName", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if !VerifySign(req.OperatorCode, req.RequestTime, "bonus", req.Sign) {
|
||
|
|
resp.ErrorCode = CodeAPIInvalidSign
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
uid, err := strconv.Atoi(req.MemberName)
|
||
|
|
if err != nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
provider := call.GetConfigGameProvider(ProviderIDMap[int(req.ProductID)])
|
||
|
|
if provider == nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
now := time.Now().Unix()
|
||
|
|
for _, v := range req.Transactions {
|
||
|
|
ct := CurrencyIDMap[v.CurrencyID]
|
||
|
|
if !ct.IsValid() {
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
ct = common.CurrencyType(currency)
|
||
|
|
}
|
||
|
|
giftResp := base.Adjustment(&base.AdjustmentReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: common.CurrencyType(ct),
|
||
|
|
Amount: common.CashFloat64ToInt64(v.TransactionAmount),
|
||
|
|
GameID: GetGameID(provider.ProviderID, v.GameID),
|
||
|
|
GameName: v.GameID,
|
||
|
|
Provider: provider,
|
||
|
|
BetID: v.TransactionID,
|
||
|
|
SessionID: v.GameRoundID,
|
||
|
|
Time: now,
|
||
|
|
Type: common.SessionTypeBonus,
|
||
|
|
})
|
||
|
|
if giftResp.Code != base.CodeOk {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
if giftResp.Code == base.CodeAccepted {
|
||
|
|
resp.ErrorCode = CodeAPIDuplicateTransaction
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
resp.Balance = util.Decimal(float64(giftResp.Balance)/common.DecimalDigits, 4)
|
||
|
|
if resp.BeforeBalance == 0 {
|
||
|
|
resp.BeforeBalance = util.Decimal(float64(giftResp.BeforeBalance)/common.DecimalDigits, 4)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func Jackpot(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := &CommonReq{}
|
||
|
|
resp := &CommonResp{}
|
||
|
|
a.RetData = resp
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("Jackpot:%+v", req)
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "MemberName", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if !VerifySign(req.OperatorCode, req.RequestTime, "jackpot", req.Sign) {
|
||
|
|
resp.ErrorCode = CodeAPIInvalidSign
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
uid, err := strconv.Atoi(req.MemberName)
|
||
|
|
if err != nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
provider := call.GetConfigGameProvider(ProviderIDMap[int(req.ProductID)])
|
||
|
|
if provider == nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
now := time.Now().Unix()
|
||
|
|
for _, v := range req.Transactions {
|
||
|
|
ct := CurrencyIDMap[v.CurrencyID]
|
||
|
|
if !ct.IsValid() {
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
ct = common.CurrencyType(currency)
|
||
|
|
}
|
||
|
|
giftResp := base.Adjustment(&base.AdjustmentReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: common.CurrencyType(ct),
|
||
|
|
Amount: common.CashFloat64ToInt64(v.TransactionAmount),
|
||
|
|
GameID: GetGameID(provider.ProviderID, v.GameID),
|
||
|
|
GameName: v.GameID,
|
||
|
|
Provider: provider,
|
||
|
|
BetID: v.TransactionID,
|
||
|
|
SessionID: v.GameRoundID,
|
||
|
|
Time: now,
|
||
|
|
Type: common.SessionTypeJackpot,
|
||
|
|
})
|
||
|
|
if giftResp.Code != base.CodeOk {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
if giftResp.Code == base.CodeAccepted {
|
||
|
|
resp.ErrorCode = CodeAPIDuplicateTransaction
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
resp.Balance = util.Decimal(float64(giftResp.Balance)/common.DecimalDigits, 4)
|
||
|
|
if resp.BeforeBalance == 0 {
|
||
|
|
resp.BeforeBalance = util.Decimal(float64(giftResp.BeforeBalance)/common.DecimalDigits, 4)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func MobileLogin(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := &GetBalanceReq{}
|
||
|
|
resp := &CommonResp2{}
|
||
|
|
a.RetData = resp
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("MobileLogin:%+v", req)
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "MemberName", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if !VerifySign(req.OperatorCode, req.RequestTime, "mobilelogin", req.Sign) {
|
||
|
|
resp.ErrorCode = CodeAPIInvalidSign
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
uid, err := strconv.Atoi(req.MemberName)
|
||
|
|
if err != nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
resp.ErrorCode = CodeInnerError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
resp.Balance = call.GetUserCurrencyFloat(uid, common.CurrencyType(currency), 4)
|
||
|
|
}
|
||
|
|
|
||
|
|
func BuyIn(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := &BuyInReq{}
|
||
|
|
resp := &CommonResp{}
|
||
|
|
a.RetData = resp
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("BuyIn:%+v", req)
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "MemberName", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if !VerifySign(req.OperatorCode, req.RequestTime, "buyin", req.Sign) {
|
||
|
|
resp.ErrorCode = CodeAPIInvalidSign
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
uid, err := strconv.Atoi(req.MemberName)
|
||
|
|
if err != nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
ct := CurrencyIDMap[req.Transaction.CurrencyID]
|
||
|
|
if !ct.IsValid() {
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
resp.ErrorCode = CodeInnerError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
ct = common.CurrencyType(currency)
|
||
|
|
}
|
||
|
|
provider := call.GetConfigGameProvider(ProviderIDMap[int(req.ProductID)])
|
||
|
|
if provider == nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
now := time.Now().Unix()
|
||
|
|
giftResp := base.Adjustment(&base.AdjustmentReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: common.CurrencyType(ct),
|
||
|
|
Amount: common.CashFloat64ToInt64(req.Transaction.TransactionAmount),
|
||
|
|
GameID: GetGameID(provider.ProviderID, req.Transaction.GameID),
|
||
|
|
GameName: req.Transaction.GameID,
|
||
|
|
Provider: provider,
|
||
|
|
BetID: req.Transaction.TransactionID,
|
||
|
|
SessionID: req.Transaction.GameRoundID,
|
||
|
|
Time: now,
|
||
|
|
Type: common.SessionTypeBuyIn,
|
||
|
|
})
|
||
|
|
if giftResp.Code != base.CodeOk {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
if giftResp.Code == base.CodeAccepted {
|
||
|
|
resp.ErrorCode = CodeAPIDuplicateTransaction
|
||
|
|
} else if giftResp.Code == base.CodeNotEnoughAmount {
|
||
|
|
resp.ErrorCode = CodeAPIMemberInsufficientBalance
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
resp.Balance = util.Decimal(float64(giftResp.Balance)/common.DecimalDigits, 4)
|
||
|
|
resp.BeforeBalance = util.Decimal(float64(giftResp.BeforeBalance)/common.DecimalDigits, 4)
|
||
|
|
}
|
||
|
|
|
||
|
|
func BuyOut(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := &BuyOutReq{}
|
||
|
|
resp := &CommonResp{}
|
||
|
|
a.RetData = resp
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("BuyOut:%+v", req)
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "MemberName", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if !VerifySign(req.OperatorCode, req.RequestTime, "buyout", req.Sign) {
|
||
|
|
resp.ErrorCode = CodeAPIInvalidSign
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
uid, err := strconv.Atoi(req.MemberName)
|
||
|
|
if err != nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
ct := CurrencyIDMap[req.Transaction.CurrencyID]
|
||
|
|
if !ct.IsValid() {
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
resp.ErrorCode = CodeInnerError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
ct = common.CurrencyType(currency)
|
||
|
|
}
|
||
|
|
provider := call.GetConfigGameProvider(ProviderIDMap[int(req.ProductID)])
|
||
|
|
if provider == nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
now := time.Now().Unix()
|
||
|
|
giftResp := base.Adjustment(&base.AdjustmentReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: common.CurrencyType(ct),
|
||
|
|
Amount: common.CashFloat64ToInt64(req.Transaction.TransactionAmount),
|
||
|
|
GameID: GetGameID(provider.ProviderID, req.Transaction.GameID),
|
||
|
|
GameName: req.Transaction.GameID,
|
||
|
|
Provider: provider,
|
||
|
|
BetID: req.Transaction.TransactionID,
|
||
|
|
SessionID: req.Transaction.GameRoundID,
|
||
|
|
Time: now,
|
||
|
|
Type: common.SessionTypeBuyOut,
|
||
|
|
})
|
||
|
|
if giftResp.Code != base.CodeOk {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
if giftResp.Code == base.CodeAccepted {
|
||
|
|
resp.ErrorCode = CodeAPIDuplicateTransaction
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
resp.Balance = util.Decimal(float64(giftResp.Balance)/common.DecimalDigits, 4)
|
||
|
|
resp.BeforeBalance = util.Decimal(float64(giftResp.BeforeBalance)/common.DecimalDigits, 4)
|
||
|
|
}
|
||
|
|
|
||
|
|
func PushBet(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := &CommonReq{}
|
||
|
|
resp := &CommonResp2{}
|
||
|
|
a.RetData = resp
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("PushBet:%+v", req)
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "MemberName", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if !VerifySign(req.OperatorCode, req.RequestTime, "pushbet", req.Sign) {
|
||
|
|
resp.ErrorCode = CodeAPIInvalidSign
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
uid, err := strconv.Atoi(req.MemberName)
|
||
|
|
if err != nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
provider := call.GetConfigGameProvider(ProviderIDMap[int(req.ProductID)])
|
||
|
|
if provider == nil {
|
||
|
|
resp.ErrorCode = CodeAPIError
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
now := time.Now().Unix()
|
||
|
|
for _, v := range req.Transactions {
|
||
|
|
ct := CurrencyIDMap[v.CurrencyID]
|
||
|
|
if !ct.IsValid() {
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
ct = common.CurrencyType(currency)
|
||
|
|
}
|
||
|
|
if v.TransactionID != "" {
|
||
|
|
pushReq := &base.PushDetailReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: ct,
|
||
|
|
SettleAmount: common.CashFloat64ToInt64(v.PayoutAmount),
|
||
|
|
BetAmount: common.CashFloat64ToInt64(v.BetAmount),
|
||
|
|
TurnOver: common.CashFloat64ToInt64(v.ValidBetAmount),
|
||
|
|
GameID: GetGameID(provider.ProviderID, v.GameID),
|
||
|
|
GameName: v.GameID,
|
||
|
|
Provider: provider,
|
||
|
|
BetID: v.TransactionID,
|
||
|
|
SessionID: v.GameRoundID,
|
||
|
|
Time: now,
|
||
|
|
}
|
||
|
|
pushDetailResp := base.PushDetail(pushReq)
|
||
|
|
resp.Balance = util.Decimal(float64(pushDetailResp.Balance)/common.DecimalDigits, 4)
|
||
|
|
} else {
|
||
|
|
resp.Balance = call.GetUserCurrencyFloat(uid, ct, 4)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|