add refund items
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
<?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;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* 退款项管理接口(Raw Category)
|
||||
*
|
||||
* 返回关键标识 + raw,供开发/调试查看原始平台数据。
|
||||
* 列表不返回 raw 字段(单条 JSONB 可达数十 KB)。
|
||||
* 详情返回完整 raw。
|
||||
*/
|
||||
#[OA\Tag(name: 'Refund Items (Raw)', description: '退款项原始数据')]
|
||||
#[Controller(prefix: "/api/v1/raw/refund-items")]
|
||||
#[Middleware(AuthMiddleware::class)]
|
||||
#[Middleware(PermissionMiddleware::class)]
|
||||
class RawRefundItemController extends RefundItemController
|
||||
{
|
||||
protected function getListFields(): array
|
||||
{
|
||||
return [
|
||||
'id', 'platform_refund_id', 'platform_parent_refund_id',
|
||||
'platform_order_id', 'store_id', 'company_id', 'platform_id',
|
||||
'refund_status_id', 'created_date', 'updated_at',
|
||||
];
|
||||
}
|
||||
|
||||
protected function getDetailFields(): array
|
||||
{
|
||||
return [
|
||||
'id', 'platform_refund_id', 'platform_parent_refund_id',
|
||||
'platform_order_id', 'store_id', 'company_id', 'platform_id',
|
||||
'refund_status_id', 'raw', 'ext', 'created_date',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款项列表(Raw)
|
||||
*/
|
||||
#[OA\Get(
|
||||
path: '/raw/refund-items',
|
||||
summary: '退款项列表(Raw)',
|
||||
description: '获取退款项原始数据列表。返回关键标识,不含 raw 字段本身(太大)。筛选参数与 Normal 接口一致。',
|
||||
security: [['bearerAuth' => []]],
|
||||
tags: ['Refund Items (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: '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 精确筛选', 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')),
|
||||
new OA\Parameter(name: 'created_date_to', in: 'query', required: false, description: '创建时间截止(含)', schema: new OA\Schema(type: 'string', format: 'date')),
|
||||
],
|
||||
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_refund_id', type: 'string'),
|
||||
new OA\Property(property: 'platform_parent_refund_id', type: 'string'),
|
||||
new OA\Property(property: 'platform_order_id', type: 'string'),
|
||||
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: 'refund_status_id', type: 'integer'),
|
||||
new OA\Property(property: 'created_date', type: 'string', format: 'date-time'),
|
||||
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(): ResponseInterface|array
|
||||
{
|
||||
return parent::index();
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款项详情(Raw)
|
||||
*/
|
||||
#[OA\Get(
|
||||
path: '/raw/refund-items/{id}',
|
||||
summary: '退款项详情(Raw)',
|
||||
description: '获取退款项原始数据详情。返回关键标识 + 完整 raw + ext。',
|
||||
security: [['bearerAuth' => []]],
|
||||
tags: ['Refund Items (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_refund_id', type: 'string'),
|
||||
new OA\Property(property: 'platform_parent_refund_id', type: 'string'),
|
||||
new OA\Property(property: 'platform_order_id', type: 'string'),
|
||||
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: 'refund_status_id', type: 'integer'),
|
||||
new OA\Property(property: 'raw', type: 'object', description: '平台原始子项数据'),
|
||||
new OA\Property(property: 'ext', type: 'object', nullable: true),
|
||||
new OA\Property(property: 'created_date', type: 'string', format: 'date-time'),
|
||||
], 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): ResponseInterface|array
|
||||
{
|
||||
return parent::show($id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
/**
|
||||
* @property int $id 主键
|
||||
@@ -35,6 +36,38 @@ use Hyperf\DbConnection\Model\Model;
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @mixin \App_Model_RefundItem
|
||||
*/
|
||||
#[OA\Schema(
|
||||
schema: 'RefundItem',
|
||||
type: 'object',
|
||||
properties: [
|
||||
new OA\Property(property: 'id', type: 'integer', example: 1),
|
||||
new OA\Property(property: 'company_id', type: 'integer', example: 1),
|
||||
new OA\Property(property: 'platform_id', type: 'integer', example: 2),
|
||||
new OA\Property(property: 'store_id', type: 'integer', example: 100),
|
||||
new OA\Property(property: 'refund_id', type: 'integer', example: 50),
|
||||
new OA\Property(property: 'platform_parent_refund_id', type: 'string', nullable: true, example: 'PRF-001'),
|
||||
new OA\Property(property: 'platform_refund_id', type: 'string', example: 'RF-ITEM-001'),
|
||||
new OA\Property(property: 'refund_status_id', type: 'integer', example: 1),
|
||||
new OA\Property(property: 'refund_type_id', type: 'integer', example: 2),
|
||||
new OA\Property(property: 'reason', type: 'string', nullable: true, example: '商品质量问题'),
|
||||
new OA\Property(property: 'currency', type: 'string', example: 'CNY'),
|
||||
new OA\Property(property: 'buyer_user_id', type: 'string', nullable: true, example: 'buyer_123'),
|
||||
new OA\Property(property: 'platform_order_id', type: 'string', example: 'ORD-20260101-001'),
|
||||
new OA\Property(property: 'platform_sub_order_id', type: 'string', nullable: true, example: 'SUB-001'),
|
||||
new OA\Property(property: 'platform_product_id', type: 'string', nullable: true, example: 'PROD-001'),
|
||||
new OA\Property(property: 'quantity', type: 'integer', example: 1),
|
||||
new OA\Property(property: 'refund_amount', type: 'number', format: 'decimal', example: 99.99),
|
||||
new OA\Property(property: 'raw', type: 'object', nullable: true, description: '平台原始子项数据'),
|
||||
new OA\Property(property: 'ext', type: 'object', nullable: true, description: '扩展字段'),
|
||||
new OA\Property(property: 'order_created_date', type: 'string', format: 'date-time', nullable: true),
|
||||
new OA\Property(property: 'order_paid_date', type: 'string', format: 'date-time', nullable: true),
|
||||
new OA\Property(property: 'created_date', type: 'string', format: 'date-time'),
|
||||
new OA\Property(property: 'updated_date', type: 'string', format: 'date-time', nullable: true),
|
||||
new OA\Property(property: 'completed_date', type: 'string', format: 'date-time', nullable: true),
|
||||
new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
|
||||
new OA\Property(property: 'updated_at', type: 'string', format: 'date-time'),
|
||||
]
|
||||
)]
|
||||
class RefundItem extends Model
|
||||
{
|
||||
/**
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,478 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HyperfTest\Cases\Integration\Refund;
|
||||
|
||||
use App\Model\RefundItem;
|
||||
use HyperfTest\TestCase;
|
||||
use HyperfTest\Traits\AuthenticatedTestTrait;
|
||||
|
||||
/**
|
||||
* RefundItemController 集成测试
|
||||
*
|
||||
* 覆盖 Normal/Raw 列表详情、字段校验、筛选、401/404
|
||||
*
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class RefundItemControllerTest extends TestCase
|
||||
{
|
||||
use AuthenticatedTestTrait;
|
||||
|
||||
protected function hasRefundItemData(): bool
|
||||
{
|
||||
return $this->runInCoroutine(static function (): bool {
|
||||
return RefundItem::query()->exists();
|
||||
});
|
||||
}
|
||||
|
||||
protected function getFirstRefundItemId(): ?int
|
||||
{
|
||||
return $this->runInCoroutine(static function (): ?int {
|
||||
return RefundItem::query()->value('id');
|
||||
});
|
||||
}
|
||||
|
||||
// ========== Normal 列表接口 ==========
|
||||
|
||||
public function test_normal_list_returns_paginated_data(): void
|
||||
{
|
||||
$response = $this->get('/api/v1/refund-items', [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonPath('code', 0);
|
||||
$response->assertJsonStructure([
|
||||
'code',
|
||||
'message',
|
||||
'data' => [
|
||||
'items',
|
||||
'total',
|
||||
'page',
|
||||
'per_page',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_normal_list_respects_per_page(): void
|
||||
{
|
||||
$response = $this->get('/api/v1/refund-items', ['per_page' => 5], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonPath('data.per_page', 5);
|
||||
}
|
||||
|
||||
public function test_normal_list_per_page_max_100(): void
|
||||
{
|
||||
$response = $this->get('/api/v1/refund-items', ['per_page' => 999], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonPath('data.per_page', 100);
|
||||
}
|
||||
|
||||
public function test_normal_list_excludes_raw(): void
|
||||
{
|
||||
if (!$this->hasRefundItemData()) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$response = $this->get('/api/v1/refund-items', [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
$first_item = $body['data']['items'][0] ?? [];
|
||||
|
||||
$this->assertArrayNotHasKey('raw', $first_item);
|
||||
}
|
||||
|
||||
public function test_normal_list_contains_expected_fields(): void
|
||||
{
|
||||
if (!$this->hasRefundItemData()) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$response = $this->get('/api/v1/refund-items', [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
$first_item = $body['data']['items'][0];
|
||||
|
||||
$expected_keys = [
|
||||
'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',
|
||||
];
|
||||
|
||||
foreach ($expected_keys as $key) {
|
||||
$this->assertArrayHasKey($key, $first_item, "列表缺少字段: {$key}");
|
||||
}
|
||||
}
|
||||
|
||||
public function test_normal_list_excludes_detail_only_fields(): void
|
||||
{
|
||||
if (!$this->hasRefundItemData()) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$response = $this->get('/api/v1/refund-items', [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
$first_item = $body['data']['items'][0] ?? [];
|
||||
|
||||
$this->assertArrayNotHasKey('ext', $first_item);
|
||||
$this->assertArrayNotHasKey('reason', $first_item);
|
||||
$this->assertArrayNotHasKey('buyer_user_id', $first_item);
|
||||
$this->assertArrayNotHasKey('order_created_date', $first_item);
|
||||
}
|
||||
|
||||
// ========== Normal 列表筛选 ==========
|
||||
|
||||
public function test_normal_list_filter_by_company_id(): void
|
||||
{
|
||||
if (!$this->hasRefundItemData()) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$company_id = $this->runInCoroutine(static function (): mixed {
|
||||
return RefundItem::query()->value('company_id');
|
||||
});
|
||||
|
||||
$response = $this->get('/api/v1/refund-items', ['company_id' => $company_id], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
|
||||
foreach ($body['data']['items'] as $item) {
|
||||
$this->assertSame($company_id, $item['company_id']);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_normal_list_filter_by_refund_id(): void
|
||||
{
|
||||
if (!$this->hasRefundItemData()) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$refund_id = $this->runInCoroutine(static function (): mixed {
|
||||
return RefundItem::query()->value('refund_id');
|
||||
});
|
||||
|
||||
$response = $this->get('/api/v1/refund-items', ['refund_id' => $refund_id], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
|
||||
foreach ($body['data']['items'] as $item) {
|
||||
$this->assertSame($refund_id, $item['refund_id']);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_normal_list_filter_by_refund_status_id(): void
|
||||
{
|
||||
if (!$this->hasRefundItemData()) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$status_id = $this->runInCoroutine(static function (): mixed {
|
||||
return RefundItem::query()->value('refund_status_id');
|
||||
});
|
||||
|
||||
$response = $this->get('/api/v1/refund-items', ['refund_status_id' => $status_id], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
|
||||
foreach ($body['data']['items'] as $item) {
|
||||
$this->assertSame($status_id, $item['refund_status_id']);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_normal_list_filter_by_refund_type_id(): void
|
||||
{
|
||||
if (!$this->hasRefundItemData()) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$type_id = $this->runInCoroutine(static function (): mixed {
|
||||
return RefundItem::query()->value('refund_type_id');
|
||||
});
|
||||
|
||||
$response = $this->get('/api/v1/refund-items', ['refund_type_id' => $type_id], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
|
||||
foreach ($body['data']['items'] as $item) {
|
||||
$this->assertSame($type_id, $item['refund_type_id']);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_normal_list_filter_by_platform_refund_id(): void
|
||||
{
|
||||
if (!$this->hasRefundItemData()) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$platform_refund_id = $this->runInCoroutine(static function (): mixed {
|
||||
return RefundItem::query()->value('platform_refund_id');
|
||||
});
|
||||
|
||||
$response = $this->get('/api/v1/refund-items', ['platform_refund_id' => $platform_refund_id], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
|
||||
foreach ($body['data']['items'] as $item) {
|
||||
$this->assertSame($platform_refund_id, $item['platform_refund_id']);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_normal_list_filter_by_platform_order_id(): void
|
||||
{
|
||||
if (!$this->hasRefundItemData()) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$platform_order_id = $this->runInCoroutine(static function (): mixed {
|
||||
return RefundItem::query()->value('platform_order_id');
|
||||
});
|
||||
|
||||
$response = $this->get('/api/v1/refund-items', ['platform_order_id' => $platform_order_id], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
|
||||
foreach ($body['data']['items'] as $item) {
|
||||
$this->assertSame($platform_order_id, $item['platform_order_id']);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_normal_list_filter_by_created_date_range(): void
|
||||
{
|
||||
if (!$this->hasRefundItemData()) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$response = $this->get('/api/v1/refund-items', [
|
||||
'created_date_from' => '2020-01-01',
|
||||
'created_date_to' => '2099-12-31',
|
||||
], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertGreaterThanOrEqual(0, $body['data']['total']);
|
||||
}
|
||||
|
||||
// ========== Normal 详情接口 ==========
|
||||
|
||||
public function test_normal_detail_returns_refund_item(): void
|
||||
{
|
||||
$id = $this->getFirstRefundItemId();
|
||||
if (!$id) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$response = $this->get('/api/v1/refund-items/' . $id, [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonPath('code', 0);
|
||||
$response->assertJsonPath('data.id', $id);
|
||||
}
|
||||
|
||||
public function test_normal_detail_contains_ext(): void
|
||||
{
|
||||
$id = $this->getFirstRefundItemId();
|
||||
if (!$id) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$response = $this->get('/api/v1/refund-items/' . $id, [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertArrayHasKey('ext', $body['data']);
|
||||
}
|
||||
|
||||
public function test_normal_detail_excludes_raw(): void
|
||||
{
|
||||
$id = $this->getFirstRefundItemId();
|
||||
if (!$id) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$response = $this->get('/api/v1/refund-items/' . $id, [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertArrayNotHasKey('raw', $body['data']);
|
||||
}
|
||||
|
||||
public function test_normal_detail_contains_expected_fields(): void
|
||||
{
|
||||
$id = $this->getFirstRefundItemId();
|
||||
if (!$id) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$response = $this->get('/api/v1/refund-items/' . $id, [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
|
||||
$expected_keys = [
|
||||
'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',
|
||||
];
|
||||
|
||||
foreach ($expected_keys as $key) {
|
||||
$this->assertArrayHasKey($key, $body['data'], "详情缺少字段: {$key}");
|
||||
}
|
||||
}
|
||||
|
||||
public function test_normal_detail_not_found_returns_404(): void
|
||||
{
|
||||
$response = $this->get('/api/v1/refund-items/999999999', [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertJsonPath('code', 404);
|
||||
}
|
||||
|
||||
// ========== Raw 列表接口 ==========
|
||||
|
||||
public function test_raw_list_returns_paginated_data(): void
|
||||
{
|
||||
$response = $this->get('/api/v1/raw/refund-items', [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonPath('code', 0);
|
||||
$response->assertJsonStructure([
|
||||
'code',
|
||||
'message',
|
||||
'data' => [
|
||||
'items',
|
||||
'total',
|
||||
'page',
|
||||
'per_page',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_raw_list_does_not_contain_raw(): void
|
||||
{
|
||||
if (!$this->hasRefundItemData()) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$response = $this->get('/api/v1/raw/refund-items', [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
$first_item = $body['data']['items'][0] ?? [];
|
||||
|
||||
$this->assertArrayNotHasKey('raw', $first_item, 'Raw 列表不应包含 raw 字段(太大)');
|
||||
}
|
||||
|
||||
public function test_raw_list_excludes_business_fields(): void
|
||||
{
|
||||
if (!$this->hasRefundItemData()) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$response = $this->get('/api/v1/raw/refund-items', [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
$first_item = $body['data']['items'][0] ?? [];
|
||||
|
||||
$this->assertArrayNotHasKey('refund_amount', $first_item);
|
||||
$this->assertArrayNotHasKey('quantity', $first_item);
|
||||
$this->assertArrayNotHasKey('buyer_user_id', $first_item);
|
||||
$this->assertArrayNotHasKey('reason', $first_item);
|
||||
}
|
||||
|
||||
// ========== Raw 详情接口 ==========
|
||||
|
||||
public function test_raw_detail_contains_raw_and_ext(): void
|
||||
{
|
||||
$id = $this->getFirstRefundItemId();
|
||||
if (!$id) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$response = $this->get('/api/v1/raw/refund-items/' . $id, [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertArrayHasKey('raw', $body['data'], 'Raw 详情应包含 raw 字段');
|
||||
$this->assertArrayHasKey('ext', $body['data'], 'Raw 详情应包含 ext 字段');
|
||||
}
|
||||
|
||||
public function test_raw_detail_excludes_business_fields(): void
|
||||
{
|
||||
$id = $this->getFirstRefundItemId();
|
||||
if (!$id) {
|
||||
$this->markTestSkipped('没有退款项数据');
|
||||
}
|
||||
|
||||
$response = $this->get('/api/v1/raw/refund-items/' . $id, [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(200);
|
||||
$body = json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertArrayNotHasKey('refund_amount', $body['data']);
|
||||
$this->assertArrayNotHasKey('quantity', $body['data']);
|
||||
$this->assertArrayNotHasKey('buyer_user_id', $body['data']);
|
||||
$this->assertArrayNotHasKey('reason', $body['data']);
|
||||
}
|
||||
|
||||
public function test_raw_detail_not_found_returns_404(): void
|
||||
{
|
||||
$response = $this->get('/api/v1/raw/refund-items/999999999', [], $this->authHeaders());
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertJsonPath('code', 404);
|
||||
}
|
||||
|
||||
// ========== 认证拦截 ==========
|
||||
|
||||
public function test_normal_list_without_token_returns_401(): void
|
||||
{
|
||||
$response = $this->get('/api/v1/refund-items');
|
||||
|
||||
$response->assertStatus(401);
|
||||
}
|
||||
|
||||
public function test_normal_detail_without_token_returns_401(): void
|
||||
{
|
||||
$response = $this->get('/api/v1/refund-items/1');
|
||||
|
||||
$response->assertStatus(401);
|
||||
}
|
||||
|
||||
public function test_raw_list_without_token_returns_401(): void
|
||||
{
|
||||
$response = $this->get('/api/v1/raw/refund-items');
|
||||
|
||||
$response->assertStatus(401);
|
||||
}
|
||||
|
||||
public function test_raw_detail_without_token_returns_401(): void
|
||||
{
|
||||
$response = $this->get('/api/v1/raw/refund-items/1');
|
||||
|
||||
$response->assertStatus(401);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user