初始化本地仓库

This commit is contained in:
2026-08-31 11:33:59 +08:00
commit 663f74b633
2390 changed files with 402918 additions and 0 deletions
@@ -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;
}
+35
View File
@@ -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;
}
}