使用优惠券时,过滤未开始的优惠券
parent
a1c8622208
commit
e9312a42bd
|
|
@ -65,6 +65,14 @@ class UserCoupon extends Model
|
||||||
* 仅查询未使用的优惠券
|
* 仅查询未使用的优惠券
|
||||||
*/
|
*/
|
||||||
public function scopeOnlyUnuse($query)
|
public function scopeOnlyUnuse($query)
|
||||||
|
{
|
||||||
|
return $query->where('is_use', false)->where('use_end_at', '>', now());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仅查询可用的优惠券
|
||||||
|
*/
|
||||||
|
public function scopeOnlyAvailable($query)
|
||||||
{
|
{
|
||||||
$time = now();
|
$time = now();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class CouponService
|
||||||
*/
|
*/
|
||||||
public function getAvailableCoupons(User $user, array $products): array
|
public function getAvailableCoupons(User $user, array $products): array
|
||||||
{
|
{
|
||||||
$coupons = $user->coupons()->onlyUnuse()->get();
|
$coupons = $user->coupons()->onlyAvailable()->get();
|
||||||
|
|
||||||
$coupons->load(['ranges' => function ($query) {
|
$coupons->load(['ranges' => function ($query) {
|
||||||
$query->isEnable();
|
$query->isEnable();
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ class OrderService
|
||||||
$coupon = null;
|
$coupon = null;
|
||||||
|
|
||||||
if ($couponId) {
|
if ($couponId) {
|
||||||
$coupon = $user->coupons()->onlyUnuse()->findOrFail($couponId);
|
$coupon = $user->coupons()->onlyAvailable()->findOrFail($couponId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$mapProducts = $this->mapProducts($user, $products, $coupon);
|
$mapProducts = $this->mapProducts($user, $products, $coupon);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue