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.
179 lines
4.7 KiB
179 lines
4.7 KiB
package jin |
|
|
|
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 PG(e *gin.RouterGroup) { |
|
e.POST("/authentication", Auth) |
|
e.POST("/result", GameBet) |
|
e.POST("/jackpot", Jackpot) |
|
} |
|
|
|
func GetGameID(providerID int, gameCode string) int { |
|
game := call.GetConfigGameListByCode(providerID, gameCode) |
|
if game != nil { |
|
return game.GameID |
|
} |
|
return 0 |
|
} |
|
|
|
func Auth(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.ResponseB() |
|
}() |
|
req := &AuthReq{} |
|
resp := &AuthResp{} |
|
a.RetData = resp |
|
if !a.SB(req) { |
|
resp.Code = CodeRequestInvalidParams |
|
return |
|
} |
|
log.Debug("Auth req:%+v", req) |
|
token := req.Token |
|
if a.ShouldRoute(req, "Token", common.ProviderAPITypePostform) { |
|
return |
|
} |
|
// 验证token |
|
uid, _ := db.Redis().GetInt(common.GetRedisKeyToken(req.Token)) |
|
if uid == 0 { |
|
resp.Code = CodeUserNotFound |
|
return |
|
} |
|
resp.Data.Accounts = strconv.Itoa(uid) |
|
resp.Data.Nickname = strconv.Itoa(uid) |
|
resp.Data.Token = token |
|
resp.Data.Amount = call.GetUserCurrencyFloat(uid, common.CurrencyType(0), 2) |
|
log.Debug("AuthResp:%+v", resp) |
|
a.Data = resp |
|
} |
|
|
|
func GameBet(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.ResponseB() |
|
}() |
|
req := &GameBetReq{} |
|
resp := &GameBetResp{} |
|
a.RetData = resp |
|
if !a.SB(req) { |
|
resp.Code = CodeRequestInvalidParams |
|
return |
|
} |
|
log.Debug("jin GameBet:%+v", req) |
|
/* |
|
// jin GameBet:&{Reference:581622397157433172 OperatorID:695865 Accounts:101239 Token:cNFFLVZCHLNGZGJMI GameID:24000 |
|
RoomID:24001 WinAmount:0 BetAmount:10 RecordType:0 BetReferenceID:581622397157433172 RoundID:6755680920055585941 IsEndRound:0} |
|
// jin GameBet:&{Reference:581622397157433173 OperatorID:695865 Accounts:101239 Token:cNFFLVZCHLNGZGJMI GameID:24000 |
|
RoomID:24001 WinAmount:14.3 BetAmount:0 RecordType:1 BetReferenceID:581622397157433172 RoundID:6755680920055585941 IsEndRound:1} |
|
*/ |
|
if a.ShouldRoute(req, "Token", common.ProviderAPITypePostform) { |
|
return |
|
} |
|
// 验证token |
|
uid, _ := db.Redis().GetInt(common.GetRedisKeyToken(req.Token)) |
|
if uid == 0 { |
|
resp.Code = CodeUserNotFound |
|
log.Error("err: uid=%v", uid) |
|
return |
|
} |
|
|
|
provider := call.GetConfigGameProvider(common.ProviderJin) |
|
now := time.Now().Unix() |
|
betReq := &base.BetReq{ |
|
UID: uid, |
|
BetAmount: int64(req.BetAmount * common.DecimalDigits), |
|
TurnOver: int64(req.BetAmount * common.DecimalDigits), |
|
SettleAmount: int64(req.WinAmount * common.DecimalDigits), |
|
SessionType: base.SessionTypeBet, |
|
GameID: GetGameID(common.ProviderJin, req.GameID), |
|
GameName: req.GameID, |
|
Provider: provider, |
|
BetID: req.RoundID, |
|
SessionID: req.BetReferenceID, |
|
Time: now, |
|
CurrencyType: common.CurrencyINR, |
|
} |
|
if req.IsEndRound == 1 { // 结算回合 |
|
betReq.SessionType = base.SessionTypeSettle |
|
} |
|
betResp := base.SessionBet(betReq) |
|
if betResp.Code != base.CodeOk { |
|
resp.Code = CodeSuccess |
|
if betResp.Code == base.CodeAccepted { |
|
resp.Code = CodeDuplicateOrder |
|
} else if betResp.Code == base.CodeNotEnoughAmount { |
|
resp.Code = CodeInsufficientBalance |
|
} |
|
log.Error("GameBetResp err:%v", resp.Code) |
|
return |
|
} |
|
resp.Data.Amount = util.Decimal(float64(betResp.Balance)/common.DecimalDigits, 2) |
|
log.Debug("GameBetResp:%+v", resp) |
|
a.Data = resp |
|
} |
|
|
|
func Jackpot(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.ResponseB() |
|
}() |
|
req := &JackpotReq{} |
|
resp := &JackpotResp{} |
|
a.RetData = resp |
|
if !a.SB(req) { |
|
resp.Code = CodeRequestInvalidParams |
|
return |
|
} |
|
log.Debug("Jackpot:%+v", req) |
|
if a.ShouldRoute(req, "Token", common.ProviderAPITypePostform) { |
|
return |
|
} |
|
// 验证token |
|
uid, _ := db.Redis().GetInt(common.GetRedisKeyToken(req.Token)) |
|
if uid == 0 { |
|
resp.Code = CodeUserNotFound |
|
return |
|
} |
|
|
|
provider := call.GetConfigGameProvider(common.ProviderJin) |
|
now := time.Now().Unix() |
|
betReq := &base.BetReq{ |
|
UID: uid, |
|
BetAmount: 0, |
|
TurnOver: 0, |
|
SettleAmount: int64(req.WinAmount * common.DecimalDigits), |
|
SessionType: base.SessionTypeSettle, |
|
GameID: GetGameID(common.ProviderJin, req.GameID), |
|
GameName: req.GameID, |
|
Provider: provider, |
|
BetID: req.RoundID, |
|
SessionID: req.BetReferenceID, |
|
Time: now, |
|
} |
|
betResp := base.SessionBet(betReq) |
|
if betResp.Code != base.CodeOk { |
|
resp.Code = CodeSuccess |
|
if betResp.Code == base.CodeAccepted { |
|
resp.Code = CodeDuplicateOrder |
|
} else if betResp.Code == base.CodeNotEnoughAmount { |
|
resp.Code = CodeInsufficientBalance |
|
} |
|
log.Error("GameBetResp err:%v", resp.Code) |
|
return |
|
} |
|
resp.Data.Amount = util.Decimal(float64(betResp.Balance)/common.DecimalDigits, 2) |
|
log.Debug("JackpotResp:%+v", resp) |
|
a.Data = resp |
|
}
|
|
|