Commit 53913ec8 authored by xianyang's avatar xianyang

Merge branch 'develop/xp' into development

# Conflicts:
#	app/api/statement/crud.py
#	app/api/statement/guild.py
parents 3bd7fcff 8cae1eeb
...@@ -13,7 +13,7 @@ from core.config.env import env ...@@ -13,7 +13,7 @@ from core.config.env import env
from libs.db_link import LinkMysql from libs.db_link import LinkMysql
from core.config.env import env from core.config.env import env
from libs.db_link import LinkMysql from libs.db_link import LinkMysql
from libs.functions import time_str_to_timestamp, timestamp_to_time_str from libs.functions import time_str_to_timestamp, timestamp_to_time_str, get_month_last_month
from libs.orm import QueryAllData from libs.orm import QueryAllData
from models.recharge import Recharge, UserWC, GuildWC, FinanceFixLog from models.recharge import Recharge, UserWC, GuildWC, FinanceFixLog
...@@ -47,103 +47,80 @@ def data_to_file(db, data, name, header, field_list): ...@@ -47,103 +47,80 @@ def data_to_file(db, data, name, header, field_list):
class RechargeStatement(object): class RechargeStatement(object):
"""充值报表""" """充值报表"""
def __init__(self): def __init__(self):
self.linkmysql = LinkMysql(env.DB_3YV2) self.linkmysql=LinkMysql(env.DB_HISTORY)
self.derive_list = [] # self.count=[]
# self.once_res=[]
# self.moeny_data=[]
def query_data(self, page, size): def query_data(self,page,size,order_number,user_id,sid,start_time,end_time,type,reference_type,month_type):
count_sql = f'SELECT count(*) FROM `orders` as d inner join v2_user as u on d.userid=u.user_id where status=1'
count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)")
sql = f'SELECT d.id as order_number,d.userid as user_id,u.user_number,u.nick_name,d.money,d.paychannel as pay_channel,d.sid,d.current,FROM_UNIXTIME(d.payment_time,"%Y-%c-%d %h:%i:%s") as payment_time,FROM_UNIXTIME(d.lastupdate,"%Y-%c-%d %h:%i:%s") as last_update FROM `orders` as d inner join v2_user as u on d.userid=u.user_id where status=1 ORDER BY id desc limit {page},{(size)}'
once_res = self.linkmysql.query_mysql(sql)
money_sql = f'SELECT sum(d.balanceadd) FROM `orders` as d inner join v2_user as u on d.userid=u.user_id where status=1'
moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(d.balanceadd)")
return count, once_res, moeny_data
def query_data(self,page,size,order_number,user_id,sid,start_time,end_time):
query=[] query=[]
if start_time:
query.append(f" lastupdate >= {time_str_to_timestamp(start_time + ' 00:00:00')} ")
if end_time:
query.append(f" lastupdate < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
if order_number: if order_number:
query.append(f"id={order_number} ") query.append(f"id={order_number} ")
if user_id: if user_id:
query.append(f"user_id={user_id} ") query.append(f"user_id={user_id} ")
if sid: if sid:
query.append(f"sid='{sid}' ") query.append(f"sid='{sid}' ")
if query==[]: if type:
count_sql=f"SELECT count(*) FROM `orders` as d inner join v2_user as u on d.userid=u.user_id where status=1" query.append(f"type='{type}' ")
if reference_type:
query.append(f"reference_type='{reference_type}'")
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])
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.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')} ")
query1.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
data.append(query)
data.append(query1)
return data
def statistics_data(self,month_type,query,page,size,now_month):
'''统计'''
if month_type==1:
count_sql = f"SELECT count(*) FROM assets_log_{now_month} where {query} and type=1"
count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)") count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)")
sql = f'SELECT d.id as order_number,d.userid as user_id,u.user_number,u.nick_name,d.money,d.paychannel as pay_channel,d.sid,d.current,FROM_UNIXTIME(d.payment_time,"%Y-%c-%d %h:%i:%s") as payment_time,FROM_UNIXTIME(d.lastupdate,"%Y-%c-%d %h:%i:%s") as last_update FROM `orders` as d inner join v2_user as u on d.userid=u.user_id where status=1 ORDER BY id desc limit {(int(page) - 1) * size},{size}' sql = f'SELECT id,a.uuid,a.amount,FROM_UNIXTIME(a.create_time,"%Y-%c-%d %h:%i:%s") as payment_time,a.amount_type,a.reference_number FROM assets_log_{now_month} as a where type=1 and {query} ORDER BY id desc limit {(int(page) - 1) * size},{size}'
once_res = self.linkmysql.query_mysql(sql) once_res = self.linkmysql.query_mysql(sql)
money_sql = f"SELECT sum(d.balanceadd) FROM `orders` as d inner join v2_user as u on d.userid=u.user_id where status=1" money_sql = f"SELECT sum(amount) FROM assets_log_{now_month} where {query} and type=1"
moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(d.balanceadd)") if \ moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(amount)") if \
self.linkmysql.query_mysql(money_sql)[0].get("sum(d.balanceadd)") != None else 0 self.linkmysql.query_mysql(money_sql)[0].get("sum(amount)") != None else 0
else: else:
query = ' and '.join(query).replace('lastupdate','d.lastupdate').replace('current','d.current') count_sql = "SELECT sum(a.b) FROM ("f"SELECT count(*) as b FROM assets_log_{int(now_month[0])} where {(' and '.join(query[0]))} and type=1 UNION ALL SELECT count(*) FROM assets_log_{int(now_month[1])} where {(' and '.join(query[1]))} and type=1 ) AS a "
count_sql=f"SELECT count(*) FROM `orders` as d inner join v2_user as u on d.userid=u.user_id where status=1 and {query}" count = self.linkmysql.query_mysql(count_sql)[0].get("sum(a.b)")
count=self.linkmysql.query_mysql(count_sql)[0].get("count(*)") query1=(' and '.join(query[0]))
sql =f'SELECT d.id as order_number,d.userid as user_id,u.user_number,u.nick_name,d.money,d.paychannel as pay_channel,d.sid,d.current,FROM_UNIXTIME(d.payment_time,"%Y-%c-%d %h:%i:%s") as payment_time,FROM_UNIXTIME(d.lastupdate,"%Y-%c-%d %h:%i:%s") as last_update FROM `orders` as d inner join v2_user as u on d.userid=u.user_id where status=1 and {query} ORDER BY id desc limit {(int(page) - 1) * size},{size}' query2=(' and '.join(query[1]))
once_res=self.linkmysql.query_mysql(sql) sql = f'SELECT id,uuid,amount,FROM_UNIXTIME(create_time,"%Y-%c-%d %h:%i:%s") as payment_time,amount_type,reference_number FROM assets_log_{int(now_month[0])} where {query1} and type=1 UNION ALL SELECT id,uuid,amount,FROM_UNIXTIME(create_time,"%Y-%c-%d %h:%i:%s") as payment_time,amount_type,reference_number FROM assets_log_{int(now_month[1])} where {query2} and type=1 ORDER BY id desc limit {(int(page) - 1) * size},{size}'
money_sql=f"SELECT sum(d.balanceadd) FROM `orders` as d inner join v2_user as u on d.userid=u.user_id where status=1 and {query}" print(sql)
moeny_data= self.linkmysql.query_mysql(money_sql)[0].get("sum(d.balanceadd)") if self.linkmysql.query_mysql(money_sql)[0].get("sum(d.balanceadd)")!=None else 0 once_res = self.linkmysql.query_mysql(sql)
return count,once_res,moeny_data 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]))} and type=1 UNION ALL SELECT sum(amount)FROM assets_log_{int(now_month[1])} where {(' and '.join(query[1]))} and type=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
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)
return count, once_res, moeny_data
# def query_all_data(self, db):
#
# msg_count = db.query(func.count(Recharge.id)).scalar()
# num = math.ceil(msg_count / 10)
# # 创建线程
# ths = []
# # 创建线程
# for x in range(num):
# ths.append(threading.Thread(target=self.check_out, args=[db, x]))
# # 启动线程
# for y in range(num):
# ths[y].start()
# # 等待子进程结束
# for z in range(num):
# ths[z].join()
# return self.derive_list
# def get_statements(self, db: Session, param, sp=None):
# """列表"""
# not_null_filters = []
# if param.order_number:
# not_null_filters.append(Recharge.order_number == param.order_number)
# if param.user_id:
# not_null_filters.append(Recharge.user_id == param.user_id)
# if param.sid:
# not_null_filters.append(Recharge.sid.like(f'%{param.sid}%'))
# if param.pay_channel:
# not_null_filters.append(Recharge.pay_channel.like(f'%{param.pay_channel}%'))
# if param.start_time:
# not_null_filters.append(Recharge.current >= param.start_time)
# if param.end_time:
# not_null_filters.append(Recharge.current <= param.end_time)
# # 判断有无条件
# try:
# if len(not_null_filters) > 0:
# get_user_orm_sql = db.query(Recharge).filter(and_(*not_null_filters))
# condition_data = db.execute(get_user_orm_sql).fetchall()
# serializer_info = [i[0].to_dict() for i in condition_data]
# serializer_info.reverse()
# else:
# serializer_info = self.query_all_data(db)
# except Exception as e:
# print(e)
# return [], 0, 0 if sp else []
# # 判断是列表还是导出接口
# if sp:
# if serializer_info:
# total = len(serializer_info)
# df = pd.DataFrame(serializer_info)
# count = df['money'].apply(lambda x: x).sum()
# return serializer_info[(int(param.page) - 1) * param.size:param.size * param.page], total, count
# return [], 0, 0
# else:
# return serializer_info
def get_statements(self,data): def get_statements(self,data):
query = [] query = []
if data.start_time: if data.start_time:
...@@ -156,22 +133,39 @@ class RechargeStatement(object): ...@@ -156,22 +133,39 @@ class RechargeStatement(object):
query.append(f"user_id={data.user_id} ") query.append(f"user_id={data.user_id} ")
elif data.sid: elif data.sid:
query.append(f"sid='{data.sid}' ") query.append(f"sid='{data.sid}' ")
if query == []: if data.month_type==1:
sql = f'SELECT d.id as order_number,d.userid as user_id,u.user_number,u.nick_name,d.money,d.paychannel as pay_channel,d.sid,d.current,FROM_UNIXTIME(d.payment_time,"%Y-%c-%d %h:%i:%s") as payment_time,FROM_UNIXTIME(d.lastupdate,"%Y-%c-%d %h:%i:%s") as last_update FROM `orders` as d inner join v2_user as u on d.userid=u.user_id where status=1 ORDER BY id desc' 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)
count,once_res,moeny_data=self.data_delcy(data.month_type,query,now_month[1])
else:
query_data=self.query_add_time(data.start_time,data.end_time)
now_month = get_month_last_month(data.month_type)
count, once_res, moeny_data = 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:
sql = f'SELECT a.uuid,a.amount,FROM_UNIXTIME(a.create_time,"%Y-%c-%d %h:%i:%s") as payment_time,a.amount_type,a.order_number FROM assets_log_{now_month} as a where type=1 and {query}'
once_res = self.linkmysql.query_mysql(sql) once_res = self.linkmysql.query_mysql(sql)
else: else:
query = ' and '.join(query) query1=(' and '.join(query[0]))
sql = f'SELECT d.id as order_number,d.userid as user_id,u.user_number,u.nick_name,d.money,d.paychannel as pay_channel,d.sid,d.current,FROM_UNIXTIME(d.payment_time,"%Y-%c-%d %h:%i:%s") as payment_time,FROM_UNIXTIME(d.lastupdate,"%Y-%c-%d %h:%i:%s") as last_update FROM `orders` as d inner join v2_user as u on d.userid=u.user_id where status=1 and {query} ORDER BY id desc' query2=(' and '.join(query[1]))
sql = f'SELECT id,uuid,amount,FROM_UNIXTIME(create_time,"%Y-%c-%d %h:%i:%s") as payment_time,amount_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,amount_type,order_number FROM assets_log_{int(now_month[1])} where {query2}'
once_res = self.linkmysql.query_mysql(sql) once_res = self.linkmysql.query_mysql(sql)
return once_res return once_res
class WithdrawStatement(object): class WithdrawStatement(object):
"""提现报表""" """提现报表"""
def __init__(self): def __init__(self):
self.derive_user_list = [] self.derive_user_list = []
self.linkmysql=LinkMysql(env.DB_3YV2) self.linkmysql=LinkMysql(env.DB_HISTORY)
self.derive_guild_list = [] self.derive_guild_list = []
def thread_to_data(self, db, num): def thread_to_data(self, db, num):
...@@ -184,169 +178,82 @@ class WithdrawStatement(object): ...@@ -184,169 +178,82 @@ class WithdrawStatement(object):
user_list.append(info_dict) user_list.append(info_dict)
self.derive_user_list += user_list self.derive_user_list += user_list
def query_user_all_data(self, db): def query_add_time(self,start_time,end_time):
msg_count = db.query(func.count(UserWC.id)).scalar() data=[]
num = math.ceil(msg_count / 10) query=[]
# 创建线程 query1=[]
ths = [] query.append(f" create_time >= {time_str_to_timestamp(start_time + ' 00:00:00')} ")
for x in range(num): query.append(f" create_time < {time_str_to_timestamp(start_time + ' 23:59:59')} ")
ths.append(threading.Thread(target=self.thread_to_data, args=[db, x])) query1.append(f" create_time >= {time_str_to_timestamp(end_time + ' 00:00:00')} ")
for y in range(num): query1.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
ths[y].start() data.append(query)
for z in range(num): data.append(query1)
ths[z].join() return data
return self.derive_user_list def get_user_withdraw_cash(self,page, size, name, status,start_time,end_time,month_type):
# def get_user_withdraw_cash(self, db: Session, param):
# """用户提现"""
# is_filters = []
# if param.name:
# is_filters.append(UserWC.nick_name.like(f'%{param.name}%'))
# if param.status or param.status == 0:
# is_filters.append(UserWC.status == param.status)
# if param.start_time:
# is_filters.append(UserWC.current >= param.start_time)
# if param.end_time:
# is_filters.append(UserWC.current <= param.end_time)
# # 判断有无条件
# try:
# if len(is_filters) > 0:
# get_user_orm_sql = db.query(UserWC).filter(and_(*is_filters))
# condition_data = db.execute(get_user_orm_sql).fetchall()
# user_info = [i[0].to_dict() for i in condition_data]
# else:
# user_info = self.query_user_all_data(db)
# except Exception as e:
# print(e)
# return [], 0, 0, 0
# # 判断是列表还是导出接口
# user_info.reverse()
# if user_info:
# total = len(user_info)
# df = pd.DataFrame(user_info)
# count = df['money'].apply(lambda x: x).sum()
# final_count = df['final_money'].apply(lambda x: float(x)).sum()
# return user_info[(int(param.page) - 1) * param.size:param.size * param.page], total, count, final_count
# return [], 0, 0, 0
def get_user_withdraw_cash(self,page, size, name, status,start_time,end_time):
query = [] query = []
if start_time:
query.append(f" current >= {time_str_to_timestamp(start_time + ' 00:00:00')} ")
if end_time:
query.append(f" update_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
if name: if name:
query.append(f" nickname like '%{name}%' ") query.append(f" nickname like '%{name}%' ")
if status: if status:
query.append(f"status={status} ") query.append(f"status={status} ")
if query==[]: query.append(f"reference_type='userWithdrawal' ")
choice = 1 if month_type==1:
count_sql = f'SELECT count(*) FROM `tixian_order` where choice=1 and `status`=3' if start_time:
count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)") # 总条数 query.append(f" create_time >= {time_str_to_timestamp(start_time + ' 00:00:00')} ")
sql = f'SELECT t.usernumber as user_number,t.status,t.id as bank_code,t.nickname as nick_name,t.truename as true_name ,t.money,t.current,t.final_money,t.idcard as id_card,t.account,t.platformServiceFee as platform_service_fee,t.thirdServiceFee as third_service_fee FROM `tixian_order` as t where choice={choice} ORDER BY id desc limit {(int(page) - 1) * size},{size}' if end_time:
statement_list = self.linkmysql.query_mysql(sql) # 提现总数 query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
money_sql = f'SELECT sum(money) FROM `tixian_order` where choice=1'
moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(money)") # 提现金额
final_data = f'SELECT sum(final_money) FROM `tixian_order` where choice=1'
final_money = self.linkmysql.query_mysql(final_data)[0].get("sum(final_money)") # 实得金额
else:
choice=1
query = ' and '.join(query) query = ' and '.join(query)
count_sql = f'SELECT count(*) FROM `tixian_order` where choice=1 and {query}' now_month = get_month_last_month(month_type)
count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)") #总条数 count,once_res,moeny_data=self.dispose_user(month_type,query,page,size,now_month[1])
sql = f'SELECT t.usernumber as user_number,t.status,t.id as bank_code,t.nickname as nick_name,t.truename as true_name ,t.money,t.current,t.final_money,t.idcard as id_card,t.account,t.platformServiceFee as platform_service_fee,t.thirdServiceFee as third_service_fee FROM `tixian_order` as t where choice={choice} and {query} ORDER BY id desc limit {(int(page) - 1) * size},{size}' else:
statement_list = self.linkmysql.query_mysql(sql) #提现总数 query_data = self.query_add_time(start_time, end_time)
money_sql = f'SELECT sum(money) FROM `tixian_order` where choice=1 and {query}' now_month = get_month_last_month(month_type)
moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(money)") #提现金额 count, once_res, moeny_data= self.dispose_user(month_type, query_data, page, size,now_month)
final_data=f'SELECT sum(final_money) FROM `tixian_order` where choice=1 and {query}' return count,once_res,moeny_data
final_money=self.linkmysql.query_mysql(final_data)[0].get("sum(final_money)") # 实得金额
return statement_list, count, moeny_data,final_money
# def dispose_guild_to_data(self, db, num): def dispose_user(self,month_type,query,page,size,now_month):
# user_list = [] if month_type == 1:
# locka.acquire() count_sql = f"SELECT count(*) FROM assets_log_{now_month} where {query}"
# once_res = db.query(GuildWC).filter().offset(num * 10).limit(10).all() count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)")
# locka.release() sql = f'SELECT uuid,a.reference_type,a.reference_number,FROM_UNIXTIME(a.create_time,"%Y-%c-%d %h:%i:%s") as payment_time,a.amount_type FROM assets_log_{now_month} as a where {query} ORDER BY id desc limit {(int(page) - 1) * size},{size}'
# for i in once_res: once_res = self.linkmysql.query_mysql(sql)
# info_dict = i.to_dict() money_sql = f"SELECT sum(amount) FROM assets_log_{now_month} where {query} "
# user_list.append(info_dict) moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(amount)") if \
# self.derive_user_list += user_list self.linkmysql.query_mysql(money_sql)[0].get("sum(amount)") != None else 0
# else:
# def query_guild_all_data(self, db): 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 "
# msg_count = db.query(func.count(UserWC.id)).scalar() count = self.linkmysql.query_mysql(count_sql)[0].get("sum(a.b)")
# num = math.ceil(msg_count / 10) query1 = (' and '.join(query[0]))
# # 创建线程 query2 = (' and '.join(query[1]))
# ths = [] sql = f"SELECT id,uuid,amount,FROM_UNIXTIME(create_time,'%Y-%c-%d %h:%i:%s') as payment_time,amount_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,amount_type,reference_number FROM assets_log_{int(now_month[1])} where {query2} ORDER BY id desc limit {(int(page) - 1) * size},{size}"
# for x in range(num): once_res = self.linkmysql.query_mysql(sql)
# ths.append(threading.Thread(target=self.dispose_guild_to_data, args=[db, x])) 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 "
# for y in range(num): moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(a.b)") if \
# ths[y].start() self.linkmysql.query_mysql(money_sql)[0].get("sum(a.b)") != None else 0
# for z in range(num): return count, once_res,moeny_data
# ths[z].join()
# return self.derive_user_list
# def get_guild_withdraw_cash(self, db: Session, cond):
# """公会提现"""
# is_guild_filters = []
# if cond.guild_id:
# is_guild_filters.append(GuildWC.guild_id == cond.guild_id)
# if cond.status or cond.status == 0:
# is_guild_filters.append(GuildWC.status == cond.status)
# if cond.start_time:
# is_guild_filters.append(GuildWC.update_time >= cond.start_time)
# if cond.end_time:
# is_guild_filters.append(GuildWC.update_time <= cond.end_time)
# # 判断有无条件
# try:
# if len(is_guild_filters) > 0:
# get_user_orm_sql = db.query(GuildWC).filter(and_(*is_guild_filters))
# condition_data = db.execute(get_user_orm_sql).fetchall()
# guild_info = [i[0].to_dict() for i in condition_data]
# else:
# guild_info = self.query_guild_all_data(db)
# except Exception as e:
# print(e)
# return [], 0, 0, 0
# # 判断是列表还是导出接口
# guild_info.reverse()
# if guild_info:
# total = len(guild_info)
# df = pd.DataFrame(guild_info)
# count = df['money'].apply(lambda x: x).sum()
# final_count = df['final_money'].apply(lambda x: float(x)).sum()
# return guild_info[(int(cond.page) - 1) * cond.size:cond.size * cond.page], total, count, final_count
# return [], 0, 0, 0
def get_guild_withdraw_cash(self,page,size,guild_id,status,start_time,end_time): def get_guild_withdraw_cash(self,page, size, name, status,start_time,end_time,month_type):
"""公会提现"""
query = [] query = []
if start_time: if name:
query.append(f" create_time >= {time_str_to_timestamp(start_time + ' 00:00:00')} ") query.append(f" nickname like '%{name}%' ")
if end_time:
query.append(f" update_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
if guild_id:
query.append(f"guild_id={guild_id} ")
if status: if status:
query.append(f"status={status} ") query.append(f"status={status} ")
if query==[]: query.append(f"reference_type='guildWithdrawal' ")
count_sql = f'SELECT count(*) FROM `guild_ti_xian`' if month_type == 1:
count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)") # 总条数 if start_time:
sql = f'SELECT t.guild_id,t.parent_id as merchants_id,g.guild_name,t.money,t.account,t.`status`,t.finalMoney as final_money,t.update_time,t.taxRate as platform_service_fee,t.thirdServiceFee as third_service_fee FROM `guild_ti_xian` as t inner join guild as g on g.id=t.guild_id ORDER BY t.id desc limit {(int(page) - 1) * size},{size}' query.append(f" create_time >= {time_str_to_timestamp(start_time + ' 00:00:00')} ")
statement_list = self.linkmysql.query_mysql(sql) # 提现总数 if end_time:
money_sql = f'SELECT sum(money) FROM `guild_ti_xian`' query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(money)") # 提现金额 query = ' and '.join(query)
final_data = f'SELECT sum(finalMoney) FROM `guild_ti_xian`' now_month = get_month_last_month(month_type)
final_money = self.linkmysql.query_mysql(final_data)[0].get("sum(finalMoney)") # 实得金额 count, once_res, moeny_data = self.dispose_user(month_type, query, page, size, now_month[1])
else: else:
query1 = ' and '.join(query) query_data = self.query_add_time(start_time, end_time)
query_time=' and '.join(query).replace('create_time','t.create_time').replace('update_time','t.update_time').replace('guild_id','t.guild_id').replace('status','t.status') now_month = get_month_last_month(month_type)
count_sql = f'SELECT count(*) FROM `guild_ti_xian` where {query1}' count, once_res, moeny_data = self.dispose_user(month_type, query_data, page, size, now_month)
count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)") # 总条数 return count, once_res, moeny_data
sql = f'SELECT t.guild_id,t.parent_id as merchants_id,g.guild_name,t.money,t.account,t.`status`,t.finalMoney as final_money,t.update_time,t.taxRate as platform_service_fee,t.thirdServiceFee as third_service_fee FROM `guild_ti_xian` as t inner join guild as g on g.id=t.guild_id where {query_time} ORDER BY t.id desc limit {(int(page) - 1) * size},{size}'
statement_list = self.linkmysql.query_mysql(sql) # 提现总数
money_sql = f'SELECT sum(money) FROM `guild_ti_xian` where {query1}'
moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(money)") if self.linkmysql.query_mysql(money_sql)[0].get("sum(money)")!=None else 0 # 提现金额
final_data = f'SELECT sum(finalMoney) FROM `guild_ti_xian` where {query1}'
final_money = self.linkmysql.query_mysql(final_data)[0].get("sum(finalMoney)") # 实得金额
return statement_list, count, moeny_data, final_money
class FinanceFix(object): class FinanceFix(object):
...@@ -363,7 +270,7 @@ class FinanceFix(object): ...@@ -363,7 +270,7 @@ class FinanceFix(object):
count_sql = f"select count(id) as num from finance_fix_log where {' and '.join(finance_filters)}" count_sql = f"select count(id) as num from finance_fix_log where {' and '.join(finance_filters)}"
data_sql = f"select id,type,money,unique_tag,amount_type,operator,create_time,remark from finance_fix_log where {' and '.join(finance_filters)} order by id DESC limit {(int(page) - 1) * size},{size}" data_sql = f"select id,type,money,unique_tag,amount_type,operator,create_time,remark from finance_fix_log where {' and '.join(finance_filters)} order by id DESC limit {(int(page) - 1) * size},{size}"
else: else:
count_sql = f"select count(id) as num from finance_fix_log" count_sql = f"select count(id) as num from finance_fix_log where {' and '.join(finance_filters)}"
data_sql = f"select id,type,money,unique_tag,amount_type,operator,create_time,remark from finance_fix_log order by id DESC limit {(int(page) - 1) * size},{size}" data_sql = f"select id,type,money,unique_tag,amount_type,operator,create_time,remark from finance_fix_log order by id DESC limit {(int(page) - 1) * size},{size}"
with ThreadPoolExecutor(max_workers=2) as pool: with ThreadPoolExecutor(max_workers=2) as pool:
future1 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, count_sql) future1 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, count_sql)
......
from fastapi import HTTPException
from typing import Optional from typing import Optional
from pydantic import BaseModel, validator from pydantic import BaseModel, validator
...@@ -24,6 +25,7 @@ class StatementList(BaseModel): ...@@ -24,6 +25,7 @@ class StatementList(BaseModel):
user_id: Optional[str] = "" user_id: Optional[str] = ""
sid: Optional[str] = "" sid: Optional[str] = ""
pay_channel: Optional[str] = "" pay_channel: Optional[str] = ""
month_type :Optional[int] =None
class Statement(StatementBase): class Statement(StatementBase):
...@@ -108,6 +110,8 @@ class UserNumber(BaseModel): ...@@ -108,6 +110,8 @@ class UserNumber(BaseModel):
type: Optional[int] = None type: Optional[int] = None
class CreateBill(BaseModel): class CreateBill(BaseModel):
dst_id: Optional[str] = "" dst_id: Optional[str] = ""
dst_name: Optional[str] = "" dst_name: Optional[str] = ""
......
...@@ -21,14 +21,14 @@ router = APIRouter() ...@@ -21,14 +21,14 @@ router = APIRouter()
@router.get("/recharge/list") @router.get("/recharge/list")
def statement_recharge_list(page: Optional[int] = 0, size: Optional[int] = 10,order_number: Optional[str] = "",user_id: Optional[int] = "",sid: Optional[str]="",start_time:Optional[str]='',end_time:Optional[str]="",token=Depends(login_required)): def statement_recharge_list(page: Optional[int] = 0, size: Optional[int] = 10,order_number: Optional[str] = "",user_id: Optional[int] = "",sid: Optional[str]="",start_time:Optional[str]='',end_time:Optional[str]="",types:Optional[str]="",reference_type:Optional[str]="",month_type:Optional[int]="",token=Depends(login_required)):
"""充值报表列表""" """充值报表列表"""
total,statement_list,money= RechargeStatement().query_data(page,size,order_number,user_id,sid,start_time,end_time) total,statement_list,money= RechargeStatement().query_data(page,size,order_number,user_id,sid,start_time,end_time,types,reference_type,month_type)
return HttpResultResponse(total=total,count=float(money),data=statement_list) return HttpResultResponse(total=total,count=float(money),data=statement_list)
@router.post("/derive/excel") @router.post("/derive/excel")
def statement_derive_excel(data: schemas.StatementList, request: Request, db: Session = Depends(get_db)): def statement_derive_excel(data: schemas.StatementList, request: Request, db: Session = Depends(get_db),token=Depends(login_required)):
"""充值报表导出 需要修改""" """充值报表导出 需要修改"""
header_list = request.get("headers") header_list = request.get("headers")
statement_list = RechargeStatement().get_statements(data) statement_list = RechargeStatement().get_statements(data)
...@@ -36,17 +36,17 @@ def statement_derive_excel(data: schemas.StatementList, request: Request, db: Se ...@@ -36,17 +36,17 @@ def statement_derive_excel(data: schemas.StatementList, request: Request, db: Se
@router.get("/userWithdrawal/list") @router.get("/userWithdrawal/list")
def user_withdrawal_list(page: Optional[int] = 0, size: Optional[int] = 10,name:Optional[str]='',status:Optional[int]='',start_time:Optional[str]='',end_time:Optional[str]="",token=Depends(login_required)): def user_withdrawal_list(page: Optional[int] = 0, size: Optional[int] = 10,name:Optional[str]='',status:Optional[int]='',start_time:Optional[str]='',end_time:Optional[str]="",month_type:Optional[int]="",token=Depends(login_required)):
"""用户提现列表""" """用户提现列表"""
statement_list, total, money, final_money = WithdrawStatement().get_user_withdraw_cash(page,size,name,status,start_time,end_time) total,statement_list,money = WithdrawStatement(). get_user_withdraw_cash(page,size,name,status,start_time,end_time,month_type)
return HttpResultResponse(total=total, count=float(money), actual_count=final_money, data=statement_list) return HttpResultResponse(total=total, count=float(money), data=statement_list)
@router.get("/guildWithdrawal/list") @router.get("/guildWithdrawal/list")
def guild_withdrawal_list(page: Optional[int] = 0, size: Optional[int] = 10,guild_id:Optional[int]='',status:Optional[int]='',start_time:Optional[str]='',end_time:Optional[str]="", token=Depends(login_required)): def guild_withdrawal_list(page: Optional[int] = 0, size: Optional[int] = 10,guild_id:Optional[int]='',status:Optional[int]='',start_time:Optional[str]='',end_time:Optional[str]="", month_type:Optional[int]="",token=Depends(login_required)):
"""公会提现列表""" """公会提现列表 暂无"""
guild_list, total, money, final_money = WithdrawStatement().get_guild_withdraw_cash(page,size,guild_id,status,start_time,end_time) total,statement_list,money= WithdrawStatement(). get_guild_withdraw_cash(page,size,guild_id,status,start_time,end_time,month_type)
return HttpResultResponse(total=total, count=float(money), actual_count=final_money, data=guild_list) return HttpResultResponse(total=total, count=float(money), data=statement_list)
@router.get("/guild/settlement") @router.get("/guild/settlement")
......
...@@ -5,7 +5,8 @@ import time ...@@ -5,7 +5,8 @@ import time
import random import random
import uuid as u import uuid as u
from datetime import datetime, timedelta from datetime import datetime, timedelta
from datetime import datetime
from dateutil.relativedelta import relativedelta
import requests import requests
from core.config.env import env from core.config.env import env
...@@ -110,4 +111,14 @@ def search(params, method): ...@@ -110,4 +111,14 @@ def search(params, method):
def get_ip(): def get_ip():
res = socket.gethostbyname(socket.gethostname()) res = socket.gethostbyname(socket.gethostname())
return res return res
\ No newline at end of file
def get_month_last_month(month_type):
last_month=0
if month_type==2:
month_date = datetime.now().date() - relativedelta(months=1)
last_month = month_date.strftime("%Y%m")
now_month =datetime.now().strftime("%Y%m")
return last_month,now_month
\ No newline at end of file
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