feat : coupon
This commit is contained in:
@@ -390,20 +390,33 @@ trait OrderTrait
|
||||
if ($this->couponId <= 0 || empty($this->orderRes['coupon']) || $this->orderRes['coupon_id'] <= 0) return;
|
||||
|
||||
if ($this->orderRes['coupon']['amount'] <= 0 && $this->orderRes['coupon']['coupon_type'] != CouponCode::COUPON_TYPE_INSTANT_REDUCTION) {
|
||||
$orderMaxPrice = max(array_column($this->orderRes['good'],'price'));
|
||||
// $orderMaxPrice = max(array_column($this->orderRes['good'],'price'));
|
||||
$this->orderRes['coupon']['amount'] = match ($this->orderRes['coupon']['coupon_type']) {
|
||||
CouponCode::COUPON_TYPE_INSTANT_REDUCTION => $this->orderRes['coupon']['amount'],
|
||||
CouponCode::COUPON_TYPE_DISCOUNT => bcmul(bcdiv(bcsub("100",(string)$this->orderRes['coupon']['ratio'],2),"100",2),$orderMaxPrice,2),
|
||||
CouponCode::COUPON_TYPE_DISCOUNT => bcmul(
|
||||
bcdiv(
|
||||
bcsub(
|
||||
"100",
|
||||
(string)$this->orderRes['coupon']['ratio'],
|
||||
2
|
||||
),
|
||||
"100",
|
||||
2
|
||||
),
|
||||
max(array_column($this->orderRes['good'],'price')),
|
||||
2
|
||||
),
|
||||
default => 0
|
||||
};
|
||||
}
|
||||
|
||||
$this->orderRes['favorable_good_price'] = $this->orderRes['coupon']['amount'];
|
||||
$this->orderRes['favorable_good_price'] = $this->orderRes['coupon']['coupon_type'] == CouponCode::COUPON_TYPE_INSTANT_REDUCTION ?
|
||||
min($this->orderRes['coupon']['amount'], $this->orderRes['good_after_discount_price']) :
|
||||
$this->orderRes['coupon']['amount'];
|
||||
$this->orderRes['good_after_discount_price'] = bcsub($this->orderRes['good_after_discount_price'],$this->orderRes['favorable_good_price'],2);
|
||||
$this->orderRes['actual_price'] = bcsub($this->orderRes['actual_price'],$this->orderRes['favorable_good_price'],2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user