adminInfo = get_login_admin(); } public function index($params) { $where[]= ['status','=',1]; if (isset($params['keywords']) && !empty($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[]= ['county','=',$user_address['area_id']]; $where[] =['township','=', $user_address['street_id']]; $where[] =['village','=', $user_address['village_id']]; } elseif ($user_address['auth_range'] == 2) { $where[]= ['county','=',$user_address['area_id']]; $where[] =['township','=', $user_address['street_id']]; } } } $category_id =$params['category_id']; if($category_id){ $map[] = ['category_id','in',$category_id]; }else{ $map = []; } $total = Db::table('fa_article') ->where($where) ->where($map) ->count(); $list = Db::table('fa_article') ->withAttr('nickname',function ($value,$data){ return Db::table('fa_szxc_information_usermsg')->where('user_id',$data['user_id'])->value('name'); }) ->withAttr('area',function ($value,$data){ return Db::table('fa_geo_area')->where('area_code',$data['county'])->value('area_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'); }) ->where($where) ->where($map) ->page($params['page']) ->limit($params['limit']) ->order('id desc') ->field('id,title,user_id,content,county,township,village,image,view_time') ->select(); $result = ['total' => $total, 'data' => $list]; return table_assign(0, '', $result); } public function add($param){ // 检验完整性 try { validate(\app\admin\validate\nk\ArticleValidate::class)->check($param); } catch (ValidateException $e) { // 验证失败 输出错误信息 return to_assign(1, $e->getError()); } $adds=Db::table('fa_szxc_information_useraddress')->where('admin_id',$this->adminInfo['id'])->find(); if($this->adminInfo['position_id'] != 1) { //不是超级管理员 $param['county']=$adds['area_id']; $param['township']=$adds['street_id']; $param['village']=$adds['village_id']; $param['user_id']=$adds['user_id']; }else{ if(empty($param['county'])){ $param['county']=$adds['area_id']; } if(empty($param['township'])){ $param['township']=$adds['street_id']; } if(empty($param['village'])){ $param['village']=$adds['village_id']; } if(empty($param['user_id'])){ $param['user_id']=$adds['user_id']; } } $param['view_time']=date('Y-m-d H:i:s'); if(empty($param['category_type'])){ $param['category_type'] = 0; } if(empty($param['end_time'])){ $param['end_time'] = date('Y-m-d H:i:s'); } $res=Db::table('fa_article')->strict(false)->field(true)->insertGetId($param); if ($res){ if(!empty($param['is_vote']) && $param['is_vote']==1){ $data=['start_time'=>date('Y-m-d H:i:s'),'end_time'=>$param['end_time'],'article_id'=>$res,'county'=>$adds['area_id'],'township'=>$adds['street_id'],'village'=>$adds['village_id']]; Db::table('fa_article_vote_side_tables')->insert($data); } return to_assign(0,'操作成功',['aid'=>$res]); } return to_assign(1, '操作失败,原因:'.$res); } public function edit($param){ if (request()->isAjax()) { try { validate(\app\admin\validate\nk\ArticleValidate::class)->check($param); } catch (ValidateException $e) { // 验证失败 输出错误信息 return to_assign(1, $e->getError()); } $adds=Db::table('fa_szxc_information_useraddress')->where('admin_id',$this->adminInfo['id'])->find(); if($this->adminInfo['position_id'] == 1) { //是超级管理员 if(empty($param['county'])){ $param['county']=$adds['area_id']; } if(empty($param['township'])){ $param['township']=$adds['street_id']; } if(empty($param['village'])){ $param['village']=$adds['village_id']; } if(empty($param['user_id'])){ $param['user_id']=$adds['user_id']; } } $res=Db::table('fa_article')->where('id',$param['id'])->strict(false)->field(true)->update($param); if ($res){ if(!empty($param['is_vote']) && $param['is_vote']==1){ Db::table('fa_article_vote_side_tables')->where('article_id',$param['id'])->update(['end_time'=>$param['end_time']]); } return to_assign(); }else{ return to_assign(1, '操作失败,原因:'.$res); } }else{ $id = isset($param['id']) ? $param['id'] : 0; $detail = Db::table('fa_article')->where('id',$id)->find(); View::assign('editor', get_system_config('other','editor')); if (!empty($detail)) { View::assign('detail', $detail); // 获取用户信息 $this->users = Db::table('fa_szxc_information_usermsg')->where('status',1)->field('user_id,name')->select(); View::assign('users', $this->users); $street = Db::table('fa_geo_area')->where(['switch' => 1, 'city_code' => '510500']) ->field('area_id id,area_code code,area_name name') ->select(); View::assign('street', $street); } else{ throw new \think\exception\HttpException(404, '找不到页面'); } } } /** * 查看信息 */ public function read($param) { $id = isset($param['id']) ? $param['id'] : 0; $detail = Db::table('fa_article')->where('id',$id)->find(); if (!empty($detail)) { $detail['comment'] = Db::table('fa_article_comment') ->where('vote_id',$id) ->withAttr('user_info',function ($value,$data){ return Db::table('fa_szxc_information_usermsg')->where('user_id',$data['user_id'])->value('name'); }) ->select(); View::assign('detail', $detail); View::assign('admin_id', $this->adminInfo['id']); } else{ throw new \think\exception\HttpException(404, '找不到页面'); } } /** * 删除 */ public function del($param) { $id = isset($param['id']) ? $param['id'] : 0; $type = isset($param['type']) ? $param['type'] : 0; $res = Db::table('fa_article')->where('id',$id)->delete(); if ($res){ return to_assign(); }else{ return to_assign(1, '操作失败,原因:'.$res); } } }