From ffa9bc40864200b6811c76d182e0714edd79fe78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Thu, 16 Dec 2021 19:55:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=8F=91=E8=B4=A7=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Endpoint/Api/Filters/OrderFilter.php | 2 +- app/Models/Order.php | 24 ++++++++++++-- ...113_add_shipping_state_to_orders_table.php | 32 +++++++++++++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 database/migrations/2021_12_16_194113_add_shipping_state_to_orders_table.php diff --git a/app/Endpoint/Api/Filters/OrderFilter.php b/app/Endpoint/Api/Filters/OrderFilter.php index 2ced1026..3f2951d1 100644 --- a/app/Endpoint/Api/Filters/OrderFilter.php +++ b/app/Endpoint/Api/Filters/OrderFilter.php @@ -15,7 +15,7 @@ class OrderFilter extends ModelFilter break; case 'unreceived': - $this->whereIn('status', [Order::STATUS_PAID, Order::STATUS_SHIPPED]); + $this->where('status', Order::STATUS_PAID); break; case 'completed': diff --git a/app/Models/Order.php b/app/Models/Order.php index 144c98db..41178ede 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -12,10 +12,13 @@ class Order extends Model public const STATUS_PENDING = 0; // 待付款 public const STATUS_PAID = 1; // 已付款 - public const STATUS_SHIPPED = 2; // 已发货 public const STATUS_COMPLETED = 9; // 已完成 public const STATUS_CANCELLED = 10; // 已取消 + public const SHIPPING_STATE_PENDING = 0; // 待发货 + public const SHIPPING_STATE_PROCESSING = 1; // 发货中 + public const SHIPPING_STATE_PROCESSED = 2; // 已完成 + public const PAY_WAY_ALIPAY = 'alipay'; public const PAY_WAY_WXPAY = 'wxpay'; public const PAY_WAY_BALANCE = 'balance'; @@ -58,6 +61,7 @@ class Order extends Model 'consignee_telephone', 'consignee_zone', 'consignee_address', + 'shipping_state', 'status', 'completed_at', ]; @@ -94,7 +98,7 @@ class Order extends Model */ public function isConfirmable(): bool { - return in_array($this->status, [static::STATUS_PAID, static::STATUS_SHIPPED]); + return $this->isPaid(); } /** @@ -104,7 +108,11 @@ class Order extends Model */ public function isCancelable(): bool { - return in_array($this->status, [static::STATUS_PENDING, static::STATUS_PAID]); + if ($this->isPaid()) { + return $this->shipping_state === static::SHIPPING_STATE_PENDING; + } + + return $this->isPending(); } /** @@ -117,6 +125,16 @@ class Order extends Model return $this->status === static::STATUS_PENDING; } + /** + * 确认此订单是否是已付款 + * + * @return bool + */ + public function isPaid(): bool + { + return $this->status === static::STATUS_PENDING; + } + /** * 获取订单券优惠金额 * diff --git a/database/migrations/2021_12_16_194113_add_shipping_state_to_orders_table.php b/database/migrations/2021_12_16_194113_add_shipping_state_to_orders_table.php new file mode 100644 index 00000000..5295b11e --- /dev/null +++ b/database/migrations/2021_12_16_194113_add_shipping_state_to_orders_table.php @@ -0,0 +1,32 @@ +tinyInteger('shipping_state')->index()->default(0)->comment('发货状态'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('orders', function (Blueprint $table) { + $table->dropColumn(['shipping_state']); + }); + } +}