Facility.php 48 KB

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