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
@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]):
return HttpResultResponse(code=500, msg='缺少必传参数')
......
......@@ -62,7 +62,7 @@ class RechargeStatement(object):
# 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):
def query_data(self, db, page, size, order_number, uuid, sid, start_time, end_time, type, menu_id, month_type,export_status):
"""列表"""
query = []
if order_number:
......@@ -98,10 +98,10 @@ class RechargeStatement(object):
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,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:
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
def query_add_time(self, start_time, end_time, old_query):
......@@ -119,9 +119,15 @@ 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,export_status):
'''统计'''
if month_type == 1:
if export_status:
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"
once_res = self.linkmysql.query_mysql(sql)
count=0
moeny_data=1000
else:
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}"
......@@ -130,21 +136,29 @@ class RechargeStatement(object):
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:
if export_status:
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"
once_res = self.linkmysql.query_mysql(sql)
count = 0
moeny_data = 1000
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]))
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}"
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
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)
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
def get_statements(self, db, data):
......@@ -250,31 +264,42 @@ class WithdrawStatement(object):
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,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:
query_data = self.query_add_time(query,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)
return count, once_res, moeny_data
count, once_res, moeny_data,reality_moeny = self.dispose_user(month_type, query_data, page, size, now_month)
return count, once_res, moeny_data,reality_moeny
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}"
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)
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
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:
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)")
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)
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 \
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):
"""公会提现"""
......@@ -312,12 +337,12 @@ class WithdrawStatement(object):
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,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:
query_data = self.query_add_time(query,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)
return count, once_res, moeny_data
count, once_res, moeny_data,reality_moeny = self.dispose_user(month_type, query_data, page, size, now_month)
return count, once_res, moeny_data,reality_moeny
class FinanceFix(object):
......
......@@ -500,7 +500,7 @@ def transfer_query(data):
platform=LinkMysql(env.DB_3YV2).perform_mysql(payment_sql)
params = {}
referNum=f'platomOutMoney_{platform}'
reference_type='finance_admin_fix'
reference_type='Payment'
uuid =data.uuid
ip=get_ip()
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:
return HttpResultResponse(code=500, msg='时间为必传参数')
query_params = request.query_params
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)
......@@ -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)):
"""充值报表导出"""
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,
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", "充值金额(元)", "支付时间", "类型", "订单号"]
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
"""用户提现列表"""
query_params = request.query_params
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)
return HttpResultResponse(total=total, count=float(money), data=statement_list)
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,reality_moeny=reality_moeny)
@router.get("/guildWithdrawal/list")
......@@ -56,8 +57,8 @@ def guild_withdrawal_list(request:Request,db: Session = Depends(get_db),page: Op
"""公会提现列表 暂无"""
query_params=request.query_params
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)
return HttpResultResponse(total=total, count=float(money), data=statement_list)
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,reality_moeny=reality_moeny)
@router.get("/guild/settlement")
......
......@@ -113,10 +113,8 @@ def search(params, method):
if response.status_code != 200:
return {}
text = json.loads(response.text)
if text.get("data").get("result").get("msg")=='success':
return True
else:
return False
print(text)
return text
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