Facility.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 设备运行跟踪
  7. */
  8. class Facility extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 左侧菜单栏
  14. * @ApiMethod (GET)
  15. * @return void
  16. * @throws \think\db\exception\DataNotFoundException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. * @throws \think\exception\DbException
  19. */
  20. public function getTab()
  21. {
  22. if ($this->request->isGet() === false){
  23. $this->error('请求错误');
  24. }
  25. $data = [];
  26. $department = Db::table('设备_基本资料')->distinct(true)->column('使用部门');
  27. if (empty($department)){
  28. $this->error('未获取到机台数据');
  29. }
  30. foreach ($department as $value){
  31. if (rtrim($value) !== '研发中心'){
  32. $machine = Db::table('设备_基本资料')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  33. foreach ($machine as $kk=>$vv){
  34. if ($vv['设备编号'] !== 'ZH01#'){
  35. $date = Db::table('设备_产量计酬')->where('sczl_jtbh',$vv['设备编号'])->distinct(true)->order('UniqId desc')->limit(40)->column('sczl_rq');
  36. $data[rtrim($value)][$vv['设备编号'].'【'.$vv['设备名称'].'】'] = $date;
  37. }
  38. }
  39. }
  40. }
  41. $this->success('成功',$data);
  42. }
  43. /**
  44. * 机台每日产量
  45. * @ApiMethod (GET)
  46. * @param string $machine 机台编号
  47. * @param string $date 日期
  48. * @return void
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. * @throws \think\exception\DbException
  52. */
  53. public function chanLiang()
  54. {
  55. if ($this->request->isGet() === false){
  56. $this->error('请求错误');
  57. }
  58. $machine = input('machine');
  59. $date = input('date');
  60. $where = [
  61. 'sczl_jtbh' => $machine,
  62. 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date)),
  63. ];
  64. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as num,rtrim(sczl_sj1) as sj1,
  65. rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,
  66. rtrim(sczl_装版工时) as 装版工时,rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常总工时,rtrim(sczl_设备运行工时) as 通电工时,
  67. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度数,
  68. rtrim(sys_id) as 用户,rtrim(mod_rq) as 更新时间,rtrim(sczl_异常工时1) as 异常补时,rtrim(sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  69. sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,sczl_rate2,sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
  70. sczl_rate8,sczl_rate9,sczl_rate10';
  71. //机台信息
  72. $machineDetail = Db::table('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
  73. //工单编号
  74. $Gd_gdbh = Db::table('设备_产量计酬')->where($where)->distinct(true)->column('sczl_gdbh');
  75. //产品名称
  76. $productName = Db::table('工单_基本资料')->whereIn('Gd_gdbh',$Gd_gdbh)->column('Gd_cpmc','Gd_gdbh');
  77. //组员信息
  78. $list = Db::table('设备_产量计酬')->where($where)->field($field)->select();
  79. $totalA = Db::table('设备_产量计酬')->where($where)->where('sczl_bzdh','A班')->field('SUM(sczl_cl) as 产量')->select();
  80. $totalB = Db::table('设备_产量计酬')->where($where)->where('sczl_bzdh','B班')->field('SUM(sczl_cl) as 产量')->select();
  81. if (empty($list)){
  82. $this->error('未找到机台数据');
  83. }
  84. foreach ($list as $key=>$value){
  85. $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName[$value['工单编号']];
  86. if ($value['yjno']<10){
  87. $list[$key]['yjno'] = '0'.$value['yjno'];
  88. }
  89. $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
  90. $list[$key]['备注'] = $value['bzdh'].'('.$value['num'].')'.date('H:i',strtotime($value['sj1'])).'<-->'.date('H:i',strtotime($value['sj2']));
  91. $list[$key]['千件工价'] = $machineDetail['千件工价'];
  92. $list[$key]['日定额'] = $machineDetail['日定额'];
  93. for ($i=1;$i<11;$i++){
  94. if (isset($value['sczl_bh'.$i])){
  95. $name = Db::table('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
  96. if (isset($name['name'])){
  97. $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
  98. }
  99. }
  100. unset($list[$key]['sczl_bh'.$i],$list[$key]['sczl_rate'.$i]);
  101. }
  102. unset($list[$key]['工序编号'],$list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['num'],$list[$key]['sj1'],$list[$key]['sj2'],$list[$key]['bzdh']);
  103. }
  104. $list['totalA'] = $totalA[0]['产量'];
  105. $list['totalB'] = $totalB[0]['产量'];
  106. $this->success('成功',$list);
  107. }
  108. /**
  109. * 当日制程检验记录
  110. * @ApiMethod (GET)
  111. * @param string $machine 机台编号
  112. * @param string $date 日期
  113. * @return void
  114. * @throws \think\db\exception\DataNotFoundException
  115. * @throws \think\db\exception\ModelNotFoundException
  116. * @throws \think\exception\DbException
  117. */
  118. public function Inspect()
  119. {
  120. if ($this->request->isGet() === false){
  121. $this->error('请求错误');
  122. }
  123. $machine = input('machine');
  124. $date = input('date');
  125. if (empty($machine) || empty($date)){
  126. $this->error('参数错误');
  127. }
  128. $last_id = Db::table('制程检验_记录')->order('UniqId desc')->field('UniqId')->find();
  129. $startId = $last_id['UniqId']-1000000;
  130. $where = [
  131. '设备编号' => $machine,
  132. '开工时间' => ['between',[date('Y-m-d 08:00:00',strtotime($date)),date('Y-m-d 08:00:00',strtotime($date)+86400)]],
  133. '类别' => ['in',['IPQC检验','机台检验']],
  134. 'UniqId' => ['>',$startId],
  135. ];
  136. $begin = Db::table('制程检验_记录')->where($where)->field('UniqId')->find();
  137. $end = Db::table('制程检验_记录')->where($where)->order('UniqId desc')->field('UniqId')->find();
  138. $where['UniqId'] = ['between',[$begin['UniqId'],$end['UniqId']+1]];
  139. //检验项目筛选
  140. $itemA = Db::table('制程检验_记录')->where($where)->distinct(true)->where('班组编号','A班')->column('rtrim(检验项目)');
  141. $itemB = Db::table('制程检验_记录')->where($where)->distinct(true)->where('班组编号','B班')->column('rtrim(检验项目)');
  142. //检验时间
  143. $InspectionTime = Db::table('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
  144. foreach ($InspectionTime as $k=>$v){
  145. $InspectionTime[$k] = date('H:i',strtotime($v));
  146. }
  147. //检测记录详情
  148. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
  149. $nameDetailA = Db::table('制程检验_记录')->where($where)->field($field)->where('班组编号','A班')->find();
  150. $nameDetailB = Db::table('制程检验_记录')->where($where)->field($field)->where('班组编号','B班')->find();
  151. $list = $data1 = $data2 = [];
  152. //A班检测数据
  153. foreach ($itemA as $key=>$value){
  154. $SubmissionTime = Db::table('制程检验_记录')->where($where)
  155. ->where('班组编号','A班')
  156. ->where('检验项目',$value)
  157. ->where('检验结果','合格')
  158. ->field('rtrim(提交时间) as 提交时间')
  159. ->select();
  160. $time = [];
  161. foreach ($SubmissionTime as $k=>$v){
  162. $time[$k] = date('H:i',strtotime($v['提交时间']));
  163. }
  164. $data1[$key] = [
  165. '工单编号' => $nameDetailA['工单编号'],
  166. '印件号' => $nameDetailA['印件号'],
  167. '工序名称' => $nameDetailA['工序名称'],
  168. '检验项目' => $value,
  169. 'inspectresult' => implode(',',$time),
  170. ];
  171. }
  172. //B班数据详情
  173. foreach ($itemB as $key=>$value){
  174. $SubmissionTime = Db::table('制程检验_记录')->where($where)
  175. ->where('班组编号','B班')
  176. ->where('检验项目',$value)
  177. ->where('检验结果','合格')
  178. ->field('rtrim(提交时间) as 提交时间')
  179. ->select();
  180. $time = [];
  181. foreach ($SubmissionTime as $k=>$v){
  182. $time[$k] = date('H:i',strtotime($v['提交时间']));
  183. }
  184. $data2[$key] = [
  185. '工单编号' => $nameDetailB['工单编号'],
  186. '印件号' => $nameDetailB['印件号'],
  187. '工序名称' => $nameDetailB['工序名称'],
  188. '检验项目' => $value,
  189. 'inspectresult' => implode(',',$time),
  190. ];
  191. }
  192. $list = array_merge($data2,$data1);
  193. $list['inspectiontime'] = $InspectionTime;
  194. $this->success('成功',$list);
  195. }
  196. //生产中工单信息
  197. public function Production()
  198. {
  199. if ($this->request->isGet() === false){
  200. $this->error('请求错误');
  201. }
  202. $machine = input('machine');
  203. if (empty($machine)){
  204. $this->error('参数错误');
  205. }
  206. $nowTime = date('Y-m-d H:i:s',time());
  207. $where = [
  208. 'Gy0_sbbh' => $machine,
  209. 'Gy0_sj1' => ['<',$nowTime],
  210. 'Gy0_sj2' => ['>',$nowTime],
  211. ];
  212. // $field = 'rtrim(Gy0_gdbh) as 工单编号,rtrim(Gy0_yjno) as 印件编号,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Ass_gxmc) as add,'
  213. }
  214. }