123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace catchAdmin\permissions\controller;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- use catchAdmin\permissions\model\Area as AreaModel;
- use catcher\exceptions\FailedException;
- class Area extends CatchController
- {
- protected $areaModel;
-
- public function __construct(AreaModel $areaModel)
- {
- $this->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()
- {
-
- }
- }
|