| #!/usr/bin/python | 
| # -*- coding: utf-8 -*- | 
| # @todo: 个人邮件查询 | 
|   | 
| import CommFunc | 
| import ConfigParser | 
| import DBOperate | 
|   | 
| import logging | 
| import mylog | 
|   | 
| cfg = ConfigParser.ConfigParser() | 
| cfg.read("../../InterfaceConfig.php") | 
| ServerPath = cfg.get("ServerInfo", "ServerPath") | 
|   | 
| def queryPlayerMailDRInfo(argvDict): | 
|     ## 查询玩家邮件信息 | 
|      | 
|     startDate = argvDict.get("startDate", "") | 
|     endDate = argvDict.get("endDate", "") | 
|      | 
|     queryTempInfo = argvDict.get("queryTempInfo", "") | 
|     queryTempList = queryTempInfo.split(",") if queryTempInfo != "" else [] | 
|      | 
|     filterInfo = argvDict.get("filterInfo", "") | 
|     filterList = filterInfo.split(",") if filterInfo != "" else [] | 
|      | 
|     # 查询中心备份的 | 
|     if CommFunc.isQueryCenterbak(argvDict): | 
|         # 备份数据默认不看拍卖相关邮件 | 
|         if "Paimai" not in filterList: | 
|             filterList.append("Paimai") | 
|         queryPlayerMailDRInfo_Centerbak(startDate, endDate, argvDict, queryTempList, filterList) | 
|         return | 
|      | 
|     playerFind = argvDict.get("playerFind", "") | 
|     if not playerFind: | 
|         print _(u"需要指定要查询的玩家") | 
|         return | 
|      | 
|     queryType = argvDict.get("queryType", "") | 
|      | 
|     dboper = DBOperate.DBOper(ServerPath) | 
|     if queryType == "playerName": | 
|         findDBRet = dboper.findPlayerInfoByName([playerFind]) | 
|     else: | 
|         findDBRet = dboper.findPlayerInfoByAccID([playerFind]) | 
|     dboper.close() | 
|     if not findDBRet or findDBRet.count() == 0: | 
|         print _(u"找不到该玩家") + "!<br/>%s<br/>" % playerFind | 
|         return | 
|      | 
|     dbPlayer = findDBRet[0] | 
|     playerID = CommFunc.encode(dbPlayer["PlayerID"]) | 
|     queryAccID = CommFunc.encode(dbPlayer["AccID"]) | 
|     playerName = CommFunc.encode(dbPlayer["PlayerName"]) | 
|      | 
|     drList = [] | 
|     giveSuccessDict = {} | 
|     delGUIDDict = {} | 
|     needQueryCenterbak = CommFunc.loopMainServerDR(cfg, startDate, endDate, argvDict, checkDrFileNeedParseFunc_MailSend, | 
|                                                    parseLineFunc_MailSend, drList, playerID, queryTempList, filterList, drNameList=["CompensationPersonal", "CompensationEntire"]) | 
|     # 领取的不限制结束日期 | 
|     CommFunc.loopMainServerDR(cfg, startDate, "", argvDict, checkDrFileNeedParseFunc_MailGiveSuccess, | 
|                               parseLineFunc_MailGiveSuccess, giveSuccessDict, playerID, drNameList=["CompensationGiveSuccess"]) | 
|     CommFunc.loopMainServerDR(cfg, startDate, "", argvDict, checkDrFileNeedParseFunc_MailDel, | 
|                               parseLineFunc_MailDel, delGUIDDict, playerID, drNameList=["CompensationPersonalDel"]) | 
|      | 
|     if needQueryCenterbak: | 
|         argvDict["playerID"] = playerID | 
|         bakDataList = CommFunc.queryBackupCenterDR(cfg, argvDict) | 
|         if bakDataList == None: | 
|             return | 
|         drList = bakDataList[0] + drList | 
|         giveSuccessDict.update(bakDataList[1]) | 
|         delGUIDDict.update(bakDataList[2]) | 
|          | 
|     # 更新邮件标题、领取时间 | 
|     tempTitleDict = CommFunc.getCfgKeyNameDict("mail", argvDict) | 
|     itemNameDict = CommFunc.getCfgKeyNameDict("item", argvDict) | 
|     for mailInfo in drList: | 
|         tempType = mailInfo["Title"] | 
|         mailInfo["Title"] = tempTitleDict.get(tempType, tempType) | 
|         # 全服邮件 | 
|         if "PlayerIDList" not in mailInfo: | 
|             mailInfo["Title"] = "%s%s" % (CommFunc.encode(mailInfo["Title"]), "<font color='red'>[" + _(u"全服") + "]</font>") | 
|              | 
|         itemInfoStr = "" | 
|         for itemInfo in mailInfo["ItemList"]: | 
|             if itemInfoStr: | 
|                 itemInfoStr += "<br/>" | 
|             itemID = itemInfo["ItemID"] | 
|             count = itemInfo["Count"] | 
|             itemName = itemNameDict.get(str(itemID), "") | 
|             if itemName: | 
|                 itemInfoStr += "%s(%s) x%s%s" % (itemName, itemID, count, _(u"个")) | 
|             else: | 
|                 itemInfoStr += "<font color='red'>%s(%s) x%s个</font>" % (_(u"未知物品ID"), itemID, count)                 | 
|             if itemInfo.get("IsAuctionItem"): | 
|                 itemInfoStr += "(%s)" % _(u"拍品") | 
|         mailInfo["ItemInfo"] = itemInfoStr | 
|          | 
|         GUID = mailInfo["GUID"] | 
|         if GUID in giveSuccessDict: | 
|             mailInfo["giveTime"] = giveSuccessDict[GUID] | 
|         elif GUID in delGUIDDict: | 
|             delTime, delEventName = delGUIDDict[GUID] | 
|             delTime, delEventName = str(delTime), str(delEventName) | 
|             if delEventName == "GMT": | 
|                 delEventName = _(u"后台") | 
|             elif delEventName == "MaxCountLimiit": | 
|                 delEventName = _(u"邮件上限") | 
|             elif delEventName == "Timeout": | 
|                 delEventName = _(u"过期") | 
|             elif delEventName == "ClientDel": | 
|                 delEventName = _(u"玩家删除") | 
|             mailInfo["giveTime"] = "%s <br/> <font color='red'>%s: %s</font>" % (delTime, _(u"被删除"), delEventName)         | 
|              | 
|     printStr = "<center><p>%s</p></center>" % _(u"个人邮件记录") | 
|     printStr += _(u"玩家ID") + ": %s<br/>" % playerID | 
|     printStr += _(u"玩家账号") + ": %s<br/>" % queryAccID | 
|     printStr += _(u"玩家名称") + ": %s<br/>" % playerName | 
|      | 
|     if startDate: | 
|         printStr += _(u"开始日期") + ": %s<br/>" % startDate | 
|     if endDate: | 
|         printStr += _(u"结束日期") + ": %s<br/>" % endDate | 
|          | 
|     # 表格输出 | 
|     printStr += CommFunc.editTableHtml(drList, ["Title", "ItemInfo", "Gold", "GoldPaper", "Silver", "time", "giveTime", "GUID"], _(u"编号"), | 
|                                        styleInfo={"Title":{"align":"left", "title":_(u"标题")}, | 
|                                                   "ItemInfo":{"align":"left", "title":_(u"物品")}, | 
|                                                   "Gold":{"title":_(u"仙玉")}, | 
|                                                   "GoldPaper":{"title":_(u"灵玉")}, | 
|                                                   "Silver":{"title":_(u"铜钱")}, | 
|                                                   "time":{"title":_(u"发送时间")}, | 
|                                                   "giveTime":{"title":_(u"领取时间")}, | 
|                                                   }) | 
|      | 
|     # 只会返回最后一个print的内容 | 
|     print printStr | 
|     return | 
|   | 
| def queryPlayerMailDRInfo_Centerbak(startDate, endDate, argvDict, queryTempList, filterList): | 
|      | 
|     drList = [] | 
|     giveSuccessDict = {} | 
|     delGUIDDict = {} | 
|     playerID = CommFunc.toInt(argvDict.get("playerID", "0")) | 
|      | 
|     if not CommFunc.loopCenterbakRarDR(cfg, startDate, endDate, argvDict, checkDrFileNeedParseFunc_MailSend, | 
|                                        parseLineFunc_MailSend, drList, playerID, queryTempList, filterList, drNameList=["CompensationPersonal", "CompensationEntire"]): | 
|         return | 
|      | 
|     if not CommFunc.loopCenterbakRarDR(cfg, startDate, "", argvDict, checkDrFileNeedParseFunc_MailGiveSuccess, | 
|                                        parseLineFunc_MailGiveSuccess, giveSuccessDict, playerID, drNameList=["CompensationGiveSuccess"]): | 
|         return | 
|      | 
|     if not CommFunc.loopCenterbakRarDR(cfg, startDate, "", argvDict, checkDrFileNeedParseFunc_MailDel, | 
|                                        parseLineFunc_MailDel, delGUIDDict, playerID, drNameList=["CompensationPersonalDel"]): | 
|         return | 
|      | 
|     return CommFunc.queryBackupCenterOK([drList, giveSuccessDict, delGUIDDict]) | 
|   | 
| def checkDrFileNeedParseFunc_MailSend(drFileName, *parseArgs, **kv): | 
|     ''' 检查流向是否需要处理 | 
|     @param drFileName: 流向文件名  xxx_日期.txt | 
|     @param *parseArgs: 自定义参数 | 
|     @return: isNeed, checkNeedParseRetInfo | 
|     ''' | 
|     isNeed = drFileName.startswith("CompensationPersonal_") or drFileName.startswith("CompensationEntire_") | 
|     return isNeed, None | 
|   | 
| def parseLineFunc_MailSend(drName, dateStr, checkNeedParseRetInfo, line, *parseArgs, **kv): | 
|     ''' 解析流向行内容 | 
|     @param drName: 流向名 | 
|     @param dateStr: 对应日期字符串 | 
|     @param checkNeedParseRetInfo: checkDrFileNeedParseFunc 返回的内容 | 
|     @param line: 本行内容 | 
|     @param *parseArgs: 自定义参数 | 
|     ''' | 
|      | 
|     drList, playerID, queryTempList, filterList = parseArgs | 
|      | 
|     if "Text" not in line: | 
|         return | 
|      | 
|     if drName == "CompensationEntire": | 
|         if "Add" not in line and "CheckOK" not in line: | 
|             return | 
|          | 
|     else: | 
|         if str(playerID) not in line: | 
|             return | 
|          | 
|     # 减少eval,上面的简单验证,eval后还是要进行严格验证 | 
|     drDict = eval(line) | 
|     Text = drDict["Text"] | 
|      | 
|     if drName == "CompensationEntire": | 
|         if drDict["eventName"] not in ["Add", "CheckOK"]: | 
|             return | 
|          | 
|     else: | 
|         if playerID not in drDict["PlayerIDList"]: | 
|             return | 
|          | 
|         # 是否指定查找 | 
|         isQuery = False | 
|         for queryTemp in queryTempList: | 
|             if queryTemp in Text: | 
|                 isQuery = True | 
|                 break | 
|              | 
|         if not isQuery: | 
|             # 是否过滤掉的 | 
|             isFilter = False | 
|             for filterStr in filterList: | 
|                 if filterStr in Text: | 
|                     isFilter = True | 
|                     break | 
|             if isFilter: | 
|                 return | 
|          | 
|     contentList = Text.split("<$_$>") | 
|     title = contentList[1] | 
|     content = contentList[2] | 
|     drDict["Title"] = title | 
|     if "</MailTemplate>" in content: | 
|         tempType = content[content.index("<MailTemplate>") + len("<MailTemplate>"):content.index("</MailTemplate>")] | 
|         drDict["Title"] = tempType | 
|          | 
|     drList.append(drDict) | 
|     return | 
|   | 
|   | 
| def checkDrFileNeedParseFunc_MailGiveSuccess(drFileName, *parseArgs, **kv): | 
|     ''' 检查流向是否需要处理 | 
|     @param drFileName: 流向文件名  xxx_日期.txt | 
|     @param *parseArgs: 自定义参数 | 
|     @return: isNeed, checkNeedParseRetInfo | 
|     ''' | 
|     isNeed = drFileName.startswith("CompensationGiveSuccess_") | 
|     return isNeed, None | 
|   | 
| def parseLineFunc_MailGiveSuccess(drName, dateStr, checkNeedParseRetInfo, line, *parseArgs, **kv): | 
|     ''' 解析流向行内容 | 
|     @param drName: 流向名 | 
|     @param dateStr: 对应日期字符串 | 
|     @param checkNeedParseRetInfo: checkDrFileNeedParseFunc 返回的内容 | 
|     @param line: 本行内容 | 
|     @param *parseArgs: 自定义参数 | 
|     ''' | 
|      | 
|     giveSuccessDict, playerID = parseArgs | 
|     if str(playerID) not in line: | 
|         return | 
|     drDict = eval(line) | 
|     if playerID != drDict["PlayerID"]: | 
|         return | 
|     giveSuccessDict[drDict["GUID"]] = drDict["time"] | 
|     return | 
|   | 
| def checkDrFileNeedParseFunc_MailDel(drFileName, *parseArgs, **kv): | 
|     ''' 检查流向是否需要处理 | 
|     @param drFileName: 流向文件名  xxx_日期.txt | 
|     @param *parseArgs: 自定义参数 | 
|     @return: isNeed, checkNeedParseRetInfo | 
|     ''' | 
|     isNeed = drFileName.startswith("CompensationPersonalDel_") | 
|     return isNeed, None | 
|   | 
| def parseLineFunc_MailDel(drName, dateStr, checkNeedParseRetInfo, line, *parseArgs, **kv): | 
|     ''' 解析流向行内容 | 
|     @param drName: 流向名 | 
|     @param dateStr: 对应日期字符串 | 
|     @param checkNeedParseRetInfo: checkDrFileNeedParseFunc 返回的内容 | 
|     @param line: 本行内容 | 
|     @param *parseArgs: 自定义参数 | 
|     ''' | 
|      | 
|     delGUIDDict, playerID = parseArgs | 
|     if str(playerID) not in line: | 
|         return | 
|     drDict = eval(line) | 
|     if playerID != drDict["PlayerID"]: | 
|         return | 
|     delGUIDDict[drDict["GUID"]] = [drDict["time"], drDict["eventName"]] | 
|     return | 
|   | 
| def main(): | 
|     CommFunc.setdefaultencoding() | 
|     argvDict = CommFunc.parse_args() | 
|     mylog.InitMyLog(argvDict.get("eventType", "")) | 
|     CommFunc.gettextInstall(argvDict.get("lang", "")) | 
|     queryPlayerMailDRInfo(argvDict) | 
|     return | 
|   | 
| if __name__ == "__main__": | 
|     try: | 
|         main() | 
|     except: | 
|         CommFunc.printExceptionError() |