관리자 환경설정이 값을 저장은 하지만 실제 동작에는 닿지 않던 결함군을 정리했다. 설정 화면(min/max)·저장 검증(FormRequest)·런타임 적용(Service) 세 계층이 각자 리터럴을 들고 있어 서로 조용히 갈라지던 것이 공통 원인이다. 경계값 SSoT 도입: - config/core.php `settings_limits` 를 단일 출처로 두고, FormRequest 는 이 값으로 규칙을 만들고 화면은 설정 응답의 `_meta.limits` 로 같은 값을 받아 바인딩한다. - 게시판·이커머스도 각 모듈 config 의 limits 를 동일 구조로 노출한다. 적용되지 않던 정책을 실제로 적용: - 비밀번호 최소 길이·특수문자 필수(신규 지정 7개 경로. 로그인은 제외 — 정책을 올렸을 때 기존 회원이 자기 계정에 접근조차 못 하는 데드락을 막기 위함) - 계정 잠금 시간 0 = 무한대(전용 컬럼 분리. timestamp 상한과 NULL 규약 때문에 기존 컬럼 재사용이 불가능하다) + 관리자 수동 해제 경로 - 업로드 최대 크기·허용 확장자, 게시판 첨부 개수·댓글 깊이, 페이지 첨부 정책, 장바구니 수량·구매 한도, 마일리지 사용 한도, 주문 부가세 파생 결함: - 큐 Job(sync 드라이버)이 진행 중인 요청의 Request 바인딩을 덮어써, 뒤이어 실행되는 훅 리스너가 헤더를 잃고 조용히 건너뛰었다. Job 이 원 바인딩을 복원하도록 고치고, 전송 헤더가 필요한 리스너는 동기 실행으로 선언한다. - 확장 업데이트 실패 시 상태만 되돌리고 상태 캐시를 비우지 않아, 그 확장의 관리자 화면만 캐시 TTL(기본 하루) 동안 404 로 남았다. 실패 경로에도 무효화를 대칭으로 두고, 빈 목록 자체를 캐시하지 않는다. - 글 작성 시 첨부 파일이 Service 로 전달되지 않아 검증·권한은 통과하고 첨부만 사라졌다. - 환경설정 저장 실패 안내가 내부 설정 키를 그대로 노출했다(105개 항목에 라벨 부여). 재발 방지: - audit 룰 3종(레이아웃 경계 리터럴 / FormRequest 경계 불일치 / Service 재클램프) - 테스트 실행 범위 강제 훅(check-test-scope) - 트러블슈팅 사례 2건(큐 Job 요청 오염 / 확장 상태 캐시 고착) 공개 이슈: gnuboard/g7
194 lines
8.5 KiB
PHP
194 lines
8.5 KiB
PHP
<?php
|
|
|
|
namespace Modules\Sirsoft\Ecommerce\DTO;
|
|
|
|
/**
|
|
* 주문 계산 합계 정보 DTO
|
|
*
|
|
* 주문의 전체 금액 합계, 할인, 배송비, 세금 등의 요약 정보를 담습니다.
|
|
*/
|
|
class Summary
|
|
{
|
|
/**
|
|
* @param int $subtotal 상품 금액 소계 (할인 전)
|
|
* @param int $productCouponDiscount 상품/카테고리 쿠폰 할인금액 합계
|
|
* @param int $codeDiscount 할인코드 할인금액 합계
|
|
* @param int $orderCouponDiscount 주문 쿠폰 할인금액 합계
|
|
* @param int $totalDiscount 총 할인금액
|
|
* @param int $baseShippingTotal 기본 배송비 합계
|
|
* @param int $extraShippingTotal 추가 배송비(도서산간) 합계
|
|
* @param int $totalShipping 총 배송비 (기본 + 추가)
|
|
* @param int $shippingDiscount 배송비 할인
|
|
* @param int $taxableAmount 과세 금액 합계
|
|
* @param int $taxFreeAmount 면세 금액 합계
|
|
* @param int $vatAmount 부가세 합계 (옵션별 세율 반영, 과세표준에 내재된 금액)
|
|
* @param int $pointsEarning 적립 예정 마일리지 합계
|
|
* @param int $pointsUsed 사용 마일리지 합계
|
|
* @param int $paymentAmount 결제금액 (마일리지 사용 전)
|
|
* @param int $finalAmount 최종 지불금액
|
|
* @param MultiCurrencyPrices|null $multiCurrency 다중 통화 변환 금액
|
|
* @param string|null $selectedPaymentCurrency 선택된 결제 통화
|
|
* @param array<string, mixed> $metadata 플러그인 확장용 메타데이터
|
|
* - deposit_used: 예치금 사용 합계 (예치금 플러그인)
|
|
* - gift_card_used: 상품권 사용 합계 (상품권 플러그인)
|
|
* - grade_discount: 회원등급 할인 합계 (회원등급 플러그인)
|
|
*/
|
|
public function __construct(
|
|
public int $subtotal = 0,
|
|
public int $productCouponDiscount = 0,
|
|
public int $codeDiscount = 0,
|
|
public int $orderCouponDiscount = 0,
|
|
public int $totalDiscount = 0,
|
|
public int $baseShippingTotal = 0,
|
|
public int $extraShippingTotal = 0,
|
|
public int $totalShipping = 0,
|
|
public int $shippingDiscount = 0,
|
|
public int $taxableAmount = 0,
|
|
public int $taxFreeAmount = 0,
|
|
public int $vatAmount = 0,
|
|
public int $pointsEarning = 0,
|
|
public int $pointsUsed = 0,
|
|
public int $paymentAmount = 0,
|
|
public int $finalAmount = 0,
|
|
public ?MultiCurrencyPrices $multiCurrency = null,
|
|
public ?string $selectedPaymentCurrency = null,
|
|
public array $metadata = [],
|
|
) {}
|
|
|
|
/**
|
|
* 총 할인금액을 계산합니다.
|
|
*
|
|
* @return int 총 할인금액
|
|
*/
|
|
public function calculateTotalDiscount(): int
|
|
{
|
|
return $this->productCouponDiscount + $this->codeDiscount + $this->orderCouponDiscount;
|
|
}
|
|
|
|
/**
|
|
* 총 배송비를 계산합니다 (기본 + 추가).
|
|
*
|
|
* @return int 총 배송비
|
|
*/
|
|
public function calculateTotalShipping(): int
|
|
{
|
|
return $this->baseShippingTotal + $this->extraShippingTotal;
|
|
}
|
|
|
|
/**
|
|
* 결제금액을 계산합니다.
|
|
*
|
|
* @return int 결제금액
|
|
*/
|
|
public function calculatePaymentAmount(): int
|
|
{
|
|
return max(0, $this->subtotal - $this->totalDiscount + $this->totalShipping - $this->shippingDiscount);
|
|
}
|
|
|
|
/**
|
|
* 최종 지불금액을 계산합니다.
|
|
*
|
|
* @return int 최종 지불금액
|
|
*/
|
|
public function calculateFinalAmount(): int
|
|
{
|
|
return max(0, $this->paymentAmount - $this->pointsUsed);
|
|
}
|
|
|
|
/**
|
|
* 배열로 변환합니다.
|
|
*
|
|
* @return array<string, mixed> 직렬화된 합계 배열
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
$result = [
|
|
'subtotal' => $this->subtotal,
|
|
'subtotal_formatted' => ecommerce_format_price($this->subtotal),
|
|
'product_coupon_discount' => $this->productCouponDiscount,
|
|
'product_coupon_discount_formatted' => ecommerce_format_price($this->productCouponDiscount),
|
|
'code_discount' => $this->codeDiscount,
|
|
'code_discount_formatted' => ecommerce_format_price($this->codeDiscount),
|
|
'order_coupon_discount' => $this->orderCouponDiscount,
|
|
'order_coupon_discount_formatted' => ecommerce_format_price($this->orderCouponDiscount),
|
|
'total_coupon_discount' => $this->productCouponDiscount + $this->orderCouponDiscount,
|
|
'total_coupon_discount_formatted' => ecommerce_format_price($this->productCouponDiscount + $this->orderCouponDiscount),
|
|
'total_discount' => $this->totalDiscount,
|
|
'discount_formatted' => ecommerce_format_price($this->totalDiscount),
|
|
'base_shipping_total' => $this->baseShippingTotal,
|
|
'extra_shipping_total' => $this->extraShippingTotal,
|
|
'total_shipping' => $this->totalShipping,
|
|
'total_shipping_fee' => $this->totalShipping,
|
|
'shipping_fee_formatted' => ecommerce_format_price($this->totalShipping),
|
|
'shipping_discount' => $this->shippingDiscount,
|
|
'shipping_discount_formatted' => ecommerce_format_price($this->shippingDiscount),
|
|
'taxable_amount' => $this->taxableAmount,
|
|
'tax_free_amount' => $this->taxFreeAmount,
|
|
'vat_amount' => $this->vatAmount,
|
|
'points_earning' => $this->pointsEarning,
|
|
'total_mileage' => $this->pointsEarning,
|
|
'mileage_formatted' => number_format($this->pointsEarning).'P',
|
|
'points_used' => $this->pointsUsed,
|
|
// 마일리지 사용액(차감) 포맷 — 다른 금액과 동일한 통화 포맷 (요약/결제완료 화면이 바인딩).
|
|
// 마일리지는 base_currency 단일 정산이므로 multi_currency 변환 없이 루트 키로만 제공.
|
|
'points_used_formatted' => ecommerce_format_price($this->pointsUsed),
|
|
'payment_amount' => $this->paymentAmount,
|
|
'payment_amount_formatted' => ecommerce_format_price($this->paymentAmount),
|
|
'final_amount' => $this->finalAmount,
|
|
'final_amount_formatted' => ecommerce_format_price($this->finalAmount),
|
|
// 하위 호환 (deprecated)
|
|
'coupon_discount' => $this->productCouponDiscount,
|
|
'coupon_discount_formatted' => ecommerce_format_price($this->productCouponDiscount),
|
|
'order_discount' => $this->orderCouponDiscount,
|
|
'order_discount_formatted' => ecommerce_format_price($this->orderCouponDiscount),
|
|
];
|
|
|
|
if ($this->selectedPaymentCurrency !== null) {
|
|
$result['selected_payment_currency'] = $this->selectedPaymentCurrency;
|
|
}
|
|
|
|
if ($this->multiCurrency !== null) {
|
|
$result['multi_currency'] = $this->multiCurrency->toArray();
|
|
}
|
|
|
|
if (! empty($this->metadata)) {
|
|
$result['metadata'] = $this->metadata;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 배열에서 DTO를 생성합니다.
|
|
*
|
|
* @param array $data 배열 데이터
|
|
* @return self 생성된 Summary DTO
|
|
*/
|
|
public static function fromArray(array $data): self
|
|
{
|
|
return new self(
|
|
subtotal: $data['subtotal'] ?? 0,
|
|
productCouponDiscount: $data['product_coupon_discount'] ?? $data['coupon_discount'] ?? 0,
|
|
codeDiscount: $data['code_discount'] ?? 0,
|
|
orderCouponDiscount: $data['order_coupon_discount'] ?? $data['order_discount'] ?? 0,
|
|
totalDiscount: $data['total_discount'] ?? 0,
|
|
baseShippingTotal: $data['base_shipping_total'] ?? 0,
|
|
extraShippingTotal: $data['extra_shipping_total'] ?? 0,
|
|
totalShipping: $data['total_shipping'] ?? 0,
|
|
shippingDiscount: $data['shipping_discount'] ?? 0,
|
|
taxableAmount: $data['taxable_amount'] ?? 0,
|
|
taxFreeAmount: $data['tax_free_amount'] ?? 0,
|
|
vatAmount: $data['vat_amount'] ?? 0,
|
|
pointsEarning: $data['points_earning'] ?? 0,
|
|
pointsUsed: $data['points_used'] ?? 0,
|
|
paymentAmount: $data['payment_amount'] ?? 0,
|
|
finalAmount: $data['final_amount'] ?? 0,
|
|
multiCurrency: isset($data['multi_currency'])
|
|
? MultiCurrencyPrices::fromArray($data['multi_currency'])
|
|
: null,
|
|
selectedPaymentCurrency: $data['selected_payment_currency'] ?? null,
|
|
metadata: $data['metadata'] ?? [],
|
|
);
|
|
}
|
|
}
|