Files
datahub/backend/app/Controller/Api/V1/RefundItemController.php
T
2026-03-13 13:50:56 +08:00

160 lines
7.6 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\Controller\AbstractDataController;
use App\Middleware\AuthMiddleware;
use App\Middleware\PermissionMiddleware;
use App\Model\RefundItem;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\RequestMapping;
use OpenApi\Attributes as OA;
use Psr\Http\Message\ResponseInterface;
/**
* 退款项管理接口(Normal Category
*
* 返回所有 parsed 字段,不含 raw
*/
#[OA\Tag(name: 'Refund Items', description: '退款项管理')]
#[Controller(prefix: "/api/v1/refund-items")]
#[Middleware(AuthMiddleware::class)]
#[Middleware(PermissionMiddleware::class)]
class RefundItemController extends AbstractDataController
{
protected function getModelClass(): string
{
return RefundItem::class;
}
protected function getListFields(): array
{
return [
'id', 'company_id', 'platform_id', 'store_id',
'refund_id', 'platform_refund_id', 'platform_order_id',
'platform_sub_order_id', 'platform_product_id',
'refund_status_id', 'refund_type_id',
'quantity', 'refund_amount', 'currency', 'created_date',
];
}
protected function getDetailFields(): array
{
return [
'id', 'company_id', 'platform_id', 'store_id',
'refund_id', 'platform_parent_refund_id', 'platform_refund_id',
'refund_status_id', 'refund_type_id',
'platform_order_id', 'platform_sub_order_id', 'platform_product_id',
'reason', 'currency', 'buyer_user_id', 'quantity', 'refund_amount',
'order_created_date', 'order_paid_date',
'created_date', 'updated_date', 'completed_date',
'ext', 'created_at', 'updated_at',
];
}
protected function getAllowedFilters(): array
{
return [
'company_id' => 'exact',
'platform_id' => 'exact',
'store_id' => 'exact',
'refund_id' => 'exact',
'refund_status_id' => 'exact',
'refund_type_id' => 'exact',
'platform_refund_id' => 'exact',
'platform_order_id' => 'exact',
'created_date_from' => 'date_from',
'created_date_to' => 'date_to',
];
}
protected function getDefaultSort(): string
{
return 'created_date';
}
/**
* 退款项列表
*/
#[OA\Get(
path: '/refund-items',
summary: '退款项列表',
description: '获取退款项列表,支持分页、按退款单/退款状态/类型/时间范围筛选。返回业务字段,不含 raw。',
security: [['bearerAuth' => []]],
tags: ['Refund Items'],
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: 'refund_id', in: 'query', required: false, description: '父退款 ID 精确筛选', schema: new OA\Schema(type: 'integer')),
new OA\Parameter(name: 'refund_status_id', in: 'query', required: false, description: '退款状态 ID 精确筛选', schema: new OA\Schema(type: 'integer')),
new OA\Parameter(name: 'refund_type_id', in: 'query', required: false, description: '退款类型 ID 精确筛选(1=仅退款 2=退货退款 3=补偿退款)', schema: new OA\Schema(type: 'integer')),
new OA\Parameter(name: 'platform_refund_id', in: 'query', required: false, description: '平台退款子项 ID 精确搜索', schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'platform_order_id', in: 'query', required: false, description: '关联平台订单 ID 筛选', schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'created_date_from', in: 'query', required: false, description: '创建时间起始(含)', schema: new OA\Schema(type: 'string', format: 'date', example: '2026-01-01')),
new OA\Parameter(name: 'created_date_to', in: 'query', required: false, description: '创建时间截止(含)', schema: new OA\Schema(type: 'string', format: 'date', example: '2026-12-31')),
],
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(ref: '#/components/schemas/RefundItem')),
new OA\Property(property: 'total', type: 'integer', example: 100),
new OA\Property(property: 'page', type: 'integer', example: 1),
new OA\Property(property: 'per_page', type: 'integer', example: 15),
], 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(): ResponseInterface|array
{
return parent::index();
}
/**
* 退款项详情
*/
#[OA\Get(
path: '/refund-items/{id}',
summary: '退款项详情',
description: '获取退款项详情,返回所有业务字段和 ext,不含 raw。',
security: [['bearerAuth' => []]],
tags: ['Refund Items'],
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', ref: '#/components/schemas/RefundItem'),
])
),
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): ResponseInterface|array
{
return parent::show($id);
}
}