update
This commit is contained in:
parent
d6fcf919b3
commit
6eb2c4afc0
@ -1446,6 +1446,109 @@ async def deliveryman_pickup_order(
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
db.rollback()
|
db.rollback()
|
||||||
return error_response(code=500, message=f"操作失败: {str(e)}")
|
return error_response(code=500, message=f"操作失败: {str(e)}")
|
||||||
|
|
||||||
|
@router.get("/platform/list", response_model=ResponseModel)
|
||||||
|
async def get_orders(
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
status: Optional[OrderStatus] = None,
|
||||||
|
user_id: Optional[int] = None,
|
||||||
|
order_id: Optional[str] = None,
|
||||||
|
skip: int = 0,
|
||||||
|
limit: int = 10):
|
||||||
|
"""获取订单列表"""
|
||||||
|
try:
|
||||||
|
# 构建基础查询
|
||||||
|
query = db.query(ShippingOrderDB)
|
||||||
|
|
||||||
|
# 添加用户ID过滤
|
||||||
|
if user_id:
|
||||||
|
query = query.filter(ShippingOrderDB.userid == user_id)
|
||||||
|
|
||||||
|
# 添加状态过滤
|
||||||
|
if status:
|
||||||
|
query = query.filter(ShippingOrderDB.status == status)
|
||||||
|
|
||||||
|
# 添加订单号过滤
|
||||||
|
if order_id:
|
||||||
|
query = query.filter(ShippingOrderDB.orderid == order_id)
|
||||||
|
|
||||||
|
# 获取总数
|
||||||
|
total = query.count()
|
||||||
|
|
||||||
|
# 分页查询
|
||||||
|
results = query.order_by(
|
||||||
|
ShippingOrderDB.create_time.desc()
|
||||||
|
).offset(skip).limit(limit).all()
|
||||||
|
|
||||||
|
orders = []
|
||||||
|
for order in results:
|
||||||
|
# 查询订单包裹信息
|
||||||
|
packages = db.query(
|
||||||
|
ShippingOrderPackageDB
|
||||||
|
).filter(
|
||||||
|
ShippingOrderPackageDB.orderid == order.orderid
|
||||||
|
).all()
|
||||||
|
|
||||||
|
# 格式化包裹信息
|
||||||
|
package_list = [{
|
||||||
|
"id": package.id,
|
||||||
|
"station_id": package.station_id,
|
||||||
|
"station_name": package.station_name,
|
||||||
|
"pickup_codes": package.pickup_codes
|
||||||
|
} for package in packages]
|
||||||
|
|
||||||
|
|
||||||
|
item = {
|
||||||
|
"orderid": order.orderid,
|
||||||
|
"userid": order.userid,
|
||||||
|
"status": order.status,
|
||||||
|
"pickup_images": order.optimized_pickup_images,
|
||||||
|
"package_count": order.package_count,
|
||||||
|
"pickup_code_count": order.pickup_code_count,
|
||||||
|
"pickup_images_count": order.pickup_images_count,
|
||||||
|
"create_time": order.create_time,
|
||||||
|
"delivery_method": order.delivery_method,
|
||||||
|
"original_amount": order.original_amount,
|
||||||
|
"coupon_discount_amount": order.coupon_discount_amount,
|
||||||
|
"point_discount_amount": order.point_discount_amount,
|
||||||
|
"complete_images": order.optimized_complete_images,
|
||||||
|
"completed_time": order.completed_time,
|
||||||
|
"final_amount": order.final_amount,
|
||||||
|
"packages": package_list,
|
||||||
|
"address": {
|
||||||
|
"name": order.address_customer_name,
|
||||||
|
"phone": order.address_customer_phone,
|
||||||
|
"gender": order.address_customer_gender,
|
||||||
|
"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
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
# 查询配送员
|
||||||
|
deliveryman = db.query(UserDB).filter(
|
||||||
|
UserDB.userid == order.deliveryman_user_id
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if deliveryman:
|
||||||
|
item["deliveryman"] = {
|
||||||
|
"name": deliveryman.nickname,
|
||||||
|
"phone": deliveryman.phone
|
||||||
|
}
|
||||||
|
|
||||||
|
orders.append(item)
|
||||||
|
|
||||||
|
return success_response(data={
|
||||||
|
"total": total,
|
||||||
|
"items": orders
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logging.exception(f"获取订单列表失败: {str(e)}")
|
||||||
|
return error_response(code=500, message=f"获取订单列表失败: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
@router.get("/admin/list", response_model=ResponseModel)
|
@router.get("/admin/list", response_model=ResponseModel)
|
||||||
async def get_admin_orders(
|
async def get_admin_orders(
|
||||||
@ -1511,8 +1614,8 @@ async def get_admin_orders(
|
|||||||
sub_orders = db.query(PointProductOrderDB).filter(
|
sub_orders = db.query(PointProductOrderDB).filter(
|
||||||
PointProductOrderDB.delivery_order_id == order.orderid
|
PointProductOrderDB.delivery_order_id == order.orderid
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
orders.append({
|
item = {
|
||||||
"orderid": order.orderid,
|
"orderid": order.orderid,
|
||||||
"userid": order.userid,
|
"userid": order.userid,
|
||||||
"status": order.status,
|
"status": order.status,
|
||||||
@ -1525,6 +1628,8 @@ async def get_admin_orders(
|
|||||||
"original_amount": order.original_amount,
|
"original_amount": order.original_amount,
|
||||||
"coupon_discount_amount": order.coupon_discount_amount,
|
"coupon_discount_amount": order.coupon_discount_amount,
|
||||||
"point_discount_amount": order.point_discount_amount,
|
"point_discount_amount": order.point_discount_amount,
|
||||||
|
"complete_images": order.optimized_complete_images,
|
||||||
|
"completed_time": order.completed_time,
|
||||||
"final_amount": order.final_amount,
|
"final_amount": order.final_amount,
|
||||||
"packages": package_list,
|
"packages": package_list,
|
||||||
"sub_orders": [PointProductOrderInfo.model_validate(sub_order) for sub_order in sub_orders],
|
"sub_orders": [PointProductOrderInfo.model_validate(sub_order) for sub_order in sub_orders],
|
||||||
@ -1538,7 +1643,20 @@ async def get_admin_orders(
|
|||||||
"building_name": order.address_community_building_name,
|
"building_name": order.address_community_building_name,
|
||||||
"address_detail": order.address_detail
|
"address_detail": order.address_detail
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
|
||||||
|
# 查询配送员
|
||||||
|
deliveryman = db.query(UserDB).filter(
|
||||||
|
UserDB.userid == order.deliveryman_user_id
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if deliveryman:
|
||||||
|
item["deliveryman"] = {
|
||||||
|
"name": deliveryman.nickname,
|
||||||
|
"phone": deliveryman.phone
|
||||||
|
}
|
||||||
|
|
||||||
|
orders.append(item)
|
||||||
|
|
||||||
return success_response(data={
|
return success_response(data={
|
||||||
"total": total,
|
"total": total,
|
||||||
|
|||||||
BIN
jobs.sqlite
BIN
jobs.sqlite
Binary file not shown.
Loading…
Reference in New Issue
Block a user