Area.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\admin\controller\shopro;
  3. use app\common\controller\Backend;
  4. /**
  5. * 省市区数据
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Area extends Backend
  10. {
  11. protected $noNeedRight = ['getCascader'];
  12. /**
  13. * Area模型对象
  14. * @var \app\admin\model\shopro\Area
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\shopro\Area;
  21. }
  22. /**
  23. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  24. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  25. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  26. */
  27. public function getCascader() {
  28. $area = cache('area-cascader');
  29. if ($area) {
  30. $area = json_decode($area, true);
  31. } else {
  32. $area = $this->model->with('children.children')->where('level', 1)->order('id asc')->select();
  33. cache('area-cascader', json_encode($area), 86400); // 缓存一天
  34. }
  35. return $this->success('操作成功', null, $area);
  36. }
  37. public function select()
  38. {
  39. $ids = $this->request->get();
  40. $area = cache('area-cascader');
  41. $area = $this->model->cache(true)->with('children.children')->where('level', 1)->order('id asc')->select();
  42. if($this->request->isAjax()) {
  43. $this->success('省市区列表', null, $area);
  44. }
  45. $this->assignconfig('areaData', $area);
  46. return $this->view->fetch();
  47. }
  48. }