adminInfo = get_login_admin(); $this->url=[ '/admin/nk.comment/index', '/admin/nk.comment/add', '/admin/nk.comment/edit', '/admin/nk.comment/del', '/admin/nk.comment/read', ]; // 获取用户信息 $this->users = Db::table('fa_szxc_information_usermsg')->where('status',1)->field('user_id,name')->select(); } /** * 数据列表 */ public function index() { if (request()->isAjax()) { $params= get_params(); // $where['status']=1; $where = []; if (isset($params['keywords'])){ // $where[]=['title','like','%'.$params['keywords'].'%']; } if($this->adminInfo['position_id'] != 1){ //不是超级管理员 $www['admin_id'] = $this->adminInfo['id']; $user_address = Db::table('fa_szxc_information_useraddress')->where($www)->find(); if ($user_address){ if($user_address['auth_range'] == 1){ $where['village'] = $user_address['village_id']; }elseif ($user_address['auth_range'] == 2){ $where['township'] = $user_address['street_id']; }elseif ($user_address['auth_range'] == 3){ $where['county'] = $user_address['area_id']; }else{ $where['village'] = $user_address['village_id']; } }else{ $where['village'] = ''; } } $total = Db::table('fa_article_comment') ->where($where) ->count(); $list = Db::table('fa_article_comment') ->withAttr('name',function ($value,$data){ return Db::table('fa_szxc_information_usermsg')->where('user_id',$data['user_id'])->value('name'); }) ->withAttr('street',function ($value,$data){ return Db::table('fa_geo_street')->where('street_code',$data['township'])->value('street_name'); }) ->withAttr('village',function ($value,$data){ return Db::table('fa_geo_village')->where('village_id',$data['village'])->value('village_name'); }) ->withAttr('status',function ($value,$data){ if($value == 1){ return '通过'; }elseif($value == 2){ return '不通过'; }else{ return '待审核'; } }) ->where($where) ->page($params['page']) ->limit($params['limit']) ->order('id desc') ->select(); $result = ['total' => $total, 'data' => $list]; return table_assign(0, '', $result); } else{ return view('nk/comment/index',['url'=>$this->url]); } } public function add(){ if (request()->isAjax()) { $param= get_params(); $adds=Db::table('fa_szxc_information_useraddress')->where('admin_id',$this->adminInfo['id'])->find(); $param['county']=$adds['area_id']; $param['township']=$adds['street_id']; $param['village']=$adds['village_id']; $res=Db::table('fa_article_comment')->strict(false)->field(true)->insertGetId($param); if ($res){ return to_assign(0,'操作成功',['aid'=>$res]); } return to_assign(1, '操作失败,原因:'.$res); }else{ $article = Db::table('fa_article')->where('status',1)->field('id,title')->select(); View::assign('editor', get_system_config('other','editor')); View::assign('users', $this->users); View::assign('article', $article); return view(); } } public function edit(){ $param= get_params(); if (request()->isAjax()) { $res=Db::table('fa_article_comment')->where('id',$param['id'])->strict(false)->field(true)->update($param); if ($res){ return to_assign(); }else{ return to_assign(1, '操作失败,原因:'.$res); } }else{ $id = isset($param['id']) ? $param['id'] : 0; $detail = Db::table('fa_article_comment')->where('id',$id)->find(); View::assign('editor', get_system_config('other','editor')); if (!empty($detail)) { View::assign('detail', $detail); View::assign('users', $this->users); $article = Db::table('fa_article')->where('status',1)->field('id,title')->select(); View::assign('article', $article); return view(); } else{ throw new \think\exception\HttpException(404, '找不到页面'); } } } /** * 查看信息 */ public function read() { $param= get_params(); $id = isset($param['id']) ? $param['id'] : 0; $detail = Db::table('fa_article_comment')->where('id',$id)->find(); if (!empty($detail)) { View::assign('detail', $detail); View::assign('users', $this->users); $article = Db::table('fa_article')->where('status',1)->field('id,title')->select(); View::assign('article', $article); return view(); } else{ throw new \think\exception\HttpException(404, '找不到页面'); } } /** * 删除 */ public function del() { $param= get_params(); $id = isset($param['id']) ? $param['id'] : 0; $type = isset($param['type']) ? $param['type'] : 0; $res = Db::table('fa_article_comment')->where('id',$id)->delete(); if ($res){ return to_assign(); }else{ return to_assign(1, '操作失败,原因:'.$res); } } }