123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <?php
- namespace app\admin\controller;
- use think\Session;
- use think\Cache;
- use think\Request;
- use app\admin\model\LogModel;
- use app\admin\model\IndexModel;
- class Index extends Base
- {
- public function server(){//运行环境
- $info = array(
- '操作系统'=>PHP_OS,
- '运行环境'=>$_SERVER["SERVER_SOFTWARE"],
- 'PHP运行方式'=>php_sapi_name(),
- '上传附件限制'=>ini_get('upload_max_filesize'),
- '执行时间限制'=>ini_get('max_execution_time').'秒',
- '服务器时间'=>date("Y年n月j日 H:i:s"),
- '北京时间'=>gmdate("Y年n月j日 H:i:s",time()+8*3600),
- 'ThinkPHP版本'=>THINK_VERSION,
- );
- //登录次数echarts统计图-----------------------------------------
- $today = date('Y-m-d');
- //取当前时间的前十四天
- $date = [];
- $date_string = '';
- for ($i=9; $i >0 ; $i--) {
- $date[] = date("Y-m-d",strtotime("-{$i} day"));
- $date_string.= date("Y-m-d",strtotime("-{$i} day")) . ',';
- }
- $date[] = $today;
- $date_string.= $today;
- $web['date_string'] = $date_string;
- $login_sum = '';
- foreach ($date as $k => $val) {
- $min_time = strtotime($val);
- $max_time = $min_time + 60*60*24;
- $where['create_time'] = [['>=',$min_time],['<=',$max_time]];
- // dump($where);die;
- $where['remark']= "登录操作";
- $login_sum.= db('user_log')->where($where)->count() . ',';
- }
- $web['login_sum'] = $login_sum;
- //end--------------------------------------------------------
- $this->assign('web',$web);
- $this->assign('info',$info);
- return view();
- }
- public function clears(){//清楚缓存
- Cache::clear();
- $this->success('index/lst');
- }
- public function lst_data(Request $request){//用户列表json数据动态表格显示(分页)
- $user = new IndexModel();
- $uname = request()->param('uname');//接收请求数据id
- $where='1=1';
- if(!empty($uname)){//不为空执行搜索条件,为空则跳过判断条件直接显示列表页,
- $where = ['uname'=>$uname];
- }
- //数据表获取总记录数
- $count = $user->where($where)->count();
- //获取每页显示的条数
- $limit= $request->param('limit');
- //获取当前页码
- $page= $request->param('page');
- //limit的起始位置
- $start=($page-1)*$limit;
- // 查询出当前页数显示的数据
- $list = $user//关联查询
- ->limit("$start,$limit")
- ->where($where)
- ->select();
- foreach($list as $k=>$v){ /*循环时间戳转时间格式*/
- $list[$k]['last_login_time'] = date('Y-m-d H:i:s',$v['last_login_time']);
- }
- //返回数据
- return ["code"=>0,"msg"=>"成功","count"=>$count,"data"=>$list];
- }
-
- public function lst()//用户列表
- {
- return view();
-
-
- }
- public function edit(){//用户信息编辑
- $user = new IndexModel();
- $id = input('id');
- $db = db('user')->where('id',$id)->find();
- if(request()->isPost()){
- $data['id'] = $id;
- $data['uname'] = input('uname');
- $data['upass'] =input('upass');
- if(empty($data['upass'])){
- $data['upass']=$db['upass'];
- $edit = $user->where('id',$id)->update($data);
- if($edit){
- return 1;
- }else{
- return 2;
- }
- }else{
- $data['upass']=md5(input('upass'));
- $edit = $user->where('id',$id)->update($data);
- if($edit){
- return 1;
- }else{
- return 2;
- }
- }
- }
-
- $this->assign([
- 'db'=>$db,//本身id
- ]);
- return view();
- }
-
- public function add(){//添加
- $user = new IndexModel();
- if(request()->isPost()){
- $data['uname'] = input('uname');
- $data['upass'] = input('upass');
- $list = $user->where('uname',trim($data['uname']))->select();
- if(empty($list)){
- $data['upass']=md5(trim($data['upass']));
- if($user->save($data)){
- return 1;
- }else{
- return 2;
- }
- }else{
- return 2;
- }
- }
-
- return view();
-
- }
-
- public function del(){//删除
- $user = new IndexModel();
- $id = input('id');
- $where = [
- 'id'=>$id,
- ];
- if($id==1){
- return 3;//超级管理员不允许删除
- }
- $list = $user->where($where)->delete();
- if($list){
- return 1;
- }else{
- return 2;
- }
- }
- public function pdel(){//批量删除
- $user = new IndexModel();
- if(request()->isPost()){
- $id = input('post.');
- $ids = implode(',',$id);
- $where = [
- 'id'=>['in',$ids],
- ];
- $list = $user->where($where)->delete();
- if($list){
- return 1;
- }else{
- return 2;//删除失败
- }
- }
- }
- public function log_data(Request $request)//日志记录列表接口
- {
- $user = new LogModel();
- // $data = $user->select();
- //数据表获取总记录数
- $count = $user->count();
- //获取每页显示的条数
- $limit= $request->param('limit');
- //获取当前页码
- $page= $request->param('page');
- //limit的起始位置
- $start=($page-1)*$limit;
- // 查询出当前页数显示的数据
- $list = $user
- ->limit("$start,$limit")
- ->select();
- //返回数据
- return ["code"=>0,"msg"=>"成功","count"=>$count,"data"=>$list];
- }
- public function log()//日志记录列表
- {
-
- return view();
- }
- public function truncate()//一键清除日志记录
- {
- if(request()->isPost()){
- $trun = db()->query('TRUNCATE ' . config('database.prefix') . 'user_log');
- return 1;//删除成功
- }else{
- return 2;//为空或者没有权限
- }
-
- }
-
- }
|