field('id,username,mobile,email,last_login_ip,status,last_login_time') ->where('delete_time',0) ->where($map) ->select(); $count = $admins->count(); if($count){ $res = ['code'=>0,'msg'=>'','count'=>$count]; foreach($admins as $k => $v){ $data = ['id'=>$v['id'],'loginname'=>$v['username'],'telphone'=>$v['mobile'],'email'=>$v['email'],'ip'=>$v['last_login_ip'],'check'=>$v['status'],'logintime'=>date("Y-m-d",$v['last_login_time'])]; $res['data'][] = $data; } } else { $res = ['code'=>-1,'msg'=>'没有查询结果!']; } return json($res); } return View::fetch(); } //管理员审核 public function check() { $data = Request::param(); //获取状态 $res = Db::name('admin')->where('id',$data['id'])->save(['status' => $data['status']]); if($res){ if($data['status'] == 1){ return json(['code'=>0,'msg'=>'设置管理员通过','icon'=>6]); } else { return json(['code'=>0,'msg'=>'管理员已取消','icon'=>5]); } }else { return json(['code'=>-1,'msg'=>'审核出错']); } } //添加管理员 public function add() { if(Request::isAjax()){ $data = Request::param(); $data['create_time'] = time(); $salt = substr(md5($data['create_time']),-6); $data['password'] = substr_replace(md5($data['password']),$salt,0,6); //$adminId = Db::name('admin')->insertGetId($data); $admin = Db::name('admin')->save($data); //Db::name('auth_group_access')->insert(['uid'=>$adminId,'group_id'=>$data['auth_group_id']]); if($admin){ $res = ['code'=>0,'msg'=>'添加成功']; }else{ $res = ['code'=>-1,'msg'=>'添加失败']; } return json($res); } //$auth_group = Db::name('auth_group')->select(); //View::assign(['auth_group'=>$auth_group]); return View::fetch(); } //管理员编辑 public function edit($id) { $admin = AdminModel::find($id); if(Request::isAjax()){ $data = Request::param(); if(empty($data['password'])){ unset($data['password']); } else { $t = strtotime($admin['create_time']); $salt = substr(md5($t),-6); $data['password'] = md5(substr_replace(md5($data['password']),$salt,0,6)); } $data['update_time'] = time(); $result = $admin->update($data); //Db::name('auth_group_access')->where('uid',$data['id'])->update(['group_id'=>$data['auth_group_id']]); if($result){ $res = ['code'=>0,'msg'=>'编辑成功']; }else{ $res = ['code'=>-1,'msg'=>'编辑失败']; } return json($res); } //$auth_group = Db::name('auth_group')->select();,'auth_group'=>$auth_group View::assign(['admin'=>$admin]); return View::fetch(); } //删除管理员 public function delete($id) { if(Request::isAjax()){ $user =AdminModel::find($id); $result = $user->delete(); if($result){ return json(['code'=>0,'msg'=>'删除成功']); }else{ return json(['code'=>-1,'msg'=>'删除失败']); } } } //基本资料显示 public function info() { $admin = AdminModel::find(Session::get('admin_id')); View::assign('admin',$admin); return View::fetch('set/user/info'); } //管理员资料更新 public function infoSet() { $admin = AdminModel::find(Session::get('admin_id')); if(Request::isAjax()){ $data = Request::only(['nickname','sex','mobile','email','remarks']); $result = $admin->save($data); if($result){ $res = ['code'=>0,'msg'=>'更新成功']; } else { $res = ['code'=>-1,'msg'=>'更新失败']; } return json($res); } } //显示改密码页面 public function repass() { $admin = AdminModel::find(Session::get('admin_id')); View::assign('admin',$admin); return View::fetch('set/user/repass'); } //密码重设 public function repassSet() { $admin = AdminModel::find(Session::get('admin_id')); if(Request::isAjax()){ $data = Request::param(); $salt = substr(md5(strtotime($admin['create_time'])),-6); $pwd = substr_replace(md5($data['oldPassword']),$salt,0,6); $data['oldPassword'] = md5($pwd); if($admin['password'] != $data['oldPassword']){ return json(['code'=>-1,'msg'=>'当前密码错误']); } elseif($data['password'] != $data['repassword']){ return json(['code'=>-1,'msg'=>'两次密码不一致']); } else { $password = md5(substr_replace(md5($data['password']),$salt,0,6)); $result = $admin->update([ 'id' => $admin['id'], 'password' => $password ]); if($result){ $res = ['code'=>0,'msg'=>'更新成功']; } else { $res = ['code'=>-1,'msg'=>'更新失败']; } return json($res); } } } //清除缓存Cache public function clearCache(){ //$atemp = app()->getRootPath().'runtime/admin/temp/'; //$itemp = app()->getRootPath().'runtime/index/temp/'; //$cache = app()->getRootPath().'runtime/cache/'; $atemp = str_replace('\\',"/",app()->getRootPath().'runtime/admin/temp/'); $itemp = str_replace('\\',"/",app()->getRootPath().'runtime/index/temp/'); $cache = str_replace('\\',"/",app()->getRootPath().'runtime/cache/'); Files::delDirAndFile($atemp); Files::delDirAndFile($itemp); if(is_dir($cache) && Files::delDirAndFile($cache)){ return json(['code'=>0,'msg'=>'清除缓存成功']); } else { return json(['code'=>-1,'msg'=>'清除缓存失败']); } } //退出登陆 public function logout() { Session::clear(); $res = ['code'=>0,'msg'=>'退出成功' ]; return json($res); } }