道具兑换撤单
This commit is contained in:
parent
5e8c7f2ca0
commit
f637724a61
|
|
@ -102,6 +102,15 @@ func (svc *ItemLogSvc) GetItemCount(req *model.ItemCountParam, count *int64) err
|
||||||
return nil
|
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() {
|
func init() {
|
||||||
rpc.Register(new(ItemLogSvc))
|
rpc.Register(new(ItemLogSvc))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,3 +87,28 @@ func GetItemCount(param *ItemCountParam) (int64, error) {
|
||||||
|
|
||||||
return ret, err
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -306,13 +306,25 @@ func CSUpBagInfo(s *netlib.Session, packetid int, data interface{}, sid int64) e
|
||||||
send()
|
send()
|
||||||
return nil
|
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 {
|
if isF {
|
||||||
pack.RetCode = bag.OpResultCode_OPRC_Sucess
|
pack.RetCode = bag.OpResultCode_OPRC_Sucess
|
||||||
pack.NowItemId = item.ItemId
|
pack.NowItemId = item.ItemId
|
||||||
pack.NowItemNum = item.ItemNum
|
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()
|
send()
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,10 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
webapiproto "mongo.games.com/game/protocol/webapi"
|
|
||||||
"mongo.games.com/game/webapi"
|
|
||||||
"mongo.games.com/game/worldsrv/internal"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/globalsign/mgo/bson"
|
||||||
"mongo.games.com/goserver/core/basic"
|
"mongo.games.com/goserver/core/basic"
|
||||||
"mongo.games.com/goserver/core/i18n"
|
"mongo.games.com/goserver/core/i18n"
|
||||||
"mongo.games.com/goserver/core/logger"
|
"mongo.games.com/goserver/core/logger"
|
||||||
|
|
@ -21,7 +19,10 @@ import (
|
||||||
"mongo.games.com/game/proto"
|
"mongo.games.com/game/proto"
|
||||||
"mongo.games.com/game/protocol/bag"
|
"mongo.games.com/game/protocol/bag"
|
||||||
playerproto "mongo.games.com/game/protocol/player"
|
playerproto "mongo.games.com/game/protocol/player"
|
||||||
|
webapiproto "mongo.games.com/game/protocol/webapi"
|
||||||
"mongo.games.com/game/srvdata"
|
"mongo.games.com/game/srvdata"
|
||||||
|
"mongo.games.com/game/webapi"
|
||||||
|
"mongo.games.com/game/worldsrv/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -63,6 +64,7 @@ type BagInfo struct {
|
||||||
Platform string //平台
|
Platform string //平台
|
||||||
BagItem map[int32]*Item //背包数据 key为itemId
|
BagItem map[int32]*Item //背包数据 key为itemId
|
||||||
dirty bool
|
dirty bool
|
||||||
|
LogId string `bson:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BagMgrSingleton 背包管理器
|
// BagMgrSingleton 背包管理器
|
||||||
|
|
@ -148,6 +150,7 @@ type ItemParam struct {
|
||||||
Operator, Remark string // 操作人,备注
|
Operator, Remark string // 操作人,备注
|
||||||
gameId, gameFreeId int64 // 游戏id,场次id
|
gameId, gameFreeId int64 // 游戏id,场次id
|
||||||
noLog bool // 是否不记录日志
|
noLog bool // 是否不记录日志
|
||||||
|
LogId string
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddItemParam struct {
|
type AddItemParam struct {
|
||||||
|
|
@ -223,6 +226,7 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int
|
||||||
var permitScore, long int64
|
var permitScore, long int64
|
||||||
var changeItems []int32
|
var changeItems []int32
|
||||||
var newBagInfo *BagInfo
|
var newBagInfo *BagInfo
|
||||||
|
var logId string
|
||||||
if _, exist := this.PlayerBag[p.SnId]; !exist {
|
if _, exist := this.PlayerBag[p.SnId]; !exist {
|
||||||
newBagInfo = &BagInfo{
|
newBagInfo = &BagInfo{
|
||||||
SnId: p.SnId,
|
SnId: p.SnId,
|
||||||
|
|
@ -312,6 +316,7 @@ func (this *BagMgr) AddItems(p *Player, addItems []*Item, add int64, gainWay int
|
||||||
})
|
})
|
||||||
if log != nil {
|
if log != nil {
|
||||||
LogChannelSingleton.WriteLog(log)
|
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 {
|
if len(changeItems) > 0 {
|
||||||
newBagInfo.dirty = true
|
newBagInfo.dirty = true
|
||||||
|
newBagInfo.LogId = logId
|
||||||
p.dirty = true
|
p.dirty = true
|
||||||
this.PlayerBag[p.SnId] = newBagInfo
|
this.PlayerBag[p.SnId] = newBagInfo
|
||||||
this.SyncBagData(p.SnId, changeItems...)
|
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 err error
|
||||||
var newMsg *model.Message
|
var newMsg *model.Message
|
||||||
|
|
@ -661,10 +667,30 @@ func (this *BagMgr) ItemExchangeCard(p *Player, itemId int32, money, cardType in
|
||||||
ItemNum: 1, // 数量
|
ItemNum: 1, // 数量
|
||||||
ObtainTime: time.Now().Unix(),
|
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)
|
logger.Logger.Errorf("获取兑换码失败 snid:%v itemID:%v res:%v err:%v", p.SnId, itemId, res, err)
|
||||||
pack.RetCode = bag.OpResultCode_OPRC_Error
|
pack.RetCode = bag.OpResultCode_OPRC_Error
|
||||||
p.SendToClient(int(bag.SPacketID_PACKET_SC_ITEM_EXCHANGE_RES), pack)
|
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
|
return
|
||||||
}
|
}
|
||||||
p := PlayerMgrSington.GetPlayerBySnId(p.SnId)
|
p := PlayerMgrSington.GetPlayerBySnId(p.SnId)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue