From 7639f07b839ee380fb70448ba9689f8c244f04de Mon Sep 17 00:00:00 2001 From: root Date: Wed, 1 Jan 2020 23:48:23 +0800 Subject: [PATCH] update --- app/Http/Controllers/OrderController.php | 18 ++++++++++++++++-- app/Models/CouponLog.php | 12 ++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 app/Models/CouponLog.php diff --git a/app/Http/Controllers/OrderController.php b/app/Http/Controllers/OrderController.php index 562a5c71..705460df 100755 --- a/app/Http/Controllers/OrderController.php +++ b/app/Http/Controllers/OrderController.php @@ -12,6 +12,7 @@ use App\Models\Order; use App\Models\Plan; use App\Models\User; use App\Models\Coupon; +use App\Models\CouponLog; use App\Utils\Helper; use Omnipay\Omnipay; use Stripe\Stripe; @@ -126,8 +127,21 @@ class OrderController extends Controller break; } $order->total_amount = $order->total_amount - $order->discount_amount; - $coupon->limit_use = $coupon->limit_use - 1; - if (!$coupon->save()) { + if ($coupon->limit_use !== NULL) { + $coupon->limit_use = $coupon->limit_use - 1; + if (!$coupon->save()) { + DB::rollback(); + abort(500, '优惠券使用失败'); + } + } + // add coupon log + if (!CouponLog::create([ + 'coupon_id' => $coupon->id, + 'user_id' => $order->user_id, + 'order_id' => $order->id, + 'total_amount' => $order->total_amount, + 'discount_amount' => $order->discount_amount + ])) { DB::rollback(); abort(500, '优惠券使用失败'); } diff --git a/app/Models/CouponLog.php b/app/Models/CouponLog.php new file mode 100644 index 00000000..c87f983c --- /dev/null +++ b/app/Models/CouponLog.php @@ -0,0 +1,12 @@ +