Category.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\admin\controller\workorder;
  3. use app\common\controller\Backend;
  4. use fast\Tree;
  5. /**
  6. * 工单类别管理
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Category extends Backend
  11. {
  12. /**
  13. * Category模型对象
  14. * @var \app\admin\model\workorder\Category
  15. */
  16. protected $model = null;
  17. protected $categorylist = [];
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\workorder\Category;
  22. $tree = Tree::instance();
  23. $tree->init(collection($this->model->order('weigh desc,id desc')->select())->toArray(), 'pid');
  24. $this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
  25. $this->view->assign("statusList", $this->model->getStatusList());
  26. }
  27. public function import()
  28. {
  29. parent::import();
  30. }
  31. /**
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. //当前是否为关联查询
  37. $this->relationSearch = true;
  38. //设置过滤方法
  39. $this->request->filter(['strip_tags', 'trim']);
  40. if ($this->request->isAjax()) {
  41. $custom = $this->request->request('custom/a');
  42. $keyValue = $this->request->request('keyValue');
  43. //构造父类select列表选项数据
  44. $list = [];
  45. if ($keyValue !== null) {
  46. $keyValue = explode(',', $keyValue);
  47. foreach ($keyValue as $index => $item) {
  48. foreach ($this->categorylist as $key => $value) {
  49. if ($value['id'] == $item) {
  50. $list[] = $value;
  51. }
  52. }
  53. }
  54. } else {
  55. foreach ($this->categorylist as $key => $value) {
  56. if (isset($custom['pid']) && $custom['pid'] == 0) {
  57. if ($value['pid'] == 0) {
  58. $list[] = $value;
  59. }
  60. } else {
  61. $we_ids = \think\Db::name('workorder_engineers')
  62. ->field('title')
  63. ->whereIn('id', $value['we_ids'])
  64. ->select();
  65. $value['we_ids_text'] = '';
  66. foreach ($we_ids as $wkey => $wvalue) {
  67. $value['we_ids_text'] .= $wvalue['title'] . ',';
  68. }
  69. $value['we_ids_text'] = trim($value['we_ids_text'], ',');
  70. $list[] = $value;
  71. }
  72. }
  73. }
  74. $total = count($list);
  75. $result = ["total" => $total, "rows" => $list];
  76. return json($result);
  77. }
  78. return $this->view->fetch();
  79. }
  80. }