Facility.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Request;
  6. /**
  7. * 设备运行跟踪
  8. */
  9. class Facility extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 左侧菜单栏
  15. * @ApiMethod (GET)
  16. * @return void
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. * @throws \think\exception\DbException
  20. */
  21. public function getTab()
  22. {
  23. if ($this->request->isGet() === false){
  24. $this->error('请求错误');
  25. }
  26. $data = [];
  27. $department = \db('设备_基本资料')->distinct(true)->column('使用部门');
  28. $date = date('Y-m-d 00:00:00',time()-3888000);
  29. if (empty($department)){
  30. $this->success('未获取到机台数据');
  31. }
  32. foreach ($department as $value){
  33. if (rtrim($value) !== '研发中心'){
  34. $machine = \db('设备_基本资料')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  35. foreach ($machine as $kk=>$vv){
  36. if ($vv['设备编号'] !== 'ZH01#'){
  37. $date = \db('设备_产量计酬')
  38. ->where('sczl_jtbh',$vv['设备编号'])
  39. // ->where('sczl_rq','> time',$date)
  40. ->distinct(true)
  41. ->cache(true)
  42. ->limit(40)
  43. ->order('UniqId desc')
  44. ->column('sczl_rq');
  45. $data[rtrim($value)][$vv['设备编号'].'【'.$vv['设备名称'].'】'] = $date;
  46. }
  47. }
  48. }
  49. }
  50. $this->success('成功',$data);
  51. // $date = date('Y-m-d 00:00:00',time()-3888000);
  52. // $department = \db('设备_基本资料')
  53. // ->distinct(true)
  54. // ->where('使用部门','<>','研发中心')
  55. // ->where('设备编组','<>','')
  56. // ->order('设备编组')
  57. // ->column('rtrim(使用部门) as 使用部门');
  58. // if (empty($department)){
  59. // $this->success('为获取到机台数据');
  60. // }
  61. // $list = \db('设备_产量计酬')
  62. // ->field([
  63. // 'DISTINCT(sczl_rq)' => '时间',
  64. // 'rtrim(sczl_jtbh)' => '机台编号'
  65. // ])
  66. // ->where('sczl_rq','>',$date)
  67. // ->cache(true,86400)
  68. // ->order('sczl_rq desc')
  69. // ->select();
  70. // if (empty($list)){
  71. // $this->success('未找到机台生产记录');
  72. // }
  73. // foreach ($department as $value){
  74. // $machine = \db('设备_基本资料')->where('使用部门',$value)->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->select();
  75. // foreach ($machine as $k=>$v){
  76. // $data[rtrim($value)][$k]['机台'] = $v['设备编号'].'-->'.$v['设备名称'];
  77. // foreach ($list as $kk=>$vv){
  78. // if ($v['设备编号'] === $vv['机台编号']){
  79. // array_push($data[rtrim($value)][$k],date('Y-m-d',strtotime($vv['时间'])));
  80. // }
  81. // }
  82. // }
  83. // }
  84. // $this->success('成功',$data);
  85. }
  86. /**
  87. * 机台每日产量
  88. * @ApiMethod (GET)
  89. * @param string $machine 机台编号
  90. * @param string $date 日期
  91. * @return void
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\ModelNotFoundException
  94. * @throws \think\exception\DbException
  95. */
  96. public function chanLiang()
  97. {
  98. if ($this->request->isGet() === false){
  99. $this->error('请求错误');
  100. }
  101. $machine = input('machine');
  102. $date = input('date');
  103. $where = [
  104. 'sczl_jtbh' => $machine,
  105. 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
  106. ];
  107. $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,
  108. 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 来料异常,
  109. rtrim(sczl_装版工时) as 装版工时,rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常总工时,rtrim(sczl_设备运行工时) as 通电工时,
  110. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度数,
  111. rtrim(sys_id) as 用户,rtrim(mod_rq) as 更新时间,rtrim(sczl_异常工时1) as 异常补时,rtrim(sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  112. 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,
  113. sczl_rate8,sczl_rate9,sczl_rate10';
  114. //机台信息
  115. $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
  116. //工单编号
  117. $Gd_gdbh = \db('设备_产量计酬')->where($where)->distinct(true)->column('sczl_gdbh');
  118. //产品名称
  119. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$Gd_gdbh)->column('Gd_cpmc','Gd_gdbh');
  120. //组员信息
  121. $list = \db('设备_产量计酬')->where($where)->field($field)->cache(true,86400)->select();
  122. $totalA = \db('设备_产量计酬')->where($where)->where('sczl_bzdh','A班')->field('SUM(sczl_cl) as 产量')->select();
  123. $totalB = \db('设备_产量计酬')->where($where)->where('sczl_bzdh','B班')->field('SUM(sczl_cl) as 产量')->select();
  124. if (empty($list)){
  125. $this->success('',[]);
  126. }
  127. foreach ($list as $key=>$value){
  128. $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName[$value['工单编号']];
  129. if ($value['yjno']<10){
  130. $list[$key]['yjno'] = '0'.$value['yjno'];
  131. }
  132. $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
  133. $list[$key]['备注'] = $value['bzdh'].'('.$value['num'].')'.date('H:i',strtotime($value['sj1'])).'<-->'.date('H:i',strtotime($value['sj2']));
  134. $list[$key]['千件工价'] = $machineDetail['千件工价'];
  135. $list[$key]['日定额'] = $machineDetail['日定额'];
  136. for ($i=1;$i<11;$i++){
  137. if (isset($value['sczl_bh'.$i])){
  138. $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
  139. if (isset($name['name'])){
  140. $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
  141. }
  142. }
  143. unset($list[$key]['sczl_bh'.$i],$list[$key]['sczl_rate'.$i]);
  144. }
  145. unset($list[$key]['工序编号'],$list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['num'],$list[$key]['sj1'],$list[$key]['sj2'],$list[$key]['bzdh']);
  146. }
  147. $list['totalA'] = $totalA[0]['产量'];
  148. $list['totalB'] = $totalB[0]['产量'];
  149. $this->success('成功',$list);
  150. }
  151. /**
  152. * 当日制程检验记录
  153. * @ApiMethod (GET)
  154. * @param string $machine 机台编号
  155. * @param string $date 日期
  156. * @return void
  157. * @throws \think\db\exception\DataNotFoundException
  158. * @throws \think\db\exception\ModelNotFoundException
  159. * @throws \think\exception\DbException
  160. */
  161. public function Inspect()
  162. {
  163. if ($this->request->isGet() === false){
  164. $this->error('请求错误');
  165. }
  166. $machine = input('machine');
  167. $date = input('date');
  168. if (empty($machine) || empty($date)){
  169. $this->error('参数错误');
  170. }
  171. $where = [
  172. '设备编号' => $machine,
  173. '开工时间' => ['between',[date('Y-m-d 08:00:00',strtotime($date)),date('Y-m-d 08:00:00',strtotime($date)+86400)]],
  174. '类别' => ['in',['IPQC检验','机台检验']],
  175. ];
  176. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,提交时间,rtrim(检验项目) as 检验项目';
  177. $list = \db('制程检验_记录')
  178. ->where($where)
  179. ->field($field)
  180. ->cache(true,86400)
  181. ->select();
  182. if (empty($list)){
  183. $this->success('未找到检验记录');
  184. }
  185. $data = [];
  186. foreach ($list as $key=>$value)
  187. {
  188. $data['item'][$key] = $value['检验项目'];
  189. $data['InspectionTime'][$key] = date('H:i',strtotime($value['提交时间']));
  190. $data['工单编号'][$key] = $value['工单编号'];
  191. }
  192. $data['item'] = array_unique($data['item']);
  193. $data['InspectionTime'] = array_values(array_unique($data['InspectionTime']));
  194. $data['工单编号'] = array_values(array_unique($data['工单编号']));
  195. foreach ($data['工单编号'] as $key => $value){
  196. foreach ($data['item'] as $k=>$v){
  197. $time = '';
  198. foreach ($list as $kk=>$vv){
  199. if ($vv['工单编号'] === $value && $vv['检验项目'] === $v){
  200. $time = $time.date('H:i',strtotime($vv['提交时间'])).',';
  201. $data['row'][$key][$k] = [
  202. '工单编号' => $value,
  203. '印件号' => $vv['印件号'],
  204. '工序名称' => $vv['工序名称'],
  205. '检验项目' => $v,
  206. 'time' => substr($time,0,-1),
  207. ];
  208. }
  209. }
  210. }
  211. $data['row'][$key] = array_values($data['row'][$key]);
  212. }
  213. unset($data['item'],$data['工单编号']);
  214. $this->success('成功',$data);
  215. }
  216. /**
  217. * 设备生产中工单信息
  218. * @ApiMethod (GET)
  219. * @param string $machine 机台编号
  220. * @return void
  221. * @throws \think\Exception
  222. * @throws \think\db\exception\DataNotFoundException
  223. * @throws \think\db\exception\ModelNotFoundException
  224. * @throws \think\exception\DbException
  225. */
  226. public function Production()
  227. {
  228. if ($this->request->isGet() === false){
  229. $this->error('请求错误');
  230. }
  231. $machine = input('machine');
  232. if (empty($machine)){
  233. $this->error('参数错误');
  234. }
  235. $sql = "SELECT
  236. rtrim(b.Gy0_gdbh) AS 工单编号,
  237. rtrim(b.Gy0_yjno) AS 印件号,
  238. rtrim(b.Gy0_gxh) AS gxh,
  239. rtrim(b.Gy0_gxmc) AS gxmc,
  240. rtrim(b.Add_gxmc) AS add_gxmc,
  241. RTRIM(a.Gd_cpmc) AS 产品名称
  242. FROM
  243. `工单_基本资料` AS a
  244. JOIN `工单_工艺资料` AS b ON a.Gd_gdbh = b.Gy0_gdbh
  245. JOIN `产品_基本资料` AS c ON a.`成品代号` = c.`产品编号`
  246. JOIN `工单_印件资料` AS d ON a.Gd_gdbh = d.Yj_Gdbh
  247. LEFT JOIN `设备_产量计酬` AS e ON e.sczl_gdbh = a.Gd_gdbh
  248. AND e.sczl_jtbh = b.Gy0_sbbh
  249. WHERE
  250. a.gd_statu = '2-生产中'
  251. AND a.`行号` = '1'
  252. AND b.Gy0_sbbh = '{$machine}'
  253. AND c.`状态` = ''
  254. AND b.PD_WG = '1900-01-01 00:00:00'
  255. AND b.Gy0_sj1 <> '1900-01-01 00:00:00'
  256. GROUP BY
  257. a.Gd_gdbh
  258. LIMIT 1";
  259. $list = Db::query($sql);
  260. if (empty($list)){
  261. $this->success('未找到排产工单',[]);
  262. }
  263. foreach ($list as $key=>$value){
  264. if ($value['gxh']<10){
  265. $list[$key]['gxh'] = '0'.$value['gxh'];
  266. }
  267. $list[$key]['工序名称'] = $list[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  268. unset($list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc']);
  269. }
  270. $this->success('成功',$list);
  271. }
  272. /**
  273. * 设备工作清单
  274. * @ApiMethod (GET)
  275. * @param string $machine 机台编号
  276. * @return void
  277. * @throws \think\db\exception\DataNotFoundException
  278. * @throws \think\db\exception\ModelNotFoundException
  279. * @throws \think\exception\DbException
  280. */
  281. public function EquipmentWorklist()
  282. {
  283. if ($this->request->isGet() === false){
  284. $this->error('请求错误');
  285. }
  286. $machine = input('machine');
  287. if (empty($machine)){
  288. $this->error('参数错误');
  289. }
  290. $sql = "SELECT
  291. rtrim( b.Gy0_gdbh ) AS gdbh,
  292. rtrim(b.质量要求) AS 质量信息,
  293. rtrim( b.Gy0_yjno ) AS yjno,
  294. rtrim( b.Gy0_gxh ) AS gxh,
  295. rtrim( b.Gy0_gxmc ) AS gxmc,
  296. rtrim( b.Add_gxmc ) AS add_gxmc,
  297. rtrim( b.Gy0_辅助工时 ) AS 装版时数,
  298. rtrim( b.Gy0_小时产能 ) AS 工序产能,
  299. rtrim( b.Gy0_生产工时 ) AS 计划工时,
  300. rtrim( b.Gy0_sj1 ) AS sj1,
  301. rtrim( b.Gy0_sj2 ) AS sj2,
  302. rtrim(b.工序备注) AS 排产备注,
  303. RTRIM(d.yj_yjmc) AS 印件名称,
  304. RTRIM(a.Gd_cpmc) AS 产品名称,
  305. RTRIM(a.成品代号) AS 产品代号,
  306. SUM(E.sczl_cl) AS 已完成,
  307. rtrim(b.Gy0_计划接货数) AS 计划接货数,
  308. RTRIM(b.Gy0_ls) AS ls
  309. FROM
  310. `工单_基本资料` AS a
  311. JOIN `工单_工艺资料` AS b ON a.Gd_gdbh = b.Gy0_gdbh
  312. JOIN `产品_基本资料` AS c ON a.`成品代号` = c.`产品编号`
  313. JOIN `工单_印件资料` AS d ON a.Gd_gdbh = d.Yj_Gdbh
  314. LEFT JOIN `设备_产量计酬` AS e ON e.sczl_gdbh = a.Gd_gdbh AND e.sczl_jtbh = b.Gy0_sbbh
  315. WHERE
  316. a.gd_statu = '2-生产中'
  317. AND a.`行号` = '1'
  318. AND b.Gy0_sbbh = '{$machine}'
  319. AND c.`状态` = ''
  320. AND b.PD_WG = '1900-01-01 00:00:00'
  321. AND b.Gy0_sj1 <> '1900-01-01 00:00:00'
  322. GROUP BY a.Gd_gdbh
  323. ORDER BY b.Gy0_sj1";
  324. $orderList = Db::query($sql);
  325. if (empty($orderList)){
  326. $this->success('未找到排产工单');
  327. }
  328. foreach ($orderList as $key=>$value){
  329. $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
  330. if ($value['yjno']<10){
  331. $orderList[$key]['yjno'] = '0'.$value['yjno'];
  332. }
  333. if ($value['gxh']<10){
  334. $orderList[$key]['gxh'] = '0'.$value['gxh'];
  335. }
  336. $orderList[$key]['印件资料'] = $orderList[$key]['yjno'].'-'.$value['印件名称'];
  337. $orderList[$key]['工序名称'] = $orderList[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  338. $orderList[$key]['计划产量/已完成'] = (int)($value['计划接货数']/$value['ls']).'/'.$value['已完成']=null?'':(int)$value['已完成'];
  339. $orderList[$key]['计划生产时段'] =substr($value['sj1'],5,5).' '.substr($value['sj1'],11,5).'<-->'.substr($value['sj2'],5,5).' '.substr($value['sj2'],11,5);
  340. unset($orderList[$key]['gdbh'],$orderList[$key]['质量信息'],$orderList[$key]['yjno'],$orderList[$key]['gxh'],$orderList[$key]['gxmc'],$orderList[$key]['add_gxmc'],$orderList[$key]['sj1'],$orderList[$key]['sj2'],$orderList[$key]['计划接货数'],$orderList[$key]['已完成'],$orderList[$key]['印件名称'],$orderList[$key]['ls']);
  341. }
  342. $this->success('成功',$orderList);
  343. }
  344. /**
  345. * 工序、印件、完成数量
  346. * @ApiMethod (GET)
  347. * @param string $workOrder 工单编号
  348. * @return void
  349. * @throws \think\Exception
  350. * @throws \think\db\exception\DataNotFoundException
  351. * @throws \think\db\exception\ModelNotFoundException
  352. * @throws \think\exception\DbException
  353. */
  354. public function Procedure()
  355. {
  356. if ($this->request->isGet() === false){
  357. $this->error('请求错误');
  358. }
  359. $workOrder = input('Gd_gdbh');
  360. if (empty($workOrder)){
  361. $this->error('参数错误');
  362. }
  363. //右边工艺及完成数量
  364. $Process = \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  365. ->distinct(true)->order('sczl_gxh')
  366. ->column('sczl_gxh');
  367. $data = [];
  368. foreach ($Process as $k=>$v){
  369. $res= \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  370. ->where('sczl_gxh',$v)
  371. ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
  372. ->find();
  373. if ($res['sczl_yjno']<10){
  374. $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
  375. }
  376. $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
  377. $processList['completed'] = \db('设备_产量计酬')
  378. ->where('sczl_gdbh',$workOrder)
  379. // ->where('UniqId','>',$startUniqid)
  380. ->where('sczl_gxh',$v)
  381. ->count();
  382. array_push($data,$processList);
  383. }
  384. $this->success('成功',$data);
  385. }
  386. /**
  387. * 班组人员及分配比例
  388. * @ApiMethod (GET)
  389. * @param string $machine 机台编号
  390. * @return void
  391. * @throws \think\db\exception\DataNotFoundException
  392. * @throws \think\db\exception\ModelNotFoundException
  393. * @throws \think\exception\DbException
  394. */
  395. public function Team()
  396. {
  397. if ($this->request->isGet() === false){
  398. $this->error('请求错误');
  399. }
  400. $machine = input('machine');
  401. if (empty($machine)){
  402. $this->error('参数错误');
  403. }
  404. $where = [
  405. 'sczl_jtbh' => $machine,
  406. ];
  407. $field = 'rtrim(sczl_bzdh) as 班组号,rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
  408. rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
  409. rtrim(sczl_bh10) as bh10,rtrim(sczl_rate1) as rate1,rtrim(sczl_rate2) as rate2,rtrim(sczl_rate3) as rate3,rtrim(sczl_rate4) as rate4,
  410. rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,
  411. rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10,rtrim(UniqId) as ID';
  412. $team = \db('设备_产量计酬')
  413. ->where('sczl_jtbh',$machine)
  414. ->field($field)
  415. ->order('UniqId desc')
  416. ->find();
  417. $list = \db('设备_班组资料')->where($where)->field($field)->select();
  418. $data = [];
  419. foreach ($list as $k=>$v){
  420. if ($team == $v){
  421. $data[$k]['status'] = 1;
  422. }else{
  423. $data[$k]['status'] = 0;
  424. }
  425. $data[$k]['ID'] = $v['ID'];
  426. $data[$k]['班组号'] = $v['班组号'];
  427. for ($i=1;$i<11;$i++){
  428. if ($v['bh'.$i] != '' && $v['bh'.$i] != '000000'){
  429. $name = \db('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
  430. $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
  431. }
  432. }
  433. }
  434. $this->success('成功',$data);
  435. }
  436. /**
  437. * 当班产量明细
  438. * @ApiMethod (GET)
  439. * @param string $machine 机台编号
  440. * @param string $workOrder 工单编号
  441. * @param string $team 班次
  442. * @return void
  443. * @throws \think\db\exception\DataNotFoundException
  444. * @throws \think\db\exception\ModelNotFoundException
  445. * @throws \think\exception\DbException
  446. */
  447. public function OutputDetail()
  448. {
  449. if ($this->request->isGet() === false){
  450. $this->error('请求错误');
  451. }
  452. $machine = input('machine');
  453. $workOrder = input('Gd_gdbh');
  454. $team = input('team');
  455. if (empty($machine) || empty($workOrder) || empty($team)){
  456. $this->error('参数错误');
  457. }
  458. $name = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(Gd_cpmc) as productName')->find();
  459. $where = [
  460. 'sczl_gdbh' => $workOrder,
  461. 'sczl_jtbh' => $machine,
  462. 'sczl_cl' => ['<>',0.0],
  463. 'sczl_bzdh' => $team,
  464. ];
  465. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as 标牌号,rtrim(sczl_cl) as 产量,
  466. rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,rtrim(sczl_装版工时) as 装版工时,
  467. rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常停机工时,rtrim(sczl_设备运行工时) as 通电工时,
  468. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
  469. rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2';
  470. $list = \db('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
  471. if (empty($list)){
  472. $this->success('未找到生产记录');
  473. }
  474. foreach ($list as $k=>$v){
  475. if ($v['yjno']<10){
  476. $list[$k]['yjno'] = '0'.$v['yjno'];
  477. }
  478. $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
  479. $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
  480. $list[$k]['产品名称'] = $name['productName'];
  481. unset($list[$k]['yjno'],$list[$k]['gxmc'],$list[$k]['sj1'],$list[$k]['sj2']);
  482. }
  483. $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
  484. SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
  485. SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
  486. SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
  487. $total = \db('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
  488. $total[0]['版数'] = count($list);
  489. $list['total'] = $total[0];
  490. $this->success('成功',$list);
  491. }
  492. /**
  493. * 检验记录
  494. * @ApiMethod (GET)
  495. * @param string $machine 机台编号
  496. * @param string $workOrder 工单编号
  497. * @param string $team 班次
  498. * @return void
  499. * @throws \think\db\exception\DataNotFoundException
  500. * @throws \think\db\exception\ModelNotFoundException
  501. * @throws \think\exception\DbException
  502. */
  503. public function InspectionRecord()
  504. {
  505. if ($this->request->isGet() === false){
  506. $this->error('请求失败');
  507. }
  508. $machine = input('machine');
  509. $workOrder = input('Gd_gdbh');
  510. $team = input('team');
  511. if (empty($machine) || empty($workOrder) || empty($team)){
  512. $this->error('参数错误');
  513. }
  514. // $last_id = \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find();
  515. // $startId = $last_id['UniqId']-100000;
  516. $where = [
  517. '设备编号' => $machine,
  518. '工单编号' => $workOrder,
  519. '班组编号' => $team,
  520. '类别' => ['in',['IPQC检验','机台检验']],
  521. // 'UniqId' => ['>',$startId],
  522. ];
  523. //检验项目筛选
  524. $item = \db('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
  525. //检验时间
  526. $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
  527. foreach ($InspectionTime as $k=>$v){
  528. $InspectionTime[$k] = date('H:i',strtotime($v));
  529. }
  530. //检测记录详情
  531. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
  532. $nameDetail = \db('制程检验_记录')->where($where)->field($field)->find();
  533. $data = [];
  534. //检测数据
  535. foreach ($item as $key=>$value){
  536. $SubmissionTime = \db('制程检验_记录')->where($where)
  537. ->where('检验项目',$value)
  538. ->where('检验结果','合格')
  539. ->field('rtrim(提交时间) as 提交时间')
  540. ->select();
  541. $time = [];
  542. foreach ($SubmissionTime as $k=>$v){
  543. $time[$k] = date('H:i',strtotime($v['提交时间']));
  544. }
  545. $data[$key] = [
  546. '工单编号' => $nameDetail['工单编号'],
  547. '印件号' => $nameDetail['印件号'],
  548. '工序名称' => $nameDetail['工序名称'],
  549. '检验项目' => $value,
  550. 'inspectresult' => implode(',',$time),
  551. ];
  552. }
  553. $data['inspectiontime'] = $InspectionTime;
  554. $this->success('成功',$data);
  555. }
  556. //班组维护
  557. public function TeamMaintenance()
  558. {
  559. if (Request::instance()->isPost() === false){
  560. $this->error('请求错误');
  561. }
  562. $data = Request::instance()->post();
  563. if (empty($data)){
  564. $this->error('参数错误');
  565. }
  566. $field = 'rtrim(sczl_bzdh) as sczl_bzdh,rtrim(sczl_bh1) as sczl_bh1,rtrim(sczl_bh2) as sczl_bh2,rtrim(sczl_bh3) as sczl_bh3,rtrim(sczl_bh4) as sczl_bh4,
  567. rtrim(sczl_bh5) as sczl_bh5,rtrim(sczl_bh6) as sczl_bh6,rtrim(sczl_bh7) as sczl_bh7,rtrim(sczl_bh8) as sczl_bh8,rtrim(sczl_bh9) as sczl_bh9,
  568. rtrim(sczl_bh10) as sczl_bh10,rtrim(sczl_rate1) as sczl_rate1,rtrim(sczl_rate2) as sczl_rate2,rtrim(sczl_rate3) as sczl_rate3,rtrim(sczl_rate4) as sczl_rate4,
  569. rtrim(sczl_rate5) as sczl_rate5,rtrim(sczl_rate6) as sczl_rate6,rtrim(sczl_rate7) as sczl_rate7,rtrim(sczl_rate8) as sczl_rate8,
  570. rtrim(sczl_rate9) as sczl_rate9,rtrim(sczl_rate10) as sczl_rate10';
  571. $TeamList = \db('设备_班组资料')->where('UniqId',$data['ID'])->field($field)->find();
  572. }
  573. /**
  574. * 机台编号列表
  575. * @ApiMethod (GET)
  576. * @return void
  577. */
  578. public function MachineList()
  579. {
  580. if ($this->request->isGet() === false){
  581. $this->error('请求错误');
  582. }
  583. $list = \db('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  584. if (empty($list)){
  585. $this->success('未找到机台编号');
  586. }
  587. $data = [];
  588. foreach ($list as $key=>$value){
  589. $data[$key] = $value['设备编号'] . '||' . $value['设备名称'];
  590. }
  591. $this->success('成功',$data);
  592. }
  593. /**
  594. * 删除班组信息
  595. * @ApiMethod (GET)
  596. * @param void
  597. * @return void
  598. * @throws \think\Exception
  599. * @throws \think\exception\PDOException
  600. */
  601. public function teamDel()
  602. {
  603. if (Request::instance()->isPost() === false){
  604. $this->error('请求错误');
  605. }
  606. $param = Request::instance()->post();
  607. if (empty($param)){
  608. $this->error('参数错误');
  609. }
  610. $res = \db('设备_班组资料')
  611. ->where('UniqId',$param['UniqId'])
  612. ->delete();
  613. if ($res !== false){
  614. $this->success('成功');
  615. }else{
  616. $this->error('失败');
  617. }
  618. }
  619. //制程检验记录->指标检验
  620. public function ProcessInspectionRecords()
  621. {
  622. if ($this->request->isGet() === false){
  623. $this->error('请求错误');
  624. }
  625. $param = $this->request->param();
  626. if (empty($param)){
  627. $this->error('参数错误');
  628. }
  629. // $filed = ''
  630. }
  631. /**
  632. * 管理人员现场巡检记录->展示
  633. * @ApiMethod (GET)
  634. * @param void
  635. * @return void
  636. * @throws \think\db\exception\DataNotFoundException
  637. * @throws \think\db\exception\ModelNotFoundException
  638. * @throws \think\exception\DbException
  639. */
  640. public function FieldInspectionRecord()
  641. {
  642. if ($this->request->isGet() === false){
  643. $this->error('请求错误');
  644. }
  645. $param = $this->request->param();
  646. if (empty($param)){
  647. $this->error('参数错误');
  648. }
  649. $date = date('Y-m-d H:i:s',time());
  650. if (empty($param['start'])){
  651. $startTime = date('Y-m-d 08:30:00',time());
  652. }else{
  653. $startTime = $param['start'];
  654. }
  655. if ($date<$startTime){
  656. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  657. }
  658. $where = [
  659. '工单编号' => $param['workOrder'],
  660. '开工时间' => $startTime,
  661. '类别' => '现场巡查记录',
  662. '班组编号' => $param['team']
  663. ];
  664. $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
  665. rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
  666. rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
  667. $list = \db('制程检验_记录')->where($where)
  668. ->field($filed)
  669. ->select();
  670. if (empty($list)){
  671. $this->success('',[]);
  672. }
  673. foreach ($list as $key=>$value){
  674. $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
  675. $list[$key]['归属时段'] = $value['开工时间'];
  676. $list[$key]['分钟差数'] = $number;
  677. if ($number != 0){
  678. $list[$key]['归属时段'] = date('Y-m-d H:i:s',strtotime($value['开工时间'])+$number*15*60);
  679. }
  680. }
  681. $this->success('成功',$list);
  682. }
  683. /**
  684. * 管理人员现场巡检记录->添加
  685. * @ApiMethod (POST)
  686. * @param void
  687. * @return void
  688. */
  689. public function FieldInspectionRecordAdd()
  690. {
  691. if (Request::instance()->isPost() === false){
  692. $this->error('请求错误');
  693. }
  694. $param = Request::instance()->post();
  695. if (empty($param)){
  696. $this->error('参数错误');
  697. }
  698. if ($param['processCode']<10){
  699. $param['processCode'] = '0'.$param['processCode'];
  700. }
  701. $date = date('Y-m-d H:i:s',time());
  702. $startTime = date('Y-m-d 08:30:00',time());
  703. if ($date<$startTime){
  704. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  705. }
  706. $data = [
  707. '类别' => $param['category'],
  708. '工单编号' => $param['workOrder'],
  709. '印件号' => $param['printCode'],
  710. '工序名称' => $param['processCode'].'-'.$param['process'],
  711. '流程单号' => $param['flowCode'],
  712. '设备编号' => $param['machine'],
  713. '班组编号' => $param['team'],
  714. '检验项目' => '['.$param['employeeCode'].'/'.$param['employeeName'].']',
  715. '相关标准' => '',
  716. '量测仪器' => '',
  717. '检验结果' => '',
  718. '检验备注' => $param['remark'],
  719. '提交时间' => date('Y-m-d H:i:s',time()),
  720. '开工时间' => $startTime,
  721. 'sys_id' => '',
  722. 'sys_rq' => date('Y-m-d H:i:s',time()),
  723. 'mod_rq' => '',
  724. 'UniqId' => \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
  725. ];
  726. $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
  727. $res = Db::query($sql);
  728. if ($res !== false){
  729. $this->success('成功');
  730. }else{
  731. $this->error('失败');
  732. }
  733. }
  734. /**
  735. * 设备点检->左侧菜单栏
  736. * @ApiMethod (GET)
  737. * @param void
  738. * @return void
  739. */
  740. public function SpotCheckItem()
  741. {
  742. if ($this->request->isGet() === false){
  743. $this->error('请求错误');
  744. }
  745. $param = $this->request->param();
  746. if (empty($param)){
  747. $this->error('参数错误');
  748. }
  749. $list = \db('设备_点检项目')
  750. ->where('适用机型','LIKE','%;'.$param['machine'].';%')
  751. ->distinct(true)
  752. ->column('部件名称','部件编号');
  753. if (empty($list)){
  754. $this->success('');
  755. }
  756. $this->success('成功',$list);
  757. }
  758. /**
  759. * 设备点检->检测项目
  760. * @ApiMethod (GET)
  761. * @param void
  762. * @return void
  763. * @throws \think\db\exception\DataNotFoundException
  764. * @throws \think\db\exception\ModelNotFoundException
  765. * @throws \think\exception\DbException
  766. */
  767. public function InspectionItem()
  768. {
  769. if ($this->request->isGet() === false){
  770. $this->error('请求错误');
  771. }
  772. $param = $this->request->param();
  773. if (empty($param)){
  774. $this->error('参数错误');
  775. }
  776. $list = \db('设备_点检项目')
  777. ->where('部件名称',$param['unitName'])
  778. ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
  779. ->select();
  780. if (empty($list)){
  781. $this->success('未找到检测项目');
  782. }
  783. $this->success('成功',$list);
  784. }
  785. /**
  786. * 设备点检->检测记录添加
  787. * @ApiMethod (POST)
  788. * @param void
  789. * @return void
  790. * @throws \think\db\exception\DataNotFoundException
  791. * @throws \think\db\exception\ModelNotFoundException
  792. * @throws \think\exception\DbException
  793. */
  794. public function InspectionItemAdd()
  795. {
  796. if (Request::instance()->isPost() === false){
  797. $this->error('请求错误');
  798. }
  799. $param = Request::instance()->post();
  800. if (empty($param)){
  801. $this->error('参数错误');
  802. }
  803. $lastNumber = \db("设备_点检记录")->field('Uniqid as ID')->order('Uniqid desc')->find()['ID'];
  804. if ((int)$lastNumber>10000000){
  805. $lastId = $lastNumber;
  806. }else{
  807. $lastId = 10000000;
  808. }
  809. $row = [];
  810. foreach ($param as $key=>$value){
  811. $unitCode = \db('设备_点检项目')->where('部件名称',$value['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
  812. $row[$key] = [
  813. '日期' => date('Y-m-d 00:00:00',time()),
  814. '班组编号' => $value['team'],
  815. '点检设备' => $value['machine'],
  816. '部件编号' => $unitCode['部件编号'],
  817. '部件名称' => $value['unitName'],
  818. '检验项目' => $value['itemName'],
  819. '判定标准' => $value['standard'],
  820. '点检方法' => $value['method'],
  821. '点检结果' => $value['status'],
  822. '备注说明' => $value['remark'],
  823. 'Sys_id' =>'',
  824. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  825. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  826. 'Uniqid' => $lastId+$key+1
  827. ];
  828. }
  829. $sql = \db('设备_点检记录')->fetchSql(true)->insertAll($row);
  830. $res = Db::query($sql);
  831. if ($res !== false){
  832. $this->success('成功');
  833. }else{
  834. $this->error('失败');
  835. }
  836. }
  837. /**
  838. * 机台印版领用->左侧菜单
  839. * @ApiMethod (GET)
  840. * @param void
  841. * @return void
  842. */
  843. public function PrintGetTab()
  844. {
  845. if ($this->request->isGet() === false){
  846. $this->error('请求错误');
  847. }
  848. $param = $this->request->param();
  849. if (empty($param)){
  850. $this->error('参数错误');
  851. }
  852. $productCode = $param['productCode'];
  853. $sql = "SELECT DISTINCT(RTRIM(b.`名称`)) as `印版分类`,RTRIM(b.`编号`) as `编号` FROM `产品_印版资料` as a
  854. JOIN `物料_存货结构` as b ON b.`编号` = SUBSTRING(a.`存货编码`,1,4)
  855. WHERE a.YB_Cpdh = '{$productCode}'";
  856. $res = Db::query($sql);
  857. if (empty($res)){
  858. $this->success('');
  859. }
  860. $this->success('成功',$res);
  861. }
  862. /**
  863. * 机台印版领用记录->数据详情
  864. * @ApiMethod (GET)
  865. * @param void
  866. * @return void
  867. */
  868. public function PrintDetail()
  869. {
  870. if ($this->request->isGet() === false){
  871. $this->error('请求失败');
  872. }
  873. $param = $this->request->param();
  874. if (empty($param)){
  875. $this->error('参数错误');
  876. }
  877. $productCode = $param['productCode'];
  878. $code = $param['code'].'%';
  879. $workOrder = $param['workOrder'];
  880. $sql = "SELECT
  881. RTRIM(a.`存货编码`) as `存货编码`,
  882. RTRIM(c.`物料名称`) as `存货名称`,
  883. RTRIM(b.`印版名称`) as `印版名称`,
  884. RTRIM(b.`供方批号`) as `供方批号`,
  885. RTRIM(b.`制造日期`) as `制造日期`,
  886. SUM(d.`Yb_印数`) as `印数`,
  887. RTRIM(e.`名称`) as `印版类别`,
  888. SUBSTRING(a.YB_Cpdh,1,4) as `客户编号`,
  889. RTRIM(f.`Gd_客户名称`) as `客户名称`,
  890. RTRIM(a.YB_Cpdh) as `产品编号`,
  891. RTRIM(f.Gd_cpmc) as `产品名称`
  892. FROM `产品_印版资料` as a
  893. LEFT JOIN `产品_印版库` as b ON b.`存货编码` = a.`存货编码`
  894. JOIN `物料_存货编码` as c ON c.`物料代码` = a.`存货编码`
  895. LEFT JOIN `工单_印版领用记录` as d ON d.`Yb_供方批号` = b.`供方批号`
  896. JOIN `物料_存货结构` as e ON e.`编号` = SUBSTRING(a.`存货编码`,1,4)
  897. JOIN `工单_基本资料` as f ON a.YB_Cpdh = f.Gd_cpdh
  898. WHERE a.YB_Cpdh = '{$productCode}'
  899. AND a.`存货编码` LIKE '{$code}'
  900. AND f.Gd_gdbh = '{$workOrder}'
  901. AND b.`报废日期` = '1900-01-01 00:00:00'
  902. GROUP BY b.`供方批号`
  903. ORDER BY a.`存货编码`";
  904. $list = Db::query($sql);
  905. if (empty($list)){
  906. $this->success('');
  907. }
  908. $this->success('成功',$list);
  909. }
  910. //换型清场记录->左侧菜单栏
  911. public function remodelGetTab()
  912. {
  913. if ($this->request->isGet() === false){
  914. $this->error('请求错误');
  915. }
  916. $date = date('Y-m-d 00:00:00',time()-3888000);
  917. $nowTime = date('Y-m-d H:i:s',time());
  918. $list = \db('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
  919. if (empty($list)){
  920. $this->error('失败');
  921. }
  922. $sql = "SELECT RTRIM(a.`设备编号`) as `设备编号`,RTRIM(b.`日期`) as `日期`,RTRIM(b.UniqId) as UniqId FROM `设备_基本资料` as a
  923. LEFT JOIN `制程_换型清场` as b ON b.`机台编号` = a.`设备编号`
  924. WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' ORDER BY b.`日期`";
  925. $res = Db::query($sql);
  926. $data = [];
  927. foreach ($list as $key=>$value){
  928. $i=0;
  929. $data[$value] = [];
  930. foreach ($res as $k=>$v){
  931. $row = [];
  932. if ($value === $v['设备编号']){
  933. $row[$i] = [
  934. '日期' => $v['日期'],
  935. 'id' => $v['UniqId']
  936. ];
  937. $i++;
  938. foreach ($row as $vv){
  939. }
  940. array_push($data[$value],$row);
  941. }
  942. }
  943. }
  944. $this->success('成功',$data);
  945. }
  946. /**
  947. * 换型清场->详情
  948. * @return void
  949. * @throws \think\db\exception\DataNotFoundException
  950. * @throws \think\db\exception\ModelNotFoundException
  951. * @throws \think\exception\DbException
  952. */
  953. public function RemodelDetail()
  954. {
  955. if ($this->request->isGet() === false){
  956. $this->error('请求错误');
  957. }
  958. $param = $this->request->param();
  959. if (empty($param)){
  960. $this->error('参数错误');
  961. }
  962. $field = 'rtrim(日期) as 日期,rtrim(班组) as 班组,rtrim(机台编号) as 机台编号,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  963. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包B,
  964. rtrim(清场项目A) as 项目1,rtrim(清场项目B) as 项目2,rtrim(清场项目C) as 项目3,rtrim(清场项目D) as 项目4,rtrim(清场项目E) as 项目5,
  965. rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
  966. $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
  967. if (empty($list)){
  968. $this->success('未找到该条清场记录');
  969. }
  970. $list['日期'] = date('Y-m-d',strtotime($list['日期']));
  971. $list['印件名称A'] = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
  972. $list['印件名称B'] = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
  973. $this->success('成功',$list);
  974. }
  975. //换型清场->当前清场记录
  976. public function ModelChangeRecord()
  977. {
  978. if ($this->request->isGet() === false){
  979. $this->error('请求错误');
  980. }
  981. $param = $this->request->param();
  982. if (empty($param)){
  983. $this->error('参数错误');
  984. }
  985. $date = date('Y-m-d 00:00:00',time()-3888000);
  986. $nowTime = date('Y-m-d H:i:s',time());
  987. $where = [
  988. '日期' =>['between',[$nowTime,$date]],
  989. ];
  990. }
  991. /**
  992. * 车间机台状态列表展示
  993. * @ApiMethod (GET)
  994. * @param void
  995. * @return void
  996. * @throws \think\db\exception\BindParamException
  997. * @throws \think\exception\PDOException
  998. */
  999. public function MachineDetailList()
  1000. {
  1001. if ($this->request->isGet() === false){
  1002. $this->error('请求错误');
  1003. }
  1004. $param = $this->request->param();
  1005. if (empty($param)){
  1006. $this->error('参数错误');
  1007. }
  1008. $workshop = $param['workshop'];
  1009. $sql = "SELECT
  1010. RTRIM( a.`设备编号` ) AS 设备编号,
  1011. RTRIM( a.`设备名称` ) AS 设备名称,
  1012. RTRIM( d.`当前状态` ) AS 状态
  1013. FROM
  1014. `设备_基本资料` AS a
  1015. JOIN (
  1016. SELECT
  1017. b.`设备编号`,
  1018. b.`当前状态`,
  1019. b.`开工时间`
  1020. FROM
  1021. `设备_产量采集` AS b
  1022. JOIN ( SELECT `设备编号`, MAX( `开工时间` ) AS `最新开工时间` FROM `设备_产量采集` GROUP BY `设备编号` ) AS c ON b.`设备编号` = c.`设备编号`
  1023. AND b.`开工时间` = c.`最新开工时间`
  1024. ) AS d ON a.`设备编号` = d.`设备编号`
  1025. WHERE
  1026. a.`使用部门` = '{$workshop}'
  1027. GROUP BY
  1028. a.`设备编号`";
  1029. $list = \db()->query($sql);
  1030. foreach ($list as $key=>$value){
  1031. if ($value['状态'] == ''){
  1032. $list[$key]['状态'] = '待单';
  1033. }
  1034. }
  1035. $this->success('成功',$list);
  1036. }
  1037. /**
  1038. * 机台当前参数展示
  1039. * @ApiMethod (GET)
  1040. * @return void
  1041. * @throws \think\db\exception\DataNotFoundException
  1042. * @throws \think\db\exception\ModelNotFoundException
  1043. * @throws \think\exception\DbException
  1044. */
  1045. public function MachineDetail()
  1046. {
  1047. if ($this->request->isGet() === false){
  1048. $this->error('请求错误');
  1049. }
  1050. $param = $this->request->param();
  1051. if (empty($param)){
  1052. $this->error('参数错误');
  1053. }
  1054. $data = [];
  1055. //机台状态时间
  1056. $startTime = \db('设备_产量采集')
  1057. ->where('设备编号',$param['machine'])
  1058. ->where('开工时间',$param['start'])
  1059. ->field('rtrim(时间) as 时间,当班产量,rtrim(当前状态) as 状态,MAX(时间) as 最大时间,MAX(当班产量) as 最大产量')
  1060. ->order('UniqId')
  1061. ->group('当前状态')
  1062. ->find();
  1063. if (!empty($startTime)){
  1064. $timeDifference = round((strtotime($startTime['最大时间'])-strtotime($startTime['时间']))/3600,2);
  1065. $data['timeDifference'] = $timeDifference;
  1066. $data['field'] = $startTime['最大产量']-$startTime['当班产量'];
  1067. }else{
  1068. $data['timeDifference'] = 0;
  1069. $data['field'] = 0;
  1070. }
  1071. //机台产能/时间明细
  1072. $row = \db('设备_产量采集')
  1073. ->where('设备编号',$param['machine'])
  1074. ->where('开工时间',$param['start'])
  1075. ->field('rtrim(时间) as 时间,rtrim(当班产量) as 产量,rtrim(当前状态) as 状态')
  1076. ->select();
  1077. if (empty($row)){
  1078. $data['row'] = '';
  1079. }
  1080. foreach ($row as $key=>$value){
  1081. $data['row'][$key]['时间'] = date('Y-m-d H:i',strtotime($value['时间']));
  1082. $data['row'][$key]['状态'] = $value['状态'];
  1083. if ($key<2){
  1084. $data['row'][$key]['产能'] = 0;
  1085. }else{
  1086. $data['row'][$key]['产能'] = ($row[$key-1]['产量']-$row[$key-2]['产量'])*60;
  1087. }
  1088. }
  1089. //机台状态
  1090. $status = end($row);
  1091. if (empty($status['状态'])){
  1092. $data['status'] = '待单';
  1093. }else{
  1094. $data['status'] = $status['状态'];
  1095. }
  1096. //检验数据
  1097. $list = \db('制程检验_记录')
  1098. ->where('开工时间',$param['start'])
  1099. ->where('设备编号',$param['machine'])
  1100. ->where('sys_rq','>',$param['start'])
  1101. ->field('rtrim(类别) as 类别,提交时间')
  1102. ->select();
  1103. $data['首件'] = $data['自检'] = $data['IPQC'] = [];
  1104. if (empty($list)){
  1105. $this->success('未找到检验记录');
  1106. }
  1107. foreach ($list as $key=>$value){
  1108. if ($value['类别'] == '现场巡查记录'){
  1109. array_push($data['首件'],$value['提交时间']);
  1110. }
  1111. if ($value['类别'] == '机台自检'){
  1112. array_push($data['自检'],$value['提交时间']);
  1113. }
  1114. if ($value['类别'] == 'IPQC检验'){
  1115. array_push($data['IPQC'],$value['提交时间']);
  1116. }
  1117. }
  1118. $data['首件'] = array_values(array_unique($data['首件']));
  1119. $data['自检'] = array_values(array_unique($data['自检']));
  1120. $data['IPQC'] = array_values(array_unique($data['IPQC']));
  1121. $this->success('成功',$data);
  1122. }
  1123. }