增加取消提现。
This commit is contained in:
parent
6e9775f530
commit
f194a99d5b
@ -29,6 +29,7 @@ async def account_summary(
|
||||
UserAccountDB.user_id == current_user.userid
|
||||
).first()
|
||||
balance = account.balance if account else Decimal('0')
|
||||
lock_balance = account.lock_balance if account else Decimal('0')
|
||||
|
||||
# 查询总收入金额
|
||||
total_income = db.query(func.sum(AccountDetailDB.amount)).filter(
|
||||
@ -44,7 +45,9 @@ async def account_summary(
|
||||
).scalar() or Decimal('0')
|
||||
|
||||
return success_response(data={
|
||||
"total_balance": float(balance + lock_balance), # 总余额
|
||||
"balance": float(balance), # 账户余额
|
||||
"lock_balance": float(lock_balance), # 锁定余额
|
||||
"total_income": float(total_income), # 总收入金额
|
||||
"today_income": float(today_income), # 今日收入金额
|
||||
})
|
||||
|
||||
@ -114,6 +114,41 @@ async def approve_withdraw(
|
||||
db.rollback()
|
||||
return error_response(code=500, message=f"审核失败: {str(e)}")
|
||||
|
||||
@router.post("/{withdraw_id}/cancel", response_model=ResponseModel)
|
||||
async def cancel_withdraw(
|
||||
withdraw_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: UserDB = Depends(get_current_user)
|
||||
):
|
||||
"""取消提现申请"""
|
||||
withdraw = db.query(WithdrawDB).filter(
|
||||
WithdrawDB.id == withdraw_id,
|
||||
WithdrawDB.status == WithdrawStatus.PENDING,
|
||||
WithdrawDB.user_id == current_user.userid
|
||||
).first()
|
||||
|
||||
if not withdraw:
|
||||
return error_response(code=404, message="提现申请不存在或已处理")
|
||||
|
||||
try:
|
||||
# 更新提现状态
|
||||
withdraw.status = WithdrawStatus.CANCELLED
|
||||
|
||||
# 返还锁定余额
|
||||
account = db.query(UserAccountDB).filter(
|
||||
UserAccountDB.user_id == withdraw.user_id
|
||||
).first()
|
||||
|
||||
account.balance += withdraw.amount
|
||||
account.lock_balance -= withdraw.amount
|
||||
|
||||
db.commit()
|
||||
return success_response(message="提现申请已取消")
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
return error_response(code=500, message=f"处理失败: {str(e)}")
|
||||
|
||||
|
||||
@router.post("/{withdraw_id}/reject", response_model=ResponseModel)
|
||||
async def reject_withdraw(
|
||||
withdraw_id: int,
|
||||
|
||||
@ -11,6 +11,7 @@ class WithdrawStatus(str, enum.Enum):
|
||||
PENDING = "PENDING" # 已申请
|
||||
APPROVED = "APPROVED" # 已通过
|
||||
REJECTED = "REJECTED" # 已驳回
|
||||
CANCELLED = "CANCELLED" # 已取消
|
||||
|
||||
class WithdrawDB(Base):
|
||||
__tablename__ = "withdraws"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user