增加了手机操作端
This commit is contained in:
@@ -16,6 +16,9 @@ class OrdersController
|
||||
$status = trim((string)$request->input('status', ''));
|
||||
$serviceProvider = trim((string)$request->input('service_provider', ''));
|
||||
$sourceChannel = $this->normalizeOrderSourceChannel((string)$request->input('source_channel', ''));
|
||||
$paginationEnabled = $request->input('page', null) !== null || $request->input('page_size', null) !== null;
|
||||
$page = max(1, (int)$request->input('page', 1));
|
||||
$pageSize = max(1, min(100, (int)$request->input('page_size', 20)));
|
||||
|
||||
$query = Db::name('orders')
|
||||
->alias('o')
|
||||
@@ -51,11 +54,38 @@ class OrdersController
|
||||
});
|
||||
}
|
||||
|
||||
$specialStatusFilters = ['returning', 'completed_signed'];
|
||||
$warehouseStatusFilters = [
|
||||
'warehouse_active',
|
||||
'warehouse_in_transit',
|
||||
'warehouse_received',
|
||||
'warehouse_pending_return',
|
||||
];
|
||||
$specialStatusFilters = array_merge(['returning', 'completed_signed'], $warehouseStatusFilters);
|
||||
if ($status !== '' && !in_array($status, $specialStatusFilters, true)) {
|
||||
$query->where('o.order_status', $status);
|
||||
}
|
||||
|
||||
if (in_array($status, $warehouseStatusFilters, true)) {
|
||||
$warehouseActiveStatuses = [
|
||||
'pending_shipping',
|
||||
'received',
|
||||
'in_first_review',
|
||||
'pending_supplement',
|
||||
'in_final_review',
|
||||
'generating_report',
|
||||
'report_published',
|
||||
];
|
||||
if ($status === 'warehouse_in_transit') {
|
||||
$query->where('o.order_status', 'pending_shipping');
|
||||
} elseif ($status === 'warehouse_received') {
|
||||
$query->whereIn('o.order_status', array_values(array_diff($warehouseActiveStatuses, ['pending_shipping', 'report_published'])));
|
||||
} elseif ($status === 'warehouse_pending_return') {
|
||||
$query->where('o.order_status', 'report_published');
|
||||
} else {
|
||||
$query->whereIn('o.order_status', $warehouseActiveStatuses);
|
||||
}
|
||||
}
|
||||
|
||||
if ($serviceProvider !== '') {
|
||||
$query->where('o.service_provider', $serviceProvider);
|
||||
}
|
||||
@@ -66,28 +96,23 @@ class OrdersController
|
||||
|
||||
$rows = $query->select()->toArray();
|
||||
|
||||
$returnTrackingMap = [];
|
||||
if ($rows) {
|
||||
$returnRows = Db::name('order_logistics')
|
||||
->whereIn('order_id', array_column($rows, 'id'))
|
||||
->where('logistics_type', 'return_to_user')
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($returnRows as $row) {
|
||||
$orderId = (int)($row['order_id'] ?? 0);
|
||||
if ($orderId > 0 && !isset($returnTrackingMap[$orderId])) {
|
||||
$returnTrackingMap[$orderId] = [
|
||||
'tracking_no' => (string)($row['tracking_no'] ?? ''),
|
||||
'tracking_status' => (string)($row['tracking_status'] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$orderIds = array_map('intval', array_column($rows, 'id'));
|
||||
$sendTrackingMap = $this->latestLogisticsMap($orderIds, 'send_to_center');
|
||||
$returnTrackingMap = $this->latestLogisticsMap($orderIds, 'return_to_user');
|
||||
|
||||
$list = array_map(function (array $item) use ($sendTrackingMap, $returnTrackingMap) {
|
||||
$orderId = (int)$item['id'];
|
||||
$sendTrackingNo = $sendTrackingMap[$orderId]['tracking_no'] ?? '';
|
||||
$sendTrackingStatus = $sendTrackingMap[$orderId]['tracking_status'] ?? '';
|
||||
$warehouseBucket = $this->warehouseOrderBucket(
|
||||
(string)$item['order_status'],
|
||||
$sendTrackingNo,
|
||||
$sendTrackingStatus,
|
||||
(string)($item['display_status'] ?? '')
|
||||
);
|
||||
|
||||
$list = array_map(function (array $item) use ($returnTrackingMap) {
|
||||
return [
|
||||
'id' => (int)$item['id'],
|
||||
'id' => $orderId,
|
||||
'order_no' => $item['order_no'],
|
||||
'appraisal_no' => $item['appraisal_no'],
|
||||
'product_name' => $item['product_name'] ?: '待完善物品信息',
|
||||
@@ -102,9 +127,11 @@ class OrdersController
|
||||
'display_status' => $this->displayStatus(
|
||||
(string)$item['order_status'],
|
||||
(string)$item['display_status'],
|
||||
$returnTrackingMap[(int)$item['id']]['tracking_no'] ?? '',
|
||||
$returnTrackingMap[(int)$item['id']]['tracking_status'] ?? '',
|
||||
$returnTrackingMap[$orderId]['tracking_no'] ?? '',
|
||||
$returnTrackingMap[$orderId]['tracking_status'] ?? '',
|
||||
),
|
||||
'warehouse_bucket' => $warehouseBucket,
|
||||
'warehouse_bucket_text' => $this->warehouseOrderBucketText($warehouseBucket),
|
||||
'estimated_finish_time' => $item['estimated_finish_time'],
|
||||
'pay_amount' => (float)$item['pay_amount'],
|
||||
'created_at' => $item['created_at'],
|
||||
@@ -123,6 +150,33 @@ class OrdersController
|
||||
}));
|
||||
}
|
||||
|
||||
if (in_array($status, $warehouseStatusFilters, true)) {
|
||||
$list = array_values(array_filter($list, function (array $item) use ($status) {
|
||||
if ($status === 'warehouse_active') {
|
||||
return in_array($item['warehouse_bucket'], [
|
||||
'warehouse_in_transit',
|
||||
'warehouse_received',
|
||||
'warehouse_pending_return',
|
||||
], true);
|
||||
}
|
||||
|
||||
return $item['warehouse_bucket'] === $status;
|
||||
}));
|
||||
}
|
||||
|
||||
$total = count($list);
|
||||
if ($paginationEnabled) {
|
||||
$offset = ($page - 1) * $pageSize;
|
||||
$list = array_slice($list, $offset, $pageSize);
|
||||
|
||||
return api_success([
|
||||
'list' => $list,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'page_size' => $pageSize,
|
||||
]);
|
||||
}
|
||||
|
||||
return api_success([
|
||||
'list' => $list,
|
||||
]);
|
||||
@@ -355,9 +409,11 @@ class OrdersController
|
||||
'items' => $supplementItems,
|
||||
] : null,
|
||||
'report_summary' => $report ? [
|
||||
'id' => (int)$report['id'],
|
||||
'report_no' => $report['report_no'],
|
||||
'report_title' => $report['report_title'],
|
||||
'report_status' => $report['report_status'],
|
||||
'report_status_text' => $this->reportStatusText((string)$report['report_status']),
|
||||
'publish_time' => $report['publish_time'],
|
||||
] : null,
|
||||
]);
|
||||
@@ -469,7 +525,7 @@ class OrdersController
|
||||
'node_text' => '仓库已改派',
|
||||
'node_desc' => sprintf('订单收货仓库已改派至 %s', $snapshot['warehouse_name']),
|
||||
'operator_type' => 'admin',
|
||||
'operator_id' => 1,
|
||||
'operator_id' => (int)$request->header('x-admin-id', 0) ?: null,
|
||||
'occurred_at' => $now,
|
||||
'created_at' => $now,
|
||||
]);
|
||||
@@ -581,7 +637,7 @@ class OrdersController
|
||||
? '包裹已由鉴定中心签收,订单已进入鉴定流程'
|
||||
: '大客户推送订单已确认到仓,订单已进入鉴定流程',
|
||||
'operator_type' => 'admin',
|
||||
'operator_id' => 1,
|
||||
'operator_id' => (int)$request->header('x-admin-id', 0) ?: null,
|
||||
'occurred_at' => $now,
|
||||
'created_at' => $now,
|
||||
]);
|
||||
@@ -729,7 +785,7 @@ class OrdersController
|
||||
'node_text' => $nodeText,
|
||||
'node_desc' => $nodeDesc,
|
||||
'operator_type' => 'admin',
|
||||
'operator_id' => 1,
|
||||
'operator_id' => (int)$request->header('x-admin-id', 0) ?: null,
|
||||
'occurred_at' => $now,
|
||||
'created_at' => $now,
|
||||
]);
|
||||
@@ -821,7 +877,7 @@ class OrdersController
|
||||
'node_text' => '用户已签收',
|
||||
'node_desc' => '回寄商品已由用户签收,本次订单已完成。',
|
||||
'operator_type' => 'admin',
|
||||
'operator_id' => 1,
|
||||
'operator_id' => (int)$request->header('x-admin-id', 0) ?: null,
|
||||
'occurred_at' => $now,
|
||||
'created_at' => $now,
|
||||
]);
|
||||
@@ -870,6 +926,18 @@ class OrdersController
|
||||
};
|
||||
}
|
||||
|
||||
private function reportStatusText(string $status): string
|
||||
{
|
||||
return match ($status) {
|
||||
'draft' => '草稿中',
|
||||
'pending_publish' => '待发布',
|
||||
'published' => '已发布',
|
||||
'updated' => '已更新',
|
||||
'invalid' => '已作废',
|
||||
default => $status,
|
||||
};
|
||||
}
|
||||
|
||||
private function displayStatus(string $orderStatus, string $displayStatus, string $returnTrackingNo = '', string $returnTrackingStatus = ''): string
|
||||
{
|
||||
if ($orderStatus === 'report_published') {
|
||||
@@ -888,6 +956,77 @@ class OrdersController
|
||||
return $displayStatus;
|
||||
}
|
||||
|
||||
private function latestLogisticsMap(array $orderIds, string $logisticsType): array
|
||||
{
|
||||
$orderIds = array_values(array_unique(array_filter(array_map('intval', $orderIds))));
|
||||
if (!$orderIds) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rows = Db::name('order_logistics')
|
||||
->whereIn('order_id', $orderIds)
|
||||
->where('logistics_type', $logisticsType)
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$map = [];
|
||||
foreach ($rows as $row) {
|
||||
$orderId = (int)($row['order_id'] ?? 0);
|
||||
if ($orderId > 0 && !isset($map[$orderId])) {
|
||||
$map[$orderId] = [
|
||||
'tracking_no' => (string)($row['tracking_no'] ?? ''),
|
||||
'tracking_status' => (string)($row['tracking_status'] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
private function warehouseOrderBucket(
|
||||
string $orderStatus,
|
||||
string $sendTrackingNo = '',
|
||||
string $sendTrackingStatus = '',
|
||||
string $displayStatus = ''
|
||||
): string
|
||||
{
|
||||
if ($orderStatus === 'pending_shipping') {
|
||||
$hasSubmittedTracking = $sendTrackingNo !== '' && $sendTrackingStatus !== 'received';
|
||||
$hasSubmittedDisplayStatus = in_array($displayStatus, ['已提交运单', '用户已提交运单'], true)
|
||||
&& $sendTrackingStatus !== 'received';
|
||||
if ($hasSubmittedTracking || $hasSubmittedDisplayStatus) {
|
||||
return 'warehouse_in_transit';
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($orderStatus, [
|
||||
'received',
|
||||
'in_first_review',
|
||||
'pending_supplement',
|
||||
'in_final_review',
|
||||
'generating_report',
|
||||
], true)) {
|
||||
return 'warehouse_received';
|
||||
}
|
||||
|
||||
if ($orderStatus === 'report_published') {
|
||||
return 'warehouse_pending_return';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private function warehouseOrderBucketText(string $bucket): string
|
||||
{
|
||||
return match ($bucket) {
|
||||
'warehouse_in_transit' => '在途',
|
||||
'warehouse_received' => '已入仓',
|
||||
'warehouse_pending_return' => '待寄回',
|
||||
default => '',
|
||||
};
|
||||
}
|
||||
|
||||
private function normalizeOrderSourceChannel(string $sourceChannel): string
|
||||
{
|
||||
$sourceChannel = trim($sourceChannel);
|
||||
|
||||
Reference in New Issue
Block a user