hxp
2025-06-04 f4a514d5ac952110da846636ecbb9de951eaf3d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @todo: 区服汇总
 
import CommFunc
import ConfigParser
import CTGOKSort
import mylog
import logging
 
 
#==================== 配置 ====================
cfg = ConfigParser.ConfigParser()
cfg.read("../../InterfaceConfig.php")
ServerPath = cfg.get("ServerInfo", "ServerPath")
# 需要处理的流向名及顺序列表
DRNameList = ["FirstLogin", "CTGOK"]
#==================== 配置 ====================
 
class ValueObj():
    def __init__(self):
        return
    
def getServerSum(argvDict):
    ## 统计所有玩家充值累加
    logging.info("getServerSum %s" % str(argvDict))
    
    startDate = argvDict.get("startDate", "")
    endDate = argvDict.get("endDate", CommFunc.getCurrentDateStr())
    
    serverSumInfo = {}
    
    # 查询中心备份的
    if CommFunc.isQueryCenterbak(argvDict):
        queryCenterBak(startDate, endDate, argvDict)
        return
    
    needQueryCenterbak = CommFunc.loopMainServerDR(cfg, startDate, endDate, argvDict, checkDrFileNeedParseFunc, parseLineFunc,
                                                   serverSumInfo, drNameList=DRNameList)
    logging.info("needQueryCenterbak %s" % needQueryCenterbak)
    if needQueryCenterbak:
        bakDataInfo = CommFunc.queryBackupCenterDR(cfg, argvDict)
        logging.info("queryBackupCenterDR OK")
        if bakDataInfo == None:
            return
        serverSumInfoBak = bakDataInfo
        # 合并数据
        for serverIDStr, serverInfoBak in serverSumInfoBak.items():
            serverID = int(serverIDStr)
            if serverID not in serverSumInfo:
                serverSumInfo[serverID] = serverInfoBak
            else:
                serverInfo = serverSumInfo[serverID]
                serverInfo["FirstLoginTotal"] = serverInfo.get("FirstLoginTotal", 0) + serverInfoBak.get("FirstLoginTotal", 0)
                CTGOKTotalInfo = serverInfo.get("CTGOKTotal", {})
                for payOrderType, orderValue in serverInfoBak.get("CTGOKTotal", {}).items():
                    CTGOKTotalInfo[str(payOrderType)] = CTGOKTotalInfo.get(str(payOrderType), 0) + orderValue
                serverInfo["CTGOKTotal"] = CTGOKTotalInfo
                
    logging.info("query all data OK")
    serverIDList = serverSumInfo.keys()
    serverIDList.sort()
    logging.info("serverIDList %s" % serverIDList)
    
    PayOrderTypeList = eval(CommFunc.getSPConfig(argvDict, "Config", "PayOrderType", "[]"))
    ctgOKTotalTDNameList, tdStyleInfo = [], {}
    for payOrderType in PayOrderTypeList:
        tdName = "CTGOKTotal%s" % payOrderType
        orderTypeName = CommFunc.getPayOrderTypeName(payOrderType)
        ctgOKTotalTDNameList.append(tdName)
        tdStyleInfo[tdName] = {"align":"right", "title":orderTypeName}
        
    dataList = []
    for serverID in serverIDList:
        serverInfo = serverSumInfo[serverID]
        serverInfo["ServerID"] = serverID
        CTGOKTotalInfo = serverInfo.get("CTGOKTotal", {})
        for payOrderType in PayOrderTypeList:
            tdName = "CTGOKTotal%s" % payOrderType
            ctgOKTotal = CTGOKTotalInfo.get(str(payOrderType), 0)
            if payOrderType not in CTGOKSort.PayByMoneyOrderTypeList:
                ctgOKTotal = CommFunc.coinToY(ctgOKTotal, CommFunc.getPayOrderCoinRate(payOrderType))
            serverInfo[tdName] = ctgOKTotal
        dataList.append(serverInfo)
        
    printStr = ""
    #printStr = "<center><p>%s</p></center>" % _(u"区服汇总")
    if startDate:
        printStr += "%s: %s<br/>" % (_(u"开始日期"), startDate)
    if endDate:
        printStr += "%s: %s<br/>" % (_(u"结束日期"), endDate)
        
    # 表格输出
    tdStyleInfo.update({"ServerID":{"title":_(u"区服ID")},
                        "FirstLoginTotal":{"align":"right", "title":_(u"总创角")},
                        })
    printStr += CommFunc.editTableHtml(dataList, ["ServerID", "FirstLoginTotal"] + ctgOKTotalTDNameList, styleInfo=tdStyleInfo)
    
    logging.info("show OK")
    # 只会返回最后一个print的内容
    print printStr
    
def queryCenterBak(startDate, endDate, argvDict):
    serverSumInfoBak = {}
    if not CommFunc.loopCenterbakRarDR(cfg, startDate, endDate, argvDict, checkDrFileNeedParseFunc, parseLineFunc,
                                       serverSumInfoBak, argvDict, drNameList=DRNameList):
        return
    
    return CommFunc.queryBackupCenterOK(serverSumInfoBak)
 
def checkDrFileNeedParseFunc(drFileName, *parseArgs, **kv):
    ''' 检查流向是否需要处理
    @param drFileName: 流向文件名  xxx_日期.txt
    @param *parseArgs: 自定义参数
    @return: isNeed, checkNeedParseRetInfo
    '''
    return True, None
 
def parseLineFunc(drName, dateStr, checkNeedParseRetInfo, line, *parseArgs, **kv):
    ''' 解析流向行内容
    @param drName: 流向名
    @param dateStr: 对应日期字符串
    @param checkNeedParseRetInfo: checkDrFileNeedParseFunc 返回的内容
    @param line: 本行内容
    @param *parseArgs: 自定义参数
    '''
    
    serverSumInfo = parseArgs[0]
    
    drDict = eval(line)
    
    # 首登
    if drName == "FirstLogin":
        accID = drDict["AccID"]
        serverID = CommFunc.getServerID(accID)
        if serverID not in serverSumInfo:
            serverSumInfo[serverID] = {}
        sumInfoDict = serverSumInfo[serverID]
        sumInfoDict["FirstLoginTotal"] = sumInfoDict.get("FirstLoginTotal", 0) + 1
        
    # 统计充值
    elif drName == "CTGOK":
        
        accID = drDict["AccID"]
        payOrderType = drDict.get("payOrderType", CTGOKSort.DefaultOrderType)
        if payOrderType in CTGOKSort.PayByMoneyOrderTypeList:
            orderValue = drDict["orderMoneyValue"]
        else:
            if not CTGOKSort.IsRealCTG(drDict):
                return
            orderValue = drDict["orderCoin"]
            
        serverID = CommFunc.getServerID(accID)
        if serverID not in serverSumInfo:
            serverSumInfo[serverID] = {}
        sumInfoDict = serverSumInfo[serverID]
        if "CTGOKTotal" not in sumInfoDict:
            sumInfoDict["CTGOKTotal"] = {}
        CTGOKTotalInfo = sumInfoDict["CTGOKTotal"]
        CTGOKTotalInfo[str(payOrderType)] = CTGOKTotalInfo.get(str(payOrderType), 0) + orderValue
        
    return
 
 
def main():
    CommFunc.setdefaultencoding()
    argvDict = CommFunc.parse_args()
    mylog.InitMyLog(argvDict.get("eventType", ""))
    CommFunc.gettextInstall(argvDict.get("lang", ""))
    getServerSum(argvDict)
    return
 
if __name__ == "__main__":
    try:
        main()
    except:
        CommFunc.printExceptionError()