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.
294 lines
7.2 KiB
294 lines
7.2 KiB
|
1 year ago
|
package tada
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"server/call"
|
||
|
|
"server/common"
|
||
|
|
"server/db"
|
||
|
|
"server/modules/web/app"
|
||
|
|
"server/modules/web/providers/base"
|
||
|
|
"server/util"
|
||
|
|
"strconv"
|
||
|
|
"strings"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
)
|
||
|
|
|
||
|
|
func Tada(e *gin.RouterGroup) {
|
||
|
|
e.POST("/auth", auth)
|
||
|
|
e.POST("/bet", bet)
|
||
|
|
e.POST("/sessionBet", sessionBet)
|
||
|
|
e.POST("/cancelSessionBet", cancelSessionBet)
|
||
|
|
}
|
||
|
|
|
||
|
|
func auth(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
resp := new(AuthResp)
|
||
|
|
req := new(AuthReq)
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = ErrorCodeInvalidParameter
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("tada auth req:%+v", req)
|
||
|
|
a.RetData = resp
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "Token", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
// 验证token
|
||
|
|
uid, _ := db.Redis().GetInt(common.GetRedisKeyToken(req.Token))
|
||
|
|
if uid == 0 {
|
||
|
|
resp.ErrorCode = ErrorCodeTokenExpired
|
||
|
|
return
|
||
|
|
}
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
resp.ErrorCode = ErrorCodeOther
|
||
|
|
return
|
||
|
|
}
|
||
|
|
resp.UserName = common.GetProviderUserName(fmt.Sprintf("%v", uid))
|
||
|
|
resp.Currency = strings.ToUpper(common.CurrencyType(currency).GetCurrencyName())
|
||
|
|
resp.Balance = call.GetUserCurrencyFloat(uid, common.CurrencyType(currency), 4)
|
||
|
|
resp.Token = common.GetProviderUserToken(req.Token)
|
||
|
|
log.Debug("tada auth resp:%+v", resp)
|
||
|
|
}
|
||
|
|
|
||
|
|
func bet(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
resp := new(BetResp)
|
||
|
|
defer func() {
|
||
|
|
log.Debug("tada bet resp:%+v", *resp)
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := new(BetReq)
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = ErrorCodeInvalidParameter
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("tada bet req:%+v", req)
|
||
|
|
a.RetData = resp
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "Token", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
ct := common.GetCurrencyID(req.Currency)
|
||
|
|
if !ct.IsValid() {
|
||
|
|
resp.ErrorCode = ErrorCodeInvalidParameter
|
||
|
|
return
|
||
|
|
}
|
||
|
|
provider := call.GetConfigGameProvider(common.ProviderTada)
|
||
|
|
if provider == nil {
|
||
|
|
resp.ErrorCode = ErrorCodeOther
|
||
|
|
return
|
||
|
|
}
|
||
|
|
// defer func() {
|
||
|
|
// // 更新游戏次数
|
||
|
|
// if resp.ErrorCode == ErrorCodeSuccess {
|
||
|
|
// call.UpdateGameSort(provider.ProviderID, req.Game)
|
||
|
|
// }
|
||
|
|
// }()
|
||
|
|
// 验证token
|
||
|
|
uid, _ := db.Redis().GetInt(common.GetRedisKeyToken(req.Token))
|
||
|
|
if uid == 0 {
|
||
|
|
var err error
|
||
|
|
uid, err = strconv.Atoi(req.UserId)
|
||
|
|
if err != nil || uid == 0 {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
resp.ErrorCode = ErrorCodeTokenExpired
|
||
|
|
return
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
betResp := base.Bet(&base.BetReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: ct,
|
||
|
|
SettleAmount: common.CashFloat64ToInt64(req.WinLoseAmount),
|
||
|
|
BetAmount: common.CashFloat64ToInt64(req.BetAmount),
|
||
|
|
GameID: req.Game,
|
||
|
|
Provider: provider,
|
||
|
|
BetID: fmt.Sprintf("%d", req.Round),
|
||
|
|
// SessionID: fmt.Sprintf("%d", req.SessionID),
|
||
|
|
Time: req.WagersTime,
|
||
|
|
})
|
||
|
|
if betResp.Code == base.CodeInnerError {
|
||
|
|
resp.ErrorCode = ErrorCodeOther
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if betResp.Code == base.CodeNotEnoughAmount {
|
||
|
|
resp.ErrorCode = ErrorCodeNotEnoughBalance
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if betResp.Code == base.CodeAccepted {
|
||
|
|
resp.TxID = betResp.MyUUID
|
||
|
|
resp.ErrorCode = ErrorCodeAccepted
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
resp.UserName = common.GetProviderUserName(fmt.Sprintf("%v", uid))
|
||
|
|
resp.Currency = req.Currency
|
||
|
|
resp.Balance = util.Decimal(float64(betResp.Balance)/common.DecimalDigits, 4)
|
||
|
|
resp.TxID = betResp.MyUUID
|
||
|
|
resp.Token = common.GetProviderUserToken(req.Token)
|
||
|
|
}
|
||
|
|
|
||
|
|
func sessionBet(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
resp := new(BetResp)
|
||
|
|
defer func() {
|
||
|
|
log.Debug("tada sessionBet resp:%+v", *resp)
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := new(SessionBetReq)
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = ErrorCodeInvalidParameter
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("tada sessionBet req:%+v", req)
|
||
|
|
a.RetData = resp
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "Token", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
ct := common.GetCurrencyID(req.Currency)
|
||
|
|
if !ct.IsValid() {
|
||
|
|
resp.ErrorCode = ErrorCodeInvalidParameter
|
||
|
|
return
|
||
|
|
}
|
||
|
|
provider := call.GetConfigGameProvider(common.ProviderTada)
|
||
|
|
if provider == nil {
|
||
|
|
resp.ErrorCode = ErrorCodeOther
|
||
|
|
return
|
||
|
|
}
|
||
|
|
// 验证token
|
||
|
|
uid, _ := db.Redis().GetInt(common.GetRedisKeyToken(req.Token))
|
||
|
|
if uid == 0 {
|
||
|
|
var err error
|
||
|
|
uid, err = strconv.Atoi(req.UserId)
|
||
|
|
if err != nil || uid == 0 {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
resp.ErrorCode = ErrorCodeTokenExpired
|
||
|
|
return
|
||
|
|
}
|
||
|
|
}
|
||
|
|
betResp := base.SessionBet(&base.BetReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: ct,
|
||
|
|
SettleAmount: common.CashFloat64ToInt64(req.WinLoseAmount),
|
||
|
|
BetAmount: common.CashFloat64ToInt64(req.BetAmount),
|
||
|
|
TurnOver: common.CashFloat64ToInt64(req.TurnOver),
|
||
|
|
Preserve: common.CashFloat64ToInt64(req.Preserve),
|
||
|
|
SessionType: req.Type,
|
||
|
|
GameID: req.Game,
|
||
|
|
Provider: provider,
|
||
|
|
BetID: fmt.Sprintf("%d", req.Round),
|
||
|
|
SessionID: fmt.Sprintf("%d", req.SessionID),
|
||
|
|
Time: req.WagersTime,
|
||
|
|
})
|
||
|
|
|
||
|
|
if betResp.Code == base.CodeInnerError {
|
||
|
|
resp.ErrorCode = ErrorCodeOther
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if betResp.Code == base.CodeNotEnoughAmount {
|
||
|
|
resp.ErrorCode = ErrorCodeNotEnoughBalance
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if betResp.Code == base.CodeAccepted {
|
||
|
|
resp.TxID = betResp.MyUUID
|
||
|
|
resp.ErrorCode = ErrorCodeAccepted
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
// defer func() {
|
||
|
|
// // 更新游戏次数
|
||
|
|
// if resp.ErrorCode == ErrorCodeSuccess {
|
||
|
|
// call.UpdateGameSort(provider.ProviderID, req.Game)
|
||
|
|
// }
|
||
|
|
// }()
|
||
|
|
|
||
|
|
resp.UserName = common.GetProviderUserName(fmt.Sprintf("%v", uid))
|
||
|
|
resp.Currency = req.Currency
|
||
|
|
resp.Balance = util.Decimal(float64(betResp.Balance)/common.DecimalDigits, 4)
|
||
|
|
resp.TxID = betResp.MyUUID
|
||
|
|
resp.Token = common.GetProviderUserToken(req.Token)
|
||
|
|
}
|
||
|
|
|
||
|
|
func cancelSessionBet(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
resp := new(BetResp)
|
||
|
|
defer func() {
|
||
|
|
log.Debug("tada cancelSessionBet resp:%+v", *resp)
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := new(SessionBetReq)
|
||
|
|
if !a.SB(req) {
|
||
|
|
resp.ErrorCode = ErrorCodeInvalidParameter
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("tada sessionBet req:%+v", req)
|
||
|
|
a.RetData = resp
|
||
|
|
|
||
|
|
if a.ShouldRoute(req, "Token", common.ProviderAPITypeJson) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
ct := common.GetCurrencyID(req.Currency)
|
||
|
|
if !ct.IsValid() {
|
||
|
|
resp.ErrorCode = ErrorCodeInvalidParameter
|
||
|
|
return
|
||
|
|
}
|
||
|
|
provider := call.GetConfigGameProvider(common.ProviderTada)
|
||
|
|
if provider == nil {
|
||
|
|
resp.ErrorCode = ErrorCodeOther
|
||
|
|
return
|
||
|
|
}
|
||
|
|
// 验证token
|
||
|
|
uid, _ := db.Redis().GetInt(common.GetRedisKeyToken(req.Token))
|
||
|
|
if uid == 0 {
|
||
|
|
var err error
|
||
|
|
uid, err = strconv.Atoi(req.UserId)
|
||
|
|
if err != nil || uid == 0 {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
resp.ErrorCode = ErrorCodeTokenExpired
|
||
|
|
return
|
||
|
|
}
|
||
|
|
}
|
||
|
|
betResp := base.CancelSessionBet(&base.BetReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: ct,
|
||
|
|
BetAmount: common.CashFloat64ToInt64(req.BetAmount),
|
||
|
|
Preserve: common.CashFloat64ToInt64(req.Preserve),
|
||
|
|
BetID: fmt.Sprintf("%d", req.Round),
|
||
|
|
SessionID: fmt.Sprintf("%d", req.SessionID),
|
||
|
|
GameID: req.Game,
|
||
|
|
Provider: provider,
|
||
|
|
Time: req.WagersTime,
|
||
|
|
SessionType: req.Type,
|
||
|
|
})
|
||
|
|
|
||
|
|
if betResp.Code == base.CodeInnerError {
|
||
|
|
resp.ErrorCode = ErrorCodeOther
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if betResp.Code == base.CodeAccepted {
|
||
|
|
resp.TxID = betResp.MyUUID
|
||
|
|
resp.ErrorCode = ErrorCodeAccepted
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
resp.UserName = common.GetProviderUserName(fmt.Sprintf("%v", uid))
|
||
|
|
resp.Currency = req.Currency
|
||
|
|
resp.Balance = util.Decimal(float64(betResp.Balance)/common.DecimalDigits, 4)
|
||
|
|
resp.TxID = betResp.MyUUID
|
||
|
|
resp.Token = common.GetProviderUserToken(req.Token)
|
||
|
|
}
|