Commit 84d84ec6 authored by 王源's avatar 王源 🎧

优化生成模板

parent 6e7419a2
...@@ -454,8 +454,7 @@ class MakeModelCommand extends HyperfCommand ...@@ -454,8 +454,7 @@ class MakeModelCommand extends HyperfCommand
/** /**
* 创建验证文件 * 创建验证文件
*/ */
private private function makeValidator()
function makeValidator()
{ {
$stubFile = $this->path . 'validator.stub'; $stubFile = $this->path . 'validator.stub';
$folder = $this->appPath . '/Validators'; $folder = $this->appPath . '/Validators';
...@@ -570,8 +569,7 @@ class MakeModelCommand extends HyperfCommand ...@@ -570,8 +569,7 @@ class MakeModelCommand extends HyperfCommand
$this->writeToFile($file, $content); $this->writeToFile($file, $content);
} }
private private function makeRepositoryInterface()
function makeRepositoryInterface()
{ {
$stubFile = $this->path . 'repositoryInterface.stub'; $stubFile = $this->path . 'repositoryInterface.stub';
$folder = $this->appPath . '/Repository/Interfaces'; $folder = $this->appPath . '/Repository/Interfaces';
...@@ -600,7 +598,7 @@ class MakeModelCommand extends HyperfCommand ...@@ -600,7 +598,7 @@ class MakeModelCommand extends HyperfCommand
$content = file_get_contents($stubFile); $content = file_get_contents($stubFile);
$info = $this->currentTableStructure; $info = $this->currentTableStructure;
//列表 //列表
$list = "\$conditions = \$this->request->input();\n"; $list = "\$conditions = \$this->request->inputs();\n";
$list .= "\t\t\$list = \$this->model->where(function (\$q) use (\$conditions) {\n"; $list .= "\t\t\$list = \$this->model->where(function (\$q) use (\$conditions) {\n";
foreach ($info['fields'] as $v) { foreach ($info['fields'] as $v) {
if (Str::endsWith($v['column_name'], "_id")) { if (Str::endsWith($v['column_name'], "_id")) {
...@@ -669,7 +667,7 @@ class MakeModelCommand extends HyperfCommand ...@@ -669,7 +667,7 @@ class MakeModelCommand extends HyperfCommand
foreach ($info['relations']['hasMany'] as $v) { foreach ($info['relations']['hasMany'] as $v) {
$rs .= "\n\tpublic function {$v['function']}(\$id): array\n"; $rs .= "\n\tpublic function {$v['function']}(\$id): array\n";
$rs .= "\t{\n"; $rs .= "\t{\n";
$rs .= "\t\t\$pageSize = (int)\$this->request->input('page_size', env(\"DEFAULT_PAGE_SIZE\",10));\n"; $rs .= "\t\t\$pageSize = (int)\$this->request->input('page_size', DEFAULT_PAGE_SIZE);\n";
$rs .= "\t\treturn \$this->find(\$id)->{$v['function']}()->orderByDesc('id')->paginate(\$pageSize)->toArray();\n"; $rs .= "\t\treturn \$this->find(\$id)->{$v['function']}()->orderByDesc('id')->paginate(\$pageSize)->toArray();\n";
$rs .= "\t}\n"; $rs .= "\t}\n";
} }
...@@ -1017,14 +1015,12 @@ class MakeModelCommand extends HyperfCommand ...@@ -1017,14 +1015,12 @@ class MakeModelCommand extends HyperfCommand
/**生成迁移文件的日期格式 /**生成迁移文件的日期格式
* @return string * @return string
*/ */
private private function getDatePrefix(): string
function getDatePrefix(): string
{ {
return date('Y_m_dHis'); return date('Y_m_dHis');
} }
public public function configure()
function configure()
{ {
//$this->call() //$this->call()
parent::configure(); parent::configure();
...@@ -1042,8 +1038,7 @@ class MakeModelCommand extends HyperfCommand ...@@ -1042,8 +1038,7 @@ class MakeModelCommand extends HyperfCommand
* 配置文件内容 * 配置文件内容
* @return array * @return array
*/ */
protected protected function getArguments()
function getArguments()
{ {
return [ return [
['name', InputArgument::OPTIONAL, '数据库表名'], ['name', InputArgument::OPTIONAL, '数据库表名'],
......
...@@ -40,7 +40,7 @@ class %ModelClass%Controller extends AbstractController ...@@ -40,7 +40,7 @@ class %ModelClass%Controller extends AbstractController
/** /**
* 获取列表数据 * 获取列表数据
* @Perm("index") * @Perm("index")
* @param $id id编号 * @param int $id id编号
* @return mixed * @return mixed
*/ */
public function show($id) public function show($id)
...@@ -61,6 +61,7 @@ class %ModelClass%Controller extends AbstractController ...@@ -61,6 +61,7 @@ class %ModelClass%Controller extends AbstractController
/** /**
* 更新数据 * 更新数据
* @param int $id id编号
* @return mixed * @return mixed
*/ */
public function update($id) public function update($id)
...@@ -71,6 +72,7 @@ class %ModelClass%Controller extends AbstractController ...@@ -71,6 +72,7 @@ class %ModelClass%Controller extends AbstractController
/** /**
* 删除单条数据 * 删除单条数据
* @param int $id id编号
* @return mixed * @return mixed
*/ */
public function delete($id) public function delete($id)
......
...@@ -13,7 +13,7 @@ namespace App\Model; ...@@ -13,7 +13,7 @@ namespace App\Model;
%namespace% %namespace%
/** /**
* 模型类 %ClassName% * 模型类 %ClassName%
* @package App\Models * @package App\Model
%properties% %properties%
*/ */
class %ClassName% extends Model class %ClassName% extends Model
......
...@@ -18,16 +18,15 @@ use Meibuyu\Micro\Exceptions\HttpResponseException; ...@@ -18,16 +18,15 @@ use Meibuyu\Micro\Exceptions\HttpResponseException;
use Meibuyu\Micro\Repository\Eloquent\BaseRepository; use Meibuyu\Micro\Repository\Eloquent\BaseRepository;
/** /**
* %ModelClass%RepositoryEloquent 类. * Class %ModelClass%RepositoryEloquent
* * @package App\Repository\Eloquent;
* @package namespace App\Repository\Eloquent;
*/ */
class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelClass%Repository class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelClass%Repository
{ {
/** /**
* %ModelClass% 模型 * %ModelClass% 模型
* @return %ModelClass% * @return %ModelClass%|string
*/ */
public function model(): %ModelClass% public function model(): %ModelClass%
{ {
...@@ -36,7 +35,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla ...@@ -36,7 +35,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla
/** /**
* 数据校验器 * 数据校验器
* @return %ModelClass%Validator * @return %ModelClass%Validator|string
*/ */
public function validator(): %ModelClass%Validator public function validator(): %ModelClass%Validator
{ {
...@@ -49,8 +48,8 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla ...@@ -49,8 +48,8 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla
*/ */
public function list(): array public function list(): array
{ {
$pageSize = (int)$this->request->input('page_size', env("DEFAULT_PAGE_SIZE",10)); $pageSize = (int)$this->request->input('page_size', DEFAULT_PAGE_SIZE);
%list%; %list%
} }
/** /**
...@@ -60,7 +59,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla ...@@ -60,7 +59,7 @@ class %ModelClass%RepositoryEloquent extends BaseRepository implements %ModelCla
*/ */
public function show($id): array public function show($id): array
{ {
%show%; %show%
} }
/** /**
......
...@@ -14,9 +14,8 @@ namespace App\Repository\Interfaces; ...@@ -14,9 +14,8 @@ namespace App\Repository\Interfaces;
use Meibuyu\Micro\Repository\Contracts\RepositoryInterface; use Meibuyu\Micro\Repository\Contracts\RepositoryInterface;
/** /**
* %ClassName% 接口类. * Interface %ClassName%
* * @package App\Repository\Interfaces
* @package namespace App\Repository\Interfaces;
*/ */
interface %ClassName% extends RepositoryInterface interface %ClassName% extends RepositoryInterface
{ {
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Validators; namespace App\Validators;
use Meibuyu\Micro\Validator\Contracts\ValidatorInterface; use Meibuyu\Micro\Validator\Contracts\ValidatorInterface;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment