feat: optimize warehouse return scan flow

This commit is contained in:
wushumin
2026-06-06 16:56:40 +08:00
parent 22b18e2dac
commit d13db60618
2 changed files with 76 additions and 66 deletions

View File

@@ -242,10 +242,16 @@ class FulfillmentFlowService
'sent_to_zhongjian' => 'inbound',
default => '',
};
$nextActionText = match ($stage) {
'warehouse_received' => '送检出库',
'sent_to_zhongjian' => '送检入库',
'report_published' => '待寄回订单可填写回寄物流',
default => '暂无可执行送检动作',
};
return array_merge($this->formatOrderContext((int)$flow['order_id']), [
'next_action' => $nextAction,
'next_action_text' => $nextAction === 'outbound' ? '送检出库' : ($nextAction === 'inbound' ? '送检入库' : '暂无可执行送检动作'),
'next_action_text' => $nextActionText,
]);
}
@@ -271,6 +277,7 @@ class FulfillmentFlowService
if (!$report || ($report['report_status'] ?? '') !== 'published') {
throw new \InvalidArgumentException('该报告未发布,不符合寄回条件');
}
$this->ensurePendingReturnOrder($flow);
return $context + [
'return_confirmation' => [
@@ -291,6 +298,7 @@ class FulfillmentFlowService
if (!$report || ($report['report_status'] ?? '') !== 'published') {
throw new \InvalidArgumentException('该报告未发布,不符合寄回条件');
}
$this->ensurePendingReturnOrder($flow);
$tag = (new MaterialTagService())->findTagByInput($qrInput);
if (!$tag || (int)($tag['report_id'] ?? 0) !== (int)$report['id']) {
@@ -342,6 +350,7 @@ class FulfillmentFlowService
if (!$report || ($report['report_status'] ?? '') !== 'published') {
throw new \InvalidArgumentException('该报告未发布,不符合寄回条件');
}
$this->ensurePendingReturnOrder($flow);
if ((int)$report['id'] !== $reportId) {
throw new \InvalidArgumentException('确认的报告与当前订单报告不匹配');
}
@@ -349,22 +358,7 @@ class FulfillmentFlowService
return $this->formatOrderContext((int)$flow['order_id'], $request);
}
if (($flow['service_provider'] ?? '') === 'zhongjian') {
$content = Db::name('report_contents')->where('report_id', (int)$report['id'])->find();
$files = $this->decodeJsonArray($content['zhongjian_report_files_json'] ?? null);
if (trim((string)($report['zhongjian_report_no'] ?? '')) === '' || !$files) {
throw new \InvalidArgumentException('中检报告未完整录入,不能确认寄回');
}
return $this->markReturnConfirmed($flow, $operator, 'return_confirmed', '中检报告已确认', '仓管已查看中检报告编号和报告文件。');
}
$boundTag = (new MaterialTagService())->findBoundTagForReport((int)$report['id']);
if (!$boundTag) {
throw new \InvalidArgumentException('当前报告未绑定验真吊牌,不能确认寄回');
}
return $this->markReturnConfirmed($flow, $operator, 'return_tag_verified', '验真吊牌确认', '仓管已核对验真吊牌与报告信息。');
return $this->markReturnConfirmed($flow, $operator, 'return_confirmed', '回寄确认', '仓管扫描内部流转码确认订单处于待寄回状态。');
}
public function shipReturn(string $tagNo, string $expressCompany, string $trackingNo, Request $request, array $packingAttachments = []): array
@@ -940,6 +934,19 @@ class FulfillmentFlowService
]);
}
private function ensurePendingReturnOrder(array $flow): array
{
$order = Db::name('orders')->where('id', (int)$flow['order_id'])->find();
if (!$order) {
throw new \RuntimeException('订单不存在', 404);
}
if ((string)($order['order_status'] ?? '') !== 'report_published') {
throw new \InvalidArgumentException('当前订单不处于待寄回状态');
}
return $order;
}
private function operator(Request $request): array
{
$id = (int)$request->header('x-admin-id', 0);