diff --git a/webapi/deprecated.go b/webapi/deprecated.go index 010eb72..657187a 100644 --- a/webapi/deprecated.go +++ b/webapi/deprecated.go @@ -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"` +} diff --git a/worldsrv/trascate_webapi.go b/worldsrv/trascate_webapi.go index b681bdd..700871d 100644 --- a/worldsrv/trascate_webapi.go +++ b/worldsrv/trascate_webapi.go @@ -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,37 +3065,98 @@ 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) - 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 - pack.Message = "返回成功" - return nil - }), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) { - - jsonDataRsp, err = json.Marshal(pack) - if err != nil { - logger.Logger.Errorf("/api/platform/downscore err: %v", err) + 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 } - tNode.TransRep.RetFiels = jsonDataRsp - tNode.Resume() - }), "/api/platform/downscore").Start() + 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.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 }))