19
This commit is contained in:
+68
-18
@@ -32,26 +32,76 @@ class User extends Command
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$action = $input->getOption('action','login');
|
||||
if($action == 'login'){
|
||||
$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;
|
||||
$action = $input->getOption('action');
|
||||
if(method_exists($this, $action)){
|
||||
return $this->$action($input, $output);
|
||||
}
|
||||
cp('action not exist');
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user