Commit 5540ed9e authored by xianyang's avatar xianyang

优化账户余额

parent 4c079e49
......@@ -9,7 +9,7 @@ from app.api.account import schemas
from core.config.env import env
from libs.db_link import LinkMysql
from libs.functions import wrapper_out, get_now_timestamp, uuid, get_before_timestamp, time_str_to_timestamp, \
get_yesterday_timestamp
get_yesterday_timestamp, search
from libs.orm import QueryAllData
from models import account as models
from models.account import AccountFinance, AccountFinanceDetails, AccountType
......@@ -45,21 +45,32 @@ class HDUd():
start, end = get_yesterday_timestamp()
if i['unique_tag'] == 'guild_account':
sql = f"select sum(initial_money) as number from v3_guild_account_statistics where create_time>={start} and create_time<{end}"
money_res = LinkMysql(env.DB_3YV2).query_mysql(sql)
i['consumable'] = money_res[0]['number'] if money_res and money_res[0]['number'] else 0
elif i['unique_tag'] == 'anchor_account':
sql = f"select sum(initial_money) as number from v3_user_account_statistics where date>={start} and date<{end}"
money_res = LinkMysql(env.DB_3YV2).query_mysql(sql)
i['consumable'] = money_res[0]['number'] if money_res and money_res[0]['number'] else 0
elif i['unique_tag'] == 'user_account':
sql = f"select sum(initial_money) as number from finance_data_calculation_sum where type=1 and calculation_time>={start} and calculation_time<{end}"
money_res = LinkMysql(env.DB_3YV2).query_mysql(sql)
i['consumable'] = money_res[0]['number'] if money_res and money_res[0]['number'] else 0
elif i['unique_tag'] == 'knapsack_account':
sql = f"select sum(initial_money) as number from finance_data_calculation_sum where type=4 and calculation_time>={start} and calculation_time<{end}"
money_res = LinkMysql(env.DB_3YV2).query_mysql(sql)
i['consumable'] = money_res[0]['number'] if money_res and money_res[0]['number'] else 0
elif i['unique_tag'] == 'pledgeDeduction':
sql = f"select sum(initial_money) as number from finance_data_calculation_sum where type=5 and calculation_time>={start} and calculation_time<{end}"
money_res = LinkMysql(env.DB_3YV2).query_mysql(sql)
i['consumable'] = money_res[0]['number'] if money_res and money_res[0]['number'] else 0
else:
sql = f"select sum(initial_money) as number from v2_system_account_statistics where create_time>={start} and create_time<{end}"
money_res = LinkMysql(env.DB_3YV2).query_mysql(sql)
if money_res and money_res[0]['number']:
i['consumable'] = money_res[0]['number']
else:
i['consumable'] = 0
platform_data = search({"uuid": i['uuid']}, 'Server.UserQuery.GetUserAsset')
if platform_data['status']:
try:
i['consumable'] = platform_data['data']['result']['data']['asset_balance']['consumable']['current_amount']
except Exception as e:
print(e)
i['consumable'] = 0
else:
i['consumable'] = 0
self.result_list.append(i)
......@@ -153,49 +164,49 @@ def get_finance_info(unique_tag, page, size, start_time, end_time, is_list=None)
finance_condition.append(f"create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
if unique_tag == 'guild_account':
if finance_condition:
count_sql = f"select count(id) as num from v3_guild_account_statistics_copy where {' and '.join(finance_condition)} GROUP BY create_time"
count_sql = f"select calculation_time from v3_guild_account_statistics_copy where {' and '.join(finance_condition)} GROUP BY create_time"
data_sql = f"select id,initial_money as balance,income,outcome,create_time from v3_guild_account_statistics_copy where {' and '.join(finance_condition)} GROUP BY create_time order by create_time DESC limit {(int(page) - 1) * size},{size}"
else:
count_sql = f"select count(id) as num from v3_guild_account_statistics_copy GROUP BY create_time"
count_sql = f"select calculation_time from v3_guild_account_statistics_copy GROUP BY create_time"
data_sql = f"select id,initial_money as balance,income,outcome,create_time from v3_guild_account_statistics_copy GROUP BY create_time order by create_time DESC limit {(int(page) - 1) * size},{size}"
elif unique_tag == 'anchor_account':
if finance_condition:
condition = [i.replace('create_time', 'date') for i in finance_condition]
count_sql = f"select count(id) as num from v3_user_account_statistics where type=2 and {' and '.join(condition)} GROUP BY calculation_time"
count_sql = f"select calculation_time from v3_user_account_statistics where type=2 and {' and '.join(condition)} GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance, income,pay as outcome,date as create_time from v3_user_account_statistics where type=2 and {' and '.join(condition)} GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
else:
count_sql = f"select count(id) as num from v3_user_account_statistics where type=2 GROUP BY calculation_time"
count_sql = f"select calculation_time from v3_user_account_statistics where type=2 GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance, income,pay as outcome,date as create_time from v3_user_account_statistics where type=2 GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
elif unique_tag == 'user_account':
if finance_condition:
condition = [i.replace('create_time', 'calculation_time') for i in finance_condition]
count_sql = f"select count(id) as num from finance_data_calculation_sum where type=1 and {' and '.join(condition)} GROUP BY calculation_time"
count_sql = f"select calculation_time from finance_data_calculation_sum where type=1 and {' and '.join(condition)} GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum where type=1 and {' and '.join(condition)} GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
else:
count_sql = f"select count(id) as num from finance_data_calculation_sum where type=1 GROUP BY calculation_time"
count_sql = f"select calculation_time from finance_data_calculation_sum where type=1 GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum where type=1 GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
elif unique_tag == 'knapsack_account':
if finance_condition:
condition = [i.replace('create_time', 'calculation_time') for i in finance_condition]
count_sql = f"select count(id) as num from finance_data_calculation_sum where type=4 and {' and '.join(condition)} GROUP BY calculation_time"
count_sql = f"select calculation_time from finance_data_calculation_sum where type=4 and {' and '.join(condition)} GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum where type=4 and {' and '.join(condition)} GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
else:
count_sql = f"select count(id) as num from finance_data_calculation_sum where type=4 GROUP BY calculation_time"
count_sql = f"select calculation_time from finance_data_calculation_sum where type=4 GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum where type=4 GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
elif unique_tag == 'pledgeDeduction':
if finance_condition:
condition = [i.replace('create_time', 'calculation_time') for i in finance_condition]
count_sql = f"select count(id) as num from finance_data_calculation_sum where type=5 and {' and '.join(condition)} GROUP BY calculation_time"
count_sql = f"select calculation_time from finance_data_calculation_sum where type=5 and {' and '.join(condition)} GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum where type=5 and {' and '.join(condition)} GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
else:
count_sql = f"select count(id) as num from finance_data_calculation_sum where type=5 GROUP BY calculation_time"
count_sql = f"select calculation_time from finance_data_calculation_sum where type=5 GROUP BY calculation_time"
data_sql = f"select id,initial_money as balance,income,outcome,calculation_time as create_time from finance_data_calculation_sum where type=5 GROUP BY calculation_time order by calculation_time DESC limit {(int(page) - 1) * size},{size}"
else:
if finance_condition:
count_sql = f"select count(id) as num from v2_system_account_statistics where {' and '.join(finance_condition)} GROUP BY create_time"
count_sql = f"select create_time from v2_system_account_statistics where {' and '.join(finance_condition)} GROUP BY create_time"
data_sql = f"select id,initial_money as balance,income,outcome,create_time from v2_system_account_statistics where {' and '.join(finance_condition)} GROUP BY create_time order by create_time DESC limit {(int(page) - 1) * size},{size}"
else:
count_sql = f"select count(id) as num from v2_system_account_statistics GROUP BY create_time"
count_sql = f"select create_time from v2_system_account_statistics GROUP BY create_time"
data_sql = f"select id,initial_money as balance,income,outcome,create_time from v2_system_account_statistics GROUP BY create_time order by create_time DESC limit {(int(page) - 1) * size},{size}"
with ThreadPoolExecutor(max_workers=2) as pool:
future1 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, count_sql)
......@@ -204,7 +215,7 @@ def get_finance_info(unique_tag, page, size, start_time, end_time, is_list=None)
res = future2.result()
# 判断是列表还是导出接口
if is_list:
return res, count[0]
return res, len(count)
else:
return res
......
......@@ -54,15 +54,15 @@ def finance_information(unique_tag: str,
end_time: Optional[str] = "",
token=Depends(login_required)):
# unique_tag:Optional[str] = Query(None, min_length=3, max_length=50, regex="^xiao\d+$") 参数验证
"""账户财务信息"""
"""账户财务详情"""
res, total = crud.get_finance_info(unique_tag, page, size, start_time, end_time, 1)
return HttpResultResponse(total=total.get("num"), data=res)
return HttpResultResponse(total=total, data=res)
@router.post("/finance/info/excel")
def finance_info_excel(data: schemas.FinanceInfo, request: Request,
token=Depends(login_required), db: Session = Depends(get_db)):
"""账户财务信息导出"""
"""账户财务详情导出"""
headers = request.get("headers")
statement_list = crud.get_finance_info(data.unique_tag, data.page, data.size, data.start_time, data.end_time)
df = ['表id', '金额', '入账', '出账', '时间']
......@@ -78,7 +78,7 @@ def finance_details(page: int,
type: Optional[int] = None,
gift_type: Optional[str] = "",
token=Depends(login_required)):
"""账户财务详情"""
"""账户财务明细"""
res, total, count = crud.get_finance_details(page, size, uuid, start_time, end_time, type, gift_type, is_list=1)
return HttpResultResponse(total=total, data=res, count=count)
......@@ -86,7 +86,7 @@ def finance_details(page: int,
@router.post("/finance/details/excel")
def finance_info_excel(data: schemas.FinanceDetails, request: Request,
token=Depends(login_required), db: Session = Depends(get_db)):
"""账户财务详情导出"""
"""账户财务明细导出"""
headers = request.get("headers")
statement_list = crud.get_finance_details(data.page, data.size, data.uuid, data.start_time, data.end_time, data.type, data.gift_type)
field_head = ['订单号', '出入账方式', '礼物类型', '金额', '时间']
......
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