增加订单的相关时间记录。
This commit is contained in:
parent
7972638e80
commit
6fbb3c44f2
@ -529,7 +529,7 @@ async def cancel_order(
|
|||||||
@router.get("/deliveryman/list", response_model=ResponseModel)
|
@router.get("/deliveryman/list", response_model=ResponseModel)
|
||||||
async def get_deliveryman_orders(
|
async def get_deliveryman_orders(
|
||||||
status: Optional[OrderStatus] = None,
|
status: Optional[OrderStatus] = None,
|
||||||
building_id: Optional[int] = None,
|
building_name: Optional[str] = None,
|
||||||
skip: int = 0,
|
skip: int = 0,
|
||||||
limit: int = 20,
|
limit: int = 20,
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
@ -546,8 +546,8 @@ async def get_deliveryman_orders(
|
|||||||
query = query.filter(ShippingOrderDB.status == status)
|
query = query.filter(ShippingOrderDB.status == status)
|
||||||
|
|
||||||
# 楼栋筛选
|
# 楼栋筛选
|
||||||
if building_id:
|
if building_name:
|
||||||
query = query.filter(AddressDB.community_building_id == building_id)
|
query = query.filter(ShippingOrderDB.address_community_building_name == building_name)
|
||||||
|
|
||||||
# 获取总数
|
# 获取总数
|
||||||
total = query.count()
|
total = query.count()
|
||||||
@ -593,7 +593,12 @@ async def get_deliveryman_orders(
|
|||||||
"community_name": order.address_community_name,
|
"community_name": order.address_community_name,
|
||||||
"building_name": order.address_community_building_name,
|
"building_name": order.address_community_building_name,
|
||||||
"address_detail": order.address_detail
|
"address_detail": order.address_detail
|
||||||
}
|
},
|
||||||
|
|
||||||
|
"complete_images": order.complete_images.split(",") if order.complete_images else None,
|
||||||
|
"received_time": order.received_time,
|
||||||
|
"pickup_time": order.pickup_time,
|
||||||
|
"completed_time": order.completed_time
|
||||||
})
|
})
|
||||||
|
|
||||||
return success_response(data={
|
return success_response(data={
|
||||||
@ -710,6 +715,9 @@ async def complete_order(
|
|||||||
if complete_data.images:
|
if complete_data.images:
|
||||||
order.complete_images = ",".join(complete_data.images)
|
order.complete_images = ",".join(complete_data.images)
|
||||||
|
|
||||||
|
# 更新完成时间
|
||||||
|
order.completed_time = datetime.now()
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
return success_response(
|
return success_response(
|
||||||
message="订单已完成" if order.final_amount == 0 else "请继续支付",
|
message="订单已完成" if order.final_amount == 0 else "请继续支付",
|
||||||
@ -746,6 +754,7 @@ async def receive_order(
|
|||||||
# 更新订单状态和配送员ID
|
# 更新订单状态和配送员ID
|
||||||
order.status = OrderStatus.RECEIVED
|
order.status = OrderStatus.RECEIVED
|
||||||
order.deliveryman_user_id = deliveryman.userid
|
order.deliveryman_user_id = deliveryman.userid
|
||||||
|
order.received_time = datetime.now()
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
return success_response(
|
return success_response(
|
||||||
@ -779,6 +788,7 @@ async def pickup_order(
|
|||||||
try:
|
try:
|
||||||
# 更新订单状态为配送中
|
# 更新订单状态为配送中
|
||||||
order.status = OrderStatus.DELIVERING
|
order.status = OrderStatus.DELIVERING
|
||||||
|
order.pickup_time = datetime.now()
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
return success_response(
|
return success_response(
|
||||||
|
|||||||
@ -24,6 +24,8 @@ from app.core.qcloud import qcloud_manager
|
|||||||
from app.models.merchant import MerchantDB
|
from app.models.merchant import MerchantDB
|
||||||
from app.models.address import AddressDB, AddressInfo
|
from app.models.address import AddressDB, AddressInfo
|
||||||
from app.models.subscribe import SubscribeDB
|
from app.models.subscribe import SubscribeDB
|
||||||
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
# Redis 连接
|
# Redis 连接
|
||||||
@ -307,17 +309,17 @@ async def password_login(
|
|||||||
if not verify_password(login_data.password, user.password):
|
if not verify_password(login_data.password, user.password):
|
||||||
return error_response(code=401, message="密码错误")
|
return error_response(code=401, message="密码错误")
|
||||||
|
|
||||||
if login_data.is_admin:
|
if login_data.platform == Platform.ADMIN:
|
||||||
if UserRole.ADMIN not in user.roles:
|
if UserRole.ADMIN not in user.roles:
|
||||||
return error_response(code=401, message="管理员账户,请先设置管理员角色")
|
return error_response(code=401, message="管理员账户,请先设置管理员角色")
|
||||||
|
|
||||||
if UserRole.MERCHANT in user.roles:
|
if login_data.platform == Platform.MERCHANT and UserRole.MERCHANT in user.roles:
|
||||||
# 检查是否有商家设置了当前用户 id
|
# 检查是否有商家设置了当前用户 id
|
||||||
merchant = db.query(MerchantDB).filter(MerchantDB.user_id == user.userid).first()
|
merchant = db.query(MerchantDB).filter(MerchantDB.user_id == user.userid).first()
|
||||||
if not merchant:
|
if not merchant:
|
||||||
return error_response(code=401, message="商家账户,请先关联商 家")
|
return error_response(code=401, message="商家账户,请先关联商家")
|
||||||
|
|
||||||
if UserRole.DELIVERYMAN in user.roles and not user.community_id:
|
if login_data.platform == Platform.DELIVERYMAN and UserRole.DELIVERYMAN in user.roles and not user.community_id:
|
||||||
return error_response(code=401, message="配送员账户,请先设置归属小区")
|
return error_response(code=401, message="配送员账户,请先设置归属小区")
|
||||||
|
|
||||||
# 生成访问令牌
|
# 生成访问令牌
|
||||||
|
|||||||
@ -222,6 +222,7 @@ async def payment_notify(
|
|||||||
# 更新订单状态
|
# 更新订单状态
|
||||||
order.pay_status = True
|
order.pay_status = True
|
||||||
order.status = OrderStatus.COMPLETED # 支付成功后状态为已完成
|
order.status = OrderStatus.COMPLETED # 支付成功后状态为已完成
|
||||||
|
order.completed_time = datetime.now()
|
||||||
order.transaction_id = transaction_id
|
order.transaction_id = transaction_id
|
||||||
order.pay_time = datetime.fromisoformat(success_time.replace('Z', '+00:00'))
|
order.pay_time = datetime.fromisoformat(success_time.replace('Z', '+00:00'))
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,10 @@ class ShippingOrderDB(Base):
|
|||||||
final_amount = Column(Float, nullable=False)
|
final_amount = Column(Float, nullable=False)
|
||||||
status = Column(Enum(OrderStatus), nullable=False, default=OrderStatus.CREATED)
|
status = Column(Enum(OrderStatus), nullable=False, default=OrderStatus.CREATED)
|
||||||
cancel_reason = Column(String(200), nullable=True) # 取消原因
|
cancel_reason = Column(String(200), nullable=True) # 取消原因
|
||||||
|
received_time = Column(DateTime(timezone=True), nullable=True) # 接单时间
|
||||||
|
pickup_time = Column(DateTime(timezone=True), nullable=True) # 取件时间
|
||||||
|
completed_time = Column(DateTime(timezone=True), nullable=True) # 完成时间
|
||||||
|
update_time = Column(DateTime(timezone=True), onupdate=func.now())
|
||||||
complete_images = Column(String(1000), nullable=True) # 完成订单的图片URL,多个URL用逗号分隔
|
complete_images = Column(String(1000), nullable=True) # 完成订单的图片URL,多个URL用逗号分隔
|
||||||
create_time = Column(DateTime(timezone=True), server_default=func.now())
|
create_time = Column(DateTime(timezone=True), server_default=func.now())
|
||||||
deliveryman_user_id = Column(Integer, ForeignKey("users.userid"), nullable=True)
|
deliveryman_user_id = Column(Integer, ForeignKey("users.userid"), nullable=True)
|
||||||
@ -114,6 +118,10 @@ class OrderInfo(BaseModel):
|
|||||||
deliveryman_user_id: Optional[int] = None
|
deliveryman_user_id: Optional[int] = None
|
||||||
cancel_reason: Optional[str] = None
|
cancel_reason: Optional[str] = None
|
||||||
cancel_user_id: Optional[int] = None
|
cancel_user_id: Optional[int] = None
|
||||||
|
|
||||||
|
received_time: Optional[datetime] = None
|
||||||
|
pickup_time: Optional[datetime] = None
|
||||||
|
completed_time: Optional[datetime] = None
|
||||||
|
|
||||||
def __init__(self, **data):
|
def __init__(self, **data):
|
||||||
super().__init__(**data)
|
super().__init__(**data)
|
||||||
|
|||||||
@ -93,7 +93,7 @@ class UserUpdate(BaseModel):
|
|||||||
class UserPasswordLogin(BaseModel):
|
class UserPasswordLogin(BaseModel):
|
||||||
phone: str = Field(..., pattern="^1[3-9]\d{9}$")
|
phone: str = Field(..., pattern="^1[3-9]\d{9}$")
|
||||||
password: str = Field(..., min_length=6, max_length=20)
|
password: str = Field(..., min_length=6, max_length=20)
|
||||||
is_admin: bool = Field(default=False)
|
role: UserRole = Field(default=UserRole.DELIVERYMAN)
|
||||||
|
|
||||||
class ChangePasswordRequest(BaseModel):
|
class ChangePasswordRequest(BaseModel):
|
||||||
verify_code: str = Field(..., min_length=6, max_length=6)
|
verify_code: str = Field(..., min_length=6, max_length=6)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user