Files
datahub/backend/app/Controller/Api/V1/RawProductController.php
T
2026-03-13 09:33:15 +08:00

147 lines
7.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace App\Controller\Api\V1;
use App\Middleware\AuthMiddleware;
use App\Middleware\PermissionMiddleware;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\RequestMapping;
use OpenApi\Attributes as OA;
/**
* 产品管理接口(Raw Category
*
* 返回关键标识 + raw + hash,供开发/调试查看原始平台数据。
* 列表不返回 raw 字段(单条 JSONB 可达数十 KB),仅返回 hash。
* 详情返回完整 raw。
*/
#[OA\Tag(name: 'Products (Raw)', description: '产品原始数据')]
#[Controller(prefix: "/api/v1/raw/products")]
#[Middleware(AuthMiddleware::class)]
#[Middleware(PermissionMiddleware::class)]
class RawProductController extends ProductController
{
protected function getListFields(): array
{
return [
'id', 'platform_item_id', 'platform_model_id', 'name',
'store_id', 'company_id', 'platform_id', 'hash',
'updated_date', 'updated_at',
];
}
protected function getDetailFields(): array
{
return [
'id', 'platform_item_id', 'platform_model_id', 'name',
'store_id', 'company_id', 'platform_id',
'raw', 'hash', 'ext',
'created_date', 'updated_date',
];
}
/**
* 产品列表(Raw
*/
#[OA\Get(
path: '/raw/products',
summary: '产品列表(Raw',
description: '获取产品原始数据列表。返回关键标识 + hash,不含 raw 字段本身(太大)。筛选参数与 Normal 接口一致。',
security: [['bearerAuth' => []]],
tags: ['Products (Raw)'],
parameters: [
new OA\Parameter(name: 'page', in: 'query', required: false, schema: new OA\Schema(type: 'integer', default: 1)),
new OA\Parameter(name: 'per_page', in: 'query', required: false, schema: new OA\Schema(type: 'integer', default: 15, maximum: 100)),
new OA\Parameter(name: 'company_id', in: 'query', required: false, description: '公司 ID 精确筛选', schema: new OA\Schema(type: 'integer')),
new OA\Parameter(name: 'platform_id', in: 'query', required: false, description: '平台 ID 精确筛选', schema: new OA\Schema(type: 'integer')),
new OA\Parameter(name: 'store_id', in: 'query', required: false, description: '店铺 ID 精确筛选', schema: new OA\Schema(type: 'integer')),
new OA\Parameter(name: 'status_id', in: 'query', required: false, description: '产品状态 ID 精确筛选', schema: new OA\Schema(type: 'integer')),
new OA\Parameter(name: 'platform_item_id', in: 'query', required: false, description: '平台商品 ID 精确搜索', schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'name', in: 'query', required: false, description: '商品名称模糊搜索', schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(
response: 200,
description: '获取成功',
content: new OA\JsonContent(properties: [
new OA\Property(property: 'code', type: 'integer', example: 0),
new OA\Property(property: 'message', type: 'string', example: '获取成功'),
new OA\Property(property: 'data', properties: [
new OA\Property(property: 'items', type: 'array', items: new OA\Items(properties: [
new OA\Property(property: 'id', type: 'integer'),
new OA\Property(property: 'platform_item_id', type: 'string'),
new OA\Property(property: 'platform_model_id', type: 'string', nullable: true),
new OA\Property(property: 'name', type: 'string', nullable: true),
new OA\Property(property: 'store_id', type: 'integer'),
new OA\Property(property: 'company_id', type: 'integer'),
new OA\Property(property: 'platform_id', type: 'integer'),
new OA\Property(property: 'hash', type: 'string'),
new OA\Property(property: 'updated_date', type: 'string', format: 'date-time', nullable: true),
new OA\Property(property: 'updated_at', type: 'string', format: 'date-time'),
], type: 'object')),
new OA\Property(property: 'total', type: 'integer'),
new OA\Property(property: 'page', type: 'integer'),
new OA\Property(property: 'per_page', type: 'integer'),
], type: 'object'),
])
),
new OA\Response(response: 401, description: '未认证', content: new OA\JsonContent(ref: '#/components/schemas/ErrorResponse')),
new OA\Response(response: 403, description: '无权限', content: new OA\JsonContent(ref: '#/components/schemas/ErrorResponse')),
]
)]
#[RequestMapping(path: "", methods: "GET")]
public function index(): \Psr\Http\Message\ResponseInterface|array
{
return parent::index();
}
/**
* 产品详情(Raw
*/
#[OA\Get(
path: '/raw/products/{id}',
summary: '产品详情(Raw',
description: '获取产品原始数据详情。返回关键标识 + 完整 raw + hash + ext。',
security: [['bearerAuth' => []]],
tags: ['Products (Raw)'],
parameters: [
new OA\Parameter(name: 'id', in: 'path', required: true, description: '产品 ID', schema: new OA\Schema(type: 'integer')),
],
responses: [
new OA\Response(
response: 200,
description: '获取成功',
content: new OA\JsonContent(properties: [
new OA\Property(property: 'code', type: 'integer', example: 0),
new OA\Property(property: 'message', type: 'string', example: '获取成功'),
new OA\Property(property: 'data', properties: [
new OA\Property(property: 'id', type: 'integer'),
new OA\Property(property: 'platform_item_id', type: 'string'),
new OA\Property(property: 'platform_model_id', type: 'string', nullable: true),
new OA\Property(property: 'name', type: 'string', nullable: true),
new OA\Property(property: 'store_id', type: 'integer'),
new OA\Property(property: 'company_id', type: 'integer'),
new OA\Property(property: 'platform_id', type: 'integer'),
new OA\Property(property: 'raw', type: 'object', description: '平台原始数据'),
new OA\Property(property: 'hash', type: 'string'),
new OA\Property(property: 'ext', type: 'object', nullable: true),
new OA\Property(property: 'created_date', type: 'string', format: 'date-time', nullable: true),
new OA\Property(property: 'updated_date', type: 'string', format: 'date-time', nullable: true),
], type: 'object'),
])
),
new OA\Response(response: 401, description: '未认证', content: new OA\JsonContent(ref: '#/components/schemas/ErrorResponse')),
new OA\Response(response: 403, description: '无权限', content: new OA\JsonContent(ref: '#/components/schemas/ErrorResponse')),
new OA\Response(response: 404, description: '数据不存在', content: new OA\JsonContent(ref: '#/components/schemas/ErrorResponse')),
]
)]
#[RequestMapping(path: "{id}", methods: "GET")]
public function show(int $id): \Psr\Http\Message\ResponseInterface|array
{
return parent::show($id);
}
}