Facility.php 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813
  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,rtrim(UniqId) as UniqId';
  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. ->select();
  157. if (empty($list)){
  158. $this->success('未找到检验记录');
  159. }
  160. $data = [];
  161. foreach ($list as $key=>$value)
  162. {
  163. $data['item'][$key] = $value['检验项目'];
  164. $data['InspectionTime'][$key] = date('H:i',strtotime($value['提交时间']));
  165. $data['工单编号'][$key] = $value['工单编号'];
  166. }
  167. $data['item'] = array_unique($data['item']);
  168. $data['InspectionTime'] = array_values(array_unique($data['InspectionTime']));
  169. $data['工单编号'] = array_values(array_unique($data['工单编号']));
  170. foreach ($data['工单编号'] as $key => $value){
  171. foreach ($data['item'] as $k=>$v){
  172. $time = '';
  173. foreach ($list as $kk=>$vv){
  174. if ($vv['工单编号'] === $value && $vv['检验项目'] === $v){
  175. $time = $time.date('H:i',strtotime($vv['提交时间'])).',';
  176. $data['row'][$key][$k] = [
  177. '工单编号' => $value,
  178. '印件号' => $vv['印件号'],
  179. '工序名称' => $vv['工序名称'],
  180. '检验项目' => $v,
  181. 'time' => substr($time,0,-1),
  182. ];
  183. }
  184. }
  185. }
  186. $data['row'][$key] = array_values($data['row'][$key]);
  187. }
  188. unset($data['item'],$data['工单编号']);
  189. $this->success('成功',$data);
  190. }
  191. /**
  192. * 设备生产中工单信息
  193. * @ApiMethod (GET)
  194. * @param string $machine 机台编号
  195. * @return void
  196. * @throws \think\Exception
  197. * @throws \think\db\exception\DataNotFoundException
  198. * @throws \think\db\exception\ModelNotFoundException
  199. * @throws \think\exception\DbException
  200. */
  201. public function Production()
  202. {
  203. if (Request::instance()->isGet() == false) {
  204. $this->error('非法请求');
  205. }
  206. $params = Request::instance()->param();
  207. if (!isset($params['machine']) || empty($params['machine'])) {
  208. $this->error('参数错误');
  209. }
  210. $machine = $params['machine'];
  211. $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
  212. $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  213. if (empty($data)){
  214. $this->success('未找到生产订单');
  215. }
  216. if (rtrim($data['工单编号']) === '' || rtrim($data['工单编号']) === null ){
  217. $this->success('未找到生产订单');
  218. }
  219. $endTime = \db('工单_工艺资料')
  220. ->where('Gy0_gdbh',$data['工单编号'])
  221. ->where('Gy0_gxh',$data['工序号'])
  222. ->where('Gy0_sbbh','like','%'.$machine.'%')
  223. ->find();
  224. $list = [];
  225. if ($endTime['PD_WG'] === '1900-01-01 00:00:00'){
  226. $list['工单编号'] = $data['工单编号'];
  227. $list['印件号'] = $data['印件号'];
  228. $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
  229. $list['产品名称'] = rtrim($name);
  230. $where['Gy0_gdbh'] = $data['工单编号'];
  231. $where['Gy0_yjno'] = $data['印件号'];
  232. $where['Gy0_gxh'] = $data['工序号'];
  233. $gxmc = \db('工单_工艺资料')->where($where)->find();
  234. if ((int)$gxmc['Gy0_gxh']<10){
  235. $gxmc['Gy0_gxh'] = '0'.rtrim($gxmc['Gy0_gxh']);
  236. }
  237. if ($gxmc['Add_gxmc'] !== ''){
  238. $printName = rtrim($gxmc['Gy0_gxh']).'-'.rtrim($gxmc['Gy0_gxmc']).'【'.rtrim($gxmc['Add_gxmc']).'】';
  239. }else{
  240. $printName = rtrim($gxmc['Gy0_gxh']).'-'.rtrim($gxmc['Gy0_gxmc']);
  241. }
  242. $list['工序名称'] = $printName;
  243. }else{
  244. $list['工单编号'] = '';
  245. $list['印件号'] = 0;
  246. $list['产品名称'] = '';
  247. $list['工序名称'] = '';
  248. }
  249. $list['状态'] = rtrim($data['当前状态']);
  250. $list['班组编号'] = rtrim($data['班组编号']);
  251. $list['班组Id'] = rtrim($data['班组ID']);
  252. $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,
  253. 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,
  254. rtrim(sczl_bh10) as bh10")->find();
  255. $row = [];
  256. for ($i=1;$i<11;$i++) {
  257. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  258. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  259. $row[$i] = [
  260. '编号' => $class['bh' . $i],
  261. '姓名' => $name['姓名']
  262. ];
  263. }
  264. }
  265. $row = array_values($row);
  266. $list['班组成员'] = $row;
  267. $list['定额代号'] = $machineCode;
  268. $this->success('成功',$list);
  269. }
  270. /**
  271. * 设备工作清单
  272. * @ApiMethod (GET)
  273. * @param string $machine 机台编号
  274. * @return void
  275. * @throws \think\db\exception\DataNotFoundException
  276. * @throws \think\db\exception\ModelNotFoundException
  277. * @throws \think\exception\DbException
  278. */
  279. public function EquipmentWorklist()
  280. {
  281. if ($this->request->isGet() === false){
  282. $this->error('请求错误');
  283. }
  284. $machine = input('machine');
  285. if (empty($machine)){
  286. $this->error('参数错误');
  287. }
  288. $sql = "SELECT
  289. rtrim( b.Gy0_gdbh ) AS gdbh,
  290. rtrim(b.质量要求) AS 质量信息,
  291. rtrim( b.Gy0_yjno ) AS yjno,
  292. rtrim( b.Gy0_gxh ) AS gxh,
  293. rtrim( b.Gy0_gxmc ) AS gxmc,
  294. rtrim( b.Add_gxmc ) AS add_gxmc,
  295. rtrim( b.Gy0_辅助工时 ) AS 装版时数,
  296. rtrim( b.Gy0_小时产能 ) AS 工序产能,
  297. rtrim( b.Gy0_生产工时 ) AS 计划工时,
  298. rtrim( b.Gy0_sj1 ) AS sj1,
  299. rtrim( b.Gy0_sj2 ) AS sj2,
  300. rtrim(b.工序备注) AS 排产备注,
  301. RTRIM(d.yj_yjmc) AS 印件名称,
  302. RTRIM(a.Gd_cpmc) AS 产品名称,
  303. RTRIM(a.成品代号) AS 产品代号,
  304. SUM(E.sczl_cl) AS 已完成,
  305. rtrim(b.Gy0_计划接货数) AS 计划接货数,
  306. RTRIM(b.Gy0_ls) AS ls ,
  307. rtrim(b.Gy0_班次安排) AS 班组,
  308. rtrim(b.UniqId) AS UniqId,
  309. rtrim(b.Gy0_最早开工时间) AS 最早开工时间
  310. FROM
  311. `工单_基本资料` AS a
  312. JOIN `工单_工艺资料` AS b ON a.Gd_gdbh = b.Gy0_gdbh
  313. JOIN `工单_印件资料` AS d ON a.Gd_gdbh = d.Yj_Gdbh
  314. LEFT JOIN `设备_产量计酬` AS e ON e.sczl_gdbh = a.Gd_gdbh AND e.sczl_jtbh = b.Gy0_sbbh
  315. WHERE
  316. a.gd_statu = '2-生产中'
  317. AND a.`行号` = '1'
  318. AND b.Gy0_sbbh = '{$machine}'
  319. AND b.PD_WG = '1900-01-01 00:00:00'
  320. AND b.Gy0_sj1 <> '1900-01-01 00:00:00'
  321. GROUP BY a.Gd_gdbh
  322. ORDER BY b.Gy0_sj1";
  323. $orderList = Db::query($sql);
  324. if (empty($orderList)){
  325. $this->success('未找到排产工单');
  326. }
  327. foreach ($orderList as $key=>$value){
  328. $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
  329. if ($value['yjno']<10){
  330. $orderList[$key]['yjno'] = '0'.$value['yjno'];
  331. }
  332. if ($value['gxh']<10){
  333. $orderList[$key]['gxh'] = '0'.$value['gxh'];
  334. }
  335. $orderList[$key]['印件资料'] = $orderList[$key]['yjno'].'-'.$value['印件名称'];
  336. $orderList[$key]['工序名称'] = $orderList[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  337. $orderList[$key]['计划产量/已完成'] = (int)($value['计划接货数']/$value['ls']).'/'.$value['已完成']=null?'':(int)$value['已完成'];
  338. $orderList[$key]['计划生产时段'] =substr($value['sj1'],5,5).' '.substr($value['sj1'],11,5).'<-->'.substr($value['sj2'],5,5).' '.substr($value['sj2'],11,5);
  339. unset($orderList[$key]['gdbh'],$orderList[$key]['质量信息'],$orderList[$key]['yjno'],$orderList[$key]['gxh'],$orderList[$key]['gxmc'],$orderList[$key]['add_gxmc'],$orderList[$key]['计划接货数'],$orderList[$key]['已完成'],$orderList[$key]['印件名称'],$orderList[$key]['ls']);
  340. }
  341. $this->success('成功',$orderList);
  342. }
  343. /**
  344. * 工序、印件、完成数量
  345. * @ApiMethod (GET)
  346. * @param string $workOrder 工单编号
  347. * @return void
  348. * @throws \think\Exception
  349. * @throws \think\db\exception\DataNotFoundException
  350. * @throws \think\db\exception\ModelNotFoundException
  351. * @throws \think\exception\DbException
  352. */
  353. public function Procedure()
  354. {
  355. if ($this->request->isGet() === false){
  356. $this->error('请求错误');
  357. }
  358. $workOrder = input('Gd_gdbh');
  359. if (empty($workOrder)){
  360. $this->error('参数错误');
  361. }
  362. //右边工艺及完成数量
  363. $Process = \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  364. ->distinct(true)->order('sczl_gxh')
  365. ->column('sczl_gxh');
  366. $data = [];
  367. foreach ($Process as $k=>$v){
  368. $res= \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  369. ->where('sczl_gxh',$v)
  370. ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
  371. ->find();
  372. if ($res['sczl_yjno']<10){
  373. $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
  374. }
  375. $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
  376. $processList['completed'] = \db('设备_产量计酬')
  377. ->where('sczl_gdbh',$workOrder)
  378. ->where('sczl_gxh',$v)
  379. ->count();
  380. array_push($data,$processList);
  381. }
  382. $this->success('成功',$data);
  383. }
  384. /**
  385. * 班组人员及分配比例
  386. * @ApiMethod (GET)
  387. * @param string $machine 机台编号
  388. * @return void
  389. * @throws \think\db\exception\DataNotFoundException
  390. * @throws \think\db\exception\ModelNotFoundException
  391. * @throws \think\exception\DbException
  392. */
  393. public function Team()
  394. {
  395. if ($this->request->isGet() === false){
  396. $this->error('请求错误');
  397. }
  398. $machine = input('machine');
  399. if (empty($machine)){
  400. $this->error('参数错误');
  401. }
  402. $where = [
  403. 'sczl_jtbh' => $machine,
  404. ];
  405. $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,
  406. 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,
  407. 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,
  408. rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,
  409. rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10,rtrim(UniqId) as ID';
  410. $team = \db('设备_产量计酬')
  411. ->where('sczl_jtbh',$machine)
  412. ->field($field)
  413. ->order('UniqId desc')
  414. ->find();
  415. $list = \db('设备_班组资料')->where($where)->field($field)->select();
  416. $data = [];
  417. foreach ($list as $k=>$v){
  418. if ($team == $v){
  419. $data[$k]['status'] = 1;
  420. }else{
  421. $data[$k]['status'] = 0;
  422. }
  423. $data[$k]['ID'] = $v['ID'];
  424. $data[$k]['班组号'] = $v['班组号'];
  425. for ($i=1;$i<11;$i++){
  426. if ($v['bh'.$i] != '' && $v['bh'.$i] != '000000'){
  427. $name = \db('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
  428. $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
  429. }
  430. }
  431. }
  432. $this->success('成功',$data);
  433. }
  434. /**
  435. * 当班产量明细
  436. * @ApiMethod (GET)
  437. * @param string $machine 机台编号
  438. * @param string $workOrder 工单编号
  439. * @param string $team 班次
  440. * @return void
  441. * @throws \think\db\exception\DataNotFoundException
  442. * @throws \think\db\exception\ModelNotFoundException
  443. * @throws \think\exception\DbException
  444. */
  445. public function OutputDetail()
  446. {
  447. if ($this->request->isGet() === false){
  448. $this->error('请求错误');
  449. }
  450. $machine = input('machine');
  451. $workOrder = input('Gd_gdbh');
  452. $team = input('team');
  453. if (empty($machine) || empty($workOrder) || empty($team)){
  454. $this->success('');
  455. }
  456. $name = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(Gd_cpmc) as productName')->find();
  457. $where = [
  458. 'sczl_gdbh' => $workOrder,
  459. 'sczl_jtbh' => $machine,
  460. 'sczl_bzdh' => $team,
  461. ];
  462. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as 标牌号,rtrim(sczl_cl) as 产量,
  463. rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,rtrim(sczl_装版工时) as 装版工时,
  464. rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常停机工时,rtrim(sczl_设备运行工时) as 通电工时,
  465. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
  466. rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2';
  467. $list = \db('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
  468. if (empty($list)){
  469. $this->success('');
  470. }
  471. foreach ($list as $k=>$v){
  472. if ($v['yjno']<10){
  473. $list[$k]['yjno'] = '0'.$v['yjno'];
  474. }
  475. $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
  476. $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
  477. $list[$k]['产品名称'] = $name['productName'];
  478. unset($list[$k]['yjno'],$list[$k]['gxmc'],$list[$k]['sj1'],$list[$k]['sj2']);
  479. }
  480. $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
  481. SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
  482. SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
  483. SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
  484. $total = \db('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
  485. $total[0]['版数'] = count($list);
  486. $list['total'] = $total[0];
  487. $this->success('成功',$list);
  488. }
  489. /**
  490. * 检验记录
  491. * @ApiMethod (GET)
  492. * @param string $machine 机台编号
  493. * @param string $workOrder 工单编号
  494. * @param string $team 班次
  495. * @return void
  496. * @throws \think\db\exception\DataNotFoundException
  497. * @throws \think\db\exception\ModelNotFoundException
  498. * @throws \think\exception\DbException
  499. */
  500. public function InspectionRecord()
  501. {
  502. if ($this->request->isGet() === false){
  503. $this->error('请求失败');
  504. }
  505. $machine = input('machine');
  506. $workOrder = input('Gd_gdbh');
  507. $team = input('team');
  508. if (empty($machine) || empty($workOrder) || empty($team)){
  509. $this->success('');
  510. }
  511. $where = [
  512. '设备编号' => $machine,
  513. '工单编号' => $workOrder,
  514. '班组编号' => $team,
  515. '类别' => ['in',['IPQC检验','机台检验']],
  516. ];
  517. //检验项目筛选
  518. $item = \db('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
  519. //检验时间
  520. $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
  521. foreach ($InspectionTime as $k=>$v){
  522. $InspectionTime[$k] = date('H:i',strtotime($v));
  523. }
  524. //检测记录详情
  525. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
  526. $nameDetail = \db('制程检验_记录')->where($where)->field($field)->find();
  527. $data = [];
  528. //检测数据
  529. foreach ($item as $key=>$value){
  530. $SubmissionTime = \db('制程检验_记录')->where($where)
  531. ->where('检验项目',$value)
  532. ->where('检验结果','合格')
  533. ->field('rtrim(提交时间) as 提交时间')
  534. ->select();
  535. $time = [];
  536. foreach ($SubmissionTime as $k=>$v){
  537. $time[$k] = date('H:i',strtotime($v['提交时间']));
  538. }
  539. $data[$key] = [
  540. '工单编号' => $nameDetail['工单编号'],
  541. '印件号' => $nameDetail['印件号'],
  542. '工序名称' => $nameDetail['工序名称'],
  543. '检验项目' => $value,
  544. 'inspectresult' => implode(',',$time),
  545. ];
  546. }
  547. $data['inspectiontime'] = $InspectionTime;
  548. $this->success('成功',$data);
  549. }
  550. /**
  551. * 班组维护->班组添加
  552. * @ApiMethod (GET)
  553. * @param void
  554. * @return void
  555. * @throws \think\db\exception\DataNotFoundException
  556. * @throws \think\db\exception\ModelNotFoundException
  557. * @throws \think\exception\DbException
  558. */
  559. public function MachineTeamAdd()
  560. {
  561. if (Request::instance()->isPost() === false ){
  562. $this->error('请求错误');
  563. }
  564. $param = Request::instance()->post();
  565. if (empty($param)){
  566. $this->error('参数错误');
  567. }
  568. $lastId = \db('设备_班组资料')
  569. ->order('UniqId desc')
  570. ->value('UniqId');
  571. if ($lastId<100000){
  572. $lastId = 1000000;
  573. }
  574. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  575. $param['UniqId'] = $lastId + 1;
  576. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  577. $sql = \db('设备_班组资料')->fetchSql(true)->insert($param);
  578. $res = \db()->query($sql);
  579. if ($res !== false){
  580. $this->success('成功');
  581. }else{
  582. $this->error('失败');
  583. }
  584. }
  585. /**
  586. * 机台编号列表
  587. * @ApiMethod (GET)
  588. * @return void
  589. */
  590. public function MachineList()
  591. {
  592. if ($this->request->isGet() === false){
  593. $this->error('请求错误');
  594. }
  595. $list = \db('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  596. if (empty($list)){
  597. $this->success('未找到机台编号');
  598. }
  599. $data = [];
  600. foreach ($list as $key=>$value){
  601. $data[$key] = $value['设备编号'] . '||' . $value['设备名称'];
  602. }
  603. $this->success('成功',$data);
  604. }
  605. /**
  606. * 删除班组信息
  607. * @ApiMethod (GET)
  608. * @param void
  609. * @return void
  610. * @throws \think\Exception
  611. * @throws \think\exception\PDOException
  612. */
  613. public function teamDel()
  614. {
  615. if (Request::instance()->isPost() === false){
  616. $this->error('请求错误');
  617. }
  618. $param = Request::instance()->post();
  619. if (empty($param)){
  620. $this->error('参数错误');
  621. }
  622. $res = \db('设备_班组资料')
  623. ->where('UniqId',$param['UniqId'])
  624. ->delete();
  625. if ($res !== false){
  626. $this->success('成功');
  627. }else{
  628. $this->error('失败');
  629. }
  630. }
  631. /**
  632. * 管理人员现场巡检记录->展示
  633. * @ApiMethod (GET)
  634. * @param void
  635. * @return void
  636. * @throws \think\db\exception\DataNotFoundException
  637. * @throws \think\db\exception\ModelNotFoundException
  638. * @throws \think\exception\DbException
  639. */
  640. public function FieldInspectionRecord()
  641. {
  642. if ($this->request->isGet() === false){
  643. $this->error('请求错误');
  644. }
  645. $param = $this->request->param();
  646. if (empty($param)){
  647. $this->error('参数错误');
  648. }
  649. $date = date('Y-m-d H:i:s',time());
  650. if (empty($param['start'])){
  651. $startTime = date('Y-m-d 08:30:00',time());
  652. }else{
  653. $startTime = $param['start'];
  654. }
  655. if ($date<$startTime){
  656. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  657. }
  658. $where = [
  659. '工单编号' => $param['workOrder'],
  660. '开工时间' => $startTime,
  661. '类别' => '现场巡查记录',
  662. '班组编号' => $param['team']
  663. ];
  664. $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
  665. rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
  666. rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
  667. $list = \db('制程检验_记录')->where($where)
  668. ->field($filed)
  669. ->select();
  670. if (empty($list)){
  671. $this->success('',[]);
  672. }
  673. foreach ($list as $key=>$value){
  674. $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
  675. $list[$key]['归属时段'] = $value['开工时间'];
  676. $list[$key]['分钟差数'] = $number;
  677. if ($number != 0){
  678. $list[$key]['归属时段'] = date('Y-m-d H:i:s',strtotime($value['开工时间'])+$number*15*60);
  679. }
  680. }
  681. $this->success('成功',$list);
  682. }
  683. /**
  684. * 管理人员现场巡检记录->添加
  685. * @ApiMethod (POST)
  686. * @param void
  687. * @return void
  688. */
  689. public function FieldInspectionRecordAdd()
  690. {
  691. if (Request::instance()->isPost() === false){
  692. $this->error('请求错误');
  693. }
  694. $param = Request::instance()->post();
  695. if (empty($param)){
  696. $this->error('参数错误');
  697. }
  698. if ($param['processCode']<10){
  699. $param['processCode'] = '0'.$param['processCode'];
  700. }
  701. $date = date('Y-m-d H:i:s',time());
  702. $startTime = date('Y-m-d 08:30:00',time());
  703. if ($date<$startTime){
  704. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  705. }
  706. $data = [
  707. '类别' => $param['category'],
  708. '工单编号' => $param['workOrder'],
  709. '印件号' => $param['printCode'],
  710. '工序名称' => $param['processCode'].'-'.$param['process'],
  711. '流程单号' => $param['flowCode'],
  712. '设备编号' => $param['machine'],
  713. '班组编号' => $param['team'],
  714. '检验项目' => '['.$param['employeeCode'].'/'.$param['employeeName'].']',
  715. '相关标准' => '',
  716. '量测仪器' => '',
  717. '检验结果' => '',
  718. '检验备注' => $param['remark'],
  719. '提交时间' => date('Y-m-d H:i:s',time()),
  720. '开工时间' => $startTime,
  721. 'sys_id' => '',
  722. 'sys_rq' => date('Y-m-d H:i:s',time()),
  723. 'mod_rq' => '0000-00-00 00:00:00',
  724. 'UniqId' => \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
  725. ];
  726. $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
  727. $res = Db::query($sql);
  728. if ($res !== false){
  729. $this->success('成功');
  730. }else{
  731. $this->error('失败');
  732. }
  733. }
  734. /**
  735. * 设备点检->左侧菜单栏
  736. * @ApiMethod (GET)
  737. * @param void
  738. * @return void
  739. */
  740. public function SpotCheckItem()
  741. {
  742. if ($this->request->isGet() === false){
  743. $this->error('请求错误');
  744. }
  745. $param = $this->request->param();
  746. if (empty($param)){
  747. $this->error('参数错误');
  748. }
  749. $list = \db('设备_点检项目')
  750. ->where('适用机型','LIKE','%;'.$param['machine'].';%')
  751. ->distinct(true)
  752. ->column('部件名称','部件编号');
  753. if (empty($list)){
  754. $this->success('');
  755. }
  756. $this->success('成功',$list);
  757. }
  758. /**
  759. * 设备点检->检测项目
  760. * @ApiMethod (GET)
  761. * @param void
  762. * @return void
  763. * @throws \think\db\exception\DataNotFoundException
  764. * @throws \think\db\exception\ModelNotFoundException
  765. * @throws \think\exception\DbException
  766. */
  767. public function InspectionItem()
  768. {
  769. if ($this->request->isGet() === false){
  770. $this->error('请求错误');
  771. }
  772. $param = $this->request->param();
  773. if (empty($param)){
  774. $this->error('参数错误');
  775. }
  776. $list = \db('设备_点检项目')
  777. ->where('部件名称',$param['unitName'])
  778. ->where('适用机型','like','%'.$param['machine'].'#%')
  779. ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
  780. ->select();
  781. if (empty($list)){
  782. $this->success('未找到检测项目');
  783. }
  784. $this->success('成功',$list);
  785. }
  786. /**
  787. * 设备点检->检测记录添加
  788. * @ApiMethod (POST)
  789. * @param void
  790. * @return void
  791. * @throws \think\db\exception\DataNotFoundException
  792. * @throws \think\db\exception\ModelNotFoundException
  793. * @throws \think\exception\DbException
  794. */
  795. public function InspectionItemAdd()
  796. {
  797. if (Request::instance()->isPost() === false){
  798. $this->error('请求错误');
  799. }
  800. $param = Request::instance()->post();
  801. if (empty($param)){
  802. $this->error('参数错误');
  803. }
  804. $lastNumber = \db("设备_点检记录")->field('Uniqid as ID')->order('Uniqid desc')->find()['ID'];
  805. if ((int)$lastNumber>10000000){
  806. $lastId = $lastNumber;
  807. }else{
  808. $lastId = 10000000;
  809. }
  810. $row = [];
  811. foreach ($param as $key=>$value){
  812. $unitCode = \db('设备_点检项目')->where('部件名称',$value['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
  813. $row[$key] = [
  814. '日期' => date('Y-m-d 00:00:00',time()),
  815. '班组编号' => $value['team'],
  816. '点检设备' => $value['machine'],
  817. '部件编号' => $unitCode['部件编号'],
  818. '部件名称' => $value['unitName'],
  819. '检验项目' => $value['itemName'],
  820. '判定标准' => $value['standard'],
  821. '点检方法' => $value['method'],
  822. '点检结果' => $value['status'],
  823. '备注说明' => $value['remark'],
  824. 'Sys_id' =>'',
  825. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  826. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  827. 'Uniqid' => $lastId+$key+1
  828. ];
  829. }
  830. $sql = \db('设备_点检记录')->fetchSql(true)->insertAll($row);
  831. $res = Db::query($sql);
  832. if ($res !== false){
  833. $this->success('成功');
  834. }else{
  835. $this->error('失败');
  836. }
  837. }
  838. /**
  839. * 机台印版领用->左侧菜单
  840. * @ApiMethod (GET)
  841. * @param void
  842. * @return void
  843. */
  844. public function PrintGetTab()
  845. {
  846. if ($this->request->isGet() === false){
  847. $this->error('请求错误');
  848. }
  849. $param = $this->request->param();
  850. if (empty($param)){
  851. $this->error('参数错误');
  852. }
  853. $productCode = $param['productCode'];
  854. $sql = "SELECT DISTINCT(RTRIM(b.`名称`)) as `印版分类`,RTRIM(b.`编号`) as `编号` FROM `产品_印版资料` as a
  855. JOIN `物料_存货结构` as b ON b.`编号` = SUBSTRING(a.`存货编码`,1,4)
  856. WHERE a.YB_Cpdh = '{$productCode}'";
  857. $res = Db::query($sql);
  858. if (empty($res)){
  859. $this->success('');
  860. }
  861. $this->success('成功',$res);
  862. }
  863. /**
  864. * 机台印版领用记录->数据详情
  865. * @ApiMethod (GET)
  866. * @param void
  867. * @return void
  868. */
  869. public function PrintDetail()
  870. {
  871. if ($this->request->isGet() === false){
  872. $this->error('请求失败');
  873. }
  874. $param = $this->request->param();
  875. if (empty($param)){
  876. $this->error('参数错误');
  877. }
  878. $productCode = $param['productCode'];
  879. $code = $param['code'].'%';
  880. $workOrder = $param['workOrder'];
  881. $sql = "SELECT
  882. RTRIM(a.`存货编码`) as `存货编码`,
  883. RTRIM(c.`物料名称`) as `存货名称`,
  884. RTRIM(b.`印版名称`) as `印版名称`,
  885. RTRIM(b.`供方批号`) as `供方批号`,
  886. RTRIM(b.`制造日期`) as `制造日期`,
  887. SUM(d.`Yb_印数`) as `印数`,
  888. RTRIM(e.`名称`) as `印版类别`,
  889. SUBSTRING(a.YB_Cpdh,1,4) as `客户编号`,
  890. RTRIM(f.`Gd_客户名称`) as `客户名称`,
  891. RTRIM(a.YB_Cpdh) as `产品编号`,
  892. RTRIM(f.Gd_cpmc) as `产品名称`,
  893. RTRIM(d.UniqID) as UniqId
  894. FROM `产品_印版资料` as a
  895. LEFT JOIN `产品_印版库` as b ON b.`存货编码` = a.`存货编码`
  896. JOIN `物料_存货编码` as c ON c.`物料代码` = a.`存货编码`
  897. LEFT JOIN `工单_印版领用记录` as d ON d.`Yb_供方批号` = b.`供方批号`
  898. JOIN `物料_存货结构` as e ON e.`编号` = SUBSTRING(a.`存货编码`,1,4)
  899. JOIN `工单_基本资料` as f ON a.YB_Cpdh = f.Gd_cpdh
  900. WHERE a.YB_Cpdh = '{$productCode}'
  901. AND a.`存货编码` LIKE '{$code}'
  902. AND f.Gd_gdbh = '{$workOrder}'
  903. AND b.`报废日期` = '1900-01-01 00:00:00'
  904. GROUP BY b.`供方批号`
  905. ORDER BY a.`存货编码`";
  906. $list = Db::query($sql);
  907. if (empty($list)){
  908. $this->success('');
  909. }
  910. $this->success('成功',$list);
  911. }
  912. /**
  913. * 换型清场->左侧菜单栏
  914. * @ApiMethod (GET)
  915. * @param void
  916. * @return void
  917. */
  918. public function remodelGetTab()
  919. {
  920. if ($this->request->isGet() === false){
  921. $this->error('请求错误');
  922. }
  923. $date = date('Y-m-d 00:00:00',time()-3456000);
  924. $nowTime = date('Y-m-d H:i:s',time());
  925. $list = \db('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
  926. if (empty($list)){
  927. $this->error('失败');
  928. }
  929. $sql = "SELECT RTRIM(a.`设备编号`) as `设备编号`,RTRIM(b.`日期`) as `日期`,RTRIM(b.UniqId) as UniqId
  930. FROM `设备_基本资料` as a
  931. LEFT JOIN `制程_换型清场` as b ON b.`机台编号` = a.`设备编号`
  932. WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' AND b.`工单编号A` <> '' AND b.`工单编号B` <> '' ORDER BY b.`UniqId`";
  933. $res = Db::query($sql);
  934. $data = $result = [];
  935. foreach ($list as $key=>$value){
  936. $data[$value] = $result[$value]= $time = [];
  937. foreach ($res as $k=>$v){
  938. if ($value === $v['设备编号']){
  939. $row = [
  940. '日期' => $v['日期'],
  941. 'id' => $v['UniqId']
  942. ];
  943. array_push($data[$value],$row);
  944. }
  945. }
  946. foreach ($data[$value] as $m=>$n){
  947. $time[$m] = $n['日期'];
  948. }
  949. $time = array_values(array_unique($time));
  950. foreach ($time as $kk=>$vv){
  951. $i=1;
  952. foreach ($data[$value] as $kkk=>$vvv){
  953. if ($kkk>=$kk && $vv === $vvv['日期']){
  954. array_push($result[$value],date('Y-m-d',strtotime($vv)).'第'.$i.'次换型/'.$vvv['id']);
  955. $i++;
  956. }
  957. }
  958. }
  959. }
  960. $this->success('成功',$result);
  961. }
  962. /**
  963. * 换型清场->详情
  964. * @return void
  965. * @throws \think\db\exception\DataNotFoundException
  966. * @throws \think\db\exception\ModelNotFoundException
  967. * @throws \think\exception\DbException
  968. */
  969. public function RemodelDetail()
  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. $field = 'rtrim(日期) as 日期,rtrim(班组) as 班组,rtrim(机台编号) as 机台编号,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  979. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包B,
  980. rtrim(清场项目A) as 项目1,rtrim(清场项目B) as 项目2,rtrim(清场项目C) as 项目3,rtrim(清场项目D) as 项目4,rtrim(清场项目E) as 项目5,
  981. rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
  982. $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
  983. if (empty($list)){
  984. $this->success('未找到该条清场记录');
  985. }
  986. $list['日期'] = date('Y-m-d',strtotime($list['日期']));
  987. $list['印件名称A'] = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
  988. // if ()
  989. $list['印件名称B'] = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
  990. $this->success('成功',$list);
  991. }
  992. /**
  993. * 换型清场->当前设备清场记录
  994. * @ApiMethod (GET)
  995. * @param void
  996. * @return void
  997. * @throws \think\db\exception\DataNotFoundException
  998. * @throws \think\db\exception\ModelNotFoundException
  999. * @throws \think\exception\DbException
  1000. */
  1001. public function ModelChangeRecord()
  1002. {
  1003. if ($this->request->isGet() === false){
  1004. $this->error('请求错误');
  1005. }
  1006. $param = $this->request->param();
  1007. if (empty($param)){
  1008. $this->error('参数错误');
  1009. }
  1010. $date = date('Y-m-d 00:00:00',time()-3888000);
  1011. $nowTime = date('Y-m-d H:i:s',time());
  1012. $where = [
  1013. '日期' =>['between',[$date,$nowTime]],
  1014. '机台编号' => $param['machine'],
  1015. '工单编号A' => ['<>',''],
  1016. '工单编号B' => ['<>',''],
  1017. ];
  1018. $field = "rtrim(日期) as 日期,rtrim(机台编号) as 机台编号,rtrim(班组) as 班组,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1019. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包号B,rtrim(清场项目A) as 清场项目A,
  1020. rtrim(清场项目B) as 清场项目B,rtrim(清场项目C) as 清场项目C,rtrim(清场项目D) as 清场项目D,rtrim(清场项目E) as 清场项目E,rtrim(机长) as 机长,
  1021. rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员,rtrim(sys_rq) as 创建时间,rtrim(UniqId) as UNIQID";
  1022. $list = \db('制程_换型清场')
  1023. ->where($where)
  1024. ->field($field)
  1025. ->select();
  1026. if (empty($list)){
  1027. $this->success('未找到换型记录');
  1028. }
  1029. foreach ($list as $key=>$value){
  1030. $list[$key]['印件名称A'] = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
  1031. $list[$key]['印件名称B'] = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
  1032. }
  1033. $this->success('成功',$list);
  1034. }
  1035. /**
  1036. * 车间机台状态列表展示
  1037. * @ApiMethod (GET)
  1038. * @param void
  1039. * @return void
  1040. * @throws \think\db\exception\BindParamException
  1041. * @throws \think\exception\PDOException
  1042. */
  1043. public function MachineDetailList()
  1044. {
  1045. if ($this->request->isGet() === false){
  1046. $this->error('请求错误');
  1047. }
  1048. $param = $this->request->param();
  1049. if (empty($param)){
  1050. $this->error('参数错误');
  1051. }
  1052. $workshop = $param['workshop'];
  1053. $sql = "SELECT
  1054. RTRIM( a.`设备编号` ) AS 设备编号,
  1055. RTRIM( a.`设备名称` ) AS 设备名称,
  1056. RTRIM( d.`当前状态` ) AS 状态
  1057. FROM
  1058. `设备_基本资料` AS a
  1059. JOIN (
  1060. SELECT
  1061. b.`设备编号`,
  1062. b.`当前状态`,
  1063. b.`开工时间`
  1064. FROM
  1065. `设备_产量采集` AS b
  1066. JOIN ( SELECT `设备编号`, MAX( `UniqId` ) AS `UniqId` FROM `设备_产量采集` GROUP BY `设备编号` ) AS c ON b.`设备编号` = c.`设备编号`
  1067. AND b.`UniqId` = c.`UniqId`
  1068. ) AS d ON a.`设备编号` = d.`设备编号`
  1069. WHERE
  1070. a.`使用部门` = '{$workshop}'
  1071. GROUP BY
  1072. a.`设备编号`
  1073. ORDER BY
  1074. a.UniqId";
  1075. $list = \db()->query($sql);
  1076. foreach ($list as $key=>$value){
  1077. if ($value['状态'] == ''){
  1078. $list[$key]['状态'] = '待单';
  1079. }
  1080. }
  1081. $this->success('成功',$list);
  1082. }
  1083. /**
  1084. * 机台当前参数展示
  1085. * @ApiMethod (GET)
  1086. * @return void
  1087. * @throws \think\db\exception\DataNotFoundException
  1088. * @throws \think\db\exception\ModelNotFoundException
  1089. * @throws \think\exception\DbException
  1090. */
  1091. public function MachineDetail()
  1092. {
  1093. if ($this->request->isGet() === false){
  1094. $this->error('请求错误');
  1095. }
  1096. $param = $this->request->param();
  1097. if (empty($param)){
  1098. $this->error('参数错误');
  1099. }
  1100. $data = [];
  1101. if ($param['start'] === ''){
  1102. if (date('Y-m-d H:i:s')>date('Y-m-d 08:30:00',time()) && date('Y-m-d H:i:s')<date('Y-m-d 20:30:00',time())){
  1103. $param['start'] = date('Y-m-d 08:30:00',time());
  1104. }elseif (date('Y-m-d H:i:s')>date('Y-m-d 20:30:00',time()) && date('Y-m-d H:i:s')<date('Y-m-d 23:59:59',time())){
  1105. $param['start'] = date('Y-m-d 20:30:00',time());
  1106. }else{
  1107. $param['start'] = date('Y-m-d 20:30:00',time()-86400);
  1108. }
  1109. }
  1110. $machineDetail = \db('设备_产量采集')
  1111. ->alias('a')
  1112. ->join('设备_基本资料 b','a.设备编号 = b.设备编号')
  1113. ->join('工单_工艺资料 c','a.工单编号 = c.Gy0_gdbh AND a.设备编号 = c.Gy0_sbbh')
  1114. ->join('工单_基本资料 d','a.工单编号 = d.Gd_gdbh')
  1115. ->field([
  1116. 'rtrim(a.开工时间)' => '开工时间',
  1117. 'rtrim(a.设备编号)' => '设备编号',
  1118. 'rtrim(a.工单编号)' => '工单编号',
  1119. 'rtrim(b.设备名称)' => '设备名称',
  1120. 'rtrim(c.Gy0_gxh)' => '工序号',
  1121. 'rtrim(c.Gy0_gxmc)' => '工序名称',
  1122. 'rtrim(d.Gd_cpmc)' => '产品名称'
  1123. ])
  1124. ->where('a.设备编号', $param['machine'])
  1125. ->order('a.UniqId desc')
  1126. ->find();
  1127. $data['machine'] = [
  1128. '日期' => $machineDetail['开工时间'],
  1129. '设备' => $machineDetail['设备编号'].'-->'.$machineDetail['设备名称'],
  1130. '工单' => $machineDetail['工单编号'].'-->'.$machineDetail['产品名称'],
  1131. '工艺' => ($machineDetail['工序号']<10?'0'.$machineDetail['工序号']:$machineDetail['工序号']).'--'.$machineDetail['工序名称']
  1132. ];
  1133. //机台状态时间
  1134. $startTime = \db('设备_产量采集')
  1135. ->where('设备编号',$param['machine'])
  1136. ->where('开工时间',$param['start'])
  1137. ->field('rtrim(时间) as 时间,当班产量,rtrim(当前状态) as 状态,MAX(时间) as 最大时间,MAX(当班产量) as 最大产量')
  1138. ->group('当前状态')
  1139. ->select();
  1140. if (!empty($startTime)){
  1141. foreach ($startTime as $key=>$value){
  1142. $data['timeDifference'][$key] = [
  1143. '时间' => round((strtotime($value['最大时间'])-strtotime($value['时间']))/3600,2),
  1144. '状态' => $value['状态'] = null?'待单':$value['状态'],
  1145. ];
  1146. if ($value['状态'] === '生产'){
  1147. $data['当班产量'] = $value['最大产量']-$value['当班产量'];
  1148. }
  1149. }
  1150. }else{
  1151. $data['timeDifference'][0] = [
  1152. '时间' => 0,
  1153. '状态' => '待单'
  1154. ];
  1155. $data['当班产量'] = 0;
  1156. }
  1157. //机台产能/时间明细
  1158. $row = \db('设备_产量采集')
  1159. ->where('设备编号',$param['machine'])
  1160. ->where('开工时间',$param['start'])
  1161. ->field('rtrim(时间) as 时间,rtrim(当班产量) as 产量,rtrim(当前状态) as 状态')
  1162. ->select();
  1163. if (empty($row)){
  1164. $data['row'] = [];
  1165. }
  1166. foreach ($row as $key=>$value){
  1167. $data['row'][$key]['时间'] = date('Y-m-d H:i',strtotime($value['时间']));
  1168. $data['row'][$key]['状态'] = $value['状态'];
  1169. if ($key<2){
  1170. $data['row'][$key]['产能'] = 0;
  1171. }else{
  1172. $data['row'][$key]['产能'] = ($row[$key-1]['产量']-$row[$key-2]['产量'])*60;
  1173. }
  1174. }
  1175. //机台状态
  1176. $status = end($row);
  1177. if (empty($status['状态'])){
  1178. $data['status'] = '待单';
  1179. }else{
  1180. $data['status'] = $status['状态'];
  1181. }
  1182. //检验数据
  1183. $list = \db('制程检验_记录')
  1184. ->where('开工时间',$param['start'])
  1185. ->where('设备编号',$param['machine'])
  1186. ->where('sys_rq','>',$param['start'])
  1187. ->field('rtrim(类别) as 类别,提交时间')
  1188. ->select();
  1189. $data['首件'] = $data['自检'] = $data['IPQC'] = [];
  1190. if (!empty($list)){
  1191. foreach ($list as $key=>$value){
  1192. if ($value['类别'] == '首件与过程确认'){
  1193. array_push($data['首件'],$value['提交时间']);
  1194. }
  1195. if ($value['类别'] == '机台检验'){
  1196. array_push($data['自检'],$value['提交时间']);
  1197. }
  1198. if ($value['类别'] == 'IPQC检验'){
  1199. array_push($data['IPQC'],$value['提交时间']);
  1200. }
  1201. }
  1202. $data['首件'] = array_values(array_unique($data['首件']));
  1203. $data['自检'] = array_values(array_unique($data['自检']));
  1204. $data['IPQC'] = array_values(array_unique($data['IPQC']));
  1205. }else{
  1206. $data['首件'] = [];
  1207. $data['自检'] = [];
  1208. $data['IPQC'] = [];
  1209. }
  1210. $this->success('成功',$data);
  1211. }
  1212. /**
  1213. * 制程检验记录->检验项目
  1214. * @ApiMethod (GET)
  1215. * @param void
  1216. * @return void
  1217. * @throws \think\db\exception\DataNotFoundException
  1218. * @throws \think\db\exception\ModelNotFoundException
  1219. * @throws \think\exception\DbException
  1220. */
  1221. public function ProcessInspectionRecordsItem()
  1222. {
  1223. if ($this->request->isGet() === false){
  1224. $this->error('请求错误');
  1225. }
  1226. $param = $this->request->param();
  1227. if (empty($param)){
  1228. $this->error('参数错误');
  1229. }
  1230. $list = \db('制程检验_项目')
  1231. ->where('工序','like','%'.$param['process'].'%')
  1232. ->select();
  1233. if (empty($list)){
  1234. $this->success('未找到检测项目');
  1235. }
  1236. $data = [];
  1237. foreach ($list as $key=>$value){
  1238. $data['首件']['指标检验'][$key] = [
  1239. '检验项目' => rtrim($value['检测项目']),
  1240. '检测方法' => rtrim($value['检测方法']),
  1241. '检验频率' => rtrim($value['首件签样要求']),
  1242. '相关标准' => rtrim($value['技术要求'])
  1243. ];
  1244. $data['机台检验']['指标检验'][$key] = [
  1245. '检验项目' => rtrim($value['检测项目']),
  1246. '检测方法' => rtrim($value['检测方法']),
  1247. '检验频率' => rtrim($value['机台自检频率']),
  1248. '相关标准' => rtrim($value['技术要求'])
  1249. ];
  1250. $data['IPQC']['指标检验'][$key] = [
  1251. '检验项目' => rtrim($value['检测项目']),
  1252. '检测方法' => rtrim($value['检测方法']),
  1253. '检验频率' => rtrim($value['IPQC检验频率']),
  1254. '相关标准' => rtrim($value['技术要求'])
  1255. ];
  1256. }
  1257. $row = \db('制程检验_项目附加')
  1258. ->where('工序','like','%'.$param['process'].'%')
  1259. ->select();
  1260. foreach ($row as $key=>$value){
  1261. $data['首件']['附加'][$key] = [
  1262. '缺陷备注' => rtrim($value['缺陷备注']),
  1263. '编号' => rtrim($value['编号'])
  1264. ];
  1265. $data['机台检验']['附加'][$key] = [
  1266. '缺陷备注' => rtrim($value['缺陷备注']),
  1267. '编号' => rtrim($value['编号'])
  1268. ];
  1269. $data['IPQC']['附加'][$key] = [
  1270. '缺陷备注' => rtrim($value['缺陷备注']),
  1271. '编号' => rtrim($value['编号'])
  1272. ];
  1273. }
  1274. $this->success('成功',$data);
  1275. }
  1276. /**
  1277. * 制程检验记录->检测记录添加
  1278. * @ApiMethod (POST)
  1279. * @param void
  1280. * @return void
  1281. * @throws \think\db\exception\DataNotFoundException
  1282. * @throws \think\db\exception\ModelNotFoundException
  1283. * @throws \think\exception\DbException
  1284. */
  1285. public function ProcessInspectionRecordsItemAdd()
  1286. {
  1287. if (Request::instance()->isPost() === false){
  1288. $this->error('请求错误');
  1289. }
  1290. $param = Request::instance()->post();
  1291. if (empty($param)){
  1292. $this->error('参数错误');
  1293. }
  1294. $startID = \db('制程检验_记录')->order('UniqId desc')->value('UniqId');
  1295. if ($startID<100000000){
  1296. $startID = 100000000;
  1297. }
  1298. $process = \db('工单_工艺资料')
  1299. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1300. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1301. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1302. ->find();
  1303. $startTime = \db('设备_产量采集')
  1304. ->where('设备编号','like','%'.$param[0]['machine'].'#%')
  1305. ->where('工单编号',$param[0]['workOrder'])
  1306. ->order('UniqId desc')
  1307. ->find();
  1308. if ((int)$process['gxh']<10){
  1309. $process['gxh'] = '0'.$process['gxh'];
  1310. }
  1311. if ($process['add_gxmc'] !== ''){
  1312. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1313. }else{
  1314. $printName = $process['gxh'].'-'.$process['gxmc'];
  1315. }
  1316. if (empty($process)){
  1317. $this->success('数据错误');
  1318. }
  1319. $data = [];
  1320. foreach ($param as $key=>$value){
  1321. $data[$key] = [
  1322. '类别' => $value['category'],
  1323. '工单编号' => $value['workOrder'],
  1324. '印件号' => $value['yjno'],
  1325. '工序名称' => $printName,
  1326. '流程单号' => $value['flow'],
  1327. '设备编号' => $value['machine'].'#',
  1328. '班组编号' => $startTime['班组编号'],
  1329. '检验项目' => $value['item'],
  1330. '相关标准' => $value['standard'],
  1331. '量测仪器' => $value['instrument'],
  1332. '检验结果' => $value['result'],
  1333. '检验备注' => $value['remark'],
  1334. '提交时间' => date('Y-m-d H:i:s',time()),
  1335. '开工时间' => rtrim($startTime['开工时间']),
  1336. 'sys_id' => '',
  1337. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1338. 'mod_rq' => '0000-00-00 00:00:00',
  1339. 'UniqId' => $startID + $key +1
  1340. ];
  1341. }
  1342. $res = \db('制程检验_记录')->insertAll($data);
  1343. if ($res !== false){
  1344. $this->success('成功');
  1345. }else{
  1346. $this->error('失败');
  1347. }
  1348. }
  1349. /**
  1350. * 制程检验记录->附加检验记录添加
  1351. * @ApiMethod (POST)
  1352. * @param void
  1353. * @return void
  1354. * @throws \think\db\exception\DataNotFoundException
  1355. * @throws \think\db\exception\ModelNotFoundException
  1356. * @throws \think\exception\DbException
  1357. */
  1358. public function AdditionalInspectionRecordAdd()
  1359. {
  1360. if (Request::instance()->isPost() === false){
  1361. $this->error('请求错误');
  1362. }
  1363. $param = Request::instance()->post();
  1364. if (empty($param)){
  1365. $this->error('参数错误');
  1366. }
  1367. $startID = \db('制程检验_记录附加')->order('UniqId desc')->value('UniqId');
  1368. if ($startID<100000000){
  1369. $startID = 100000000;
  1370. }
  1371. $process = \db('工单_工艺资料')
  1372. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1373. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1374. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1375. ->find();
  1376. $startTime = \db('设备_产量采集')
  1377. ->where('设备编号','like','%'.$param[0]['machine'].'#%')
  1378. ->where('工单编号',$param[0]['workOrder'])
  1379. ->order('UniqId desc')
  1380. ->find();
  1381. if ((int)$process['gxh']<10){
  1382. $process['gxh'] = '0'.$process['gxh'];
  1383. }
  1384. if ($process['add_gxmc'] !== ''){
  1385. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1386. }else{
  1387. $printName = $process['gxh'].'-'.$process['gxmc'];
  1388. }
  1389. if (empty($process)){
  1390. $this->success('数据错误');
  1391. }
  1392. $data = [];
  1393. foreach ($param as $key=>$value){
  1394. $data[$key] = [
  1395. '工单编号' => $value['workOrder'],
  1396. '印件号' => $value['yjno'],
  1397. '工序名称' => $printName,
  1398. '流程单号' => $value['flow'],
  1399. '设备编号' => $value['machine'],
  1400. '班组编号' => $startTime['班组编号'],
  1401. '缺陷备注' => $value['remark'],
  1402. '提交时间' => date('Y-m-d H:i:s',time()),
  1403. '开工时间' => rtrim($startTime['开工时间']),
  1404. 'sys_id' => '',
  1405. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1406. 'mod_rq' => '0000-00-00 00:00:00',
  1407. 'UniqId' => $startID + $key +1
  1408. ];
  1409. }
  1410. $res = \db('制程检验_记录附加')->insertAll($data);
  1411. if ($res !== false){
  1412. $this->success('成功');
  1413. }else{
  1414. $this->error('失败');
  1415. }
  1416. }
  1417. /**
  1418. * 客诉记录
  1419. * @ApiMethod (GET)
  1420. * @param void
  1421. * @return void
  1422. * @throws \think\db\exception\DataNotFoundException
  1423. * @throws \think\db\exception\ModelNotFoundException
  1424. * @throws \think\exception\DbException
  1425. */
  1426. public function ComplaintRecord()
  1427. {
  1428. if ($this->request->isGet() === false){
  1429. $this->error('请求错误');
  1430. }
  1431. $param = $this->request->param();
  1432. if (isset($param['productCode'])){
  1433. $where['产品编号'] = $param['productCode'];
  1434. }
  1435. $filed = "rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,rtrim(客诉日期) as 客诉日期,rtrim(客诉单号) as 客诉单号,
  1436. rtrim(客诉方式) as 客诉方式,rtrim(订单编号) as 订单编号,rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,
  1437. rtrim(客诉描述) as 客诉描述,rtrim(缺陷关键字) as 缺陷关键字,rtrim(客诉性质) as 客诉性质,rtrim(扣分) as 扣分,
  1438. rtrim(主要责任部门) as 主要责任部门,rtrim(次要责任部门) as 次要责任部门";
  1439. $list = \db('db_客诉记录')
  1440. ->where($where)
  1441. ->field($filed)
  1442. ->select();
  1443. if (empty($list)){
  1444. $this->success('未找到该产品客诉记录');
  1445. }
  1446. $this->success('成功',$list);
  1447. }
  1448. /**
  1449. * 设置机台班组信息
  1450. * @return void
  1451. * @throws \think\db\exception\DataNotFoundException
  1452. * @throws \think\db\exception\ModelNotFoundException
  1453. * @throws \think\exception\DbException
  1454. */
  1455. public function setMachineTeam()
  1456. {
  1457. if (Request::instance()->isPost() == false) {
  1458. $this->error('非法请求');
  1459. }
  1460. $params = Request::instance()->post();
  1461. if (!isset($params['machine']) || empty($params['machine'] )) {
  1462. $this->error('参数不能为空');
  1463. }
  1464. if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
  1465. $this->error('请先选择班组成员');
  1466. }
  1467. $machine = $params['machine'] . '#';
  1468. $data = [];
  1469. $lastData = \db('设备_产量采集')
  1470. ->order('UniqId desc')
  1471. ->find();
  1472. if ($lastData['UniqId'] < 160000000) {
  1473. $id = 160000000;
  1474. } else {
  1475. $id = $lastData['UniqId'] + 1;
  1476. }
  1477. $data['当前状态'] = $params['status'];
  1478. $data['时间'] = date('Y-m-d H:i:s');
  1479. $data['设备编号'] = $machine;
  1480. $data['工单编号'] = $params['order'];
  1481. $data['印件号'] = $params['yjno'];
  1482. $data['工序号'] = (int)substr($params['gy_name'], 0, 2);
  1483. $data['工序名称'] = $params['gy_name'];
  1484. $data['当班产量'] = $params['production_now'];
  1485. $data['累计产量'] = $params['production_all'];
  1486. $data['班组编号'] = $params['sczl_bzdh'];
  1487. $data['班组ID'] = $params['team_id'];
  1488. // 获取当前时间
  1489. $current_time = time();
  1490. // 设置时间范围
  1491. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  1492. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  1493. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  1494. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  1495. // 判断当前时间属于哪个时间范围
  1496. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  1497. $data['开工时间'] = date('Y-m-d') . ' 08:30:00';
  1498. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  1499. $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  1500. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  1501. $data['开工时间'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  1502. }
  1503. $option['Gy0_gdbh'] = $params['order'];
  1504. $option['Gy0_yjno'] = $params['yjno'];
  1505. $option['Gy0_gxh'] = $data['工序号'];
  1506. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  1507. $data['UniqId'] = $id;
  1508. $sql = \db('设备_产量采集')->fetchSql(true)->insert($data);
  1509. $res = Db::query($sql);
  1510. if ($res === false) {
  1511. $this->error('设置失败');
  1512. } else {
  1513. $this->success('设置成功');
  1514. }
  1515. }
  1516. /**
  1517. * 首页数据
  1518. * @return void
  1519. * @throws \think\Exception
  1520. * @throws \think\db\exception\DataNotFoundException
  1521. * @throws \think\db\exception\ModelNotFoundException
  1522. * @throws \think\exception\DbException
  1523. */
  1524. public function index()
  1525. {
  1526. if ($this->request->isGet() === false){
  1527. $this->error('请求错误');
  1528. }
  1529. $nowTime = date('Y-m-d H:i:s',time());
  1530. $oldTime = (date('Y')-1).'-'.date('m-d H:i:s');
  1531. $where =[
  1532. 'Mod_rq' => ['between',[$oldTime,$nowTime]],
  1533. '行号' => '1'
  1534. ];
  1535. $data = [];
  1536. //按状态查询工单信息
  1537. $orderList = \db('工单_基本资料')
  1538. ->where($where)
  1539. ->field('count(Gd_gdbh) as 数量,rtrim(gd_statu) as 状态')
  1540. ->group('gd_statu')
  1541. ->select();
  1542. foreach ($orderList as $value){
  1543. if ($value['状态'] === '1-已完工'){
  1544. $data['workOrderData']['已完工'] = $value['数量'];
  1545. }
  1546. if ($value['状态'] === '3-计划中'){
  1547. $data['workOrderData']['计划中'] = $value['数量'];
  1548. }
  1549. }
  1550. $data['workOrderData']['排程中'] = db('工单_基本资料')->alias('a')
  1551. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  1552. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  1553. ->where([
  1554. 'a.gd_statu' => '2-生产中',
  1555. 'a.行号' => '1',
  1556. 'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
  1557. 'b.PD_WG' => '1900-01-01 00:00:00',
  1558. 'b.Gy0_sj1' => '1900-01-01 00:00:00',
  1559. 'c.状态' => '',
  1560. ])
  1561. ->group('a.Gd_gdbh')
  1562. ->count();
  1563. $data['workOrderData']['制程中'] = db('工单_基本资料')->alias('a')
  1564. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  1565. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  1566. ->where([
  1567. 'a.gd_statu' => '2-生产中',
  1568. 'a.行号' => '1',
  1569. 'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
  1570. 'b.PD_WG' => '1900-01-01 00:00:00',
  1571. 'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'],
  1572. 'c.状态' => '',
  1573. ])
  1574. ->group('a.Gd_gdbh')
  1575. ->count();
  1576. //按月份查询工单信息
  1577. $data['monthData'] = \db('工单_基本资料')
  1578. ->where('Mod_rq', 'between', [$oldTime, $nowTime])
  1579. ->field('DATE_FORMAT(Mod_rq, "%Y-%m") as month, COUNT(*) as count')
  1580. ->group('month')
  1581. ->order('month')
  1582. ->select();
  1583. //查询最近十条客诉信息
  1584. $data['customer'] = \db('db_客诉记录')
  1585. ->field('rtrim(客诉描述) as 客诉描述,DATE_FORMAT(客诉日期, "%Y-%m-%d") as 日期,rtrim(UniqID) as UniqId')
  1586. ->limit(10)
  1587. ->order('Sys_rq desc')
  1588. ->select();
  1589. $this->success('成功',$data);
  1590. }
  1591. /**
  1592. * 员工信息获取
  1593. * @return void
  1594. * @throws \think\db\exception\DataNotFoundException
  1595. * @throws \think\db\exception\ModelNotFoundException
  1596. * @throws \think\exception\DbException
  1597. */
  1598. public function EmployeeData()
  1599. {
  1600. if ($this->request->isGet() === false){
  1601. $this->error('请求错误');
  1602. }
  1603. $param = $this->request->param();
  1604. if (isset($param['code']) === false){
  1605. $this->error('参数错误');
  1606. }
  1607. $res = \db('人事_基本资料')
  1608. ->where('员工编号','like',$param['code'].'%')
  1609. ->field('rtrim(员工编号) as 员工编号,rtrim(员工姓名) as 员工姓名')
  1610. ->select();
  1611. if (empty($res)){
  1612. $this->success('未找到该员工');
  1613. }
  1614. $this->success('成功',$res);
  1615. }
  1616. /**
  1617. * 换型清场添加
  1618. * @return void
  1619. * @throws \think\db\exception\BindParamException
  1620. * @throws \think\exception\PDOException
  1621. */
  1622. public function remodelDataAdd()
  1623. {
  1624. if (Request::instance()->isPost() === false){
  1625. $this->error('请求错误');
  1626. }
  1627. $param = Request::instance()->post();
  1628. if (empty($param)){
  1629. $this->error('参数错误');
  1630. }
  1631. $lastId = \db('制程_换型清场')->order('UniqId desc')->value('UniqId');
  1632. $param['sys_id'] = '['.$param['机台编号'].']';
  1633. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  1634. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1635. $param['UniqId'] = $lastId + 1;
  1636. $sql = \db('制程_换型清场')->fetchSql(true)->insert($param);
  1637. $res = \db()->query($sql);
  1638. if ($res !== false){
  1639. $this->success('成功');
  1640. }else{
  1641. $this->error('失败');
  1642. }
  1643. }
  1644. /**
  1645. * 换型清场记录修改
  1646. * @return void
  1647. * @throws \think\Exception
  1648. * @throws \think\db\exception\BindParamException
  1649. * @throws \think\exception\PDOException
  1650. */
  1651. public function remodelDataEdit()
  1652. {
  1653. if (Request::instance()->isPost() === false){
  1654. $this->error('请求错误');
  1655. }
  1656. $param = Request::instance()->post();
  1657. if (empty($param)){
  1658. $this->error('参数错误');
  1659. }
  1660. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1661. $sql = \db('制程_换型清场')->fetchSql(true)->update($param);
  1662. $res = \db()->query($sql);
  1663. if ($res !== false){
  1664. $this->success('成功');
  1665. }else{
  1666. $this->error('失败');
  1667. }
  1668. }
  1669. /**
  1670. * 换型清场记录删除
  1671. * @return void
  1672. * @throws \think\Exception
  1673. * @throws \think\exception\PDOException
  1674. */
  1675. public function remodelDataDel()
  1676. {
  1677. if ($this->request->isGet() === false){
  1678. $this->error('请求错误');
  1679. }
  1680. $param = $this->request->param();
  1681. if (empty($param)){
  1682. $this->error('参数错误');
  1683. }
  1684. $res = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->delete();
  1685. if ($res !== false){
  1686. $this->success('删除成功');
  1687. }else{
  1688. $this->error('删除失败');
  1689. }
  1690. }
  1691. /**
  1692. * 印版领用记录添加
  1693. * @return void
  1694. * @throws \think\db\exception\BindParamException
  1695. * @throws \think\exception\PDOException
  1696. */
  1697. public function PrintDetailAdd()
  1698. {
  1699. if (Request::instance()->isPost() === false){
  1700. $this->error('请求错误');
  1701. }
  1702. $param = Request::instance()->post();
  1703. if (empty($param)){
  1704. $this->error('参数错误');
  1705. }
  1706. $lastId = \db('工单_印版领用记录')->order('UniqID desc')->value('UniqID');
  1707. foreach ($param as $key=>$value){
  1708. $param[$key]['Yb_领用日期'] = date('Y-m-d H:i:s',time());
  1709. $param[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  1710. $param[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  1711. $param[$key]['UniqID'] = $lastId + $key +1;
  1712. }
  1713. $sql = \db('工单_印版领用记录')->fetchSql(true)->insertAll($param);
  1714. $res = \db()->query($sql);
  1715. if ($res !== false){
  1716. $this->success('添加成功');
  1717. }else{
  1718. $this->error('添加失败');
  1719. }
  1720. }
  1721. /**
  1722. * 印版领用记录退还
  1723. * @return void
  1724. * @throws \think\Exception
  1725. * @throws \think\db\exception\BindParamException
  1726. * @throws \think\exception\PDOException
  1727. */
  1728. public function PrintDetailEdit()
  1729. {
  1730. if ($this->request->isGet() === false){
  1731. $this->error('请求错误');
  1732. }
  1733. $param = $this->request->param();
  1734. if (empty($param)){
  1735. $this->error('参数错误');
  1736. }
  1737. $idList = explode(',',$param['id']);
  1738. $i = 0;
  1739. foreach ($idList as $key=>$value){
  1740. $data['Yb_退还日期'] = date('Y-m-d H:i:s',time());
  1741. $data['Mod_rq'] = date('Y-m-d H:i:s',time());
  1742. $sql = \db('工单_印版领用记录')->where('UniqID',$value)->fetchSql(true)->update($data);
  1743. $res = \db()->query($sql);
  1744. if ($res === false){
  1745. $i++;
  1746. }
  1747. }
  1748. if ($i !== 0){
  1749. $this->error('退还失败');
  1750. }else{
  1751. $this->success('退还成功');
  1752. }
  1753. }
  1754. }