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'); }); }