feat(ecommerce): 마일리지 적립 절사 기준 신설 및 주문 시점 스냅샷
적립 포인트 절사가 코드에 1점 버림으로 고정돼 있어 운영자가 조정할 수 없었다. 언어/통화 설정의 환율 절사를 따라가는 방안을 먼저 검토했으나, 그쪽은 외화 환산 분기에서만 적용되어 기본 통화 상점에는 따라갈 값 자체가 없다. 적립은 기본 통화 원장에 정수로 확정 기록되는 값이라 성격이 다르므로 마일리지 통화별 규칙에 신설했다. - earn_rounding_unit(1/10/100) + earn_rounding_method(floor/round/ceil) - 기본값은 종전 하드코딩과 정확히 같은 금액을 산출 — 기존 쇼핑몰 적립액 무변화 - 주문 계산·옵션 분할·부분취소 안분 전 경로에 동일 기준 적용 - 주문 시점 값을 스냅샷으로 보관 — 이후 기준을 바꿔도 과거 주문이 소급 변경되지 않는다 - 설정 UI·검증·다국어(ko/en/ja)·API 문서 동반, 기존 사이트는 업그레이드 스텝이 명시 기입 함께 처리: 마일리지 내역 목록 테스트가 첫 컬럼 field 를 `no` 로 단언해 실패하던 것을 현재 레이아웃 값(`number`)에 맞춰 정정했다. 이 브랜치와 무관한 stale 케이스다.
This commit is contained in:
1 parent
0ae3289c60
commit
60cccbf62d
36 files changed
+1793
-65
No files matched your search
@@ -37,6 +37,7 @@ use Modules\Sirsoft\Ecommerce\Repositories\Contracts\CouponIssueRepositoryInterf
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\ProductAdditionalOptionValueRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\ProductOptionRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\ShippingPolicyRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Support\MileageRounding;
|
||||
use Modules\Sirsoft\Ecommerce\Support\VatCalculator;
|
||||
|
||||
/**
|
||||
@@ -316,7 +317,8 @@ class OrderCalculationService
|
||||
$pointsPerItem = $this->calculatePointsEarning(
|
||||
$preparedItems,
|
||||
$itemsAfterOrderDiscount,
|
||||
$pointsUsageResult
|
||||
$pointsUsageResult,
|
||||
$input
|
||||
);
|
||||
$pointsPerItem = HookManager::applyFilters(
|
||||
'sirsoft-ecommerce.calculation.after_points_earning',
|
||||
@@ -855,12 +857,20 @@ class OrderCalculationService
|
||||
* @param array $preparedItems 준비된 아이템 배열
|
||||
* @param array $discountedItems 할인 후 아이템 배열 (주문쿠폰 적용 후)
|
||||
* @param array $pointsUsageResult 마일리지 사용 결과 (points_by_option 포함)
|
||||
* @param CalculationInput|null $input 계산 입력 (재계산 시 주문 시점 절사 기준 복원용)
|
||||
* @return array 옵션별 마일리지 배열 [product_option_id => points]
|
||||
*/
|
||||
protected function calculatePointsEarning(array $preparedItems, array $discountedItems, array $pointsUsageResult = []): array
|
||||
protected function calculatePointsEarning(array $preparedItems, array $discountedItems, array $pointsUsageResult = [], ?CalculationInput $input = null): array
|
||||
{
|
||||
$pointsPerItem = [];
|
||||
|
||||
// 적립 절사 기준. 재계산(부분취소·추가결제)은 주문 스냅샷을 우선한다 — 설정을 다시 읽으면
|
||||
// 운영자가 이후에 바꾼 절사 기준이 과거 주문에 소급 적용돼, 취소하지 않은 잔여분의
|
||||
// 적립액이 취소 처리만으로 달라진다.
|
||||
$rounding = $input?->mileagePolicySnapshot !== null
|
||||
? MileageRounding::fromOrderSnapshot($input->mileagePolicySnapshot)
|
||||
: MileageRounding::normalize($this->resolveMileageCurrencyRule($input));
|
||||
|
||||
foreach ($preparedItems as $item) {
|
||||
$optionId = $item['product_option_id'];
|
||||
$option = $item['product_option'];
|
||||
@@ -890,21 +900,52 @@ class OrderCalculationService
|
||||
if ($option->mileage_value !== null && $option->mileage_type !== null) {
|
||||
if ($option->mileage_type === 'fixed') {
|
||||
// 정액 적립: mileage_value를 그대로 사용 (수량 곱)
|
||||
$pointsPerItem[$optionId] = (int) floor($option->mileage_value * $item['quantity']);
|
||||
$pointsPerItem[$optionId] = MileageRounding::apply($option->mileage_value * $item['quantity'], $rounding);
|
||||
} else {
|
||||
// 정률 적립: earnableAmount 기준으로 계산
|
||||
$pointsPerItem[$optionId] = (int) floor($earnableAmount * $option->mileage_value / 100);
|
||||
$pointsPerItem[$optionId] = MileageRounding::apply($earnableAmount * $option->mileage_value / 100, $rounding);
|
||||
}
|
||||
} else {
|
||||
// 기본 마일리지 적립율 (설정값, 기본 1%)
|
||||
$defaultRate = (float) $this->settingsService->getSetting('mileage.default_earn_rate', 1);
|
||||
$pointsPerItem[$optionId] = (int) floor($earnableAmount * $defaultRate / 100);
|
||||
$pointsPerItem[$optionId] = MileageRounding::apply($earnableAmount * $defaultRate / 100, $rounding);
|
||||
}
|
||||
}
|
||||
|
||||
return $pointsPerItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* 적립 절사 기준을 담은 통화별 마일리지 규칙을 조회합니다.
|
||||
*
|
||||
* 마일리지는 표시통화가 아니라 기준통화(base_currency)로 적립·정산되므로, 규칙도
|
||||
* 기준통화 기준으로 고른다. 스냅샷 모드에서는 주문 시점 기준통화를, 신규 주문에서는
|
||||
* 현재 기본 통화를 쓴다. 해당 통화 규칙이 없으면 첫 행(기본 통화 규칙)으로 폴백한다 —
|
||||
* `UserMileageService::currencyRule()` 과 같은 해석 규칙이다.
|
||||
*
|
||||
* @param CalculationInput|null $input 계산 입력
|
||||
* @return array|null 통화별 마일리지 규칙 (없으면 null → 절사 기본값 적용)
|
||||
*/
|
||||
protected function resolveMileageCurrencyRule(?CalculationInput $input): ?array
|
||||
{
|
||||
$rules = (array) $this->settingsService->getSetting('mileage.currency_rules', []);
|
||||
|
||||
if ($rules === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$currency = $input->metadata['currency_snapshot']['base_currency']
|
||||
?? $this->currencyService->getDefaultCurrency();
|
||||
|
||||
foreach ($rules as $rule) {
|
||||
if (is_array($rule) && ($rule['currency_code'] ?? null) === $currency) {
|
||||
return $rule;
|
||||
}
|
||||
}
|
||||
|
||||
return is_array($rules[0] ?? null) ? $rules[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 단계 2-b: 과세/면세 금액을 분류합니다.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user