58 lines
2.2 KiB
PHP
58 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\Http\Controllers\Api;
|
|
|
|
use App\Abstracts\Http\ApiController;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Modules\EcommerceFinance\Repositories\WorkOrderMirrorRepository;
|
|
|
|
class WorkOrders extends ApiController
|
|
{
|
|
public function __construct(private readonly WorkOrderMirrorRepository $repository)
|
|
{
|
|
}
|
|
|
|
public function index(): JsonResponse
|
|
{
|
|
$filters = request()->validate([
|
|
'work_type' => ['nullable', 'string', 'max:191'],
|
|
'order_no' => ['nullable', 'string', 'max:191'],
|
|
'status' => ['nullable', 'string', 'max:64'],
|
|
'create_user' => ['nullable', 'string', 'max:191'],
|
|
'assign_user' => ['nullable', 'string', 'max:191'],
|
|
'created_from' => ['nullable', 'date_format:Y-m-d'],
|
|
'created_to' => ['nullable', 'date_format:Y-m-d'],
|
|
'page' => ['nullable', 'integer', 'min:1'],
|
|
'limit' => ['nullable', 'integer', 'min:1', 'max:100'],
|
|
]);
|
|
|
|
if (! empty($filters['created_from']) && ! empty($filters['created_to'])
|
|
&& $filters['created_to'] < $filters['created_from']) {
|
|
return response()->json([
|
|
'message' => '创建结束日期不能早于开始日期。',
|
|
'errors' => ['created_to' => ['创建结束日期不能早于开始日期。']],
|
|
], 422);
|
|
}
|
|
|
|
$page = (int) ($filters['page'] ?? 1);
|
|
$limit = (int) ($filters['limit'] ?? 25);
|
|
unset($filters['page'], $filters['limit']);
|
|
|
|
$result = $this->repository->paginate($page, $limit, $filters);
|
|
if (! $result['ready']) {
|
|
return response()->json([
|
|
'message' => '聚水潭协同工单镜像尚未完成首次同步,请先完成共享镜像同步;页面不会临时访问上游。',
|
|
'ready' => false,
|
|
'sync_status' => $result['sync_status'],
|
|
'data' => [],
|
|
'total' => 0,
|
|
'page' => $page,
|
|
'per_page' => $limit,
|
|
'last_page' => 1,
|
|
], 503, ['Retry-After' => '30']);
|
|
}
|
|
|
|
return response()->json($result);
|
|
}
|
|
}
|