feat: add open warehouse list api
This commit is contained in:
48
server-api/app/support/EnterpriseWarehouseService.php
Normal file
48
server-api/app/support/EnterpriseWarehouseService.php
Normal 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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user