Facility.php 67 KB

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