| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #  | 
| #  | 
| ##@package PlayerCompensation.py  | 
| #  | 
| # @todo:Óʼþ¹ÜÀí£¨²¹³¥£©  | 
| #        1. È«·þÓʼþÒ»¸öGUIDÒ»·âÓʼþ£¬ÓÐʱ¼äÏÞÖÆ£¬½ÓÊÕÓʼþµÄ³ÖÐøÊ±¼äºÍÑÓ³Ùɾ³ýʱ¼äµã(¿É½ÓÊÕºóµÄXÌìɾ³ýÓʼþ)  | 
| #           ±íʾÈç¹ûÈ«·þÓʼþÒѾ֪ͨ¹ýij¸öÍæ¼Ò£¬ÄÇô¶ÔÓÚ¸ÃÍæ¼Ò£¬¼´Ê¹Óʼþ¹ýÆÚÍæ¼ÒûÓÐÖ÷¶¯É¾³ýÓʼþ£¬Ò²Ó¦¸Ã֪ͨ¸ÃÍæ¼Ò  | 
| #        2. ¸öÈËÓʼþÒ»¸öGUID¿ÉÒÔÊǸöÈË»òÕß¶àÈËÓʼþ£¬µ«ÊǶàÈËÓʼþ²»Ö§³ÖÅäÖÿÉÁìÈ¡µÄ³ÖÐøÊ±¼ä£¬ÈôÒªÖ§³ÖÐèÐÞ¸ÄÁìÈ¡¼Ç¼Âß¼  | 
| #        3. ¸öÈËÓʼþ°´ÀàÐÍ·Ö²»Í¬µÄ¿É±£´æÊýÁ¿£¬Íæ¼Ò²»¸ÐÖª  | 
| #        4. ¹ØÓÚÓʼþ·¢¼þÈË ±êÌ⠺͠ÕýÎÄ£¬Èç¹ûÊÇÄ£°å»òÕß×éºÏÐÅÏ¢À࣬¶¼Ó¦¸ÃÓÉǰ¶Ë×éÖ¯Íê³É£¬ºó¶Ëֻȡģ°å±êʶ  | 
| #        5. ¿ÉÁìÈ¡¼´ÒÑ֪ͨ¹ýÍæ¼Ò¸Ã·âÓʼþ£¬ÐèÒªÔÚÓʼþ·¢ÉúʱºÍÉÏÏßʱÉèÖÃ״̬  | 
| #  | 
| # @author alee  | 
| # @date 2017-08-11 20:00  | 
| # @version 1.1  | 
| # @note:  | 
| # @change: "2018-08-10 12:00" hxp È«·þÓʼþÔö¼ÓÉý¼¶ºóÊÇ·ñ¿ÉÁìȡѡÏîÉèÖã¬Ôö¼ÓÓʼþ²éѯ¡¢Í¨¹ýÉóºË¡¢É¾³ý¹¦ÄÜ£»  | 
| #------------------------------------------------------------------------------   | 
| #"""Version = 2018-08-10 12:00"""  | 
| #------------------------------------------------------------------------------   | 
| import GameWorld  | 
| import ChConfig  | 
| #import ShareDefine  | 
| import IPY_GameServer  | 
| import ChGameToMapPyPack  | 
| import NetPackCommon  | 
| import CommFunc  | 
| import ChPyNetSendPack  | 
| import DataRecordPack  | 
| import ReadChConfig  | 
| import PlayerDBOper  | 
| import EventReport  | 
| import IpyGameDataPY  | 
| import PlayerControl  | 
| import datetime  | 
| import uuid  | 
| import math  | 
| import json  | 
| #Áìȡ״̬  ¸öλÊý±êʶ £¨¿ÉÁìÈ¡¼´ÒÑ֪ͨ¹ýÍæ¼Ò¸Ã·âÓʼþ£¬ÐèÒªÔÚÓʼþ·¢ÉúʱºÍÉÏÏßʱÉèÖÃ״̬  | 
| #0 Î´Í¨Öª£¬1 ²»¿ÉÁìÈ¡£¬ 2 ¿ÉÁìÈ¡£¬ 3 ÒÑÁìÈ¡  | 
| (  | 
| Unknown_State,  | 
| Disable_State,  | 
| Enable_State,  | 
| Yet_State  | 
| ) = range(4)  | 
|   | 
| CheckState_OK = 0 # ÒÑÉóºË  | 
| CheckState_No = 1 # Î´ÉóºË  | 
|   | 
| LimitLVType_Not = 0 # Éý¼¶Âú×ãÁìÈ¡µÈ¼¶ºó²»¿ÉÁì  | 
| LimitLVType_Can = 1 # Éý¼¶Âú×ãÁìÈ¡µÈ¼¶ºó¿ÉÁì  | 
|   | 
| #Áìȡ״̬  Ê®Î»Êý±êʶ  | 
| (  | 
| Read_State_No,  # Óʼþδ¶Á  | 
| Read_State_Yes  # ÓʼþÒѶÁ  | 
| ) = range(2)  | 
|   | 
| #Áìȡ״̬  | 
| (  | 
| Entire_CompensationType,    #È«·þ  | 
| Personal_CompensationType,  #¸öÈË  | 
| Unknow_CompensationType     #δ֪  | 
| ) = range(3)  | 
|   | 
| Def_RequestState = "CompensationRequestState"  | 
|   | 
| ## ¸ù¾ÝÎïÆ·ÐÅÏ¢×ֵ䣬Éú³É²¹³¥ÎïÆ·ÊµÀý£¬ÓÃÓÚGM¹¤¾ßÌí¼Ó²¹³¥  | 
| #  @param curItemDict   | 
| #  @return IpyCompensationItem  | 
| def MakeCompensationItem(curItemDict):  | 
|     curItemData = IPY_GameServer.IpyCompensationItem()  | 
|     #curItemData.GUID = curItemDict['GUID']  | 
|     curItemData.ItemID = curItemDict['ItemID']  | 
|     curItemData.Count = curItemDict['Count']  | 
|     curItemData.IsBind = curItemDict.get('IsBind',0)  | 
|     curItemData.UserData = curItemDict.get('UserData', '')  | 
|     return curItemData  | 
|   | 
| #  ´Ë´¦»õ±ÒplayerIDList·¢·Åͳһ£¬Èç¸ù¾ÝÍæ¼Ò²»Í¬¶ø±ä£¬ÔòÓ¦ÐèÐÞ¸Ä  | 
| ## ¹¦ÄÜ·¢·ÅÎïÆ·²¹³¥/½±ÀøÓʼþ  | 
| #  @param addItemList [(itemID, itemCnt, isBind), {»òÎïÆ·ÐÅÏ¢×Öµä}, ...]  | 
| #  @return GUID  | 
| def SendPersonalItemMailEx(title, content, getDays, playerIDList, addItemList,   | 
|                            gold = 0, goldPaper = 0, silver = 0, sourceType = ChConfig.Mail_Type_Default):  | 
|     limitTime = str(GameWorld.GetDatetimeByDiffDays(getDays))  | 
|     limitTime = limitTime.split(".")[0]  | 
|     return SendPersonalItemMail(title, content, limitTime, playerIDList, addItemList,   | 
|                                 gold, goldPaper, silver, sourceType)  | 
|       | 
| def SendPersonalItemMailBatch(batchMailInfoList):  | 
|     ## ÅúÁ¿·¢ËÍÓʼþ  | 
|     mailTypeKey, batchPlayerIDList, batchAddItemList, batchParamList, batchGold, batchGoldPaper, batchSilver = batchMailInfoList  | 
|      | 
|     lenPlayerID = len(batchPlayerIDList)  | 
|     lenItem = len(batchAddItemList)  | 
|     lenParam = len(batchParamList)  | 
|     lenGold = len(batchGold)  | 
|     lenGoldPaper = len(batchGoldPaper)  | 
|     lenSilver = len(batchSilver)  | 
|       | 
|     title = ""  | 
|     getDays = 30  | 
|     limitTime = str(GameWorld.GetDatetimeByDiffDays(getDays))  | 
|     limitTime = limitTime.split(".")[0]  | 
|       | 
|     for i, playerIDList in enumerate(batchPlayerIDList):  | 
|         addItemList = batchAddItemList[i] if lenItem == lenPlayerID else []  | 
|         paramList = batchParamList[i] if lenParam == lenPlayerID else []  | 
|         gold = batchGold[i] if lenGold == lenPlayerID else 0  | 
|         goldPaper = batchGoldPaper[i] if lenGoldPaper == lenPlayerID else 0  | 
|         silver = batchSilver[i] if lenSilver == lenPlayerID else 0  | 
|         content = "<MailTemplate>%s</MailTemplate>%s" % (mailTypeKey, str(paramList))  | 
|         SendPersonalItemMail(title, content, limitTime, playerIDList, addItemList, gold, goldPaper, silver)  | 
|           | 
|     return  | 
|   | 
| def SendMailByKey(mailTypeKey, playerIDList, addItemList, paramList=[], gold=0, goldPaper=0, silver=0):  | 
|     GameWorld.DebugLog("SendMailByKey %s, playerIDList=%s, addItemList=%s, paramList=%s, gold=%s, goldPaper=%s, silver=%s"   | 
|                        % (mailTypeKey, playerIDList, addItemList, paramList, gold, goldPaper, silver))  | 
|     title = ""  | 
|     content = "<MailTemplate>%s</MailTemplate>%s" % (mailTypeKey, json.dumps(paramList, ensure_ascii=False))  | 
|     return SendPersonalItemMailEx(title, content, 30, playerIDList, addItemList, gold, goldPaper, silver)  | 
|   | 
| #  ´Ë´¦»õ±ÒplayerIDList·¢·Åͳһ£¬Èç¸ù¾ÝÍæ¼Ò²»Í¬¶ø±ä£¬ÔòÓ¦ÐèÐÞ¸Ä  | 
| ## ¹¦ÄÜ·¢·ÅÎïÆ·²¹³¥/½±ÀøÓʼþ  | 
| #  @param addItemList [(itemID, itemCnt, isBind), {»òÎïÆ·ÐÅÏ¢×Öµä}, ...]  | 
| #  @return GUID  | 
| #  @remarks addItemListÖ§³Öappend×Öµä  | 
| def SendPersonalItemMail(title, content, limitTime, playerIDList, addItemList,  | 
|                          gold = 0, goldPaper = 0, silver = 0, sourceType = ChConfig.Mail_Type_Default):  | 
|     if not playerIDList:  | 
|         return ""  | 
|       | 
|     #if not addItemList:  | 
|     #    return ""  | 
|   | 
|     curServerTime = GameWorld.GetCurrentDataTimeStr()  | 
|     # µ±Ç°Ê±¼äÒѾ³¬¹ýÁìȡʱ¼ä  | 
|     if not curServerTime or curServerTime >= limitTime:  | 
|         GameWorld.DebugLog("¹¦ÄÜ·¢·ÅÎïÆ·²¹³¥/½±ÀøÓʼþ£¬Áìȡʱ¼äÒѳ¬Ê±£¬Ä¬Èϲ»Ìí¼Ó£¡LimitTime=%s" % limitTime)  | 
|         return ""  | 
|       | 
|     addItemDictList = []  | 
|     for itemInfo in addItemList:  | 
|         if isinstance(itemInfo, dict):  | 
|             addItemDictList.append(itemInfo)  | 
|             continue  | 
|           | 
|           | 
|         if len(itemInfo) == 3:  | 
|             itemID, itemCnt, isBind = itemInfo  | 
|         else:  | 
|             continue  | 
|               | 
|         addItemDict = {}  | 
|         addItemDict['ItemID'] = itemID  | 
|         addItemDict['Count'] = itemCnt  | 
|         addItemDict['IsBind'] = isBind  | 
|         addItemDictList.append(addItemDict)  | 
|           | 
|     perMailItemCnt = IpyGameDataPY.GetFuncCfg("MailMaxItemCnt")  | 
|     mailCnt = max(1, int(math.ceil(len(addItemDictList)/float(perMailItemCnt)))) # Ò»·âÓʼþ×î¶à5¸öÎïÆ·  | 
|     for i in xrange(mailCnt):  | 
|         startIndex = i*perMailItemCnt  | 
|         GUID = str(uuid.uuid1())  | 
|         AddPersonalItem(GUID, addItemDictList[startIndex:startIndex + perMailItemCnt], playerIDList,   | 
|                                            limitTime, "%s<$_$>%s<$_$>%s" % (ChConfig.Def_Mail_SenderSys, title, content),  | 
|                                            gold, goldPaper, silver)  | 
|     return GUID  | 
|   | 
| ## ·¢ËÍ´¿ÎÄ×Ö¸öÈ˲¹³¥  | 
| #  @param limitTime ¿ÉÒÔ´«¿Õ  | 
| #  @param sourceType ²é¿´ Mail_Type_Default Ïà¹Ø¶¨Òå  | 
| #  @return None  | 
| def SendPersonalAsTextMail(PlayerID, title, content, limitTime, sourceType = ChConfig.Mail_Type_Default):  | 
|     if GameWorld.IsMergeServer():  | 
|         return  | 
|     GUID = str(uuid.uuid1())  | 
|     PyAddPersonalCompensation(GUID, PlayerID, GameWorld.GetCurrentDataTimeStr(), limitTime,   | 
|                               "%s<$_$>%s<$_$>%s" % (ChConfig.Def_Mail_SenderSys,title, content), sourceType)  | 
|     return  | 
|   | 
| def GetEntireCompensationInfo(checkState, limitLVType, limitLV):  | 
|     return checkState * 1000000 + limitLVType * 100000 + limitLV  | 
| def ParseEntireCompensationInfo(mailInfo):  | 
|     limitLV = mailInfo % 100000  | 
|     checkState = mailInfo / 1000000  | 
|     limitLVType = (mailInfo - checkState * 1000000) / 100000  | 
|     return checkState, limitLVType, limitLV  | 
|   | 
| def QueryCompensationInfo(fromDate, toDate, guid, searchTitle, searchContent, searchState=None, maxCount=10):  | 
|     '''²¹³¥Óʼþ²éѯ  | 
|     '''  | 
|       | 
|     compensationMgr = GameWorld.GetCompensationMgr()  | 
|     retList = []  | 
|     if guid:  | 
|         infoDict = __GetQueryCompensationInfoDict(compensationMgr, compensationMgr.FindEntireCompensation(guid), "", "", searchTitle, searchContent, searchState)  | 
|         if infoDict:  | 
|             retList.append(infoDict)  | 
|         return retList  | 
|       | 
|     if fromDate:  | 
|         fromDate = "%s 00:00:00" % fromDate  | 
|     if toDate:  | 
|         toDate = "%s 23:59:59" % toDate  | 
|           | 
|     entireCnt = compensationMgr.GetEntireCompensationCount()  | 
|     for i in xrange(entireCnt):  | 
|         compensation = compensationMgr.AtEntireCompensation(i)  | 
|                       | 
|         infoDict = __GetQueryCompensationInfoDict(compensationMgr, compensation, fromDate, toDate, searchTitle, searchContent, searchState)  | 
|         if not infoDict:  | 
|             continue  | 
|           | 
|         retList.append(infoDict)  | 
|         if len(retList) >= maxCount:  | 
|             break  | 
|           | 
|     return retList  | 
|   | 
| def __GetQueryCompensationInfoDict(compensationMgr, compensation, fromDate, toDate, searchTitle, searchContent, searchState):  | 
|     if not compensation or not compensation.GUID:  | 
|         return  | 
|       | 
|     if fromDate and compensation.CreateTime < fromDate:  | 
|         return  | 
|       | 
|     if toDate and compensation.CreateTime > toDate:  | 
|         return  | 
|       | 
|     contentList = compensation.Text.split("<$_$>")  | 
|     if len(contentList) != 3:  | 
|         return  | 
|     sender, title, content = contentList  | 
|       | 
|     if searchTitle and searchTitle not in title:  | 
|         return  | 
|       | 
|     if searchContent and searchContent not in content:  | 
|         return  | 
|       | 
|     checkState, limitLVType, limitLV = ParseEntireCompensationInfo(compensation.PlayerLV)  | 
|     if searchState != None and searchState != checkState:  | 
|         return  | 
|       | 
|     GUID = compensation.GUID  | 
|     itemList = []  | 
|     curGUIDItemCount = compensationMgr.FindItemCount(GUID)  | 
|     for i in xrange(curGUIDItemCount):  | 
|         curItem = GameWorld.GetCompensationMgr().FindItemAt(GUID, i)  | 
|         itemID = curItem.ItemID  | 
|         if not itemID:  | 
|             continue  | 
|         itemList.append([itemID, curItem.Count, curItem.IsBind, curItem.UserData])  | 
|           | 
|     compensationDict = {"GUID":GUID, "CheckState":checkState, "LimitLVType":limitLVType, "LimitLV":limitLV,  | 
|                         "Gold":compensation.Gold, "GoldPaper":compensation.GoldPaper, "Silver":compensation.Silver,  | 
|                         "PlayerJob":compensation.PlayerJob, "Sender":sender, "Title":title, "Content":content,  | 
|                         "CreateTime":compensation.CreateTime, "LimitTime":compensation.LimitTime, "ItemList":itemList}  | 
|     return compensationDict  | 
|   | 
| def EntireCompensationOper(operGUIDList, operation):  | 
|     '''È«·þÓʼþ²Ù×÷¹ÜÀí  | 
|     @param operGUIDList: ´ý²Ù×÷µÄÓʼþGUIDÁÐ±í  | 
|     @param operation: 1-ͨ¹ý£»2-ɾ³ý  | 
|     '''  | 
|       | 
|     okGUIDList = []  | 
|     successGUIDList = []  | 
|     compensationMgr = GameWorld.GetCompensationMgr()  | 
|     for GUID in operGUIDList:  | 
|         compensation = compensationMgr.FindEntireCompensation(GUID)  | 
|         if not compensation or compensation.GUID != GUID:  | 
|             continue  | 
|           | 
|         # É¾³ý  | 
|         if operation == 2:  | 
|             compensationMgr.DeleteEntireCompensation(GUID)  | 
|             compensationMgr.DeleteCompensationItem(GUID)  | 
|             compensationMgr.DeleteRecByGUID(GUID)  | 
|             GameWorld.Log("ɾ³ýÈ«·þÓʼþ: GUID=%s" % GUID)  | 
|             DataRecordPack.DR_EntireCompensation(GUID, "Delete")  | 
|               | 
|         # Í¨¹ý  | 
|         elif operation == 1:  | 
|             mailInfo = compensation.PlayerLV  | 
|             checkState, limitLVType, limitLV = ParseEntireCompensationInfo(mailInfo)  | 
|             updMailInfo = GetEntireCompensationInfo(CheckState_OK, limitLVType, limitLV)  | 
|             compensationMgr.SetEntireCompensationPlayerLV(GUID, updMailInfo)  | 
|             GameWorld.Log("È«·þÓʼþÉóºËͨ¹ý: GUID=%s,mailInfo=%s,checkState=%s,updMailInfo=%s"   | 
|                           % (GUID, mailInfo, checkState, updMailInfo))  | 
|             if checkState != CheckState_OK:  | 
|                 okGUIDList.append(GUID)  | 
|                 DataRecordPack.DR_EntireCompensation(GUID, "CheckOK")  | 
|         else:  | 
|             continue  | 
|         successGUIDList.append(GUID)  | 
|           | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for i in xrange(playerManager.GetActivePlayerCount()):  | 
|         player = playerManager.GetActivePlayerAt(i)  | 
|         if player == None or not player.GetInitOK() or PlayerControl.GetIsTJG(player):  | 
|             continue  | 
|         #¹ã²¥ÔÚÏßÍæ¼Ò  | 
|         notifyList = []  | 
|         for GUID in okGUIDList:  | 
|             compensationType, curEntireRequire = CheckRequestCompensation(player, GUID, False)  | 
|             if compensationType == Unknow_CompensationType:  | 
|                 continue  | 
|             Text, gold, goldPaper, silver = curEntireRequire.Text, curEntireRequire.Gold, curEntireRequire.GoldPaper, curEntireRequire.Silver  | 
|             createTime = curEntireRequire.CreateTime  | 
|             notifyList.append((GUID, Text, createTime, gold, goldPaper, silver))  | 
|               | 
|         #GameWorld.DebugLog("¹ã²¥ÔÚÏßÍæ¼ÒÈ«·þÓʼþ: %s" % str(notifyList), player.GetPlayerID())  | 
|         if notifyList:  | 
|             SyncQueryCompensationResult(player, notifyList)  | 
|               | 
|     return successGUIDList  | 
|   | 
| ## Ìí¼ÓÈ«·þ²¹³¥  | 
| #  @param addItemDictList, LimitTime, mailInfo, PlayerJob,  Text   | 
| #  @return None  | 
| def AddEntireItem(GUID, addItemDictList, LimitTime, mailInfo, PlayerJob, Text,  | 
|                   gold = 0, goldPaper = 0, silver = 0):  | 
|     '''  | 
|     @param mailInfo: GetEntireCompensationInfo µÄ·µ»ØÖµ, Ä¿Ç°ÔÝ´æ×ֶΠPlayerLV ÖÐ  | 
|     '''  | 
|     if GameWorld.IsMergeServer():  | 
|         return  | 
|     #GameWorld.DebugLog("Compensation### AddEntireItem GUID:%s ItemDict:\n%s "%(GUID, addItemDictList))  | 
|       | 
|     #Ìí¼Ó²¹³¥°üµÄËùÓÐÎïÆ·  | 
|     for addItemDict in addItemDictList:  | 
|         curItemData = MakeCompensationItem(addItemDict)  | 
|         GameWorld.GetCompensationMgr().AddCompensationItem(GUID, curItemData)  | 
|           | 
|     createTime = GameWorld.GetCurrentDataTimeStr()  | 
|     #Ìí¼ÓÈ«·þÁìÈ¡²¹³¥Ìõ¼þ  | 
|     GameWorld.GetCompensationMgr().AddEntireCompensationItem(GUID, createTime, LimitTime, mailInfo,   | 
|                                                              PlayerJob, Text, gold, goldPaper, silver)  | 
|     checkState, limitLVType, limitLV = ParseEntireCompensationInfo(mailInfo)  | 
|     addDict = {"LimitTime":LimitTime, "LimitLV":limitLV, "LimitLVType":limitLVType, "CheckState":checkState, "PlayerJob":PlayerJob, "Text":Text,   | 
|                "Gold":gold, "GoldPaper":goldPaper, "Silver":silver, "ItemList":addItemDictList}  | 
|     #Ìí¼ÓÁ÷Ïò  | 
|     eventName = "Add" if checkState == CheckState_OK else "AddToCheck"  | 
|     DataRecordPack.DR_EntireCompensation(GUID, eventName, addDict)  | 
|     __WriteSendMailOKEvent(GUID, addItemDictList, LimitTime, Text, None, mailInfo, PlayerJob)  | 
|       | 
|     testAccIDList = ReadChConfig.GetEvalChConfig("TestAccID")  | 
|     playerManager = GameWorld.GetPlayerManager()  | 
|     for i in xrange(playerManager.GetActivePlayerCount()):  | 
|         player = playerManager.GetActivePlayerAt(i)  | 
|         if player == None or not player.GetInitOK() or PlayerControl.GetIsTJG(player):  | 
|             continue  | 
|         if checkState == CheckState_No:  | 
|             playerAccID = GameWorld.GetPlatformAccID(player.GetAccID())  | 
|             if playerAccID not in testAccIDList:  | 
|                 continue  | 
|                   | 
|         #¹ã²¥ÔÚÏßÍæ¼Ò  | 
|         compensationType, curEntireRequire = CheckRequestCompensation(player, GUID, False)  | 
|         if compensationType == Unknow_CompensationType:  | 
|             continue  | 
|         Text, gold, goldPaper, silver = curEntireRequire.Text, curEntireRequire.Gold, curEntireRequire.GoldPaper, curEntireRequire.Silver  | 
|         #GameWorld.Log("#¹ã²¥ÔÚÏßÍæ¼Ò%s"%player.GetPlayerID())  | 
|         SyncQueryCompensationResult(player, [(GUID, Text, createTime, gold, goldPaper, silver)])  | 
|     return  | 
|   | 
| # ¼ì²éÓʼþÊÇ·ñÒÑ´ïµ½±£´æÉÏÏÞ£¬È糬¹ýÔòÏÈɾ³ý¾ÉÓʼþ  | 
| # @param LimitTime ²ÎÊý¿É´«¿Õ£¬¸öÈËÓʼþ²»ÏÞÖÆÁìÈ¡ÆÚÏÞ£¬Ö»ÏÞÖÆ±£´æÊýÁ¿£¬   | 
| def PyAddPersonalCompensation(GUID, PlayerID, CreateTime, LimitTime, Text, sourceType,   | 
|                               gold = 0, goldPaper = 0, silver = 0):  | 
|     curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(PlayerID)  | 
|     cnt = GameWorld.GetCompensationMgr().GetPersonalCompensationCountByType(PlayerID, sourceType)  | 
|     #´ýÖ§³Öpy¶Á±í  | 
|     tmpDict = {ChConfig.Mail_Type_Default:IpyGameDataPY.GetFuncCfg("MailDefaultCount"),   | 
|                ChConfig.Mail_Type_Market:IpyGameDataPY.GetFuncCfg("MailMarketCount")}  | 
|       | 
|     delcnt = cnt - tmpDict[sourceType] + 1  | 
|     #GameWorld.DebugLog("PyAddPersonalCompensation typecnt = %s-%s"%(cnt, delcnt))  | 
|     if delcnt > 0:  | 
|         #ÏÈÈ¡µÃҪɾ³ýµÄGUID  | 
|         delGUIDs = []  | 
|         for i in xrange(delcnt):  | 
|             tmpGuid = GameWorld.GetCompensationMgr().AtGUIDInPersonalTypesByType(PlayerID, sourceType, i)  | 
|             if not tmpGuid:  | 
|                 #GameWorld.DebugLog("PyAddPersonalCompensation not GUID = %s"%tmpGuid)  | 
|                 continue  | 
|             delGUIDs.append(tmpGuid)  | 
|           | 
|         for guid in delGUIDs:      | 
|             ClearPersonalCompensation(PlayerID, guid)  | 
|             #GameWorld.DebugLog("PyAddPersonalCompensation DeletePersonalCompensation GUID = %s"%guid)  | 
|               | 
|             if curPlayer:  | 
|                 NotifyCompensationResult(curPlayer, guid, 1)  | 
|             #δ²¹Á÷Ïò  | 
|       | 
|     #GameWorld.DebugLog("PyAddPersonalCompensation CreateTime %s"%CreateTime)  | 
|     #´Ë´¦Ã»ÓÐÏ·¢Í¨Öª  | 
|     GameWorld.GetCompensationMgr().AddPersonalCompensation(GUID, PlayerID, CreateTime,  | 
|                                                            LimitTime, Text, sourceType, gold, goldPaper, silver)  | 
|     return  | 
|   | 
|   | 
| #  ´Ë´¦»õ±ÒplayerIDList·¢·Åͳһ£¬Èç¸ù¾ÝÍæ¼Ò²»Í¬¶ø±ä£¬ÔòÓ¦ÐèÐÞ¸Ä  | 
| ## Ìí¼Ó¸öÈ˲¹³¥  | 
| #  @param addItemDict, PlayerIDList, LimitTime, Text   | 
| #  @return None  | 
| def AddPersonalItem(GUID, addItemDictList, PlayerIDList, LimitTime, Text,   | 
|                     gold = 0, goldPaper = 0, silver = 0, sourceType = ChConfig.Mail_Type_Default):  | 
|     if GameWorld.IsMergeServer():  | 
|         return  | 
|     GameWorld.DebugLog("Compensation### AddPersonalItem GUID:%s ItemDict:\n%s "%(GUID, addItemDictList))  | 
|       | 
|     #Ìí¼Ó²¹³¥°üµÄËùÓÐÎïÆ·  | 
|     for addItemDict in addItemDictList:  | 
|         curItemData = MakeCompensationItem(addItemDict)  | 
|         GameWorld.GetCompensationMgr().AddCompensationItem(GUID, curItemData)  | 
|           | 
|     #offlinePlayerIDList = []  | 
|     onlinePlayerInfo = {}  | 
|     #ÅúÁ¿Ìí¼ÓÍæ¼Ò¸öÈ˲¹³¥ÁìÈ¡±í  | 
|     createTime = GameWorld.GetCurrentDataTimeStr()  | 
|     for PlayerID in PlayerIDList:  | 
|         PyAddPersonalCompensation(GUID, PlayerID, createTime, LimitTime,   | 
|                                   Text, sourceType, gold, goldPaper, silver)  | 
|         # Õë¶Ô¸öÈ˲¹³¥£¬Èç¹ûÊÇÔÚÏßÍæ¼Ò£¬ÔòÁ¢¼´ÍÆË͸ø¿Í»§¶Ë  | 
|         curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(PlayerID)  | 
|         if curPlayer:  | 
|             SyncQueryCompensationResult(curPlayer, [(GUID, Text, createTime, gold, goldPaper, silver)])  | 
|             onlinePlayerInfo[curPlayer.GetAccID()] = [curPlayer.GetName(), curPlayer.GetLV()]  | 
|     #===========================================================================  | 
|     #    else:  | 
|     #        offlinePlayerIDList.append(PlayerID)  | 
|     #          | 
|     # if offlinePlayerIDList:  | 
|     #    PlayerDBOper.FindDBOper(PlayerDBOper.Table_DBPlayer, {"PlayerID":{"$in":offlinePlayerIDList}},  | 
|     #                            {"PlayerID":1, "AccID":1, "PlayerName":1, "LV":1, "_id":0},  | 
|     #                            FindDBResult_SendMail, [GUID, addItemDictList, createTime, Text])  | 
|     # if onlinePlayerInfo:  | 
|     #    __WriteSendMailOKEvent(GUID, addItemDictList, createTime, Text, onlinePlayerInfo)  | 
|     #===========================================================================  | 
|       | 
|     #Ìí¼ÓÁ÷Ïò  | 
|     addDict = {"LimitTime":LimitTime, "Text":Text, "Gold":gold, "GoldPaper":goldPaper, "Silver":silver,   | 
|                "ItemListLen":len(addItemDictList)}  | 
|     DataRecordPack.DR_AddPersonalCompensation(PlayerIDList, GUID, addItemDictList, addDict)  | 
|     return  | 
|   | 
| def FindDBResult_SendMail(resultSetList, extendValueList):  | 
|     if not resultSetList:  | 
|         return  | 
|       | 
|     playerInfoDict = {}  | 
|     GUID, addItemDictList, LimitTime, Text = extendValueList  | 
|     GameWorld.Log("ÓʼþÀëÏßÍæ¼ÒDBÐÅÏ¢: GUID=%s, %s" % (GUID, str(resultSetList)))  | 
|     for resultDict in resultSetList:  | 
|         playerInfoDict[resultDict["AccID"]] = [resultDict["PlayerName"], resultDict["LV"]]  | 
|           | 
|     __WriteSendMailOKEvent(GUID, addItemDictList, LimitTime, Text, playerInfoDict)  | 
|     return  | 
|   | 
| ## Í¨ÖªµØÍ¼Óʼþ·¢ËÍOK  | 
| def __WriteSendMailOKEvent(GUID, addItemDictList, LimitTime, Text, playerInfoDict={}, playerLV=0, playerJob=0):  | 
| #===============================================================================  | 
| #    eventName = "SendMail"  | 
| #    #%s<$_$>%s  | 
| #    sender, title, content = Text.split("<$_$>")  | 
| #   | 
| #    #<MailTemplate>Ä£°å±àºÅ</MailTemplate>[%s,%s]  | 
| #    if "</MailTemplate>" in content:  | 
| #        mailContentList = content.split("</MailTemplate>")  | 
| #        mailTemplateNO = GameWorld.ToIntDef(mailContentList[0][14:], None)  | 
| #        EventMailInfo = ReadChConfig.GetEvalChConfig("EventMailInfo")  | 
| #        if mailTemplateNO not in EventMailInfo:  | 
| #            return  | 
| #        title, content = EventMailInfo[mailTemplateNO]  | 
| #          | 
| #        mailParamStr = mailContentList[1]  | 
| #        mailParamStr = mailParamStr.replace(" ", "")  | 
| #        if mailParamStr.startswith("[") and mailParamStr.endswith("]") and len(mailParamStr) > 2:  | 
| #            content = content % tuple(eval(mailParamStr))  | 
| #              | 
| #    itemInfo = "ÎïÆ·:"  | 
| #    for addItemDict in addItemDictList:  | 
| #        itemName = "%s" % addItemDict['ItemID']  | 
| #        if addItemDict.get('IsBind',0):  | 
| #            itemName += "(°ó)"  | 
| #        itemInfo += " %s*%s" % (itemName, addItemDict['Count'])  | 
| #          | 
| #    # È«·þ  | 
| #    if not playerInfoDict:  | 
| #        comments = "%s: %s ÓÐЧÆÚ:%s, ÏÞÖÆµÈ¼¶:%s,Ö°Òµ:%s; %s; %s" % (title, GUID, LimitTime, playerLV, playerJob, itemInfo, content)  | 
| #        customEvent = EventReport.custom_events()  | 
| #        customEvent.account_id = "ServerAccount"  | 
| #        customEvent.event_name = eventName  | 
| #        customEvent.session_id = "ServerSession"  | 
| #        customEvent.account_name = customEvent.account_id  | 
| #        customEvent.comments = CommFunc.GetStrCutoff(comments, 255)  | 
| #        EventReport.WriteEvent(customEvent)  | 
| #    else:  | 
| #        comments = "%s: %s ÓÐЧÆÚ:%s, %s; %s" % (title, GUID, LimitTime, itemInfo, content)  | 
| #        comments = CommFunc.GetStrCutoff(comments, 255)  | 
| #        for accID, playerInfo in playerInfoDict.items():  | 
| #            playerName, playerLV = playerInfo  | 
| #            customEvent = EventReport.custom_events()  | 
| #            customEvent.SetEventAgentInfo(GameWorld.GetPlayerPlatform(accID))  | 
| #            customEvent.account_id = GameWorld.GetPlatformAccID(accID)  | 
| #            customEvent.event_name = eventName  | 
| #            customEvent.session_id = "GameServerPlayerSession"  | 
| #              | 
| #            customEvent.account_name = customEvent.account_id  | 
| #            customEvent.chr_name = playerName  | 
| #            customEvent.comments = comments  | 
| #            EventReport.WriteEvent(customEvent)  | 
| #===============================================================================  | 
|     return  | 
|   | 
|   | 
| ##A9 A1 ²éÑ¯Íæ¼Ò²¹³¥#tagCGQueryCompensation  | 
| #  @param index, clientData, tick   | 
| #  @return None  | 
| def OnQueryPlayerCompensation(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     NotifyPlayerCompensation(curPlayer)  | 
|   | 
|   | 
| # ÌáÈ¡½ÓÊÕÓʼþÏ·¢  | 
| def NotifyPlayerCompensation(curPlayer):  | 
|     notifyList = SeekPlayerCompensation(curPlayer)  | 
|     SyncQueryCompensationResult(curPlayer, notifyList)  | 
|     return  | 
|   | 
| # É¾³ý¸öÈËÓʼþ±í ×´Ì¬±í£¬Í¬Ò»¸öGUID ¿ÉÒÔ¶àÈËÁìÈ¡£¬²»ÄÜͬʱɾ³ýÎïÆ·  | 
| def ClearPersonalCompensation(curPlayerID, curGUID):  | 
|     GameWorld.GetCompensationMgr().DeletePersonalCompensation(curPlayerID, curGUID)  | 
|     GameWorld.GetCompensationMgr().DeletePlayerCompensationRec(curPlayerID, curGUID)  | 
|       | 
|     #´æÔÚ¶àÈËÓʼþµÄÇé¿ö£¬¹Êɾ³ýÎïÆ·Ðè¼ì²éÊÇ·ñ×îºóÒ»¸öÁìÈ¡Õ߲ſÉɾ³ý  | 
|     if GameWorld.GetCompensationMgr().GetPersonalCountByGUID(curGUID) == 0:  | 
|         GameWorld.GetCompensationMgr().DeleteCompensationItem(curGUID)  | 
|     return  | 
|   | 
| # ÉèÖÃÁìȡ״̬  | 
| def SetPrizeState(curPlayerID, GUID, prizeState, readState):  | 
|     state = readState*10 + prizeState  | 
|     GameWorld.GetCompensationMgr().AddPlayerRec(curPlayerID, GUID, state)  | 
|   | 
| ##²éÕÒÍæ¼Ò¿ÉÁìÈ¡µÄ²¹³¥ÁÐ±í  | 
| #  @param curPlayer   | 
| #  @return None  | 
| def SeekPlayerCompensation(curPlayer):  | 
|     curPlayerID = curPlayer.GetID()  | 
|     curTime = datetime.datetime.today()  | 
|   | 
|     allList = [] #²¹³¥ÎïÆ·±í [(GUID,TEXT),(GUID,TEXT),...]  | 
|     #¸öÈ˲¹³¥  | 
|     curPersonalCount = GameWorld.GetCompensationMgr().GetPersonalCompensationCount(curPlayerID)  | 
|     for i in xrange(curPersonalCount):  | 
|         curIpyPersonalData = GameWorld.GetCompensationMgr().PersonalCompensationAt(curPlayerID, i)  | 
|   | 
|         #¿ÉÒÔÓõĽ±Àø  | 
|         allList.append((curIpyPersonalData.GUID, curIpyPersonalData.Text, curIpyPersonalData.CreateTime,  | 
|                         curIpyPersonalData.Gold, curIpyPersonalData.GoldPaper, curIpyPersonalData.Silver))  | 
|       | 
|     #È«·þ²¹³¥      | 
|     curEntireCount = GameWorld.GetCompensationMgr().GetEntireCompensationCount()  | 
|     curJob = curPlayer.GetJob()  | 
|     curLV = curPlayer.GetLV()  | 
|     isTestAccID = GameWorld.GetPlatformAccID(curPlayer.GetAccID()) in ReadChConfig.GetEvalChConfig("TestAccID")  | 
|     for i in xrange(curEntireCount - 1, -1, -1):  | 
|         curRequire = GameWorld.GetCompensationMgr().AtEntireCompensation(i)  | 
|           | 
|         checkState, limitLVType, limitLV = ParseEntireCompensationInfo(curRequire.PlayerLV)  | 
|         if checkState == CheckState_No:  | 
|             if not isTestAccID:  | 
|                 #δÉóºËµÄÓʼþ²»´¦Àí  | 
|                 continue  | 
|               | 
|         #»ñÈ¡¼Ç¼  | 
|         states = GameWorld.GetCompensationMgr().FindPlayerRecState(curPlayerID, curRequire.GUID)  | 
|         readState = states/10    # ¿É¶Á         | 
|         curState = states%10    # Áìȡ״̬  | 
|         if curState in (Disable_State, Yet_State):  | 
|             #²»¿ÉÁì »ò ÒÑÁì  | 
|               | 
|             continue  | 
|           | 
|         limitTime = datetime.datetime.strptime(curRequire.LimitTime, ChConfig.TYPE_Time_Format)  | 
|         if limitTime < curTime and curState == Unknown_State:  | 
|             #δ֪ͨ¹ýµÄÓʼþ³¬Ê±£¬²Å¿ÉÉèÖóɲ»¿ÉÁìÈ¡  | 
|             SetPrizeState(curPlayerID, curRequire.GUID, Disable_State, readState)  | 
|             continue  | 
|           | 
|         if limitLV > curLV:  | 
|             #µÈ¼¶²»×ã  | 
|             if limitLVType == LimitLVType_Not:  | 
|                 SetPrizeState(curPlayerID, curRequire.GUID, Disable_State, readState)  | 
|             continue  | 
|         if curRequire.PlayerJob not in (-1, 127):  | 
|             curJob = curPlayer.GetJob()  | 
|             #ÓÐÖ°ÒµÏÞÖÆ  | 
|             if (curRequire.PlayerJob&pow(2,curJob)) == 0:  | 
|                 SetPrizeState(curPlayerID, curRequire.GUID, Disable_State, readState)  | 
|                 continue  | 
|               | 
|         #¿ÉÒÔÓõĽ±Àø  | 
|         if Enable_State != curState:  | 
|             SetPrizeState(curPlayerID, curRequire.GUID, Enable_State, readState)  | 
|         allList.append((curRequire.GUID, curRequire.Text, curRequire.CreateTime,  | 
|                         curRequire.Gold, curRequire.GoldPaper, curRequire.Silver))  | 
|   | 
|     return allList  | 
|   | 
| ##·¢ËÍ¿ÉÁìÈ¡½±Àø²éѯ½á¹û  | 
| #  @param curPlayer, notifyList   | 
| #  @return None  | 
| def SyncQueryCompensationResult(curPlayer, notifyList):  | 
|     sendPack = ChPyNetSendPack.tagGCQueryCompensationResult()  | 
|     sendPack.Clear()  | 
|     for GUID, Text, CreateTime, gold, goldPaper, silver in notifyList:  | 
|         curGUIDItemCount = GameWorld.GetCompensationMgr().FindItemCount(GUID)  | 
|         subPack = ChPyNetSendPack.tagGCCompensationPack()  | 
|         subPack.GUID = GUID  | 
|         subPack.CreateTime = CreateTime  | 
|         subPack.Text = Text  | 
|         subPack.TextLen = len(Text)  | 
|         subPack.Gold = gold  | 
|         subPack.GoldPaper = goldPaper  | 
|         subPack.Silver = silver   | 
|         subPack.IsRead = GameWorld.GetCompensationMgr().FindPlayerRecState(curPlayer.GetPlayerID(), GUID)/10  | 
|         for index in xrange(curGUIDItemCount):  | 
|             curItem = GameWorld.GetCompensationMgr().FindItemAt(GUID, index)  | 
|             subPackItem = ChPyNetSendPack.tagGCCompensationItem()  | 
|             subPackItem.ItemID = curItem.ItemID  | 
|             subPackItem.Count = curItem.Count  | 
|             subPackItem.IsBind = curItem.IsBind  | 
|             subPackItem.UserData = curItem.UserData  | 
|             subPackItem.UserDataLen = len(curItem.UserData)  | 
|             subPack.Items.append(subPackItem)  | 
|         subPack.Count = len(subPack.Items)  | 
|         sendPack.PackList.append(subPack)  | 
|     sendPack.Count = len(sendPack.PackList)  | 
|     NetPackCommon.SendFakePack(curPlayer, sendPack)  | 
|     return  | 
|   | 
| ##03 03 Íæ¼ÒÇëÇóÁìÈ¡²¹³¥#tagMGRequestCompensation  | 
| #  @param routeIndex, mapID, curPackData, tick  | 
| #  @return None  | 
| def OnMGRequestCompensation(routeIndex, mapID, curPackData, tick):  | 
|     global g_PlayerRequestStateDict  | 
|     GameWorld.DebugLog("Compensation### OnMGRequestCompensation in")  | 
|     myPlayerID = curPackData.PlayerID      | 
|     curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(myPlayerID)  | 
|     if not curPlayer:  | 
|         return  | 
|     if curPlayer.GetDictByKey(Def_RequestState):#УÑéËø  | 
|         GameWorld.DebugLog("Compensation### already request")  | 
|         return  | 
|       | 
|     curPlayer.SetDict(Def_RequestState, 1)#¼ÓËø  | 
|       | 
|     GUID = curPackData.GUID  | 
|     GameWorld.DebugLog("Compensation### OnMGRequestCompensation myPlayerID %s GUID %s"%(myPlayerID, GUID))  | 
|       | 
|     compensationType, curEntireRequire = CheckRequestCompensation(curPlayer, GUID)   | 
|     if compensationType == Unknow_CompensationType:  | 
|         #Áìȡʧ°Ü  | 
|         curPlayer.SetDict(Def_RequestState, 0)#½âËø  | 
|         GameWorld.DebugLog("Compensation### OnMGRequestCompensation no found")  | 
|         return  | 
|     Text, gold, goldPaper, silver = curEntireRequire.Text, curEntireRequire.Gold, curEntireRequire.GoldPaper, curEntireRequire.Silver  | 
|     #УÑé±³°üÊ£Óà¿Õ¼äÊÇ·ñ×ã¹»  | 
|     #===========================================================================  | 
|     # curCUIDItemCount = GameWorld.GetCompensationMgr().FindItemCount(GUID)  | 
|     # if curPackData.PackSpaceCount < curCUIDItemCount:  | 
|     #    curPlayer.SetDict(Def_RequestState, 0)#½âËø  | 
|     #    GameWorld.DebugLog("Compensation### OnMGRequestCompensation no enough space")  | 
|     #    return  | 
|     #===========================================================================  | 
|     #·¢Ë͵½MapServer¸øÓè½±Àø  | 
|     SendGMRequestCompensationResult(routeIndex, mapID, curPlayer, GUID, compensationType, Text, gold, goldPaper, silver)  | 
|     GameWorld.DebugLog("Compensation### OnMGRequestCompensation out")  | 
|       | 
| ##ÇëÇóÁìÈ¡ÎïÆ·  | 
| #  @param curPlayer, GUID   | 
| #  @return CompensationType ²¹³¥ÀàÐÍ  | 
| def CheckRequestCompensation(curPlayer, GUID, isPersonnal = True):  | 
|     curPlayerID = curPlayer.GetID()  | 
|       | 
|     if isPersonnal:  | 
|         #ÔÚ¸öÈ˲¹³¥ÖÐ  | 
|         curPersonalCompensation = GameWorld.GetCompensationMgr().FindPersonalCompensation(curPlayerID, GUID)  | 
|         if curPersonalCompensation.PlayerID == curPlayerID:  | 
|             #·µ»Ø²¹³¥ÀàÐÍ  | 
|             return Personal_CompensationType, curPersonalCompensation  | 
|           | 
|     #---------  | 
|     #ÔÚÈ«·þ²¹³¥ÖÐ  | 
|     states = GameWorld.GetCompensationMgr().FindPlayerRecState(curPlayerID, GUID)  | 
|     readState = states/10    # ¿É¶Á         | 
|     curState = states%10    # Áìȡ״̬  | 
|       | 
|     if curState in (Disable_State, Yet_State):  | 
|         #²»¿ÉÁì »ò ÒÑÁì  | 
|         return Unknow_CompensationType, None  | 
|     curEntireRequire = GameWorld.GetCompensationMgr().FindEntireCompensation(GUID)  | 
|     if curEntireRequire.GUID != GUID:  | 
|         #²»ÔÙÈ«·þ²¹³¥ÖУ¬É¾³ý¼Ç¼  | 
|         GameWorld.GetCompensationMgr().DeletePlayerCompensationRec(curPlayerID, GUID)  | 
|         return Unknow_CompensationType, None  | 
|       | 
|     checkState, limitLVType, limitLV = ParseEntireCompensationInfo(curEntireRequire.PlayerLV)  | 
|     if checkState == CheckState_No:  | 
|         isTestAccID = GameWorld.GetPlatformAccID(curPlayer.GetAccID()) in ReadChConfig.GetEvalChConfig("TestAccID")  | 
|         if not isTestAccID:  | 
|             #δÉóºËµÄÓʼþ²»´¦Àí  | 
|             return Unknow_CompensationType, None  | 
|           | 
|     #δ֪ͨ¹ý£¬ÇÒÒѳ¬Ê±  | 
|     limitTime = datetime.datetime.strptime(curEntireRequire.LimitTime, ChConfig.TYPE_Time_Format)  | 
|     curTime = datetime.datetime.today()  | 
|     if limitTime < curTime and Unknown_State == curState:  | 
|         #³¬Ê±£¬ÉèÖóɲ»¿ÉÁìÈ¡  | 
|         SetPrizeState(curPlayerID, GUID, Disable_State, readState)  | 
|         return Unknow_CompensationType, None  | 
|   | 
|     if Enable_State == curState:  | 
|         #¿ÉÁìÈ¡ÇÒδ³¬Ê±£¬·µ»ØÎïÆ·ÐÅÏ¢  | 
|         return Entire_CompensationType, curEntireRequire  | 
|       | 
|     curLV = curPlayer.GetLV()  | 
|     if limitLV > curLV:  | 
|         #µÈ¼¶²»×ã  | 
|         if limitLVType == LimitLVType_Not:  | 
|             SetPrizeState(curPlayerID, GUID, Disable_State, readState)  | 
|         return Unknow_CompensationType, None  | 
|     curJob = curPlayer.GetJob()  | 
|     if curEntireRequire.PlayerJob not in (-1, 127):  | 
|         #ÓÐÖ°ÒµÏÞÖÆ  | 
|         if (curEntireRequire.PlayerJob&pow(2,curJob)) == 0:  | 
|             SetPrizeState(curPlayerID, GUID, Disable_State, readState)  | 
|             return Unknow_CompensationType, None  | 
|           | 
|     #¿ÉÒÔÓõĽ±Àø  | 
|     SetPrizeState(curPlayerID, GUID, Enable_State, readState)  | 
|     #·µ»ØÎïÆ·ÐÅÏ¢     | 
|     return Entire_CompensationType, curEntireRequire  | 
|   | 
| ##·¢ËÍ·â°ü 03 02 Íæ¼ÒÁìÈ¡²¹³¥½á¹û#tagGMRequestCompensationResult  | 
| #  @param routeIndex, mapID, curPlayer, curItem  | 
| #  @return None  | 
| def SendGMRequestCompensationResult(routeIndex, mapID, curPlayer, GUID, compensationType, Text,  | 
|                                     gold, goldPaper, silver):  | 
|     sendPack = ChGameToMapPyPack.tagGMRequestCompensationResult()   | 
|     sendPack.PlayerID = curPlayer.GetID()  | 
|     sendPack.CompensationType = compensationType  | 
|     sendPack.GUID = GUID  | 
|     sendPack.Text = Text  | 
|     sendPack.TextLen = len(Text)  | 
|     sendPack.Gold = gold  | 
|     sendPack.GoldPaper = goldPaper  | 
|     sendPack.Silver = silver  | 
|     curGUIDItemCount = GameWorld.GetCompensationMgr().FindItemCount(GUID)  | 
|       | 
|     for i in xrange(curGUIDItemCount):  | 
|         curItem = GameWorld.GetCompensationMgr().FindItemAt(GUID, i)  | 
|         subPackItem = ChGameToMapPyPack.tagGMCompensationItem()  | 
|         subPackItem.ItemID = curItem.ItemID  | 
|         subPackItem.Count = curItem.Count  | 
|         subPackItem.IsBind = curItem.IsBind  | 
|         subPackItem.UserData = curItem.UserData  | 
|         subPackItem.UserDataLen = len(curItem.UserData)  | 
|         sendPack.Items.append(subPackItem)  | 
|     sendPack.Count = len(sendPack.Items)  | 
|     NetPackCommon.SendPyPackToMapServer(routeIndex, mapID, sendPack)   | 
|     return  | 
|   | 
|   | 
| ##03 04 Íæ¼ÒÁìÈ¡²¹³¥ÎïÆ··¢·Å½á¹û#tagMGGiveCompensationResult  | 
| #  @param routeIndex, mapID, curPackData, tick  | 
| #  @return None  | 
| def OnMGGiveCompensationResult(routeIndex, mapID, curPackData, tick):  | 
|       | 
|     myPlayerID = curPackData.PlayerID  | 
|     curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(myPlayerID)  | 
|     if not curPlayer:  | 
|         return  | 
|     GUID = curPackData.GUID  | 
|     CompensationType = curPackData.CompensationType  | 
|     curPlayer.SetDict(Def_RequestState, 0)#½âËø  | 
|     if curPackData.Result:  | 
|         GiveCompensationSuccess(curPlayer, GUID, CompensationType)  | 
|     return  | 
|   | 
|   | 
|   | 
| ##Íæ¼ÒÁìÈ¡²¹³¥ÎïÆ··¢·Å³É¹¦  | 
| #  @param curPlayer, GUID  | 
| #  @return None  | 
| def GiveCompensationSuccess(curPlayer, GUID, CompensationType):  | 
|     curPlayerID = curPlayer.GetID()  | 
|     NotifyCompensationResult(curPlayer, GUID, 1)  | 
|       | 
|     #Á÷Ïò¼Ç¼  | 
|     DataRecordPack.DR_GiveCompensationSuccess(curPlayerID, GUID)  | 
|     #È«·þ½±ÀøÁìÈ¡¼Ç¼±ä¸üΪÒÑÁìÈ¡  | 
|     if CompensationType == Entire_CompensationType:  | 
|         GameWorld.GetCompensationMgr().AddPlayerRec(curPlayerID, GUID, 10 + Yet_State)  | 
|         return  | 
|     #¸öÈ˽±ÀøÁìÈ¡ÌõĿִÐÐɾ³ý  | 
|     if CompensationType == Personal_CompensationType:  | 
|         ClearPersonalCompensation(curPlayerID, GUID)  | 
|         return  | 
|       | 
|     return  | 
|   | 
| ##ÇåÀí³¬Ê±È«·þ²¹³¥, È«·þÓʼþ·ÖÁ½²¿´¦Àí£º1. Óʼþ½ÓÊÕµÄÓÐЧʱ¼ä£¬ºǫ́ÉèÖã¬2. Óʼþɾ³ýʱ¼äΪ½ÓÊÕÓÐЧʱ¼äÔÙÑÓ³¤30Ìì  | 
| #  @param None  | 
| #  @return None  | 
| def ClearUpEntireCompensation():  | 
|     #УÑé¹ýÆÚ²¹³¥  | 
|     curTime = datetime.datetime.today()  | 
|     needClearGUIDList = []  | 
|     entireCnt = GameWorld.GetCompensationMgr().GetEntireCompensationCount()  | 
|     for i in xrange(entireCnt):  | 
|         curEntireRequire = GameWorld.GetCompensationMgr().AtEntireCompensation(i)  | 
|         # ³¬¹ý½ÓÊÕÓʼþ30ÌìÔòÍêȫɾ³ý´ËÓʼþ  | 
|         limitTime = datetime.datetime.strptime(curEntireRequire.LimitTime, ChConfig.TYPE_Time_Format) + datetime.timedelta(days = 30)  | 
|         if limitTime < curTime:  | 
|             needClearGUIDList.append(curEntireRequire.GUID)  | 
|               | 
|     #ɾ³ý¹ýÆÚ²¹³¥ÐÅÏ¢£¬ Ã»ÓÐÖ÷¶¯Í¨ÖªÔÚÏßÍæ¼Ò  | 
|     for GUID in needClearGUIDList:  | 
|         #ɾ³ýÁìÈ¡Ìõ¼þ  | 
|         GameWorld.GetCompensationMgr().DeleteEntireCompensation(GUID)  | 
|         #ɾ³ý¹ýÆÚÎïÆ·  | 
|         GameWorld.GetCompensationMgr().DeleteCompensationItem(GUID)  | 
|         #Çå³ýÁìȡ״̬¼Ç¼¾Í  | 
|         GameWorld.GetCompensationMgr().DeleteRecByGUID(GUID)  | 
|     return  | 
|   | 
|   | 
| ## ÇåÀí³¬Ê±²¹³¥, ¸öÈËÓʼþÔÚ³¬¹ýÉÏÏÞºó²Å»á×Ô¶¯É¾³ý  | 
| #  @param None  | 
| #  @return None  | 
| def ClearUpTimeOutCompensation():  | 
|       | 
|     ClearUpEntireCompensation()  | 
|     return  | 
|   | 
|   | 
| #===============================================================================  | 
| # //A9 A6 ÉèÖÃÓʼþ£¨²¹³¥£©ÒѶÁ״̬ #tagCGReadCompensation  | 
| #   | 
| # struct    tagCGReadCompensation  | 
| # {  | 
| #    tagHead        Head;  | 
| #    char        GUID[40];  | 
| #    BYTE        IsRead;        //ÉèÖÃÓʼþ£¨²¹³¥£©ÊÇ·ñÒѶÁ 1¶ÁÈ¡  | 
| # };  | 
| #===============================================================================  | 
| def OnReadCompensation(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|       | 
|     GUID = clientData.GUID  | 
|     curPlayerID = curPlayer.GetID()  | 
|       | 
|     #ÔÚ¸öÈ˲¹³¥ÖÐ  | 
|     curPersonalCompensation = GameWorld.GetCompensationMgr().FindPersonalCompensation(curPlayerID, GUID)  | 
|     if curPersonalCompensation.PlayerID != curPlayerID:  | 
|         curEntireRequire = GameWorld.GetCompensationMgr().FindEntireCompensation(GUID)  | 
|         if curEntireRequire.GUID != GUID:  | 
|             #GameWorld.DebugLog("ÕÒ²»µ½ÓʼþGUID:%s"%GUID)  | 
|             # ÕÒ²»µ½Óʼþ  | 
|             return  | 
|     curState = GameWorld.GetCompensationMgr().FindPlayerRecState(curPlayerID, GUID)  | 
|     if curState/10 >= Read_State_Yes:  | 
|         # ÒѶÁ  | 
|         #GameWorld.DebugLog("ÒѶÁGUID:%s"%GUID)  | 
|         return  | 
|     curState = Read_State_Yes*10 + curState%10  | 
|     GameWorld.GetCompensationMgr().AddPlayerRec(curPlayerID, GUID, curState)  | 
|     #GameWorld.DebugLog("ÒѶÁcurState:%s"%curState)  | 
|     return  | 
|   | 
| #===============================================================================  | 
| # //A9 A7 É¾³ýÓʼþ£¨²¹³¥£© #tagCGDelCompensation  | 
| #   | 
| # struct    tagCGDelCompensation  | 
| # {  | 
| #    tagHead        Head;  | 
| #    char        GUID[40];  | 
| # };  | 
| #===============================================================================  | 
| def OnDelCompensation(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     GUID = clientData.GUID  | 
|     curPlayerID = curPlayer.GetID()  | 
|       | 
|     #ÔÚ¸öÈ˲¹³¥ÖÐ  | 
|     curPersonalCompensation = GameWorld.GetCompensationMgr().FindPersonalCompensation(curPlayerID, GUID)  | 
|     if curPersonalCompensation.PlayerID == curPlayerID:  | 
|         ClearPersonalCompensation(curPlayerID, GUID)  | 
|         NotifyCompensationResult(curPlayer, GUID, 1)  | 
|         #GameWorld.DebugLog("¸öÈ˲¹³¥ÖÐOnDelCompensation:%s"%GUID)  | 
|         return  | 
|       | 
|     curEntireRequire = GameWorld.GetCompensationMgr().FindEntireCompensation(GUID)  | 
|     if curEntireRequire.GUID != GUID:  | 
|         # ÕÒ²»µ½Óʼþ  | 
|         NotifyCompensationResult(curPlayer, GUID, 0)  | 
|         #GameWorld.DebugLog("ÕÒ²»µ½ÓʼþOnDelCompensation:%s"%GUID)  | 
|         return  | 
|       | 
|     #È«·þÓʼþ  | 
|     curEntireRequire = GameWorld.GetCompensationMgr().FindEntireCompensation(GUID)  | 
|     if curEntireRequire.GUID == GUID:  | 
|         SetPrizeState(curPlayerID, GUID, Disable_State, GameWorld.GetCompensationMgr().FindPlayerRecState(curPlayerID, GUID)/10)  | 
|         NotifyCompensationResult(curPlayer, GUID, 1)  | 
|         #GameWorld.DebugLog("È«·þÓʼþOnDelCompensation:%s"%GUID)  | 
|         return  | 
|   | 
|     NotifyCompensationResult(curPlayer, GUID, 0)  | 
|           | 
| # Óʼþɾ³ýÇé¿ö     | 
| def NotifyCompensationResult(curPlayer, GUID, result):      | 
|     sendMCPack = ChPyNetSendPack.tagGCDelCompensationResult()  | 
|     sendMCPack.GUID = GUID  | 
|     sendMCPack.Result = result  | 
|     NetPackCommon.SendFakePack(curPlayer, sendMCPack)  | 
|       | 
|      |