123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- /*
- * @Descripttion:
- * @version: 1.0.0
- * @Author: likang
- * @Date: 2022-06-17 15:45:05
- * @LastEditors: likang
- * @LastEditTime: 2022-06-21 19:13:45
- */
- namespace catchAdmin\equipment\controller;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- use catchAdmin\equipment\model\EquipmentType as equipmentTypeModel;
- class EquipmentType extends CatchController
- {
- protected $equipmentTypeModel;
-
- public function __construct(EquipmentTypeModel $equipmentTypeModel)
- {
- $this->equipmentTypeModel = $equipmentTypeModel;
- }
-
- /**
- * 列表
- * @time 2022年06月17日 15:45
- * @param Request $request
- */
- public function index(Request $request) : \think\Response
- {
- $pch =null;
- $pch = $this->equipmentTypeModel->where('pid',0)->order('order asc')->select()->toArray();
- foreach($pch as $key=>$value)
- {
- $list= $this->equipmentTypeModel->where('pid',$value['id'])->order('order asc')->select()->toArray();
- foreach($list as $k=>$v)
- {
- $list[$k]['pid'] = strval($v['pid']);
- $list[$k]['status']=strval($v['status']);
- }
- $pch[$key]['children']= $list;
- $pch[$key]['pid'] = strval($value['pid']);
- $pch[$key]['status']=strval($value['status']);
- }
- return CatchResponse::success($pch);
- }
-
- /**
- * 保存信息
- * @time 2022年06月17日 15:45
- * @param Request $request
- */
- public function save(Request $request) : \think\Response
- {
- return CatchResponse::success($this->equipmentTypeModel->storeBy($request->post()));
- }
-
- /**
- * 读取
- * @time 2022年06月17日 15:45
- * @param $id
- */
- public function read($id) : \think\Response
- {
- return CatchResponse::success($this->equipmentTypeModel->findBy($id));
- }
-
- /**
- * 更新
- * @time 2022年06月17日 15:45
- * @param Request $request
- * @param $id
- */
- public function update(Request $request, $id) : \think\Response
- {
-
- return CatchResponse::success($this->equipmentTypeModel->updateBy($id, $request->post()));
- }
-
- /**
- * 删除
- * @time 2022年06月17日 15:45
- * @param $id
- */
- public function delete($id) : \think\Response
- {
- if($id<=7)
- {
- return CatchResponse::fail('该类型不能删除');
- }
- return CatchResponse::success($this->equipmentTypeModel->deleteBy($id,true));
- }
- /**
- * @Descripttion: 获取父类设备种类
- * @name: likang
- * @return {*}
- */
- public function findParentEquipmentType()
- {
- $pch = $this->equipmentTypeModel->where('pid',0)->order('order asc')->select();
- return CatchResponse::success($pch);
- }
- /** 根据pid 获取所有的种类
- * @Descripttion:
- * @name: likang
- * @return {*}
- */
- public function findAllBypid(Request $request)
- {
- $data =$request->get();
- $pid =$data['id'];
- $ls = $this->equipmentTypeModel->where('pid',$pid)->select();
- return CatchResponse::success($ls);
- }
- }
|