Flange.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace catchAdmin\flange\controller;
  3. use catcher\base\CatchRequest as Request;
  4. use catcher\CatchResponse;
  5. use catcher\base\CatchController;
  6. use catchAdmin\flange\model\Flange as model;
  7. use PhpParser\Node\Expr\FuncCall;
  8. use think\facade\Db;
  9. use think\response\Json;
  10. class Flange extends CatchController
  11. {
  12. protected $model;
  13. public function __construct(Model $model)
  14. {
  15. $this->model = $model;
  16. }
  17. /**
  18. * 列表
  19. * @time 2022年05月06日 14:59
  20. * @param Request $request
  21. */
  22. public function index(Request $request) : \think\Response
  23. {
  24. return CatchResponse::paginate($this->model->getList());
  25. }
  26. /**
  27. * 保存信息
  28. * @time 2022年05月06日 14:59
  29. * @param Request $request
  30. */
  31. public function save(Request $request) : \think\Response
  32. {
  33. $data = $request->post();
  34. if($data['out_date']){
  35. $data['out_date'] = date('Y-m-d',$data['out_date']);
  36. }
  37. return CatchResponse::success($this->model->storeBy($data));
  38. }
  39. /**
  40. * 读取
  41. * @time 2022年05月06日 14:59
  42. * @param $id
  43. */
  44. public function read($id) : \think\Response
  45. {
  46. return CatchResponse::success($this->model->findBy($id));
  47. }
  48. /**
  49. * 更新
  50. * @time 2022年05月06日 14:59
  51. * @param Request $request
  52. * @param $id
  53. */
  54. public function update(Request $request, $id) : \think\Response
  55. {
  56. $data = $request->post();
  57. if(!strstr($data['out_date'],'-'))
  58. {
  59. $data['out_date'] = date('Y-m-d',$data['out_date']);
  60. }
  61. return CatchResponse::success($this->model->updateBy($id,$data));
  62. }
  63. /**
  64. * 删除
  65. * @time 2022年05月06日 14:59
  66. * @param $id
  67. */
  68. public function delete($id) : \think\Response
  69. {
  70. return CatchResponse::success($this->model->deleteBy($id));
  71. }
  72. /**
  73. * 获取风场和风机
  74. */
  75. public function getWindFan(Request $request)
  76. {
  77. $data = $request->get();
  78. if(!empty($data['wind']))
  79. {
  80. $where[]=['name','like','%'.$data['wind'].'%'];
  81. }
  82. $wind_list = Db::name("wind")->field('id as wid,number as value,name as text')->select();
  83. $wind_list =json_decode(json_encode($wind_list),true);
  84. foreach($wind_list as $key=>$item)
  85. {
  86. $wind_list[$key]['children'] = Db::name('fan')
  87. ->where('wind_id',$item['wid'])
  88. ->field('id as value,number as text')
  89. ->select();
  90. $wind_list[$key]['value'] =(int)$item['value'];
  91. }
  92. return CatchResponse::success($wind_list);
  93. }
  94. /**
  95. * Undocumented 选择扳手
  96. *
  97. * @param [type] $request
  98. * @return void
  99. */
  100. public function chooseWrench(Request $request)
  101. {
  102. $data = $request->get();
  103. $where = [];
  104. if(!empty($data["id"]))
  105. {
  106. $ids = implode(',',$data['id']);
  107. $where[] =["w.id","in",$ids];
  108. }
  109. $wrenchList = Db::name("wrench")->alias('w')->leftJoin("device_mold d",'w.model=d.id')
  110. ->where($where)->field('w.id as value,w.name as text,w.number,d.name as name')->select();
  111. return CatchResponse::success($wrenchList);
  112. }
  113. }