Commit dd1f2011 authored by xianyang's avatar xianyang

优化

parent 3b1d75a6
......@@ -39,7 +39,8 @@ def data_to_file(db, data, name, header, field_list):
bk = pd.DataFrame(data)
if data[0].get('create_time'):
if isinstance(data[0]['create_time'], int):
bk['create_time'] = bk['create_time'].apply(lambda x: time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(x)))
bk['create_time'] = bk['create_time'].apply(
lambda x: time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(x)))
bk.columns = field_list # 修改pandas头
with pd.ExcelWriter(f'static/{name}.xlsx') as writer:
bk.to_excel(writer, sheet_name='Sheet1', index=False)
......@@ -56,13 +57,13 @@ class RechargeStatement(object):
"""充值报表"""
def __init__(self):
self.linkmysql=LinkMysql(env.DB_HISTORY)
self.linkmysql = LinkMysql(env.DB_HISTORY)
# self.count=[]
# self.once_res=[]
# self.moeny_data=[]
def query_data(self,db,page,size,order_number,uuid,sid,start_time,end_time,type,menu_id,month_type):
query=[]
def query_data(self, db, page, size, order_number, uuid, sid, start_time, end_time, type, menu_id, month_type):
query = []
if order_number:
query.append(f"reference_number={order_number} ")
if uuid:
......@@ -72,30 +73,32 @@ class RechargeStatement(object):
if type:
query.append(f"type='{type}' ")
if menu_id:
querydata=db.query(Menuconfig).filter(Menuconfig.id.in_(tuple(menu_id)))
reference_data = [QueryAllData.serialization(item,remove={'menu_name','remark','menu_type','create_time','id'}) for item in querydata]
querydata = db.query(Menuconfig).filter(Menuconfig.id.in_(tuple(menu_id)))
reference_data = [
QueryAllData.serialization(item, remove={'menu_name', 'remark', 'menu_type', 'create_time', 'id'}) for
item in querydata]
if len([item.get("menu_label") for item in reference_data]) > 1:
reference_type=tuple([item.get("menu_label") for item in reference_data])
reference_type = tuple([item.get("menu_label") for item in reference_data])
else:
reference_type="('" + [item.get("menu_label") for item in reference_data][0] + "')"
reference_type = "('" + [item.get("menu_label") for item in reference_data][0] + "')"
query.append(f"reference_type in {reference_type}")
if month_type==1:
if month_type == 1:
if start_time:
query.append(f" create_time >= {time_str_to_timestamp(start_time + ' 00:00:00')} ")
if end_time:
query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
query = ' and '.join(query)
now_month = get_month_last_month(month_type)
count,once_res,moeny_data=self.statistics_data(month_type,query,page,size,now_month[1])
count, once_res, moeny_data = self.statistics_data(month_type, query, page, size, now_month[1])
else:
query_data=self.query_add_time(start_time,end_time)
count,once_res,moeny_data=self.thread_data(month_type,query_data,page,size)
return count,once_res,moeny_data
def query_add_time(self,start_time,end_time):
data=[]
query=[]
query1=[]
query_data = self.query_add_time(start_time, end_time)
count, once_res, moeny_data = self.thread_data(month_type, query_data, page, size)
return count, once_res, moeny_data
def query_add_time(self, start_time, end_time):
data = []
query = []
query1 = []
query.append(f" create_time >= {time_str_to_timestamp(start_time + ' 00:00:00')} ")
query.append(f" create_time < {time_str_to_timestamp(start_time + ' 23:59:59')} ")
query1.append(f" create_time >= {time_str_to_timestamp(end_time + ' 00:00:00')} ")
......@@ -104,9 +107,9 @@ class RechargeStatement(object):
data.append(query1)
return data
def statistics_data(self,month_type,query,page,size,now_month):
def statistics_data(self, month_type, query, page, size, now_month):
'''统计'''
if month_type==1:
if month_type == 1:
count_sql = f"SELECT count(*) FROM assets_log_{now_month} where {query}"
count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)")
sql = f"SELECT id,a.uuid,a.amount,FROM_UNIXTIME(a.create_time,'%Y-%c-%d %h:%i:%s') as payment_time,a.reference_type,a.reference_number FROM assets_log_{now_month} as a where {query} ORDER BY id desc limit {(int(page) - 1) * size},{size}"
......@@ -119,8 +122,8 @@ class RechargeStatement(object):
else:
count_sql = "SELECT sum(a.b) FROM ("f"SELECT count(*) as b FROM assets_log_{int(now_month[0])} where {(' and '.join(query[0]))} UNION ALL SELECT count(*) FROM assets_log_{int(now_month[1])} where {(' and '.join(query[1]))}) AS a "
count = self.linkmysql.query_mysql(count_sql)[0].get("sum(a.b)")
query1=(' and '.join(query[0]))
query2=(' and '.join(query[1]))
query1 = (' and '.join(query[0]))
query2 = (' and '.join(query[1]))
sql = f"SELECT id,uuid,amount,FROM_UNIXTIME(create_time,'%Y-%c-%d %h:%i:%s') as payment_time,reference_type,reference_number FROM assets_log_{int(now_month[0])} where {query1} UNION ALL SELECT id,uuid,amount,FROM_UNIXTIME(create_time,'%Y-%c-%d %h:%i:%s') as payment_time,reference_type,reference_number FROM assets_log_{int(now_month[1])} where {query2} ORDER BY id desc limit {(int(page) - 1) * size},{size}"
once_res = self.linkmysql.query_mysql(sql)
money_sql = f"SELECT sum(a.b) FROM ("f"SELECT sum(amount) as b FROM assets_log_{int(now_month[0])} where {(' and '.join(query[0]))} UNION ALL SELECT sum(amount)FROM assets_log_{int(now_month[1])} where {(' and '.join(query[1]))}) AS a "
......@@ -128,14 +131,12 @@ class RechargeStatement(object):
self.linkmysql.query_mysql(money_sql)[0].get("sum(a.b)") != None else 0
return count, once_res, moeny_data
def thread_data(self,month_type,query,page,size):
def thread_data(self, month_type, query, page, size):
now_month = get_month_last_month(month_type)
count, once_res, moeny_data=self.statistics_data(month_type,query,page,size,now_month)
count, once_res, moeny_data = self.statistics_data(month_type, query, page, size, now_month)
return count, once_res, moeny_data
def get_statements(self,db,data):
def get_statements(self, db, data):
query = []
if data.order_number:
query.append(f"id={data.order_number} ")
......@@ -144,46 +145,47 @@ class RechargeStatement(object):
if data.sid:
query.append(f"sid='{data.sid}' ")
if data.menu_id:
querydata=db.query(Menuconfig).filter(Menuconfig.id.in_(tuple(data.menu_id)))
reference_data = [QueryAllData.serialization(item,remove={'menu_name','remark','menu_type','create_time','id'}) for item in querydata]
querydata = db.query(Menuconfig).filter(Menuconfig.id.in_(tuple(data.menu_id)))
reference_data = [
QueryAllData.serialization(item, remove={'menu_name', 'remark', 'menu_type', 'create_time', 'id'}) for
item in querydata]
if len([item.get("menu_label") for item in reference_data]) > 1:
reference_type=tuple([item.get("menu_label") for item in reference_data])
reference_type = tuple([item.get("menu_label") for item in reference_data])
else:
reference_type="('" + [item.get("menu_label") for item in reference_data][0] + "')"
reference_type = "('" + [item.get("menu_label") for item in reference_data][0] + "')"
query.append(f"reference_type in {reference_type}")
if data.month_type==1:
if data.month_type == 1:
if data.start_time:
query.append(f" create_time >= {time_str_to_timestamp(data.start_time + ' 00:00:00')} ")
if data.end_time:
query.append(f" create_time < {time_str_to_timestamp(data.end_time + ' 23:59:59')} ")
query = ' and '.join(query)
now_month = get_month_last_month(data.month_type)
once_res=self.data_delcy(data.month_type,query,now_month[1])
once_res = self.data_delcy(data.month_type, query, now_month[1])
else:
query_data=self.query_add_time(data.start_time,data.end_time)
query_data = self.query_add_time(data.start_time, data.end_time)
now_month = get_month_last_month(data.month_type)
once_res = self.data_delcy(data.month_type, query_data,now_month)
once_res = self.data_delcy(data.month_type, query_data, now_month)
return once_res
def data_delcy(self,month_type,query,now_month):
if month_type==1:
def data_delcy(self, month_type, query, now_month):
if month_type == 1:
sql = f"SELECT a.uuid,a.amount,FROM_UNIXTIME(a.create_time,'%Y-%c-%d %h:%i:%s') as payment_time,a.reference_type,a.order_number FROM assets_log_{now_month} as a where {query}"
once_res = self.linkmysql.query_mysql(sql)
else:
query1=(' and '.join(query[0]))
query2=(' and '.join(query[1]))
query1 = (' and '.join(query[0]))
query2 = (' and '.join(query[1]))
sql = f"SELECT id,uuid,amount,FROM_UNIXTIME(create_time,'%Y-%c-%d %h:%i:%s') as payment_time,reference_type,order_number FROM assets_log_{int(now_month[0])} where {query1} UNION ALL SELECT id,uuid,amount,FROM_UNIXTIME(create_time,'%Y-%c-%d %h:%i:%s') as payment_time,reference_type,order_number FROM assets_log_{int(now_month[1])} where {query2} "
once_res = self.linkmysql.query_mysql(sql)
return once_res
class WithdrawStatement(object):
"""提现报表"""
def __init__(self):
self.derive_user_list = []
self.linkmysql=LinkMysql(env.DB_HISTORY)
self.linkmysql = LinkMysql(env.DB_HISTORY)
self.derive_guild_list = []
def thread_to_data(self, db, num):
......@@ -196,10 +198,10 @@ class WithdrawStatement(object):
user_list.append(info_dict)
self.derive_user_list += user_list
def query_add_time(self,start_time,end_time):
data=[]
query=[]
query1=[]
def query_add_time(self, start_time, end_time):
data = []
query = []
query1 = []
query.append(f" create_time >= {time_str_to_timestamp(start_time + ' 00:00:00')} ")
query.append(f" create_time < {time_str_to_timestamp(start_time + ' 23:59:59')} ")
query1.append(f" create_time >= {time_str_to_timestamp(end_time + ' 00:00:00')} ")
......@@ -207,36 +209,38 @@ class WithdrawStatement(object):
data.append(query)
data.append(query1)
return data
def get_user_withdraw_cash(self,db,page, size, uuid, status,start_time,end_time,month_type,menu_id):
def get_user_withdraw_cash(self, db, page, size, uuid, status, start_time, end_time, month_type, menu_id):
query = []
if uuid:
query.append(f" uuid='{uuid}'")
if status:
query.append(f"status={status} ")
if menu_id:
querydata=db.query(Menuconfig).filter(Menuconfig.id.in_(tuple(menu_id)))
reference_data = [QueryAllData.serialization(item,remove={'menu_name','remark','menu_type','create_time','id'}) for item in querydata]
querydata = db.query(Menuconfig).filter(Menuconfig.id.in_(tuple(menu_id)))
reference_data = [
QueryAllData.serialization(item, remove={'menu_name', 'remark', 'menu_type', 'create_time', 'id'}) for
item in querydata]
if len([item.get("menu_label") for item in reference_data]) > 1:
reference_type=tuple([item.get("menu_label") for item in reference_data])
reference_type = tuple([item.get("menu_label") for item in reference_data])
else:
reference_type="('" + [item.get("menu_label") for item in reference_data][0] + "')"
reference_type = "('" + [item.get("menu_label") for item in reference_data][0] + "')"
query.append(f"reference_type in {reference_type}")
if month_type==1:
if month_type == 1:
if start_time:
query.append(f" create_time >= {time_str_to_timestamp(start_time + ' 00:00:00')} ")
if end_time:
query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
query = ' and '.join(query)
now_month = get_month_last_month(month_type)
count,once_res,moeny_data=self.dispose_user(month_type,query,page,size,now_month[1])
count, once_res, moeny_data = self.dispose_user(month_type, query, page, size, now_month[1])
else:
query_data = self.query_add_time(start_time, end_time)
now_month = get_month_last_month(month_type)
count, once_res, moeny_data= self.dispose_user(month_type, query_data, page, size,now_month)
return count,once_res,moeny_data
count, once_res, moeny_data = self.dispose_user(month_type, query_data, page, size, now_month)
return count, once_res, moeny_data
def dispose_user(self,month_type,query,page,size,now_month):
def dispose_user(self, month_type, query, page, size, now_month):
if month_type == 1:
count_sql = f"SELECT count(*) FROM assets_log_{now_month} where {query}"
print(count_sql)
......@@ -257,10 +261,9 @@ class WithdrawStatement(object):
money_sql = f"SELECT sum(a.b) FROM ("f"SELECT sum(amount) as b FROM assets_log_{int(now_month[0])} where {(' and '.join(query[0]))} UNION ALL SELECT sum(amount)FROM assets_log_{int(now_month[1])} where {(' and '.join(query[1]))} ) AS a "
moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(a.b)") if \
self.linkmysql.query_mysql(money_sql)[0].get("sum(a.b)") != None else 0
return count, once_res,moeny_data
return count, once_res, moeny_data
def get_guild_withdraw_cash(self,db,page, size, name, status,start_time,end_time,month_type,menu_id):
def get_guild_withdraw_cash(self, db, page, size, name, status, start_time, end_time, month_type, menu_id):
"""公会提现"""
query = []
if name:
......@@ -268,12 +271,14 @@ class WithdrawStatement(object):
if status:
query.append(f"status={status} ")
if menu_id:
querydata=db.query(Menuconfig).filter(Menuconfig.id.in_(tuple(menu_id)))
reference_data = [QueryAllData.serialization(item,remove={'menu_name','remark','menu_type','create_time','id'}) for item in querydata]
querydata = db.query(Menuconfig).filter(Menuconfig.id.in_(tuple(menu_id)))
reference_data = [
QueryAllData.serialization(item, remove={'menu_name', 'remark', 'menu_type', 'create_time', 'id'}) for
item in querydata]
if len([item.get("menu_label") for item in reference_data]) > 1:
reference_type=tuple([item.get("menu_label") for item in reference_data])
reference_type = tuple([item.get("menu_label") for item in reference_data])
else:
reference_type="('" + [item.get("menu_label") for item in reference_data][0] + "')"
reference_type = "('" + [item.get("menu_label") for item in reference_data][0] + "')"
query.append(f"reference_type in {reference_type}")
if month_type == 1:
if start_time:
......@@ -322,9 +327,11 @@ class FinanceFix(object):
return result, total[0]['num']
return [], 0
def create_menu(db: Session, menu: schemas.MenuAdd):
try:
db_menu = Menuconfig(menu_name=menu.menu_name, menu_label=menu.menu_label,menu_type=menu.menu_type,create_time=datetime.now(),remark=menu.remark if menu.remark!='' else '')
db_menu = Menuconfig(menu_name=menu.menu_name, menu_label=menu.menu_label, menu_type=menu.menu_type,
create_time=datetime.now(), remark=menu.remark if menu.remark != '' else '')
db.add(db_menu)
db.commit()
db.refresh(db_menu)
......@@ -333,6 +340,7 @@ def create_menu(db: Session, menu: schemas.MenuAdd):
return {}
return db_menu
def get_menu_name(db: Session, menu_name: str):
return db.query(Menuconfig).filter(Menuconfig.menu_name == menu_name).first()
......@@ -340,26 +348,26 @@ def get_menu_name(db: Session, menu_name: str):
def get_menu_id(db: Session, id: str):
return db.query(Menuconfig).filter(Menuconfig.id == id).first()
def get_menu_update(db: Session,data):
query_data=db.query(Menuconfig).filter(Menuconfig.id == data.id).update({Menuconfig.menu_name: data.menu_name,
def get_menu_update(db: Session, data):
query_data = db.query(Menuconfig).filter(Menuconfig.id == data.id).update({Menuconfig.menu_name: data.menu_name,
Menuconfig.menu_label: data.menu_label,
Menuconfig.menu_type: data.menu_type,
Menuconfig.remark: data.remark,
Menuconfig.create_time:datetime.now()
Menuconfig.create_time: datetime.now()
})
db.commit()
return query_data
def get_menu_delete(db: Session,id):
query_data=db.query(Menuconfig).filter(Menuconfig.id == id).delete()
def get_menu_delete(db: Session, id):
query_data = db.query(Menuconfig).filter(Menuconfig.id == id).delete()
db.commit()
return query_data
def get_menu_list(db: Session,page,size,menu_name,menu_label,menu_type):
querys=[]
def get_menu_list(db: Session, page, size, menu_name, menu_label, menu_type):
querys = []
if menu_name:
querys.append(Menuconfig.menu_name.like(f'%{menu_name}%'))
if menu_label:
......@@ -375,14 +383,14 @@ def get_menu_list(db: Session,page,size,menu_name,menu_label,menu_type):
Menuconfig.id.desc()).offset((int(page) - 1) * size).limit(size)
data = [QueryAllData.serialization(item) for item in querydata]
count = db.query(func.count(Menuconfig.id)).filter().scalar()
return data,count
return data, count
def get_menu_config(db: Session,menu_type):
querys=[]
def get_menu_config(db: Session, menu_type):
querys = []
if menu_type:
querys.append(Menuconfig.menu_type == menu_type)
querydata = db.query(Menuconfig).filter(*querys).order_by(
Menuconfig.id.desc())
data = [QueryAllData.serialization(item,remove={'create_time','remark'}) for item in querydata]
data = [QueryAllData.serialization(item, remove={'create_time', 'remark'}) for item in querydata]
return data
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 to comment