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