Facility.php 72 KB

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