From 9fe2b28655c04e522c2cd64399a4d7c221931c98 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Tue, 7 Feb 2023 15:26:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Order::subTotal=20?= =?UTF-8?q?=E5=92=8C=20Order::getNextStatuses=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Models/Order.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/beike/Models/Order.php b/beike/Models/Order.php index 269feffa..bda22c90 100644 --- a/beike/Models/Order.php +++ b/beike/Models/Order.php @@ -13,6 +13,7 @@ namespace Beike\Models; use Beike\Notifications\NewOrderNotification; use Beike\Notifications\UpdateOrderNotification; +use Beike\Services\StateMachineService; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Notifications\Notifiable; @@ -58,6 +59,13 @@ class Order extends Base return $this->hasMany(OrderShipment::class); } + public function subTotal() + { + $totals = $this->orderTotals; + + return $totals->where('code', 'sub_total')->first(); + } + public function getStatusFormatAttribute() { return trans('order.' . $this->status); @@ -68,6 +76,17 @@ class Order extends Base return currency_format($this->total, $this->currency_code, $this->currency_value); } + /** + * 获取该订单可以变更的状态 + * + * @return array + * @throws \Exception + */ + public function getNextStatuses() + { + return StateMachineService::getInstance($this)->nextBackendStatuses(); + } + /** * 新订单通知 */