no message

This commit is contained in:
hajimi
2026-06-11 12:15:29 +08:00
parent 10ebe39c30
commit 96efa1d905
5859 changed files with 815501 additions and 5 deletions
@@ -0,0 +1,65 @@
<?php
namespace app\common\command;
use app\common\model\user\User;
use app\common\model\SmsLog;
use think\console\Command;
use think\console\Input;
use think\console\Output;
/**
* 短信验证定时任务
* 轮询有手机号但未验证(is_bind_mobile=0)的用户,
* 从 la_sms_upload 反向校验是否有该手机号的任意上传记录,
* 若匹配则标记 is_bind_mobile=1
*/
class SmsVerifyCommand extends Command
{
protected function configure()
{
$this->setName('sms_verify')
->setDescription('轮询未验证手机号用户,从上传记录反向校验并更新绑定状态');
}
protected function execute(Input $input, Output $output)
{
$users = User::where('mobile', '<>', '')
->where('is_bind_mobile', 0)
->field('id, mobile')
->select();
if ($users->isEmpty()) {
$output->writeln('<info>[SmsVerify] 无待验证用户</info>');
return;
}
$output->writeln('<info>[SmsVerify] 待验证用户: ' . $users->count() . '</info>');
$updated = 0;
foreach ($users as $user) {
$mobile = $user->mobile;
// 查询 la_sms_upload 是否有该手机号的任意上传记录(兼容+86前缀)
$record = SmsLog::where(function ($query) use ($mobile) {
$query->where('phone', $mobile)
->whereOr('phone', '+86' . $mobile)
->whereOr('phone', '86' . $mobile);
})
->order('sms_time', 'desc')
->findOrEmpty();
if (!$record->isEmpty()) {
if ((int)$record->status === 0) {
$record->status = 1;
$record->save();
}
User::where('id', $user->id)->update(['is_bind_mobile' => 1]);
$updated++;
$output->writeln("<info> ✓ 用户 {$user->id} ({$mobile}) 已验证</info>");
}
}
$output->writeln("<info>[SmsVerify] 完成,更新 {$updated} 个用户</info>");
}
}