feat : coupon

This commit is contained in:
2025-03-04 18:01:07 +08:00
parent 0d2932ea4a
commit 63f60bc92b

View File

@@ -42,6 +42,9 @@ class ConfirmationOrderService extends BaseOrderService
return $this->return->success('success',$this->orderRes);
}
/**
* @return void
*/
private function autoSelectCoupon(): void
{
if ($this->couponId != 0) return;
@@ -56,7 +59,7 @@ class ConfirmationOrderService extends BaseOrderService
$maxValidityEndTimeDate = max(array_column($noUseCoupon,'validity_end_time'));
$filtered = array_filter($noUseCoupon, function($item) use($maxValidityEndTimeDate) {
return $item['validity_end_time'] === $maxValidityEndTimeDate;
return $item['validity_end_time'] == $maxValidityEndTimeDate;
});
$selectMaxPrice = 0;
@@ -64,7 +67,7 @@ class ConfirmationOrderService extends BaseOrderService
foreach ($filtered as &$value) {
$value['amount'] = match ($value['coupon_type']) {
CouponCode::COUPON_TYPE_INSTANT_REDUCTION => $value['amount'],
CouponCode::COUPON_TYPE_DISCOUNT => $value['amount'] * $orderMaxPrice,
CouponCode::COUPON_TYPE_DISCOUNT => $value['ratio'] * $orderMaxPrice,
default => 0
};