From cde7b6d836b81941ccb76ccd393f77abdc1f667f Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Thu, 23 Dec 2021 16:25:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88=E8=AE=A2=E5=8D=95=E6=97=B6?= =?UTF-8?q?=E9=80=80=E4=BC=98=E6=83=A0=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/OrderService.php | 7 +++++++ .../2021_12_16_140921_add_coupon_id_to_orders_table.php | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Services/OrderService.php b/app/Services/OrderService.php index 198f5f4e..1d0cce1a 100644 --- a/app/Services/OrderService.php +++ b/app/Services/OrderService.php @@ -825,6 +825,13 @@ class OrderService } } + // 取消订单,退券 + if ($order->user_coupon_id) { + UserCoupon::where('user_id', $order->user_id)->where('id', $order->user_coupon_id)->update([ + 'is_use'=>false, + ]); + } + $order->update([ 'status' => Order::STATUS_CANCELLED, ]); diff --git a/database/migrations/2021_12_16_140921_add_coupon_id_to_orders_table.php b/database/migrations/2021_12_16_140921_add_coupon_id_to_orders_table.php index 5464838d..4531051b 100644 --- a/database/migrations/2021_12_16_140921_add_coupon_id_to_orders_table.php +++ b/database/migrations/2021_12_16_140921_add_coupon_id_to_orders_table.php @@ -14,7 +14,7 @@ class AddCouponIdToOrdersTable extends Migration public function up() { Schema::table('orders', function (Blueprint $table) { - $table->unsignedBigInteger('user_coupon_id')->unique()->nullable()->comment('用户优惠券ID'); + $table->unsignedBigInteger('user_coupon_id')->nullable()->comment('用户优惠券ID'); }); }