Facility.php 61 KB

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