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.
325 lines
7.9 KiB
325 lines
7.9 KiB
|
1 year ago
|
package pgsoft
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"server/call"
|
||
|
|
"server/common"
|
||
|
|
"server/db"
|
||
|
|
"server/modules/web/app"
|
||
|
|
"server/modules/web/providers/base"
|
||
|
|
"server/util"
|
||
|
|
"strconv"
|
||
|
|
"strings"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
)
|
||
|
|
|
||
|
|
func PGSoft(e *gin.RouterGroup) {
|
||
|
|
e.POST("/VerifySession", verifySession)
|
||
|
|
e.POST("/Cash/Get", cashGet)
|
||
|
|
e.POST("/Cash/TransferInOut", transInOut)
|
||
|
|
e.POST("/Cash/Adjustment", adjsutment)
|
||
|
|
}
|
||
|
|
|
||
|
|
func verifySession(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
resp := &CommonResp{}
|
||
|
|
a.RetData = resp
|
||
|
|
thisRet := new(verifySessionResp)
|
||
|
|
errCode := ""
|
||
|
|
flag := false
|
||
|
|
defer func() {
|
||
|
|
if flag {
|
||
|
|
a.ResponseB()
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if errCode != "" {
|
||
|
|
resp.Error = &Error{
|
||
|
|
Code: errCode,
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
resp.Data = thisRet
|
||
|
|
}
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := new(verifySessionReq)
|
||
|
|
c.Request.ParseForm()
|
||
|
|
util.ParseFormReq(c.Request.PostForm, req)
|
||
|
|
log.Debug("pgsoft VerifySession req:%+v,traceID:%v", c.Request.Form, c.Query("trace_id"))
|
||
|
|
if req.OperatorToken != OperatorToken || req.SecretKey != SecretKey {
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if a.ShouldRoute(req, "OperatorPlayerSession", common.ProviderAPITypePostform) {
|
||
|
|
flag = true
|
||
|
|
return
|
||
|
|
}
|
||
|
|
// 验证token
|
||
|
|
uid, _ := db.Redis().GetInt(common.GetRedisKeyToken(req.OperatorPlayerSession))
|
||
|
|
if uid == 0 {
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
p, _ := call.GetUserXInfo(uid, "nick")
|
||
|
|
thisRet.PlayerName = common.GetProviderUserName(fmt.Sprintf("%v", uid))
|
||
|
|
thisRet.Currency = strings.ToUpper(common.CurrencyType(currency).GetCurrencyName())
|
||
|
|
thisRet.Nickname = p.Nick
|
||
|
|
log.Debug("thisRet:%+v", thisRet)
|
||
|
|
}
|
||
|
|
|
||
|
|
func cashGet(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
resp := &CommonResp{}
|
||
|
|
a.RetData = resp
|
||
|
|
thisRet := new(CashGetResp)
|
||
|
|
errCode := ""
|
||
|
|
flag := false
|
||
|
|
defer func() {
|
||
|
|
if flag {
|
||
|
|
a.ResponseB()
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if errCode != "" {
|
||
|
|
resp.Error = &Error{
|
||
|
|
Code: errCode,
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
resp.Data = thisRet
|
||
|
|
}
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := new(CashGetReq)
|
||
|
|
c.Request.ParseForm()
|
||
|
|
util.ParseFormReq(c.Request.PostForm, req)
|
||
|
|
log.Debug("pgsoft cashGet req:%+v,traceID:%v", req, c.Query("trace_id"))
|
||
|
|
if req.OperatorToken != OperatorToken || req.SecretKey != SecretKey {
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if a.ShouldRoute(req, "OperatorPlayerSession", common.ProviderAPITypePostform) {
|
||
|
|
flag = true
|
||
|
|
return
|
||
|
|
}
|
||
|
|
// 验证token
|
||
|
|
uid, _ := db.Redis().GetInt(common.GetRedisKeyToken(req.OperatorPlayerSession))
|
||
|
|
if uid == 0 {
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
// reqUID, err := strconv.Atoi(req.PlayerName)
|
||
|
|
// if err != nil || reqUID != uid {
|
||
|
|
// errCode = "1034"
|
||
|
|
// return
|
||
|
|
// }
|
||
|
|
currency, err := db.Redis().GetInt(common.GetRedisKeyGameCurrency(uid))
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
ct := common.CurrencyType(currency)
|
||
|
|
thisRet.CurrencyCode = strings.ToUpper(ct.GetCurrencyName())
|
||
|
|
thisRet.BalanceAmount = call.GetUserCurrencyFloat(uid, ct, 2)
|
||
|
|
thisRet.UpdatedTime = time.Now().Unix()
|
||
|
|
}
|
||
|
|
|
||
|
|
func transInOut(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
resp := &CommonResp{}
|
||
|
|
a.RetData = resp
|
||
|
|
thisRet := new(TransInOutResp)
|
||
|
|
errCode := ""
|
||
|
|
flag := false
|
||
|
|
defer func() {
|
||
|
|
if flag {
|
||
|
|
a.ResponseB()
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if errCode != "" {
|
||
|
|
resp.Error = &Error{
|
||
|
|
Code: errCode,
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
resp.Data = thisRet
|
||
|
|
}
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := new(TransInOutReq)
|
||
|
|
c.Request.ParseForm()
|
||
|
|
util.ParseFormReq(c.Request.PostForm, req)
|
||
|
|
log.Debug("pgsoft transInOut req:%+v,traceID:%v", req, c.Query("trace_id"))
|
||
|
|
if req.OperatorToken != OperatorToken || req.SecretKey != SecretKey {
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
// 验证token
|
||
|
|
// uid, _ := db.Redis().GetInt(common.GetRedisKeyToken(req.OperatorPlayerSession))
|
||
|
|
// if uid == 0 {
|
||
|
|
// errCode = "1034"
|
||
|
|
// return
|
||
|
|
// }
|
||
|
|
if a.ShouldRoute(req, "PlayerName", common.ProviderAPITypePostform) {
|
||
|
|
flag = true
|
||
|
|
return
|
||
|
|
}
|
||
|
|
uid, err := strconv.Atoi(req.PlayerName)
|
||
|
|
if err != nil {
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if !db.Mysql().Exist(&common.PlayerDBInfo{Id: uid}) {
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
currency := common.GetCurrencyID(req.CurrencyCode)
|
||
|
|
if !currency.IsValid() {
|
||
|
|
log.Error("unknown currency:%v", currency)
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
ct := common.CurrencyType(currency)
|
||
|
|
st := common.SessionTypeBet
|
||
|
|
if !req.IsWager {
|
||
|
|
st = common.SessionTypeSettle
|
||
|
|
}
|
||
|
|
provider := call.GetConfigGameProvider(common.ProviderPGSoft)
|
||
|
|
if provider == nil {
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if req.BetAmount == 0 && req.TransferAmount == 0 {
|
||
|
|
thisRet.CurrencyCode = strings.ToUpper(ct.GetCurrencyName())
|
||
|
|
thisRet.BalanceAmount = call.GetUserCurrencyFloat(uid, ct, 2)
|
||
|
|
thisRet.UpdatedTime = req.UpdatedTime
|
||
|
|
return
|
||
|
|
}
|
||
|
|
betResp := base.SessionBet(&base.BetReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: ct,
|
||
|
|
SettleAmount: common.CashFloat64ToInt64(req.WinAmount),
|
||
|
|
BetAmount: common.CashFloat64ToInt64(req.BetAmount),
|
||
|
|
TurnOver: common.CashFloat64ToInt64(req.BetAmount),
|
||
|
|
SessionType: st,
|
||
|
|
GameID: req.GameID,
|
||
|
|
Provider: provider,
|
||
|
|
BetID: req.TansactionID,
|
||
|
|
SessionID: req.ParentBetID,
|
||
|
|
Time: req.UpdatedTime,
|
||
|
|
// SettleWithoutBet: true,
|
||
|
|
})
|
||
|
|
log.Debug("betResp:%+v", betResp)
|
||
|
|
if betResp.Code != 0 {
|
||
|
|
if betResp.Code == base.CodeAccepted {
|
||
|
|
thisRet.BalanceAmount = call.GetUserCurrencyFloat(uid, ct, 2)
|
||
|
|
thisRet.CurrencyCode = strings.ToUpper(ct.GetCurrencyName())
|
||
|
|
thisRet.UpdatedTime = req.UpdatedTime
|
||
|
|
} else {
|
||
|
|
errCode = "1034"
|
||
|
|
if betResp.Code == base.CodeNotEnoughAmount {
|
||
|
|
errCode = "3202"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
thisRet.CurrencyCode = strings.ToUpper(ct.GetCurrencyName())
|
||
|
|
thisRet.BalanceAmount = util.Decimal(float64(betResp.Balance)/common.DecimalDigits, 2)
|
||
|
|
thisRet.UpdatedTime = req.UpdatedTime
|
||
|
|
}
|
||
|
|
|
||
|
|
func adjsutment(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
resp := &CommonResp{}
|
||
|
|
a.RetData = resp
|
||
|
|
thisRet := new(AdjustmentResp)
|
||
|
|
errCode := ""
|
||
|
|
flag := false
|
||
|
|
defer func() {
|
||
|
|
if flag {
|
||
|
|
a.ResponseB()
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if errCode != "" {
|
||
|
|
resp.Error = &Error{
|
||
|
|
Code: errCode,
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
resp.Data = thisRet
|
||
|
|
}
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
req := new(AdjustmentReq)
|
||
|
|
c.Request.ParseForm()
|
||
|
|
util.ParseFormReq(c.Request.PostForm, req)
|
||
|
|
log.Debug("pgsoft adjsutment req:%+v,traceID:%v", req, c.Query("trace_id"))
|
||
|
|
if req.OperatorToken != OperatorToken || req.SecretKey != SecretKey {
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if a.ShouldRoute(req, "PlayerName", common.ProviderAPITypePostform) {
|
||
|
|
flag = true
|
||
|
|
return
|
||
|
|
}
|
||
|
|
uid, err := strconv.Atoi(req.PlayerName)
|
||
|
|
if err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if !db.Mysql().Exist(&common.PlayerDBInfo{Id: uid}) {
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
ct := common.GetCurrencyID(req.CurrencyCode)
|
||
|
|
if !ct.IsValid() {
|
||
|
|
log.Error("unknown currency:%v", ct)
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
provider := call.GetConfigGameProvider(common.ProviderPGSoft)
|
||
|
|
if provider == nil {
|
||
|
|
errCode = "1034"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if req.TransferAmount != 0 {
|
||
|
|
adjustResp := base.Adjustment(&base.AdjustmentReq{
|
||
|
|
UID: uid,
|
||
|
|
CurrencyType: ct,
|
||
|
|
Amount: common.CashFloat64ToInt64(req.TransferAmount),
|
||
|
|
Provider: provider,
|
||
|
|
BetID: req.AdjustmentTransaction,
|
||
|
|
Time: req.AdjustmentTime / 1000,
|
||
|
|
Ess: req.TransactionType,
|
||
|
|
Type: common.SessionTypeAdjustment,
|
||
|
|
})
|
||
|
|
if adjustResp.Code == base.CodeAccepted {
|
||
|
|
thisRet.BalanceAfter = call.GetUserCurrencyFloat(uid, ct, 2)
|
||
|
|
thisRet.BalanceBefore = thisRet.BalanceAfter - req.TransferAmount
|
||
|
|
} else if adjustResp.Code != base.CodeOk {
|
||
|
|
errCode = "1034"
|
||
|
|
if adjustResp.Code == base.CodeNotEnoughAmount {
|
||
|
|
errCode = "3202"
|
||
|
|
}
|
||
|
|
return
|
||
|
|
} else {
|
||
|
|
thisRet.BalanceBefore = util.Decimal(float64(adjustResp.BeforeBalance)/common.DecimalDigits, 2)
|
||
|
|
thisRet.BalanceAfter = util.Decimal(float64(adjustResp.Balance)/common.DecimalDigits, 2)
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
thisRet.BalanceBefore = call.GetUserCurrencyFloat(uid, ct, 2)
|
||
|
|
thisRet.BalanceAfter = thisRet.BalanceBefore
|
||
|
|
}
|
||
|
|
thisRet.AdjustAmount = req.TransferAmount
|
||
|
|
thisRet.UpdatedTime = time.Now().Unix()
|
||
|
|
}
|