lqmac 3 months ago
parent 536443de7c
commit 84d30b79d2
  1. 6
      app/admin/controller/Store.php
  2. 9
      app/store/controller/Order.php
  3. 41
      app/store/model/Order.php

@ -53,6 +53,12 @@ class Store extends Controller
$list = $list->toArray(); $list = $list->toArray();
foreach ($list['data'] as &$value) { foreach ($list['data'] as &$value) {
$value['store_version'] = $value['store_version'] == 0 ? "单商户" : "多商户"; $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')); return $this->renderSuccess(compact('list'));

@ -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() ?: '订单取消失败');
}
/** /**
* 非商城订单 * 非商城订单
*/ */

@ -26,6 +26,7 @@ use app\common\service\order\Printer as PrinterService;
use app\common\service\order\Refund as RefundService; use app\common\service\order\Refund as RefundService;
use cores\exception\BaseException; use cores\exception\BaseException;
use app\store\model\Goods as GoodsModel; 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']); static::related($order, ['user', 'address', 'express', 'extract']);
return $order; 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 * @param array $param

Loading…
Cancel
Save