| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.PlayerActRechargeRebateGold  | 
| #  | 
| # @todo:ÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯  | 
| # @author hxp  | 
| # @date 2020-10-15  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯£¨»î¶¯½áÊøÓʼþ·¢·Å£¬Ö»Ëã×î¸ßÒ»µµ£©  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2020-10-15 12:00"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import ChConfig  | 
| import ShareDefine  | 
| import PlayerControl  | 
| import PyGameData  | 
| import GameWorld  | 
| import NetPackCommon  | 
| import ChPyNetSendPack  | 
| import IpyGameDataPY  | 
|   | 
| def OnPlayerLogin(curPlayer):  | 
|     isReset = __CheckPlayerRechargeRebateGoldAction(curPlayer)  | 
|     if not isReset:  | 
|         actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RechargeRebateGold, {})  | 
|         # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢  | 
|         if actInfo.get(ShareDefine.ActKey_State):  | 
|             Sync_RechargeRebateGoldActionInfo(curPlayer)  | 
|             Sync_RechargeRebateGoldPlayerInfo(curPlayer)  | 
|     return  | 
|   | 
| def RefreshRechargeRebateGoldActionInfo():  | 
|     ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for index in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(index)  | 
|         if curPlayer.GetID() == 0:  | 
|             continue  | 
|         __CheckPlayerRechargeRebateGoldAction(curPlayer)  | 
|     return  | 
|   | 
| def __CheckPlayerRechargeRebateGoldAction(curPlayer):  | 
|     ## ¼ì²éÍæ¼ÒÀۼƳäÖµ»î¶¯Êý¾ÝÐÅÏ¢  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|       | 
|     actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RechargeRebateGold, {})  | 
|     actID = actInfo.get(ShareDefine.ActKey_ID, 0)  | 
|     state = actInfo.get(ShareDefine.ActKey_State, 0)  | 
|       | 
|     playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RechargeRebateGoldID) # Íæ¼ÒÉíÉϵĻID  | 
|     templateID = GetTemplateID(actInfo.get(ShareDefine.ActKey_CfgID, 0), actInfo.get(ShareDefine.ActKey_DayIndex, 0))  | 
|     playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RechargeRebateGoldTemplateID)  | 
|       | 
|     # »î¶¯ID ÏàͬµÄ»°²»´¦Àí  | 
|     if actID == playerActID:  | 
|         GameWorld.DebugLog("ÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯ID²»±ä£¬²»´¦Àí£¡", playerID)  | 
|         if state:  | 
|             if playerTemplateID != templateID and templateID:  | 
|                 PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RechargeRebateGoldTemplateID, templateID)  | 
|                 GameWorld.DebugLog("    »î¶¯Ä£°åID±ä¸ü£¬¸üÐÂÍæ¼ÒÉíÉÏÄ£°åID¼Ç¼£¡playerTemplateID=%s,updTemplateID=%s"   | 
|                                    % (playerTemplateID, templateID), playerID)  | 
|         return  | 
|       | 
|     GameWorld.DebugLog("ÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯ÖØÖÃ! actID=%s,playerActID=%s,state=%s" % (actID, playerActID, state), playerID)  | 
|       | 
|     totalRMB = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RechargeRebateGoldRMB)  | 
|     if playerActID and playerTemplateID and totalRMB > 0:  | 
|         __SendRebateGoldMail(curPlayer, playerTemplateID, totalRMB)  | 
|           | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RechargeRebateGoldID, actID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RechargeRebateGoldTemplateID, templateID)  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RechargeRebateGoldRMB, 0)  | 
|       | 
|     Sync_RechargeRebateGoldActionInfo(curPlayer)  | 
|     Sync_RechargeRebateGoldPlayerInfo(curPlayer)  | 
|     return True  | 
|   | 
| def GetTemplateID(cfgID, dayIndex):  | 
|     if cfgID == None or dayIndex == None:  | 
|         return 0  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActRechargeRebateGold", cfgID)          | 
|     if not ipyData:  | 
|         return 0  | 
|     templateIDList = ipyData.GetTemplateIDList()  | 
|     templateID = templateIDList[-1] if dayIndex >= len(templateIDList) else templateIDList[dayIndex]  | 
|     return templateID  | 
|   | 
| def __SendRebateGoldMail(curPlayer, playerTemplateID, totalRMB):  | 
|     ## ·¢ËÍ·µÀû½±ÀøÓʼþ£¬È¡×î´ó½±Àøµµ·¢½±Àø  | 
|       | 
|     playerID = curPlayer.GetPlayerID()  | 
|     GameWorld.DebugLog("ÀۼƳäÖµ·µÀûÏÉÓñ·¢Ëͽ±ÀøÓʼþ! playerTemplateID=%s,totalRMB=%s" % (playerTemplateID, totalRMB), playerID)  | 
|       | 
|     ipyDataList = IpyGameDataPY.GetIpyGameDataList("RechargeRebateGoldTemplate", playerTemplateID)  | 
|     if not ipyDataList:  | 
|         return  | 
|       | 
|     rebateIpyData = None  | 
|     for ipyData in ipyDataList:  | 
|         rmbMin = ipyData.GetRMBMin()  | 
|         rmbMax = ipyData.GetRMBMax()  | 
|         if (rmbMin <= totalRMB <= rmbMax) or (rmbMin <= totalRMB and rmbMax == 0):  | 
|             rebateIpyData = ipyData  | 
|             break  | 
|           | 
|     if not rebateIpyData:  | 
|         GameWorld.DebugLog("Íæ¼ÒÎÞ·µÀûÏÉÓñ½±Àø!", playerID)  | 
|         return  | 
|       | 
|     rebateRate = rebateIpyData.GetRebateRate()  | 
|     addItemList = []  | 
|     paramList = [totalRMB, rebateRate]  | 
|     gold = min(int(totalRMB * rebateRate / 100.0), ShareDefine.Def_UpperLimit_DWord)  | 
|     GameWorld.DebugLog("    ·µÀûÏÉÓñ°Ù·Ö±È=%s%%, gold=%s" % (rebateRate, gold), playerID)  | 
|     PlayerControl.SendMailByKey("RechargeRebateGold", [playerID], addItemList, paramList, gold)  | 
|     return  | 
|   | 
| def AddRechargeRebateGoldRMB(curPlayer, addRMB):  | 
|     ## Ôö¼Ó»î¶¯ÒÑÀۼƳäÖµRMB£¬ Ö÷¸É·ÖÖ§¼Ç¼µÄÊÇÏÉÓñ£¬Ö»ËãÖ±³ä£¬Ö÷¸ÉûÓÐRMB¶ÔÓ¦±ÈÀýÅäÖã¬Ö±½Ó¼Ç¼ÏÉÓñ  | 
|     actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RechargeRebateGold, {})      | 
|     if not actInfo:  | 
|         return  | 
|       | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     totalRMB = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RechargeRebateGoldRMB) + addRMB  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_RechargeRebateGoldRMB, totalRMB)  | 
|       | 
|     GameWorld.DebugLog("ÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯Ôö¼ÓÍæ¼ÒÀۼƳäÖµRMB: addRMB=%s,totalRMB=%s" % (addRMB, totalRMB), curPlayer.GetPlayerID())  | 
|     Sync_RechargeRebateGoldPlayerInfo(curPlayer)  | 
|     return  | 
|   | 
|   | 
| def Sync_RechargeRebateGoldPlayerInfo(curPlayer):  | 
|     ## Í¨ÖªÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯Íæ¼ÒÊý¾ÝÐÅÏ¢  | 
|     playerActInfo = ChPyNetSendPack.tagMCRechargeRebateGoldPlayerInfo()  | 
|     playerActInfo.RechargeRMBTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_RechargeRebateGoldRMB)  | 
|     NetPackCommon.SendFakePack(curPlayer, playerActInfo)  | 
|     return  | 
|   | 
| def Sync_RechargeRebateGoldActionInfo(curPlayer):  | 
|     ## Í¨ÖªÀۼƳäÖµ·µÀûÏÉÓñ»î¶¯ÐÅÏ¢  | 
|       | 
|     actInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RechargeRebateGold, {})      | 
|     if not actInfo:  | 
|         return  | 
|       | 
|     if not actInfo.get(ShareDefine.ActKey_State):  | 
|         return  | 
|       | 
|     cfgID = actInfo.get(ShareDefine.ActKey_CfgID)  | 
|     ipyData = IpyGameDataPY.GetIpyGameData("ActRechargeRebateGold", cfgID)  | 
|     if not ipyData:  | 
|         return  | 
|       | 
|     templateIDList = ipyData.GetTemplateIDList()  | 
|     if not templateIDList:  | 
|         return  | 
|       | 
|     startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)  | 
|     actInfo = ChPyNetSendPack.tagMCActRechargeRebateGoldInfo()  | 
|     actInfo.StartDate = startDateStr  | 
|     actInfo.EndtDate = endDateStr  | 
|     actInfo.LimitLV = ipyData.GetLVLimit()  | 
|     actInfo.IsDayReset = ipyData.GetIsDayReset()  | 
|     actInfo.RebateDayInfo = []  | 
|     for templateID in templateIDList:  | 
|         ipyDataList = IpyGameDataPY.GetIpyGameDataList("RechargeRebateGoldTemplate", templateID)  | 
|         if not ipyDataList:  | 
|             continue  | 
|           | 
|         dayInfo = ChPyNetSendPack.tagMCActRechargeRebateDay()  | 
|         dayInfo.RebateInfo = []  | 
|         for dayIpyData in ipyDataList:  | 
|             rebateInfo = ChPyNetSendPack.tagMCActRechargeRebate()  | 
|             rebateInfo.RMBMin = dayIpyData.GetRMBMin()  | 
|             rebateInfo.RMBMax = dayIpyData.GetRMBMax()  | 
|             rebateInfo.RebateRate = dayIpyData.GetRebateRate()  | 
|             dayInfo.RebateInfo.append(rebateInfo)  | 
|               | 
|         dayInfo.Rebates = len(dayInfo.RebateInfo)  | 
|         actInfo.RebateDayInfo.append(dayInfo)  | 
|           | 
|     actInfo.RebateDays = len(actInfo.RebateDayInfo)  | 
|     NetPackCommon.SendFakePack(curPlayer, actInfo)  | 
|     return  |