v7.0.0 release
This commit is contained in:
1 parent
0e7fa04b03
commit
c4ea9a6cd1
3582 files changed
+626189
-160151
No files matched your search
@@ -6,11 +6,14 @@ use App\Extension\HookManager;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\OrderOptionSourceTypeEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\OrderStatusEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\PaymentMethodEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Exceptions\OrderProcessingException;
|
||||
use Modules\Sirsoft\Ecommerce\Models\Order;
|
||||
use Modules\Sirsoft\Ecommerce\Models\OrderOption;
|
||||
use Modules\Sirsoft\Ecommerce\Models\ProductReview;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\OrderOptionRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\OrderRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\OrderShippingRepositoryInterface;
|
||||
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\ProductReviewRepositoryInterface;
|
||||
|
||||
/**
|
||||
* 주문 옵션 서비스
|
||||
@@ -22,12 +25,63 @@ class OrderOptionService
|
||||
/**
|
||||
* @param OrderOptionRepositoryInterface $orderOptionRepository 주문 옵션 Repository
|
||||
* @param OrderShippingRepositoryInterface $orderShippingRepository 주문 배송 Repository
|
||||
* @param OrderRepositoryInterface $orderRepository 주문 Repository
|
||||
* @param ProductReviewRepositoryInterface $productReviewRepository 상품 리뷰 Repository
|
||||
*/
|
||||
public function __construct(
|
||||
protected OrderOptionRepositoryInterface $orderOptionRepository,
|
||||
protected OrderShippingRepositoryInterface $orderShippingRepository,
|
||||
protected OrderRepositoryInterface $orderRepository,
|
||||
protected ProductReviewRepositoryInterface $productReviewRepository,
|
||||
protected StockService $stockService,
|
||||
protected EcommerceSettingsService $settingsService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 취소 → 판매 상태 복원 전이인지 판정합니다.
|
||||
*
|
||||
* 옵션의 변경 전 상태가 취소상태(cancelled/partial_cancelled)이고 변경 후 상태가
|
||||
* 판매 반영 상태(payment_complete~confirmed)일 때만 재고 재차감 대상이다.
|
||||
* OrderService::isReactivationTransition 과 동일 정책(SSoT 집합 재사용)을 옵션 단위로 적용한다.
|
||||
*
|
||||
* @param string|null $oldStatus 변경 전 옵션 상태 값
|
||||
* @param OrderStatusEnum $newStatus 변경 후 옵션 상태
|
||||
* @return bool 재차감 대상 전이 여부
|
||||
*/
|
||||
protected function isReactivationTransition(?string $oldStatus, OrderStatusEnum $newStatus): bool
|
||||
{
|
||||
if ($oldStatus === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array($oldStatus, OrderStatusEnum::syncExcludedValues(), true)
|
||||
&& in_array($newStatus->value, OrderStatusEnum::salesEligibleValues(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 판매 상태 → 취소 전이인지 판정합니다.
|
||||
*
|
||||
* 옵션의 변경 전 상태가 판매 반영 상태(payment_complete~confirmed, 재고 차감됨)이고
|
||||
* 변경 후 상태가 취소상태(cancelled/partial_cancelled)일 때 재고 복원 대상이다.
|
||||
* isReactivationTransition(재차감) 의 역방향이며, 동일 SSoT 집합을 재사용한다.
|
||||
*
|
||||
* per-line 상태 변경 드롭다운에서 "주문취소" 로 전이할 때, PG 환불 동반(취소 모달,
|
||||
* OrderCancellationService) 경로가 아니어도 재고가 복원되어야 한다(재고-주문 정합성).
|
||||
*
|
||||
* @param string|null $oldStatus 변경 전 옵션 상태 값
|
||||
* @param OrderStatusEnum $newStatus 변경 후 옵션 상태
|
||||
* @return bool 재고 복원 대상 전이 여부
|
||||
*/
|
||||
protected function isCancellationTransition(?string $oldStatus, OrderStatusEnum $newStatus): bool
|
||||
{
|
||||
if ($oldStatus === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array($oldStatus, OrderStatusEnum::salesEligibleValues(), true)
|
||||
&& in_array($newStatus->value, OrderStatusEnum::syncExcludedValues(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 주문 옵션 상태를 수량 단위로 변경합니다.
|
||||
* 변경 수량이 전체 수량보다 작으면 레코드를 분할합니다.
|
||||
@@ -36,23 +90,78 @@ class OrderOptionService
|
||||
* @param OrderStatusEnum $newStatus 변경할 상태
|
||||
* @param int $quantity 변경할 수량
|
||||
* @param array $metadata 추가 정보 (carrier, tracking_number 등)
|
||||
* @param bool $restoreStockOnCancel 판매 → 취소 전이 시 이 메서드가 재고를 복원할지 여부.
|
||||
* per-line 상태변경(직접 호출)은 true(기본) — 이 경로가 유일한 복원 주체.
|
||||
* 취소 모달(OrderCancellationService)은 false — 자체 restoreStock() 이
|
||||
* 복원을 전담하므로 여기서 복원하면 이중 복원이 된다.
|
||||
* @return array{original: OrderOption, split: ?OrderOption} 변경 결과
|
||||
*/
|
||||
public function changeStatusWithQuantity(
|
||||
OrderOption $option,
|
||||
OrderStatusEnum $newStatus,
|
||||
int $quantity,
|
||||
array $metadata = []
|
||||
array $metadata = [],
|
||||
bool $restoreStockOnCancel = true
|
||||
): array {
|
||||
// 변경 전 훅
|
||||
HookManager::doAction('sirsoft-ecommerce.order_option.before_status_change', $option, $newStatus, $quantity);
|
||||
|
||||
$result = ['original' => $option, 'split' => null];
|
||||
|
||||
DB::transaction(function () use ($option, $newStatus, $quantity, $metadata, &$result) {
|
||||
// 변경 전 옵션 상태 캡처 (취소↔판매 전이 판정용)
|
||||
$oldStatusValue = $option->option_status instanceof OrderStatusEnum
|
||||
? $option->option_status->value
|
||||
: $option->option_status;
|
||||
|
||||
// 상태 전이 규칙 2차 도메인 불변식 가드 (우회 방어).
|
||||
// 정상 흐름은 FormRequest(단건/일괄)가 먼저 422 로 막으므로 여기 도달하지 않는다.
|
||||
// 취소(CANCELLED) 진입은 게이트가 통과 처리하므로 취소 모달 경로는 비간섭.
|
||||
$oldEnum = $oldStatusValue !== null ? OrderStatusEnum::tryFrom($oldStatusValue) : null;
|
||||
if ($oldEnum instanceof OrderStatusEnum && ! $oldEnum->canTransitionTo($newStatus)) {
|
||||
throw new OrderProcessingException(
|
||||
__('sirsoft-ecommerce::validation.orders.status_transition.invalid', [
|
||||
'from' => $oldEnum->label(),
|
||||
'to' => $newStatus->label(),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
$isReactivation = $this->isReactivationTransition($oldStatusValue, $newStatus);
|
||||
$isCancellation = $this->isCancellationTransition($oldStatusValue, $newStatus);
|
||||
// 판매 → 취소 전이 시 재고 복원 여부.
|
||||
// - $restoreStockOnCancel=false (취소 모달 경로): OrderCancellationService::restoreStock() 이 전담 → 여기선 스킵(이중 복원 방지)
|
||||
// - $restoreStockOnCancel=true (per-line 직접 경로): 이 메서드가 유일 복원 주체
|
||||
// 복원 여부는 설정(stock_restore_on_cancel)을 따른다(취소 모달 경로와 동일 정책).
|
||||
$shouldRestoreOnCancel = $restoreStockOnCancel && $isCancellation && $this->settingsService->getSetting(
|
||||
'order_settings.stock_restore_on_cancel',
|
||||
true
|
||||
);
|
||||
|
||||
DB::transaction(function () use ($option, $newStatus, $quantity, $metadata, $isReactivation, $shouldRestoreOnCancel, &$result) {
|
||||
if ($quantity === $option->quantity) {
|
||||
// 전체 수량 변경 → UPDATE만
|
||||
$this->orderOptionRepository->update($option, ['option_status' => $newStatus]);
|
||||
$updateData = ['option_status' => $newStatus];
|
||||
// 배송완료 진입 시점 기록 (confirmed_at 과 대칭 — 지연 적립 기준)
|
||||
if ($newStatus === OrderStatusEnum::DELIVERED && $option->delivered_at === null) {
|
||||
$updateData['delivered_at'] = now();
|
||||
}
|
||||
$this->orderOptionRepository->update($option, $updateData);
|
||||
|
||||
// 배송 정보(택배사·송장번호) 기록 — 병합 전 상태 변경 대상 옵션에 반영.
|
||||
$this->applyShippingTracking($option, $newStatus, $metadata);
|
||||
|
||||
// 취소 → 판매 상태 복원 전이면 이 옵션(전체 수량)의 재고를 재차감한다.
|
||||
// (취소 시 복원된 재고를 되돌리는 역연산 — 부족 시 예외 전파 → 트랜잭션 롤백으로 상태 복원 차단)
|
||||
if ($isReactivation) {
|
||||
$this->stockService->redeductOrderOptionForReactivation($option);
|
||||
}
|
||||
|
||||
// 판매 → 취소 전이면 이 옵션(전체 수량)의 재고를 복원한다.
|
||||
// PG 환불 동반(취소 모달) 경로가 아니어도 재고는 복원되어야 한다(재고-주문 정합성).
|
||||
// 복원 + is_stock_deducted 플래그 정리를 원자적으로 처리.
|
||||
if ($shouldRestoreOnCancel) {
|
||||
$this->stockService->restoreOptionStockForOrderOption($option, $quantity);
|
||||
}
|
||||
|
||||
// 병합 가능한 형제 레코드 검색 → 있으면 병합
|
||||
$mergeCandidate = $this->orderOptionRepository->findMergeCandidate($option, $newStatus);
|
||||
@@ -74,6 +183,10 @@ class OrderOptionService
|
||||
$splitOption->option_status = $newStatus;
|
||||
$splitOption->parent_option_id = $option->id;
|
||||
$splitOption->source_type = OrderOptionSourceTypeEnum::SPLIT;
|
||||
// 배송완료로 분할 전이 시 분할 레코드에 배송완료 시점 기록
|
||||
if ($newStatus === OrderStatusEnum::DELIVERED && $splitOption->delivered_at === null) {
|
||||
$splitOption->delivered_at = now();
|
||||
}
|
||||
|
||||
// 분할 레코드 금액 = 원본 × ratio
|
||||
$this->applySplitAmounts($splitOption, $origAmounts, $ratio, $quantity);
|
||||
@@ -83,6 +196,21 @@ class OrderOptionService
|
||||
$this->applyRemainingAmounts($option, $origAmounts, $splitOption, $remainingQuantity);
|
||||
$this->orderOptionRepository->save($option);
|
||||
|
||||
// 배송 정보(택배사·송장번호) 기록 — 새 상태로 전이한 분할 레코드에 반영.
|
||||
$this->applyShippingTracking($splitOption, $newStatus, $metadata);
|
||||
|
||||
// 취소 → 판매 상태 복원 전이면 판매 상태로 전이된 분할 레코드(quantity)만 재차감한다.
|
||||
// 잔여 원본($option)은 취소 상태를 유지하므로 재차감 대상 아님.
|
||||
if ($isReactivation) {
|
||||
$this->stockService->redeductOrderOptionForReactivation($splitOption);
|
||||
}
|
||||
|
||||
// 판매 → 취소 전이면 취소된 분할 레코드(quantity)만 재고 복원한다.
|
||||
// 잔여 원본($option)은 판매 상태를 유지하므로 복원 대상 아님(차감 유지).
|
||||
if ($shouldRestoreOnCancel) {
|
||||
$this->stockService->restoreOptionStockForOrderOption($splitOption, $quantity);
|
||||
}
|
||||
|
||||
// 병합 가능한 형제 레코드 검색 → 있으면 병합
|
||||
$mergeCandidate = $this->orderOptionRepository->findMergeCandidate($splitOption, $newStatus);
|
||||
if ($mergeCandidate && $mergeCandidate->id !== $splitOption->id) {
|
||||
@@ -101,6 +229,46 @@ class OrderOptionService
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 배송 관련 상태 전이 시 택배사·송장번호를 해당 옵션의 배송 레코드에 기록합니다.
|
||||
*
|
||||
* 관리자 주문상태 변경(일괄변경)에서 배송준비완료/배송중/배송완료로 전이할 때 입력한
|
||||
* 택배사·송장번호(metadata)를 옵션 단위 배송 레코드에 반영한다. 배송 상태가 아니거나
|
||||
* metadata 에 배송정보가 없으면 아무 것도 하지 않는다(상태만 변경되는 경로 무영향).
|
||||
*
|
||||
* @param OrderOption $option 상태가 변경된 옵션
|
||||
* @param OrderStatusEnum $newStatus 전이 목표 상태
|
||||
* @param array $metadata ['carrier_id' => int, 'tracking_number' => string] 부분 배열
|
||||
*/
|
||||
private function applyShippingTracking(OrderOption $option, OrderStatusEnum $newStatus, array $metadata): void
|
||||
{
|
||||
$carrierId = $metadata['carrier_id'] ?? null;
|
||||
$trackingNumber = $metadata['tracking_number'] ?? null;
|
||||
|
||||
// 배송정보가 전혀 없으면 기록할 것이 없음.
|
||||
if (($carrierId === null || $carrierId === '') && ($trackingNumber === null || $trackingNumber === '')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 배송 정보가 의미 있는 상태(배송준비완료/배송중/배송완료)로의 전이에만 반영.
|
||||
$shippingStatuses = [
|
||||
OrderStatusEnum::SHIPPING_READY,
|
||||
OrderStatusEnum::SHIPPING,
|
||||
OrderStatusEnum::DELIVERED,
|
||||
];
|
||||
if (! in_array($newStatus, $shippingStatuses, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->orderShippingRepository->updateTrackingByOrderOptionId(
|
||||
$option->id,
|
||||
[
|
||||
'carrier_id' => $carrierId,
|
||||
'tracking_number' => $trackingNumber,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 일괄 상태 변경 (수량 분할 지원)
|
||||
*
|
||||
@@ -116,7 +284,16 @@ class OrderOptionService
|
||||
): array {
|
||||
// 스냅샷 캡처 (ChangeDetector용)
|
||||
$optionIds = collect($items)->pluck('option_id')->filter()->unique()->toArray();
|
||||
$snapshots = OrderOption::whereIn('id', $optionIds)->get()->keyBy('id')->map->toArray()->all();
|
||||
$snapshots = $this->orderOptionRepository->getSnapshotsByIds($optionIds);
|
||||
|
||||
// 결제완료(payment_complete) 목표 전이 시 본인인증(IDV) 정책 가드 (A8 / N4).
|
||||
// 관리자 주문상세 "주문상태 변경"(옵션 일괄변경)이 결제완료로 부모 주문을 전이시키는,
|
||||
// 실무에서 가장 흔한 결제승인 경로다. OrderService::update / bulkUpdate 와 동일하게
|
||||
// 변경 자체(트랜잭션) 전에 IDV 훅을 발화해 enforce 가 미인증 시 428 로 전이를 막는다.
|
||||
// 부모 주문의 결제수단에 따라 DBANK → 입금확인, 그 외 → 결제 승인으로 분기(결정 7).
|
||||
if ($newStatus === OrderStatusEnum::PAYMENT_COMPLETE) {
|
||||
$this->enforcePaymentCompleteIdv($optionIds);
|
||||
}
|
||||
|
||||
// 일괄 변경 전 훅
|
||||
HookManager::doAction('sirsoft-ecommerce.order_option.before_bulk_status_change', $items, $newStatus);
|
||||
@@ -152,7 +329,7 @@ class OrderOptionService
|
||||
});
|
||||
|
||||
// 부모 주문 상태 동기화
|
||||
$orderIds = OrderOption::whereIn('id', $optionIds)->pluck('order_id')->unique()->toArray();
|
||||
$orderIds = $this->orderOptionRepository->getOrderIdsByOptionIds($optionIds);
|
||||
foreach ($orderIds as $orderId) {
|
||||
$this->syncParentOrderStatus($orderId);
|
||||
}
|
||||
@@ -209,7 +386,6 @@ class OrderOptionService
|
||||
* @param array $origAmounts 원본 금액 캡처 데이터
|
||||
* @param float $ratio 분할 비율 (변경수량 / 원본수량)
|
||||
* @param int $quantity 분할 수량
|
||||
* @return void
|
||||
*/
|
||||
private function applySplitAmounts(OrderOption $splitOption, array $origAmounts, float $ratio, int $quantity): void
|
||||
{
|
||||
@@ -251,7 +427,6 @@ class OrderOptionService
|
||||
* @param array $origAmounts 원본 금액 캡처 데이터
|
||||
* @param OrderOption $splitOption 분할 레코드
|
||||
* @param int $remainingQuantity 잔여 수량
|
||||
* @return void
|
||||
*/
|
||||
private function applyRemainingAmounts(OrderOption $option, array $origAmounts, OrderOption $splitOption, int $remainingQuantity): void
|
||||
{
|
||||
@@ -293,14 +468,12 @@ class OrderOptionService
|
||||
*
|
||||
* @param OrderOption $survivor 생존 레코드
|
||||
* @param OrderOption $consumed 피흡수 레코드
|
||||
* @return void
|
||||
*/
|
||||
private function mergeOptions(OrderOption $survivor, OrderOption $consumed): void
|
||||
{
|
||||
// 1. 의존 레코드 이전 (cascade 삭제 방지)
|
||||
$this->orderShippingRepository->transferByOrderOptionId($consumed->id, $survivor->id);
|
||||
ProductReview::where('order_option_id', $consumed->id)
|
||||
->update(['order_option_id' => $survivor->id]);
|
||||
$this->productReviewRepository->transferByOrderOptionId($consumed->id, $survivor->id);
|
||||
|
||||
// 2. 수량/금액 합산
|
||||
$amountFields = [
|
||||
@@ -334,8 +507,7 @@ class OrderOptionService
|
||||
$this->orderOptionRepository->save($survivor);
|
||||
|
||||
// 3. 피흡수 레코드의 분할 자식들을 생존 레코드로 이전
|
||||
OrderOption::where('parent_option_id', $consumed->id)
|
||||
->update(['parent_option_id' => $survivor->id]);
|
||||
$this->orderOptionRepository->transferChildren($consumed->id, $survivor->id);
|
||||
|
||||
// 4. 피흡수 레코드 삭제 (의존 레코드 이미 이전됨 → cascade 안전)
|
||||
$this->orderOptionRepository->delete($consumed);
|
||||
@@ -383,33 +555,81 @@ class OrderOptionService
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 결제완료 전이 대상 주문들에 대해 본인인증(IDV) 정책 가드 훅을 발화합니다 (A8 / N4).
|
||||
*
|
||||
* 옵션 일괄변경으로 부모 주문이 결제완료로 전이되기 직전, 이미 결제완료가 아닌 주문만
|
||||
* 골라 결제수단별로 IDV 훅을 발화한다(DBANK → 입금확인, 그 외 → 결제 승인). 미인증 시
|
||||
* EnforceIdentityPolicyListener 가 428(IdentityVerificationRequiredException)을 던져
|
||||
* 트랜잭션 진입 전에 변경을 차단한다. 정책 비활성(enabled=false) 시에는 enforce 가 통과시킨다.
|
||||
*
|
||||
* @param array<int> $optionIds 변경 대상 옵션 ID 배열
|
||||
*/
|
||||
private function enforcePaymentCompleteIdv(array $optionIds): void
|
||||
{
|
||||
$orderIds = $this->orderOptionRepository->getOrderIdsByOptionIds($optionIds);
|
||||
|
||||
foreach ($orderIds as $orderId) {
|
||||
$order = $this->orderRepository->find($orderId);
|
||||
if (! $order) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 이미 결제완료인 주문은 전이가 일어나지 않으므로 가드 대상에서 제외.
|
||||
$currentStatus = $order->order_status instanceof OrderStatusEnum
|
||||
? $order->order_status->value
|
||||
: $order->order_status;
|
||||
if ($currentStatus === OrderStatusEnum::PAYMENT_COMPLETE->value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$paymentMethod = $order->payment?->payment_method;
|
||||
$paymentMethod = $paymentMethod instanceof PaymentMethodEnum
|
||||
? $paymentMethod->value
|
||||
: $paymentMethod;
|
||||
$idvHook = $paymentMethod === PaymentMethodEnum::DBANK->value
|
||||
? 'sirsoft-ecommerce.payment.before_confirm_deposit'
|
||||
: 'sirsoft-ecommerce.payment.before_approve';
|
||||
HookManager::doAction($idvHook, $order);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 부모 주문 상태를 자식 옵션 상태에 맞게 동기화합니다.
|
||||
*
|
||||
* - 모든 활성 옵션(취소 제외)이 동일 상태 → 주문도 해당 상태로 변경
|
||||
* - 활성 옵션(취소 제외)이 모두 동일 상태 → 주문도 해당 상태로 변경
|
||||
* - 혼합 상태 → 가장 낮은 진행 단계(보수적)로 설정
|
||||
* - 활성 옵션이 0개(전부 취소) → 주문도 취소(CANCELLED)로 전이
|
||||
*
|
||||
* @param int $orderId 동기화할 주문 ID
|
||||
* 부분취소는 별도 주문 상태가 아니라 "취소 옵션 + 잔여 활성 옵션 공존" 파생 상태다.
|
||||
* 따라서 주문 상태는 항상 잔여 활성 옵션 기준으로 결정하고, 부분취소 여부는
|
||||
* Order::isPartiallyCancelled() 파생 플래그로 노출한다 (PO 2026-06-22, partial_cancelled 제거).
|
||||
*
|
||||
* @param int $orderId 동기화할 주문 ID
|
||||
*/
|
||||
private function syncParentOrderStatus(int $orderId): void
|
||||
public function syncParentOrderStatus(int $orderId): void
|
||||
{
|
||||
$order = Order::find($orderId);
|
||||
$order = $this->orderRepository->find($orderId);
|
||||
if (! $order) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 취소 상태를 제외한 활성 옵션의 상태 값 목록 (string)
|
||||
// 취소/클레임 등 별도 라이프사이클을 제외한 활성 옵션의 상태 값 목록 (string)
|
||||
// 제외 목록은 OrderStatusEnum SSoT 로 일원화한다.
|
||||
$activeStatusValues = $order->options()
|
||||
->whereNotIn('option_status', [
|
||||
OrderStatusEnum::CANCELLED->value,
|
||||
OrderStatusEnum::PARTIAL_CANCELLED->value,
|
||||
])
|
||||
->whereNotIn('option_status', OrderStatusEnum::syncExcludedValues())
|
||||
->pluck('option_status')
|
||||
->map(fn ($s) => $s instanceof OrderStatusEnum ? $s->value : $s)
|
||||
->unique()
|
||||
->values();
|
||||
|
||||
if ($activeStatusValues->isEmpty()) {
|
||||
// 활성 옵션이 하나도 없으면 주문 전체가 취소된 것 → CANCELLED 로 전이.
|
||||
// (옵션이 아예 없는 비정상 데이터는 전이 대상에서 제외.)
|
||||
if ($order->options()->exists()) {
|
||||
$this->transitionOrderStatus($order, OrderStatusEnum::CANCELLED);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -418,17 +638,8 @@ class OrderOptionService
|
||||
$newStatus = OrderStatusEnum::from($activeStatusValues->first());
|
||||
} else {
|
||||
// 혼합 상태 → 진행 순서상 가장 낮은 상태 (보수적)
|
||||
$progressOrder = [
|
||||
OrderStatusEnum::PENDING_ORDER->value,
|
||||
OrderStatusEnum::PENDING_PAYMENT->value,
|
||||
OrderStatusEnum::PAYMENT_COMPLETE->value,
|
||||
OrderStatusEnum::SHIPPING_HOLD->value,
|
||||
OrderStatusEnum::PREPARING->value,
|
||||
OrderStatusEnum::SHIPPING_READY->value,
|
||||
OrderStatusEnum::SHIPPING->value,
|
||||
OrderStatusEnum::DELIVERED->value,
|
||||
OrderStatusEnum::CONFIRMED->value,
|
||||
];
|
||||
// 진행 순서는 OrderStatusEnum SSoT 로 일원화한다 (전이 규칙과 동일 배열 공유).
|
||||
$progressOrder = OrderStatusEnum::progressOrderValues();
|
||||
|
||||
$lowestIndex = PHP_INT_MAX;
|
||||
foreach ($activeStatusValues as $statusValue) {
|
||||
@@ -441,9 +652,30 @@ class OrderOptionService
|
||||
$newStatus = OrderStatusEnum::from($progressOrder[$lowestIndex]);
|
||||
}
|
||||
|
||||
if ($order->order_status !== $newStatus) {
|
||||
$order->update(['order_status' => $newStatus->value]);
|
||||
$this->transitionOrderStatus($order, $newStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 주문 상태를 목표 상태로 전이하고 변경 시 상태변경 알림 훅을 발화합니다.
|
||||
*
|
||||
* syncParentOrderStatus 의 잔여옵션 파생 전이와 전부취소(CANCELLED) 전이가 공유하는 헬퍼.
|
||||
*
|
||||
* @param Order $order 대상 주문
|
||||
* @param OrderStatusEnum $newStatus 목표 주문 상태
|
||||
*/
|
||||
private function transitionOrderStatus($order, OrderStatusEnum $newStatus): void
|
||||
{
|
||||
if ($order->order_status === $newStatus) {
|
||||
return;
|
||||
}
|
||||
|
||||
$previousStatus = $order->order_status?->value;
|
||||
$order->update(['order_status' => $newStatus->value]);
|
||||
|
||||
// 옵션별 일괄 상태변경(운송장 등)으로 부모 주문 상태가 전이되면 알림 훅 발화 (A35/A36/C3).
|
||||
// OrderStatusNotificationListener 가 결제완료/배송중/배송완료/구매확정 알림으로 매핑한다.
|
||||
// 목표 상태($newStatus->value)를 스칼라로 명시 전달 — 큐 지연 재로드 오매핑 방지 (N1).
|
||||
HookManager::doAction('sirsoft-ecommerce.order.after_status_change', $order->fresh(), $previousStatus, $newStatus->value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user