调整自动生成curd

This commit is contained in:
2025-07-21 19:39:49 +08:00
parent c42236da7e
commit 9d103a2c34
3 changed files with 20 additions and 30 deletions
+18 -17
View File
@@ -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 . "<info>文件生成成功!</info> <br/>";
}
@@ -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;
}
@@ -4,7 +4,7 @@ namespace app\{{validateModule}}\validate;
use think\Validate;
class {{validateName}}Validator extends Validate
class {{validateName}}Validate extends Validate
{
// 规则
protected $rule = [
+1 -12
View File
@@ -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();