model = new \app\admin\model\Area; } public function import() { parent::import(); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //当前是否为关联查询 $this->relationSearch = false; //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model ->where($where) ->where('level',2) ->order($sort, $order) ->paginate($limit); $result = array("total" => $list->total(), "rows" => $list->items()); return json($result); } return $this->view->fetch(); } public function air_set($ids){ if($this->request->isGet()){ return view(); }else{ $area=\app\common\model\Area::city()->findOrFail($ids); $data=input(); $this->validate($data,[ 'longitude'=>['require','number'], 'latitude'=>['require','number'], ]); $area->save([ 'air_longitude'=>$data['longitude'], 'air_latitude'=>$data['latitude'], ]); $this->success(); } } public function get_data() { $params = [ 'A-G' => ['安徽省', '北京', '重庆', '福建省', '甘肃省', '广东省', '广西壮族自治区', '贵州省'], 'H-K' => ['海南省', '河北省', '黑龙江省', '河南省', '湖北省', '湖南省', '江苏省', '江西省', '吉林省'], 'L-S' => ['辽宁省', '内蒙古自治区', '宁夏回族自治区', '青海省', '山东省', '上海', '山西省', '陕西省', '四川省'], 'T-Z' => ['天津', '新疆维吾尔自治区', '西藏自治区', '云南省', '浙江省'], '-' => ['台湾', '香港特别行政区', '澳门特别行政区'] ]; $provinceData = []; $provinceIds = []; foreach ($params as $key => $value) { $tempProvinceData = []; foreach ($value as $val) { $province = ModelArea::where('name', 'like', $val)->find(); if (empty($province)) { continue; } $tempProvinceData[] = [ 'code' => $province->id ?? 0, 'address' => $province->name ?? '' ]; $provinceIds[] = $province->id ?? 0; } $provinceData[$key] = $tempProvinceData; } $data = [ '86' => $provinceData ]; foreach ($provinceIds as $provinceId) { $cities = ModelArea::where('pid', $provinceId)->column('name', 'id'); if (empty($cities)) { continue; } $data[$provinceId] = $cities; foreach ($cities as $cityId => $city) { $districts = ModelArea::where('pid', $cityId)->column('name', 'id'); if (empty($districts)) { continue; } $data[$cityId] = $districts; } } echo json_encode($data, JSON_UNESCAPED_UNICODE); die; } }