Commit c59d6a49 authored by xianyang's avatar xianyang

优化业务类型汇总导出,余额查询

parent 875cb8bd
...@@ -46,11 +46,10 @@ class FinanceDetails(PublicModel): ...@@ -46,11 +46,10 @@ class FinanceDetails(PublicModel):
class FixTable(BaseModel): class FixTable(BaseModel):
type: int type: int
uuid: str = '' uuid: str
money: float money: float
amount_type: Optional[str] = "consumable" amount_type: Optional[str] = "consumable"
remark: str remark: str
unique_tag: Optional[str] = ""
class AccountTypeUpdate(BaseModel): class AccountTypeUpdate(BaseModel):
......
...@@ -75,17 +75,21 @@ class CalculationMonthlyBill(object): ...@@ -75,17 +75,21 @@ class CalculationMonthlyBill(object):
def month_statistics_task(self, date, key_type, name, page, size): def month_statistics_task(self, date, key_type, name, page, size):
"""主函数""" """主函数"""
if key_type and not name: assert_list = []
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{key_type}' GROUP BY reference_type, type ORDER BY reference_type" if name:
if name and not key_type: k_list = []
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{name}' GROUP BY reference_type, type ORDER BY reference_type"
for k, v in TYPE_NAME.items(): for k, v in TYPE_NAME.items():
if v == name: if v == name or name in v:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{k}' GROUP BY reference_type, type ORDER BY reference_type" k_list.append(k)
break if len(k_list) > 1:
if name and key_type: assert_list.append(f" reference_type in{tuple(k_list)}")
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{key_type}' GROUP BY reference_type, type ORDER BY reference_type" if len(k_list) == 1:
if not name and not key_type: assert_list.append(f" reference_type='{k_list[0]}'")
if key_type:
assert_list.append(f" reference_type like '%{key_type}%'")
if assert_list:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where {' and '.join(assert_list)} GROUP BY reference_type, type ORDER BY reference_type"
else:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} GROUP BY reference_type, type ORDER BY reference_type" sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} GROUP BY reference_type, type ORDER BY reference_type"
try: try:
res_data = LinkMysql(env.DB_HISTORY).query_mysql(sql) res_data = LinkMysql(env.DB_HISTORY).query_mysql(sql)
...@@ -172,19 +176,22 @@ class MonthDataDerive(object): ...@@ -172,19 +176,22 @@ class MonthDataDerive(object):
return StreamingResponse(file, media_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') return StreamingResponse(file, media_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
def derive_data(self, date, key_type, name): def derive_data(self, date, key_type, name):
assets_list = [] if key_type and not name:
if name:
assets_list.append(f" create_time <= {time_str_to_timestamp(start_time + ' 00:00:00')} ")
if key_type:
assets_list.append(f" create_time <= {time_str_to_timestamp(end_time + ' 23:59:59')} ")
if assets_list:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{key_type}' GROUP BY reference_type, type ORDER BY reference_type" sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{key_type}' GROUP BY reference_type, type ORDER BY reference_type"
else: if name and not key_type:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{name}' GROUP BY reference_type, type ORDER BY reference_type"
for k, v in TYPE_NAME.items():
if v == name:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{k}' GROUP BY reference_type, type ORDER BY reference_type"
break
if name and key_type:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} where reference_type='{key_type}' GROUP BY reference_type, type ORDER BY reference_type"
if not name and not key_type:
sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} GROUP BY reference_type, type ORDER BY reference_type" sql = f"SELECT reference_type, type, SUM(cast(amount as decimal(20,6)))/1000 as money FROM {date} GROUP BY reference_type, type ORDER BY reference_type"
try: try:
res_data = LinkMysql(env.DB_HISTORY).query_mysql(sql) res_data = LinkMysql(env.DB_HISTORY).query_mysql(sql)
except Exception as e: except Exception as e:
return [], 0 return []
for res in res_data: for res in res_data:
if res["reference_type"] in self.derive_key: if res["reference_type"] in self.derive_key:
continue continue
......
...@@ -96,7 +96,6 @@ def month_to_export(param: schemas.MonthStatistics, request: Request, token=Depe ...@@ -96,7 +96,6 @@ def month_to_export(param: schemas.MonthStatistics, request: Request, token=Depe
headers = request.get("headers") headers = request.get("headers")
if not param.date: if not param.date:
return HttpResultResponse(code=500, msg='查询月份不能为空') return HttpResultResponse(code=500, msg='查询月份不能为空')
result, num = crud.CalculationMonthlyBill().month_statistics_task('assets_log_' + param.date, param.type, param.name, result = crud.MonthDataDerive().derive_data('assets_log_' + param.date, param.type, param.name)
param.page, 999999)
field_head = ['业务名称', '财务编码类型', '出账金额', '入账金额', '是否异常', '异常金额'] field_head = ['业务名称', '财务编码类型', '出账金额', '入账金额', '是否异常', '异常金额']
return statement_crud.data_to_file(db, result, "业务类型汇总", headers, field_head) return statement_crud.data_to_file(db, result, "业务类型汇总", headers, field_head)
...@@ -233,12 +233,12 @@ def query_uuid_or_user_number(param): ...@@ -233,12 +233,12 @@ def query_uuid_or_user_number(param):
return {} return {}
def account_money(uuid): def account_money(uuid, amount_type):
"""查询账户余额""" """查询账户余额"""
platform_data = search({"uuid": uuid}, 'Server.UserQuery.GetUserAsset') platform_data = search({"uuid": uuid}, 'Server.UserQuery.GetUserAsset')
if platform_data['status']: if platform_data['status']:
try: try:
platform_money = platform_data['data']['result']['data']['asset_balance']['consumable']['current_amount'] platform_money = platform_data['data']['result']['data']['asset_balance'][amount_type]['current_amount']
except Exception as e: except Exception as e:
print(f"清算系统异常:{e}") print(f"清算系统异常:{e}")
platform_money = 0 platform_money = 0
...@@ -272,7 +272,7 @@ def transfer_trigger_task(uuid, user_id, balance, type, amount_type, remark='用 ...@@ -272,7 +272,7 @@ def transfer_trigger_task(uuid, user_id, balance, type, amount_type, remark='用
"reference_type": type, "reference_type": type,
"amount": balance, "amount": balance,
"timestamp": get_now_timestamp(), "timestamp": get_now_timestamp(),
"amount_type": 'consumable' if amount_type ==1 else 'withdrawable', "amount_type": amount_type if amount_type else 'consumable',
"notify_url": "" "notify_url": ""
} }
res = search(request_data, 'Server.UserExecute.Transfer') res = search(request_data, 'Server.UserExecute.Transfer')
...@@ -285,8 +285,9 @@ def transfer_trigger_task(uuid, user_id, balance, type, amount_type, remark='用 ...@@ -285,8 +285,9 @@ def transfer_trigger_task(uuid, user_id, balance, type, amount_type, remark='用
if res['status'] == 0: if res['status'] == 0:
errmsg = json.dumps(res['data']) errmsg = json.dumps(res['data'])
status = 3 status = 3
amount_type_id = 1 if amount_type == 'consumable' else 2
add_sql = f"insert into all_record_table(user_id, type, status, reference_number, remark, money, is_add, money_data,create_time,amount_type) " \ add_sql = f"insert into all_record_table(user_id, type, status, reference_number, remark, money, is_add, money_data,create_time,amount_type) " \
f"values({user_id}, '{type}', {status},'{get_order()}','{remark}', {balance * 10 if amount_type == 1 else balance * 100},1,'{json.dumps(money_data)}',{get_now_timestamp()},{amount_type});" f"values({user_id}, '{type}', {status},'{get_order()}','{remark}', {balance * 10 if amount_type == 'consumable' else balance * 100},1,'{json.dumps(money_data)}',{get_now_timestamp()},{amount_type_id});"
LinkMysql(env.DB_3YV2).perform_mysql(add_sql) LinkMysql(env.DB_3YV2).perform_mysql(add_sql)
return '' return ''
...@@ -294,12 +295,11 @@ def transfer_trigger_task(uuid, user_id, balance, type, amount_type, remark='用 ...@@ -294,12 +295,11 @@ def transfer_trigger_task(uuid, user_id, balance, type, amount_type, remark='用
def transfer_money(db: Session, param, h_list): def transfer_money(db: Session, param, h_list):
"""转账""" """转账"""
user_id = 0 user_id = 0
amount_type_dict = {'withdrawable': 2, 'consumable': 1}
if param.type == 0: # 系统转系统 if param.type == 0: # 系统转系统
out_sql = f"select name from fi_account where uuid='{param.dst_id}' limit 0,1" out_sql = f"select name from fi_account where uuid='{param.dst_id}' limit 0,1"
out = LinkMysql(env.DB_3YV2).query_mysql(out_sql) out = LinkMysql(env.DB_3YV2).query_mysql(out_sql)
dst_name = out[0]['name'] dst_name = out[0]['name']
amount_type = 1 amount_type = 'consumable'
if param.type == 1: # 系统转个人/公会 if param.type == 1: # 系统转个人/公会
out_sql = f"select name from fi_account where uuid='{param.dst_id}' limit 0,1" out_sql = f"select name from fi_account where uuid='{param.dst_id}' limit 0,1"
out = LinkMysql(env.DB_3YV2).query_mysql(out_sql) out = LinkMysql(env.DB_3YV2).query_mysql(out_sql)
...@@ -309,7 +309,7 @@ def transfer_money(db: Session, param, h_list): ...@@ -309,7 +309,7 @@ def transfer_money(db: Session, param, h_list):
if income: if income:
user_id = income[0]['user_id'] user_id = income[0]['user_id']
dst_name = out[0]['name'] dst_name = out[0]['name']
amount_type = amount_type_dict.get(param.transfer_type) if amount_type_dict.get(param.transfer_type) else 1 amount_type = param.transfer_type if param.transfer_type else 'consumable'
if param.type == 2: # 个人/公会转系统 if param.type == 2: # 个人/公会转系统
out_sql = f"select nick_name from v2_user where uuid='{param.dst_id}' limit 0,1" out_sql = f"select nick_name from v2_user where uuid='{param.dst_id}' limit 0,1"
out = LinkMysql(env.DB_3YV2).query_mysql(out_sql) out = LinkMysql(env.DB_3YV2).query_mysql(out_sql)
...@@ -319,7 +319,7 @@ def transfer_money(db: Session, param, h_list): ...@@ -319,7 +319,7 @@ def transfer_money(db: Session, param, h_list):
out_guild_sql = f"select guild_name from guild where uuid='{param.transfer_id}'" out_guild_sql = f"select guild_name from guild where uuid='{param.transfer_id}'"
out_guild = LinkMysql(env.DB_3YV2).query_mysql(out_guild_sql) out_guild = LinkMysql(env.DB_3YV2).query_mysql(out_guild_sql)
dst_name = out_guild[0]['guild_name'] if out_guild else param.transfer_id dst_name = out_guild[0]['guild_name'] if out_guild else param.transfer_id
amount_type = amount_type_dict.get(param.transfer_type) if amount_type_dict.get(param.transfer_type) else 1 amount_type = param.transfer_type if param.transfer_type else 'consumable'
try: try:
# 转账 # 转账
...@@ -338,15 +338,9 @@ def transfer_money(db: Session, param, h_list): ...@@ -338,15 +338,9 @@ def transfer_money(db: Session, param, h_list):
def create_fix_table(db: Session, param, h_list): def create_fix_table(db: Session, param, h_list):
"""增加修复报表""" """增加修复报表"""
uuid = param.uuid
unique_res = []
if param.type == 0:
acc_sql = f"select unique_tag,uuid from fi_account where unique_tag='{param.unique_tag}'"
unique_res = LinkMysql(env.DB_3YV2).query_mysql(acc_sql)
uuid = unique_res[0]['uuid']
if param.amount_type == 'backpack': if param.amount_type == 'backpack':
guild_sql = f"select count(id) as num from guild where uuid='{uuid}'" guild_sql = f"select count(id) as num from guild where uuid='{param.uuid}'"
user_sql = f"select user_id,nick_name,user_number from v2_user where uuid='{uuid}'" user_sql = f"select user_id,nick_name,user_number from v2_user where uuid='{param.uuid}'"
with ThreadPoolExecutor(max_workers=2) as pool: with ThreadPoolExecutor(max_workers=2) as pool:
future1 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, guild_sql) future1 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, guild_sql)
future2 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, user_sql) future2 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, user_sql)
...@@ -369,7 +363,7 @@ def create_fix_table(db: Session, param, h_list): ...@@ -369,7 +363,7 @@ def create_fix_table(db: Session, param, h_list):
method = 'Server.BaseExecute.Increase' method = 'Server.BaseExecute.Increase'
data = { data = {
"ip": ip, "ip": ip,
"dst_uuid": uuid, "dst_uuid": param.uuid,
"dst_amount_type": param.amount_type, "dst_amount_type": param.amount_type,
"amount": param.money, "amount": param.money,
"fee": 0, "fee": 0,
...@@ -382,7 +376,7 @@ def create_fix_table(db: Session, param, h_list): ...@@ -382,7 +376,7 @@ def create_fix_table(db: Session, param, h_list):
method = 'Server.BaseExecute.Reduce' method = 'Server.BaseExecute.Reduce'
data = { data = {
"ip": ip, "ip": ip,
"src_uuid": uuid, "src_uuid": param.uuid,
"src_amount_type": param.amount_type, "src_amount_type": param.amount_type,
"amount": param.money, "amount": param.money,
"fee": 0, "fee": 0,
...@@ -394,7 +388,11 @@ def create_fix_table(db: Session, param, h_list): ...@@ -394,7 +388,11 @@ def create_fix_table(db: Session, param, h_list):
clearing_res = search(data, method) clearing_res = search(data, method)
print(clearing_res) print(clearing_res)
if clearing_res['status']: if clearing_res['status']:
unique_tag = unique_res[0]['unique_tag'] if unique_res else uuid unique_res = []
if param.type == 0:
acc_sql = f"select unique_tag from fi_account where uuid='{param.uuid}'"
unique_res = LinkMysql(env.DB_3YV2).query_mysql(acc_sql)
unique_tag = unique_res[0]['unique_tag'] if unique_res else param.uuid
user = query_token(db, h_list) user = query_token(db, h_list)
try: try:
insert_fix_sql = f"insert into finance_fix_log(type, money, create_time, unique_tag, amount_type, remark, operator,operator_id) " \ insert_fix_sql = f"insert into finance_fix_log(type, money, create_time, unique_tag, amount_type, remark, operator,operator_id) " \
......
...@@ -102,11 +102,11 @@ def out_on_account(page: int, ...@@ -102,11 +102,11 @@ def out_on_account(page: int,
@router.get("/query/consumable") @router.get("/query/consumable")
def query_account_money(uuid: str, token=Depends(login_required)): def query_account_money(uuid: str, amount_type: Optional[str] = "consumable", token=Depends(login_required)):
"""查询账户余额""" """查询账户余额"""
if not uuid: if not uuid:
return HttpResultResponse(code=500, msg='请输入uuid') return HttpResultResponse(code=500, msg='请输入uuid')
consumable = account_money(uuid) consumable = account_money(uuid, amount_type)
return HttpResultResponse(data=consumable) return HttpResultResponse(data=consumable)
...@@ -154,7 +154,7 @@ def finance_fix(page: int, ...@@ -154,7 +154,7 @@ def finance_fix(page: int,
def finance_fix(data: acc_schemas.FixTable, request: Request, def finance_fix(data: acc_schemas.FixTable, request: Request,
token=Depends(login_required), db: Session = Depends(get_db)): token=Depends(login_required), db: Session = Depends(get_db)):
"""新增修复报表""" """新增修复报表"""
if not all([data.money, data.amount_type, data.remark]): if not all([data.money, data.uuid, data.amount_type, data.remark]):
return HttpResultResponse(code=500, msg='缺少必传参数') return HttpResultResponse(code=500, msg='缺少必传参数')
header_list = request.get("headers") header_list = request.get("headers")
res = guild.create_fix_table(db, data, header_list) res = guild.create_fix_table(db, data, header_list)
......
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