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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @todo: CTGReportAll 充值分析报告所有汇总
 
import CommFunc
import ConfigParser
 
import logging
import mylog
import json
 
# ==================== 配置 ====================
cfg = ConfigParser.ConfigParser()
cfg.read("../../InterfaceConfig.php")
ServerPath = cfg.get("ServerInfo", "ServerPath")
# 需要处理的流向名及顺序列表
DRNameList = ["CTGOK"]
# ==================== 配置 ====================
 
 
def getCTGReportInfo(argvDict):
    logging.info("getCTGReportInfo %s" % argvDict)
    startDate = argvDict.get("startDate", "")
    endDate = argvDict.get("endDate", "")
    payOrderTypeGroup = argvDict.get("payOrderTypeGroup", "")
 
    CTGReportOrderTypeList = eval(CommFunc.getSPConfig(
        argvDict, "Config", "CTGReportOrderType", "[1]"))
 
    reportInfo = {} # {key:{orderInfo:{k:v, ...}, ...}, ...}
    # 查询中心备份的
    if CommFunc.isQueryCenterbak(argvDict):
        queryCenterBak(startDate, endDate, argvDict, CTGReportOrderTypeList)
        return
 
    needQueryCenterbak = CommFunc.loopMainServerDR(cfg, startDate, endDate, argvDict, checkDrFileNeedParseFunc,
                                                   parseLineFunc, reportInfo, CTGReportOrderTypeList, payOrderTypeGroup, drNameList=DRNameList)
 
    # logging.info("1 reportInfo %s" % reportInfo)
    logging.info("needQueryCenterbak %s" % needQueryCenterbak)
    if needQueryCenterbak:
        retBak = CommFunc.queryBackupCenterDR(cfg, argvDict)
        if retBak == None:
            return
        reportInfoBak = retBak[0]
        # logging.info("reportInfoBak %s" % reportInfoBak)
        for key, orderInfoDictBak in reportInfoBak.items():
            if key not in reportInfo:
                reportInfo[key] = orderInfoDictBak
                continue
            orderInfoDict = reportInfo[key]
            for orderInfo, bakData in orderInfoDictBak.items():
                orderInfo = str(orderInfo)
                if orderInfo not in orderInfoDict:
                    orderInfoDict[orderInfo] = bakData
                else:
                    retData = orderInfoDict[orderInfo]
                    for k, v in bakData.items():
                        if k == "orderCoin":
                            continue;
                        retData[k] = retData.get(k, 0) + v
    # logging.info("2 reportInfo %s" % reportInfo)
    ret = {"OK": 1, "reportInfo": reportInfo}
    print json.dumps(ret, ensure_ascii=False, default=lambda obj: obj.__dict__)
    return
 
 
def queryCenterBak(startDate, endDate, argvDict, CTGReportOrderTypeList):
    # 查询中心服务器备份充值信息
    reportInfoBak = {}
    payOrderTypeGroup = argvDict.get("payOrderTypeGroup", "")
    if not CommFunc.loopCenterbakRarDR(cfg, startDate, endDate, argvDict, checkDrFileNeedParseFunc,
                                       parseLineFunc, reportInfoBak, CTGReportOrderTypeList, payOrderTypeGroup, drNameList=DRNameList):
        return
    return CommFunc.queryBackupCenterOK([reportInfoBak])
 
 
def checkDrFileNeedParseFunc(drFileName, *parseArgs, **kv):
    ''' 检查流向是否需要处理
    @param drFileName: 流向文件名  xxx_日期.txt
    @param *parseArgs: 自定义参数
    @return: isNeed, checkNeedParseRetInfo
    '''
    # 因为指定了 drNameList , 所以默认返回True
    return True, None
 
 
def parseLineFunc(drName, dateStr, checkNeedParseRetInfo, line, *parseArgs, **kv):
    ''' 解析流向行内容
    @param drName: 流向名
    @param dateStr: 对应日期字符串
    @param checkNeedParseRetInfo: checkDrFileNeedParseFunc 返回的内容
    @param line: 本行内容
    @param *parseArgs: 自定义参数
    '''
 
    reportInfo, CTGReportOrderTypeList, payOrderTypeGroup = parseArgs
 
    drDict = eval(line)
 
    payOrderType = drDict.get("payOrderType", 1)
    if payOrderType not in CTGReportOrderTypeList:
        return
 
    if "orderInfo" not in drDict:
        return
 
    orderInfo = drDict["orderInfo"]
    orderCoin = drDict.get("orderCoin", 0)
    key = str(payOrderType) if payOrderTypeGroup else ""
    if key not in reportInfo:
        reportInfo[key] = {}
    orderInfoDict = reportInfo[key]
    if orderInfo not in orderInfoDict:
        orderInfoDict[orderInfo] = {}
    retData = orderInfoDict[orderInfo]
    retData["orderCoin"] = orderCoin
    retData["payCount"] = retData.get("payCount", 0) + 1
    payOrderTypeKey = "payOrderType%s" % payOrderType
    retData[payOrderTypeKey] = retData.get(payOrderTypeKey, 0) + 1
    return
 
# =================================================================================================
 
 
def main():
    CommFunc.setdefaultencoding()
    argvDict = CommFunc.parse_args()
    mylog.InitMyLog(argvDict.get("eventType", ""))
    CommFunc.gettextInstall(argvDict.get("lang", ""))
    getCTGReportInfo(argvDict)
    return
 
 
if __name__ == "__main__":
    try:
        main()
    except:
        CommFunc.printExceptionError()