Facility.php 79 KB

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