From 358da77924e4b42b9989204c26222fe35f02d59a Mon Sep 17 00:00:00 2001 From: "DESKTOP-45ANQ2C\\unis" <121212121@qq.com> Date: Fri, 13 Dec 2024 16:02:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=91=E9=97=B2=E5=B9=B3=E5=8F=B0=E4=B8=8A?= =?UTF-8?q?=E5=88=86=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worldsrv/trascate_webapi.go | 88 +++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 18 deletions(-) diff --git a/worldsrv/trascate_webapi.go b/worldsrv/trascate_webapi.go index b08d445..b681bdd 100644 --- a/worldsrv/trascate_webapi.go +++ b/worldsrv/trascate_webapi.go @@ -2902,6 +2902,8 @@ func init() { "Platform": "1", "Channel": AccountInfo.Channel, "Timestamp": AccountInfo.Timestamp, + "Avatar": AccountInfo.Avatar, + "NickName": AccountInfo.Nickname, "Exp": time.Now().Add(time.Hour * 24).Unix(), }) tokenStr, err := token.SignedString([]byte(common.Config.AppId)) @@ -2933,7 +2935,7 @@ func init() { Plt: acc.Platform, AccId: acc.AccountId.Hex(), NickName: AccountInfo.Nickname, - HeadUrl: AccountInfo.Avater, + HeadUrl: AccountInfo.Avatar, }) if pi == nil || tf == false { @@ -2965,37 +2967,87 @@ func init() { WebAPIHandlerMgrSingleton.RegisteWebAPIHandler("/api/platform/upscore", WebAPIHandlerWrapper( func(tNode *transact.TransNode, params []byte) (int, interface{}) { - var AccountInfo *webapi.PlatfromCreateAccountReq - err := json.Unmarshal(params, &AccountInfo) + var msg *webapi.PlatfromUpScoreReq + err := json.Unmarshal(params, &msg) if err != nil { - logger.Logger.Error("Unmarshal webapi.PlatfromCreateAccountReq error:", err) + logger.Logger.Error("Unmarshal webapi.PlatfromUpScoreReq error:", err) } - pack := &webapi.PlatfromGameLoginRsp{ + logger.Logger.Tracef("/api/platform/upscore upScoreReqInfo%v", msg) + pack := &webapi.PlatfromUpScoreRsp{ Success: false, Code: 200, Message: "未知错误", } - logger.Logger.Tracef("/api/platform/upscore %v", pack) - var jsonDataRsp []byte + player := PlayerMgrSington.GetPlayerByAccount(msg.Username) - task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - pack.Success = true - pack.Message = "返回成功" + //玩家在线 + if player != nil { + var remainNum int64 + var addcoin int64 = msg.Count + var logtype = int32(common.GainWayPlatformUpScore) - return nil - }), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) { + remainNum = player.Coin - jsonDataRsp, err = json.Marshal(pack) - if err != nil { - logger.Logger.Errorf("/api/platform/createUser err: %v", err) + 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/upscore").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: msg.Count, + RemainNum: remainNum + msg.Count, + 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 + } + 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/upscore err: %v", err) + } + + tNode.TransRep.RetFiels = jsonDataRsp + tNode.Resume() + }), "/api/platform/upscore").Start() + } return common.ResponseTag_TransactYield, jsonDataRsp }))