初始化本地仓库
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
use madong\swagger\schema\BaseRequestDTO;
|
||||
|
||||
#[OA\Schema(
|
||||
title: '基础表单请求',
|
||||
description: '通用表单请求基类'
|
||||
)]
|
||||
abstract class BaseFormRequest extends BaseRequestDTO
|
||||
{
|
||||
|
||||
#[OA\Property(
|
||||
property: 'id',
|
||||
description: 'ID',
|
||||
type: 'string',
|
||||
example: '246996721795072000',
|
||||
nullable: false
|
||||
)]
|
||||
public string|int|null $id ;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
use madong\swagger\schema\BaseRequestDTO;
|
||||
|
||||
#[OA\Schema(
|
||||
title: '基础分页查询请求',
|
||||
description: '通用分页查询请求参数'
|
||||
)]
|
||||
class BaseQueryRequest extends BaseRequestDTO
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'page',
|
||||
description: '当前页码',
|
||||
type: 'integer|null',
|
||||
minimum: 0,
|
||||
example: 1
|
||||
)]
|
||||
public ?int $page = 1;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'limit',
|
||||
description: '每页条数',
|
||||
type: 'integer',
|
||||
maximum: 999999,
|
||||
minimum: 1,
|
||||
example: 15
|
||||
)]
|
||||
public ?int $limit = 15;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'sort_field',
|
||||
description: '排序字段',
|
||||
type: 'string',
|
||||
example: 'id'
|
||||
)]
|
||||
public ?string $sortField = null;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'sort_order',
|
||||
description: '排序方式',
|
||||
type: 'string',
|
||||
enum: ['asc', 'desc'],
|
||||
example: 'desc'
|
||||
)]
|
||||
public ?string $sortOrder = 'desc';
|
||||
|
||||
#[OA\Property(
|
||||
property: 'keyword',
|
||||
description: '关键词搜索',
|
||||
type: 'string',
|
||||
example: ''
|
||||
)]
|
||||
public ?string $keyword = null;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request;
|
||||
|
||||
use madong\swagger\schema\BaseRequestDTO;
|
||||
use OpenApi\Attributes as OA;
|
||||
use WebmanTech\DTO\Attributes\ValidationRules;
|
||||
|
||||
#[OA\Schema(
|
||||
title: '批量删除请求',
|
||||
description: '批量删除请求参数'
|
||||
)]
|
||||
class BatchDeleteRequest extends BaseRequestDTO
|
||||
{
|
||||
#[OA\Property(description: '批量删除ID数组', type: 'array', items: new OA\Items(type: 'string'), example: [1, 2])]
|
||||
#[ValidationRules(rules: 'array|required|min:1|each:integer|each:min:1|distinct')]
|
||||
public array $ids = [];
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request;
|
||||
|
||||
use madong\swagger\schema\BaseRequestDTO;
|
||||
use OpenApi\Attributes as OA;
|
||||
use WebmanTech\DTO\Attributes\ValidationRules;
|
||||
|
||||
#[OA\Schema(
|
||||
title: '状态变更请求',
|
||||
description: '状态变更请求参数'
|
||||
)]
|
||||
class ChangeStatusRequest extends BaseRequestDTO
|
||||
{
|
||||
|
||||
#[OA\Parameter(
|
||||
name: 'id',
|
||||
description: '任务ID',
|
||||
in: 'path',
|
||||
required: true,
|
||||
schema: new OA\Schema(type: 'string', example: 1)
|
||||
)]
|
||||
#[ValidationRules(rules: 'string|required|in:0,1')]
|
||||
public int $id;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'enabled',
|
||||
description: '目标状态(0:禁用,1:启用)',
|
||||
type: 'integer',
|
||||
enum: [0, 1],
|
||||
example: 1
|
||||
)]
|
||||
#[ValidationRules(rules: 'string|required|in:0,1')]
|
||||
public int $enabled;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
use madong\swagger\schema\BaseRequestDTO;
|
||||
use WebmanTech\DTO\Attributes\ValidationRules;
|
||||
|
||||
#[OA\Schema(
|
||||
title: 'ID查询请求',
|
||||
description: '根据ID查询单条记录的请求参数'
|
||||
)]
|
||||
class IdRequest extends BaseRequestDTO
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'id',
|
||||
description: '记录ID',
|
||||
type: 'string',
|
||||
example: 1
|
||||
)]
|
||||
#[ValidationRules(rules: 'string|required|min:1')]
|
||||
public int $id;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
use madong\swagger\schema\BaseRequestDTO;
|
||||
|
||||
#[OA\Schema(
|
||||
title: '路径ID参数请求',
|
||||
description: '通过路径参数传递ID的请求结构,用于 /api/resource/{id} 类型的接口'
|
||||
)]
|
||||
class PathIdRequest extends BaseRequestDTO
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'id',
|
||||
description: '资源ID(从路径参数获取)',
|
||||
type: 'string',
|
||||
example: 123,
|
||||
)]
|
||||
public int $id;
|
||||
|
||||
public function __construct(int $id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证ID是否有效
|
||||
*/
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->id > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从路由参数创建实例
|
||||
*/
|
||||
public static function fromRoute(int $id): self
|
||||
{
|
||||
return new self($id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request\common;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
use madong\swagger\schema\BaseRequestDTO;
|
||||
|
||||
#[OA\Schema(
|
||||
title: '通用数据请求',
|
||||
description: '包含通用data字段的请求结构,用于传递任意业务数据'
|
||||
)]
|
||||
class DataRequest extends BaseRequestDTO
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'data',
|
||||
description: '业务数据',
|
||||
type: 'object',
|
||||
example: []
|
||||
)]
|
||||
public mixed $data = null;
|
||||
|
||||
public function __construct(mixed $data = null)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function getData(): mixed
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据并转换为数组
|
||||
*/
|
||||
public function getDataAsArray(): array
|
||||
{
|
||||
return is_array($this->data) ? $this->data : (array) $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从请求体创建实例
|
||||
*/
|
||||
public static function fromBody(mixed $data): self
|
||||
{
|
||||
return new self($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有数据
|
||||
*/
|
||||
public function hasData(): bool
|
||||
{
|
||||
return $this->data !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查数据是否为空
|
||||
*/
|
||||
public function isEmpty(): bool
|
||||
{
|
||||
if ($this->data === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (is_array($this->data)) {
|
||||
return empty($this->data);
|
||||
}
|
||||
|
||||
if (is_object($this->data)) {
|
||||
return empty((array) $this->data);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request\traits;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
trait WithDateRange
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'start_date',
|
||||
description: '开始日期 (YYYY-MM-DD)',
|
||||
type: 'string',
|
||||
format: 'date',
|
||||
example: '2024-01-01',
|
||||
nullable: true
|
||||
)]
|
||||
public ?string $startDate = null;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'end_date',
|
||||
description: '结束日期 (YYYY-MM-DD)',
|
||||
type: 'string',
|
||||
format: 'date',
|
||||
example: '2024-12-31',
|
||||
nullable: true
|
||||
)]
|
||||
public ?string $endDate = null;
|
||||
|
||||
public function getStartDate(): ?string
|
||||
{
|
||||
return $this->startDate;
|
||||
}
|
||||
|
||||
public function getEndDate(): ?string
|
||||
{
|
||||
return $this->endDate;
|
||||
}
|
||||
|
||||
public function hasDateRange(): bool
|
||||
{
|
||||
return !empty($this->startDate) && !empty($this->endDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日期范围数组
|
||||
*/
|
||||
public function getDateRange(): array
|
||||
{
|
||||
return [
|
||||
'start' => $this->startDate,
|
||||
'end' => $this->endDate,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证日期范围是否有效
|
||||
*/
|
||||
public function isValidDateRange(): bool
|
||||
{
|
||||
if (!$this->hasDateRange()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$start = strtotime($this->startDate);
|
||||
$end = strtotime($this->endDate);
|
||||
|
||||
return $start && $end && $start <= $end;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request\traits;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
trait WithId
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'id',
|
||||
description: '主键ID',
|
||||
type: 'integer',
|
||||
minimum: 1,
|
||||
example: 1
|
||||
)]
|
||||
public ?int $id = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function hasId(): bool
|
||||
{
|
||||
return !empty($this->id);
|
||||
}
|
||||
|
||||
public function isUpdate(): bool
|
||||
{
|
||||
return $this->hasId();
|
||||
}
|
||||
|
||||
public function isCreate(): bool
|
||||
{
|
||||
return !$this->hasId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request\traits;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
trait WithPagination
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'page',
|
||||
description: '当前页码',
|
||||
type: 'integer|null',
|
||||
minimum: 1,
|
||||
example: 1
|
||||
)]
|
||||
public ?int $page = 1;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'limit',
|
||||
description: '每页条数',
|
||||
type: 'integer',
|
||||
maximum: 999999,
|
||||
minimum: 1,
|
||||
example: 15
|
||||
)]
|
||||
public ?int $limit = 15;
|
||||
|
||||
public function getPage(): int
|
||||
{
|
||||
return $this->page ?? 1;
|
||||
}
|
||||
|
||||
public function getLimit(): int
|
||||
{
|
||||
$limit = $this->limit ?? 15;
|
||||
return min(max($limit, 1), 100);
|
||||
}
|
||||
|
||||
public function getOffset(): int
|
||||
{
|
||||
return ($this->getPage() - 1) * $this->getLimit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request\traits;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
trait WithSearch
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'keyword',
|
||||
description: '关键词搜索',
|
||||
type: 'string',
|
||||
example: ''
|
||||
)]
|
||||
public ?string $keyword = null;
|
||||
|
||||
public function getKeyword(): ?string
|
||||
{
|
||||
return $this->keyword;
|
||||
}
|
||||
|
||||
public function hasKeyword(): bool
|
||||
{
|
||||
return !empty($this->keyword);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request\traits;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
trait WithSorting
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'sort_field',
|
||||
description: '排序字段',
|
||||
type: 'string',
|
||||
example: 'id'
|
||||
)]
|
||||
public ?string $sortField = null;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'sort_order',
|
||||
description: '排序方式',
|
||||
type: 'string',
|
||||
enum: ['asc', 'desc'],
|
||||
example: 'desc'
|
||||
)]
|
||||
public ?string $sortOrder = 'desc';
|
||||
|
||||
#[OA\Property(
|
||||
property: 'order',
|
||||
description: '排序规则 (例: sort asc, id desc)',
|
||||
type: 'string',
|
||||
example: 'id desc'
|
||||
)]
|
||||
public ?string $order = null;
|
||||
|
||||
public function getSortField(): ?string
|
||||
{
|
||||
return $this->sortField;
|
||||
}
|
||||
|
||||
public function getSortOrder(): string
|
||||
{
|
||||
return in_array(strtolower($this->sortOrder ?? ''), ['asc', 'desc'])
|
||||
? strtolower($this->sortOrder)
|
||||
: 'desc';
|
||||
}
|
||||
|
||||
public function getOrder(): ?string
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取排序字符串 (用于数据库查询)
|
||||
*/
|
||||
public function getOrderBy(): string
|
||||
{
|
||||
if (!empty($this->order)) {
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
if (!empty($this->sortField)) {
|
||||
return $this->sortField . ' ' . $this->getSortOrder();
|
||||
}
|
||||
|
||||
return 'id desc';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request\traits;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
trait WithStatus
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'status',
|
||||
description: '状态(0:禁用,1:启用)',
|
||||
type: 'integer',
|
||||
enum: [0, 1],
|
||||
example: 1,
|
||||
nullable: true
|
||||
)]
|
||||
public ?int $status = null;
|
||||
|
||||
public function getStatus(): ?int
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function hasStatus(): bool
|
||||
{
|
||||
return $this->status !== null;
|
||||
}
|
||||
|
||||
public function isEnable(): bool
|
||||
{
|
||||
return $this->status === 1;
|
||||
}
|
||||
|
||||
public function isDisable(): bool
|
||||
{
|
||||
return $this->status === 0;
|
||||
}
|
||||
|
||||
public function setEnable(): void
|
||||
{
|
||||
$this->status = 1;
|
||||
}
|
||||
|
||||
public function setDisable(): void
|
||||
{
|
||||
$this->status = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\request\traits;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
trait WithTimeRange
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'start_time',
|
||||
description: '开始时间 (YYYY-MM-DD HH:mm:ss)',
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
example: '2024-01-01 00:00:00',
|
||||
nullable: true
|
||||
)]
|
||||
public ?string $startTime = null;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'end_time',
|
||||
description: '结束时间 (YYYY-MM-DD HH:mm:ss)',
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
example: '2024-12-31 23:59:59',
|
||||
nullable: true
|
||||
)]
|
||||
public ?string $endTime = null;
|
||||
|
||||
public function getStartTime(): ?string
|
||||
{
|
||||
return $this->startTime;
|
||||
}
|
||||
|
||||
public function getEndTime(): ?string
|
||||
{
|
||||
return $this->endTime;
|
||||
}
|
||||
|
||||
public function hasTimeRange(): bool
|
||||
{
|
||||
return !empty($this->startTime) && !empty($this->endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时间范围数组
|
||||
*/
|
||||
public function getTimeRange(): array
|
||||
{
|
||||
return [
|
||||
'start' => $this->startTime,
|
||||
'end' => $this->endTime,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证时间范围是否有效
|
||||
*/
|
||||
public function isValidTimeRange(): bool
|
||||
{
|
||||
if (!$this->hasTimeRange()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$start = strtotime($this->startTime);
|
||||
$end = strtotime($this->endTime);
|
||||
|
||||
return $start && $end && $start <= $end;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\response;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
use madong\swagger\schema\BaseResponseDTO;
|
||||
|
||||
#[OA\Schema(
|
||||
title: '错误响应',
|
||||
description: '错误响应结构'
|
||||
)]
|
||||
class ErrorResponse extends BaseResponseDTO
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'error',
|
||||
description: '错误信息',
|
||||
type: 'string',
|
||||
example: '参数错误'
|
||||
)]
|
||||
public string $error;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'code',
|
||||
description: '错误码',
|
||||
type: 'string',
|
||||
example: 'VALIDATION_ERROR'
|
||||
)]
|
||||
public ?string $code = null;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'details',
|
||||
description: '错误详情',
|
||||
type: 'array',
|
||||
items: new OA\Items(type: 'string'),
|
||||
example: []
|
||||
)]
|
||||
public ?array $details = null;
|
||||
|
||||
public function __construct(
|
||||
string $error = '操作失败',
|
||||
?string $code = null,
|
||||
?array $details = null
|
||||
)
|
||||
{
|
||||
$this->error = $error;
|
||||
$this->code = $code;
|
||||
$this->details = $details;
|
||||
}
|
||||
|
||||
public static function make(
|
||||
string $error,
|
||||
?string $code = null,
|
||||
?array $details = null
|
||||
): self
|
||||
{
|
||||
return new self($error, $code, $details);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\response;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
use madong\swagger\schema\BaseResponseDTO;
|
||||
|
||||
#[OA\Schema(
|
||||
title: '列表数据响应',
|
||||
description: '列表数据响应结构'
|
||||
)]
|
||||
class ListResponse extends BaseResponseDTO
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'list',
|
||||
description: '数据列表',
|
||||
type: 'array',
|
||||
items: new OA\Items(),
|
||||
example: []
|
||||
)]
|
||||
public array $list;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\response;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
use madong\swagger\schema\BaseResponseDTO;
|
||||
|
||||
#[OA\Schema(
|
||||
title: '分页数据响应',
|
||||
description: '分页数据响应结构'
|
||||
)]
|
||||
class PageResponse extends BaseResponseDTO
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'total',
|
||||
description: '总记录数',
|
||||
type: 'integer',
|
||||
example: 100
|
||||
)]
|
||||
public int $total;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'page',
|
||||
description: '当前页码',
|
||||
type: 'integer',
|
||||
example: 1
|
||||
)]
|
||||
public int $page;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'limit',
|
||||
description: '每页条数',
|
||||
type: 'integer',
|
||||
example: 15
|
||||
)]
|
||||
public int $limit;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'items',
|
||||
description: '数据列表',
|
||||
type: 'array',
|
||||
items: new OA\Items(),
|
||||
example: []
|
||||
)]
|
||||
public array $items;
|
||||
|
||||
public function __construct(
|
||||
int $total = 0,
|
||||
int $page = 1,
|
||||
int $limit = 15,
|
||||
array $items = []
|
||||
) {
|
||||
$this->total = $total;
|
||||
$this->page = $page;
|
||||
$this->limit = $limit;
|
||||
$this->items = $items;
|
||||
}
|
||||
|
||||
public static function make(int $total, int $page, int $limit, array $items): self
|
||||
{
|
||||
return new self($total, $page, $limit, $items);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
|
||||
namespace app\schema\response;
|
||||
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
#[OA\Schema(
|
||||
title: 'API响应结构',
|
||||
description: '系统统一API响应数据格式'
|
||||
)]
|
||||
class Result implements Arrayable
|
||||
{
|
||||
public function __construct(
|
||||
#[OA\Property(ref: 'ResultCode', title: '响应码')]
|
||||
public ResultCode $code = ResultCode::SUCCESS,
|
||||
#[OA\Property(title: '响应消息', type: 'string', example: 'success')]
|
||||
public ?string $msg = null,
|
||||
#[OA\Property(title: '响应数据', example: [])]
|
||||
public mixed $data = []
|
||||
)
|
||||
{
|
||||
if ($this->code === ResultCode::SUCCESS) {
|
||||
$this->msg = $this->msg ?? 'success';
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'code' => $this->code->value,
|
||||
'msg' => $this->msg,
|
||||
'data' => $this->data,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\response;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
#[OA\Schema(
|
||||
title: 'API响应状态',
|
||||
type: 'integer',
|
||||
default: 0
|
||||
)]
|
||||
enum ResultCode: int
|
||||
{
|
||||
|
||||
case SUCCESS = 0;
|
||||
|
||||
case FAIL = -1;
|
||||
|
||||
case UNAUTHORIZED = 401;
|
||||
|
||||
case FORBIDDEN = 403;
|
||||
|
||||
case NOT_FOUND = 404;
|
||||
|
||||
case METHOD_NOT_ALLOWED = 405;
|
||||
|
||||
case NOT_ACCEPTABLE = 406;
|
||||
|
||||
case UNPROCESSABLE_ENTITY = 422;
|
||||
|
||||
case DISABLED = 423;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\response;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
use madong\swagger\schema\BaseResponseDTO;
|
||||
|
||||
#[OA\Schema(
|
||||
title: '简单数据响应',
|
||||
description: '简单数据响应结构,用于返回单个值或简单对象'
|
||||
)]
|
||||
class SimpleResponse extends BaseResponseDTO
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'flag',
|
||||
description: '操作状态标识',
|
||||
type: 'boolean',
|
||||
example: true
|
||||
)]
|
||||
public bool $flag;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'message',
|
||||
description: '操作消息',
|
||||
type: 'string',
|
||||
example: '操作成功'
|
||||
)]
|
||||
public ?string $message = null;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'data',
|
||||
description: '附加数据',
|
||||
type: 'object',
|
||||
example: []
|
||||
)]
|
||||
public mixed $data = null;
|
||||
|
||||
public function __construct(
|
||||
bool $flag = true,
|
||||
?string $message = null,
|
||||
mixed $data = null
|
||||
)
|
||||
{
|
||||
$this->flag = $flag;
|
||||
$this->message = $message ?? ($flag ? '操作成功' : '操作失败');
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public static function success(?string $message = '操作成功', mixed $data = null): self
|
||||
{
|
||||
return new self(true, $message, $data);
|
||||
}
|
||||
|
||||
public static function fail(?string $message = '操作失败', mixed $data = null): self
|
||||
{
|
||||
return new self(false, $message, $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
*+------------------
|
||||
* madong
|
||||
*+------------------
|
||||
* Copyright (c) https://gitee.com/motion-code All rights reserved.
|
||||
*+------------------
|
||||
* Author: Mr. April (405784684@qq.com)
|
||||
*+------------------
|
||||
* Official Website: http://www.madong.tech
|
||||
*/
|
||||
|
||||
namespace app\schema\response;
|
||||
|
||||
use OpenApi\Attributes as OA;
|
||||
use madong\swagger\schema\BaseResponseDTO;
|
||||
|
||||
#[OA\Schema(
|
||||
title: '树形数据响应',
|
||||
description: '树形结构数据响应,用于菜单、部门等层级数据'
|
||||
)]
|
||||
class TreeResponse extends BaseResponseDTO
|
||||
{
|
||||
#[OA\Property(
|
||||
property: 'id',
|
||||
description: '节点ID',
|
||||
type: 'string',
|
||||
example: 1
|
||||
)]
|
||||
public string $id;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'pid',
|
||||
description: '父节点ID',
|
||||
type: 'string',
|
||||
example: 0
|
||||
)]
|
||||
public string $pid;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'name',
|
||||
description: '节点名称',
|
||||
type: 'string',
|
||||
example: '系统管理'
|
||||
)]
|
||||
public string $name;
|
||||
|
||||
#[OA\Property(
|
||||
property: 'children',
|
||||
description: '子节点列表',
|
||||
type: 'array',
|
||||
items: new OA\Items(),
|
||||
example: []
|
||||
)]
|
||||
public array $children = [];
|
||||
|
||||
public function __construct(
|
||||
string|int $id = 0,
|
||||
string|int $parentId = 0,
|
||||
string $name = '',
|
||||
array $children = []
|
||||
)
|
||||
{
|
||||
$this->id = (string)$id;
|
||||
$this->pid = (string)$parentId;
|
||||
$this->name = $name;
|
||||
$this->children = $children;
|
||||
}
|
||||
|
||||
public static function make(
|
||||
int $id,
|
||||
int $parentId,
|
||||
string $name,
|
||||
array $children = []
|
||||
): self
|
||||
{
|
||||
return new self($id, $parentId, $name, $children);
|
||||
}
|
||||
|
||||
public function hasChildren(): bool
|
||||
{
|
||||
return !empty($this->children);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user