休闲平台上下分

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"` Message string `json:"message"`
Success bool `json:"success"` 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) var logtype = int32(common.GainWayPlatformUpScore)
remainNum = player.Coin remainNum = player.Coin
platform := player.Platform platform := player.Platform
//玩家在游戏内 //玩家在游戏内
if player.scene != nil { if player.scene != nil {
@ -3033,11 +3032,23 @@ func init() {
logger.Logger.Errorf("model.InsertCoinLogs err:%v log:%v", err, coinlogex) logger.Logger.Errorf("model.InsertCoinLogs err:%v log:%v", err, coinlogex)
return err return err
} }
pack.Success = true return nil
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
pack.Code = int(webapiproto.TagCode_SUCCESS)
pack.Message = "返回成功" pack.Message = "返回成功"
return nil if data != nil {
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) { 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) jsonDataRsp, err = json.Marshal(pack)
if err != nil { if err != nil {
@ -3054,37 +3065,98 @@ func init() {
WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/platform/downscore", WebAPIHandlerWrapper( WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/platform/downscore", WebAPIHandlerWrapper(
func(tNode *transact.TransNode, params []byte) (int, interface{}) { func(tNode *transact.TransNode, params []byte) (int, interface{}) {
var AccountInfo *webapi.PlatfromCreateAccountReq var msg *webapi.PlatfromDownScoreReq
err := json.Unmarshal(params, &AccountInfo) err := json.Unmarshal(params, &msg)
if err != nil { 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, Success: false,
Code: 200, Code: 200,
Message: "未知错误", Message: "未知错误",
} }
logger.Logger.Tracef("/api/platform/downscore %v", pack)
var jsonDataRsp []byte var jsonDataRsp []byte
player := PlayerMgrSington.GetPlayerByAccount(msg.Username)
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { //玩家在线
if player != nil {
var remainNum int64
var addcoin int64 = -player.Coin
var logtype = int32(common.GainWayPlatformDownScore)
pack.Success = true remainNum = player.Coin
pack.Message = "返回成功" platform := player.Platform
return nil //玩家在游戏内
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) { if player.scene != nil {
pack.Code = int(webapiproto.TagCode_FAILED)
jsonDataRsp, err = json.Marshal(pack) pack.Message = "Unsupported!!! because player in scene!"
if err != nil { return common.ResponseTag_ParamError, pack
logger.Logger.Errorf("/api/platform/downscore err: %v", err) }
if len(platform) > 0 {
pack.Code = int(webapiproto.TagCode_FAILED)
pack.Message = "player platform forbit!"
return common.ResponseTag_ParamError, pack
} }
tNode.TransRep.RetFiels = jsonDataRsp if player.Coin+addcoin < 0 {
tNode.Resume() pack.Code = int(webapiproto.TagCode_FAILED)
}), "/api/platform/downscore").Start() 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.Data.Count = 0
jsonDataRsp, err = json.Marshal(pack)
if err != nil {
logger.Logger.Errorf("/api/platform/downscore err: %v", err)
}
tNode.TransRep.RetFiels = jsonDataRsp
tNode.Resume()
}), "/api/platform/downscore").Start()
}
return common.ResponseTag_TransactYield, jsonDataRsp return common.ResponseTag_TransactYield, jsonDataRsp
})) }))