From 8532cf79b7fec586561bea3cc05d58fd7d5c9b52 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期四, 28 十二月 2023 16:24:08 +0800
Subject: [PATCH] 10077 游戏代币方案

---
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCoin.py |   90 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 85 insertions(+), 5 deletions(-)

diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCoin.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCoin.py
index 6bdfd40..5905aa3 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCoin.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerCoin.py
@@ -70,6 +70,16 @@
 import time
 import copy
 
+# 充值订单类型
+PayOrderTypeList = (
+PayOrderType_RMB, # 人民币 1
+PayOrderType_USD, # 美元 2
+PayOrderType_VND, # 越南盾 3
+PayOrderType_Soha, # soha平台币 4
+PayOrderType_BuyOrder, # 使用订单价值对应货币支付 5
+PayOrderType_PayCoin, # 代币 6
+) = range(1, 1 + 6)
+
 # 充值类型定义
 PayType_Gold = 2  # 常规仙玉充值
 PayType_GoldPlus = 3  # 至尊仙玉充值
@@ -238,6 +248,64 @@
     Sync_CoinToGoldCountInfo(curPlayer, [recordID] if recordID else [])
     return
 
+#// A1 25 代币购买充值商品编号商品 #tagCMCoinBuyOrderInfo
+#
+#struct    tagCMCoinBuyOrderInfo
+#{
+#    tagHead        Head;
+#    BYTE        AppIDLen;
+#    char        AppID[AppIDLen];
+#    BYTE        OrderInfoLen;
+#    char        OrderInfo[OrderInfoLen];    //商品编号
+#};
+def OnCoinBuyOrderInfo(index, clientData, tick):
+    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
+    appID = clientData.AppID
+    orderInfo = clientData.OrderInfo
+    
+    ipyData = IpyGameDataPY.GetIpyGameData("OrderInfo", orderInfo, appID)
+    if not ipyData:
+        return
+    orderCoin = CommFunc.RMBToCoin(ipyData.GetPayRMBNum())    
+    cPlayerCoin = CPY_PlayerCoinToGold()
+    cPlayerCoin.useCoin = orderCoin
+    cPlayerCoin.orderInfo = orderInfo
+    cPlayerCoin.appID = appID
+    cPlayerCoin.orderID = ""
+    PlayerCoinToGold(curPlayer, cPlayerCoin, "CoinBuyOrderInfo", PayOrderType_PayCoin)
+    return
+
+def ExchangePayCoin(curPlayer, errorInfo, addDRDict):
+    ''' 充值兑换成代币
+                一般可用于一些充值订单兑换游戏功能时,游戏功能有限制如限购,
+                该充值视为成功,并转化为对应代币,可以理解为类似充值点券,代币可用于下次充值时支付;
+    '''
+    orderInfo = addDRDict.get("orderInfo", "")
+    orderCoin = addDRDict.get("orderCoin", 0)
+    payOrderType = addDRDict.get("payOrderType", PayOrderType_RMB)
+    if not orderCoin or not orderInfo:
+        DataRecordPack.DR_CTGError(curPlayer, errorInfo, addDRDict)
+        return
+    eventName = addDRDict.get("eventName", "ExchangePayCoin")
+    playerID = curPlayer.GetPlayerID()
+    befPayCoin = PlayerControl.GetPayCoin(curPlayer)
+    drDict = {ChConfig.Def_Give_Reason_SonKey:orderInfo, "payOrderType":payOrderType}
+    PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_PayCoin, orderCoin, eventName, drDict)
+    aftPayCoin = PlayerControl.GetPayCoin(curPlayer)
+    GameWorld.Log("充值转化为代币: orderInfo=%s,orderCoin=%s,payOrderType=%s,eventName=%s,befPayCoin=%s,aftPayCoin=%s,errorInfo=%s" 
+                  % (orderInfo, orderCoin, payOrderType, eventName, befPayCoin, aftPayCoin, errorInfo), playerID)
+    
+    addItemList = []
+    paramList = [orderInfo, CommFunc.CoinToYuan(orderCoin)]
+    PlayerControl.SendMailByKey("ExchangeToPayCoin", [playerID], addItemList, paramList)
+    
+    if payOrderType != PayOrderType_PayCoin:
+        serverDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) + 1
+        addDRDict.update({"coinType":ChConfig.CoinType_ExchangePayCoin, "PayCoin":[befPayCoin, aftPayCoin], 
+                          "VIPLv":curPlayer.GetVIPLv(), "ServerDay":serverDay, "eventName":eventName})
+        DataRecordPack.DR_CTGOK(curPlayer, addDRDict)
+    return
+
 ## 创角赠送
 #  @param curPlayer 玩家实例
 #  @return None
@@ -309,7 +377,7 @@
 # @param useCoin 使用的点卷
 # @param eventName 兑换事件名
 # @return None
