增加提现通知
This commit is contained in:
parent
ec7eee5686
commit
4325d510a4
@ -12,13 +12,13 @@ from typing import List, Optional, Dict
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field
|
||||
from app.core.account import AccountManager
|
||||
from fastapi import BackgroundTasks
|
||||
from app.core.wecombot import WecomBot
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class WithdrawApproveRequest(BaseModel):
|
||||
"""提现审核请求"""
|
||||
skip: int = Field(default=0)
|
||||
limit: int = Field(default=20)
|
||||
transaction_id: str = Field(..., max_length=64) # 银行交易流水号
|
||||
|
||||
class WithdrawRejectRequest(BaseModel):
|
||||
@ -27,6 +27,7 @@ class WithdrawRejectRequest(BaseModel):
|
||||
|
||||
@router.post("", response_model=ResponseModel)
|
||||
async def create_withdraw(
|
||||
background_tasks: BackgroundTasks,
|
||||
withdraw: WithdrawCreate,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: UserDB = Depends(get_current_user)
|
||||
@ -42,7 +43,7 @@ async def create_withdraw(
|
||||
return error_response(code=404, message="银行卡不存在")
|
||||
|
||||
# 最低提现金额
|
||||
min_withdraw_amount = 100
|
||||
min_withdraw_amount = 10
|
||||
if withdraw.amount < min_withdraw_amount:
|
||||
return error_response(code=400, message=f"最低提现金额为{min_withdraw_amount}元")
|
||||
|
||||
@ -70,6 +71,10 @@ async def create_withdraw(
|
||||
|
||||
db.commit()
|
||||
db.refresh(withdraw_record)
|
||||
|
||||
# 异步发送提现申请通知
|
||||
wecombot = WecomBot()
|
||||
await wecombot.send_withdrawal_apply_notification(withdraw_record)
|
||||
|
||||
return success_response(data=WithdrawInfo.model_validate(withdraw_record))
|
||||
except Exception as e:
|
||||
@ -115,6 +120,10 @@ async def approve_withdraw(
|
||||
|
||||
db.commit()
|
||||
|
||||
# 异步发送提现审核通知
|
||||
wecombot = WecomBot()
|
||||
await wecombot.send_withdrawal_approve_notification(withdraw)
|
||||
|
||||
return success_response(data=WithdrawInfo.model_validate(withdraw))
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
|
||||
@ -16,6 +16,9 @@ class Settings(BaseSettings):
|
||||
URL_WECOMBOT_SYS_EXCEPTION : str = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=edcc54c5-c352-42dd-b9be-0cc5b39cc0dc"
|
||||
# 企业微信机器人每日报告通知
|
||||
URL_WECOMBOT_DAILY_REPORT : str = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=6869b6e2-57fc-471a-bb62-028014e2b1c8"
|
||||
# 企业微信机器人提现申请
|
||||
URL_WECOMBOT_WITHDRAWAL_APPLY : str = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a559ed6c-0d75-4a42-b11d-7ab47c929ac5"
|
||||
|
||||
|
||||
# 积分别名
|
||||
POINT_ALIAS: str = "蜂蜜"
|
||||
|
||||
@ -12,6 +12,8 @@ from app.models.user import UserDB
|
||||
from sqlalchemy.orm import Session
|
||||
import logging
|
||||
from app.core.config import settings
|
||||
from app.models.withdraw import WithdrawDB
|
||||
|
||||
class WecomBot:
|
||||
"""企业微信机器人工具类"""
|
||||
|
||||
@ -273,4 +275,53 @@ class WecomBot:
|
||||
|
||||
except Exception as e:
|
||||
logging.exception(f"发送企业微信消息失败: {str(e)}")
|
||||
raise e
|
||||
raise e
|
||||
|
||||
async def send_withdrawal_approve_notification(self, withdraw: WithdrawDB) -> bool:
|
||||
"""
|
||||
发送提现审核通知
|
||||
"""
|
||||
try:
|
||||
content = f"""# ‼️ 提现审核通知
|
||||
|
||||
> **环境:{settings.ENV_NAME}**
|
||||
|
||||
**提现信息**
|
||||
> 提现用户ID: {withdraw.user.userid}
|
||||
> 提现用户: {withdraw.user.nickname}
|
||||
|
||||
> 提现姓名: {withdraw.bank_card.name}
|
||||
> 提现银行卡: {withdraw.bank_card.bank_name} {withdraw.bank_card.card_number[:4]}\*\*\*\*{withdraw.bank_card.card_number[-4:]}
|
||||
> 提现金额: ¥{withdraw.amount}
|
||||
> 提现状态: <font color="green">已通过</font>
|
||||
> 提现时间: {CommonUtils.get_asia_datetime(withdraw.create_time)}
|
||||
"""
|
||||
return await self.send_markdown(content, settings.URL_WECOMBOT_WITHDRAWAL_APPLY)
|
||||
except Exception as e:
|
||||
logging.exception(f"发送企业微信消息失败: {str(e)}")
|
||||
raise e
|
||||
|
||||
async def send_withdrawal_apply_notification(self, withdraw: WithdrawDB) -> bool:
|
||||
"""
|
||||
发送提现申请通知
|
||||
"""
|
||||
try:
|
||||
content = f"""# ‼️ 提现申请通知
|
||||
|
||||
> **环境:{settings.ENV_NAME}**
|
||||
|
||||
**提现信息**
|
||||
> 提现用户ID: {withdraw.user.userid}
|
||||
> 提现用户: {withdraw.user.nickname}
|
||||
|
||||
> 提现姓名: {withdraw.bank_card.name}
|
||||
> 提现银行卡: {withdraw.bank_card.bank_name} {withdraw.bank_card.card_number[:4]}\*\*\*\*{withdraw.bank_card.card_number[-4:]}
|
||||
> 提现金额: ¥{withdraw.amount}
|
||||
> 提现状态: <font color="red">未处理</font>
|
||||
|
||||
> 提现时间: {CommonUtils.get_asia_datetime(withdraw.create_time)}
|
||||
"""
|
||||
return await self.send_markdown(content, settings.URL_WECOMBOT_WITHDRAWAL_APPLY)
|
||||
except Exception as e:
|
||||
logging.exception(f"发送企业微信消息失败: {str(e)}")
|
||||
raise e
|
||||
|
||||
@ -29,6 +29,8 @@ class WithdrawDB(Base):
|
||||
# 关联关系
|
||||
bank_card = relationship("UserBankCardDB", backref="withdraws")
|
||||
|
||||
user = relationship("UserDB", backref="withdraws")
|
||||
|
||||
class WithdrawCreate(BaseModel):
|
||||
bank_card_id: int
|
||||
amount: float = Field(..., gt=0)
|
||||
|
||||
BIN
jobs.sqlite
BIN
jobs.sqlite
Binary file not shown.
Loading…
Reference in New Issue
Block a user