Facility.php 57 KB

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