From 84d30b79d2cf0a35ebacf7676651a4776b3c2318 Mon Sep 17 00:00:00 2001 From: lqmac Date: Sun, 20 Oct 2024 10:42:49 +0800 Subject: [PATCH] 1 --- app/admin/controller/Store.php | 6 +++++ app/store/controller/Order.php | 9 +++++++- app/store/model/Order.php | 41 ++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/app/admin/controller/Store.php b/app/admin/controller/Store.php index 98526423..afe535d1 100644 --- a/app/admin/controller/Store.php +++ b/app/admin/controller/Store.php @@ -53,6 +53,12 @@ class Store extends Controller $list = $list->toArray(); foreach ($list['data'] as &$value) { $value['store_version'] = $value['store_version'] == 0 ? "单商户" : "多商户"; + $value['p_store_name'] = ""; + if ($value['p_store_id']) { + $info = StoreModel::where('store_id', $value['p_store_id'])->find(); + $value['p_store_name'] = $info['store_name'] ?? ""; + } + } } return $this->renderSuccess(compact('list')); diff --git a/app/store/controller/Order.php b/app/store/controller/Order.php index 78b1a414..93f05441 100644 --- a/app/store/controller/Order.php +++ b/app/store/controller/Order.php @@ -233,7 +233,14 @@ class Order extends Controller } } - + //强制取消订单 + public function forceCancel(int $orderId){ + $model = OrderModel::detail($orderId); + if ($model->cancel()) { + return $this->renderSuccess($model->getMessage()); + } + return $this->renderError($model->getError() ?: '订单取消失败'); + } /** * 非商城订单 */ diff --git a/app/store/model/Order.php b/app/store/model/Order.php index d1de649f..870819f8 100644 --- a/app/store/model/Order.php +++ b/app/store/model/Order.php @@ -26,6 +26,7 @@ use app\common\service\order\Printer as PrinterService; use app\common\service\order\Refund as RefundService; use cores\exception\BaseException; use app\store\model\Goods as GoodsModel; +use app\api\service\{order\source\Factory as OrderSourceFactory}; /** * 订单管理 @@ -76,7 +77,47 @@ class Order extends OrderModel static::related($order, ['user', 'address', 'express', 'extract']); return $order; } + /** + * 取消订单 + * @return bool|mixed + */ + public function cancel() + { + // 判断订单是否允许取消 + $orderSource = OrderSourceFactory::getFactory($this['order_source']); + if (!$orderSource->checkOrderByCancel($this)) { + $this->error = $orderSource->getError(); + return false; + } + //订单已取消提示 + if ($this['order_status'] == OrderStatusEnum::CANCELLED) { + $this->error = '订单已取消成功,无需重复操作'; + return false; + } + if ($this['order_status'] == OrderStatusEnum::APPLY_CANCEL) { + $this->error = '订单已申请取消,需等待后台审核'; + return false; + } + + // 订单是否已支付 + $isPay = $this['pay_status'] == PayStatusEnum::SUCCESS; + // 提示信息 + $this->message = $isPay ? '订单已申请取消,需等待后台审核' : '订单已取消成功'; + // 订单取消事件 + return $this->transaction(function () use ($isPay) { + // 订单取消事件 + !$isPay && OrderService::cancelEvent($this); + // 更新订单状态: 已付款的订单设置为"待取消", 等待后台审核 + return $this->save(['order_status' => $isPay ? OrderStatusEnum::APPLY_CANCEL : OrderStatusEnum::CANCELLED]); + }); + } + + // 返回提示信息 + public function getMessage(): string + { + return $this->message; + } /** * 订单列表 * @param array $param