-def PlayerCoinToGold(curPlayer, chargeInfo, eventName):
+def PlayerCoinToGold(curPlayer, chargeInfo, eventName, payOrderType=PayOrderType_RMB):
     ## 按商品编号充值
     orderCoin = chargeInfo.GetCoin() # 金额 已乘以100  人民币单位为分
     #notePrizeCoin = chargeInfo.GetPrizeCoin()
@@ -338,6 +406,15 @@
     if orderCoin != CommFunc.RMBToCoin(payRMBNum):
         DataRecordPack.DR_CTGError(curPlayer, "The orderCoin is not equal to the ipyData's RMB(%s)!" % payRMBNum, addDRDict)
         return
+    
+    if payOrderType == PayOrderType_PayCoin:
+        #直接扣,类似充值扣钱,这里是发放物品,可能会有发放失败的当做 CTGError 处理
+        if not PlayerControl.PayMoney(curPlayer, ShareDefine.TYPE_Price_PayCoin, orderCoin, eventName, {ChConfig.Def_Cost_Reason_SonKey:orderInfo}):
+            GameWorld.ErrLog("代币不足! appID=%s,orderInfo=%s,orderCoin=%s,curPayCoin=%s" 
+                             % (appID, orderInfo, orderCoin, PlayerControl.GetPayCoin(curPlayer)), curPlayer.GetPlayerID())
+            return
+        
+    addDRDict["payOrderType"] = payOrderType
     
     addGold, prizeGold, giveItemList, ctgIpyData = 0, 0, [], None
     
@@ -398,7 +475,7 @@
     if totalBuyCountLimit:
         addDRDict.update({"totalBuyCountLimit":totalBuyCountLimit, "totalBuyCount":totalBuyCount})
         if totalBuyCount >= totalBuyCountLimit:
-            DataRecordPack.DR_CTGError(curPlayer, "Pay count limit total!totalBuyCount=%s" % totalBuyCount, addDRDict)
+            ExchangePayCoin(curPlayer, "Pay count limit total!totalBuyCount=%s" % totalBuyCount, addDRDict)
             return        
     
     dailyBuyCountLimit = ipyData.GetDailyBuyCount()
@@ -406,7 +483,7 @@
     if dailyBuyCountLimit:
         addDRDict.update({"dailyBuyCountLimit":dailyBuyCountLimit, "todayBuyCount":todayBuyCount})
         if todayBuyCount >= dailyBuyCountLimit:
-            DataRecordPack.DR_CTGError(curPlayer, "Pay count limit today!todayBuyCount=%s" % todayBuyCount, addDRDict)
+            ExchangePayCoin(curPlayer, "Pay count limit today!todayBuyCount=%s" % todayBuyCount, addDRDict)
             return
         
     weekBuyCountLimit = ipyData.GetWeekBuyCount()
@@ -414,7 +491,7 @@
     if weekBuyCountLimit:
         addDRDict.update({"weekBuyCountLimit":weekBuyCountLimit, "weekBuyCount":weekBuyCount})
         if weekBuyCount >= weekBuyCountLimit:
-            DataRecordPack.DR_CTGError(curPlayer, "Pay count limit week!weekBuyCount=%s" % weekBuyCount, addDRDict)
+            ExchangePayCoin(curPlayer, "Pay count limit week!weekBuyCount=%s" % weekBuyCount, addDRDict)
             return
         
     monthBuyCountLimit = ipyData.GetMonthBuyCount()
@@ -422,7 +499,7 @@
     if monthBuyCountLimit:
         addDRDict.update({"monthBuyCountLimit":monthBuyCountLimit, "monthBuyCount":monthBuyCount})
         if monthBuyCount >= monthBuyCountLimit:
-            DataRecordPack.DR_CTGError(curPlayer, "Pay count limit month!monthBuyCount=%s" % monthBuyCount, addDRDict)
+            ExchangePayCoin(curPlayer, "Pay count limit month!monthBuyCount=%s" % monthBuyCount, addDRDict)
             return
         
     totalBuyCountUpd = min(totalBuyCount + 1, ChConfig.Def_UpperLimit_DWord)
@@ -490,6 +567,9 @@
         return
     
     isRealMoney = True if addDRDict.get("orderID") else False # 是否真实货币充值,仅真实货币充值订单有orderID,后台充值的不算真实货币充值
+    payOrderType = addDRDict.get("payOrderType", PayOrderType_RMB)
+    if payOrderType == PayOrderType_PayCoin:
+        isRealMoney = True # 代币充值在游戏内容上算真实充值
     ctgRealToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGRealToday) # 当日真实货币充值Coin数 ,不含后台充值- 今日
     ctgRealTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGRealTotal) # 累计真实货币充值Coin数 ,不包后台充值 - 总计
     ctgRealFirstTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CTGRealFirstTime) # 首次真实货币充值时间戳

--
Gitblit v1.8.0