From fec3f975333201311559234ae8944e60320e832f Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Wed, 9 Apr 2025 16:50:05 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=B7=BB=E5=8A=A0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbproxy/svc/l_coinlog.go | 1 + model/coinlog.go | 3 +++ webapi/deprecated.go | 22 +++++++++------- worldsrv/cachedata.go | 19 ++++++++++++++ worldsrv/player.go | 8 +++++- worldsrv/trascate_webapi.go | 52 ++++++++++++++++++++++++++++++------- 6 files changed, 85 insertions(+), 20 deletions(-) diff --git a/dbproxy/svc/l_coinlog.go b/dbproxy/svc/l_coinlog.go index 92bcb0b..28702ff 100644 --- a/dbproxy/svc/l_coinlog.go +++ b/dbproxy/svc/l_coinlog.go @@ -34,6 +34,7 @@ func CoinLogsCollection(plt string) *mongo.Collection { c_coinlogrec.EnsureIndex(mgo.Index{Key: []string{"ts"}, Background: true, Sparse: true}) c_coinlogrec.EnsureIndex(mgo.Index{Key: []string{"channel"}, Background: true, Sparse: true}) c_coinlogrec.EnsureIndex(mgo.Index{Key: []string{"-ts", "logtype", "cointype", "channel"}, Background: true, Sparse: true}) + c_coinlogrec.EnsureIndex(mgo.Index{Key: []string{"transferid"}, Background: true, Sparse: true}) } return c_coinlogrec } diff --git a/model/coinlog.go b/model/coinlog.go index bdc91f3..cb81dab 100644 --- a/model/coinlog.go +++ b/model/coinlog.go @@ -44,6 +44,7 @@ type CoinLog struct { DiamondAdd int64 // 钻石加成 GameFreeId int64 // 场次id BaseCoin int64 // 底分 + TransferID string // 订单号 } type CoinLogV1 struct { @@ -90,6 +91,7 @@ type CoinLogParam struct { BaseCoin int64 // 底注 Operator string // 操作人 Remark string // 备注 + TransferID string } func NewCoinLogEx(param *CoinLogParam) *CoinLog { @@ -110,6 +112,7 @@ func NewCoinLogEx(param *CoinLogParam) *CoinLog { cl.Ts = tNow.Unix() cl.GameFreeId = param.GameFreeID cl.BaseCoin = param.BaseCoin + cl.TransferID = param.TransferID //todo 后期修改数据结构,余额,加成,各用一个字段存储; NewCoinLogExV2 switch param.ChangeType { diff --git a/webapi/deprecated.go b/webapi/deprecated.go index 1f50fdb..b5cd44d 100644 --- a/webapi/deprecated.go +++ b/webapi/deprecated.go @@ -259,17 +259,19 @@ type PlatfromGameLoginRsp struct { // 上分请求 type PlatfromUpScoreReq struct { - Username string `json:"username"` - Channel string `json:"channel"` - Timestamp string `json:"timestamp"` - Count string `json:"count"` + Username string `json:"username"` + Channel string `json:"channel"` + Timestamp string `json:"timestamp"` + Count string `json:"count"` + TransferID string `json:"transferid"` } // 上分返回 type PlatfromUpScoreRsp struct { Code int `json:"code"` Data struct { - Count int64 `json:"count"` + Count int64 `json:"count"` + TransferID string `json:"transferid"` } `json:"data"` Message string `json:"message"` Success bool `json:"success"` @@ -277,16 +279,18 @@ type PlatfromUpScoreRsp struct { // 下分请求 type PlatfromDownScoreReq struct { - Username string `json:"username"` - Channel string `json:"channel"` - Timestamp string `json:"timestamp"` + Username string `json:"username"` + Channel string `json:"channel"` + Timestamp string `json:"timestamp"` + TransferID string `json:"transferid"` } // 下分返回 type PlatfromDownScoreRsp struct { Code int `json:"code"` Data struct { - Money string `json:"money"` + Money string `json:"money"` + TransferID string `json:"transferid"` } `json:"data"` Message string `json:"message"` Success bool `json:"success"` diff --git a/worldsrv/cachedata.go b/worldsrv/cachedata.go index f768133..2230430 100644 --- a/worldsrv/cachedata.go +++ b/worldsrv/cachedata.go @@ -129,6 +129,25 @@ func (this *CacheDataManager) ClearCacheBill(billNo int, platform string) { this.HourCache.Delete(key) } +func (this *CacheDataManager) CacheBillStr(billNo string, platform string) { + key := fmt.Sprintf("BillNo-%v-%v", billNo, platform) + this.addCacheData(AfterHour, key, key) +} + +func (this *CacheDataManager) CacheBillStrCheck(billNo string, platform string) bool { + key := fmt.Sprintf("BillNo-%v-%v", billNo, platform) + if _, ok := this.HourCache.Load(key); ok { + return true + } else { + return false + } +} + +func (this *CacheDataManager) ClearCacheStrBill(billNo string, platform string) { + key := fmt.Sprintf("BillNo-%v-%v", billNo, platform) + this.HourCache.Delete(key) +} + func init() { common.ClockMgrSingleton.RegisterSinker(CacheDataMgr) } diff --git a/worldsrv/player.go b/worldsrv/player.go index 724edf0..6e28527 100644 --- a/worldsrv/player.go +++ b/worldsrv/player.go @@ -1436,7 +1436,7 @@ func (this *Player) AddDiamond(num, add int64, gainWay int32, oper, remark strin // AddCoin 添加钻石 // num 总数 // add num总数中有多少是加成获得 -func (this *Player) AddCoin(num, add int64, gainWay int32, oper, remark string) { +func (this *Player) AddCoin(num, add int64, gainWay int32, oper, remark string, param ...string) { if num == 0 { return } @@ -1467,6 +1467,10 @@ func (this *Player) AddCoin(num, add int64, gainWay int32, oper, remark string) this.SendDiffData() if !this.IsRob { + var transferID string + if len(param) > 0 { + transferID = param[0] + } log := model.NewCoinLogEx(&model.CoinLogParam{ Platform: this.Platform, SnID: this.SnId, @@ -1482,7 +1486,9 @@ func (this *Player) AddCoin(num, add int64, gainWay int32, oper, remark string) BaseCoin: 0, Operator: oper, Remark: remark, + TransferID: transferID, }) + if log != nil { mq.Write(log) } diff --git a/worldsrv/trascate_webapi.go b/worldsrv/trascate_webapi.go index a126a6f..164edc4 100644 --- a/worldsrv/trascate_webapi.go +++ b/worldsrv/trascate_webapi.go @@ -3010,8 +3010,15 @@ func init() { //玩家在线 if player != nil { + if CacheDataMgr.CacheBillStrCheck(msg.TransferID, player.Platform) { + jsonDataRsp, err = json.Marshal(pack) + return common.ResponseTag_ParamError, jsonDataRsp + } + CacheDataMgr.CacheBillStr(msg.TransferID, player.Platform) + remainNum = player.Coin if player.Coin+addCoin < 0 { + CacheDataMgr.ClearCacheStrBill(msg.TransferID, player.Platform) pack.Code = int(webapiproto.TagCode_FAILED) pack.Message = "coin not enough!" return common.ResponseTag_ParamError, pack @@ -3030,7 +3037,7 @@ func init() { pack.Code = int(webapiproto.TagCode_SUCCESS) pack.Message = data.(error).Error() } else { - player.AddCoin(addCoin, 0, common.GainWayPlatformUpScore, "platform", "平台上分") + player.AddCoin(addCoin, 0, common.GainWayPlatformUpScore, "platform", "平台上分", msg.TransferID) player.SendDiffData() } @@ -3043,15 +3050,23 @@ func init() { tNode.TransRep.RetFiels = jsonDataRsp tNode.Resume() + CacheDataMgr.ClearCacheStrBill(msg.TransferID, player.Platform) }), "/api/platform/upscore").StartByFixExecutor("UserName:" + msg.Username) } else { //玩家不在线 var acc *model.Account - acc, err = model.GetAccountByName("1", msg.Username) - if acc == nil { - return common.ResponseTag_ParamError, pack - } task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { + acc, err = model.GetAccountByName("1", msg.Username) + if acc == nil { + return errors.New("not found") + } + + if CacheDataMgr.CacheBillStrCheck(msg.TransferID, acc.Platform) { + jsonDataRsp, err = json.Marshal(pack) + return errors.New("transfer repeat") + } + CacheDataMgr.CacheBillStr(msg.TransferID, acc.Platform) + findPlayer, _ := model.GetPlayerDataBySnId("1", int32(acc.SnId), false, true) if findPlayer != nil { remainNum = findPlayer.Coin @@ -3072,13 +3087,14 @@ func init() { BaseCoin: 0, Operator: "休闲平台", Remark: "不在线平台上分", + TransferID: msg.TransferID, }) err := model.UpdatePlayerCoin(findPlayer.Platform, findPlayer.SnId, findPlayer.Coin+addCoin, findPlayer.Diamond, findPlayer.SafeBoxCoin, findPlayer.CoinPayTs, findPlayer.SafeBoxCoinTs, findPlayer.MoneyPayTotal, findPlayer.ShopID) if err != nil { logger.Logger.Errorf("model.UpdatePlayerCoin err:%v.", err) - return nil + return err } //账变记录 @@ -3113,6 +3129,7 @@ func init() { tNode.TransRep.RetFiels = jsonDataRsp tNode.Resume() + CacheDataMgr.ClearCacheStrBill(msg.TransferID, acc.Platform) }), "/api/platform/upscore").StartByFixExecutor("UserName:" + msg.Username) } @@ -3159,6 +3176,12 @@ func init() { return common.ResponseTag_ParamError, jsonDataRsp } + if CacheDataMgr.CacheBillStrCheck(msg.TransferID, player.Platform) { + jsonDataRsp, err = json.Marshal(pack) + return common.ResponseTag_ParamError, jsonDataRsp + } + CacheDataMgr.CacheBillStr(msg.TransferID, player.Platform) + task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { return nil }), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) { @@ -3167,7 +3190,7 @@ func init() { remainNum = player.Coin logger.Logger.Tracef("/api/platform/downscore player online snid:%v, player.Coin:%v", player.SnId, player.Coin) - player.AddCoin(addCoin, 0, common.GainWayPlatformDownScore, "platform", "平台下分") + player.AddCoin(addCoin, 0, common.GainWayPlatformDownScore, "platform", "平台下分", msg.TransferID) player.SendDiffData() pack.Code = int(webapiproto.TagCode_SUCCESS) @@ -3182,16 +3205,23 @@ func init() { tNode.TransRep.RetFiels = jsonDataRsp tNode.Resume() + CacheDataMgr.ClearCacheStrBill(msg.TransferID, player.Platform) }), "/api/platform/downscore").StartByFixExecutor("UserName:" + msg.Username) } else { //玩家不在线 + var acc *model.Account task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - var acc *model.Account acc, err = model.GetAccountByName("1", msg.Username) if acc == nil { - return nil + return errors.New("not found") } + if CacheDataMgr.CacheBillStrCheck(msg.TransferID, acc.Platform) { + jsonDataRsp, err = json.Marshal(pack) + return errors.New("transfer repeat") + } + CacheDataMgr.CacheBillStr(msg.TransferID, acc.Platform) + findPlayer, _ := model.GetPlayerDataBySnId(acc.Platform, int32(acc.SnId), false, true) if findPlayer != nil { @@ -3219,13 +3249,14 @@ func init() { BaseCoin: 0, Operator: "休闲平台", Remark: "不在线平台下分", + TransferID: msg.TransferID, }) err := model.UpdatePlayerCoin(findPlayer.Platform, findPlayer.SnId, findPlayer.Coin+addCoin, findPlayer.Diamond, findPlayer.SafeBoxCoin, findPlayer.CoinPayTs, findPlayer.SafeBoxCoinTs, findPlayer.MoneyPayTotal, findPlayer.ShopID) if err != nil { logger.Logger.Errorf("model.UpdatePlayerCoin err:%v.", err) - return nil + return err } //账变记录 @@ -3260,6 +3291,7 @@ func init() { tNode.TransRep.RetFiels = jsonDataRsp tNode.Resume() + CacheDataMgr.ClearCacheStrBill(msg.TransferID, acc.Platform) }), "/api/platform/downscore").StartByFixExecutor("UserName:" + msg.Username) } return common.ResponseTag_TransactYield, jsonDataRsp