印度包网
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.

144 lines
3.2 KiB

package jili2
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 JiLi(e *gin.RouterGroup) {
e.POST("/VerifySession", VerifySession)
e.POST("/Cash/Get", GetPlayerBalance)
e.POST("/Cash/Bet", PlaceBet)
}
func GetGameID(providerID int, gameCode string) int {
game := call.GetConfigGameListByCode(providerID, gameCode)
if game != nil {
return game.GameID
}
return 0
}
func VerifySession(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.ResponseB()
}()
req := &VerifySessionReq{}
resp := &VerifySessionResp{}
a.RetData = resp
if !a.SB(req) {
resp.Code = ErrCodeInternalError
return
}
log.Debug("VerifySession req:%+v", req)
uid, err := strconv.Atoi(req.Uname)
if err != nil {
log.Error("err:%v", err)
resp.Code = ErrCodePlayerNotFound
return
}
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
if err != nil {
log.Error("err:%v", err)
resp.Code = ErrCodeInternalError
return
}
resp.Data.Balance = call.GetUserCurrencyFloat(uid, common.CurrencyType(currency), 2)
a.Data = resp
}
func GetPlayerBalance(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.ResponseB()
}()
req := &GetBalanceRequest{}
resp := &GetBalanceResponse{}
a.RetData = resp
if !a.SB(req) {
resp.Code = ErrCodeInternalError
return
}
log.Debug("GetPlayerBalance req:%+v", req)
uid, err := strconv.Atoi(req.Uname)
if err != nil {
log.Error("err:%v", err)
resp.Code = ErrCodePlayerNotFound
return
}
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
if err != nil {
log.Error("err:%v", err)
resp.Code = ErrCodeInternalError
return
}
resp.Data.Uname = req.Uname
resp.Data.Balance = call.GetUserCurrencyFloat(uid, common.CurrencyType(currency), 2)
a.Data = resp
}
func PlaceBet(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.ResponseB()
}()
req := &PlaceBetRequest{}
resp := &PlaceBetResponse{}
a.RetData = resp
if !a.SB(req) {
resp.Code = ErrCodeInternalError
return
}
log.Debug("PlaceBet:%+v", req)
// 验证token
uid, _ := db.Redis().GetInt(common.GetRedisKeyToken(req.Token))
if uid == 0 {
resp.Code = ErrCodePlayerNotFound
return
}
provider := call.GetConfigGameProvider(common.ProviderJiLi2)
now := time.Now().Unix()
betReq := &base.BetReq{
UID: uid,
CurrencyType: common.CurrencyINR,
BetAmount: int64(req.Bet * common.DecimalDigits),
TurnOver: int64(req.Bet * common.DecimalDigits),
SettleAmount: int64(req.Award * common.DecimalDigits),
SessionType: common.SessionTypeSettle,
GameID: GetGameID(common.ProviderJiLi2, req.GameID),
GameName: req.GameID,
Provider: provider,
BetID: req.BetID,
SessionID: req.SessionID,
Time: now,
}
betResp := base.SessionBet(betReq)
if betResp.Code != base.CodeOk {
resp.Code = ErrCodeInternalError
if betResp.Code == base.CodeAccepted {
resp.Code = ErrCodeInternalError
} else if betResp.Code == base.CodeNotEnoughAmount {
resp.Code = ErrCodeInsufficientBal
}
return
}
resp.Data.Balance = util.Decimal(float64(betResp.Balance)/common.DecimalDigits, 2)
a.Data = resp
}