Facility.php 57 KB

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