update
This commit is contained in:
parent
e4b53b6f04
commit
0a0acfbba7
@ -21,38 +21,14 @@ async def account_summary(
|
|||||||
"""获取账户收益汇总"""
|
"""获取账户收益汇总"""
|
||||||
# 获取当前日期范围
|
# 获取当前日期范围
|
||||||
today = datetime.now().date()
|
today = datetime.now().date()
|
||||||
yesterday = today - timedelta(days=1)
|
|
||||||
today_start = datetime.combine(today, datetime.min.time())
|
today_start = datetime.combine(today, datetime.min.time())
|
||||||
today_end = datetime.combine(today, datetime.max.time())
|
today_end = datetime.combine(today, datetime.max.time())
|
||||||
yesterday_start = datetime.combine(yesterday, datetime.min.time())
|
|
||||||
yesterday_end = datetime.combine(yesterday, datetime.max.time())
|
|
||||||
|
|
||||||
# 查询账户余额
|
# 查询账户余额
|
||||||
account = db.query(UserAccountDB).filter(
|
account = db.query(UserAccountDB).filter(
|
||||||
UserAccountDB.user_id == current_user.userid
|
UserAccountDB.user_id == current_user.userid
|
||||||
).first()
|
).first()
|
||||||
balance = account.balance if account else Decimal('0')
|
balance = account.balance if account else Decimal('0')
|
||||||
lock_balance = account.lock_balance if account else Decimal('0')
|
|
||||||
|
|
||||||
# 查询总收入记录数
|
|
||||||
total = db.query(func.count(AccountDetailDB.id)).filter(
|
|
||||||
AccountDetailDB.user_id == current_user.userid,
|
|
||||||
AccountDetailDB.type == AccountDetailType.INCOME
|
|
||||||
).scalar() or 0
|
|
||||||
|
|
||||||
# 查询今日收入记录数
|
|
||||||
today_total = db.query(func.count(AccountDetailDB.id)).filter(
|
|
||||||
AccountDetailDB.user_id == current_user.userid,
|
|
||||||
AccountDetailDB.type == AccountDetailType.INCOME,
|
|
||||||
AccountDetailDB.create_time.between(today_start, today_end)
|
|
||||||
).scalar() or 0
|
|
||||||
|
|
||||||
# 查询昨日收入记录数
|
|
||||||
yesterday_total = db.query(func.count(AccountDetailDB.id)).filter(
|
|
||||||
AccountDetailDB.user_id == current_user.userid,
|
|
||||||
AccountDetailDB.type == AccountDetailType.INCOME,
|
|
||||||
AccountDetailDB.create_time.between(yesterday_start, yesterday_end)
|
|
||||||
).scalar() or 0
|
|
||||||
|
|
||||||
# 查询总收入金额
|
# 查询总收入金额
|
||||||
total_income = db.query(func.sum(AccountDetailDB.amount)).filter(
|
total_income = db.query(func.sum(AccountDetailDB.amount)).filter(
|
||||||
@ -67,22 +43,10 @@ async def account_summary(
|
|||||||
AccountDetailDB.create_time.between(today_start, today_end)
|
AccountDetailDB.create_time.between(today_start, today_end)
|
||||||
).scalar() or Decimal('0')
|
).scalar() or Decimal('0')
|
||||||
|
|
||||||
# 查询昨日收入金额
|
|
||||||
yesterday_income = db.query(func.sum(AccountDetailDB.amount)).filter(
|
|
||||||
AccountDetailDB.user_id == current_user.userid,
|
|
||||||
AccountDetailDB.type == AccountDetailType.INCOME,
|
|
||||||
AccountDetailDB.create_time.between(yesterday_start, yesterday_end)
|
|
||||||
).scalar() or Decimal('0')
|
|
||||||
|
|
||||||
return success_response(data={
|
return success_response(data={
|
||||||
"balance": float(balance), # 账户余额
|
"balance": float(balance), # 账户余额
|
||||||
"lock_balance" : float(lock_balance), #锁定余额
|
|
||||||
"total": total, # 总收入记录数
|
|
||||||
"today_total": today_total, # 今日收入记录数
|
|
||||||
"yesterday_total": yesterday_total, # 昨日收入记录数
|
|
||||||
"total_income": float(total_income), # 总收入金额
|
"total_income": float(total_income), # 总收入金额
|
||||||
"today_income": float(today_income), # 今日收入金额
|
"today_income": float(today_income), # 今日收入金额
|
||||||
"yesterday_income": float(yesterday_income) # 昨日收入金额
|
|
||||||
})
|
})
|
||||||
|
|
||||||
# 添加 Pydantic 模型用于返回明细数据
|
# 添加 Pydantic 模型用于返回明细数据
|
||||||
|
|||||||
@ -290,6 +290,8 @@ async def payment_notify(
|
|||||||
# 对商家进行分账计算
|
# 对商家进行分账计算
|
||||||
account_manager = AccountManager(db)
|
account_manager = AccountManager(db)
|
||||||
settlement_amount = float(order.MerchantPayOrderDB.amount) * float(order.MerchantDB.pay_share_rate) / 100
|
settlement_amount = float(order.MerchantPayOrderDB.amount) * float(order.MerchantDB.pay_share_rate) / 100
|
||||||
|
|
||||||
|
if settlement_amount > 0:
|
||||||
account_manager.change_balance(
|
account_manager.change_balance(
|
||||||
user_id=order.MerchantDB.user_id,
|
user_id=order.MerchantDB.user_id,
|
||||||
amount=settlement_amount,
|
amount=settlement_amount,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user