SupplierCate.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace app\operate\controller;
  3. use library\Controller;
  4. use library\service\MenuService;
  5. use library\tools\Data;
  6. use think\Db;
  7. /**
  8. * 供应商分类
  9. * Class RecruitCate
  10. * @package app\operate\controller
  11. */
  12. class SupplierCate extends Controller
  13. {
  14. /**
  15. * 绑定数据表
  16. * @var string
  17. */
  18. protected $table = 'SupplierCate';
  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)->order('sort desc,id asc')->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','is_deleted'=>0])->order('sort desc,id asc')->column('id,pid,title,logo');
  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. if($this->request->isPost() && in_array($this->request->action(),['add','edit'])){
  105. if(!isset($vo['id']) && $vo['pid']){
  106. $plev = Db::name($this->table)->where('id',$vo['pid'])->value('lev');
  107. $vo['lev'] = $plev + 1;
  108. }
  109. }
  110. }
  111. /**
  112. * 启用
  113. * @auth true
  114. * @menu true
  115. * @throws \think\Exception
  116. * @throws \think\exception\PDOException
  117. */
  118. public function resume()
  119. {
  120. $this->_save($this->table, ['status' => '1']);
  121. }
  122. /**
  123. * 禁用
  124. * @auth true
  125. * @menu true
  126. * @throws \think\Exception
  127. * @throws \think\db\exception\DataNotFoundException
  128. * @throws \think\db\exception\ModelNotFoundException
  129. * @throws \think\exception\DbException
  130. * @throws \think\exception\PDOException
  131. */
  132. public function forbid()
  133. {
  134. $this->_save($this->table, ['status' => '0']);
  135. }
  136. /**
  137. * 删除
  138. * @auth true
  139. * @menu true
  140. * @throws \think\Exception
  141. * @throws \think\exception\PDOException
  142. */
  143. public function remove()
  144. {
  145. $this->_save($this->table, ['is_deleted' => 1]);
  146. }
  147. }