Facility.php 79 KB

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