108 lines
3.5 KiB
PHP
Executable File
108 lines
3.5 KiB
PHP
Executable File
<?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()
|
|
{
|
|
$this->addOption('user_id','u', InputArgument::OPTIONAL, 'user_id');
|
|
$this->addOption('action','a', InputArgument::OPTIONAL, '操作类型');
|
|
}
|
|
|
|
/**
|
|
* @param InputInterface $input
|
|
* @param OutputInterface $output
|
|
* @return int
|
|
*/
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$action = $input->getOption('action');
|
|
if(method_exists($this, $action)){
|
|
return $this->$action($input, $output);
|
|
}
|
|
cp('操作不存在:'.$action);
|
|
return 0;
|
|
|
|
}
|
|
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;
|
|
}
|
|
$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']);
|
|
return 0;
|
|
}
|
|
function build_team(InputInterface $input, OutputInterface $output){
|
|
$list = Db::name('user')->field('id')->order('id','asc')->select();
|
|
foreach($list as $k=>$user){
|
|
//team_total
|
|
$team_user_ids = Db::name('user_team')->where('descendant_id',$user['id'])
|
|
->where('depth','>',0)
|
|
->order('depth','ASC')
|
|
->column('ancestor_id');
|
|
Db::name('user_extend')->where('user_id',$user['id'])->data([
|
|
'team_total'=> count($team_user_ids)
|
|
])->save();
|
|
cache('team_user_count_'.$user['id'],count($team_user_ids));
|
|
|
|
$direct_use_count = Db::name('user')->where('parent_id',$user['id'])->count('id');
|
|
$vip_user_count = Db::name('user')->whereIn('id',$team_user_ids)->where('role_id','>',0)->count('id');
|
|
|
|
Db::name('user_extend')->where('user_id',$user['id'])->data([
|
|
'direct_total'=> $direct_use_count,
|
|
'vip_total'=> $vip_user_count
|
|
])->save();
|
|
cache('team_direct_total_'.$user['id'],$direct_use_count);
|
|
cache('team_vip_total_'.$user['id'],$vip_user_count);
|
|
$this->level_up($user['id'],$vip_user_count);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
protected function level_up($user_id,$count=0){
|
|
$levels = [
|
|
0,
|
|
500,
|
|
1000,
|
|
5000,
|
|
10000,
|
|
20000,
|
|
];
|
|
$level = 0;
|
|
foreach($levels as $k=>$v){
|
|
if($count>=$v){
|
|
$level= $k;
|
|
}else{
|
|
break;
|
|
}
|
|
}
|
|
Db::name('user')->where('id',$user_id)->data(['level'=>$level])->save();
|
|
|
|
}
|
|
}
|