Facility.php 46 KB

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