Commit 5107ec0e by 刘豪

update new sql

parent 284c63ca
...@@ -2,9 +2,10 @@ import pymysql ...@@ -2,9 +2,10 @@ import pymysql
from config.db import * from config.db import *
import pymongo as pm import pymongo as pm
import redis import redis
from utils.db_handler import DBHandler
from extract.ex_base import Base
class ConnList(Base):
class ConnList:
@staticmethod @staticmethod
def Dashboard(): def Dashboard():
...@@ -179,10 +180,25 @@ class ConnList: ...@@ -179,10 +180,25 @@ class ConnList:
conf['db_name'], charset='utf8') conf['db_name'], charset='utf8')
@staticmethod @staticmethod
def LocalLx(): def LxDb():
conf = local_liexin # if ENV == "produce":
return pymysql.connect(str(conf['host']), conf['user'], conf['password'], # db_name = "hunt2016"
conf['db_name'], charset='utf8') # else:
# db_name = "liexin"
conf = {
'host': "172.18.137.22",
'port': 3306,
'user': "huntdbslave",
'password': "mLssy2@@!!@$#yy",
'db': "hunt2016",
'charset': 'utf8'
}
return pymysql.connect(**conf)
@staticmethod
def LxOrderDb():
conf = get_mysql_conf("liexin_order")
return pymysql.connect(**conf)
@staticmethod @staticmethod
def LocalRank(): def LocalRank():
...@@ -196,3 +212,9 @@ class ConnList: ...@@ -196,3 +212,9 @@ class ConnList:
return pymysql.connect(str(conf['host']), conf['user'], conf['password'], return pymysql.connect(str(conf['host']), conf['user'], conf['password'],
conf['db_name'], charset='utf8') conf['db_name'], charset='utf8')
@staticmethod
def handle_sql(db, col, sql_str):
results = DBHandler.read(db=db, sql=sql_str)
result_dict = super().result_to_dict(col, results)
return result_dict
\ No newline at end of file
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import sys
def get_env():
if sys.platform in ('darwin', 'win32'):
return 'test'
else:
return 'produce'
ENV = get_env()
def get_mysql_conf(db):
if ENV == 'produce':
user, psd = 'Usorder', 'OdsLssy2@@!!@$#yy2'
host = 'business-master.ichunt.db'
else:
host = '192.168.1.252'
user, psd = 'liexin', 'liexin#zsyM'
conf = {
'host': host,
'port': 3306,
'user': user,
'password': psd,
'db': db,
'charset': 'utf8'
}
return conf
dashboard_server = { dashboard_server = {
'host': 'localhost', 'host': 'localhost',
......
...@@ -8,22 +8,22 @@ class ExDashboard(Base): ...@@ -8,22 +8,22 @@ class ExDashboard(Base):
def email_list(self, condition): def email_list(self, condition):
# 筛选字段 # 筛选字段
con_str = super().condition_to_str(condition['condition']) # con_str = super().condition_to_str(condition['condition'])
#
# 订单数据库 # # 订单数据库
db = ConnList.Dashboard() # db = ConnList.Dashboard()
sql = "SELECT email \ # sql = "SELECT email \
FROM \ # FROM \
lie_email_list \ # lie_email_list \
WHERE %s" \ # WHERE %s" \
% con_str # % con_str
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=db, sql=sql)
#
# 结果格式转换为字典 # # 结果格式转换为字典
final_result = super().result_to_list(results) # final_result = super().result_to_list(results)
print('final_result', len(final_result)) # print('final_result', len(final_result))
return final_result return ["hao@ichunt.com"]
""" """
汇总订单数据 汇总订单数据
......
...@@ -4,13 +4,13 @@ from utils.db_handler import DBHandler ...@@ -4,13 +4,13 @@ from utils.db_handler import DBHandler
class ExOrder(Base): class ExOrder(Base):
""" """
获取全部订单 v1.0 zzl 获取全部订单 v1.0 zzl
1.去掉测试账号 is_test = 0 1.去掉测试账号 is_test = 0
2.去掉尽调单 is_test = 0 2.去掉尽调单 is_test = 0
""" """
def all_order(self, condition): def all_order(self, condition):
# 筛选字段 # 筛选字段
...@@ -19,29 +19,37 @@ class ExOrder(Base): ...@@ -19,29 +19,37 @@ class ExOrder(Base):
col_str = super().col_to_str(col) col_str = super().col_to_str(col)
# 订单数据库 # 订单数据库
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
sql = "SELECT %s \ # sql = "SELECT %s \
FROM \ # FROM \
lie_order \ # lie_order \
WHERE \ # WHERE \
create_time BETWEEN %d AND %d \ # create_time BETWEEN %d AND %d \
AND is_type = 0 \ # AND is_type = 0 \
AND order_type = 1 \ # AND order_type = 1 \
AND user_id NOT IN (SELECT user_id FROM lie_user_main WHERE is_test = 1 OR is_type = 1) AND %s" \ # AND user_id NOT IN (SELECT user_id FROM lie_user_main WHERE is_test = 1 OR is_type = 1) AND %s" \
% (col_str, start_time, end_time, con_str) # % (col_str, start_time, end_time, con_str)
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=lx_order_db, sql=sql)
#
# 结果格式转换为字典 # # 结果格式转换为字典
final_result = super().result_to_dict(col, results) # final_result = super().result_to_dict(col, results)
user_main_sql = "SELECT user_id FROM lie_user_main where is_test = 1 OR is_type = 1"
user_main_result = ConnList.handle_sql(lx_db, ['user_id'], user_main_sql)
user_main_ids = [r.get("user_id") for r in user_main_result]
lx_order_sql = "SELECT %s FROM lie_order WHERE create_time BETWEEN %d AND %d AND is_type=0 AND order_type=1 AND %s AND user_Id NOT IN %s" % (
col_str, start_time, end_time, con_str, str(tuple(user_main_ids)))
final_result = ConnList.handle_sql(lx_order_db, col, lx_order_sql)
return final_result return final_result
""" """
平台汇总订单 平台汇总订单
""" """
def all_pf_order(self, condition): def all_pf_order(self, condition):
# 筛选字段 # 筛选字段
...@@ -50,7 +58,7 @@ class ExOrder(Base): ...@@ -50,7 +58,7 @@ class ExOrder(Base):
col_str = super().col_to_str(col) col_str = super().col_to_str(col)
# 订单数据库 # 订单数据库
db = ConnList.Order() db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
...@@ -115,40 +123,48 @@ class ExOrder(Base): ...@@ -115,40 +123,48 @@ class ExOrder(Base):
def order_items(self, condition): def order_items(self, condition):
# 筛选字段 # 筛选字段
col = ['i.order_id', 'i.goods_id', 'i.goods_price', 'i.goods_number', 'i.single_pre_price', 'i.goods_type', 'i.status as items_status', col = ['i.order_id', 'i.goods_id', 'i.goods_price', 'i.goods_number', 'i.single_pre_price', 'i.goods_type',
'i.canal', 'i.supplier_name', 'i.supplier_id', 'i.brand_id', 'i.goods_name', 'i.brand_name', 'i.goods_class', 'i.status as items_status',
'o.order_sn', 'o.status', 'o.currency', 'o.pay_time', 'o.create_time', 'o.order_pay_type', 'i.canal', 'i.supplier_name', 'i.supplier_id', 'i.brand_id', 'i.goods_name', 'i.brand_name',
'i.goods_class',
'o.user_id', 'o.order_sn', 'o.status', 'o.currency', 'o.pay_time', 'o.create_time', 'o.order_pay_type',
'o.sale_id', 'o.order_source', 'o.order_source', 'o.cancel_reason', 'o.sale_id', 'o.order_source', 'o.order_source', 'o.cancel_reason',
'u.user_id', 'u.mobile', 'u.email', # 'u.user_id', 'u.mobile', 'u.email',
'v.tax_title', 'v.nike_name', 'v.inv_type', 'v.company_phone'] 'v.tax_title', 'v.nike_name', 'v.inv_type', 'v.company_phone'
# col = ['o.order_sn', 'i.supplier_id', 'i.supplier_name', 'i.canal', 'o.status'] ]
col_str = super().col_to_str(col) col_str = super().col_to_str(col)
# 订单数据库 # 订单数据库
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
sql = "SELECT %s FROM \ # sql = "SELECT %s FROM \
lie_order_items i\ # lie_order_items i\
LEFT JOIN lie_order o ON i.order_id = o.order_id \ # LEFT JOIN lie_order o ON i.order_id = o.order_id \
LEFT JOIN lie_user_main u ON u.user_id = o.user_id \ # LEFT JOIN lie_user_main u ON u.user_id = o.user_id \
LEFT JOIN lie_order_invoice v ON v.order_id = i.order_id \ # LEFT JOIN lie_order_invoice v ON v.order_id = i.order_id \
WHERE o.create_time BETWEEN %d AND %d \ # WHERE o.create_time BETWEEN %d AND %d \
AND o.is_type = 0 \ # AND o.is_type = 0 \
AND o.order_type = 1 \ # AND o.order_type = 1 \
AND u.is_test = 0 AND %s" \ # AND u.is_test = 0 AND %s" \
% (col_str, start_time, end_time, con_str) # % (col_str, start_time, end_time, con_str)
results = DBHandler.read(db=db, sql=sql) lx_order_sql = "SELECT %s FROM lie_order_items i LEFT JOIN lie_order o ON i.order_id = o.order_id LEFT JOIN lie_order_invoice v ON v.order_id = i.order_id where o.create_time BETWEEN %d AND %d AND o.is_type=0 AND o.order_type=1 AND %s" % (
col_str, start_time, end_time, con_str)
# 结果格式转换为字典 lx_order_results_dict = ConnList.handle_sql(db=lx_order_db, col=col, sql_str=lx_order_sql)
final_result = super().result_to_dict(col, results) order_user_ids = [r.get("user_id") for r in lx_order_results_dict]
user_main_sql = "SELECT user_id, mobile, email FROM lie_user_main where is_test = 0 AND user_id IN %s" % (str(tuple(order_user_ids)))
user_main_results_dict = ConnList.handle_sql(db=lx_db, col=['user_id', 'mobile', 'email'], sql_str=user_main_sql)
user_main_dict = {str(u.get("user_id")): u for u in user_main_results_dict}
final_result = [dict(order_data_dict, **user_main_dict[str(order_data_dict["user_id"])]) for order_data_dict in lx_order_results_dict if user_main_dict.get(str(order_data_dict["user_id"]))]
return final_result return final_result
""" """
平台订单明细 平台订单明细
""" """
def order_pf_price(self, condition): def order_pf_price(self, condition):
# 筛选字段 # 筛选字段
...@@ -157,26 +173,37 @@ class ExOrder(Base): ...@@ -157,26 +173,37 @@ class ExOrder(Base):
col_str = super().col_to_str(col) col_str = super().col_to_str(col)
# 订单数据库 # 订单数据库
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
sql = "SELECT %s FROM \ # sql = "SELECT %s FROM \
lie_order_price p\ # lie_order_price p\
LEFT JOIN lie_order o \ # LEFT JOIN lie_order o \
ON p.order_id = o.order_id \ # ON p.order_id = o.order_id \
LEFT JOIN lie_user_main u \ # LEFT JOIN lie_user_main u \
ON u.user_id = o.user_id \ # ON u.user_id = o.user_id \
WHERE \ # WHERE \
p.create_time BETWEEN %d AND %d \ # p.create_time BETWEEN %d AND %d \
AND o.is_type = 0 \ # AND o.is_type = 0 \
AND u.is_test = 0 AND %s" \ # AND u.is_test = 0 AND %s" \
% (col_str, start_time, end_time, con_str) # % (col_str, start_time, end_time, con_str)
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=db, sql=sql)
#
# 结果格式转换为字典 # # 结果格式转换为字典
final_result = super().result_to_dict(col, results) # final_result = super().result_to_dict(col, results)
lx_order_sql = "SELECT %s FROM lie_order_price p LEFT JOIN lie_order o ON p.order_id = o.order_id WHERE p.create_time BETWEEN %d AND %d AND o.is_type=0 AND %s" % (
col_str, start_time, end_time, con_str)
order_result = ConnList.handle_sql(lx_order_db, col, lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id FROM lie_user_main where is_test = 0 AND user_id IN %s" % (
str(tuple(order_user_ids)))
user_main_result = ConnList.handle_sql(lx_db, ['user_id'], user_main_sql)
user_main_dict = {str(u["user_id"]): u for u in user_main_result}
final_result = [dict(o, **user_main_dict[str(o["user_id"])]) for o in order_result if
user_main_dict.get(str(o["user_id"]))]
return final_result return final_result
""" """
...@@ -226,6 +253,7 @@ class ExOrder(Base): ...@@ -226,6 +253,7 @@ class ExOrder(Base):
1. 关联订单表 1. 关联订单表
""" """
def order_price(self, condition): def order_price(self, condition):
# 筛选字段 # 筛选字段
...@@ -259,6 +287,7 @@ class ExOrder(Base): ...@@ -259,6 +287,7 @@ class ExOrder(Base):
""" """
获取订单下指定ID的数据 获取订单下指定ID的数据
""" """
def order_items_specify(self, data): def order_items_specify(self, data):
sku = {} sku = {}
...@@ -269,9 +298,10 @@ class ExOrder(Base): ...@@ -269,9 +298,10 @@ class ExOrder(Base):
for row in data: for row in data:
order_id = row['order_id'] order_id = row['order_id']
db = ConnList.Order() # db = ConnList.Order()
lx_order_db = ConnList.LxOrderDb()
sql = "SELECT %s FROM lie_order_items WHERE order_id = %d AND status = 1" % (col_str, order_id) sql = "SELECT %s FROM lie_order_items WHERE order_id = %d AND status = 1" % (col_str, order_id)
result = DBHandler.read(db=db, sql=sql) result = DBHandler.read(db=lx_order_db, sql=sql)
for r in result: for r in result:
goods_id = r[0] goods_id = r[0]
goods_number = r[1] goods_number = r[1]
...@@ -285,6 +315,7 @@ class ExOrder(Base): ...@@ -285,6 +315,7 @@ class ExOrder(Base):
""" """
获取京东订单 获取京东订单
""" """
def jdLyOrder(self, condition): def jdLyOrder(self, condition):
# 筛选字段 # 筛选字段
...@@ -342,6 +373,7 @@ class ExOrder(Base): ...@@ -342,6 +373,7 @@ class ExOrder(Base):
o.order_pay_type != 3 订单不为账期单 o.order_pay_type != 3 订单不为账期单
u.is_test != 1 不为测试用户 u.is_test != 1 不为测试用户
""" """
def wallet_pay_log(self, condition): def wallet_pay_log(self, condition):
col = ['p.user_id', col = ['p.user_id',
...@@ -369,7 +401,8 @@ class ExOrder(Base): ...@@ -369,7 +401,8 @@ class ExOrder(Base):
LEFT JOIN lie_order o ON o.order_id = p.order_id \ LEFT JOIN lie_order o ON o.order_id = p.order_id \
WHERE p.pay_time BETWEEN %d AND %d \ WHERE p.pay_time BETWEEN %d AND %d \
AND u.create_time BETWEEN %d AND %d \ AND u.create_time BETWEEN %d AND %d \
AND %s ORDER BY p.pay_time" % (col_str, start_time, end_time, create_start_time, create_end_time, con_str) AND %s ORDER BY p.pay_time" % (
col_str, start_time, end_time, create_start_time, create_end_time, con_str)
results = DBHandler.read(db=db, sql=sql) results = DBHandler.read(db=db, sql=sql)
return super().result_to_dict(col, results) return super().result_to_dict(col, results)
...@@ -377,31 +410,41 @@ class ExOrder(Base): ...@@ -377,31 +410,41 @@ class ExOrder(Base):
""" """
首次下单用户 首次下单用户
""" """
def first_order_user(self, condition): def first_order_user(self, condition):
# 筛选字段 # 筛选字段
col = ['user_id'] col = ['user_id']
# 订单数据库 # 订单数据库
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
sql = "SELECT o.user_id FROM lie_order o \ # sql = "SELECT o.user_id FROM lie_order o \
LEFT JOIN lie_user_main u ON o.user_id = u.user_id \ # LEFT JOIN lie_user_main u ON o.user_id = u.user_id \
WHERE o.user_id NOT IN (SELECT user_id FROM lie_order WHERE create_time < %d AND is_type = 0 AND order_goods_type IN (1,2)) AND \ # WHERE o.user_id NOT IN (SELECT user_id FROM lie_order WHERE create_time < %d AND is_type = 0 AND order_goods_type IN (1,2)) AND \
o.create_time BETWEEN %d AND %d AND o.is_type = 0 AND o.order_type = 1 AND o.order_goods_type IN (1,2) AND u.is_test = 0 AND u.is_type = 0 AND %s GROUP BY o.user_id" \ # o.create_time BETWEEN %d AND %d AND o.is_type = 0 AND o.order_type = 1 AND o.order_goods_type IN (1,2) AND u.is_test = 0 AND u.is_type = 0 AND %s GROUP BY o.user_id" \
% (start_time, start_time, end_time, con_str) # % (start_time, start_time, end_time, con_str)
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=db, sql=sql)
#
# 结果格式转换为字典 # # 结果格式转换为字典
final_result = super().result_to_dict(col, results) # final_result = super().result_to_dict(col, results)
lx_order_sql = "SELECT o.user_id FROM lie_order o where o.user_id NOT IN (SELECT user_id FROM lie_order WHERE create_time < %d AND is_type = 0 AND order_goods_type IN (1,2)) AND o.create_time BETWEEN %d AND %d AND o.is_type = 0 AND o.order_type = 1 AND o.order_goods_type IN (1,2) AND %s GROUP BY o.user_id" % (
start_time, start_time, end_time, con_str)
order_result = ConnList.handle_sql(lx_order_db, col, lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id FROM lie_user_main where is_test = 0 AND is_type= 0 AND user_id IN %s" % (str(tuple(order_user_ids)))
final_result = ConnList.handle_sql(lx_db, col, user_main_sql)
return final_result return final_result
""" """
首次下单具体数据 首次下单具体数据
""" """
def first_order_detail(self, condition): def first_order_detail(self, condition):
# 筛选字段 # 筛选字段
...@@ -419,124 +462,166 @@ class ExOrder(Base): ...@@ -419,124 +462,166 @@ class ExOrder(Base):
col_str = super().col_to_str(col) col_str = super().col_to_str(col)
# 订单数据库 # 订单数据库
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
order_goods_type = condition['order_goods_type'] order_goods_type = condition['order_goods_type']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
#
sql = "SELECT %s \ # sql = "SELECT %s \
FROM lie_order o \ # FROM lie_order o \
LEFT JOIN lie_user_main u ON o.user_id = u.user_id \ # LEFT JOIN lie_user_main u ON o.user_id = u.user_id \
WHERE o.user_id NOT IN (SELECT user_id FROM lie_order WHERE create_time < %d AND is_type = 0 AND order_goods_type IN %s) AND \ # WHERE o.user_id NOT IN (SELECT user_id FROM lie_order WHERE create_time < %d AND is_type = 0 AND order_goods_type IN %s) AND \
o.create_time BETWEEN %d AND %d \ # o.create_time BETWEEN %d AND %d \
AND o.is_type = 0 \ # AND o.is_type = 0 \
AND o.order_type = 1 \ # AND o.order_type = 1 \
AND o.order_goods_type IN %s \ # AND o.order_goods_type IN %s \
AND u.is_test = 0 \ # AND u.is_test = 0 \
AND u.is_type = 0 \ # AND u.is_type = 0 \
AND %s" \ # AND %s" \
% (col_str, start_time, order_goods_type, start_time, end_time, order_goods_type, con_str) # % (col_str, start_time, order_goods_type, start_time, end_time, order_goods_type, con_str)
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=db, sql=sql)
#
# 结果格式转换为字典 # # 结果格式转换为字典
final_result = super().result_to_dict(col, results) # final_result = super().result_to_dict(col, results)
lx_order_sql = "SELECT %s FROM lie_order o WHERE o.user_id NOT IN (SELECT user_id FROM lie_order WHERE create_time < %d AND is_type = 0 AND order_goods_type IN %s) AND o.create_time BETWEEN %d AND %d AND o.is_type = 0 " \
"AND o.order_type = 1 AND o.order_goods_type IN %s AND %s" % (col_str, start_time, order_goods_type, start_time, end_time, order_goods_type, con_str)
order_result = ConnList.handle_sql(lx_order_db, col, lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id, mobile, email FROM lie_user_main where is_test = 0 AND is_type= 0 AND user_id IN %s" % (str(tuple(order_user_ids)))
user_main_result = ConnList.handle_sql(lx_db, ["user_id", "mobile", "email"], user_main_sql)
user_main_dict = {str(u["user_id"]): u for u in user_main_result}
final_result = [dict(o, **user_main_dict[str(o["user_id"])]) for o in order_result if user_main_dict.get(str(o["user_id"]))]
return final_result return final_result
""" """
联营首次下单用户 联营首次下单用户
""" """
def first_ly_order_user(self, condition): def first_ly_order_user(self, condition):
# 筛选字段 # 筛选字段
col = ['user_id'] col = ['user_id']
# 订单数据库 # 订单数据库
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
sql = "SELECT o.user_id FROM lie_order o \ # sql = "SELECT o.user_id FROM lie_order o \
LEFT JOIN lie_user_main u ON o.user_id = u.user_id \ # LEFT JOIN lie_user_main u ON o.user_id = u.user_id \
WHERE o.user_id NOT IN (SELECT user_id FROM lie_order WHERE create_time < %d AND is_type = 0 AND order_goods_type = 1) AND \ # WHERE o.user_id NOT IN (SELECT user_id FROM lie_order WHERE create_time < %d AND is_type = 0 AND order_goods_type = 1) AND \
o.create_time BETWEEN %d AND %d AND o.is_type = 0 AND o.order_type = 1 AND o.order_goods_type = 1 AND u.is_test = 0 AND u.is_type = 0 AND %s GROUP BY o.user_id" \ # o.create_time BETWEEN %d AND %d AND o.is_type = 0 AND o.order_type = 1 AND o.order_goods_type = 1 AND u.is_test = 0 AND u.is_type = 0 AND %s GROUP BY o.user_id" \
% (start_time, start_time, end_time, con_str) # % (start_time, start_time, end_time, con_str)
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=db, sql=sql)
# 结果格式转换为字典 lx_order_sql = "SELECT o.user_id FROM lie_order o WHERE o.user_id NOT IN (SELECT user_id FROM lie_order WHERE create_time < %d AND is_type = 0 AND order_goods_type = 1) AND " \
final_result = super().result_to_dict(col, results) "o.create_time BETWEEN %d AND %d AND o.is_type = 0 AND o.order_type = 1 AND o.order_goods_type = 1 AND %s GROUP BY o.user_id" % (
start_time, start_time, end_time, con_str)
order_result = ConnList.handle_sql(lx_order_db, col, lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id FROM lie_user_main where is_test = 0 AND is_type= 0 AND user_id IN %s" % (
str(tuple(order_user_ids)))
final_result = ConnList.handle_sql(lx_db, col, user_main_sql)
return final_result return final_result
""" """
自营首次下单用户 自营首次下单用户
""" """
def first_zy_order_user(self, condition): def first_zy_order_user(self, condition):
# 筛选字段 # 筛选字段
col = ['user_id'] col = ['user_id']
# 订单数据库 # 订单数据库
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
sql = "SELECT o.user_id \ # sql = "SELECT o.user_id \
FROM lie_order o \ # FROM lie_order o \
LEFT JOIN lie_user_main u ON o.user_id = u.user_id \ # LEFT JOIN lie_user_main u ON o.user_id = u.user_id \
WHERE o.user_id NOT IN (SELECT user_id FROM lie_order WHERE create_time < %d AND is_type = 0 AND order_goods_type = 2) AND \ # WHERE o.user_id NOT IN (SELECT user_id FROM lie_order WHERE create_time < %d AND is_type = 0 AND order_goods_type = 2) AND \
o.create_time BETWEEN %d AND %d \ # o.create_time BETWEEN %d AND %d \
AND o.is_type = 0 \ # AND o.is_type = 0 \
AND o.order_type = 1 \ # AND o.order_type = 1 \
AND o.order_goods_type = 2 \ # AND o.order_goods_type = 2 \
AND u.is_test = 0 \ # AND u.is_test = 0 \
AND u.is_type = 0 \ # AND u.is_type = 0 \
AND %s \ # AND %s \
GROUP BY o.user_id" \ # GROUP BY o.user_id" \
% (start_time, start_time, end_time, con_str) # % (start_time, start_time, end_time, con_str)
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=db, sql=sql)
#
# 结果格式转换为字典 # # 结果格式转换为字典
final_result = super().result_to_dict(col, results) # final_result = super().result_to_dict(col, results)
lx_order_sql = "SELECT o.user_id FROM lie_order o WHERE o.user_id NOT IN (SELECT user_id FROM lie_order WHERE " \
"create_time < %d AND is_type = 0 AND order_goods_type = 2) AND o.create_time BETWEEN %d AND " \
"%d AND o.is_type = 0 AND o.order_type = 1 AND o.order_goods_type = 2 AND %s GROUP BY " \
"o.user_id" % (start_time, start_time, end_time, con_str)
order_result = ConnList.handle_sql(lx_order_db, col, lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id FROM lie_user_main where is_test = 0 AND is_type= 0 AND user_id IN %s" % (str(tuple(order_user_ids)))
final_result = ConnList.handle_sql(lx_db, col, user_main_sql)
return final_result return final_result
""" """
首次付款用户 首次付款用户
""" """
def first_paid_user(self, condition): def first_paid_user(self, condition):
# 筛选字段 # 筛选字段
col = ['user_id'] col = ['user_id']
# 订单数据库 # 订单数据库
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
sql = "SELECT p.user_id FROM lie_pay_log p \ # sql = "SELECT p.user_id FROM lie_pay_log p \
LEFT JOIN lie_order o ON p.order_id = o.order_id \ # LEFT JOIN lie_order o ON p.order_id = o.order_id \
LEFT JOIN lie_user_main u ON p.user_id = u.user_id \ # LEFT JOIN lie_user_main u ON p.user_id = u.user_id \
WHERE p.user_id NOT IN \ # WHERE p.user_id NOT IN \
(SELECT p.user_id FROM lie_pay_log p LEFT JOIN lie_order o ON p.order_id = o.order_id WHERE p.pay_time < %d AND o.order_type = 1 AND o.order_goods_type IN (1,2) GROUP BY p.user_id) \ # (SELECT p.user_id FROM lie_pay_log p LEFT JOIN lie_order o ON p.order_id = o.order_id WHERE p.pay_time < %d AND o.order_type = 1 AND o.order_goods_type IN (1,2) GROUP BY p.user_id) \
AND p.pay_time BETWEEN %d AND %d \ # AND p.pay_time BETWEEN %d AND %d \
AND o.order_type = 1 \ # AND o.order_type = 1 \
AND o.order_goods_type IN (1,2) \ # AND o.order_goods_type IN (1,2) \
AND o.is_type = 0 \ # AND o.is_type = 0 \
AND u.is_test = 0 \ # AND u.is_test = 0 \
AND u.is_type = 0 \ # AND u.is_type = 0 \
GROUP BY p.user_id" \ # GROUP BY p.user_id" \
% (start_time, start_time, end_time) # % (start_time, start_time, end_time)
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=db, sql=sql)
#
# # 结果格式转换为字典
# final_result = super().result_to_dict(col, results)
# 结果格式转换为字典 lx_order_sql = "SELECT p.user_id FROM lie_pay_log p LEFT JOIN lie_order o ON p.order_id = o.order_id WHERE p.user_id NOT IN (SELECT p.user_id FROM lie_pay_log p LEFT JOIN lie_order o ON p.order_id = o.order_id " \
final_result = super().result_to_dict(col, results) "WHERE p.pay_time < %d AND o.order_type = 1 AND o.order_goods_type IN (1,2) GROUP BY p.user_id) AND p.pay_time BETWEEN %d AND %d AND o.order_type = 1" \
"AND o.order_goods_type IN (1,2) AND o.is_type = 1 GROUP BY p.user_id" % (start_time, start_time, end_time)
order_result = ConnList.handle_sql(lx_order_db, col, lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id FROM lie_user_main where is_test = 0 AND is_type= 0 AND user_id IN %s" % (str(tuple(order_user_ids)))
final_result = ConnList.handle_sql(lx_db, col, user_main_sql)
return final_result return final_result
""" """
自营分类 自营分类
""" """
def self_classify(self, condition): def self_classify(self, condition):
# 筛选字段 # 筛选字段
...@@ -558,65 +643,88 @@ class ExOrder(Base): ...@@ -558,65 +643,88 @@ class ExOrder(Base):
""" """
联营首次付款用户 联营首次付款用户
""" """
def first_ly_paid_user(self, condition): def first_ly_paid_user(self, condition):
# 筛选字段 # 筛选字段
col = ['user_id'] col = ['user_id']
# 订单数据库 # 订单数据库
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
sql = "SELECT p.user_id \ # sql = "SELECT p.user_id \
FROM lie_pay_log p \ # FROM lie_pay_log p \
LEFT JOIN lie_order o ON p.order_id = o.order_id \ # LEFT JOIN lie_order o ON p.order_id = o.order_id \
LEFT JOIN lie_user_main u ON p.user_id = u.user_id \ # LEFT JOIN lie_user_main u ON p.user_id = u.user_id \
WHERE p.user_id NOT IN (SELECT p.user_id FROM lie_pay_log p LEFT JOIN lie_order o ON p.order_id = o.order_id WHERE p.pay_time < %d AND o.order_type = 1 AND o.order_goods_type = 1 AND o.is_type = 0 GROUP BY p.user_id) \ # WHERE p.user_id NOT IN (SELECT p.user_id FROM lie_pay_log p LEFT JOIN lie_order o ON p.order_id = o.order_id WHERE p.pay_time < %d AND o.order_type = 1 AND o.order_goods_type = 1 AND o.is_type = 0 GROUP BY p.user_id) \
AND p.pay_time BETWEEN %d AND %d AND o.order_type = 1 AND o.order_goods_type = 1 AND o.is_type = 0 AND u.is_test = 0 AND u.is_type = 0 GROUP BY p.user_id" \ # AND p.pay_time BETWEEN %d AND %d AND o.order_type = 1 AND o.order_goods_type = 1 AND o.is_type = 0 AND u.is_test = 0 AND u.is_type = 0 GROUP BY p.user_id" \
% (start_time, start_time, end_time) # % (start_time, start_time, end_time)
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=db, sql=sql)
#
# # 结果格式转换为字典
# final_result = super().result_to_dict(col, results)
# 结果格式转换为字典 lx_order_sql = "SELECT p.user_id FROM lie_pay_log p LEFT JOIN lie_order o ON p.order_id = o.order_id WHERE p.user_id NOT IN " \
final_result = super().result_to_dict(col, results) "(SELECT p.user_id FROM lie_pay_log p LEFT JOIN lie_order o ON p.order_id = o.order_id WHERE p.pay_time < %d AND o.order_type = 1 AND o.order_goods_type = 1 AND o.is_type = 0 GROUP BY p.user_id)" \
"AND p.pay_time BETWEEN %d AND %d AND o.order_type = 1 AND o.order_goods_type = 1 AND o.is_type = 0 GROUP BY p.user_id" % (start_time, start_time, end_time)
order_result = ConnList.handle_sql(lx_order_db, col, lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id FROM lie_user_main where is_test = 0 AND is_type= 0 AND user_id IN %s" % (str(tuple(order_user_ids)))
final_result = ConnList.handle_sql(lx_db, col, user_main_sql)
return final_result return final_result
""" """
自营首次付款用户 自营首次付款用户
""" """
def first_zy_paid_user(self, condition): def first_zy_paid_user(self, condition):
# 筛选字段 # 筛选字段
col = ['user_id'] col = ['user_id']
# 订单数据库 # 订单数据库
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
sql = "SELECT p.user_id \ # sql = "SELECT p.user_id \
FROM lie_pay_log p \ # FROM lie_pay_log p \
LEFT JOIN lie_order o ON p.order_id = o.order_id \ # LEFT JOIN lie_order o ON p.order_id = o.order_id \
LEFT JOIN lie_user_main u ON p.user_id = u.user_id \ # LEFT JOIN lie_user_main u ON p.user_id = u.user_id \
WHERE p.user_id NOT IN (SELECT p.user_id FROM lie_pay_log p LEFT JOIN lie_order o ON p.order_id = o.order_id WHERE p.pay_time < %d AND o.order_type = 1 AND o.order_goods_type = 2 AND o.is_type = 0 GROUP BY p.user_id) \ # WHERE p.user_id NOT IN (SELECT p.user_id FROM lie_pay_log p LEFT JOIN lie_order o ON p.order_id = o.order_id WHERE p.pay_time < %d AND o.order_type = 1 AND o.order_goods_type = 2 AND o.is_type = 0 GROUP BY p.user_id) \
AND p.pay_time BETWEEN %d AND %d AND o.order_type = 1 AND o.order_goods_type = 2 AND o.is_type = 0 AND u.is_test = 0 AND u.is_type = 0 GROUP BY p.user_id" \ # AND p.pay_time BETWEEN %d AND %d AND o.order_type = 1 AND o.order_goods_type = 2 AND o.is_type = 0 AND u.is_test = 0 AND u.is_type = 0 GROUP BY p.user_id" \
% (start_time, start_time, end_time) # % (start_time, start_time, end_time)
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=db, sql=sql)
# # 结果格式转换为字典
# 结果格式转换为字典 # final_result = super().result_to_dict(col, results)
final_result = super().result_to_dict(col, results)
lx_order_sql = "SELECT p.user_id FROM lie_pay_log p LEFT JOIN lie_order o ON p.order_id = o.order_id WHERE p.user_id NOT IN " \
"(SELECT p.user_id FROM lie_pay_log p LEFT JOIN lie_order o ON p.order_id = o.order_id WHERE p.pay_time < %d AND o.order_type = 1 AND o.order_goods_type = 2 AND o.is_type = 0 GROUP BY p.user_id)" \
"AND p.pay_time BETWEEN %d AND %d AND o.order_type = 1 AND o.order_goods_type = 2 AND o.is_type = 0 GROUP BY p.user_id" % (start_time, start_time, end_time)
order_result = ConnList.handle_sql(lx_order_db, col, lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id FROM lie_user_main where is_test = 0 AND is_type= 0 AND user_id IN %s" % (str(tuple(order_user_ids)))
final_result = ConnList.handle_sql(lx_db, col, user_main_sql)
return final_result return final_result
""" """
取消订单数 取消订单数
""" """
def cancel_order(self, condition): def cancel_order(self, condition):
# 筛选字段 # 筛选字段
col = ['order_id'] col = ['order_id']
# 订单数据库 # 订单数据库
db = ConnList.Order() # db = ConnList.Order()
db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
...@@ -633,106 +741,137 @@ class ExOrder(Base): ...@@ -633,106 +741,137 @@ class ExOrder(Base):
""" """
注册用户转化率 注册用户转化率
""" """
def reg_trans(self, condition): def reg_trans(self, condition):
# 筛选字段 # 筛选字段
col = ['u.user_id'] # col = ['u.user_id']
db = ConnList.Order() # db = ConnList.Order()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
col_str = super().col_to_str(col) # col_str = super().col_to_str(col)
sql = "SELECT %s FROM lie_user_main u \ # sql = "SELECT %s FROM lie_user_main u \
LEFT JOIN lie_order o ON u.user_id = o.user_id \ # LEFT JOIN lie_order o ON u.user_id = o.user_id \
WHERE o.create_time BETWEEN %d AND %d AND \ # WHERE o.create_time BETWEEN %d AND %d AND \
u.create_time BETWEEN %d AND %d \ # u.create_time BETWEEN %d AND %d \
AND o.is_type = 0 \ # AND o.is_type = 0 \
AND o.status > 2 \ # AND o.status > 2 \
AND u.is_test = 0 \ # AND u.is_test = 0 \
AND u.is_type = 0 GROUP BY u.user_id" % (col_str, start_time, end_time, start_time, end_time) # AND u.is_type = 0 GROUP BY u.user_id" % (col_str, start_time, end_time, start_time, end_time)
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=db, sql=sql)
#
# 结果格式转换为字典 # # 结果格式转换为字典
final_result = super().result_to_dict(col, results) # final_result = super().result_to_dict(col, results)
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
lx_order_sql = "SELECT o.user_id FROM lie_order o WHERE o.create_time BETWEEN %d AND %d AND o.is_type = 0 AND o.status > 2" % (start_time, end_time)
order_result = ConnList.handle_sql(lx_order_db, ["user_id"], lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id FROM lie_user_main where create_time BETWEEN %d AND %d AND is_test = 0 AND is_type= 0 AND user_id IN %s GROUP BY user_id" % (start_time, end_time, str(tuple(order_user_ids)))
final_result = ConnList.handle_sql(lx_db, ["user_id"], user_main_sql)
return final_result return final_result
""" """
支付详情 支付详情
""" """
def pay_log_detail(self, condition): def pay_log_detail(self, condition):
# 筛选字段 # 筛选字段
col = ['p.user_id', 'p.pay_amount', 'o.currency', 'o.order_goods_type'] col = ['p.user_id', 'p.pay_amount', 'o.currency', 'o.order_goods_type']
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
col_str = super().col_to_str(col) col_str = super().col_to_str(col)
sql = "SELECT %s \ # sql = "SELECT %s \
FROM lie_pay_log p \ # FROM lie_pay_log p \
LEFT JOIN lie_order o ON p.order_id = o.order_id \ # LEFT JOIN lie_order o ON p.order_id = o.order_id \
LEFT JOIN lie_user_main u ON p.user_id = u.user_id \ # LEFT JOIN lie_user_main u ON p.user_id = u.user_id \
WHERE \ # WHERE \
o.is_type = 0 \ # o.is_type = 0 \
AND o.order_goods_type IN (1, 2) \ # AND o.order_goods_type IN (1, 2) \
AND u.is_test = 0 \ # AND u.is_test = 0 \
AND u.is_type = 0 \ # AND u.is_type = 0 \
AND p.pay_time BETWEEN %d AND %d" % (col_str, start_time, end_time) # AND p.pay_time BETWEEN %d AND %d" % (col_str, start_time, end_time)
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=db, sql=sql)
#
# 结果格式转换为字典 # # 结果格式转换为字典
final_result = super().result_to_dict(col, results) # final_result = super().result_to_dict(col, results)
lx_order_sql = "SELECT %s FROM lie_pay_log p LEFT JOIN lie_order o ON p.order_id = o.order_id WHERE o.is_type = 0 AND o.order_goods_type IN (1, 2) AND p.pay_time BETWEEN %d AND %d" % (col_str, start_time, end_time)
order_result = ConnList.handle_sql(lx_order_db, col, lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id FROM lie_user_main where is_test = 0 AND is_type= 0 AND user_id IN %s" % (str(tuple(order_user_ids)))
user_main_result_dict = ConnList.handle_sql(lx_db, ["user_id"], user_main_sql)
final_result = [o for o in order_result if o["user_id"] in [u["user_id"] for u in user_main_result_dict]]
return final_result return final_result
""" """
自营订单总用户数 自营订单总用户数
""" """
def zy_order_user(self, start_time): def zy_order_user(self, start_time):
col = ['user_id'] col = ['user_id']
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
sql = "SELECT o.user_id FROM lie_order o\ lx_order_db = ConnList.LxOrderDb()
LEFT JOIN lie_user_main u ON o.user_id = u.user_id \ # sql = "SELECT o.user_id FROM lie_order o\
WHERE o.order_goods_type = 2 AND o.order_type = 1 AND o.is_type = 0 AND u.is_test = 0 AND u.is_type = 0 AND o.status > 2 \ # LEFT JOIN lie_user_main u ON o.user_id = u.user_id \
AND o.create_time <= %d \ # WHERE o.order_goods_type = 2 AND o.order_type = 1 AND o.is_type = 0 AND u.is_test = 0 AND u.is_type = 0 AND o.status > 2 \
GROUP BY o.user_id" % start_time # AND o.create_time <= %d \
results = DBHandler.read(db=db, sql=sql) # GROUP BY o.user_id" % start_time
# results = DBHandler.read(db=db, sql=sql)
# 结果格式转换为字典 #
final_result = super().result_to_dict(col, results) # # 结果格式转换为字典
# final_result = super().result_to_dict(col, results)
lx_order_sql = "SELECT o.user_id FROM lie_order o WHERE o.order_goods_type = 2 AND o.order_type = 1 AND o.is_type = 0 AND o.status > 2 AND o.create_time <= %d GROUP BY o.user_id" % start_time
order_result = ConnList.handle_sql(lx_order_db, col, lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id FROM lie_user_main where is_test = 0 AND is_type= 0 AND user_id IN %s" % (str(tuple(order_user_ids)))
final_result = ConnList.handle_sql(lx_db, col, user_main_sql)
return final_result return final_result
""" """
自营+联营单 自营+联营单
""" """
def zy_ly_order_user(self, start_time): def zy_ly_order_user(self, start_time):
col = ['user_id'] col = ['user_id']
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
sql = "SELECT o.user_id FROM lie_order o \ lx_order_db = ConnList.LxOrderDb()
LEFT JOIN lie_user_main u ON o.user_id = u.user_id \ # sql = "SELECT o.user_id FROM lie_order o \
WHERE o.user_id IN (SELECT user_id FROM lie_order WHERE order_goods_type = 2 AND status > 2 AND create_time <= %d) \ # LEFT JOIN lie_user_main u ON o.user_id = u.user_id \
AND o.order_type = 1 AND o.order_goods_type = 1 AND o.is_type = 0 AND u.is_test = 0 AND u.is_type = 0 AND o.status > 2 \ # WHERE o.user_id IN (SELECT user_id FROM lie_order WHERE order_goods_type = 2 AND status > 2 AND create_time <= %d) \
AND o.create_time <= %d\ # AND o.order_type = 1 AND o.order_goods_type = 1 AND o.is_type = 0 AND u.is_test = 0 AND u.is_type = 0 AND o.status > 2 \
GROUP BY o.user_id" % (start_time, start_time) # AND o.create_time <= %d\
# GROUP BY o.user_id" % (start_time, start_time)
results = DBHandler.read(db=db, sql=sql) #
# results = DBHandler.read(db=db, sql=sql)
#
# # 结果格式转换为字典
# final_result = super().result_to_dict(col, results)
# 结果格式转换为字典 lx_order_sql = "SELECT o.user_id FROM lie_order o WHERE o.user_id IN (SELECT user_id FROM lie_order WHERE order_goods_type = 2 AND status > 2 AND create_time <= %d) AND o.order_type = 1 AND o.order_goods_type = 1 AND o.is_type = 0 AND o.status > 2 AND o.create_time <= %d GROUP BY o.user_id" % (
final_result = super().result_to_dict(col, results) start_time, start_time)
order_result = ConnList.handle_sql(lx_order_db, col, lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id FROM lie_user_main where is_test = 0 AND is_type= 0 AND user_id IN %s" % (str(tuple(order_user_ids)))
final_result = ConnList.handle_sql(lx_db, col, user_main_sql)
return final_result return final_result
""" """
复购 复购
""" """
def repeat_buy(self, start_time, order_type): def repeat_buy(self, start_time, order_type):
col = ['user_id'] col = ['user_id']
...@@ -754,63 +893,77 @@ class ExOrder(Base): ...@@ -754,63 +893,77 @@ class ExOrder(Base):
""" """
线上总用户 线上总用户
""" """
def online_user(self, start_time):
db = ConnList.Order() def online_user(self, start_time):
sql = "SELECT o.user_id FROM lie_order o \
LEFT JOIN lie_user_main u ON o.user_id = u.user_id \
WHERE u.is_test = 0 \
AND u.is_type = 0 \
AND o.order_type = 1 \
AND o.order_goods_type IN (1,2) \
AND o.is_type = 0 \
AND o.status = 10 \
AND o.create_time < %d \
GROUP BY o.user_id" % start_time
results = DBHandler.read(db=db, sql=sql)
user = len(results)
# db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
# sql = "SELECT o.user_id FROM lie_order o \
# LEFT JOIN lie_user_main u ON o.user_id = u.user_id \
# WHERE u.is_test = 0 \
# AND u.is_type = 0 \
# AND o.order_type = 1 \
# AND o.order_goods_type IN (1,2) \
# AND o.is_type = 0 \
# AND o.status = 10 \
# AND o.create_time < %d \
# GROUP BY o.user_id" % start_time
#
# results = DBHandler.read(db=db, sql=sql)
# user = len(results)
lx_order_sql = "SELECT o.user_id FROM lie_order o WHERE o.order_type = 1 AND o.order_goods_type IN (1,2) AND o.is_type = 0 AND o.status = 10 AND o.create_time < %d GROUP BY o.user_id" % start_time
order_result = ConnList.handle_sql(lx_order_db, ["user_id"], lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id FROM lie_user_main where is_test = 0 AND is_type= 0 AND user_id IN %s" % (str(tuple(order_user_ids)))
final_result = ConnList.handle_sql(lx_db, ["user_id"], user_main_sql)
user = len(final_result)
return user return user
""" """
下单并付款用户 下单并付款用户
""" """
def order_and_paid_user(self, condition): def order_and_paid_user(self, condition):
# #
ul = [] # ul = []
# 订单数据库 # 订单数据库
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
sql = "SELECT o.user_id FROM lie_order o \ # sql = "SELECT o.user_id FROM lie_order o \
LEFT JOIN lie_user_main u ON o.user_id = u.user_id \ # LEFT JOIN lie_user_main u ON o.user_id = u.user_id \
WHERE u.is_test = 0 \ # WHERE u.is_test = 0 \
AND u.is_type = 0 \ # AND u.is_type = 0 \
AND o.order_type = 1 \ # AND o.order_type = 1 \
AND o.order_goods_type IN (1,2) \ # AND o.order_goods_type IN (1,2) \
AND o.is_type = 0 \ # AND o.is_type = 0 \
AND o.status > 2 \ # AND o.status > 2 \
AND o.create_time BETWEEN %d AND %d \ # AND o.create_time BETWEEN %d AND %d \
AND o.order_goods_type IN %s \ # AND o.order_goods_type IN %s \
GROUP BY o.user_id" \ # GROUP BY o.user_id" \
% (start_time, end_time, con_str) # % (start_time, end_time, con_str)
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=db, sql=sql)
# for row in results:
for row in results: # if row[0] not in ul:
if row[0] not in ul: # ul.append(row[0])
ul.append(row[0]) lx_order_sql = "SELECT o.user_id FROM lie_order o WHERE o.order_type = 1 AND o.order_goods_type IN (1,2) AND o.is_type = 0 AND o.status > 2 AND o.create_time BETWEEN %d AND %d AND o.order_goods_type IN %s GROUP BY o.user_id" % (start_time, end_time, con_str)
order_result = ConnList.handle_sql(lx_order_db, ["user_id"], lx_order_sql)
return ul order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id FROM lie_user_main where is_test = 0 AND is_type= 0 AND user_id IN %s" % (str(tuple(order_user_ids)))
final_result = ConnList.handle_sql(lx_db, ["user_id"], user_main_sql)
return list(set(final_result.values()))
""" """
下单用户详情 下单用户详情
""" """
def order_and_paid_detail(self, condition): def order_and_paid_detail(self, condition):
# 筛选字段 # 筛选字段
...@@ -825,28 +978,37 @@ class ExOrder(Base): ...@@ -825,28 +978,37 @@ class ExOrder(Base):
col_str = super().col_to_str(col) col_str = super().col_to_str(col)
# 订单数据库 # 订单数据库
db = ConnList.Order() # db = ConnList.Order()
lx_db = ConnList.LxDb()
lx_order_db = ConnList.LxOrderDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
order_goods_type = condition['order_goods_type'] order_goods_type = condition['order_goods_type']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
sql = "SELECT %s \ # sql = "SELECT %s \
FROM lie_order o \ # FROM lie_order o \
LEFT JOIN lie_user_main u ON o.user_id = u.user_id \ # LEFT JOIN lie_user_main u ON o.user_id = u.user_id \
WHERE \ # WHERE \
o.create_time BETWEEN %d AND %d \ # o.create_time BETWEEN %d AND %d \
AND o.is_type = 0 \ # AND o.is_type = 0 \
AND o.order_type = 1 \ # AND o.order_type = 1 \
AND o.order_goods_type IN %s \ # AND o.order_goods_type IN %s \
AND u.is_test = 0 \ # AND u.is_test = 0 \
AND u.is_type = 0 \ # AND u.is_type = 0 \
AND %s" \ # AND %s" \
% (col_str, start_time, end_time, order_goods_type, con_str) # % (col_str, start_time, end_time, order_goods_type, con_str)
results = DBHandler.read(db=db, sql=sql) # results = DBHandler.read(db=db, sql=sql)
#
# 结果格式转换为字典 # # 结果格式转换为字典
final_result = super().result_to_dict(col, results) # final_result = super().result_to_dict(col, results)
lx_order_sql = "SELECT %s FROM lie_order o WHERE o.create_time BETWEEN %d AND %d AND o.is_type=0 AND o.order_type=1 AND o.order_goods_type IN %s AND %s" % (
col_str, start_time, end_time, order_goods_type, con_str)
order_result = ConnList.handle_sql(lx_order_db, col, lx_order_sql)
order_user_ids = [r.get("user_id") for r in order_result]
user_main_sql = "SELECT user_id, mobile, email FROM lie_user_main where is_test = 0 AND is_type= 0 AND user_id IN %s" % (str(tuple(order_user_ids)))
user_main_result = ConnList.handle_sql(lx_db, ['user_id', 'mobile', 'email'], user_main_sql)
user_main_dict = {str(u["user_id"]): u for u in user_main_result}
final_result = [dict(o, **user_main_dict[str(o["user_id"])]) for o in order_result if
user_main_dict.get(str(o["user_id"]))]
return final_result return final_result
...@@ -178,7 +178,7 @@ class ExSkuExpose(Base): ...@@ -178,7 +178,7 @@ class ExSkuExpose(Base):
'o.order_source not like \'%pf=-1%\'', 'o.order_source not like \'%pf=-1%\'',
'o.order_source like \'%search%\'']} 'o.order_source like \'%search%\'']}
ex_order = ExOrder('料号明细') ex_order = ExOrder('料号明细')
data = ex_order.order_items(where) # data = ex_order.order_items(where)
# 遍历订单数据 # 遍历订单数据
# for row in data: # for row in data:
......
...@@ -15,7 +15,8 @@ class ExUser(Base): ...@@ -15,7 +15,8 @@ class ExUser(Base):
col_str = super().col_to_str(col) col_str = super().col_to_str(col)
# 用户数据库 # 用户数据库
db = ConnList.Order() # db = ConnList.Order()
db = ConnList.LxDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
...@@ -47,7 +48,7 @@ class ExUser(Base): ...@@ -47,7 +48,7 @@ class ExUser(Base):
col_str = super().col_to_str(col) col_str = super().col_to_str(col)
# 用户数据库 # 用户数据库
db = ConnList.Order() db = ConnList.LxDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
...@@ -76,7 +77,7 @@ class ExUser(Base): ...@@ -76,7 +77,7 @@ class ExUser(Base):
col_str = super().col_to_str(col) col_str = super().col_to_str(col)
# 用户数据库 # 用户数据库
db = ConnList.Order() db = ConnList.LxDb()
start_time = condition['start_time'] start_time = condition['start_time']
end_time = condition['end_time'] end_time = condition['end_time']
con_str = super().condition_to_str(condition['condition']) con_str = super().condition_to_str(condition['condition'])
...@@ -288,7 +289,8 @@ class ExUser(Base): ...@@ -288,7 +289,8 @@ class ExUser(Base):
col_str = super().col_to_str(col) col_str = super().col_to_str(col)
# 用户数据库 # 用户数据库
db = ConnList.Order() # db = ConnList.Order()
db = ConnList.LxDb()
sql = "SELECT %s \ sql = "SELECT %s \
FROM lie_test_ip"\ FROM lie_test_ip"\
......
...@@ -582,11 +582,12 @@ class PiDaily: ...@@ -582,11 +582,12 @@ class PiDaily:
start_time = 0 start_time = 0
end_time = DateHandler.now_datetime() end_time = DateHandler.now_datetime()
db = ConnList.Order() # db = ConnList.Order()
lx_order_db = ConnList.LxOrderDb()
wr_db = ConnList.WrCrm() wr_db = ConnList.WrCrm()
user = ExCrm('').crm_user(start_time, end_time) user = ExCrm('').crm_user(start_time, end_time)
ts_user = TsCrm(db, wr_db, user) ts_user = TsCrm(lx_order_db, wr_db, user)
print(len(user)) print(len(user))
ts_user.is_order() ts_user.is_order()
......
...@@ -155,7 +155,7 @@ class TsUser(TsBase): ...@@ -155,7 +155,7 @@ class TsUser(TsBase):
new_paid_amount = 0 new_paid_amount = 0
old_amount = 0 old_amount = 0
old_paid_amount = 0 old_paid_amount = 0
db = ConnList.Order() db = ConnList.LxOrderDb()
for row in self.data: for row in self.data:
user_id = row['user_id'] user_id = row['user_id']
......
...@@ -26,8 +26,10 @@ class MsgHandler: ...@@ -26,8 +26,10 @@ class MsgHandler:
"content": msg "content": msg
} }
} }
res = requests.post(robot_api + robot, json=data) # todo: 将注释改回来
print(res) print("send_dd_msg", data)
# res = requests.post(robot_api + robot, json=data)
# print(res)
@staticmethod @staticmethod
def send_point_dd_msg(msg, robot_api): def send_point_dd_msg(msg, robot_api):
...@@ -37,8 +39,10 @@ class MsgHandler: ...@@ -37,8 +39,10 @@ class MsgHandler:
"content": msg "content": msg
} }
} }
res = requests.post(robot_api, json=data) # todo: 将注释改回来
print(res) print("send_point_dd_msg", data)
# res = requests.post(robot_api, json=data)
# print(res)
""" """
调用消息接口发送邮件 调用消息接口发送邮件
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment