update
This commit is contained in:
parent
f545bf4efd
commit
ce3c96768e
@ -132,12 +132,22 @@ async def cancel_order(
|
||||
if not order:
|
||||
return error_response(code=404, message="订单不存在")
|
||||
|
||||
order.status = MerchantOrderStatus.CANCELLED
|
||||
db.commit()
|
||||
try:
|
||||
|
||||
#TODO 退款
|
||||
order.status = MerchantOrderStatus.REFUNDING
|
||||
db.commit()
|
||||
|
||||
return success_response(data=MerchantOrderInfo.model_validate(order))
|
||||
wechat = WeChatClient()
|
||||
await wechat.apply_refund(
|
||||
order_id=order.order_id,
|
||||
total_amount=int(float(order.pay_amount) * 100) if not settings.DEBUG else 1, # 转换为分
|
||||
reason="用户取消订单"
|
||||
)
|
||||
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}/confirm", response_model=ResponseModel)
|
||||
async def confirm_order(
|
||||
@ -153,10 +163,24 @@ async def confirm_order(
|
||||
if not order:
|
||||
return error_response(code=404, message="订单不存在")
|
||||
|
||||
order.status = MerchantOrderStatus.DELIVERING
|
||||
db.commit()
|
||||
try:
|
||||
order.status = MerchantOrderStatus.DELIVERING
|
||||
db.commit()
|
||||
|
||||
return success_response(data=MerchantOrderInfo.model_validate(order))
|
||||
# 如果订单有赠送积分,增加积分
|
||||
if order.gift_points > 0:
|
||||
point_manager = PointManager(db)
|
||||
point_manager.add_points(
|
||||
user_id = order.user_id,
|
||||
points = order.gift_points,
|
||||
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.get("/merchant/verify/{verify_code}", response_model=ResponseModel)
|
||||
|
||||
@ -345,19 +345,9 @@ async def refund_notify(
|
||||
return error_response(code=404, message="订单不存在或状态不正确")
|
||||
|
||||
# 更新订单状态
|
||||
order.status = MerchantOrderStatus.REFUNDED
|
||||
order.status = MerchantOrderStatus.CANCELLED
|
||||
order.refund_transaction_id = data.get("transaction_id")
|
||||
order.refund_time = datetime.fromisoformat(success_time.replace('Z', '+00:00'))
|
||||
|
||||
# 如果订单有赠送积分,则扣除积分
|
||||
if order.gift_points > 0:
|
||||
point_manager = PointManager(db)
|
||||
point_manager.deduct_points(
|
||||
user_id = order.user_id,
|
||||
points = order.gift_points,
|
||||
description = f"订单退款,返还积分",
|
||||
order_id = order.order_id
|
||||
)
|
||||
|
||||
elif out_trade_no.startswith('P'): # 商家在线买单
|
||||
order = db.query(MerchantPayOrderDB).filter(
|
||||
@ -377,7 +367,7 @@ async def refund_notify(
|
||||
point_manager.deduct_points(
|
||||
user_id = order.user_id,
|
||||
points = order.gift_points,
|
||||
description = f"订单退款,返还积分",
|
||||
description = f"订单取消扣除",
|
||||
order_id = order.order_id
|
||||
)
|
||||
|
||||
|
||||
BIN
jobs.sqlite
BIN
jobs.sqlite
Binary file not shown.
Loading…
Reference in New Issue
Block a user