feat: update appraisal return address and test packaging assets

This commit is contained in:
wushumin
2026-06-15 20:08:36 +08:00
parent fa267c4413
commit 9be60fbe17
23 changed files with 1806 additions and 393 deletions

View File

@@ -299,6 +299,93 @@ class EnterpriseOrderService
];
}
public function saveReturnAddress(array $customer, array $payload): array
{
$externalOrderNo = trim((string)($payload['external_order_no'] ?? ''));
if ($externalOrderNo === '') {
throw new \InvalidArgumentException('external_order_no 不能为空');
}
$returnAddress = $this->normalizeReturnAddress((array)($payload['return_address'] ?? []));
if (!$returnAddress) {
throw new \InvalidArgumentException('return_address 不能为空');
}
$ref = Db::name('enterprise_customer_order_refs')
->where('customer_id', (int)$customer['id'])
->where('external_order_no', $externalOrderNo)
->find();
if (!$ref) {
throw new \RuntimeException('订单不存在');
}
$order = Db::name('orders')->where('id', (int)$ref['order_id'])->find();
if (!$order) {
throw new \RuntimeException('订单不存在');
}
$returnLogistics = Db::name('order_logistics')
->where('order_id', (int)$order['id'])
->where('logistics_type', 'return_to_user')
->order('id', 'desc')
->find();
if (!empty($returnLogistics['tracking_no'])) {
throw new \InvalidArgumentException('回寄运单已生成,当前不可再修改寄回地址');
}
$existing = Db::name('order_return_addresses')->where('order_id', (int)$order['id'])->find();
$now = date('Y-m-d H:i:s');
$updated = (bool)$existing;
$snapshot = array_merge($returnAddress, [
'user_address_id' => null,
]);
Db::startTrans();
try {
if ($existing) {
Db::name('order_return_addresses')->where('order_id', (int)$order['id'])->update(array_merge($snapshot, [
'updated_at' => $now,
]));
$nodeText = '已更新寄回地址';
} else {
Db::name('order_return_addresses')->insert(array_merge($snapshot, [
'order_id' => (int)$order['id'],
'created_at' => $now,
'updated_at' => $now,
]));
$nodeText = '已确认寄回地址';
}
Db::name('order_timelines')->insert([
'order_id' => (int)$order['id'],
'node_code' => 'return_address_selected',
'node_text' => $nodeText,
'node_desc' => sprintf(
'大客户已确认寄回地址:%s%s%s%s',
$returnAddress['province'],
$returnAddress['city'],
$returnAddress['district'],
$returnAddress['detail_address']
),
'operator_type' => 'system',
'operator_id' => null,
'occurred_at' => $now,
'created_at' => $now,
]);
Db::commit();
} catch (\Throwable $e) {
Db::rollback();
throw $e;
}
return [
'updated' => $updated,
'return_address' => $this->formatReturnAddress($snapshot),
'order' => $this->buildOrderProgress((int)$customer['id'], $ref, (string)$customer['customer_code']),
];
}
public function buildOrderProgress(int $customerId, array $ref, string $customerCode = ''): array
{
$order = Db::name('orders')->where('id', (int)$ref['order_id'])->find();
@@ -309,6 +396,7 @@ class EnterpriseOrderService
$timeline = Db::name('order_timelines')->where('order_id', (int)$order['id'])->order('occurred_at', 'asc')->select()->toArray();
$sendLogistics = Db::name('order_logistics')->where('order_id', (int)$order['id'])->where('logistics_type', 'send_to_center')->order('id', 'desc')->find();
$returnLogistics = Db::name('order_logistics')->where('order_id', (int)$order['id'])->where('logistics_type', 'return_to_user')->order('id', 'desc')->find();
$returnAddress = Db::name('order_return_addresses')->where('order_id', (int)$order['id'])->find();
$report = Db::name('reports')
->where('order_id', (int)$order['id'])
->where('report_status', 'published')
@@ -339,6 +427,7 @@ class EnterpriseOrderService
'occurred_at' => (string)$item['occurred_at'],
], $timeline),
'inbound_logistics' => $this->formatLogistics($sendLogistics),
'return_address' => $returnAddress ? $this->formatReturnAddress($returnAddress) : null,
'return_logistics' => $this->formatLogistics($returnLogistics),
'report_summary' => $report ? [
'report_no' => (string)$report['report_no'],
@@ -586,4 +675,23 @@ class EnterpriseOrderService
'latest_time' => (string)($logistics['latest_time'] ?? ''),
];
}
private function formatReturnAddress(array $item): array
{
return [
'consignee' => (string)($item['consignee'] ?? ''),
'mobile' => (string)($item['mobile'] ?? ''),
'province' => (string)($item['province'] ?? ''),
'city' => (string)($item['city'] ?? ''),
'district' => (string)($item['district'] ?? ''),
'detail_address' => (string)($item['detail_address'] ?? ''),
'full_address' => trim(sprintf(
'%s%s%s%s',
$item['province'] ?? '',
$item['city'] ?? '',
$item['district'] ?? '',
$item['detail_address'] ?? ''
)),
];
}
}