MachineInspection.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. class MachineInspection extends Api
  5. {
  6. protected $noNeedLogin = ['*'];
  7. protected $noNeedRight = ['*'];
  8. /**
  9. * 设备点检统计左侧菜单栏
  10. * @return void
  11. * @throws \think\db\exception\DataNotFoundException
  12. * @throws \think\db\exception\ModelNotFoundException
  13. * @throws \think\exception\DbException
  14. */
  15. public function getTab()
  16. {
  17. if ($this->request->isGet() === false){
  18. $this->error('请求错误');
  19. }
  20. //筛选出参与点检的设备编号
  21. $machie = db('设备_点检项目')
  22. ->group('适用机型')
  23. ->column('适用机型');
  24. $str = '';
  25. foreach ($machie as $k => $v){
  26. $str = $str . substr($v, 1);
  27. }
  28. $string = explode(';', $str);
  29. array_pop($string);
  30. //查询出点检设备基本资料
  31. $MachineList = db('设备_基本资料')
  32. ->where('sys_sbID','<>','')
  33. ->whereNotNull('sys_sbID')
  34. ->where('设备编号','in',$string)
  35. ->order('设备编号')
  36. ->select();
  37. $data = [];
  38. foreach ($MachineList as $k => $v) {
  39. if (!isset($data[rtrim($v['使用部门'])])) {
  40. $data[rtrim($v['使用部门'])] = [];
  41. }
  42. if (!isset($data[rtrim($v['使用部门'])][substr(rtrim($v['设备编组']),5)])) {
  43. $data[rtrim($v['使用部门'])][substr(rtrim($v['设备编组']),5)] = [];
  44. }
  45. array_push($data[rtrim($v['使用部门'])][substr(rtrim($v['设备编组']),5)], rtrim($v['设备编号']).'【'.rtrim($v['设备名称']).'】');
  46. }
  47. $this->success('成功', $data);
  48. }
  49. /**
  50. * 设备点检详情
  51. * @return void
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. * @throws \think\exception\DbException
  55. */
  56. public function InspectionDetail()
  57. {
  58. if ($this->request->isGet() === false){
  59. $this->error('成功');
  60. }
  61. $params = $this->request->param();
  62. if (empty($params) || !isset($params['machineID']) || empty($params['machineID'])){
  63. $this->error('参数错误');
  64. }
  65. //获取最新一个月参与点检日期
  66. $lastDay = db('设备_点检记录')
  67. ->where('点检设备', $params['machineID'])
  68. ->order('日期', 'desc')
  69. ->value('DATE_FORMAT(日期, "%Y-%m-%d")');
  70. $startDay = date('Y-m-d', strtotime($lastDay)-2592000);
  71. $dayList = db('设备_点检记录')
  72. ->where('日期','between',[$startDay,$lastDay])
  73. ->where('点检设备', $params['machineID'])
  74. ->group('日期')
  75. ->order('日期','desc')
  76. ->column('DATE_FORMAT(日期, "%Y%m%d")');
  77. //查询点检项目
  78. $ProjectList = db('设备_点检项目')
  79. ->where('适用机型','like','%'.$params['machineID'].'%')
  80. ->field('部件编号,rtrim(部件名称) as 部件名称,rtrim(检验项目) as 检验项目')
  81. ->select();
  82. $data = ['日期'=>$dayList,'项目'=>[]];
  83. foreach ($ProjectList as $k => $v) {
  84. $res = db('设备_点检记录')
  85. ->where('部件名称', $v['部件名称'])
  86. ->where('检验项目', $v['检验项目'])
  87. ->where('点检设备', $params['machineID'])
  88. ->where('日期','between',[$startDay,$lastDay])
  89. ->where('点检结果','合格')
  90. ->order('日期','desc')
  91. ->column('DATE_FORMAT(日期, "%Y%m%d")');
  92. $data['项目'][] = array_merge($v,$res);
  93. }
  94. $this->success('成功', $data);
  95. }
  96. }