update
This commit is contained in:
parent
ce3c96768e
commit
d5a306d06b
@ -31,6 +31,7 @@ from app.core.imageprocessor import process_image, ImageFormat
|
||||
from starlette.datastructures import Headers
|
||||
from app.models.merchant_order import MerchantOrderVerify
|
||||
from app.core.point_manager import PointManager, PointRecordType
|
||||
from app.models.merchant_product import DeliveryType, DeliveryTimeType
|
||||
from datetime import timedelta
|
||||
router = APIRouter()
|
||||
|
||||
@ -86,6 +87,37 @@ async def create_merchant_order(
|
||||
db.rollback()
|
||||
return error_response(code=500, message=f"创建订单失败: {str(e)}")
|
||||
|
||||
@router.get("/merchant", response_model=ResponseModel)
|
||||
async def get_merchant_orders(
|
||||
skip: int = 0,
|
||||
limit: int = 100,
|
||||
delivery_type: DeliveryType = None,
|
||||
delivery_time_type: DeliveryTimeType = None,
|
||||
db: Session = Depends(get_db),
|
||||
merchant_user: UserDB = Depends(get_merchant_user)
|
||||
):
|
||||
"""获取商家订单列表"""
|
||||
orders = db.query(MerchantOrderDB).filter(
|
||||
MerchantOrderDB.merchant_id == merchant_user.userid
|
||||
).order_by(
|
||||
MerchantOrderDB.create_time.desc()
|
||||
).offset(skip).limit(limit).all()
|
||||
|
||||
result = []
|
||||
for order in orders:
|
||||
product = db.query(MerchantProductDB).filter(
|
||||
MerchantProductDB.id == order.merchant_product_id
|
||||
).first()
|
||||
merchant = db.query(MerchantDB).filter(
|
||||
MerchantDB.id == product.merchant_id
|
||||
).first()
|
||||
result.append({
|
||||
"order" : MerchantOrderInfo.model_validate(order),
|
||||
"product" : MerchantProductInfo.model_validate(product),
|
||||
"merchant" : MerchantInfo.model_validate(merchant)
|
||||
})
|
||||
return success_response(data=result)
|
||||
|
||||
@router.get("/user", response_model=ResponseModel)
|
||||
async def get_user_orders(
|
||||
skip: int = 0,
|
||||
@ -149,22 +181,26 @@ async def cancel_order(
|
||||
db.rollback()
|
||||
return error_response(code=500, message=f"取消订单失败: {str(e)}")
|
||||
|
||||
@router.put("/{order_id}/confirm", response_model=ResponseModel)
|
||||
async def confirm_order(
|
||||
@router.put("/{order_id}/complete", response_model=ResponseModel)
|
||||
async def complete_order(
|
||||
order_id: str,
|
||||
db: Session = Depends(get_db),
|
||||
merchant_user: UserDB = Depends(get_merchant_user)
|
||||
):
|
||||
"""商家确认订单"""
|
||||
order = db.query(MerchantOrderDB).filter(
|
||||
):
|
||||
"""商家完成订单"""
|
||||
order = db.query(MerchantOrderDB).filter(
|
||||
MerchantOrderDB.order_id == order_id,
|
||||
MerchantOrderDB.merchant_id == merchant_user.userid
|
||||
).first()
|
||||
|
||||
if not order:
|
||||
return error_response(code=404, message="订单不存在")
|
||||
|
||||
if order.status not in [MerchantOrderStatus.DELIVERING, MerchantOrderStatus.PICKUP_READY]:
|
||||
return error_response(code=400, message="订单状态不正确")
|
||||
|
||||
try:
|
||||
order.status = MerchantOrderStatus.DELIVERING
|
||||
order.status = MerchantOrderStatus.COMPLETED
|
||||
db.commit()
|
||||
|
||||
# 如果订单有赠送积分,增加积分
|
||||
@ -176,6 +212,41 @@ async def confirm_order(
|
||||
description = f"消费送蜂蜜",
|
||||
order_id = order.order_id
|
||||
)
|
||||
|
||||
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}/accept", response_model=ResponseModel)
|
||||
async def accept_order(
|
||||
order_id: str,
|
||||
db: Session = Depends(get_db),
|
||||
merchant_user: UserDB = Depends(get_merchant_user)
|
||||
):
|
||||
"""商家接单订单"""
|
||||
order = db.query(MerchantOrderDB).filter(
|
||||
MerchantOrderDB.order_id == order_id,
|
||||
MerchantOrderDB.merchant_id == merchant_user.userid
|
||||
).first()
|
||||
if not order:
|
||||
return error_response(code=404, message="订单不存在")
|
||||
|
||||
product = db.query(MerchantProductDB).filter(
|
||||
MerchantProductDB.id == order.merchant_product_id
|
||||
).first()
|
||||
if not product:
|
||||
return error_response(code=404, message="商品不存在")
|
||||
|
||||
if product.delivery_type != DeliveryType.PICKUP:
|
||||
return error_response(code=400, message="商品类型不正确")
|
||||
|
||||
if order.status != MerchantOrderStatus.PENDING:
|
||||
return error_response(code=400, message="订单状态不正确")
|
||||
|
||||
try:
|
||||
order.status = MerchantOrderStatus.DELIVERING
|
||||
db.commit()
|
||||
|
||||
return success_response(data=MerchantOrderInfo.model_validate(order))
|
||||
except Exception as e:
|
||||
|
||||
BIN
jobs.sqlite
BIN
jobs.sqlite
Binary file not shown.
Loading…
Reference in New Issue
Block a user