feat : coupon

This commit is contained in:
2025-03-28 11:14:08 +08:00
parent 2feb14361e
commit 297b3363ad
2 changed files with 18 additions and 5 deletions

View File

@@ -35,7 +35,7 @@ class CouponListService extends BaseService
*/ */
public function handle(): array public function handle(): array
{ {
$limit = $this->request->input('limit',20); $limit = (int)$this->request->input('limit',20);
$data = $this->couponTemplateModel $data = $this->couponTemplateModel
->join('user_coupon', function ($join) { ->join('user_coupon', function ($join) {

View File

@@ -390,20 +390,33 @@ trait OrderTrait
if ($this->couponId <= 0 || empty($this->orderRes['coupon']) || $this->orderRes['coupon_id'] <= 0) return; 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) { 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']) { $this->orderRes['coupon']['amount'] = match ($this->orderRes['coupon']['coupon_type']) {
CouponCode::COUPON_TYPE_INSTANT_REDUCTION => $this->orderRes['coupon']['amount'], 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 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['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); $this->orderRes['actual_price'] = bcsub($this->orderRes['actual_price'],$this->orderRes['favorable_good_price'],2);
} }
/** /**
* @return void * @return void
*/ */