休闲平台上下分

This commit is contained in:
DESKTOP-45ANQ2C\unis 2024-12-16 10:24:56 +08:00
parent 358da77924
commit 42fa6c57d3
2 changed files with 111 additions and 22 deletions

View File

@ -274,3 +274,20 @@ type PlatfromUpScoreRsp struct {
Message string `json:"message"`
Success bool `json:"success"`
}
// 下分请求
type PlatfromDownScoreReq struct {
Username string `json:"username"`
Channel string `json:"channel"`
Timestamp int64 `json:"timestamp"`
}
// 下分返回
type PlatfromDownScoreRsp struct {
Code int `json:"code"`
Data struct {
Count int64 `json:"count"`
} `json:"data"`
Message string `json:"message"`
Success bool `json:"success"`
}

View File

@ -2990,7 +2990,6 @@ func init() {
var logtype = int32(common.GainWayPlatformUpScore)
remainNum = player.Coin
platform := player.Platform
//玩家在游戏内
if player.scene != nil {
@ -3033,11 +3032,23 @@ func init() {
logger.Logger.Errorf("model.InsertCoinLogs err:%v log:%v", err, coinlogex)
return err
}
pack.Success = true
return nil
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
pack.Code = int(webapiproto.TagCode_SUCCESS)
pack.Message = "返回成功"
return nil
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
if data != nil {
pack.Success = true
pack.Code = int(webapiproto.TagCode_SUCCESS)
pack.Message = data.(error).Error()
} else {
player.Coin += addcoin
player.SendDiffData()
}
pack.Success = true
pack.Data.Count = msg.Count
jsonDataRsp, err = json.Marshal(pack)
if err != nil {
@ -3054,28 +3065,88 @@ func init() {
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/platform/downscore", WebAPIHandlerWrapper(
func(tNode *transact.TransNode, params []byte) (int, interface{}) {
var AccountInfo *webapi.PlatfromCreateAccountReq
err := json.Unmarshal(params, &AccountInfo)
var msg *webapi.PlatfromDownScoreReq
err := json.Unmarshal(params, &msg)
if err != nil {
logger.Logger.Error("Unmarshal webapi.PlatfromCreateAccountReq error:", err)
logger.Logger.Error("Unmarshal webapi.PlatfromDownScoreReq error:", err)
}
pack := &webapi.PlatfromGameLoginRsp{
logger.Logger.Tracef("/api/platform/downscore downScoreReqInfo%v", msg)
pack := &webapi.PlatfromDownScoreRsp{
Success: false,
Code: 200,
Message: "未知错误",
}
logger.Logger.Tracef("/api/platform/downscore %v", pack)
var jsonDataRsp []byte
player := PlayerMgrSington.GetPlayerByAccount(msg.Username)
//玩家在线
if player != nil {
var remainNum int64
var addcoin int64 = -player.Coin
var logtype = int32(common.GainWayPlatformDownScore)
remainNum = player.Coin
platform := player.Platform
//玩家在游戏内
if player.scene != nil {
pack.Code = int(webapiproto.TagCode_FAILED)
pack.Message = "Unsupported!!! because player in scene!"
return common.ResponseTag_ParamError, pack
}
if len(platform) > 0 {
pack.Code = int(webapiproto.TagCode_FAILED)
pack.Message = "player platform forbit!"
return common.ResponseTag_ParamError, pack
}
if player.Coin+addcoin < 0 {
pack.Code = int(webapiproto.TagCode_FAILED)
pack.Message = "coin not enough!"
return common.ResponseTag_ParamError, pack
}
//增加帐变记录
coinlogex := model.NewCoinLogEx(&model.CoinLogParam{
Platform: player.Platform,
SnID: player.SnId,
Channel: player.Channel,
ChangeType: common.LoginTypePlatformToken,
ChangeNum: -player.Coin,
RemainNum: remainNum + player.Coin,
Add: 0,
LogType: logtype,
GameID: 0,
GameFreeID: 0,
BaseCoin: 0,
})
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
err := model.InsertCoinLog(coinlogex)
if err != nil {
//回滚到对账日志
model.RemoveCoinLogOne(platform, coinlogex.LogId)
logger.Logger.Errorf("model.InsertCoinLogs err:%v log:%v", err, coinlogex)
return err
}
return nil
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
pack.Code = int(webapiproto.TagCode_SUCCESS)
pack.Message = "返回成功"
if data != nil {
pack.Success = true
pack.Code = int(webapiproto.TagCode_SUCCESS)
pack.Message = data.(error).Error()
} else {
player.Coin += addcoin
player.SendDiffData()
}
pack.Success = true
pack.Message = "返回成功"
return nil
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
pack.Data.Count = 0
jsonDataRsp, err = json.Marshal(pack)
if err != nil {
@ -3085,6 +3156,7 @@ func init() {
tNode.TransRep.RetFiels = jsonDataRsp
tNode.Resume()
}), "/api/platform/downscore").Start()
}
return common.ResponseTag_TransactYield, jsonDataRsp
}))