adminInfo = get_login_admin(); $this->url=[ '/admin/nk.village/index', '/admin/nk.village/add', '/admin/nk.village/edit', '/admin/nk.village/del', '/admin/nk.village/read', ]; } /** * 查看 */ public function index() { if (request()->isAjax()) { $params= get_params(); $where[]=['status','=',1]; $where[]=['village_id','>',0]; 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_id','=',$user_address['village_id']]; }elseif ($user_address['auth_range'] == 2){ $where[] = ['street_id','=',$user_address['street_id']]; }elseif ($user_address['auth_range'] == 3){ $where[] = ['area_id','=',$user_address['area_id']]; }else{ $where[] = ['village_id','=',$user_address['village_id']]; } }else{ $where[] = ['village_id','=','']; } } $total = Db::table('fa_szxc_village') ->where($where)->count(); $list = Db::table('fa_szxc_village') ->withAttr('is_hot',function ($value,$data){ return $value==1?'是':'否'; }) ->withAttr('is_tourism',function ($value,$data){ return $value==1?'是':'否'; }) ->where($where) ->page($params['page']) ->limit($params['limit']) ->order('id desc') ->select(); $result = ['total' => $total, 'data' => $list]; return table_assign(0, '', $result); } View::assign('url', $this->url); return view(); } /** * 添加 */ public function add() { $adds=Db::table('fa_szxc_information_useraddress')->where('admin_id',$this->adminInfo['id'])->find(); if (request()->isAjax()) { $params= get_params(); if (!empty($params['is_hot'])&&$params['is_hot']=='on'){ $params['is_hot']=1; }else{ $params['is_hot']=0; } if (!empty($params['is_tourism'])&&$params['is_tourism']=='on'){ $params['is_tourism']=1; }else{ $params['is_tourism']=0; } if(empty($params['village_id'])){ return to_assign(1, '请选择村/社区'); } if($this->adminInfo['position_id'] != 1){ //不是超级管理员 $params['area_id']=$adds['area_id']; $params['street_id']=$adds['street_id']; } $area_code=Db::table('fa_geo_area')->where('area_code',$params['area_id'])->value('area_name'); $street_code=Db::table('fa_geo_street')->where('street_code',$params['street_id'])->value('street_name'); $village_id=Db::table('fa_geo_village')->where('village_id',$params['village_id'])->value('village_name'); $params['address']='泸州市'.$area_code.$street_code.$village_id; $params['createtime']=time(); $params['people_num']=0; $res=Db::table('fa_szxc_village')->strict(false)->field(true)->insertGetId($params); if ($res){ return to_assign(0,'操作成功',['aid'=>$res]); } return to_assign(1, '操作失败,原因:'.$res); } 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['auth_range'] == 1) { $street = Db::table('fa_geo_area')->where('city_code', '510500')->field('area_id id,area_code code,area_name name')->where('area_code', $user_address['area_id'])->select(); } elseif ($user_address['auth_range'] == 2) { $street = Db::table('fa_geo_area')->where('city_code', '510500')->field('area_id id,area_code code,area_name name')->where('area_code', $user_address['area_id'])->select(); } elseif ($user_address['auth_range'] == 3) { $street = Db::table('fa_geo_area')->where('city_code', '510500')->field('area_id id,area_code code,area_name name')->where('area_code', $user_address['area_id'])->select(); } elseif ($user_address['auth_range'] == 4) { $street = Db::table('fa_geo_area')->where('city_code', '510500')->field('area_id id,area_code code,area_name name')->select(); } else { $street = Db::table('fa_geo_area')->where('city_code', '510500')->field('area_id id,area_code code,area_name name')->select(); } }else{ $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); View::assign('detail', $adds); View::assign('editor', get_system_config('other','editor')); View::assign('url', $this->url); View::assign('admin_id', $this->adminInfo['id']); return view(); } /** * 修改 */ public function edit() { $params= get_params(); if (request()->isAjax()) { if (!empty($params['is_hot'])&&$params['is_hot']=='on'){ $params['is_hot']=1; }else{ $params['is_hot']=0; } if (!empty($params['is_tourism'])&&$params['is_tourism']=='on'){ $params['is_tourism']=1; }else{ $params['is_tourism']=0; } if(empty($params['village_id'])){ return to_assign(1, '请选择村/社区'); } $adds=Db::table('fa_szxc_information_useraddress')->where('admin_id',$this->adminInfo['id'])->find(); if($this->adminInfo['position_id'] != 1){ //不是超级管理员 $params['area_id']=$adds['area_id']; $params['street_id']=$adds['street_id']; } $area_code=Db::table('fa_geo_area')->where('area_code',$params['area_id'])->value('area_name'); $street_code=Db::table('fa_geo_street')->where('street_code',$params['street_id'])->value('street_name'); $village_id=Db::table('fa_geo_village')->where('village_id',$params['village_id'])->value('village_name'); $params['address']='泸州市'.$area_code.$street_code.$village_id; $res=Db::table('fa_szxc_village')->where('id',$params['id'])->strict(false)->field(true)->update($params); if ($res){ return to_assign(); }else{ return to_assign(1, '操作失败,原因:'.$res); } } $detail = Db::table('fa_szxc_village')->where('id',$params['id'])->find(); 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['auth_range'] == 1) { $street = Db::table('fa_geo_area')->where('city_code', '510500')->field('area_id id,area_code code,area_name name')->where('area_code', $user_address['area_id'])->select(); } elseif ($user_address['auth_range'] == 2) { $street = Db::table('fa_geo_area')->where('city_code', '510500')->field('area_id id,area_code code,area_name name')->where('area_code', $user_address['area_id'])->select(); } elseif ($user_address['auth_range'] == 3) { $street = Db::table('fa_geo_area')->where('city_code', '510500')->field('area_id id,area_code code,area_name name')->where('area_code', $user_address['area_id'])->select(); } elseif ($user_address['auth_range'] == 4) { $street = Db::table('fa_geo_area')->where('city_code', '510500')->field('area_id id,area_code code,area_name name')->select(); } else { $street = Db::table('fa_geo_area')->where('city_code', '510500')->field('area_id id,area_code code,area_name name')->select(); } }else{ $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); View::assign('detail', $detail); View::assign('url', $this->url); View::assign('admin_id', $this->adminInfo['id']); return view(); } /** * 查看信息 */ public function read() { $params = get_params(); $detail = Db::table('fa_szxc_village')->where('id',$params['id'])->find(); View::assign('url', $this->url); View::assign('detail', $detail); return view(); } /** * 修改 */ public function del() { $param= get_params(); $id = isset($param['id']) ? $param['id'] : 0; $type = isset($param['type']) ? $param['type'] : 0; $res = Db::table('fa_szxc_village')->where('id',$id)->update(['status'=>$type]); if ($res){ return to_assign(); }else{ return to_assign(1, '操作失败,原因:'.$res); } } }