diff --git a/app/admin/controller/store_order/StoreOrderController.php b/app/admin/controller/store_order/StoreOrderController.php index 8a819c7de..97a97c499 100644 --- a/app/admin/controller/store_order/StoreOrderController.php +++ b/app/admin/controller/store_order/StoreOrderController.php @@ -21,6 +21,7 @@ use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\system_store\SystemStore; use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_product\WarehouseProduct; +use app\common\service\RefundOrderService; use app\common\service\xlsx\Beforehand; use app\common\service\xlsx\OrderDetail; use support\exception\BusinessException; @@ -124,17 +125,16 @@ class StoreOrderController extends BaseAdminController * @return \support\Response * @throws \Exception */ - public function refund() + public function refund(RefundOrderService $refundOrderService) { $params = $this->request->post(); $detail = StoreOrder::where('order_id', $params['order_id'])->findOrEmpty(); if (empty($detail)) { return $this->fail('无该订单请检查'); } - $res = StoreOrderLogic::refund($detail, $params); - if ($res == false) { - return $this->fail('退款失败'); - } + $params['id'] = $detail['id']; + $params['old_cart_id'] = StoreOrderCartInfo::where('oid', $detail['id'])->column('id'); + $refundOrderService->refund($detail['uid'], $params); return $this->success('退款成功',[],1,1); } diff --git a/app/common/model/store_order/StoreOrder.php b/app/common/model/store_order/StoreOrder.php index 129794553..5ed2f2abf 100644 --- a/app/common/model/store_order/StoreOrder.php +++ b/app/common/model/store_order/StoreOrder.php @@ -129,7 +129,7 @@ class StoreOrder extends BaseModel public function allowRefund(): bool { - if (in_array($this->status, [0, 1]) && $this->paid == 1) { + if (in_array($this->status, [0, 1, 2])) { return true; } return false; diff --git a/app/common/service/RefundOrderService.php b/app/common/service/RefundOrderService.php index 83fe60449..ecbd4b89e 100644 --- a/app/common/service/RefundOrderService.php +++ b/app/common/service/RefundOrderService.php @@ -31,6 +31,9 @@ class RefundOrderService if (empty($order)) { throw new BusinessException('订单不存在'); } + if (!$order->allowRefund()) { + throw new BusinessException('订单不能退款'); + } $orderCartProducts = StoreOrderCartInfo::where('oid', $order['id'])->whereIn('id', $params['old_cart_id'])->select(); if ($order->status == 2 && $order->is_writeoff == 1) { $this->refundStoreMoney($order);