v卡兑换消耗统计

This commit is contained in:
sk 2024-07-10 16:12:24 +08:00
parent b5aba457a0
commit c21dd8e565
2 changed files with 11 additions and 33 deletions

View File

@ -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
}

View File

@ -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