Facility.php 73 KB

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