mirror of
https://github.com/v2board/v2board.git
synced 2025-06-16 06:37:53 +08:00
update: fix coupon & server record rate issue
This commit is contained in:
@ -15,7 +15,9 @@ class CouponService
|
||||
|
||||
public function __construct($code)
|
||||
{
|
||||
$this->coupon = Coupon::where('code', $code)->first();
|
||||
$this->coupon = Coupon::where('code', $code)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
}
|
||||
|
||||
public function use(Order $order):bool
|
||||
@ -37,6 +39,7 @@ class CouponService
|
||||
}
|
||||
if ($this->coupon->limit_use !== NULL) {
|
||||
$this->coupon->limit_use = $this->coupon->limit_use - 1;
|
||||
if ($this->coupon->limit_use <= 0) return false;
|
||||
if (!$this->coupon->save()) {
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user