feat: add open warehouse list api

This commit is contained in:
wushumin
2026-06-18 13:56:20 +08:00
parent a982ee2b60
commit 9aa7788b7f
6 changed files with 307 additions and 34 deletions

View File

@@ -0,0 +1,48 @@
<?php
namespace app\support;
class EnterpriseWarehouseService
{
public function list(string $serviceProvider = ''): array
{
$serviceProvider = trim($serviceProvider);
$warehouses = (new WarehouseService())->list();
$warehouses = array_values(array_filter($warehouses, static function (array $item) use ($serviceProvider) {
if ((string)($item['status'] ?? '') !== 'enabled') {
return false;
}
return $serviceProvider === '' || (string)($item['service_provider'] ?? '') === $serviceProvider;
}));
return array_map(fn(array $item) => $this->formatOpenWarehouse($item), $warehouses);
}
private function formatOpenWarehouse(array $item): array
{
return [
'id' => (int)$item['id'],
'warehouse_name' => (string)$item['warehouse_name'],
'warehouse_code' => (string)$item['warehouse_code'],
'service_provider' => (string)$item['service_provider'],
'service_provider_text' => (string)$item['service_provider_text'],
'receiver_name' => (string)$item['receiver_name'],
'receiver_mobile' => (string)$item['receiver_mobile'],
'province' => (string)$item['province'],
'city' => (string)$item['city'],
'district' => (string)$item['district'],
'detail_address' => (string)$item['detail_address'],
'full_address' => (string)$item['full_address'],
'service_time' => (string)$item['service_time'],
'notice' => (string)$item['notice'],
'supported_category_ids' => array_values((array)($item['supported_category_ids'] ?? [])),
'supported_category_names' => array_values((array)($item['supported_category_names'] ?? [])),
'service_area_provinces' => array_values((array)($item['service_area_provinces'] ?? [])),
'service_area_cities' => array_values((array)($item['service_area_cities'] ?? [])),
'is_default' => (bool)$item['is_default'],
'sort_order' => (int)$item['sort_order'],
];
}
}