| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package GMT_AddPersonalCompensation.py  | 
| #  | 
| # @todo:Ìí¼ÓÈ«·þ²¹³¥  | 
| # @author xmnathan  | 
| # @date 2014-09-29 13:00  | 
| # @version 1.4  | 
| #  | 
| # @change: "2014-10-24 17:30" hxp Ôö¼Ó²¹³¥Áìȡʱ¼äÅжϣ¬ÒѹýÆÚ·µ»ØGM¹¤¾ßʱ¼ä´íÎó  | 
| # @change: "2015-06-19 17:00" hxp ÎÞÎïÆ·¿ÉÌí¼Ó²¹³¥  | 
| # @change: "2015-11-06 20:30" hxp ÎÞÎïÆ·¿ÉÌí¼Ó²¹³¥  | 
| # @change: "2017-04-26 16:30" hxp ÓÅ»¯´úÂ룻װ±¸»ù´¡ÊôÐÔ±ÈÀý¡¢Á¶»¯µÈ¼¶Ö§³Ö£»×°±¸UserdataÐÅÏ¢Ö±½Ó¸´ÖÆÖ§³Ö;  | 
| #  | 
| # ÏêϸÃèÊö: Ìí¼Ó¸öÈ˲¹³¥  | 
| #  | 
| #---------------------------------------------------------------------  | 
| #"""Version = 2015-11-06 20:30"""  | 
| #---------------------------------------------------------------------  | 
|   | 
| #µ¼Èë  | 
| import DataRecordPack  | 
| import PlayerCompensation  | 
| import GameWorld  | 
| import GMCommon  | 
| import uuid  | 
| import ChConfig  | 
| #---------------------------------------------------------------------  | 
|   | 
|   | 
| ## ÇåÀí×Öµä  | 
| #  @param gmCmdDict µ±Ç°Íæ¼Ò  | 
| #  @return None  | 
| def ClearEmptyFromDict(gmCmdDict):  | 
|     keysList = gmCmdDict.keys()[::]  | 
|     for key in keysList:  | 
|         if gmCmdDict[key] == '':  | 
|             gmCmdDict.pop(key)  | 
|             continue  | 
|     return gmCmdDict  | 
|   | 
| ## Ö´ÐÐÂß¼  | 
| #  @param curPlayer µ±Ç°Íæ¼Ò  | 
| #  @param gmCmdDict: ÃüÁî×Öµä  | 
| #  @return None  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def OnExec(orderId, gmCmdDict):  | 
|     strMsg = ""  | 
|     gmCmdDict = ClearEmptyFromDict(gmCmdDict)  | 
|     queryType = gmCmdDict.get(GMCommon.Def_GMKey_QueryType, '')  | 
|     if queryType == GMCommon.Def_GMKey_FamilyID:  | 
|         sendFamilyIDList = []  | 
|         PlayerIDList = []  | 
|         familyIDList = gmCmdDict.get("playerList", "").split(",")  | 
|         GameWorld.Log("·¢ËÍÏÉÃËÓʼþ: familyIDList=%s" % familyIDList)  | 
|         for familyID in familyIDList:  | 
|             familyID = GameWorld.ToIntDef(familyID)  | 
|             familyInfo = {"familyID":familyID}  | 
|             memberIDList = []  | 
|             family = GameWorld.GetFamilyManager().FindFamily(familyID)  | 
|             if not family:  | 
|                 GameWorld.DebugLog("    not family %s" % familyID)  | 
|                 continue  | 
|             for index in range(family.GetCount()):  | 
|                 curMember = family.GetAt(index)  | 
|                 curMemberID = curMember.GetPlayerID()  | 
|                 if curMemberID:  | 
|                     memberIDList.append(curMemberID)  | 
|             PlayerIDList += memberIDList  | 
|             familyInfo["PlayerIDList"] = memberIDList  | 
|             sendFamilyIDList.append(familyInfo)  | 
|         GameWorld.Log("    send FamilyIDList=%s" % sendFamilyIDList)  | 
|         GameWorld.Log("    send PlayerIDList=%s" % PlayerIDList)  | 
|         strMsg = str(sendFamilyIDList)  | 
|     else:  | 
|         PlayerIDList = eval(gmCmdDict.get('PlayerIDList', '[]'))  | 
|     if PlayerIDList == []:  | 
|         GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_ParamErr)  | 
|         return  | 
|       | 
|     LimitTime = gmCmdDict.get('EndTime', '2050-12-13 00:00:00')  | 
|       | 
|     curServerTime = GameWorld.GetCurrentDataTimeStr()  | 
|     # µ±Ç°Ê±¼äÒѾ³¬¹ýÁìȡʱ¼ä  | 
|     if not curServerTime or curServerTime >= LimitTime:  | 
|         GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_InvalidTime)  | 
|         return  | 
|           | 
|     Title = gmCmdDict.get('Title', '')  | 
|     Text = gmCmdDict.get('Text', '')  | 
|     GUID = str(uuid.uuid1())  | 
|       | 
|     gold = int(gmCmdDict.get('Gold', '0'))  | 
|     goldPaper = int(gmCmdDict.get('GoldPaper', '0'))  | 
|     silver = int(gmCmdDict.get('Silver', '0'))   | 
|     sender = gmCmdDict.get('Sender', ChConfig.Def_Mail_SenderSys)  | 
|     detail = gmCmdDict.get('Detail', "")  | 
|       | 
|     #¹¤¾ß·¢¹ýÀ´µÄÎïÆ·Ï±êÒÀ¾Ý 'index,index,...'  ²»Ò»¶¨ÊÇ´Ó0¿ªÊ¼²¢°´Ë³ÐòÁ¬Ðø =_=#  | 
|     intemIndexStrList = []  | 
|     itemNums = gmCmdDict.get('itemNums', '')  | 
|     if itemNums.strip() != '':  | 
|         intemIndexStrList = itemNums.split(',')  | 
|     #Ìí¼ÓÎïÆ·  | 
|     addItemDictList = []  | 
|     for itemIndexStr in intemIndexStrList:  | 
|         addItemDict = GetGMTCompensationItemDict(gmCmdDict, itemIndexStr)  | 
|         if not addItemDict:  | 
|             continue  | 
|         #Ìí¼Óµ½ÎïÆ·ÐÅÏ¢ÁÐ±í  | 
|         addItemDictList.append(addItemDict)  | 
|           | 
|     #if len(addItemDictList) == 0:  | 
|     #    GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_ParamErr)  | 
|     #    return  | 
|     PlayerCompensation.AddPersonalItem(GUID, addItemDictList, PlayerIDList,   | 
|                                        LimitTime, "%s<$_$>%s<$_$>%s"%(sender, Title, Text),  | 
|                                        gold, goldPaper, silver, detail=detail)  | 
|       | 
|     #Ö´Ðгɹ¦  | 
|     GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_Success, strMsg)  | 
|     # Á÷Ïò  | 
|     DataRecordPack.DR_ToolGMOperate(0, '', '', 'GMT_AddPersonalCompensation', str(gmCmdDict))  | 
|     return  | 
|       | 
|       | 
| def GetGMTCompensationItemDict(gmCmdDict, itemIndexStr):  | 
|     addItemDict = {}  | 
|     addItemDict['ItemID'] = GameWorld.ToIntDef(gmCmdDict.get('ItemID%s'%itemIndexStr, '0'))  | 
|     if addItemDict['ItemID'] == 0:  | 
|         return {}  | 
|     addItemDict['Count'] = GameWorld.ToIntDef(gmCmdDict.get('ItemCnt%s'%itemIndexStr, '0'))  | 
|     if addItemDict['Count'] == 0:  | 
|         return {}  | 
|     addItemDict['IsAuctionItem'] = GameWorld.ToIntDef(gmCmdDict.get('IsBind%s'%itemIndexStr, '0'))  | 
|     #Ìí¼ÓUserDataÐÅÏ¢  | 
|     addItemDict['UserData'] = ''  | 
|     UserDataDict = {}  | 
|     #===========================================================================  | 
|     # #È¡ÏûʹÓõȼ¶ÏÞÖÆ  | 
|     # IsCancelUseLV = GameWorld.ToIntDef(gmCmdDict.get('IsCancelUseLV%s'%itemIndexStr, '0'))  | 
|     # if IsCancelUseLV:  | 
|     #    UserDataDict["%s"%ShareDefine.Def_IudetCancelUseLV] = ["%s"%IsCancelUseLV]  | 
|     # #ÎïÆ·À´Ô´,100 Îª²»´¦Àí  | 
|     # source = GameWorld.ToIntDef(gmCmdDict.get('ItemSource%s'%itemIndexStr, '100'))  | 
|     # if source != 100:  | 
|     #    UserDataDict["%s"%ShareDefine.Def_IudetSource] = ["%s"%source]  | 
|     #      | 
|     # #Ì××°¾«Á¶µÈ¼¶  | 
|     # SuiteLV = GameWorld.ToIntDef(gmCmdDict.get('SuiteLV%s'%itemIndexStr, '0'))  | 
|     # if SuiteLV:  | 
|     #    UserDataDict["%s"%ShareDefine.Def_IudetSuiteLV] = ["%s"%SuiteLV]  | 
|     #===========================================================================  | 
|           | 
|     itemUserData = {}  | 
|     #ÆäËûUserdata  | 
|     UserDataEx = eval(gmCmdDict.get('UserDataEx%s'%itemIndexStr, '{}'))  | 
|     if UserDataEx:  | 
|         itemUserData = UserDataEx  | 
|     for key, value in UserDataDict.items():  | 
|         #ÒÔUserDataExÖеÄΪ׼  | 
|         if key in itemUserData:  | 
|             continue  | 
|         itemUserData[key] = value  | 
|           | 
|     if itemUserData:  | 
|         addItemDict['UserData'] = '%s'%itemUserData  | 
|           | 
|     GameWorld.DebugLog("GetGMTCompensationItemDict %s, %s" % (itemIndexStr, addItemDict))  | 
|     return addItemDict  |