Facility.php 50 KB

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