|
|
@ -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 |
|
|
|