feat: add open warehouse list api
This commit is contained in:
31
server-api/app/controller/open/WarehousesController.php
Normal file
31
server-api/app/controller/open/WarehousesController.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller\open;
|
||||
|
||||
use app\support\EnterpriseOpenApiAuthService;
|
||||
use app\support\EnterpriseWarehouseService;
|
||||
use support\Request;
|
||||
|
||||
class WarehousesController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
(new EnterpriseOpenApiAuthService())->authenticate($request);
|
||||
} catch (\Throwable $e) {
|
||||
return api_error($e->getMessage(), 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$serviceProvider = trim((string)$request->input('service_provider', ''));
|
||||
|
||||
return api_success([
|
||||
'warehouses' => (new EnterpriseWarehouseService())->list($serviceProvider),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return api_error('仓库地址获取失败', 500, [
|
||||
'detail' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
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