2026-02-15 19:41:56 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\command;
|
|
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
use support\think\Db;
|
|
|
|
|
use isszz\hashids\facade\Hashids;
|
|
|
|
|
use function GuzzleHttp\json_encode;
|
|
|
|
|
|
|
|
|
|
class User extends Command
|
|
|
|
|
{
|
|
|
|
|
protected static $defaultName = 'User';
|
|
|
|
|
protected static $defaultDescription = '用户';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function configure()
|
|
|
|
|
{
|
2026-04-04 08:52:59 +08:00
|
|
|
$this->addOption('user_id','u', InputOption::VALUE_OPTIONAL, 'user_id');
|
|
|
|
|
$this->addOption('action','a', InputOption::VALUE_OPTIONAL, '操作类型','test');
|
2026-02-15 19:41:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param InputInterface $input
|
|
|
|
|
* @param OutputInterface $output
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
|
{
|
2026-03-25 02:48:30 +08:00
|
|
|
$action = $input->getOption('action');
|
|
|
|
|
if(method_exists($this, $action)){
|
|
|
|
|
return $this->$action($input, $output);
|
|
|
|
|
}
|
|
|
|
|
cp('操作不存在:'.$action);
|
|
|
|
|
return 0;
|
2026-04-04 08:52:59 +08:00
|
|
|
}
|
|
|
|
|
function test(InputInterface $input, OutputInterface $output)
|
|
|
|
|
{
|
|
|
|
|
$user_id = 104864;
|
|
|
|
|
$_user = Db::name('user')->where('id',$user_id)->find();
|
|
|
|
|
Db::query('delete FROM `wa_user_team` WHERE descendant_id='.$user_id.' or ancestor_id='.$user_id.';');
|
|
|
|
|
Hook('user.register_successed',$_user);
|
|
|
|
|
//管理团队人数
|
|
|
|
|
// $team_user_ids = Db::name('user_team')->where('descendant_id',$_user['id'])
|
|
|
|
|
// ->where('depth','>',0)
|
|
|
|
|
// ->order('depth','ASC')
|
|
|
|
|
// ->column('ancestor_id');
|
2026-03-25 02:48:30 +08:00
|
|
|
|
2026-04-04 08:52:59 +08:00
|
|
|
// Db::name('user_extend')->whereIn('user_id',$team_user_ids)->data([
|
|
|
|
|
// 'team_total'=> Db::raw('team_total+1')
|
|
|
|
|
// ])->save();
|
|
|
|
|
// $list = Db::name('user_extend')->whereIn('user_id',$team_user_ids)->field('user_id,team_total')->select();
|
|
|
|
|
// foreach($list as $v){
|
|
|
|
|
// cache('team_user_count_'.$v['user_id'],$v['team_total']);
|
|
|
|
|
// }
|
|
|
|
|
// cp($team_user_ids);
|
|
|
|
|
return 0;
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
|
|
|
|
function login(InputInterface $input, OutputInterface $output){
|
|
|
|
|
// $IM = new \support\OpenImSdk\Client([
|
|
|
|
|
// 'host' => 'http://127.0.0.1:10002', // OpenIM API地址
|
|
|
|
|
// 'secret' => 'n1e5a6s6m7', // OpenIM密钥
|
|
|
|
|
// ]);
|
|
|
|
|
$user_id = $input->getOption('user_id');
|
|
|
|
|
if(!$user_id){
|
|
|
|
|
return false;
|
2026-02-15 19:41:56 +08:00
|
|
|
}
|
2026-03-25 02:48:30 +08:00
|
|
|
$user = \support\Jwt::direct($user_id);
|
|
|
|
|
//$imToken = $IM->auth->getUserToken($user['userID'],2);
|
|
|
|
|
cp('userID:' . $user['id']);
|
|
|
|
|
cp('nickname:' . $user['nickname']);
|
|
|
|
|
cp('token:' . $user['token']);
|
|
|
|
|
//cp('imToken:' . $imToken['token']);
|
2026-02-15 19:41:56 +08:00
|
|
|
return 0;
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:10:44 +08:00
|
|
|
function otop(InputInterface $input, OutputInterface $output){
|
|
|
|
|
$user_id = $input->getOption('user_id');
|
|
|
|
|
if(!$user_id){
|
|
|
|
|
return false;
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:10:44 +08:00
|
|
|
/**
|
|
|
|
|
* @var \plugin\admin\app\model\Admin $admin
|
|
|
|
|
*/
|
|
|
|
|
$admin = \plugin\admin\app\model\Admin::where('id',$user_id)->find();
|
|
|
|
|
if(!$admin){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$totp = \OTPHP\TOTP::create($admin->totp_secret);
|
|
|
|
|
cp($totp->now());
|
|
|
|
|
return 1;
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:10:44 +08:00
|
|
|
function build_team(){
|
|
|
|
|
Db::name('user_team')->where('ancestor_id','>',0)->delete();
|
|
|
|
|
$list = Db::name('user')->field('id,parent_id')->order('id','asc')->select();
|
|
|
|
|
foreach($list as $k=>$user){
|
|
|
|
|
build_user_team($user);
|
|
|
|
|
cp('user_id:'.$user['id']);
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:10:44 +08:00
|
|
|
return 0;
|
2026-02-15 19:41:56 +08:00
|
|
|
}
|
|
|
|
|
}
|