订单回调优化

This commit is contained in:
sk 2024-09-25 11:30:27 +08:00
parent 532ff64d3b
commit d269955408
2 changed files with 179 additions and 218 deletions

View File

@ -330,7 +330,7 @@ func (this *Player) OnLogined() {
this.SendJackPotInit() this.SendJackPotInit()
this.GetPayGoodsInfo() this.GetShopInfo()
PlayerOnlineSington.Check = true PlayerOnlineSington.Check = true
@ -419,7 +419,7 @@ func (this *Player) OnRehold() {
this.SendJackPotInit() this.SendJackPotInit()
PlayerOnlineSington.Check = true PlayerOnlineSington.Check = true
this.GetPayGoodsInfo() this.GetShopInfo()
this.CheckShowRed() this.CheckShowRed()
@ -3720,39 +3720,34 @@ func (this *Player) GetMatchFreeTimes() int32 {
return 0 return 0
} }
// 玩家登录 检查充值状态 // DoShopInfo 订单完成处理逻辑
func (this *Player) GetPayGoodsInfo() { // isLogin 是否登录
if this.IsRob { func (this *Player) DoShopInfo(info *model.DbShop, isLogin bool) {
if info == nil {
return return
} }
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
info := model.GetDbShopLogsByState(this.Platform, this.SnId) op := "Callback"
if info != nil { if isLogin {
for _, shop := range info { op = "CallbackLogin"
err := model.UpdateDbShopState(shop.Platform, shop.LogId.Hex(), 1)
if err != nil {
logger.Logger.Error("GetPayGoodsInfo.UpdateDbShopState err:", err)
return nil
} }
}
}
return info
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
if data != nil {
infos := data.([]*model.DbShop)
for _, info := range infos {
switch info.PageId { switch info.PageId {
case ShopPageBackend: case ShopPageBackend:
logger.Logger.Tracef("GetPayGoodsInfo ShopPageBackend %+v", *info) logger.Logger.Tracef("GetPayGoodsInfo ShopPageBackend %+v", *info)
default: default:
var itemInfo []*playerproto.PayItem
var items []*model.Item
if len(info.Amount) > 0 { if len(info.Amount) > 0 {
this.AddCoin(int64(info.Amount[0]), 0, info.GainWay, "Callback_login", info.Remark) this.AddCoin(int64(info.Amount[0]), 0, info.GainWay, op, info.Remark)
this.AddDiamond(int64(info.Amount[1]), 0, info.GainWay, "Callback_login", info.Remark) this.AddDiamond(int64(info.Amount[1]), 0, info.GainWay, op, info.Remark)
} }
this.AddMoneyPayTotal(int64(info.ConsumeNum)) this.AddMoneyPayTotal(int64(info.ConsumeNum))
this.MoneyTotal += int64(info.ConsumeTypeNum) this.MoneyTotal += int64(info.ConsumeTypeNum)
info.Amount[2] = int32(this.GetVIPExpByPay(int64(info.ConsumeNum)))
this.dirty = true
this.SendDiffData()
var itemInfo []*playerproto.PayItem
var items []*model.Item
if info.ItemInfo != nil { if info.ItemInfo != nil {
for _, v := range info.ItemInfo { for _, v := range info.ItemInfo {
items = append(items, &model.Item{ItemId: v.ItemId, ItemNum: v.ItemNum}) items = append(items, &model.Item{ItemId: v.ItemId, ItemNum: v.ItemNum})
@ -3762,10 +3757,23 @@ func (this *Player) GetPayGoodsInfo() {
}) })
} }
} }
if len(items) > 0 {
BagMgrSingleton.AddItems(&model.AddItemParam{
Platform: this.Platform,
SnId: this.SnId,
Change: items,
GainWay: info.GainWay,
Operator: info.Operator,
Remark: info.Remark,
})
}
//钻石存储罐 //钻石存储罐
if info.PageId == ShopPageDiamondBank { if info.PageId == ShopPageDiamondBank {
WelfareMgrSington.DiamondBankTakeCoin(this) WelfareMgrSington.DiamondBankTakeCoin(this)
} }
// 通行证
if info.PageId == ShopPagePermit { if info.PageId == ShopPagePermit {
this.Permit = info.CreateTs.Local() this.Permit = info.CreateTs.Local()
LogChannelSingleton.WriteLog(&model.BackendPermitJoin{ LogChannelSingleton.WriteLog(&model.BackendPermitJoin{
@ -3779,6 +3787,7 @@ func (this *Player) GetPayGoodsInfo() {
Num: 1, Num: 1,
}) })
} }
switch info.Remark { switch info.Remark {
case "BlindBox": case "BlindBox":
if len(info.OtherParams) > 0 { if len(info.OtherParams) > 0 {
@ -3796,30 +3805,16 @@ func (this *Player) GetPayGoodsInfo() {
} }
case "ContinuousPay": case "ContinuousPay":
if len(info.OtherParams) > 0 { if len(info.OtherParams) > 0 {
this.WelfData.ContinuousPayDay = info.OtherParams[0] this.WelfData.ContinuousPayDay = info.OtherParams[0]
this.WelfData.ContinuousPayTickets = info.Ts this.WelfData.ContinuousPayTickets = info.Ts
} else { } else {
logger.Logger.Errorf("GetPayGoodsInfo ContinuousPay OtherParams is nil") logger.Logger.Errorf("GetPayGoodsInfo ContinuousPay OtherParams is nil")
} }
} }
this.UpdatePlayerVipBag(info.ShopId) this.UpdatePlayerVipBag(info.ShopId)
this.UpdateShopID(info.ShopId) this.UpdateShopID(info.ShopId)
this.dirty = true
this.SendDiffData()
info.Amount[2] = int32(this.GetVIPExpByPay(int64(info.ConsumeNum)))
BagMgrSingleton.AddItems(&model.AddItemParam{
Platform: this.Platform,
SnId: this.SnId,
Change: items,
GainWay: info.GainWay,
Operator: info.Operator,
Remark: info.Remark,
})
PayGoodsInfo := &playerproto.SCPayGoodsInfo{ PayGoodsInfo := &playerproto.SCPayGoodsInfo{
Gold: info.Amount, Gold: info.Amount,
Item: itemInfo, Item: itemInfo,
@ -3827,19 +3822,43 @@ func (this *Player) GetPayGoodsInfo() {
Money: int64(info.ConsumeTypeNum), Money: int64(info.ConsumeTypeNum),
Name: info.Remark, Name: info.Remark,
} }
proto.SetDefaults(PayGoodsInfo)
this.SendToClient(int(playerproto.PlayerPacketID_PACKET_SC_PAYGOODSINFO), PayGoodsInfo) this.SendToClient(int(playerproto.PlayerPacketID_PACKET_SC_PAYGOODSINFO), PayGoodsInfo)
} }
// 充值任务
if info.ConsumeNum > 0 { if info.ConsumeNum > 0 {
TaskSubjectSingleton.Touch(common.TaskTypePay, &TaskData{ TaskSubjectSingleton.Touch(common.TaskTypePay, &TaskData{
SnId: this.SnId, SnId: this.SnId,
Num: int64(info.ConsumeNum), Num: int64(info.ConsumeNum),
}) })
} }
} }
}
})).StartByFixExecutor("GetPayGoodsLogs") func (this *Player) GetShopInfo() {
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
info := model.GetDbShopLogsByState(this.Platform, this.SnId)
if info != nil {
for _, shop := range info {
err := model.UpdateDbShopState(shop.Platform, shop.LogId.Hex(), 1)
if err != nil {
logger.Logger.Error("Player CallbackPayment UpdateDbShopState err:", err)
return nil
}
}
}
return info
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
if i == nil {
return
}
shops, ok := i.([]*model.DbShop)
if !ok {
return
}
for _, info := range shops {
this.DoShopInfo(info, true)
}
})).StartByExecutor(fmt.Sprintf("Player%v", this.SnId))
} }
func (this *Player) SendJackPotInit() { func (this *Player) SendJackPotInit() {

View File

@ -3445,8 +3445,18 @@ func init() {
pack.Msg = "OrderId == nil || msg.Platform == nil" pack.Msg = "OrderId == nil || msg.Platform == nil"
return common.ResponseTag_ParamError, pack return common.ResponseTag_ParamError, pack
} }
retFail := func(errorMsg string) {
pack.Tag = webapiproto.TagCode_FAILED
pack.Msg = errorMsg
tNode.TransRep.RetFiels = pack
tNode.Resume()
}
var info *model.DbShop
var state int32
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
info := model.GetDbShopLog(msg.Platform, msg.OrderId) info = model.GetDbShopLog(msg.Platform, msg.OrderId)
if info == nil { if info == nil {
return errors.New("info is nil") return errors.New("info is nil")
} }
@ -3454,123 +3464,55 @@ func init() {
if info.State != 0 { if info.State != 0 {
return errors.New("the order state not 0 " + info.LogId.Hex()) return errors.New("the order state not 0 " + info.LogId.Hex())
} }
var state = msg.State return nil
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
if i != nil || info == nil {
logger.Logger.Errorf("CallbackPayment error %v shoplog:%#v", i, info)
retFail("购买记录查询失败")
return
}
state = msg.GetState()
player := PlayerMgrSington.GetPlayerBySnId(info.SnId) player := PlayerMgrSington.GetPlayerBySnId(info.SnId)
if player != nil && player.IsOnLine() { if player == nil {
if len(info.Amount) > 0 { if info.State == 1 {
player.AddCoin(int64(info.Amount[0]), 0, info.GainWay, "Callback", info.Remark)
player.AddDiamond(int64(info.Amount[1]), 0, info.GainWay, "Callback", info.Remark)
}
player.AddMoneyPayTotal(int64(info.ConsumeNum))
player.MoneyTotal += int64(info.ConsumeTypeNum)
player.dirty = true
player.SendDiffData()
info.Amount[2] = int32(player.GetVIPExpByPay(int64(info.ConsumeNum)))
var itemInfo []*playerproto.PayItem
var items []*model.Item
if info.ItemInfo != nil {
for _, v := range info.ItemInfo {
items = append(items, &model.Item{ItemId: v.ItemId, ItemNum: v.ItemNum})
itemInfo = append(itemInfo, &playerproto.PayItem{
ItemId: v.ItemId,
ItemNum: v.ItemNum,
})
}
}
BagMgrSingleton.AddItems(&model.AddItemParam{
Platform: player.Platform,
SnId: player.SnId,
Change: items,
GainWay: info.GainWay,
Operator: "Callback",
Remark: info.Remark,
})
//钻石存储罐
if info.PageId == ShopPageDiamondBank {
WelfareMgrSington.DiamondBankTakeCoin(player)
}
if info.PageId == ShopPagePermit {
player.Permit = info.CreateTs.Local()
LogChannelSingleton.WriteLog(&model.BackendPermitJoin{
Platform: player.Platform,
StartTs: PlatformMgrSingleton.GetConfig(player.Platform).PermitStartTs,
SnId: player.SnId,
Ts: time.Now().Unix(),
})
TaskSubjectSingleton.Touch(common.TaskTypeBuyPermit, &TaskData{
SnId: player.SnId,
Num: 1,
})
}
switch info.Remark {
case "BlindBox":
if len(info.OtherParams) > 0 {
player.WelfData.BlindBoxId = info.OtherParams[0]
} else {
logger.Logger.Errorf("CallbackPayment BlindBox OtherParams is nil")
}
case "FirstRecharge":
if len(info.OtherParams) > 0 {
player.WelfData.FirstPayDay = info.OtherParams[0]
player.WelfData.FirstPayTickets = info.Ts
} else {
logger.Logger.Errorf("CallbackPayment FirstRecharge OtherParams is nil")
}
case "ContinuousPay":
if len(info.OtherParams) > 0 {
player.WelfData.ContinuousPayDay = info.OtherParams[0]
player.WelfData.ContinuousPayTickets = info.Ts
} else {
logger.Logger.Errorf("CallbackPayment ContinuousPay OtherParams is nil")
}
}
player.UpdatePlayerVipBag(info.ShopId)
player.UpdateShopID(info.ShopId)
PayGoodsInfo := &playerproto.SCPayGoodsInfo{
Gold: info.Amount,
Item: itemInfo,
}
proto.SetDefaults(PayGoodsInfo)
player.SendToClient(int(playerproto.PlayerPacketID_PACKET_SC_PAYGOODSINFO), PayGoodsInfo)
TaskSubjectSingleton.Touch(common.TaskTypePay, &TaskData{
SnId: player.SnId,
Num: int64(info.ConsumeNum),
})
InviteTask(msg.Platform, player.PSnId, player.SnId, common.InviteScoreTypePay, int64(info.ConsumeNum))
} else {
if state == 1 {
state = 3 state = 3
} }
psnid, err := model.GetPlayerInviteSnid(msg.Platform, info.SnId)
if err != nil {
logger.Logger.Error("UpdateDbShopState.err:", err)
return err
}
InviteTask(msg.Platform, psnid, info.SnId, common.InviteScoreTypePay, int64(info.ConsumeNum))
} }
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
err := model.UpdateDbShopState(msg.Platform, msg.OrderId, state) err := model.UpdateDbShopState(msg.Platform, msg.OrderId, state)
if err != nil { if err != nil {
logger.Logger.Error("UpdateDbShopState.err:", err) logger.Logger.Error("CallbackPayment UpdateDbShopState error:", err)
return err return err
} }
return nil return nil
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) { }), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
if data != nil && data.(error) != nil { if i != nil {
info := data.(error) retFail("购买记录状态修改失败")
pack.Tag = webapiproto.TagCode_FAILED return
pack.Msg = fmt.Sprintf("%v", info) }
if player != nil {
player.DoShopInfo(info, false)
// 邀请积分
InviteTask(msg.Platform, player.PSnId, info.SnId, common.InviteScoreTypePay, int64(info.ConsumeNum))
} else { } else {
// 邀请积分
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
psnid, err := model.GetPlayerInviteSnid(msg.Platform, info.SnId)
if err != nil {
logger.Logger.Error("CallbackPayment GetPlayerInviteSnid error:", err)
return err
}
InviteTask(msg.Platform, psnid, info.SnId, common.InviteScoreTypePay, int64(info.ConsumeNum))
return nil
}), nil, "InvitePayTask").Start()
}
pack.Tag = webapiproto.TagCode_SUCCESS pack.Tag = webapiproto.TagCode_SUCCESS
pack.Msg = "success" pack.Msg = "success"
}
tNode.TransRep.RetFiels = pack tNode.TransRep.RetFiels = pack
tNode.Resume() tNode.Resume()
}), "CallbackPayment").Start() })).StartByExecutor(fmt.Sprintf("Player%v", info.SnId))
})).StartByFixExecutor("CallbackPayment")
return common.ResponseTag_TransactYield, pack return common.ResponseTag_TransactYield, pack
})) }))