From c21dd8e5657a8d77c36c13a829702fc761e08c85 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Wed, 10 Jul 2024 16:12:24 +0800 Subject: [PATCH] =?UTF-8?q?v=E5=8D=A1=E5=85=91=E6=8D=A2=E6=B6=88=E8=80=97?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbproxy/svc/l_itemlog.go | 39 +++++++++------------------------------ worldsrv/bagmgr.go | 5 ++--- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/dbproxy/svc/l_itemlog.go b/dbproxy/svc/l_itemlog.go index 2ddbbaa..8cb0dcd 100644 --- a/dbproxy/svc/l_itemlog.go +++ b/dbproxy/svc/l_itemlog.go @@ -49,14 +49,15 @@ func (svc *ItemLogSvc) InsertItemLog(log *model.ItemLog, ret *bool) (err error) return } +// GetItemCount 获取v卡兑换消耗数量 func GetItemCount(platform string, snid, id int32, tp int) (count int64) { c := ItemLogsCollection(platform) if c == nil { return 0 } var err error - var swapN, matchN int64 - var costN, gainN int64 + var swapN int64 + var costN int64 type m struct { Count int64 `bson:"count"` } @@ -72,22 +73,10 @@ func GetItemCount(platform string, snid, id int32, tp int) (count int64) { } swapN = tc.Count - // 比赛返回 - tc = new(m) - err = c.Pipe([]bson.M{ - {"$match": bson.M{"snid": snid, "logtype": 0, "itemid": id, "typeid": common.GainWay_MatchSignup}}, - {"$group": bson.M{"_id": nil, "count": bson.M{"$sum": "$count"}}}, - }).AllowDiskUse().One(tc) - if err != nil && !errors.Is(err, mgo.ErrNotFound) { - logger.Logger.Warn("GetItemCount matchN error:", err) - return 0 - } - matchN = tc.Count - // 消耗总数量 tc = new(m) err = c.Pipe([]bson.M{ - {"$match": bson.M{"snid": snid, "logtype": 1, "itemid": id}}, + {"$match": bson.M{"snid": snid, "logtype": 1, "itemid": id, "typeid": common.GainWay_Exchange}}, {"$group": bson.M{"_id": nil, "count": bson.M{"$sum": "$count"}}}, }).AllowDiskUse().One(tc) if err != nil && !errors.Is(err, mgo.ErrNotFound) { @@ -96,24 +85,14 @@ func GetItemCount(platform string, snid, id int32, tp int) (count int64) { } costN = tc.Count - // 获得总数量 - tc = new(m) - err = c.Pipe([]bson.M{ - {"$match": bson.M{"snid": snid, "logtype": 0, "itemid": id}}, - {"$group": bson.M{"_id": nil, "count": bson.M{"$sum": "$count"}}}, - }).AllowDiskUse().One(tc) - if err != nil && !errors.Is(err, mgo.ErrNotFound) { - logger.Logger.Warn("GetItemCount gainN error:", err) - return 0 - } - gainN = tc.Count - if tp == 0 { // 获得数量 = 获得总数量 - 兑换返还 - 比赛返回 - count = gainN - swapN - matchN } else { - // 消耗数量 = 消耗总数量 - 兑换返还 - 比赛返回 - count = costN - swapN - matchN + // 消耗数量 = 消耗总数量 - 兑换返还 + count = costN - swapN + } + if count < 0 { + count = 0 } return count } diff --git a/worldsrv/bagmgr.go b/worldsrv/bagmgr.go index 7cc753e..e9ae6db 100644 --- a/worldsrv/bagmgr.go +++ b/worldsrv/bagmgr.go @@ -322,9 +322,8 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int if v.ItemId == common.ItemIDPetSkill && v.ItemNum > 0 { PetMgrSington.CheckShowRed(p) } - if v.ItemId == common.ItemIDVCard && (v.ItemNum <= 0 || - gainWay == common.GainWay_MatchSignup || gainWay == common.GainWay_Exchange) { - // 比赛报名返还,兑换返还 + // 统计 v卡兑换消耗数量 + if v.ItemId == common.ItemIDVCard && gainWay == common.GainWay_Exchange { p.VCardCost += -v.ItemNum if p.VCardCost < 0 { p.VCardCost = 0