This commit is contained in:
2026-01-05 14:33:21 +08:00
commit ee348b4925
451 changed files with 39954 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace app\command;
use app\common\model\User;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class InitUserPasswordCommand extends Command
{
protected static $defaultName = 'init:user-password';
protected static $defaultDescription = '初始化user表密码,如果密码为空则用sn加密后写入password字段';
protected function execute(InputInterface $input, OutputInterface $output): int
{
$users = User::whereNull('password')->orWhere('password', '')->get();
$count = 0;
foreach ($users as $user) {
if (!empty($user->sn)) {
$user->password = password_hash($user->sn, PASSWORD_DEFAULT);
$user->save();
$output->writeln("用户ID {$user->id} 密码已初始化");
$count++;
} else {
$output->writeln("<error>用户ID {$user->id} 的sn字段为空,无法初始化密码</error>");
}
}
$output->writeln("共初始化 {$count} 个用户密码");
return self::SUCCESS;
}
}