EquipmentType.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /*
  3. * @Descripttion:
  4. * @version: 1.0.0
  5. * @Author: likang
  6. * @Date: 2022-06-17 15:45:05
  7. * @LastEditors: likang
  8. * @LastEditTime: 2022-06-21 19:13:45
  9. */
  10. namespace catchAdmin\equipment\controller;
  11. use catcher\base\CatchRequest as Request;
  12. use catcher\CatchResponse;
  13. use catcher\base\CatchController;
  14. use catchAdmin\equipment\model\EquipmentType as equipmentTypeModel;
  15. class EquipmentType extends CatchController
  16. {
  17. protected $equipmentTypeModel;
  18. public function __construct(EquipmentTypeModel $equipmentTypeModel)
  19. {
  20. $this->equipmentTypeModel = $equipmentTypeModel;
  21. }
  22. /**
  23. * 列表
  24. * @time 2022年06月17日 15:45
  25. * @param Request $request
  26. */
  27. public function index(Request $request) : \think\Response
  28. {
  29. $pch =null;
  30. $pch = $this->equipmentTypeModel->where('pid',0)->order('order asc')->select()->toArray();
  31. foreach($pch as $key=>$value)
  32. {
  33. $list= $this->equipmentTypeModel->where('pid',$value['id'])->order('order asc')->select()->toArray();
  34. foreach($list as $k=>$v)
  35. {
  36. $list[$k]['pid'] = strval($v['pid']);
  37. $list[$k]['status']=strval($v['status']);
  38. }
  39. $pch[$key]['children']= $list;
  40. $pch[$key]['pid'] = strval($value['pid']);
  41. $pch[$key]['status']=strval($value['status']);
  42. }
  43. return CatchResponse::success($pch);
  44. }
  45. /**
  46. * 保存信息
  47. * @time 2022年06月17日 15:45
  48. * @param Request $request
  49. */
  50. public function save(Request $request) : \think\Response
  51. {
  52. return CatchResponse::success($this->equipmentTypeModel->storeBy($request->post()));
  53. }
  54. /**
  55. * 读取
  56. * @time 2022年06月17日 15:45
  57. * @param $id
  58. */
  59. public function read($id) : \think\Response
  60. {
  61. return CatchResponse::success($this->equipmentTypeModel->findBy($id));
  62. }
  63. /**
  64. * 更新
  65. * @time 2022年06月17日 15:45
  66. * @param Request $request
  67. * @param $id
  68. */
  69. public function update(Request $request, $id) : \think\Response
  70. {
  71. return CatchResponse::success($this->equipmentTypeModel->updateBy($id, $request->post()));
  72. }
  73. /**
  74. * 删除
  75. * @time 2022年06月17日 15:45
  76. * @param $id
  77. */
  78. public function delete($id) : \think\Response
  79. {
  80. if($id<=7)
  81. {
  82. return CatchResponse::fail('该类型不能删除');
  83. }
  84. return CatchResponse::success($this->equipmentTypeModel->deleteBy($id,true));
  85. }
  86. /**
  87. * @Descripttion: 获取父类设备种类
  88. * @name: likang
  89. * @return {*}
  90. */
  91. public function findParentEquipmentType()
  92. {
  93. $pch = $this->equipmentTypeModel->where('pid',0)->order('order asc')->select();
  94. return CatchResponse::success($pch);
  95. }
  96. /** 根据pid 获取所有的种类
  97. * @Descripttion:
  98. * @name: likang
  99. * @return {*}
  100. */
  101. public function findAllBypid(Request $request)
  102. {
  103. $data =$request->get();
  104. $pid =$data['id'];
  105. $ls = $this->equipmentTypeModel->where('pid',$pid)->select();
  106. return CatchResponse::success($ls);
  107. }
  108. }