From 4325d510a49845d0c2032d4317c6dc8e939c5d14 Mon Sep 17 00:00:00 2001
From: aaron <>
Date: Wed, 26 Mar 2025 11:01:44 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8F=90=E7=8E=B0=E9=80=9A?=
=?UTF-8?q?=E7=9F=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/api/endpoints/withdraw.py | 15 ++++++++--
app/core/config.py | 3 ++
app/core/wecombot.py | 53 +++++++++++++++++++++++++++++++++-
app/models/withdraw.py | 2 ++
jobs.sqlite | Bin 24576 -> 24576 bytes
5 files changed, 69 insertions(+), 4 deletions(-)
diff --git a/app/api/endpoints/withdraw.py b/app/api/endpoints/withdraw.py
index 44e44bd..bfcb5f3 100644
--- a/app/api/endpoints/withdraw.py
+++ b/app/api/endpoints/withdraw.py
@@ -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()
diff --git a/app/core/config.py b/app/core/config.py
index 56d67a2..d596833 100644
--- a/app/core/config.py
+++ b/app/core/config.py
@@ -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 = "蜂蜜"
diff --git a/app/core/wecombot.py b/app/core/wecombot.py
index fa24e7d..5ea213f 100644
--- a/app/core/wecombot.py
+++ b/app/core/wecombot.py
@@ -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
\ No newline at end of file
+ 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}
+> 提现状态: 已通过
+> 提现时间: {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}
+> 提现状态: 未处理
+
+> 提现时间: {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
diff --git a/app/models/withdraw.py b/app/models/withdraw.py
index 50a6988..2915007 100644
--- a/app/models/withdraw.py
+++ b/app/models/withdraw.py
@@ -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)
diff --git a/jobs.sqlite b/jobs.sqlite
index 17f82a83b9ae1b79f4f3d5387d0db07998007470..0ec0755731b443cb04263dc100520b79dd148863 100644
GIT binary patch
delta 82
zcmZoTz}Rqrae_4C-ib2KjC(gGt)%Hq8&>`$~i8d#?~
jO?Gsb*?d`AmIWyOQJzVG2Pn?W!OX$}4Co>2h+uNxck
delta 82
zcmZoTz}Rqrae_4C!ih4@j0-m=