feat: update appraisal return address and test packaging assets
This commit is contained in:
@@ -18,6 +18,7 @@ class OrdersController
|
||||
public function index(Request $request)
|
||||
{
|
||||
$keyword = trim((string)$request->input('keyword', ''));
|
||||
$externalOrderNo = trim((string)$request->input('external_order_no', ''));
|
||||
$trackingNo = trim((string)$request->input('tracking_no', ''));
|
||||
$userMobile = trim((string)$request->input('user_mobile', ''));
|
||||
$status = trim((string)$request->input('status', ''));
|
||||
@@ -30,10 +31,12 @@ class OrdersController
|
||||
$query = Db::name('orders')
|
||||
->alias('o')
|
||||
->leftJoin('order_products p', 'p.order_id = o.id')
|
||||
->leftJoin('enterprise_customer_order_refs ecor', 'ecor.order_id = o.id')
|
||||
->field([
|
||||
'o.id',
|
||||
'o.order_no',
|
||||
'o.appraisal_no',
|
||||
'ecor.external_order_no',
|
||||
'o.service_provider',
|
||||
'o.order_status',
|
||||
'o.display_status',
|
||||
@@ -64,6 +67,12 @@ class OrdersController
|
||||
});
|
||||
}
|
||||
|
||||
if ($externalOrderNo !== '') {
|
||||
$query->whereRaw('ecor.external_order_no LIKE :external_order_no', [
|
||||
'external_order_no' => "%{$externalOrderNo}%",
|
||||
]);
|
||||
}
|
||||
|
||||
if ($trackingNo !== '') {
|
||||
$query->whereRaw(
|
||||
"EXISTS (SELECT 1 FROM order_logistics ol WHERE ol.order_id = o.id AND ol.logistics_type IN ('send_to_center', 'return_to_user') AND ol.tracking_no LIKE :tracking_no)",
|
||||
@@ -155,6 +164,7 @@ class OrdersController
|
||||
'id' => $orderId,
|
||||
'order_no' => $item['order_no'],
|
||||
'appraisal_no' => $item['appraisal_no'],
|
||||
'external_order_no' => (string)($item['external_order_no'] ?? ''),
|
||||
'product_name' => $item['product_name'] ?: '待完善物品信息',
|
||||
'category_name' => $item['category_name'] ?: '',
|
||||
'brand_name' => $item['brand_name'] ?: '',
|
||||
@@ -255,6 +265,7 @@ class OrdersController
|
||||
->where('order_id', $id)
|
||||
->order('id', 'desc')
|
||||
->find();
|
||||
$enterpriseOrderRef = Db::name('enterprise_customer_order_refs')->where('order_id', $id)->find();
|
||||
$timeline = Db::name('order_timelines')
|
||||
->where('order_id', $id)
|
||||
->order('occurred_at', 'asc')
|
||||
@@ -343,6 +354,7 @@ class OrdersController
|
||||
'id' => (int)$order['id'],
|
||||
'order_no' => $order['order_no'],
|
||||
'appraisal_no' => $order['appraisal_no'],
|
||||
'external_order_no' => (string)($enterpriseOrderRef['external_order_no'] ?? ''),
|
||||
'service_provider' => $order['service_provider'],
|
||||
'service_provider_text' => $order['service_provider'] === 'zhongjian' ? '中检鉴定' : '实物鉴定',
|
||||
'price_package_name' => (string)($order['price_package_name'] ?? ''),
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace app\controller\app;
|
||||
|
||||
use app\support\ContentService;
|
||||
use app\support\FileStorageService;
|
||||
use support\Request;
|
||||
use support\think\Db;
|
||||
|
||||
@@ -9,11 +11,19 @@ class CatalogController
|
||||
{
|
||||
public function categories(Request $request)
|
||||
{
|
||||
$categoryVisuals = $this->categoryVisualMap($request);
|
||||
$list = Db::name('catalog_categories')
|
||||
->field(['id AS category_id', 'name AS category_name', 'code AS category_code'])
|
||||
->where('is_enabled', 1)
|
||||
->order('sort_order', 'asc')
|
||||
->select()
|
||||
->map(function ($item) use ($categoryVisuals) {
|
||||
$codeKey = $this->categoryMatchKey((string)$item['category_code']);
|
||||
$nameKey = $this->categoryMatchKey((string)$item['category_name']);
|
||||
$item['image_url'] = $categoryVisuals['code:' . $codeKey] ?? $categoryVisuals['name:' . $nameKey] ?? '';
|
||||
|
||||
return $item;
|
||||
})
|
||||
->toArray();
|
||||
|
||||
return api_success(['list' => $list]);
|
||||
@@ -39,4 +49,45 @@ class CatalogController
|
||||
]);
|
||||
}
|
||||
|
||||
private function categoryVisualMap(Request $request): array
|
||||
{
|
||||
$items = (new ContentService())->getHomeConfig()['category_visuals'] ?? [];
|
||||
if (!is_array($items)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$map = [];
|
||||
$storage = new FileStorageService();
|
||||
foreach ($items as $item) {
|
||||
if (!is_array($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$imageUrl = trim((string)($item['image_url'] ?? ''));
|
||||
if ($imageUrl === '') {
|
||||
continue;
|
||||
}
|
||||
$imageUrl = $storage->normalizeUrl($imageUrl, $request);
|
||||
|
||||
$categoryCode = $this->categoryMatchKey((string)($item['category_code'] ?? ''));
|
||||
if ($categoryCode !== '') {
|
||||
$map['code:' . $categoryCode] = $imageUrl;
|
||||
}
|
||||
|
||||
$categoryName = $this->categoryMatchKey((string)($item['category_name'] ?? ''));
|
||||
if ($categoryName !== '') {
|
||||
$map['name:' . $categoryName] = $imageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
private function categoryMatchKey(string $value): string
|
||||
{
|
||||
$value = trim($value);
|
||||
$normalized = preg_replace('/[\s\p{Cf}]+/u', '', $value);
|
||||
|
||||
return strtolower($normalized ?? $value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,34 @@ class OrdersController
|
||||
return api_success($result, '运单已提交');
|
||||
}
|
||||
|
||||
public function saveReturnAddress(Request $request)
|
||||
{
|
||||
try {
|
||||
$auth = (new EnterpriseOpenApiAuthService())->authenticate($request);
|
||||
} catch (\Throwable $e) {
|
||||
return api_error($e->getMessage(), 401);
|
||||
}
|
||||
|
||||
$payload = json_decode($request->rawBody(), true);
|
||||
if (!is_array($payload)) {
|
||||
return api_error('请求体必须是合法 JSON 对象', 422);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = (new EnterpriseOrderService())->saveReturnAddress($auth['customer'], $payload);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return api_error($e->getMessage(), 422);
|
||||
} catch (\RuntimeException $e) {
|
||||
return api_error($e->getMessage(), 404);
|
||||
} catch (\Throwable $e) {
|
||||
return api_error('寄回地址保存失败', 500, [
|
||||
'detail' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
return api_success($result, '寄回地址已保存');
|
||||
}
|
||||
|
||||
public function servicePricePackages(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -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'] ?? ''
|
||||
)),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user