1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace manager\controllers;
- use Yii;
- class SpyController extends BaseController
- {
- const sleep = 60*5;
- const dead = 60*15;
- const kill = 60*25;
- const keylist = 'uactive';
- public function actionIndex()
- {
- return $this->redirect("news/list");
- }
- public function actionView()
- {
- $cache = Yii::$app->memcache;
- $user = Yii::$app->user->identity->profile->name;
- $id = Yii::$app->user->identity->profile->user_id;
- $mduser = $id;
- $uactive = $cache->get(self::keylist);
- $html = '';
- if( $uactive ){
- $uactive = unserialize($uactive);
- $html = $this->renderPartial('_item',['users'=>$uactive, 'obj'=>$this, 'id'=>$id]);
- }else{
- $html = '';
- }
- return $this->render("view", ['html'=>$html]);
- }
- public function actionAuthorping()
- {
- $cache = Yii::$app->memcache;
- $user = Yii::$app->user->identity->profile->name;
- $id = Yii::$app->user->identity->profile->user_id;
- $mduser = $id;
- $uactive = $cache->get(self::keylist);
- $html = '';
- if( $uactive ){
- $uactive = unserialize($uactive);
- $uactive[$mduser] = ['name'=>$user, 'time' => time(), 'id' => $id];
- $cache->set( self::keylist, serialize($uactive), self::dead );
- $a = [];
- foreach($uactive as $userid => $data){
- if( time()-$data['time'] < self::kill ){
- $a[$userid] = $data;
- }
- }
- $uactive = $a;
- $html = $this->renderPartial('list',['users'=>$uactive, 'obj'=>$this, 'id'=>$id]);
- }else{
- $uactive = [];
- $uactive[$mduser] = ['name'=>$user, 'time' => time(), 'id' => $id];
- $cache->add( self::keylist, serialize($uactive), self::dead );
- }
- return json_encode( ['status'=>'ok', 'html'=>$html, 'count' =>count($uactive)] );
- }
- }
|