Facility.php 46 KB

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