From 406c1a6775ef7dde34ba379843322bd2d5ca23d2 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期二, 02 十二月 2025 16:29:24 +0800
Subject: [PATCH] 320 【付费内容】商城-服务端(xssg充值回调接口;游戏服务器兑换充值商品逻辑修改;)
---
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/LogicProcess/UserCtrlDB.py | 251 ++++++++++++++++++++++++++++++++-----------------
1 files changed, 163 insertions(+), 88 deletions(-)
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/LogicProcess/UserCtrlDB.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/LogicProcess/UserCtrlDB.py
index 2605dea..4f0250d 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/LogicProcess/UserCtrlDB.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/PyMongoDB/LogicProcess/UserCtrlDB.py
@@ -19,6 +19,7 @@
from ServerClientShareDefine import *
import ConfigParser
import IpyGameDataPY
+import PlayerCoin
#import IPY_GameWorld
#from Config import (DBConfig,)
DBConfig = __import__('Config.DBConfig')
@@ -402,6 +403,16 @@
CheckGameVersion()
self.loadDBPlayerIDMap()
+ return
+
+ def onSecondProcess(self):
+ '''子类实现 - 每秒处理'''
+ if not self.Connected:
+ return
+ if self.IsMergeServer():
+ pass
+ else:
+ self.OnQueryRechargeByLoop()
return
def loadDBPlayerIDMap(self):
@@ -1226,86 +1237,147 @@
def OnFinishRecharge(self, db, pack):
# map完成兑换,假设此处没有回复,则此单变成丢单,暂由人工维护
# 若真频繁发生则改为上线恢复
- try:
- buf = pack.getBuffer()
- packLen = pack.getLength()
- recvPack = RecvPackProtocol.tagMDFinishRecharge()
- pos = 0
- recvPack.ReadData(buf, pos)
- orderID = recvPack.OrderID.strip(chr(0))
- mylog.debug('OnFinishRecharge ...%s'%orderID)
-
- col = db[UCN_PayInfo]
- result = col.find({"OrderID":orderID})
+ return
+# try:
+# buf = pack.getBuffer()
+# packLen = pack.getLength()
+# recvPack = RecvPackProtocol.tagMDFinishRecharge()
+# pos = 0
+# recvPack.ReadData(buf, pos)
+# orderID = recvPack.OrderID.strip(chr(0))
+# mylog.debug('OnFinishRecharge ...%s'%orderID)
+#
+# col = db[UCN_PayInfo]
+# result = col.find({"OrderID":orderID})
+#
+# if not result or result.count() == 0:
+# # 没有充值订单
+# return
+#
+# curTime = datetime.datetime.today()
+# curTimeStr = str(curTime)
+# curTimeStr = curTimeStr.split(".")[0]
+# col.update({"OrderID":orderID}, {"$set":{"IsProcess":1, 'EndOrderTime':curTimeStr}})
+#
+# mylog.debug('OnFinishRecharge OrderID = %s'%(orderID))
+#
+# return
+# except Exception, e:
+# msg = error.formatMsg('error', error.ERROR_NO_170, "OnFinishRecharge error %s!pack = %s"%(e, binascii.b2a_hex(buf)))
+# mylog.error(msg)
+# except:
+# msg = error.formatMsg('error', error.ERROR_NO_170, "OnFinishRecharge error!pack = %s"%(binascii.b2a_hex(buf)))
+# mylog.error(msg)
+# return
+
+ def OnQueryRechargeByLoop(self):
+ '''定时处理充值订单兑换' 每秒处理一次
+ 充值流程
+ 客户端支付商品 -> 平台回调游戏中心服务器 -> 游戏服务器插入订单tagPayInfo
+ 商品兑换旧流程:
+ curPlayer.SendDBQueryRecharge() -> gstQueryRecharge -> OnQueryRecharge -> 【GameServerRefresh.PushRecharge】 -> PlayerCoin.PlayerCoinToGold ->
+ -> curPlayer.SendDBFinishRecharge(orderID) -> gstFinishRecharge -> OnFinishRecharge
+ 发起方式:
+ 1. 游戏服务器每秒轮询未处理的订单进行兑换商品 -> MT_GetCoinReqs -> curPlayer.SendDBQueryRecharge()
+ 2. A8 06 查询充值结果 #tagCMQueryRecharge -> curPlayer.SendDBQueryRecharge()
- if not result or result.count() == 0:
- # 没有充值订单
+ 商品兑换新流程:
+ 1. 游戏服务器每秒轮询未处理的订单进行兑换商品 -> 直接调用 PlayerCoin.OnDBPushRecharge -> 直接更新订单 IsProcess
+ 2. 废弃, A8 06 查询充值结果 #tagCMQueryRecharge,只使用后端轮询即可,后续有问题再补充优化
+ '''
+ PayRechargeCount = 5 # 单次处理条数
+ if PayRechargeCount <= 0:
+ return
+ if not PyGameData.g_onlineAccIDList:
+ return
+ if PyGameData.g_ctgOrderIDList:
+ GameWorld.DebugLog("还有正在处理兑换商品的充值订单! %s" % PyGameData.g_ctgOrderIDList)
+ return
+ try:
+ col = self.db[UCN_PayInfo]
+ spec = {'AccID':{'$in':PyGameData.g_onlineAccIDList}, 'IsProcess':0}
+ fields = {"_id":0, "AccID":1, "OrderID":1, "OrderInfo":1, "OrderAmount":1}
+ result = col.find(spec, fields).limit(PayRechargeCount)
+ if not result or not result.count():
+ # 没有在线玩家未兑换的充值订单
return
curTime = datetime.datetime.today()
curTimeStr = str(curTime)
curTimeStr = curTimeStr.split(".")[0]
- col.update({"OrderID":orderID}, {"$set":{"IsProcess":1, 'EndOrderTime':curTimeStr}})
- mylog.debug('OnFinishRecharge OrderID = %s'%(orderID))
-
- return
- except Exception, e:
- msg = error.formatMsg('error', error.ERROR_NO_170, "OnFinishRecharge error %s!pack = %s"%(e, binascii.b2a_hex(buf)))
- mylog.error(msg)
+ for billInfo in result:
+ accID = fix_outgoingText(billInfo['AccID'])
+ orderID = fix_outgoingText(billInfo['OrderID'])
+ orderInfo = fix_outgoingText(billInfo['OrderInfo'])
+ orderAmount = billInfo['OrderAmount']
+ curPlayer = GameWorld.GetPlayerManager().FindPlayerByAccID(accID)
+ if not curPlayer or curPlayer.IsEmpty():
+ GameWorld.Log("充值兑换商品时玩家不在线! accID=%s,orderAmount=%s,orderInfo=%s,orderID=%s" % (accID, orderAmount, orderInfo, orderID))
+ continue
+ if orderID in PyGameData.g_ctgOrderIDList:
+ continue
+ PyGameData.g_ctgOrderIDList.append(orderID)
+ # 直接设置为已处理,订单如果实际异常未到账的情况由人工补偿处理
+ col.update({"OrderID":orderID}, {"$set":{"IsProcess":1, 'EndOrderTime':curTimeStr}})
+ PlayerCoin.OnDBPushRecharge(curPlayer, orderID, orderInfo, orderAmount)
+
except:
- msg = error.formatMsg('error', error.ERROR_NO_170, "OnFinishRecharge error!pack = %s"%(binascii.b2a_hex(buf)))
+ msg = error.formatMsg('error', error.ERROR_NO_170, "traceback = %s" % (traceback.format_exc()))
mylog.error(msg)
+
+ PyGameData.g_ctgOrderIDList = []
return
-
def OnQueryRecharge(self, db, pack):
# map查询新的充值订单, 查询充值表
- try:
- buf = pack.getBuffer()
- packLen = pack.getLength()
- recvPack = RecvPackProtocol.tagMDQueryRecharge()
- pos = 0
- recvPack.ReadData(buf, pos)
- account = recvPack.Account.strip(chr(0))
- mylog.debug('OnQueryRecharge ...%s'%account)
-
- col = db[UCN_PayInfo]
- result = col.find({'AccID':account, 'IsProcess':0, 'EndOrderTime':0})
-
- if not result or result.count() == 0:
- # 没有充值订单
- return
-
- # 一单一单发
- # 先设置IsProcess为1兑换中,等回复结果在真正完成订单
- billInfo = result[0]
-
- sendPack = SendPackProtocol.tagDMRechargePush()
- sendPack.Type = CommonDefine.dgDBToMapServer
- sendPack.SubType = CommonDefine.gmReChargePush
- sendPack.OrderID = fix_outgoingText(billInfo['OrderID'])
- sendPack.OrderIDLen = len(sendPack.OrderID)
- sendPack.OrderInfo = fix_outgoingText(billInfo['OrderInfo'])
- sendPack.OrderInfoLen = len(sendPack.OrderInfo)
- sendPack.Money = int(billInfo['OrderAmount'])
- sendPack.Extras = fix_outgoingText(billInfo['Extras'])
- sendPack.ExtrasLen = len(sendPack.Extras)
-
- col.update({"OrderID":sendPack.OrderID}, {"$set":{"IsProcess":1}})
-
- self.sendString(pack, sendPack.GetBuffer())
- mylog.debug('OnQueryRecharge OrderID = %s'%(sendPack.OrderID))
- #mylog.debug('send %s'%sendPack.OutputString())
- return
- except Exception, e:
- msg = error.formatMsg('error', error.ERROR_NO_170, "OnQueryRecharge error %s!pack = %s"%(e, binascii.b2a_hex(buf)))
- mylog.error(msg)
- except:
- msg = error.formatMsg('error', error.ERROR_NO_170, "OnQueryRecharge error!pack = %s"%(binascii.b2a_hex(buf)))
- mylog.error(msg)
-
+ # 暂废弃
return
+# try:
+# buf = pack.getBuffer()
+# packLen = pack.getLength()
+# recvPack = RecvPackProtocol.tagMDQueryRecharge()
+# pos = 0
+# recvPack.ReadData(buf, pos)
+# account = recvPack.Account.strip(chr(0))
+# mylog.debug('OnQueryRecharge ...%s'%account)
+#
+# col = db[UCN_PayInfo]
+# result = col.find({'AccID':account, 'IsProcess':0, 'EndOrderTime':0})
+#
+# if not result or result.count() == 0:
+# # 没有充值订单
+# return
+#
+# # 一单一单发
+# # 先设置IsProcess为1兑换中,等回复结果在真正完成订单
+# billInfo = result[0]
+#
+# sendPack = SendPackProtocol.tagDMRechargePush()
+# sendPack.Type = CommonDefine.dgDBToMapServer
+# sendPack.SubType = CommonDefine.gmReChargePush
+# sendPack.OrderID = fix_outgoingText(billInfo['OrderID'])
+# sendPack.OrderIDLen = len(sendPack.OrderID)
+# sendPack.OrderInfo = fix_outgoingText(billInfo['OrderInfo'])
+# sendPack.OrderInfoLen = len(sendPack.OrderInfo)
+# sendPack.Money = int(billInfo['OrderAmount'])
+# sendPack.Extras = fix_outgoingText(billInfo['Extras'])
+# sendPack.ExtrasLen = len(sendPack.Extras)
+#
+# col.update({"OrderID":sendPack.OrderID}, {"$set":{"IsProcess":1}})
+#
+# self.sendString(pack, sendPack.GetBuffer())
+# mylog.debug('OnQueryRecharge OrderID = %s'%(sendPack.OrderID))
+# #mylog.debug('send %s'%sendPack.OutputString())
+# return
+# except Exception, e:
+# msg = error.formatMsg('error', error.ERROR_NO_170, "OnQueryRecharge error %s!pack = %s"%(e, binascii.b2a_hex(buf)))
+# mylog.error(msg)
+# except:
+# msg = error.formatMsg('error', error.ERROR_NO_170, "OnQueryRecharge error!pack = %s"%(binascii.b2a_hex(buf)))
+# mylog.error(msg)
+#
+# return
def OnQueryNewGuyCardState(self, db, pack):
try:
@@ -1501,8 +1573,11 @@
DataDumper.DumpData(GlobalFunctions.getAppPath(), 'UserLogs\\SaveFailDump', '%s.mdat'%playerID, saveData)
+ if accID in PyGameData.g_onlineAccIDList:
+ PyGameData.g_onlineAccIDList.remove(accID)
+
# 玩家下线恢复充值兑换中的订单,IsProcee为1,但endtime为空的情况
- self.RevoverBillProcess(db, accID)
+ #self.RevoverBillProcess(db, accID)
mylog.info("onSaveMapServerPlayerData result = %s, playerID = %s"%(result, playerID))
# 下线成功入库后同步移动玩家备档备份文件夹
@@ -1610,26 +1685,24 @@
return
# 玩家下线恢复充值兑换中的订单,IsProcee为1,但endtime为空的情况
- def RevoverBillProcess(self, db, accID):
- try:
- if not accID:
- return
- account = accID.strip(chr(0))
- col = db[UCN_PayInfo]
- result = col.find({'AccID':account, 'IsProcess':1, 'EndOrderTime':0})
-
- if not result or result.count() == 0:
- # 没有充值订单
- return
-
- # 一单一单 恢复
- billInfo = result[0]
- orderID = billInfo['OrderID']
- col.update({"OrderID":orderID}, {"$set":{"IsProcess":0}})
-
- mylog.debug('RevoverBillProcess success...%s'%orderID)
- except:
- mylog.error("RevoverBillProcess error %s"%traceback.format_exc())
+# def RevoverBillProcess(self, db, accID):
+# try:
+# if not accID:
+# return
+# account = accID.strip(chr(0))
+# col = db[UCN_PayInfo]
+# result = col.find({'AccID':account, 'IsProcess':1, 'EndOrderTime':0})
+#
+# if not result or result.count() == 0:
+# # 没有充值订单
+# return
+#
+# for billInfo in result:
+# orderID = billInfo['OrderID']
+# col.update({"OrderID":orderID}, {"$set":{"IsProcess":0}})
+# mylog.debug('RevoverBillProcess success...%s'%orderID)
+# except:
+# mylog.error("RevoverBillProcess error %s"%traceback.format_exc())
def SavePlayerMapServerData(self, db, saveData):
playerRec = DataServerPlayerData.tagDBPlayer()
@@ -3291,7 +3364,9 @@
sendPack.MapID = GameWorld.GetGameWorld().GetMapID()
mylog.info('gstPlayerDetail Send OnCreate accid = %s'%(accountRec.ACCID))
NetPackCommon.SendPyPackToMapServerSelf(sendPack.GetBuffer(), sendPack.GetLength())
-
+
+ if authAccID not in PyGameData.g_onlineAccIDList:
+ PyGameData.g_onlineAccIDList.append(authAccID)
return True
def sendOKString(self, type, fromPacket, buf):
--
Gitblit v1.8.0