Territory.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace app\mall\controller;
  3. use library\Controller;
  4. use library\service\MenuService;
  5. use library\tools\Data;
  6. use think\Db;
  7. /**
  8. * 地域
  9. * Class Territory
  10. * @package app\mall\controller
  11. */
  12. class Territory extends Controller
  13. {
  14. /**
  15. * 绑定数据表
  16. * @var string
  17. */
  18. protected $table = 'GoodsTerritory';
  19. /**
  20. * 地域列表
  21. * @auth true
  22. * @menu true
  23. * @throws \think\Exception
  24. * @throws \think\db\exception\DataNotFoundException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. * @throws \think\exception\DbException
  27. * @throws \think\exception\PDOException
  28. */
  29. public function index()
  30. {
  31. $this->title = '地域列表';
  32. $query = $this->_query($this->table)->where('is_deleted',0)->page(false);
  33. }
  34. /**
  35. * 数据列表处理
  36. * @auth true
  37. * @menu true
  38. * @param array $data
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. * @throws \think\exception\DbException
  42. */
  43. protected function _index_page_filter(&$data)
  44. {
  45. foreach ($data as &$vo) {
  46. $vo['ids'] = join(',', Data::getArrSubIds($data, $vo['id']));
  47. }
  48. $data = Data::arr2table($data);
  49. }
  50. /**
  51. * 添加地域
  52. * @auth true
  53. * @menu true
  54. * @throws \think\Exception
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. * @throws \think\exception\DbException
  58. * @throws \think\exception\PDOException
  59. */
  60. public function add()
  61. {
  62. $this->title = '添加地域';
  63. $this->_form($this->table, 'form');
  64. }
  65. /**
  66. * 编辑地域
  67. * @auth true
  68. * @menu true
  69. * @throws \think\Exception
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. * @throws \think\exception\DbException
  73. * @throws \think\exception\PDOException
  74. */
  75. public function edit()
  76. {
  77. $this->title = '编辑地域';
  78. $this->_form($this->table, 'form');
  79. }
  80. /**
  81. * 表单数据处理
  82. * @param array $vo
  83. * @throws \ReflectionException
  84. * @throws \think\db\exception\DataNotFoundException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. * @throws \think\exception\DbException
  87. */
  88. protected function _form_filter(&$vo)
  89. {
  90. if ($this->request->isGet()) {
  91. // 读取系统功能节点
  92. $this->nodes = MenuService::instance()->getList();
  93. // 选择自己的上级地域
  94. if (empty($vo['pid']) && $this->request->get('pid', '0')) $vo['pid'] = $this->request->get('pid', '0');
  95. // 列出可选上级地域
  96. $menus = Db::name($this->table)->where(['status' => '1'])->order('sort desc,id asc')->column('id,pid,title');
  97. $this->menus = Data::arr2table(array_merge($menus, [['id' => '0', 'pid' => '-1', 'title' => '顶部地域']]));
  98. if (isset($vo['id'])) foreach ($this->menus as $key => $menu) if ($menu['id'] === $vo['id']) $vo = $menu;
  99. foreach ($this->menus as $key => &$menu) {
  100. if ($menu['spt'] >= 2) unset($this->menus[$key]);
  101. if (isset($vo['spt']) && $vo['spt'] <= $menu['spt']) unset($this->menus[$key]);
  102. }
  103. }
  104. }
  105. /**
  106. * 启用
  107. * @auth true
  108. * @menu true
  109. * @throws \think\Exception
  110. * @throws \think\exception\PDOException
  111. */
  112. public function resume()
  113. {
  114. $this->_save($this->table, ['status' => '1']);
  115. }
  116. /**
  117. * 禁用
  118. * @auth true
  119. * @menu true
  120. * @throws \think\Exception
  121. * @throws \think\db\exception\DataNotFoundException
  122. * @throws \think\db\exception\ModelNotFoundException
  123. * @throws \think\exception\DbException
  124. * @throws \think\exception\PDOException
  125. */
  126. public function forbid()
  127. {
  128. $this->_save($this->table, ['status' => '0']);
  129. }
  130. /**
  131. * 删除
  132. * @auth true
  133. * @menu true
  134. * @throws \think\Exception
  135. * @throws \think\exception\PDOException
  136. */
  137. public function remove()
  138. {
  139. $this->_save($this->table, ['is_deleted' => 1]);
  140. }
  141. }