Commit ee580351 authored by 王源's avatar 王源 🎧

优化

parent b2cd81d1
...@@ -6,11 +6,11 @@ namespace Meibuyu\Micro\Command; ...@@ -6,11 +6,11 @@ namespace Meibuyu\Micro\Command;
use Hyperf\Command\Annotation\Command; use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand; use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Contract\ContainerInterface;
use Hyperf\Database\ConnectionResolverInterface; use Hyperf\Database\ConnectionResolverInterface;
use Hyperf\Database\Schema\MySqlBuilder; use Hyperf\Database\Schema\MySqlBuilder;
use Hyperf\DbConnection\Db; use Hyperf\DbConnection\Db;
use Hyperf\Utils\Str; use Hyperf\Utils\Str;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
...@@ -678,7 +678,7 @@ class MakeModelCommand extends HyperfCommand ...@@ -678,7 +678,7 @@ class MakeModelCommand extends HyperfCommand
$content .= "\n\t\tRouter::delete('/{id}', 'App\Controller\\" . $modelClass . "Controller@delete');"; $content .= "\n\t\tRouter::delete('/{id}', 'App\Controller\\" . $modelClass . "Controller@delete');";
if ($routes) { if ($routes) {
foreach ($routes as $v) { foreach ($routes as $v) {
$content .= "\n\t\tRouter::get('/$r/\{id\}', 'App\Controller\\" . $modelClass . "Controller@$v');"; $content .= "\n\t\tRouter::get('/$v/\{id\}', 'App\Controller\\" . $modelClass . "Controller@$v');";
} }
} }
$content .= "\n\t});"; $content .= "\n\t});";
...@@ -721,7 +721,7 @@ class MakeModelCommand extends HyperfCommand ...@@ -721,7 +721,7 @@ class MakeModelCommand extends HyperfCommand
$rs = []; $rs = [];
$required = "nullable"; $required = "nullable";
if ($null !== 'YES') { if ($null !== 'YES') {
if ($default !== '') { if ($default !== '' && $default !== '0' && !$default) {
$required = "required"; $required = "required";
$messages[] = "\t\t'{$name}.{$required}' => '{$msgName}不能为空!'"; $messages[] = "\t\t'{$name}.{$required}' => '{$msgName}不能为空!'";
} }
...@@ -872,7 +872,8 @@ class MakeModelCommand extends HyperfCommand ...@@ -872,7 +872,8 @@ class MakeModelCommand extends HyperfCommand
$n = ((isset($length[0]) && $length[0] && $length[0] < $maxNumber) ? $length[0] : $maxNumber); $n = ((isset($length[0]) && $length[0] && $length[0] < $maxNumber) ? $length[0] : $maxNumber);
$n = rand(1, $n); $n = rand(1, $n);
$n2 = ((isset($length[1]) && $length[1] < $maxNumber) ? $length[1] : 2); $n2 = ((isset($length[1]) && $length[1] < $maxNumber) ? $length[1] : 2);
$fields[] = "\t\t\t\t'{$name}' => \$faker->randomFloat($n,$n2),"; $n3 = $n2 + 20;
$fields[] = "\t\t\t\t'{$name}' => \$faker->randomFloat($n,$n2,$n3),";
break; break;
case "char": case "char":
case "varchar": case "varchar":
...@@ -1136,7 +1137,7 @@ class MakeModelCommand extends HyperfCommand ...@@ -1136,7 +1137,7 @@ class MakeModelCommand extends HyperfCommand
if ($null == 'YES') { if ($null == 'YES') {
$t .= "->nullable()"; $t .= "->nullable()";
} }
if ($default !== '') { if (($default && $default !== '') || $default === '0') {
$t .= "->default('$default')"; $t .= "->default('$default')";
} }
if ($collation) { if ($collation) {
......
...@@ -17,7 +17,7 @@ class %className% extends Seeder ...@@ -17,7 +17,7 @@ class %className% extends Seeder
public function run() public function run()
{ {
$faker = Factory::create('zh-CN'); $faker = Factory::create('zh-CN');
%modelClass%::truncate(); %modelClass%::query()->truncate();
$n = %generateCount%; $n = %generateCount%;
for ($i = 0; $i < $n; $i++) { for ($i = 0; $i < $n; $i++) {
$instance = %modelClass%::create([ $instance = %modelClass%::create([
......
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