Facility.php 58 KB

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