<?php
/**
 * Created by PhpStorm.
 * User: chouchou
 * Date: 2019-6-10
 * Time: 19:33
 */

namespace app\admin\controller;

use think\Controller;
use think\Request;
use think\db;
class Log extends  Base 
{
       public function loginlog_list(Request $request){
       			$map=[];
			    $search_text = $request->get('search_text');
			    $search_type = $request->get('search_type'); 
			    if($search_text){
		        switch ($search_type) {
		        	case '1':
		          $map[]=['name','like',"%$search_text%"];;
		          $this->assign('search_text',$search_text);
		          $this->assign('search_type',$search_type);
		        		break;
		          	case '2':
		          $map[]=['ip','like',"%$search_text%"];;
		          $this->assign('search_text',$search_text);
		          $this->assign('search_type',$search_type);
		        		break;
		        }
			   }else{
			   	  $this->assign('search_type','');
			   	  $this->assign('search_text','');
			   }
				$page = $request->get('page')?$request->get('page'):1;
				$limit = $request->get('limit')?$request->get('limit'):10;
				if(empty($request->get('page'))){
                   $page_s=0;
				}else{
					$page_s=(($page-1)*$limit);
				}
        
				$loginlog=db::name('loginlog')->field('*,FROM_UNIXTIME(create_time, "%Y-%m-%d %H:%i:%s") as create_time')->where($map)->limit($page_s,$limit)->select();
				$loginlogcnt=db::name('loginlog')->where($map)->count();
				if($request->get('page')){
	
				return ['code'=>0,'msg'=>'','count'=>$loginlogcnt,'data'=>$loginlog];
				}
				 return $this->fetch('loginlog_list'); 
       }
       public function clouldlog_list(Request $request){
			$page = $request->get('page')?$request->get('page'):1;
			$limit = $request->get('limit')?$request->get('limit'):10;
			if(empty($request->get('page'))){
			$page_s=0;
			}else{
			$page_s=(($page-1)*$limit);
			}

			$cloudlog=db::name('cloudlog')->field('*,FROM_UNIXTIME(create_time, "%Y-%m-%d %H:%i:%s") as create_time')->limit($page_s,$limit)->select();
			foreach ($cloudlog as $key => $value) {
			$cloudlog[$key]['content']=json_decode($value['content'],true);
			$cloudlog[$key]['content']=$cloudlog[$key]['content']['info'];
			}
			$cloudlogcnt=db::name('cloudlog')->count();
			if($request->get('page')){

			return ['code'=>0,'msg'=>'','count'=>$cloudlogcnt,'data'=>$cloudlog];
			}
       	 return $this->fetch('clouldlog_list'); 
       }

       
          public function activity_log(Request $request){
          	$map=[];
			    $search_text = $request->get('search_text');
			    $search_type = $request->get('search_type'); 
			    if($search_text){
		        switch ($search_type) {
		        	case '1':
		          $map[]=['name','like',"%$search_text%"];;
		          $this->assign('search_text',$search_text);
		          $this->assign('search_type',$search_type);
		        		break;
		        }
			   }else{
			   	  $this->assign('search_type','');
			   	  $this->assign('search_text','');
			   }
			$page = $request->get('page')?$request->get('page'):1;
			$limit = $request->get('limit')?$request->get('limit'):10;
			if(empty($request->get('page'))){
			$page_s=0;
			}else{
			$page_s=(($page-1)*$limit);
			}

			$activity_log=db::name('activity_log')->field('*,FROM_UNIXTIME(create_time, "%Y-%m-%d %H:%i:%s") as create_time')->where($map)->limit($page_s,$limit)->select();
			foreach ($activity_log as $key => $value) {
			$activity_log[$key]['description']=json_decode($value['description'],true);
			}
			$activity_logcnt=db::name('activity_log')->where($map)->count();
			if($request->get('page')){

			return ['code'=>0,'msg'=>'','count'=>$activity_logcnt,'data'=>$activity_log];
			}
       	 return $this->fetch('activitylog_list'); 
       }
}