mirror of
https://github.com/v2board/v2board.git
synced 2024-11-14 07:29:13 +08:00
update
This commit is contained in:
parent
2a693e4911
commit
7639f07b83
@ -12,6 +12,7 @@ use App\Models\Order;
|
|||||||
use App\Models\Plan;
|
use App\Models\Plan;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Coupon;
|
use App\Models\Coupon;
|
||||||
|
use App\Models\CouponLog;
|
||||||
use App\Utils\Helper;
|
use App\Utils\Helper;
|
||||||
use Omnipay\Omnipay;
|
use Omnipay\Omnipay;
|
||||||
use Stripe\Stripe;
|
use Stripe\Stripe;
|
||||||
@ -126,12 +127,25 @@ class OrderController extends Controller
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$order->total_amount = $order->total_amount - $order->discount_amount;
|
$order->total_amount = $order->total_amount - $order->discount_amount;
|
||||||
|
if ($coupon->limit_use !== NULL) {
|
||||||
$coupon->limit_use = $coupon->limit_use - 1;
|
$coupon->limit_use = $coupon->limit_use - 1;
|
||||||
if (!$coupon->save()) {
|
if (!$coupon->save()) {
|
||||||
DB::rollback();
|
DB::rollback();
|
||||||
abort(500, '优惠券使用失败');
|
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, '优惠券使用失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
// free process
|
// free process
|
||||||
if ($order->total_amount <= 0) {
|
if ($order->total_amount <= 0) {
|
||||||
$order->total_amount = 0;
|
$order->total_amount = 0;
|
||||||
|
12
app/Models/CouponLog.php
Normal file
12
app/Models/CouponLog.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class CouponLog extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'v2_coupon_log';
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
protected $guarded = ['id'];
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user