Loading src/Command/MakeModelCommand.php +8 −4 Original line number Original line Diff line number Diff line Loading @@ -113,6 +113,10 @@ class MakeModelCommand extends HyperfCommand if ($v == 'migrations') { if ($v == 'migrations') { continue; continue; } } if (!$this->builder->hasTable($v)) { $this->info("表" . $v . "不存在!"); continue; } $this->tableIndex = $k; $this->tableIndex = $k; $this->input->setArgument("name", $v); $this->input->setArgument("name", $v); $this->table = $v; $this->table = $v; Loading Loading @@ -495,11 +499,11 @@ class MakeModelCommand extends HyperfCommand $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")) { $list .= "\t\t\tif(\$conditions['" . $v['column_name'] . "'] !== '') {\n"; $list .= "\t\t\tif(isset(\$conditions['" . $v['column_name'] . "']) && \$conditions['" . $v['column_name'] . "'] !== '') {\n"; $list .= "\t\t\t\t\$q->where('" . $v['column_name'] . "', \$conditions['" . $v['column_name'] . "']);\n"; $list .= "\t\t\t\t\$q->where('" . $v['column_name'] . "', \$conditions['" . $v['column_name'] . "']);\n"; $list .= "\t\t\t}\n"; $list .= "\t\t\t}\n"; } else if ($v['column_name'] == 'name' || Str::contains($v['column_name'], "_name")) { } else if ($v['column_name'] == 'name' || Str::contains($v['column_name'], "_name")) { $list .= "\t\t\tif(\$conditions['keyword'] !== '') {\n"; $list .= "\t\t\tif(isset(\$conditions['" . $v['column_name'] . "']) && \$conditions['keyword'] !== '') {\n"; $list .= "\t\t\t\t\$q->where('" . $v['column_name'] . "', \$conditions['keyword']);\n"; $list .= "\t\t\t\t\$q->where('" . $v['column_name'] . "', \$conditions['keyword']);\n"; $list .= "\t\t\t}\n"; $list .= "\t\t\t}\n"; } } Loading Loading @@ -668,7 +672,7 @@ class MakeModelCommand extends HyperfCommand return true; return true; } } $info = $this->currentTableStructure; $info = $this->currentTableStructure; $tableComment = $info['table_comment'] ? $info['table_comment'] : $table; $tableComment = (isset($info['table_comment']) && $info['table_comment']) ? $info['table_comment'] : $table; $content .= "\n\t// " . $tableComment; $content .= "\n\t// " . $tableComment; $content .= "\n\tRouter::addGroup('" . $group . "', function () {"; $content .= "\n\tRouter::addGroup('" . $group . "', function () {"; $content .= "\n\t\tRouter::get('', 'App\Controller\\" . $modelClass . "Controller@index');"; $content .= "\n\t\tRouter::get('', 'App\Controller\\" . $modelClass . "Controller@index');"; Loading Loading @@ -1192,7 +1196,7 @@ class MakeModelCommand extends HyperfCommand } } $attributes = implode("\n", $attributes); $attributes = implode("\n", $attributes); $tableComment = ""; $tableComment = ""; if ($info['table_comment']) { if (isset($info['table_comment']) && $info['table_comment']) { $tableComment = 'Db::statement("alter table `' . $table . '` comment \'' . $info['table_comment'] . '\'");'; $tableComment = 'Db::statement("alter table `' . $table . '` comment \'' . $info['table_comment'] . '\'");'; } } $patterns = ["%ClassName%", '%tablename%', '%attributes%', '%tableComment%']; $patterns = ["%ClassName%", '%tablename%', '%attributes%', '%tableComment%']; Loading Loading
src/Command/MakeModelCommand.php +8 −4 Original line number Original line Diff line number Diff line Loading @@ -113,6 +113,10 @@ class MakeModelCommand extends HyperfCommand if ($v == 'migrations') { if ($v == 'migrations') { continue; continue; } } if (!$this->builder->hasTable($v)) { $this->info("表" . $v . "不存在!"); continue; } $this->tableIndex = $k; $this->tableIndex = $k; $this->input->setArgument("name", $v); $this->input->setArgument("name", $v); $this->table = $v; $this->table = $v; Loading Loading @@ -495,11 +499,11 @@ class MakeModelCommand extends HyperfCommand $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")) { $list .= "\t\t\tif(\$conditions['" . $v['column_name'] . "'] !== '') {\n"; $list .= "\t\t\tif(isset(\$conditions['" . $v['column_name'] . "']) && \$conditions['" . $v['column_name'] . "'] !== '') {\n"; $list .= "\t\t\t\t\$q->where('" . $v['column_name'] . "', \$conditions['" . $v['column_name'] . "']);\n"; $list .= "\t\t\t\t\$q->where('" . $v['column_name'] . "', \$conditions['" . $v['column_name'] . "']);\n"; $list .= "\t\t\t}\n"; $list .= "\t\t\t}\n"; } else if ($v['column_name'] == 'name' || Str::contains($v['column_name'], "_name")) { } else if ($v['column_name'] == 'name' || Str::contains($v['column_name'], "_name")) { $list .= "\t\t\tif(\$conditions['keyword'] !== '') {\n"; $list .= "\t\t\tif(isset(\$conditions['" . $v['column_name'] . "']) && \$conditions['keyword'] !== '') {\n"; $list .= "\t\t\t\t\$q->where('" . $v['column_name'] . "', \$conditions['keyword']);\n"; $list .= "\t\t\t\t\$q->where('" . $v['column_name'] . "', \$conditions['keyword']);\n"; $list .= "\t\t\t}\n"; $list .= "\t\t\t}\n"; } } Loading Loading @@ -668,7 +672,7 @@ class MakeModelCommand extends HyperfCommand return true; return true; } } $info = $this->currentTableStructure; $info = $this->currentTableStructure; $tableComment = $info['table_comment'] ? $info['table_comment'] : $table; $tableComment = (isset($info['table_comment']) && $info['table_comment']) ? $info['table_comment'] : $table; $content .= "\n\t// " . $tableComment; $content .= "\n\t// " . $tableComment; $content .= "\n\tRouter::addGroup('" . $group . "', function () {"; $content .= "\n\tRouter::addGroup('" . $group . "', function () {"; $content .= "\n\t\tRouter::get('', 'App\Controller\\" . $modelClass . "Controller@index');"; $content .= "\n\t\tRouter::get('', 'App\Controller\\" . $modelClass . "Controller@index');"; Loading Loading @@ -1192,7 +1196,7 @@ class MakeModelCommand extends HyperfCommand } } $attributes = implode("\n", $attributes); $attributes = implode("\n", $attributes); $tableComment = ""; $tableComment = ""; if ($info['table_comment']) { if (isset($info['table_comment']) && $info['table_comment']) { $tableComment = 'Db::statement("alter table `' . $table . '` comment \'' . $info['table_comment'] . '\'");'; $tableComment = 'Db::statement("alter table `' . $table . '` comment \'' . $info['table_comment'] . '\'");'; } } $patterns = ["%ClassName%", '%tablename%', '%attributes%', '%tableComment%']; $patterns = ["%ClassName%", '%tablename%', '%attributes%', '%tableComment%']; Loading