From 855b173764102f00b844b4957b27a771da0266fc Mon Sep 17 00:00:00 2001 From: aaron <> Date: Mon, 17 Feb 2025 18:21:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=8A=B6=E6=80=81=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/order.py | 32 +++++++++++++++++++++++++++++++- app/models/order.py | 4 ++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/api/endpoints/order.py b/app/api/endpoints/order.py index a4f0db6..f9b0b3f 100644 --- a/app/api/endpoints/order.py +++ b/app/api/endpoints/order.py @@ -174,6 +174,8 @@ async def create_order( address_customer_name=address.name, address_customer_phone=address.phone, address_customer_gender=address.gender, + address_community_id=address.community_id, + address_community_building_id=address.community_building_id, address_community_name=address.community_name, address_community_building_name=address.community_building_name, address_detail=address.address_detail, @@ -339,6 +341,32 @@ async def get_order_detail( "packages": package_list }) +# 提供一个接口,传入community_id,返回订单状态数量 +@router.get("/status/count", response_model=ResponseModel) +async def get_order_status_count( + community_id: int, + db: Session = Depends(get_db), + current_user: UserDB = Depends(get_current_user) +): + """获取社区订单状态数量""" + status_order_count = db.query( + ShippingOrderDB.status, + func.count(ShippingOrderDB.orderid) + ).filter( + ShippingOrderDB.address_community_id == community_id + ).group_by( + ShippingOrderDB.status + ).all() + + result = [] + for status, count in status_order_count: + result.append({ + "status": status, + "count": count + }) + + return success_response(data=result) + # 提供一个接口,传入 community_id 返回每栋楼栋的订单数量 @router.get("/community_building/count", response_model=ResponseModel) async def get_community_building_order_count( @@ -451,7 +479,9 @@ async def get_user_orders( "address": { "name": order.address_customer_name, "phone": order.address_customer_phone, + "community_id": order.address_community_id, "community_name": order.address_community_name, + "building_id": order.address_community_building_id, "building_name": order.address_community_building_name, "address_detail": order.address_detail } @@ -559,7 +589,7 @@ async def get_deliveryman_orders( # 格式化返回数据 orders = [] - for order, address, building, community in results: + for order in results: # 查询订单包裹信息 packages = db.query( ShippingOrderPackageDB, diff --git a/app/models/order.py b/app/models/order.py index dbf9cd7..170cac9 100644 --- a/app/models/order.py +++ b/app/models/order.py @@ -32,7 +32,9 @@ class ShippingOrderDB(Base): address_customer_name = Column(String(50), nullable=False, default='') # 客户名称快照 address_customer_phone = Column(String(11), nullable=False, default='') # 客户电话快照 address_customer_gender = Column(Enum(Gender), nullable=False, default=Gender.UNKNOWN) # 客户性别快照 + address_community_id = Column(Integer, nullable=False) address_community_name = Column(String(50), nullable=False, default='') # 小区名称快照 + address_community_building_id = Column(Integer, nullable=False) address_community_building_name = Column(String(50), nullable=False, default='') # 楼栋名称快照 address_detail = Column(String(100), nullable=False, default='') # 详细地址快照 @@ -98,7 +100,9 @@ class OrderInfo(BaseModel): address_customer_name: str address_customer_phone: str + address_community_id: int address_community_name: str + address_community_building_id: int address_community_building_name: str address_detail: str address_customer_gender: Gender