saas_add.py
5.58 KB
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
import logging
import pandas as pdas
from djcardrenewal.common.dbase.MysqlHelper import MysqlHelper
from djcardrenewal.common.dbase import DbConect
from djcardrenewal.common.sqlcontent import DjSql
from djcardrenewal.common.sqlcontent import CurMonthYzl
from djcardrenewal.common.string.StringBuilder import StringBuilder
print("sys config " + __name__)
log_name = './log/djcardrenewal/handlemain.log'
log_format = '[%(asctime)s-%(filename)s-%(levelname)s:%(message)s]'
log_level = logging.DEBUG
log_mode = 'a'
logging.basicConfig(filename=log_name, format=log_format, level=log_level, filemode=log_mode)
class HandelMain:
handleDescription = ''
handleMonth = ''
hmonth = ''
djdb = None
plusDb = None
yearArray = ['2020','2021','2022']
def __init__(self, handle_month):
logging.info("init construct bean")
self.handleDescription = "dj renewal match iccid and device location"
self.handleMonth = handle_month
self.hmonth = handle_month.replace('-', '')[2:6]
self.djdb = MysqlHelper(DbConect.DB_shen_release_dj)
self.plusDb = MysqlHelper(DbConect.DB_shen_release_plus)
#------1 1.1转化店面数据 ------
def dealTransformMerchant(self):
for yearline in self.yearArray:
selectSql = f'''SELECT COUNT(DISTINCT (CASE WHEN b.`sub_shop_merchant_id` THEN b.`sub_shop_merchant_id` ELSE b.`merchant_id` END)) AS '数量'
FROM `dj_car_life_goods_sub_order` a
INNER JOIN `dj_car_life_goods_order` b ON b.`order_code`=a.`order_code`
LEFT JOIN `dj_car_life_order_expense_category_calculated` d ON d.sub_order_code=a.sub_order_code
LEFT JOIN `dj_car_life_goods` e ON e.`id`=a.`goods_id`
LEFT JOIN `temp_dj_car_life_pricetype` f ON f.`id`=a.`id`
WHERE DATE_FORMAT(b.`success_date`, '%Y')='{yearline}' AND e.`business_scene_type`=1 AND b.`upgrade_flag`='Y'
;'''
merData = self.plusDb.execute_select(selectSql)
print("---Plus_1.1转化 %s 商户数:%s" % (yearline, merData[0][0]))
return True
#------1 1.3众筹 ------
def dealDyEquitMerchant(self):
for yearline in self.yearArray:
selectSql = f'''SELECT count(distinct b.`merchant_id`) FROM `shopmall_order` a
LEFT JOIN `shopmall_activity_info` b ON b.`activity_id`=a.`activity_id` AND a.source=b.source
WHERE a.`marketing_status`=1 and DATE_FORMAT(a.`created_date`, '%Y')='{yearline}'
;'''
merData = self.plusDb.execute_select(selectSql)
print("---Plus_1.3众筹 %s 商户数:%s" % (yearline, merData[0][0]))
return True
#------1 合并 ------
def dealDyXsAndEqMerchant(self):
for yearline in self.yearArray:
selectSql = f'''select count(distinct aat.merchantId) from (
SELECT DISTINCT (CASE WHEN b.`sub_shop_merchant_id` THEN b.`sub_shop_merchant_id` ELSE b.`merchant_id` END) as merchantId
FROM `dj_car_life_goods_sub_order` a
INNER JOIN `dj_car_life_goods_order` b ON b.`order_code`=a.`order_code`
LEFT JOIN `dj_car_life_order_expense_category_calculated` d ON d.sub_order_code=a.sub_order_code
LEFT JOIN `dj_car_life_goods` e ON e.`id`=a.`goods_id`
LEFT JOIN `temp_dj_car_life_pricetype` f ON f.`id`=a.`id`
WHERE DATE_FORMAT(b.`success_date`, '%Y')='{yearline}' AND e.`business_scene_type`=1 AND b.`upgrade_flag`='Y'
UNION ALL
SELECT distinct b.`merchant_id` as merchantId FROM `shopmall_order` a
LEFT JOIN `shopmall_activity_info` b ON b.`activity_id`=a.`activity_id` AND a.source=b.source
WHERE a.`marketing_status`=1 and DATE_FORMAT(a.`created_date`, '%Y')='{yearline}'
) aat
;'''
merData = self.plusDb.execute_select(selectSql)
print("---Plus_合并 %s 商户数:%s" % (yearline, merData[0][0]))
return True
#------2 saasPlus在订阅中开展业务的店面数 ------
def dealPlusInnerDyMerchant(self):
return True
#------2 saasPlus在订阅中开展业务的店面数 ------
def dealPlusMergeDyMerchant(self):
return True
def proxySaasPlusMerchantCount(self):
# 处理 1.1转化业务
xsRes = False
xsRes = handleMain.dealTransformMerchant()
logging.info(f'===Plus1.1转化:{xsRes}')
# 处理 1.3众筹业务
qyRes = False
qyRes = handleMain.dealDyEquitMerchant()
logging.info(f'===Plus1.3众筹:{qyRes}')
# 合并数据
hbRes = False
hbRes = handleMain.dealDyXsAndEqMerchant()
logging.info(f'===Plus合并处理OK:{hbRes}')
def proxyXXXMerchantCount(self):
# 处理 xxx
xsRes = False
xsRes = handleMain.dealPlusInnerDyMerchant()
logging.info(f'===xxx:{xsRes}')
# 合并数据
hbRes = False
hbRes = handleMain.dealPlusMergeDyMerchant()
logging.info(f'===xxx合并处理OK:{hbRes}')
if __name__ == "__main__":
handle_month = '2022-12'
dedRes = False
diRes = False
urRes = False
#启动初始化
handleMain = HandelMain(handle_month)
logging.info("start handle" + handleMain.handleDescription + ' the month:' + handleMain.handleMonth)
# 输出店面数据
handleMain.proxySaasPlusMerchantCount()
# 输出XXX店面数据
# handleMain.proxyXXXMerchantCount()