From f637724a618d12babc8ca7cb97bcc19a04711aeb Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Fri, 19 Jul 2024 09:30:19 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=93=E5=85=B7=E5=85=91=E6=8D=A2=E6=92=A4?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbproxy/svc/l_itemlog.go | 9 +++++++++ model/itemdatalog.go | 25 +++++++++++++++++++++++++ worldsrv/action_bag.go | 16 ++++++++++++++-- worldsrv/bagmgr.go | 36 +++++++++++++++++++++++++++++++----- 4 files changed, 79 insertions(+), 7 deletions(-) diff --git a/dbproxy/svc/l_itemlog.go b/dbproxy/svc/l_itemlog.go index 8cb0dcd..4fda8b7 100644 --- a/dbproxy/svc/l_itemlog.go +++ b/dbproxy/svc/l_itemlog.go @@ -102,6 +102,15 @@ func (svc *ItemLogSvc) GetItemCount(req *model.ItemCountParam, count *int64) err return nil } +func (svc *ItemLogSvc) UpdateState(req *model.UpdateParam, res *model.UpdateRes) error { + c := ItemLogsCollection(req.Platform) + if c == nil { + return nil + } + err := c.UpdateId(req.LogId, bson.M{"$set": bson.M{"status": req.State}}) + return err +} + func init() { rpc.Register(new(ItemLogSvc)) } diff --git a/model/itemdatalog.go b/model/itemdatalog.go index 4482baf..f19c122 100644 --- a/model/itemdatalog.go +++ b/model/itemdatalog.go @@ -87,3 +87,28 @@ func GetItemCount(param *ItemCountParam) (int64, error) { return ret, err } + +type UpdateParam struct { + Platform string + LogId bson.ObjectId + State int +} + +type UpdateRes struct { +} + +func UpdateItemState(param *UpdateParam) error { + if rpcCli == nil { + logger.Logger.Warnf("rpcCli is nil") + return errors.New("rpcCli is nil") + } + + var ret UpdateRes + err := rpcCli.CallWithTimeout("ItemLogSvc.UpdateState", param, &ret, time.Second*30) + if err != nil { + logger.Logger.Warnf("UpdateItemState err:%v", err) + return err + } + + return err +} diff --git a/worldsrv/action_bag.go b/worldsrv/action_bag.go index 8244887..7f6b13e 100644 --- a/worldsrv/action_bag.go +++ b/worldsrv/action_bag.go @@ -306,13 +306,25 @@ func CSUpBagInfo(s *netlib.Session, packetid int, data interface{}, sid int64) e send() return nil } - _, _, isF := BagMgrSingleton.AddItem(p, int64(msg.ItemId), int64(-1), 0, common.GainWayItemChange, "sys", "背包内使用兑换", 0, 0, false) + bagInfo, _, isF := BagMgrSingleton.AddItemsV2(&ItemParam{ + P: p, + Change: []*Item{ + { + ItemId: msg.GetItemId(), + ItemNum: -1, + }, + }, + GainWay: common.GainWayItemChange, + Operator: "system", + Remark: "背包内使用兑换", + noLog: false, + }) if isF { pack.RetCode = bag.OpResultCode_OPRC_Sucess pack.NowItemId = item.ItemId pack.NowItemNum = item.ItemNum //获取兑换码 - BagMgrSingleton.ItemExchangeCard(p, msg.ItemId, int32(itemInfo.Num), msg.CardType) + BagMgrSingleton.ItemExchangeCard(p, msg.ItemId, int32(itemInfo.Num), msg.CardType, bagInfo.LogId) } } send() diff --git a/worldsrv/bagmgr.go b/worldsrv/bagmgr.go index ff56c4b..23bad9e 100644 --- a/worldsrv/bagmgr.go +++ b/worldsrv/bagmgr.go @@ -4,12 +4,10 @@ import ( "errors" "fmt" "math" - webapiproto "mongo.games.com/game/protocol/webapi" - "mongo.games.com/game/webapi" - "mongo.games.com/game/worldsrv/internal" "strconv" "time" + "github.com/globalsign/mgo/bson" "mongo.games.com/goserver/core/basic" "mongo.games.com/goserver/core/i18n" "mongo.games.com/goserver/core/logger" @@ -21,7 +19,10 @@ import ( "mongo.games.com/game/proto" "mongo.games.com/game/protocol/bag" playerproto "mongo.games.com/game/protocol/player" + webapiproto "mongo.games.com/game/protocol/webapi" "mongo.games.com/game/srvdata" + "mongo.games.com/game/webapi" + "mongo.games.com/game/worldsrv/internal" ) const ( @@ -63,6 +64,7 @@ type BagInfo struct { Platform string //平台 BagItem map[int32]*Item //背包数据 key为itemId dirty bool + LogId string `bson:"-"` } // BagMgrSingleton 背包管理器 @@ -148,6 +150,7 @@ type ItemParam struct { Operator, Remark string // 操作人,备注 gameId, gameFreeId int64 // 游戏id,场次id noLog bool // 是否不记录日志 + LogId string } type AddItemParam struct { @@ -223,6 +226,7 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int var permitScore, long int64 var changeItems []int32 var newBagInfo *BagInfo + var logId string if _, exist := this.PlayerBag[p.SnId]; !exist { newBagInfo = &BagInfo{ SnId: p.SnId, @@ -312,6 +316,7 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int }) if log != nil { LogChannelSingleton.WriteLog(log) + logId = log.LogId.Hex() } } @@ -342,6 +347,7 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int if len(changeItems) > 0 { newBagInfo.dirty = true + newBagInfo.LogId = logId p.dirty = true this.PlayerBag[p.SnId] = newBagInfo this.SyncBagData(p.SnId, changeItems...) @@ -606,7 +612,7 @@ func (this *BagMgr) SyncBagData(snid int32, changeItemIds ...int32) { } // 兑换话费卡 -func (this *BagMgr) ItemExchangeCard(p *Player, itemId int32, money, cardType int32) bool { +func (this *BagMgr) ItemExchangeCard(p *Player, itemId int32, money, cardType int32, logId string) bool { // 兑换码奖品 var err error var newMsg *model.Message @@ -661,10 +667,30 @@ func (this *BagMgr) ItemExchangeCard(p *Player, itemId int32, money, cardType in ItemNum: 1, // 数量 ObtainTime: time.Now().Unix(), }) - this.AddItems(p, items, 0, common.GainWayItemChange, "system", "背包内使用兑换失败", 0, 0, false) + this.AddItemsV2(&ItemParam{ + P: p, + Change: items, + Add: 0, + GainWay: common.GainWayItemChange, + Operator: "system", + Remark: "背包内使用兑换失败", + gameId: 0, + gameFreeId: 0, + noLog: false, + LogId: logId, + }) logger.Logger.Errorf("获取兑换码失败 snid:%v itemID:%v res:%v err:%v", p.SnId, itemId, res, err) pack.RetCode = bag.OpResultCode_OPRC_Error p.SendToClient(int(bag.SPacketID_PACKET_SC_ITEM_EXCHANGE_RES), pack) + // 标记兑换失败 + task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { + model.UpdateItemState(&model.UpdateParam{ + Platform: p.Platform, + LogId: bson.ObjectIdHex(logId), + State: 1, + }) + return nil + }), nil).Start() return } p := PlayerMgrSington.GetPlayerBySnId(p.SnId)