README.md 2.3 KB

Test 模块

模块说明

Test 模块是一个示例模块,用于展示模块化开发的最佳实践。

目录结构

app/Module/Test/
├── Models/              # 模型目录
├── Events/              # 事件目录
├── Services/            # 服务目录
│   ├── TestService.php              # 基础服务
│   ├── TestServiceInterface.php     # 基础服务接口
│   ├── TestStatisticsService.php    # 统计服务
│   └── TestStatisticsServiceInterface.php  # 统计服务接口
├── Enums/               # 枚举目录
│   └── TestType.php     # 测试类型枚举
├── Database/            # 数据库目录
│   └── Migrations/      # 迁移文件
└── Tests/               # 测试目录

安装说明

  1. 运行数据库迁移:

    php artisan migrate
    

使用说明

枚举使用

use App\Module\Test\Enums\TestType;

// 获取枚举值
$enabled = TestType::ENABLED->value; // 1
$disabled = TestType::DISABLED->value; // 0

// 获取枚举标签
$enabledLabel = TestType::ENABLED->label(); // "启用"
$disabledLabel = TestType::DISABLED->label(); // "禁用"

基础服务

use App\Module\Test\Services\TestService;
use App\Module\Test\Enums\TestType;

$test = new TestService();

// 创建数据
$model = $test->create([
    'name' => '测试数据',
    'code' => 'TEST001',
    'status' => TestType::ENABLED->value
]);

// 更新数据
$test->update($model, [
    'name' => '更新后的数据',
    'status' => TestType::DISABLED->value
]);

// 删除数据
$test->delete($model);

统计服务

use App\Module\Test\Services\TestStatisticsService;
use App\Module\Test\Enums\TestType;

$statistics = new TestStatisticsService();

// 获取总数统计
$totals = $statistics->getTotalStatistics();

// 获取状态分布
$statusDistribution = $statistics->getStatusDistribution();

// 获取每日创建数量统计
$dailyStats = $statistics->getDailyCreationStatistics(7);

配置说明

暂无配置项。

开发说明

  1. 遵循 PSR-12 编码规范
  2. 使用强类型声明
  3. 编写单元测试
  4. 保持代码简洁

测试说明

运行测试:

php artisan test app/Module/Test/Tests

贡献指南

  1. Fork 项目
  2. 创建特性分支
  3. 提交更改
  4. 推送到分支
  5. 创建 Pull Request