Commit 000df4fc authored by xupeng's avatar xupeng

查询新增实得总金额

parent 16f0204d
...@@ -101,7 +101,7 @@ def month_to_export(param: schemas.MonthStatistics, request: Request, token=Depe ...@@ -101,7 +101,7 @@ def month_to_export(param: schemas.MonthStatistics, request: Request, token=Depe
@router.get("/referenceType/total") @router.get("/referenceType/total")
def reference_type_total(date: str, type: str, token=Depends(login_required)): def reference_type_total(date: str, type: str):
"""消费类型分类汇总""" """消费类型分类汇总"""
if not all([date, type]): if not all([date, type]):
return HttpResultResponse(code=500, msg='缺少必传参数') return HttpResultResponse(code=500, msg='缺少必传参数')
......
...@@ -62,7 +62,7 @@ class RechargeStatement(object): ...@@ -62,7 +62,7 @@ class RechargeStatement(object):
# self.once_res=[] # self.once_res=[]
# self.moeny_data=[] # self.moeny_data=[]
def query_data(self, db, page, size, order_number, uuid, sid, start_time, end_time, type, menu_id, month_type): def query_data(self, db, page, size, order_number, uuid, sid, start_time, end_time, type, menu_id, month_type,export_status):
"""列表""" """列表"""
query = [] query = []
if order_number: if order_number:
...@@ -98,10 +98,10 @@ class RechargeStatement(object): ...@@ -98,10 +98,10 @@ class RechargeStatement(object):
query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ") query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
query = ' and '.join(query) query = ' and '.join(query)
now_month = get_month_last_month(month_type,start_time,end_time) now_month = get_month_last_month(month_type,start_time,end_time)
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],export_status)
else: else:
query_data = self.query_add_time(start_time, end_time, query) query_data = self.query_add_time(start_time, end_time, query)
count, once_res, moeny_data = self.thread_data(month_type, query_data, page, size,start_time,end_time) count, once_res, moeny_data = self.thread_data(month_type, query_data, page, size,start_time,end_time,export_status)
return count, once_res, moeny_data return count, once_res, moeny_data
def query_add_time(self, start_time, end_time, old_query): def query_add_time(self, start_time, end_time, old_query):
...@@ -119,32 +119,46 @@ class RechargeStatement(object): ...@@ -119,32 +119,46 @@ class RechargeStatement(object):
data.append(query1) data.append(query1)
return data return data
def statistics_data(self, month_type, query, page, size, now_month): def statistics_data(self, month_type, query, page, size, now_month,export_status):
'''统计''' '''统计'''
if month_type == 1: if month_type == 1:
count_sql = f"SELECT count(*) FROM assets_log_{now_month} where {query}" if export_status:
count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)") sql = f"SELECT a.id,a.uuid,a.amount/1000 as amount,FROM_UNIXTIME(a.create_time) as payment_time,a.reference_type,a.reference_number FROM assets_log_{now_month} as a where {query} ORDER BY id desc"
sql = f"SELECT a.id,a.uuid,a.amount/1000 as amount,FROM_UNIXTIME(a.create_time) 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}" once_res = self.linkmysql.query_mysql(sql)
once_res = self.linkmysql.query_mysql(sql) count=0
money_sql = f"SELECT sum(amount) FROM assets_log_{now_month} where {query}" moeny_data=1000
moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(amount)") if \ else:
self.linkmysql.query_mysql(money_sql)[0].get("sum(amount)") != None else 0 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 a.id,a.uuid,a.amount/1000 as amount,FROM_UNIXTIME(a.create_time) 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}"
once_res = self.linkmysql.query_mysql(sql)
money_sql = f"SELECT sum(amount) FROM assets_log_{now_month} where {query}"
moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(amount)") if \
self.linkmysql.query_mysql(money_sql)[0].get("sum(amount)") != None else 0
else: 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 " if export_status:
count = self.linkmysql.query_mysql(count_sql)[0].get("sum(a.b)") query1 = (' and '.join(query[0]))
query1 = (' and '.join(query[0])) query2 = (' and '.join(query[1]))
query2 = (' and '.join(query[1])) sql = f"SELECT id,uuid,(amount/1000) as amount as amount,FROM_UNIXTIME(create_time) as payment_time,reference_type,reference_number FROM assets_log_{int(now_month[0])} where {query1} UNION ALL SELECT id,uuid,amount/1000 as amount,FROM_UNIXTIME(create_time) as payment_time,reference_type,reference_number FROM assets_log_{int(now_month[1])} where {query2} ORDER BY payment_time"
sql = f"SELECT id,uuid,amount/1000 as amount,FROM_UNIXTIME(create_time) as payment_time,reference_type,reference_number FROM assets_log_{int(now_month[0])} where {query1} UNION ALL SELECT id,uuid,amount/1000 as amount,FROM_UNIXTIME(create_time) as payment_time,reference_type,reference_number FROM assets_log_{int(now_month[1])} where {query2} ORDER BY payment_time desc limit {(int(page) - 1) * size},{size}" once_res = self.linkmysql.query_mysql(sql)
once_res = self.linkmysql.query_mysql(sql) count = 0
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 = 1000
moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(a.b)") if \ else:
self.linkmysql.query_mysql(money_sql)[0].get("sum(a.b)") != None else 0 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]))
sql = f"SELECT id,uuid,(amount/1000) as amount as amount,FROM_UNIXTIME(create_time) as payment_time,reference_type,reference_number FROM assets_log_{int(now_month[0])} where {query1} UNION ALL SELECT id,uuid,amount/1000 as amount,FROM_UNIXTIME(create_time) as payment_time,reference_type,reference_number FROM assets_log_{int(now_month[1])} where {query2} ORDER BY payment_time 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 "
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/1000 return count, once_res, moeny_data/1000
def thread_data(self, month_type, query, page, size,start_time,end_time): def thread_data(self, month_type, query, page, size,start_time,end_time,export_status):
now_month = get_month_last_month(month_type,start_time,end_time) now_month = get_month_last_month(month_type,start_time,end_time)
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,export_status)
return count, once_res, moeny_data return count, once_res, moeny_data
def get_statements(self, db, data): def get_statements(self, db, data):
...@@ -250,31 +264,42 @@ class WithdrawStatement(object): ...@@ -250,31 +264,42 @@ class WithdrawStatement(object):
query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ") query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
query = ' and '.join(query) query = ' and '.join(query)
now_month = get_month_last_month(month_type,start_time,end_time) now_month = get_month_last_month(month_type,start_time,end_time)
count, once_res, moeny_data = self.dispose_user(month_type, query, page, size, now_month[1]) count, once_res, moeny_data,reality_moeny = self.dispose_user(month_type, query, page, size, now_month[1])
else: else:
query_data = self.query_add_time(query,start_time, end_time) query_data = self.query_add_time(query,start_time, end_time)
now_month = get_month_last_month(month_type,start_time,end_time) now_month = get_month_last_month(month_type,start_time,end_time)
count, once_res, moeny_data = self.dispose_user(month_type, query_data, page, size, now_month) count, once_res, moeny_data,reality_moeny = self.dispose_user(month_type, query_data, page, size, now_month)
return count, once_res, moeny_data return count, once_res, moeny_data,reality_moeny
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: if month_type == 1:
count_sql = f"SELECT count(*) FROM assets_log_{now_month} where {query}" count_sql = f"SELECT count(*) FROM assets_log_{now_month} where {query}"
count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)") count = self.linkmysql.query_mysql(count_sql)[0].get("count(*)")
sql = f'SELECT uuid,amount,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}' sql = f'SELECT uuid,(amount/1000) as amount,a.reference_type,a.reference_number,FROM_UNIXTIME(a.create_time) 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}'
once_res = self.linkmysql.query_mysql(sql) once_res = self.linkmysql.query_mysql(sql)
money_sql = f"SELECT sum(amount) FROM assets_log_{now_month} where {query} " money_sql = f"SELECT sum(amount) FROM assets_log_{now_month} where {query} "
moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(amount)") if \ moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(amount)") if \
self.linkmysql.query_mysql(money_sql)[0].get("sum(amount)") != None else 0 self.linkmysql.query_mysql(money_sql)[0].get("sum(amount)") != None else 0
query_type=query.replace('type = 0','type = 1') #收入
income_sql = f"SELECT sum(amount) FROM assets_log_{now_month} where {query_type} "
moeny_income = self.linkmysql.query_mysql(income_sql)[0].get("sum(amount)") if \
self.linkmysql.query_mysql(income_sql)[0].get("sum(amount)") != None else 0
reality_moeny=moeny_data-abs(moeny_income)
else: else:
count_sql = "SELECT sum(a.b) FROM ("f"SELECT count(*) as b FROM assets_log_{int(now_month[0])} where {(' and '.join(query))} UNION ALL SELECT count(*) FROM assets_log_{int(now_month[1])} where {(' and '.join(query))}) AS a " count_sql = "SELECT sum(a.b) FROM ("f"SELECT count(*) as b FROM assets_log_{int(now_month[0])} where {(' and '.join(query))} UNION ALL SELECT count(*) FROM assets_log_{int(now_month[1])} where {(' and '.join(query))}) AS a "
count = self.linkmysql.query_mysql(count_sql)[0].get("sum(a.b)") count = self.linkmysql.query_mysql(count_sql)[0].get("sum(a.b)")
sql = f"SELECT id,uuid,amount,amount_type, 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 {(' and '.join(query))} UNION ALL SELECT id,uuid,amount,amount_type, 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 {(' and '.join(query))} ORDER BY id desc limit {(int(page) - 1) * size},{size}" sql = f"SELECT id,uuid,(amount/1000) as amount ,amount_type, FROM_UNIXTIME(create_time) as payment_time,reference_type,reference_number FROM assets_log_{int(now_month[0])} where {(' and '.join(query))} UNION ALL SELECT id,uuid,amount,amount_type, FROM_UNIXTIME(create_time) as payment_time,reference_type,reference_number FROM assets_log_{int(now_month[1])} where {(' and '.join(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(a.b) FROM ("f"SELECT sum(amount) as b FROM assets_log_{int(now_month[0])} where {(' and '.join(query))} UNION ALL SELECT sum(amount)FROM assets_log_{int(now_month[1])} where {(' and '.join(query))} ) AS a " 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))} UNION ALL SELECT sum(amount)FROM assets_log_{int(now_month[1])} where {(' and '.join(query))} ) AS a "
moeny_data = self.linkmysql.query_mysql(money_sql)[0].get("sum(a.b)") if \ 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 self.linkmysql.query_mysql(money_sql)[0].get("sum(a.b)") != None else 0
return count, once_res, moeny_data query[1] = 'type = 1' #收入
income_sql = f"SELECT sum(a.b) FROM ("f"SELECT sum(amount) as b FROM assets_log_{int(now_month[0])} where {(' and '.join(query))} UNION ALL SELECT sum(amount)FROM assets_log_{int(now_month[1])} where {(' and '.join(query))} ) AS a "
moeny_income = self.linkmysql.query_mysql(income_sql)[0].get("sum(a.b)") if \
self.linkmysql.query_mysql(income_sql)[0].get("sum(a.b)") != None else 0
reality_moeny=moeny_data-abs(moeny_income)
return count, once_res, moeny_data,reality_moeny
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):
"""公会提现""" """公会提现"""
...@@ -312,12 +337,12 @@ class WithdrawStatement(object): ...@@ -312,12 +337,12 @@ class WithdrawStatement(object):
query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ") query.append(f" create_time < {time_str_to_timestamp(end_time + ' 23:59:59')} ")
query = ' and '.join(query) query = ' and '.join(query)
now_month = get_month_last_month(month_type,start_time,end_time) now_month = get_month_last_month(month_type,start_time,end_time)
count, once_res, moeny_data = self.dispose_user(month_type, query, page, size, now_month[1]) count, once_res, moeny_data,reality_moeny = self.dispose_user(month_type, query, page, size, now_month[1])
else: else:
query_data = self.query_add_time(query,start_time, end_time) query_data = self.query_add_time(query,start_time, end_time)
now_month = get_month_last_month(month_type,start_time,end_time) now_month = get_month_last_month(month_type,start_time,end_time)
count, once_res, moeny_data = self.dispose_user(month_type, query_data, page, size, now_month) count, once_res, moeny_data,reality_moeny = self.dispose_user(month_type, query_data, page, size, now_month)
return count, once_res, moeny_data return count, once_res, moeny_data,reality_moeny
class FinanceFix(object): class FinanceFix(object):
......
...@@ -500,7 +500,7 @@ def transfer_query(data): ...@@ -500,7 +500,7 @@ def transfer_query(data):
platform=LinkMysql(env.DB_3YV2).perform_mysql(payment_sql) platform=LinkMysql(env.DB_3YV2).perform_mysql(payment_sql)
params = {} params = {}
referNum=f'platomOutMoney_{platform}' referNum=f'platomOutMoney_{platform}'
reference_type='finance_admin_fix' reference_type='Payment'
uuid =data.uuid uuid =data.uuid
ip=get_ip() ip=get_ip()
money=data.money * -1 if data.money < 0 else data.money money=data.money * -1 if data.money < 0 else data.money
......
...@@ -27,7 +27,7 @@ def statement_recharge_list(request: Request,db: Session = Depends(get_db),page: ...@@ -27,7 +27,7 @@ def statement_recharge_list(request: Request,db: Session = Depends(get_db),page:
return HttpResultResponse(code=500, msg='时间为必传参数') return HttpResultResponse(code=500, msg='时间为必传参数')
query_params = request.query_params query_params = request.query_params
menu_id=query_params.getlist("menu_id[]") menu_id=query_params.getlist("menu_id[]")
total,statement_list,money= RechargeStatement().query_data(db,page,size,order_number,uuid,sid,start_time,end_time,types,menu_id,month_type) total,statement_list,money= RechargeStatement().query_data(db,page,size,order_number,uuid,sid,start_time,end_time,types,menu_id,month_type,'')
return HttpResultResponse(total=total,count=float(money),data=statement_list) return HttpResultResponse(total=total,count=float(money),data=statement_list)
...@@ -35,9 +35,10 @@ def statement_recharge_list(request: Request,db: Session = Depends(get_db),page: ...@@ -35,9 +35,10 @@ def statement_recharge_list(request: Request,db: Session = Depends(get_db),page:
def statement_derive_excel(request:Request,data: schemas.StatementList,db: Session = Depends(get_db),token=Depends(login_required)): def statement_derive_excel(request:Request,data: schemas.StatementList,db: Session = Depends(get_db),token=Depends(login_required)):
"""充值报表导出""" """充值报表导出"""
header_list = request.get("headers") header_list = request.get("headers")
export_status =1
total,statement_list,money= RechargeStatement().query_data(db, data.page, data.size, data.order_number, data.uuid, total,statement_list,money= RechargeStatement().query_data(db, data.page, data.size, data.order_number, data.uuid,
data.sid, data.start_time, data.end_time, data.types, data.sid, data.start_time, data.end_time, data.types,
data.menu_id, data.month_type) data.menu_id, data.month_type,export_status)
field_list = ["id", "uuid", "充值金额(元)", "支付时间", "类型", "订单号"] field_list = ["id", "uuid", "充值金额(元)", "支付时间", "类型", "订单号"]
return crud.data_to_file(db, statement_list, "充值报表", header_list, field_list) return crud.data_to_file(db, statement_list, "充值报表", header_list, field_list)
...@@ -47,8 +48,8 @@ def user_withdrawal_list(request:Request,db: Session = Depends(get_db),page: Opt ...@@ -47,8 +48,8 @@ def user_withdrawal_list(request:Request,db: Session = Depends(get_db),page: Opt
"""用户提现列表""" """用户提现列表"""
query_params = request.query_params query_params = request.query_params
menu_id = query_params.getlist("menu_id[]") menu_id = query_params.getlist("menu_id[]")
total,statement_list,money = WithdrawStatement(). get_user_withdraw_cash(db,page,size,uuid,status,start_time,end_time,month_type,menu_id) total,statement_list,money,reality_moeny = WithdrawStatement(). get_user_withdraw_cash(db,page,size,uuid,status,start_time,end_time,month_type,menu_id)
return HttpResultResponse(total=total, count=float(money), data=statement_list) return HttpResultResponse(total=total, count=float(money), data=statement_list,reality_moeny=reality_moeny)
@router.get("/guildWithdrawal/list") @router.get("/guildWithdrawal/list")
...@@ -56,8 +57,8 @@ def guild_withdrawal_list(request:Request,db: Session = Depends(get_db),page: Op ...@@ -56,8 +57,8 @@ def guild_withdrawal_list(request:Request,db: Session = Depends(get_db),page: Op
"""公会提现列表 暂无""" """公会提现列表 暂无"""
query_params=request.query_params query_params=request.query_params
menu_id=query_params.getlist("menu_id[]") menu_id=query_params.getlist("menu_id[]")
total,statement_list,money= WithdrawStatement(). get_guild_withdraw_cash(db,page,size,guild_id,status,start_time,end_time,month_type,menu_id) total,statement_list,money,reality_moeny= WithdrawStatement(). get_guild_withdraw_cash(db,page,size,guild_id,status,start_time,end_time,month_type,menu_id)
return HttpResultResponse(total=total, count=float(money), data=statement_list) return HttpResultResponse(total=total, count=float(money), data=statement_list,reality_moeny=reality_moeny)
@router.get("/guild/settlement") @router.get("/guild/settlement")
......
...@@ -113,10 +113,8 @@ def search(params, method): ...@@ -113,10 +113,8 @@ def search(params, method):
if response.status_code != 200: if response.status_code != 200:
return {} return {}
text = json.loads(response.text) text = json.loads(response.text)
if text.get("data").get("result").get("msg")=='success': print(text)
return True return text
else:
return False
def get_ip(): def get_ip():
......
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