| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Titan 名字就是密码
- * Date: 2019/4/25
- * Time: 18:03
- * 权限管理
- */
- namespace app\admin\controller;
- use think\Controller;
- use think\Db;
- use think\Request;
- class AuthortyManage extends Controller
- {
- /**
- * 管理员首页
- * @return mixed
- */
- public function index()
- {
- $admin = Db::name('admin')->select();
- $this->assign('admin',$admin);
- return $this->fetch();
- }
- /**
- * 增加管理员
- * @param Request $request
- * @return bool|mixed
- */
- public function addAdmin(Request $request)
- {
- if($request->isPost() && $request->isAjax()){
- $data = $request->param();
- $data['user_nickname'] = '管理员';
- $data['create_time'] = time();
- $data['password'] = md5($data['password']);
- $authority = '';
- //管理组
- foreach ($data['authority'] as $key=>$v){
- $authority .= $v .",";
- }
- $data['authority'] = substr($authority,0,-1);
- unset($data['repass']);
- $name = Db::name('admin')->where('username',$data['username'])->find();
- $openid = Db::name('admin')->where('openid',$data['openid'])->find();
- if($name){
- echo json_encode(['status'=>0,'message'=>'登录名重复'],JSON_UNESCAPED_UNICODE);
- exit;
- }
- if($openid){
- echo json_encode(['status'=>0,'message'=>'此微信已绑定,不能重复绑定'],JSON_UNESCAPED_UNICODE);
- exit;
- }
- $insert = Db::name('admin')->insert($data);
- if($insert){
- echo json_encode(['status'=>1,'message'=>'增加成功'],JSON_UNESCAPED_UNICODE);
- exit;
- }
- echo json_encode(['status'=>0,'message'=>'增加失败'],JSON_UNESCAPED_UNICODE);
- }else{
- $this->assign('adminGroup',$this->getGroup());
- $this->assign('admin',$this->admin());
- return $this->fetch();
- }
- }
- public function admin()
- {
- $admin = Db::name('user')->where(['identity'=>99,'is_register'=>1,'is_check'=>1])->field(['openid','headimgurl','nickname','username'])->select();
- return $admin;
- }
- /**
- * 删除管理员
- * @param Request $request
- */
- public function del(Request $request)
- {
- $id = $request->param('id');
- $result = Db::name('admin')->delete($id);
- if($result){
- header('Location: /admin/authorty_manage/index');
- exit;
- }
- }
- /**
- * 获取所有组
- * @return false|\PDOStatement|string|\think\Collection
- */
- public function getGroup()
- {
- $adminGroup = Db::name('group')->select();
- return $adminGroup;
- }
- /**
- * 查看管理员
- * @param Request $request
- * @return mixed
- */
- public function view(Request $request)
- {
- $id = $request->param('adminId');
- $data = Db::name('admin')->where('id',$id)->find();
- $this->assign('data',$data);
- $this->assign('adminGroup',$this->getGroup());
- return $this->fetch();
- }
- /**
- * 编辑管理员
- * @param Request $request
- * @return bool|mixed
- */
- public function editAdmin(Request $request)
- {
- if($request->isGet()){
- $id = $request->param('adminId');
- $data = Db::name('admin')->where('id',$id)->find();
- $this->assign('data',$data);
- $this->assign('adminGroup',$this->getGroup());
- return $this->fetch();
- }else{
- $id = $request->param('id');
- $data = $request->param();
- $authority = '';
- foreach ($data['authority'] as $key=>$v){
- $authority .= $v .",";
- }
- $data['authority'] = substr($authority,0,-1);
- $result = Db::name('admin')->where('id',$id)->update($data);
- return true;
- }
- }
- }
|