From b82d5c5374f84429d060716c457e340ea1e4f815 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Fri, 28 Mar 2025 14:44:48 +0800 Subject: [PATCH] update --- app/api/endpoints/merchant_order.py | 45 ++++++++++++++++++++++++-- app/api/endpoints/merchant_product.py | 11 ++++--- jobs.sqlite | Bin 24576 -> 24576 bytes 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/app/api/endpoints/merchant_order.py b/app/api/endpoints/merchant_order.py index 7bec9d9..f9a5c7b 100644 --- a/app/api/endpoints/merchant_order.py +++ b/app/api/endpoints/merchant_order.py @@ -215,8 +215,49 @@ async def get_user_orders( "items": result }) +class MerchantCancelOrderRequest(BaseModel): + reason: str + +@router.put("/{order_id}/merchant/cancel", response_model=ResponseModel) +async def merchant_cancel_order( + order_id: str, + request: MerchantCancelOrderRequest, + db: Session = Depends(get_db), + merchant_user: UserDB = Depends(get_merchant_user) +): + """取消订单""" + + merchant = db.query(MerchantDB).filter( + MerchantDB.user_id == merchant_user.userid + ).first() + if not merchant: + return error_response(code=404, message="商家不存在") + + order = db.query(MerchantOrderDB).filter( + MerchantOrderDB.order_id == order_id, + MerchantOrderDB.merchant_id == merchant.id + ).first() + if not order: + return error_response(code=404, message="订单不存在") + + try: + order.status = MerchantOrderStatus.REFUNDING + db.commit() + + wechat = WeChatClient() + await wechat.apply_refund( + order_id=order.order_id, + total_amount=int(float(order.pay_amount) * 100) if not settings.DEBUG else 1, # 转换为分 + reason="商家取消订单" + ) + return success_response(data=MerchantOrderInfo.model_validate(order)) + + except Exception as e: + db.rollback() + return error_response(code=500, message=f"取消订单失败: {str(e)}") + @router.put("/{order_id}/user/cancel", response_model=ResponseModel) -async def cancel_order( +async def user_cancel_order( order_id: str, db: Session = Depends(get_db), current_user: UserDB = Depends(get_current_user) @@ -269,7 +310,7 @@ async def complete_order( if not order: return error_response(code=404, message="订单不存在") - if order.status not in [MerchantOrderStatus.DELIVERING]: + if order.status not in [MerchantOrderStatus.DELIVERING, MerchantOrderStatus.PICKUP_READY]: return error_response(code=400, message="订单状态不正确") try: diff --git a/app/api/endpoints/merchant_product.py b/app/api/endpoints/merchant_product.py index cf694b9..cc6bdc8 100644 --- a/app/api/endpoints/merchant_product.py +++ b/app/api/endpoints/merchant_product.py @@ -79,7 +79,7 @@ async def update_product( @router.get("/list", response_model=ResponseModel) async def list_merchant_products( - merchant_id: Optional[int] = None, + user_id: Optional[int] = None, community_id: Optional[int] = None, skip: int = 0, limit: int = 20, @@ -90,10 +90,11 @@ async def list_merchant_products( query = db.query(MerchantProductDB).options( joinedload(MerchantProductDB.merchant) ) - - # 如果指定了商家ID,添加筛选条件 - if merchant_id: - query = query.filter(MerchantProductDB.merchant_id == merchant_id) + + if user_id: + merchant = db.query(MerchantDB).filter(MerchantDB.user_id == user_id).first() + if merchant: + query = query.filter(MerchantProductDB.merchant_id == merchant.id) if community_id: query = query.filter(MerchantProductDB.merchant.has(community_id=community_id)) diff --git a/jobs.sqlite b/jobs.sqlite index 6fec867b6ccb13c7e362c809f3dc65a73974e743..ef5c313e3311cc87856efc08ec75e831110a0978 100644 GIT binary patch delta 19 bcmZoTz}Rqrae_4C+KDpGjB7V0EQkjHN{a`I delta 19 bcmZoTz}Rqrae_4C?1?hYjI%c;EQkjHNqq-q