fix order issue.
This commit is contained in:
parent
fe41fcc12b
commit
5028e1148c
@ -37,7 +37,7 @@ deactivate () {
|
||||
# unset irrelevant variables
|
||||
deactivate nondestructive
|
||||
|
||||
VIRTUAL_ENV="/Users/aaron/Desktop/code/deliveryman/.venv"
|
||||
VIRTUAL_ENV="/Users/aaron/source_code/beefast-api/.venv"
|
||||
export VIRTUAL_ENV
|
||||
|
||||
_OLD_VIRTUAL_PATH="$PATH"
|
||||
|
||||
@ -8,7 +8,7 @@ alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PA
|
||||
# Unset irrelevant variables.
|
||||
deactivate nondestructive
|
||||
|
||||
setenv VIRTUAL_ENV "/Users/aaron/Desktop/code/deliveryman/.venv"
|
||||
setenv VIRTUAL_ENV "/Users/aaron/source_code/beefast-api/.venv"
|
||||
|
||||
set _OLD_VIRTUAL_PATH="$PATH"
|
||||
setenv PATH "$VIRTUAL_ENV/bin:$PATH"
|
||||
|
||||
@ -29,7 +29,7 @@ end
|
||||
# Unset irrelevant variables.
|
||||
deactivate nondestructive
|
||||
|
||||
set -gx VIRTUAL_ENV "/Users/aaron/Desktop/code/deliveryman/.venv"
|
||||
set -gx VIRTUAL_ENV "/Users/aaron/source_code/beefast-api/.venv"
|
||||
|
||||
set -gx _OLD_VIRTUAL_PATH $PATH
|
||||
set -gx PATH "$VIRTUAL_ENV/bin" $PATH
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
from app.models.order import (
|
||||
ShippingOrderDB,
|
||||
ShippingOrderPackageDB,
|
||||
@ -15,12 +15,13 @@ from app.models.order import (
|
||||
OrderComplete
|
||||
)
|
||||
from app.models.database import get_db
|
||||
from app.api.deps import get_current_user
|
||||
from app.api.deps import get_current_user, get_deliveryman_user
|
||||
from app.models.user import UserDB
|
||||
from app.core.response import success_response, error_response, ResponseModel
|
||||
from app.models.coupon import UserCouponDB, CouponStatus
|
||||
from datetime import datetime, timezone
|
||||
from app.core.config import settings
|
||||
from app.models.address import AddressDB
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@ -51,18 +52,14 @@ async def create_shipping_order(
|
||||
# 计算优惠券折扣
|
||||
coupon_discount = 0
|
||||
coupon_id = None
|
||||
if order.price_request.coupon_id:
|
||||
# 查询用户优惠券
|
||||
user_coupon = db.query(UserCouponDB).filter(
|
||||
UserCouponDB.id == order.price_request.coupon_id,
|
||||
UserCouponDB.user_id == current_user.userid,
|
||||
UserCouponDB.status == CouponStatus.UNUSED,
|
||||
UserCouponDB.expire_time > datetime.now(timezone.utc)
|
||||
).first()
|
||||
|
||||
if not user_coupon:
|
||||
return error_response(code=400, message="优惠券无效或已过期")
|
||||
|
||||
if user_coupon:
|
||||
coupon_discount = user_coupon.coupon_amount
|
||||
coupon_id = user_coupon.id
|
||||
# 更新优惠券状态
|
||||
@ -285,3 +282,49 @@ async def complete_order(
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
return error_response(code=500, message=f"完成订单失败: {str(e)}")
|
||||
|
||||
@router.get("/delivery", response_model=ResponseModel)
|
||||
async def get_delivery_orders(
|
||||
status: Optional[OrderStatus] = None,
|
||||
community_building_id: Optional[int] = None,
|
||||
skip: int = 0,
|
||||
limit: int = 10,
|
||||
db: Session = Depends(get_db),
|
||||
deliveryman: UserDB = Depends(get_deliveryman_user) # 使用已有的配送员权限检查
|
||||
):
|
||||
"""获取配送订单列表(仅配送员可用)
|
||||
|
||||
Args:
|
||||
status: 订单状态筛选
|
||||
community_building_id: 社区楼栋ID筛选
|
||||
skip: 分页偏移
|
||||
limit: 每页数量
|
||||
"""
|
||||
# 基础查询
|
||||
query = db.query(ShippingOrderDB).join(
|
||||
AddressDB,
|
||||
ShippingOrderDB.addressid == AddressDB.id
|
||||
)
|
||||
|
||||
# 添加状态筛选
|
||||
if status:
|
||||
query = query.filter(ShippingOrderDB.status == status)
|
||||
|
||||
# 添加社区楼栋筛选
|
||||
if community_building_id:
|
||||
query = query.filter(
|
||||
AddressDB.community_building_id == community_building_id
|
||||
)
|
||||
|
||||
# 获取总数
|
||||
total = query.count()
|
||||
|
||||
# 获取分页数据并按创建时间倒序排序
|
||||
orders = query.order_by(
|
||||
ShippingOrderDB.create_time.desc()
|
||||
).offset(skip).limit(limit).all()
|
||||
|
||||
return success_response(data={
|
||||
"total": total,
|
||||
"items": [OrderInfo.model_validate(o) for o in orders]
|
||||
})
|
||||
@ -7,15 +7,15 @@ from .database import Base
|
||||
import enum
|
||||
|
||||
class OrderStatus(str, enum.Enum):
|
||||
CREATED = "created" # 已下单
|
||||
ACCEPTED = "accepted" # 已接单
|
||||
UNPAID = "unpaid" # 未支付
|
||||
COMPLETED = "completed" # 已完成
|
||||
CANCELLED = "cancelled" # 已取消
|
||||
CREATED = "CREATED" # 已下单
|
||||
ACCEPTED = "ACCEPTED" # 已接单
|
||||
UNPAID = "UNPAID" # 未支付
|
||||
COMPLETED = "COMPLETED" # 已完成
|
||||
CANCELLED = "CANCELLED" # 已取消
|
||||
|
||||
class DeliveryMethod(str, enum.Enum):
|
||||
DELIVERY_TO_DOOR = "delivery_to_door" # 放在门口
|
||||
DELIVERY_TO_ROOM = "delivery_to_room" # 投递到家
|
||||
DELIVERY_AT_DOORSTEP = "DELIVERY_AT_DOORSTEP" # 放在门口
|
||||
DELIVERY_TO_ROOM = "DELIVERY_TO_ROOM" # 投递到家
|
||||
|
||||
# 数据库模型
|
||||
class ShippingOrderDB(Base):
|
||||
@ -33,7 +33,11 @@ class ShippingOrderDB(Base):
|
||||
cancel_reason = Column(String(200), nullable=True) # 取消原因
|
||||
complete_images = Column(String(1000), nullable=True) # 完成订单的图片URL,多个URL用逗号分隔
|
||||
create_time = Column(DateTime(timezone=True), server_default=func.now())
|
||||
delivery_method = Column(Enum(DeliveryMethod), nullable=False, default=DeliveryMethod.DELIVERY_TO_DOOR)
|
||||
delivery_method = Column(
|
||||
Enum(DeliveryMethod),
|
||||
nullable=False,
|
||||
default=DeliveryMethod.DELIVERY_AT_DOORSTEP
|
||||
)
|
||||
|
||||
class ShippingOrderPackageDB(Base):
|
||||
__tablename__ = "shipping_order_packages"
|
||||
@ -58,7 +62,7 @@ class OrderCreate(BaseModel):
|
||||
addressid: int
|
||||
price_request: OrderPriceCalculateRequest
|
||||
delivery_method: DeliveryMethod = Field(
|
||||
default=DeliveryMethod.DELIVERY_TO_DOOR,
|
||||
default=DeliveryMethod.DELIVERY_AT_DOORSTEP,
|
||||
description="配送方式:放在门口或投递到家"
|
||||
)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user