areaModel = $areaModel; } /** * 列表 * @time 2020年12月15日 16:41 * @param Request $request */ public function index(Request $request) : \think\Response { return CatchResponse::success($this->areaModel->getList()); // return CatchResponse::paginate($this->areaModel->getList()); } /** * 保存信息 * @time 2020年12月15日 16:41 * @param Request $request */ public function save(Request $request) : \think\Response { $param=$request->post(); // var_dump($param); if($param['parent_id']){ $p_info=$this->areaModel->where('id',$param['parent_id'])->find(); $param['province_id']=$p_info['province_id']; $param['city_id']=$p_info['city_id']; $param['district_id']=$p_info['district_id']; }else{ $param['province_id']=$param['city'][0]; $param['city_id']=$param['city'][1]; $param['district_id']=$param['city'][2]; } return CatchResponse::success($this->areaModel->storeBy($param)); } /** * 读取 * @time 2020年12月15日 16:41 * @param $id */ public function read($id) : \think\Response { return CatchResponse::success($this->areaModel->findBy($id)); } /** * 更新 * @time 2020年12月15日 16:41 * @param Request $request * @param $id */ public function update(Request $request, $id) : \think\Response { $param=$request->post(); // var_dump($param); if($param['parent_id']){ $p_info=$this->areaModel->where('id',$param['parent_id'])->find(); $param['province_id']=$p_info['province_id']; $param['city_id']=$p_info['city_id']; $param['district_id']=$p_info['district_id']; }else{ $param['province_id']=$param['city'][0]; $param['city_id']=$param['city'][1]; $param['district_id']=$param['city'][2]; } //var_dump($param); return CatchResponse::success($this->areaModel->updateBy($id, $param)); } /** * 删除 * @time 2020年12月15日 16:41 * @param $id */ public function delete($id) : \think\Response { if ($this->areaModel->where('parent_id', $id)->find()) { throw new FailedException('存在子区域,无法删除'); } return CatchResponse::success($this->areaModel->deleteBy($id)); } /** * 获取下属区域 */ public function getDistrictChildrenArea(Request $request) { $data = $this->areaModel->getDistrictChildrenArea($request->post('id')); return CatchResponse::success($data); } /** * 获取区域树组件数据 */ public function getAreaTreeData() { return CatchResponse::success($this->areaModel->getAreaTreeData()); } /** * 根据城市获取区域树组件数据 */ public function getAreaTreeDataByCity($cityid) { return CatchResponse::success($this->areaModel->getAreaTreeDataByCity($cityid)); } /** * 顶部新增按钮 */ public function topAddButton() { } }