Facility.php 46 KB

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