From 9d103a2c3401af11983023da9b3e1ea9a2500cc0 Mon Sep 17 00:00:00 2001
From: chenlan <18339827479@163.com>
Date: Mon, 21 Jul 2025 19:39:49 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=87=AA=E5=8A=A8=E7=94=9F?=
=?UTF-8?q?=E6=88=90curd?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/common/utils/scaffold/Generate.php | 35 ++++++++++---------
.../scaffold/templates/ValidateStub.stub | 2 +-
app/controller/IndexController.php | 13 +------
3 files changed, 20 insertions(+), 30 deletions(-)
diff --git a/app/common/utils/scaffold/Generate.php b/app/common/utils/scaffold/Generate.php
index 687780d..fee26b1 100644
--- a/app/common/utils/scaffold/Generate.php
+++ b/app/common/utils/scaffold/Generate.php
@@ -25,12 +25,12 @@ class Generate
$fs = new Filesystem();
// 模板路径
- $templateDir = __DIR__ . '/../templates/';
- $controllerPath = __DIR__ . "/../../../{$this->options['controller']['module']}/controller/{$this->options['controller']['name']}Controller.php";
- $servicePath = __DIR__ . "/../../../{$this->options['service']['module']}/service/{$this->options['service']['name']}Service.php";
- $logicPath = __DIR__ . "/../../../{$this->options['logic']['module']}/service/{$this->options['logic']['name']}Service.php";
- $modelPath = __DIR__ . "/../../../{$this->options['model']['module']}/model/{$this->options['model']['name']}.php";
- $validatePath = __DIR__ . "/../../../{$this->options['validate']['module']}/validate/{$this->options['validate']['name']}Validate.php";
+ $templateDir = __DIR__ . '/templates/';
+ $controllerPath = __DIR__ . "/../../../{$this->options['controller']['module']}/controller/".ucfirst($this->options['controller']['name'])."Controller.php";
+ $servicePath = __DIR__ . "/../../../{$this->options['service']['module']}/service/".ucfirst($this->options['service']['name'])."Service.php";
+ $logicPath = __DIR__ . "/../../../{$this->options['logic']['module']}/logic/".ucfirst($this->options['logic']['name'])."Logic.php";
+ $modelPath = __DIR__ . "/../../../{$this->options['model']['module']}/model/".ucfirst($this->options['model']['name']).".php";
+ $validatePath = __DIR__ . "/../../../{$this->options['validate']['module']}/validate/".ucfirst($this->options['validate']['name'])."Validate.php";
// 创建目录(如果不存在)
$fs->mkdir(__DIR__ . "/../../../{$this->options['controller']['module']}/controller");
@@ -59,7 +59,7 @@ class Generate
$ModelStub = $this->generateFile($templateDir, 'ModelStub.stub', $modelPath, 'model');
// 生成验证器类文件
- $ValidatorStub = $this->generateFile($templateDir, 'ValidatorStub.stub', $validatePath, 'validate');
+ $ValidatorStub = $this->generateFile($templateDir, 'ValidateStub.stub', $validatePath, 'validate');
return $ControllerStub . $ServiceStub . $LogicStub . $ModelStub . $ValidatorStub . "文件生成成功!
";
}
@@ -107,31 +107,32 @@ class Generate
case 'controller':
$content = str_replace('{{controllerModule}}', $this->options['controller']['module'], $content);
$content = str_replace('{{serviceModule}}', $this->options['service']['module'], $content);
- $content = str_replace('{{serviceName}}', $this->options['service']['name'], $content);
- $content = str_replace('{{controllerName}}', $this->options['controller']['name'], $content);
+ $content = str_replace('{{serviceName}}', ucfirst($this->options['service']['name']), $content);
+ $content = str_replace('{{controllerName}}', ucfirst($this->options['controller']['name']), $content);
break;
case 'service':
$content = str_replace('{{serviceModule}}', $this->options['service']['module'], $content);
- $content = str_replace('{{validateName}}', $this->options['validate']['name'], $content);
+ $content = str_replace('{{validateModule}}', $this->options['validate']['module'], $content);
+ $content = str_replace('{{validateName}}', ucfirst($this->options['validate']['name']), $content);
$content = str_replace('{{modelModule}}', $this->options['model']['module'], $content);
- $content = str_replace('{{modelName}}', $this->options['model']['name'], $content);
- $content = str_replace('{{serviceName}}', $this->options['service']['name'], $content);
+ $content = str_replace('{{modelName}}', ucfirst($this->options['model']['name']), $content);
+ $content = str_replace('{{serviceName}}', ucfirst($this->options['service']['name']), $content);
break;
case 'logic':
$content = str_replace('{{logicModule}}', $this->options['logic']['module'], $content);
$content = str_replace('{{modelModule}}', $this->options['model']['module'], $content);
- $content = str_replace('{{modelName}}', $this->options['model']['name'], $content);
- $content = str_replace('{{logicName}}', $this->options['logic']['name'], $content);
+ $content = str_replace('{{modelName}}', ucfirst($this->options['model']['name']), $content);
+ $content = str_replace('{{logicName}}', ucfirst($this->options['logic']['name']), $content);
break;
case 'model':
$content = str_replace('{{modelModule}}', $this->options['model']['module'], $content);
- $content = str_replace('{{modelName}}', $this->options['model']['name'], $content);
+ $content = str_replace('{{modelName}}', ucfirst($this->options['model']['name']), $content);
$content = str_replace('{{table}}', $this->options['table'], $content);
- $content = str_replace('{{fillable}}', $this->options['fillable'], $content);
+ $content = str_replace('{{fillable}}', $this->fillableFields(), $content);
break;
case 'validate':
$content = str_replace('{{validateModule}}', $this->options['validate']['module'], $content);
- $content = str_replace('{{validateName}}', $this->options['validate']['name'], $content);
+ $content = str_replace('{{validateName}}', ucfirst($this->options['validate']['name']), $content);
break;
}
diff --git a/app/common/utils/scaffold/templates/ValidateStub.stub b/app/common/utils/scaffold/templates/ValidateStub.stub
index 01aa1b2..862b6f1 100644
--- a/app/common/utils/scaffold/templates/ValidateStub.stub
+++ b/app/common/utils/scaffold/templates/ValidateStub.stub
@@ -4,7 +4,7 @@ namespace app\{{validateModule}}\validate;
use think\Validate;
-class {{validateName}}Validator extends Validate
+class {{validateName}}Validate extends Validate
{
// 规则
protected $rule = [
diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php
index 53d6280..b694a23 100644
--- a/app/controller/IndexController.php
+++ b/app/controller/IndexController.php
@@ -90,18 +90,7 @@ class IndexController
'module' => 'admin',
'name' => 'systems'
],
- 'table' => 'systems',
- 'fillable' => [
- 'code',
- 'name',
- 'type',
- 'desc',
- 'icon',
- 'domain_url',
- 'is_role',
- 'sort',
- 'status'
- ]
+ 'table' => 'systems'
];
$result = (new Generate($options))->doGenerate();