发送通知。
This commit is contained in:
parent
6c5febe330
commit
ab7fa6b895
@ -28,6 +28,9 @@ from app.models.order import ShippingOrderDB, OrderStatus
|
||||
from app.core.redis_client import redis_client
|
||||
import logging
|
||||
from fastapi import Request
|
||||
from app.core.wecombot import WecomBot
|
||||
from fastapi import BackgroundTasks
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@ -437,6 +440,7 @@ async def change_password(
|
||||
|
||||
@router.put("/deliveryman/set_delivering", response_model=ResponseModel)
|
||||
async def deliveryman_set_delivering(
|
||||
background_tasks: BackgroundTasks,
|
||||
request: DeliverymanSetDelivering,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: UserDB = Depends(get_current_user)
|
||||
@ -444,6 +448,16 @@ async def deliveryman_set_delivering(
|
||||
"""配送员设置是否在配送中"""
|
||||
current_user.is_delivering = request.is_delivering
|
||||
db.commit()
|
||||
|
||||
# 发送企微通知
|
||||
if not request.is_delivering:
|
||||
wecom_bot = WecomBot()
|
||||
background_tasks.add_task(
|
||||
wecom_bot.send_deliveryman_close_delivering,
|
||||
db,
|
||||
current_user,
|
||||
current_user.community.name
|
||||
)
|
||||
return success_response(message="设置成功",data={
|
||||
"is_delivering": current_user.is_delivering
|
||||
})
|
||||
|
||||
@ -151,6 +151,26 @@ class WecomBot:
|
||||
except Exception as e:
|
||||
print(f"发送异常: {str(e)}")
|
||||
return False
|
||||
|
||||
async def send_deliveryman_close_delivering(self,db: Session, user: UserDB, community_name: str) -> bool:
|
||||
"""
|
||||
发送配送员关闭配送通知
|
||||
"""
|
||||
|
||||
try:
|
||||
content = f"""# ‼️ 配送员关闭配送通知
|
||||
|
||||
> **环境:{settings.ENV_NAME}**
|
||||
|
||||
**配送员信息**
|
||||
> 所属小区: {community_name}
|
||||
> 姓名: {user.nickname}
|
||||
> 电话: {user.phone[:3]}\*\*\*\*{user.phone[7:]}
|
||||
"""
|
||||
return await self.send_markdown(content, user.community.webot_webhook)
|
||||
except Exception as e:
|
||||
logging.exception(f"发送企业微信消息失败: {str(e)}")
|
||||
raise e
|
||||
|
||||
async def send_order_notification(self,db: Session, shipping_order: ShippingOrderDB, notify_type: OrderStatus = OrderStatus.CREATED) -> bool:
|
||||
"""
|
||||
|
||||
BIN
jobs.sqlite
BIN
jobs.sqlite
Binary file not shown.
Loading…
Reference in New Issue
Block a user