Facility.php 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822
  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. $param = $this->request->param();
  27. // if (isset($param['sort'])){
  28. // $where['使用部门'] = '智能车间';
  29. // }else{
  30. // $where['使用部门'] = ['<>','智能车间'];
  31. // }
  32. $data = [];
  33. $date = date('Y-m-d 00:00:00',time()-3888000);
  34. $department = \db('设备_基本资料')
  35. ->distinct(true)
  36. ->where('使用部门','<>','研发中心')
  37. ->where('设备编组','<>','')
  38. ->where('sys_sbID','<>','')
  39. // ->where($where)
  40. ->order('设备编组')
  41. ->column('rtrim(使用部门) as 使用部门');
  42. if (empty($department)){
  43. $this->success('为获取到机台数据');
  44. }
  45. $list = \db('设备_产量计酬')
  46. ->field([
  47. 'DISTINCT(sczl_rq)' => '时间',
  48. 'rtrim(sczl_jtbh)' => '机台编号'
  49. ])
  50. ->where('sczl_rq','>',$date)
  51. ->order('sczl_rq desc')
  52. ->select();
  53. if (empty($list)){
  54. $this->success('未找到机台生产记录');
  55. }
  56. foreach ($department as $value){
  57. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->order('设备编号')->select();
  58. foreach ($machine as $k=>$v){
  59. $data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']] = [];
  60. foreach ($list as $kk=>$vv){
  61. if ($v['设备编号'] === $vv['机台编号']){
  62. array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],date('Y-m-d',strtotime($vv['时间'])));
  63. }
  64. }
  65. }
  66. }
  67. $this->success('成功',$data);
  68. }
  69. /**
  70. * 机台每日产量
  71. * @ApiMethod (GET)
  72. * @param string $machine 机台编号
  73. * @param string $date 日期
  74. * @return void
  75. * @throws \think\db\exception\DataNotFoundException
  76. * @throws \think\db\exception\ModelNotFoundException
  77. * @throws \think\exception\DbException
  78. */
  79. public function chanLiang()
  80. {
  81. if ($this->request->isGet() === false){
  82. $this->error('请求错误');
  83. }
  84. $machine = input('machine');
  85. $date = input('date');
  86. $where = [
  87. 'sczl_jtbh' => $machine,
  88. 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
  89. ];
  90. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_dedh) as dedh,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxh) as gxh,
  91. rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as num,rtrim(sczl_sj1) as sj1,
  92. rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,IF(sczl_zcfp = 0, "",sczl_zcfp) as 制程废品,
  93. IF(sczl_zccp = 0, "",sczl_zccp) as 制程次品,IF(sczl_前工序废 = 0, "",sczl_前工序废) as 前工序废,
  94. IF(sczl_来料少数 = 0, "",sczl_来料少数) as 来料异常,IF(sczl_装版总工时 = 0, "",sczl_装版总工时) as 装版总工时,
  95. IF(sczl_打样总工时 = 0, "",sczl_打样总工时) as 打样总工时,
  96. IF(sczl_装版工时 = 0, "",sczl_装版工时) as 装版工时, IF(sczl_保养工时 = 0, "",sczl_保养工时) as 保养工时,
  97. IF(sczl_打样工时 = 0, "",sczl_打样工时) as 打样工时,IF(sczl_异常停机工时 = 0, "",sczl_异常停机工时) as 异常总工时,
  98. IF(sczl_设备运行工时 = 0, "",sczl_设备运行工时) as 通电工时,
  99. IF(码开始行 = 0, "",码开始行) as 码开始行,IF(码结束行 = 0, "",码结束行) as 码结束行,
  100. IF(码包 = 0, "",码包) as 码包,IF(主电表 = 0, "",主电表) as 主电表,IF(辅电表 = 0, "",辅电表) as 辅电表,
  101. IF(sczl_ms = 0, "",sczl_ms) as 色度数,
  102. rtrim(sys_id) as 用户,rtrim(sys_rq) as 更新时间,IF(sczl_异常工时1 = 0, "",sczl_异常工时1) as 异常补时,
  103. IF(sczl_异常类型1 = 0, "",sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  104. sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,sczl_rate2,
  105. sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
  106. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId,rtrim(sczl_工价系数) as 难度系数,
  107. rtrim(sczl_dedh) as 定额代号';
  108. //机台信息
  109. $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
  110. //组员信息
  111. $list = \db('设备_产量计酬')->where($where)->field($field)->select();
  112. $totalA = \db('设备_产量计酬')
  113. ->where($where)
  114. ->where('sczl_bzdh','like','A%')
  115. ->field('SUM(sczl_cl) as 产量, SUM(sczl_zcfp) as 制程废品, SUM(sczl_zccp) as 制程次品, SUM(sczl_来料少数) as 来料异常, SUM(sczl_装版工时) as 装版工时, SUM(sczl_保养工时) as 保养工时, SUM(sczl_打样工时) as 打样工时,SUM(sczl_异常停机工时) as 异常工时,SUM(sczl_异常工时1) as 异常补时工时,SUM(sczl_设备运行工时) as 通电工时,SUM(sczl_前工序废) as 前工序废')
  116. ->select();
  117. $totalB = \db('设备_产量计酬')
  118. ->where($where)
  119. ->where('sczl_bzdh','like','B%')
  120. ->field('SUM(sczl_cl) as 产量, SUM(sczl_zcfp) as 制程废品, SUM(sczl_zccp) as 制程次品, SUM(sczl_来料少数) as 来料异常, SUM(sczl_装版工时) as 装版工时, SUM(sczl_保养工时) as 保养工时, SUM(sczl_打样工时) as 打样工时,SUM(sczl_异常停机工时) as 异常工时,SUM(sczl_异常工时1) as 异常补时工时,SUM(sczl_设备运行工时) as 通电工时,SUM(sczl_前工序废) as 前工序废')
  121. ->select();
  122. if (empty($list)){
  123. $this->success('',[]);
  124. }
  125. foreach ($list as $key=>$value){
  126. //产品名称
  127. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$value['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  128. if (!empty($productName)){
  129. if (!empty($productName['成品名称'])){
  130. $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['成品名称'];
  131. $list[$key]['cpmc'] = $productName['成品名称'];
  132. }else{
  133. $list[$key]['产品名称'] = $value['工单编号'];
  134. $list[$key]['cpmc'] = '';
  135. }
  136. }else{
  137. $list[$key]['产品名称'] = $value['工单编号'];
  138. $list[$key]['cpmc'] = '';
  139. }
  140. $process = \db('工单_工艺资料')
  141. ->where('Gy0_gdbh',$value['工单编号'])
  142. ->where('Gy0_yjno',$value['yjno'])
  143. ->where('Gy0_gxh',$value['gxh'])
  144. ->field('rtrim(工价系数) as 工价系数,rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距')
  145. ->find();
  146. if (!empty($process)){
  147. if ($value['难度系数'] == 0){
  148. $list[$key]['难度系数'] = $process['工价系数'];
  149. }else{
  150. $list[$key]['难度系数'] = $process['工价系数'].'x'.$value['难度系数'];
  151. }
  152. $list[$key]['印刷方式'] = $process['印刷方式'].' '.$process['版距'];
  153. }else{
  154. $list[$key]['难度系数'] = '';
  155. $list[$key]['印刷方式'] = '';
  156. }
  157. if ($value['yjno']<10){
  158. $list[$key]['yjno'] = '0'.$value['yjno'];
  159. }
  160. if (empty($value['定额代号'])){
  161. $list[$key]['千件工价'] = '';
  162. $list[$key]['日定额'] = '';
  163. $list[$key]['补产标准'] = '';
  164. }else{
  165. $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
  166. $list[$key]['千件工价'] = $row['千件工价'];
  167. $list[$key]['日定额'] = $row['日定额'];
  168. $list[$key]['补产标准'] = $row['补产标准'];
  169. }
  170. $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
  171. $list[$key]['备注'] = $value['bzdh'].'('.$value['num'].')'.date('H:i',strtotime($value['sj1'])).'<-->'.date('H:i',strtotime($value['sj2']));
  172. for ($i=1;$i<11;$i++){
  173. if (isset($value['sczl_bh'.$i])){
  174. $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
  175. if (isset($name['name'])){
  176. $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
  177. }
  178. }
  179. unset($list[$key]['sczl_bh'.$i],$list[$key]['sczl_rate'.$i]);
  180. }
  181. }
  182. $list['totalA'] = $totalA[0]['产量'];
  183. $list['totalB'] = $totalB[0]['产量'];
  184. $list['制程废品A'] = $totalA[0]['制程废品'];
  185. $list['制程废品B'] = $totalB[0]['制程废品'];
  186. $list['制程次品A'] = $totalA[0]['制程次品'];
  187. $list['制程次品B'] = $totalB[0]['制程次品'];
  188. $list['来料异常A'] = $totalA[0]['来料异常'];
  189. $list['来料异常B'] = $totalB[0]['来料异常'];
  190. $list['装版工时A'] = $totalA[0]['装版工时'];
  191. $list['装版工时B'] = $totalB[0]['装版工时'];
  192. $list['保养工时A'] = $totalA[0]['保养工时'];
  193. $list['保养工时B'] = $totalB[0]['保养工时'];
  194. $list['打样工时A'] = $totalA[0]['打样工时'];
  195. $list['打样工时B'] = $totalB[0]['打样工时'];
  196. $list['异常工时A'] = $totalA[0]['异常工时'];
  197. $list['异常工时B'] = $totalB[0]['异常工时'];
  198. $list['异常补时工时A'] = $totalA[0]['异常补时工时'];
  199. $list['异常补时工时B'] = $totalB[0]['异常补时工时'];
  200. $list['通电工时A'] = $totalA[0]['通电工时'];
  201. $list['通电工时B'] = $totalB[0]['通电工时'];
  202. $list['前工序废A'] = $totalA[0]['前工序废'];
  203. $list['前工序废B'] = $totalB[0]['前工序废'];
  204. $this->success('成功',$list);
  205. }
  206. /**
  207. * 当日制程检验记录
  208. * @ApiMethod (GET)
  209. * @param string $machine 机台编号
  210. * @param string $date 日期
  211. * @return void
  212. * @throws \think\db\exception\DataNotFoundException
  213. * @throws \think\db\exception\ModelNotFoundException
  214. * @throws \think\exception\DbException
  215. */
  216. public function Inspect()
  217. {
  218. if ($this->request->isGet() === false){
  219. $this->error('请求错误');
  220. }
  221. $machine = input('machine');
  222. // $date = input('date');
  223. // 获取当前时间
  224. $current_time = time();
  225. // 设置时间范围
  226. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  227. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  228. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  229. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  230. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  231. // 判断当前时间属于哪个时间范围
  232. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  233. $startTime = date('Y-m-d') . ' 08:30:00';
  234. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  235. $startTime = date('Y-m-d') . ' 20:30:00';
  236. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  237. $startTime = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  238. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  239. $startTime = date('Y-m-d') . ' 20:30:00';
  240. }
  241. if (empty($machine)){
  242. $this->error('参数错误');
  243. }
  244. $where = [
  245. '设备编号' => $machine,
  246. '开工时间' => $startTime,
  247. '类别' => ['in',['IPQC检验','机台检验']],
  248. ];
  249. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,提交时间,rtrim(检验项目) as 检验项目';
  250. $list = \db('制程检验_记录')
  251. ->where($where)
  252. ->field($field)
  253. ->select();
  254. if (empty($list)){
  255. $this->success('未找到检验记录');
  256. }
  257. $data = [];
  258. foreach ($list as $key=>$value)
  259. {
  260. $data['item'][$key] = $value['检验项目'];
  261. $data['InspectionTime'][$key] = date('H:i',strtotime($value['提交时间']));
  262. $data['工单编号'][$key] = $value['工单编号'];
  263. }
  264. $data['item'] = array_unique($data['item']);
  265. $data['InspectionTime'] = array_values(array_unique($data['InspectionTime']));
  266. $data['工单编号'] = array_values(array_unique($data['工单编号']));
  267. foreach ($data['工单编号'] as $key => $value){
  268. foreach ($data['item'] as $k=>$v){
  269. $time = '';
  270. foreach ($list as $kk=>$vv){
  271. if ($vv['工单编号'] === $value && $vv['检验项目'] === $v){
  272. $time = $time.date('H:i',strtotime($vv['提交时间'])).',';
  273. $data['row'][$key][$k] = [
  274. '工单编号' => $value,
  275. '印件号' => $vv['印件号'],
  276. '工序名称' => $vv['工序名称'],
  277. '检验项目' => $v,
  278. 'time' => substr($time,0,-1),
  279. ];
  280. }
  281. }
  282. }
  283. $data['row'][$key] = array_values($data['row'][$key]);
  284. }
  285. unset($data['item'],$data['工单编号']);
  286. $this->success('成功',$data);
  287. }
  288. /**
  289. * 设备生产中工单信息
  290. * @ApiMethod (GET)
  291. * @param string $machine 机台编号
  292. * @return void
  293. * @throws \think\Exception
  294. * @throws \think\db\exception\DataNotFoundException
  295. * @throws \think\db\exception\ModelNotFoundException
  296. * @throws \think\exception\DbException
  297. */
  298. public function Production()
  299. {
  300. if (Request::instance()->isGet() == false) {
  301. $this->error('非法请求');
  302. }
  303. $params = Request::instance()->param();
  304. if (!isset($params['machine']) || empty($params['machine'])) {
  305. $this->error('参数错误');
  306. }
  307. $machine = $params['machine'];
  308. $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
  309. $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  310. $list = [];
  311. $row = [];
  312. if (!empty($data['工单编号'])){
  313. $endTime = \db('工单_工艺资料')
  314. ->where('Gy0_gdbh',$data['工单编号'])
  315. ->where('Gy0_yjno',$data['印件号'])
  316. ->where('Gy0_gxh',$data['工序号'])
  317. ->find();
  318. $list['工单编号'] = $data['工单编号'];
  319. if (!empty($endTime)){
  320. $list['印件号'] = $data['印件号'];
  321. $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
  322. $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品代号');
  323. $list['产品名称'] = rtrim($name);
  324. $list['产品代号'] = rtrim($code);
  325. $list['工序名称'] = $data['工序名称'];
  326. }
  327. $list['状态'] = rtrim($data['当前状态']);
  328. $list['开工时间'] = $data['开工时间'];
  329. }else{
  330. $list['工单编号'] = '';
  331. $list['印件号'] = 0;
  332. $list['产品名称'] = '';
  333. $list['工序名称'] = '';
  334. $list['产品代号'] = '';
  335. $list['状态'] = '';
  336. $list['开工时间'] = '';
  337. }
  338. $list['班组编号'] = rtrim($data['班组编号']);
  339. $list['班组Id'] = rtrim($data['班组ID']);
  340. $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,
  341. 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,
  342. rtrim(sczl_bh10) as bh10")->find();
  343. if (!empty($class)){
  344. for ($i=1;$i<11;$i++) {
  345. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  346. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  347. $row[$i] = [
  348. '编号' => $class['bh' . $i],
  349. '姓名' => $name['姓名']
  350. ];
  351. }
  352. }
  353. $row = array_values($row);
  354. }
  355. $list['班组成员'] = $row;
  356. $list['定额代号'] = $machineCode;
  357. $this->success('成功',$list);
  358. }
  359. /**
  360. * 设备工作清单
  361. * @ApiMethod (GET)
  362. * @param string $machine 机台编号
  363. * @return void
  364. * @throws \think\db\exception\DataNotFoundException
  365. * @throws \think\db\exception\ModelNotFoundException
  366. * @throws \think\exception\DbException
  367. */
  368. public function EquipmentWorklist()
  369. {
  370. if ($this->request->isGet() === false){
  371. $this->error('请求错误');
  372. }
  373. $machine = input('machine');
  374. if (empty($machine)){
  375. $this->error('参数错误');
  376. }
  377. $orderList = \db('工单_工艺资料')
  378. ->alias('a')
  379. // ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_yjno = b.sczl_yjno AND a.Gy0_gxh = b.sczl_gxh','LEFT')
  380. ->join('工单_基本资料 c','a.Gy0_gdbh = c.Gd_gdbh')
  381. ->join('工单_印件资料 d','a.Gy0_gdbh = d.Yj_Gdbh AND a.Gy0_yjno = d.yj_Yjno')
  382. ->field('a.Gy0_gdbh as gdbh,rtrim(a.质量要求) as 质量信息,a.Gy0_yjno as yjno,a.Gy0_gxh as gxh,a.Gy0_sbbh as sbbh,
  383. rtrim(a.Gy0_gxmc) as gxmc,rtrim(a.Add_gxmc) as add_gxmc,a.Gy0_辅助工时 as 装版工时,a.Gy0_小时产能 as 工序产能,a.Gy0_生产工时 as 计划工时,
  384. a.Gy0_sj1 as sj1,a.Gy0_sj2 as sj2,rtrim(a.工序备注) as 排产备注,d.yj_yjmc as 印件名称,c.成品名称 as 产品名称,c.成品代号 as 产品代号,
  385. a.Gy0_计划接货数 as 计划接货数,a.Gy0_ls as ls,a.Gy0_班次安排 as 班组,a.UniqId as UniqId,a.Gy0_最早开工时间 as 最早开工时间')
  386. ->where('a.Gy0_sbbh','like','%'.$machine.'%')
  387. ->where('a.PD_WG','1900-01-01 00:00:00')
  388. ->where('a.Gy0_sj1','<>','1900-01-01 00:00:00')
  389. ->where('c.gd_statu','2-生产中')
  390. ->group('a.Gy0_gdbh,a.Gy0_yjno,a.Gy0_gxh')
  391. ->order('a.Gy0_sj1')
  392. ->select();
  393. if (!empty($orderList)){
  394. $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  395. foreach ($orderList as $key=>$value){
  396. $machineList = explode(' ',$value['sbbh']);
  397. $cl_data = \db('设备_产量计酬')
  398. ->field('SUM(sczl_cl) as 已完成,SUM(sczl_zcfp) as 制程废品')
  399. ->where('sczl_gdbh',$value['gdbh'])
  400. ->where('sczl_yjno',$value['yjno'])
  401. ->where('sczl_gxh',$value['gxh'])
  402. ->select();
  403. $orderList[$key]['status'] = 0;
  404. if (!empty($data)){
  405. if ($value['gdbh'] === $data['工单编号'] && $value['yjno'] === $data['印件号'] && $value['gxh'] === $data['工序号']) {
  406. $orderList[$key]['status'] = 1;
  407. }
  408. }
  409. $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
  410. $orderList[$key]['印件号'] = $value['yjno'];
  411. $orderList[$key]['工序号'] = $value['gxh'];
  412. if ($value['yjno']<10){
  413. $orderList[$key]['yjno'] = '0'.$value['yjno'];
  414. }
  415. if ($value['gxh']<10){
  416. $orderList[$key]['gxh'] = '0'.$value['gxh'];
  417. }
  418. $orderList[$key]['印件资料'] = $orderList[$key]['yjno'].'-'.$value['印件名称'];
  419. $orderList[$key]['工序名称'] = $orderList[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  420. if ((int)$cl_data[0]['制程废品'] === 0){
  421. $orderList[$key]['计划产量/已完成'] = (int)$value['计划接货数'].'/'.$cl_data[0]['已完成']=null?'':(int)$cl_data[0]['已完成'];
  422. }else{
  423. $orderList[$key]['计划产量/已完成'] = (int)$value['计划接货数'].'/'.$cl_data[0]['已完成']=null?'':(int)$cl_data[0]['已完成'].'('.$cl_data[0]['制程废品'].')';
  424. }
  425. $orderList[$key]['计划生产时段'] =substr($value['sj1'],5,5).' '.substr($value['sj1'],11,5).'<-->'.substr($value['sj2'],5,5).' '.substr($value['sj2'],11,5);
  426. unset($orderList[$key]['gdbh'],$orderList[$key]['质量信息'],$orderList[$key]['gxh'],$orderList[$key]['yjno'],$orderList[$key]['gxmc'],$orderList[$key]['add_gxmc'],$orderList[$key]['计划接货数'],$orderList[$key]['已完成'],$orderList[$key]['印件名称'],$orderList[$key]['ls'],$orderList[$key]['制程废品']);
  427. if (in_array($machine,$machineList) === false){
  428. unset($orderList[$key]);
  429. }
  430. }
  431. $data = array_values($orderList);
  432. $this->success('成功',$data);
  433. }else{
  434. $this->error('未找到数据');
  435. }
  436. }
  437. /**
  438. * 工序、印件、完成数量
  439. * @ApiMethod (GET)
  440. * @param string $workOrder 工单编号
  441. * @return void
  442. * @throws \think\Exception
  443. * @throws \think\db\exception\DataNotFoundException
  444. * @throws \think\db\exception\ModelNotFoundException
  445. * @throws \think\exception\DbException
  446. */
  447. public function Procedure()
  448. {
  449. if ($this->request->isGet() === false){
  450. $this->error('请求错误');
  451. }
  452. $workOrder = input('Gd_gdbh');
  453. $data = [];
  454. if (!empty($workOrder)){
  455. //右边工艺及完成数量
  456. $Process = \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  457. ->distinct(true)->order('sczl_gxh')
  458. ->column('sczl_gxh');
  459. foreach ($Process as $k=>$v){
  460. $res= \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  461. ->where('sczl_gxh',$v)
  462. ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
  463. ->find();
  464. if ($res['sczl_yjno']<10){
  465. $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
  466. }
  467. $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
  468. $processList['completed'] = \db('设备_产量计酬')
  469. ->where('sczl_gdbh',$workOrder)
  470. ->where('sczl_gxh',$v)
  471. ->count('DISTINCT sczl_num');
  472. array_push($data,$processList);
  473. }
  474. }
  475. $this->success('成功',$data);
  476. }
  477. /**
  478. * 班组人员及分配比例
  479. * @ApiMethod (GET)
  480. * @param string $machine 机台编号
  481. * @return void
  482. * @throws \think\db\exception\DataNotFoundException
  483. * @throws \think\db\exception\ModelNotFoundException
  484. * @throws \think\exception\DbException
  485. */
  486. public function Team()
  487. {
  488. if ($this->request->isGet() === false){
  489. $this->error('请求错误');
  490. }
  491. $machine = input('machine');
  492. if (empty($machine)){
  493. $this->error('参数错误');
  494. }
  495. $where = [
  496. 'sczl_jtbh' => $machine,
  497. ];
  498. $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,
  499. 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,
  500. 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,
  501. rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,
  502. rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10,rtrim(UniqId) as ID';
  503. $team = \db('设备_产量计酬')
  504. ->where('sczl_jtbh',$machine)
  505. ->field($field)
  506. ->order('UniqId desc')
  507. ->find();
  508. $list = \db('设备_班组资料')->where($where)->field($field)->select();
  509. $data = [];
  510. foreach ($list as $k=>$v){
  511. if ($team == $v){
  512. $data[$k]['status'] = 1;
  513. }else{
  514. $data[$k]['status'] = 0;
  515. }
  516. $data[$k]['ID'] = $v['ID'];
  517. $data[$k]['班组号'] = $v['班组号'];
  518. for ($i=1;$i<11;$i++){
  519. if ($v['bh'.$i] != ''){
  520. $name = \db('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
  521. if ($v['rate'.$i] > 0){
  522. $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
  523. }else{
  524. $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' (0.00%'.')';
  525. }
  526. }
  527. }
  528. }
  529. $this->success('成功',$data);
  530. }
  531. /**
  532. * 当班产量明细
  533. * @ApiMethod (GET)
  534. * @param string $machine 机台编号
  535. * @param string $workOrder 工单编号
  536. * @param string $team 班次
  537. * @return void
  538. * @throws \think\db\exception\DataNotFoundException
  539. * @throws \think\db\exception\ModelNotFoundException
  540. * @throws \think\exception\DbException
  541. */
  542. public function OutputDetail()
  543. {
  544. if ($this->request->isGet() === false){
  545. $this->error('请求错误');
  546. }
  547. $machine = input('machine');
  548. $workOrder = input('Gd_gdbh');
  549. $team = substr(input('team'),0,1);
  550. if (empty($machine) || empty($team)){
  551. $this->success('');
  552. }
  553. $sczlTime = date('Y-m-d H:i:s',time());
  554. if ($sczlTime>date('Y-m-d 00:00:00') && $sczlTime<date('Y-m-d 08:30:00')){
  555. $time = date('Y-m-d 00:00:00',time()-86400);
  556. }else{
  557. $time = date('Y-m-d 00:00:00');
  558. }
  559. $where = [
  560. 'sczl_jtbh' => $machine,
  561. 'sczl_bzdh' => ['like',$team.'%'],
  562. 'sczl_rq' => $time,
  563. ];
  564. $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 产量,
  565. rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,rtrim(sczl_装版工时) as 装版工时,
  566. rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常停机工时,rtrim(sczl_设备运行工时) as 通电工时,
  567. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
  568. rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2,rtrim(UniqId) as UniqId,rtrim(sczl_bh98) as 拉料,rtrim(sczl_ls) as ls';
  569. $list = \db('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
  570. if (!empty($list)){
  571. foreach ($list as $k=>$v){
  572. $name = \db('工单_印件资料')->where('Yj_Gdbh',$v['工单编号'])->where('yj_Yjno',$v['yjno'])->field('rtrim(yj_yjmc) as cpmc')->find();
  573. if ($v['yjno']<10){
  574. $list[$k]['yjno'] = '0'.$v['yjno'];
  575. }
  576. if (!empty($v['拉料'])){
  577. $list[$k]['拉料姓名'] = \db('人事_基本资料')->where('员工编号',$v['拉料'])->value('rtrim(员工姓名) as 员工姓名');
  578. }
  579. if (isset($list[$k]['拉料姓名']) === false){
  580. $list[$k]['拉料姓名'] = '';
  581. }
  582. $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
  583. $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
  584. $list[$k]['产品名称'] = $name['cpmc'];
  585. }
  586. $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
  587. SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
  588. SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
  589. SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
  590. $total = \db('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
  591. $total[0]['版数'] = count($list);
  592. $list['total'] = $total[0];
  593. }
  594. $this->success('成功',$list);
  595. }
  596. /**
  597. * 检验记录
  598. * @ApiMethod (GET)
  599. * @param string $machine 机台编号
  600. * @param string $workOrder 工单编号
  601. * @param string $team 班次
  602. * @return void
  603. * @throws \think\db\exception\DataNotFoundException
  604. * @throws \think\db\exception\ModelNotFoundException
  605. * @throws \think\exception\DbException
  606. */
  607. public function InspectionRecord()
  608. {
  609. if ($this->request->isGet() === false){
  610. $this->error('请求失败');
  611. }
  612. $machine = input('machine');
  613. $workOrder = input('Gd_gdbh');
  614. $team = input('team');
  615. if (empty($machine) || empty($workOrder) || empty($team)){
  616. $this->success('');
  617. }
  618. $where = [
  619. '设备编号' => $machine,
  620. '工单编号' => $workOrder,
  621. '班组编号' => $team,
  622. '类别' => ['in',['IPQC检验','机台检验']],
  623. ];
  624. //检验项目筛选
  625. $item = \db('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
  626. //检验时间
  627. $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
  628. foreach ($InspectionTime as $k=>$v){
  629. $InspectionTime[$k] = date('H:i',strtotime($v));
  630. }
  631. //检测记录详情
  632. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
  633. $nameDetail = \db('制程检验_记录')->where($where)->field($field)->find();
  634. $data = [];
  635. //检测数据
  636. foreach ($item as $key=>$value){
  637. $SubmissionTime = \db('制程检验_记录')->where($where)
  638. ->where('检验项目',$value)
  639. ->where('检验结果','合格')
  640. ->field('rtrim(提交时间) as 提交时间')
  641. ->select();
  642. $time = [];
  643. foreach ($SubmissionTime as $k=>$v){
  644. $time[$k] = date('H:i',strtotime($v['提交时间']));
  645. }
  646. $data[$key] = [
  647. '工单编号' => $nameDetail['工单编号'],
  648. '印件号' => $nameDetail['印件号'],
  649. '工序名称' => $nameDetail['工序名称'],
  650. '检验项目' => $value,
  651. 'inspectresult' => implode(',',$time),
  652. ];
  653. }
  654. $data['inspectiontime'] = $InspectionTime;
  655. $this->success('成功',$data);
  656. }
  657. /**
  658. * 班组维护->班组添加
  659. * @ApiMethod (GET)
  660. * @param void
  661. * @return void
  662. * @throws \think\db\exception\DataNotFoundException
  663. * @throws \think\db\exception\ModelNotFoundException
  664. * @throws \think\exception\DbException
  665. */
  666. public function MachineTeamAdd()
  667. {
  668. if (Request::instance()->isPost() === false ){
  669. $this->error('请求错误');
  670. }
  671. $param = Request::instance()->post();
  672. if (empty($param)){
  673. $this->error('参数错误');
  674. }
  675. $lastId = \db('设备_班组资料')
  676. ->order('UniqId desc')
  677. ->value('UniqId');
  678. if (empty($lastId)){
  679. $lastId = 0;
  680. }
  681. for($i=1;$i<11;$i++){
  682. if (!empty($param['sczl_bh'.$i])){
  683. $name = \db('人事_基本资料')->where('员工编号',$param['sczl_bh'.$i])->value('员工编号');
  684. if (empty($name)){
  685. $this->error('未找到编号'.$param['sczl_bh'.$i].'员工信息,无法添加,请输入正确的员工编号');
  686. }
  687. }
  688. }
  689. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  690. $param['UniqId'] = $lastId + 1;
  691. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  692. $sql = \db('设备_班组资料')->fetchSql(true)->insert($param);
  693. $res = \db()->query($sql);
  694. if ($res !== false){
  695. $this->success('成功');
  696. }else{
  697. $this->error('失败');
  698. }
  699. }
  700. /**
  701. * 机台编号列表
  702. * @ApiMethod (GET)
  703. * @return void
  704. */
  705. public function MachineList()
  706. {
  707. if ($this->request->isGet() === false){
  708. $this->error('请求错误');
  709. }
  710. $list = \db('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  711. if (empty($list)){
  712. $this->success('未找到机台编号');
  713. }
  714. $data = [];
  715. foreach ($list as $key=>$value){
  716. $data[$key] = $value['设备编号'] . '||' . $value['设备名称'];
  717. }
  718. $this->success('成功',$data);
  719. }
  720. /**
  721. * 删除班组信息
  722. * @ApiMethod (GET)
  723. * @param void
  724. * @return void
  725. * @throws \think\Exception
  726. * @throws \think\exception\PDOException
  727. */
  728. public function teamDel()
  729. {
  730. if (Request::instance()->isPost() === false){
  731. $this->error('请求错误');
  732. }
  733. $param = Request::instance()->post();
  734. if (empty($param)){
  735. $this->error('参数错误');
  736. }
  737. $machine = \db('设备_班组资料')
  738. ->where('UniqId',$param['UniqId'])
  739. ->value('sczl_jtbh');
  740. $teamId = \db('设备_产量采集')
  741. ->where('设备编号',$machine)
  742. ->order('UniqId desc')
  743. ->value('班组ID');
  744. if ($teamId === (int)$param['UniqId']){
  745. $this->success('无法删除正在生产的班组资料,请先切换班组');
  746. }
  747. $res = \db('设备_班组资料')
  748. ->where('UniqId',$param['UniqId'])
  749. ->delete();
  750. if ($res !== false){
  751. $this->success('成功');
  752. }else{
  753. $this->error('失败');
  754. }
  755. }
  756. /**
  757. * 管理人员现场巡检记录->展示
  758. * @ApiMethod (GET)
  759. * @param void
  760. * @return void
  761. * @throws \think\db\exception\DataNotFoundException
  762. * @throws \think\db\exception\ModelNotFoundException
  763. * @throws \think\exception\DbException
  764. */
  765. public function FieldInspectionRecord()
  766. {
  767. if ($this->request->isGet() === false){
  768. $this->error('请求错误');
  769. }
  770. $param = $this->request->param();
  771. if (empty($param)){
  772. $this->error('参数错误');
  773. }
  774. // $date = date('Y-m-d H:i:s',time());
  775. // if (empty($param['start'])){
  776. // $startTime = date('Y-m-d 08:30:00',time());
  777. // }else{
  778. // $startTime = date('Y-m-d H:i:s',strtotime($param['start']));
  779. // }
  780. // if ($date<$startTime){
  781. // $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  782. // }
  783. // 获取当前时间
  784. $current_time = time();
  785. // 设置时间范围
  786. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  787. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  788. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  789. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  790. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  791. // 判断当前时间属于哪个时间范围
  792. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  793. $startTime = date('Y-m-d') . ' 08:30:00';
  794. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  795. $startTime = date('Y-m-d') . ' 20:30:00';
  796. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  797. $startTime = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  798. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  799. $startTime = date('Y-m-d') . ' 20:30:00';
  800. }
  801. $where = [
  802. '工单编号' => $param['workOrder'],
  803. '开工时间' => $startTime,
  804. '类别' => '现场巡查记录',
  805. '班组编号' => ['like',substr($param['team'],0,1).'%']
  806. ];
  807. $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
  808. rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
  809. rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
  810. $list = \db('制程检验_记录')->where($where)
  811. ->field($filed)
  812. ->select();
  813. if (empty($list)){
  814. $this->success('',[]);
  815. }
  816. foreach ($list as $key=>$value){
  817. $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
  818. $list[$key]['归属时段'] = $value['开工时间'];
  819. $list[$key]['分钟差数'] = $number;
  820. if ($number != 0){
  821. $list[$key]['归属时段'] = date('Y-m-d H:i:s',strtotime($value['开工时间'])+$number*15*60);
  822. }
  823. }
  824. $this->success('成功',$list);
  825. }
  826. /**
  827. * 管理人员现场巡检记录->添加
  828. * @ApiMethod (POST)
  829. * @param void
  830. * @return void
  831. */
  832. public function FieldInspectionRecordAdd()
  833. {
  834. if (Request::instance()->isPost() === false){
  835. $this->error('请求错误');
  836. }
  837. $param = Request::instance()->post();
  838. if (empty($param)){
  839. $this->error('参数错误');
  840. }
  841. if ($param['processCode']<10){
  842. $param['processCode'] = '0'.$param['processCode'];
  843. }
  844. $date = date('Y-m-d H:i:s',time());
  845. $startTime = date('Y-m-d 08:30:00',time());
  846. if ($date<$startTime){
  847. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  848. }
  849. $data = [
  850. '类别' => $param['category'],
  851. '工单编号' => $param['workOrder'],
  852. '印件号' => $param['printCode'],
  853. '工序名称' => $param['processCode'].'-'.$param['process'],
  854. '流程单号' => $param['flowCode'],
  855. '设备编号' => $param['machine'],
  856. '班组编号' => $param['team'],
  857. '检验项目' => '['.$param['employeeCode'].'/'.$param['employeeName'].']',
  858. '相关标准' => '',
  859. '量测仪器' => '',
  860. '检验结果' => '',
  861. '检验备注' => $param['remark'],
  862. '提交时间' => date('Y-m-d H:i:s',time()),
  863. '开工时间' => $startTime,
  864. 'sys_id' => '',
  865. 'sys_rq' => date('Y-m-d H:i:s',time()),
  866. 'mod_rq' => '0000-00-00 00:00:00',
  867. 'UniqId' => \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
  868. ];
  869. $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
  870. $res = Db::query($sql);
  871. if ($res !== false){
  872. $this->success('成功');
  873. }else{
  874. $this->error('失败');
  875. }
  876. }
  877. /**
  878. * 设备点检->左侧菜单栏
  879. * @ApiMethod (GET)
  880. * @param void
  881. * @return void
  882. */
  883. public function SpotCheckItem()
  884. {
  885. if ($this->request->isGet() === false){
  886. $this->error('请求错误');
  887. }
  888. $param = $this->request->param();
  889. if (empty($param)){
  890. $this->error('参数错误');
  891. }
  892. $list = \db('设备_点检项目')
  893. ->where('适用机型','LIKE','%;'.$param['machine'].';%')
  894. ->distinct(true)
  895. ->column('部件名称','部件编号');
  896. if (empty($list)){
  897. $this->success('');
  898. }
  899. $this->success('成功',$list);
  900. }
  901. /**
  902. * 设备点检->检测项目
  903. * @ApiMethod (GET)
  904. * @param void
  905. * @return void
  906. * @throws \think\db\exception\DataNotFoundException
  907. * @throws \think\db\exception\ModelNotFoundException
  908. * @throws \think\exception\DbException
  909. */
  910. public function InspectionItem()
  911. {
  912. if ($this->request->isGet() === false){
  913. $this->error('请求错误');
  914. }
  915. $param = $this->request->param();
  916. if (empty($param)){
  917. $this->error('参数错误');
  918. }
  919. $list = \db('设备_点检项目')
  920. ->where('部件名称',$param['unitName'])
  921. ->where('适用机型','like','%'.$param['machine'].'#%')
  922. ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
  923. ->select();
  924. if (empty($list)){
  925. $this->success('未找到检测项目');
  926. }
  927. $this->success('成功',$list);
  928. }
  929. /**
  930. * 设备点检->检测记录添加
  931. * @ApiMethod (POST)
  932. * @param void
  933. * @return void
  934. * @throws \think\db\exception\DataNotFoundException
  935. * @throws \think\db\exception\ModelNotFoundException
  936. * @throws \think\exception\DbException
  937. */
  938. public function InspectionItemAdd()
  939. {
  940. if (Request::instance()->isPost() === false){
  941. $this->error('请求错误');
  942. }
  943. $param = Request::instance()->post();
  944. if (empty($param)){
  945. $this->error('参数错误');
  946. }
  947. $lastNumber = \db("设备_点检记录")->field('Uniqid as ID')->order('Uniqid desc')->find()['ID'];
  948. if (empty($lastNumber)){
  949. $lastId = 0;
  950. }else{
  951. $lastId = $lastNumber;
  952. }
  953. $row = [];
  954. foreach ($param as $key=>$value){
  955. $unitCode = \db('设备_点检项目')->where('部件名称',$value['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
  956. $row[$key] = [
  957. '日期' => date('Y-m-d 00:00:00',time()),
  958. '班组编号' => $value['team'],
  959. '点检设备' => $value['machine'],
  960. '部件编号' => $unitCode['部件编号'],
  961. '部件名称' => $value['unitName'],
  962. '检验项目' => $value['itemName'],
  963. '判定标准' => $value['standard'],
  964. '点检方法' => $value['method'],
  965. '点检结果' => $value['status'],
  966. '备注说明' => $value['remark'],
  967. 'Sys_id' =>'',
  968. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  969. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  970. 'Uniqid' => $lastId+$key+1
  971. ];
  972. }
  973. $sql = \db('设备_点检记录')->fetchSql(true)->insertAll($row);
  974. $res = Db::query($sql);
  975. if ($res !== false){
  976. $this->success('成功');
  977. }else{
  978. $this->error('失败');
  979. }
  980. }
  981. /**
  982. * 机台印版领用->左侧菜单
  983. * @ApiMethod (GET)
  984. * @param void
  985. * @return void
  986. */
  987. public function PrintGetTab()
  988. {
  989. if ($this->request->isGet() === false){
  990. $this->error('请求错误');
  991. }
  992. $param = $this->request->param();
  993. if (empty($param)){
  994. $this->error('参数错误');
  995. }
  996. $productCode = $param['productCode'];
  997. $sql = "SELECT DISTINCT(RTRIM(b.`名称`)) as `印版分类`,RTRIM(b.`编号`) as `编号` FROM `产品_印版资料` as a
  998. JOIN `物料_存货结构` as b ON b.`编号` = SUBSTRING(a.`存货编码`,1,4)
  999. WHERE a.YB_Cpdh = '{$productCode}'";
  1000. $res = Db::query($sql);
  1001. if (empty($res)){
  1002. $this->success('');
  1003. }
  1004. $this->success('成功',$res);
  1005. }
  1006. /**
  1007. * 机台印版领用记录->数据详情
  1008. * @ApiMethod (GET)
  1009. * @param void
  1010. * @return void
  1011. */
  1012. public function PrintDetail()
  1013. {
  1014. if (!$this->request->isGet()) {
  1015. $this->error('请求失败');
  1016. }
  1017. $param = $this->request->param();
  1018. if (empty($param)) {
  1019. $this->error('参数错误');
  1020. }
  1021. // 分页参数(带默认值)
  1022. $page = isset($param['page']) ? max(1, intval($param['page'])) : 1;
  1023. $limit = isset($param['limit']) ? min(max(1, intval($param['limit'])), 100) : 10;
  1024. $productCode = $param['productCode'];
  1025. $code = $param['code'] . '%';
  1026. $workOrder = $param['workOrder'];
  1027. // 1. 先查询总数
  1028. $countSql = "SELECT COUNT(*) AS total FROM (
  1029. SELECT
  1030. b.`供方批号`
  1031. FROM `产品_印版资料` a
  1032. JOIN `物料_存货编码` c ON c.`物料代码` = a.`存货编码`
  1033. JOIN `物料_存货结构` e ON e.`编号` = (
  1034. CASE
  1035. WHEN a.`存货编码` REGEXP '[A-Za-z]'
  1036. THEN SUBSTRING(a.`存货编码`, 1, 5)
  1037. ELSE SUBSTRING(a.`存货编码`, 1, 4)
  1038. END
  1039. )
  1040. JOIN `工单_基本资料` f ON a.YB_Cpdh = f.Gd_cpdh
  1041. LEFT JOIN `产品_印版库` b ON b.`存货编码` = a.`存货编码`
  1042. AND b.`报废日期` = '1900-01-01 00:00:00'
  1043. LEFT JOIN `工单_印版领用记录` d ON d.`Yb_供方批号` = b.`供方批号`
  1044. AND d.`Yb_工单编号` IS NOT NULL
  1045. WHERE
  1046. a.YB_Cpdh = '{$productCode}'
  1047. AND a.`存货编码` LIKE '{$code}'
  1048. AND f.Gd_gdbh = '{$workOrder}'
  1049. GROUP BY
  1050. a.`存货编码`,
  1051. b.`供方批号`
  1052. ) AS t";
  1053. $total = Db::query($countSql)[0]['total'] ?? 0;
  1054. // 2. 查询分页数据
  1055. $dataSql = "SELECT
  1056. RTRIM(a.`存货编码`) AS `存货编码`,
  1057. RTRIM(c.`物料名称`) AS `存货名称`,
  1058. RTRIM(b.`印版名称`) AS `印版名称`,
  1059. RTRIM(b.`供方批号`) AS `供方批号`,
  1060. RTRIM(b.`制造日期`) AS `制造日期`,
  1061. SUM(d.`Yb_印数`) AS `印数`,
  1062. RTRIM(e.`名称`) AS `印版类别`,
  1063. SUBSTRING(a.YB_Cpdh, 1, 4) AS `客户编号`,
  1064. RTRIM(f.`Gd_客户名称`) AS `客户名称`,
  1065. RTRIM(a.YB_Cpdh) AS `产品编号`,
  1066. RTRIM(f.Gd_cpmc) AS `产品名称`,
  1067. MAX(d.UniqID) AS UniqId,
  1068. MAX(CASE
  1069. WHEN d.`Yb_领用日期` IS NOT NULL AND d.`Yb_退还日期` IS NULL
  1070. THEN d.`Yb_工单编号`
  1071. ELSE NULL
  1072. END) AS `工单编号`
  1073. FROM `产品_印版资料` a
  1074. JOIN `物料_存货编码` c ON c.`物料代码` = a.`存货编码`
  1075. JOIN `物料_存货结构` e ON e.`编号` = (
  1076. CASE
  1077. WHEN a.`存货编码` REGEXP '[A-Za-z]'
  1078. THEN SUBSTRING(a.`存货编码`, 1, 5)
  1079. ELSE SUBSTRING(a.`存货编码`, 1, 4)
  1080. END
  1081. )
  1082. JOIN `工单_基本资料` f ON a.YB_Cpdh = f.Gd_cpdh
  1083. LEFT JOIN `产品_印版库` b ON b.`存货编码` = a.`存货编码`
  1084. AND b.`报废日期` = '1900-01-01 00:00:00'
  1085. LEFT JOIN `工单_印版领用记录` d ON d.`Yb_供方批号` = b.`供方批号`
  1086. AND d.`Yb_工单编号` IS NOT NULL
  1087. WHERE
  1088. a.YB_Cpdh = '{$productCode}'
  1089. AND a.`存货编码` LIKE '{$code}'
  1090. AND f.Gd_gdbh = '{$workOrder}'
  1091. GROUP BY
  1092. a.`存货编码`,
  1093. c.`物料名称`,
  1094. b.`印版名称`,
  1095. b.`供方批号`,
  1096. b.`制造日期`,
  1097. e.`名称`,
  1098. f.`Gd_客户名称`,
  1099. a.YB_Cpdh,
  1100. f.Gd_cpmc
  1101. ORDER BY a.`存货编码`
  1102. LIMIT " . ($page - 1) * $limit . ", " . $limit;
  1103. $list = Db::query($dataSql);
  1104. $this->success('成功', [
  1105. 'data' => $list ?: [],
  1106. 'total' => $total,
  1107. ]);
  1108. }
  1109. /**
  1110. * 换型清场->左侧菜单栏
  1111. * @ApiMethod (GET)
  1112. * @param void
  1113. * @return void
  1114. */
  1115. public function remodelGetTab()
  1116. {
  1117. if ($this->request->isGet() === false){
  1118. $this->error('请求错误');
  1119. }
  1120. $date = date('Y-m-d 00:00:00',time()-3456000);
  1121. $nowTime = date('Y-m-d H:i:s',time());
  1122. $list = \db('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
  1123. if (empty($list)){
  1124. $this->error('失败');
  1125. }
  1126. $sql = "SELECT RTRIM(a.`设备编号`) as `设备编号`,RTRIM(b.`日期`) as `日期`,RTRIM(b.UniqId) as UniqId
  1127. FROM `设备_基本资料` as a
  1128. LEFT JOIN `制程_换型清场` as b ON b.`机台编号` = a.`设备编号`
  1129. WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' AND b.`工单编号A` <> '' AND b.`工单编号B` <> '' ORDER BY b.`UniqId`";
  1130. $res = Db::query($sql);
  1131. $data = $result = [];
  1132. foreach ($list as $key=>$value){
  1133. $data[$value] = $result[$value]= $time = [];
  1134. foreach ($res as $k=>$v){
  1135. if ($value === $v['设备编号']){
  1136. $row = [
  1137. '日期' => $v['日期'],
  1138. 'id' => $v['UniqId']
  1139. ];
  1140. array_push($data[$value],$row);
  1141. }
  1142. }
  1143. foreach ($data[$value] as $m=>$n){
  1144. $time[$m] = $n['日期'];
  1145. }
  1146. $time = array_values(array_unique($time));
  1147. foreach ($time as $kk=>$vv){
  1148. $i=1;
  1149. foreach ($data[$value] as $kkk=>$vvv){
  1150. if ($kkk>=$kk && $vv === $vvv['日期']){
  1151. array_push($result[$value],date('Y-m-d',strtotime($vv)).'第'.$i.'次换型/'.$vvv['id']);
  1152. $i++;
  1153. }
  1154. }
  1155. }
  1156. }
  1157. $this->success('成功',$result);
  1158. }
  1159. /**
  1160. * 换型清场->详情
  1161. * @return void
  1162. * @throws \think\db\exception\DataNotFoundException
  1163. * @throws \think\db\exception\ModelNotFoundException
  1164. * @throws \think\exception\DbException
  1165. */
  1166. public function RemodelDetail()
  1167. {
  1168. if ($this->request->isGet() === false){
  1169. $this->error('请求错误');
  1170. }
  1171. $param = $this->request->param();
  1172. if (empty($param)){
  1173. $this->error('参数错误');
  1174. }
  1175. $field = 'rtrim(日期) as 日期,rtrim(班组) as 班组,rtrim(机台编号) as 机台编号,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1176. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包B,
  1177. rtrim(清场项目A) as 项目1,rtrim(清场项目B) as 项目2,rtrim(清场项目C) as 项目3,rtrim(清场项目D) as 项目4,rtrim(清场项目E) as 项目5,
  1178. rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
  1179. $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
  1180. if (empty($list)){
  1181. $this->success('未找到该条清场记录');
  1182. }
  1183. $list['日期'] = date('Y-m-d',strtotime($list['日期']));
  1184. $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find();
  1185. if (empty($printNameA)){
  1186. $list['印件名称A'] = '';
  1187. }else{
  1188. $list['印件名称A'] = $printNameA['yjmc'];
  1189. }
  1190. $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find();
  1191. if (empty($printNameB)){
  1192. $list['印件名称B'] = '';
  1193. }else{
  1194. $list['印件名称B'] = $printNameB['yjmc'];
  1195. }
  1196. $this->success('成功',$list);
  1197. }
  1198. /**
  1199. * 换型清场->当前设备清场记录
  1200. * @ApiMethod (GET)
  1201. * @param void
  1202. * @return void
  1203. * @throws \think\db\exception\DataNotFoundException
  1204. * @throws \think\db\exception\ModelNotFoundException
  1205. * @throws \think\exception\DbException
  1206. */
  1207. public function ModelChangeRecord()
  1208. {
  1209. if ($this->request->isGet() === false){
  1210. $this->error('请求错误');
  1211. }
  1212. $param = $this->request->param();
  1213. if (empty($param)){
  1214. $this->error('参数错误');
  1215. }
  1216. $date = date('Y-m-d 00:00:00',time()-3888000);
  1217. $nowTime = date('Y-m-d H:i:s',time());
  1218. $where = [
  1219. '日期' =>['between',[$date,$nowTime]],
  1220. '机台编号' => $param['machine'],
  1221. '工单编号A' => ['<>',''],
  1222. '工单编号B' => ['<>',''],
  1223. ];
  1224. $field = "rtrim(日期) as 日期,rtrim(机台编号) as 机台编号,rtrim(班组) as 班组,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1225. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包号B,rtrim(清场项目A) as 清场项目A,
  1226. rtrim(清场项目B) as 清场项目B,rtrim(清场项目C) as 清场项目C,rtrim(清场项目D) as 清场项目D,rtrim(清场项目E) as 清场项目E,rtrim(机长) as 机长,
  1227. rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员,rtrim(sys_rq) as 创建时间,rtrim(UniqId) as UNIQID";
  1228. $list = \db('制程_换型清场')
  1229. ->where($where)
  1230. ->field($field)
  1231. ->select();
  1232. if (empty($list)){
  1233. $this->success('未找到换型记录');
  1234. }
  1235. foreach ($list as $key=>$value){
  1236. $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号A'])->value('rtrim(yj_yjmc) as yjmc');
  1237. if (empty($printNameA)){
  1238. $list[$key]['印件名称A'] = '';
  1239. }else{
  1240. $list[$key]['印件名称A'] = $printNameA;
  1241. }
  1242. $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号B'])->value('rtrim(yj_yjmc) as yjmc');
  1243. if (empty($printNameB)){
  1244. $list[$key]['印件名称B'] = '';
  1245. }else{
  1246. $list[$key]['印件名称B'] = $printNameB;
  1247. }
  1248. }
  1249. $this->success('成功',$list);
  1250. }
  1251. /**
  1252. * 车间机台状态列表展示
  1253. * @ApiMethod (GET)
  1254. * @param void
  1255. * @return void
  1256. * @throws \think\db\exception\BindParamException
  1257. * @throws \think\exception\PDOException
  1258. */
  1259. public function MachineDetailList()
  1260. {
  1261. if ($this->request->isGet() === false){
  1262. $this->error('请求错误');
  1263. }
  1264. $param = $this->request->param();
  1265. if (empty($param)){
  1266. $this->error('参数错误');
  1267. }
  1268. $workshop = $param['workshop'];
  1269. $sql = "SELECT
  1270. RTRIM( a.`设备编号` ) AS 设备编号,
  1271. RTRIM( a.`设备名称` ) AS 设备名称,
  1272. RTRIM( d.`当前状态` ) AS 状态
  1273. FROM
  1274. `设备_基本资料` AS a
  1275. JOIN (
  1276. SELECT
  1277. b.`设备编号`,
  1278. b.`当前状态`,
  1279. b.`开工时间`
  1280. FROM
  1281. `设备_产量采集` AS b
  1282. JOIN ( SELECT `设备编号`, MAX( `UniqId` ) AS `UniqId` FROM `设备_产量采集` GROUP BY `设备编号` ) AS c ON b.`设备编号` = c.`设备编号`
  1283. AND b.`UniqId` = c.`UniqId`
  1284. ) AS d ON a.`设备编号` = d.`设备编号`
  1285. WHERE
  1286. a.`使用部门` = '{$workshop}'
  1287. GROUP BY
  1288. a.`设备编号`
  1289. ORDER BY
  1290. a.UniqId";
  1291. $list = \db()->query($sql);
  1292. foreach ($list as $key=>$value){
  1293. if ($value['状态'] == ''){
  1294. $list[$key]['状态'] = '待单';
  1295. }
  1296. }
  1297. $this->success('成功',$list);
  1298. }
  1299. /**
  1300. * 机台当前参数展示
  1301. * @ApiMethod (GET)
  1302. * @return void
  1303. * @throws \think\db\exception\DataNotFoundException
  1304. * @throws \think\db\exception\ModelNotFoundException
  1305. * @throws \think\exception\DbException
  1306. */
  1307. public function MachineDetail()
  1308. {
  1309. if ($this->request->isGet() === false){
  1310. $this->error('请求错误');
  1311. }
  1312. $param = $this->request->param();
  1313. if (empty($param)){
  1314. $this->error('参数错误');
  1315. }
  1316. $data = [];
  1317. if ($param['start'] === ''){
  1318. 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())){
  1319. $param['start'] = date('Y-m-d 08:30:00',time());
  1320. }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())){
  1321. $param['start'] = date('Y-m-d 20:30:00',time());
  1322. }else{
  1323. $param['start'] = date('Y-m-d 20:30:00',time()-86400);
  1324. }
  1325. }
  1326. $machineDetail = \db('设备_产量采集')
  1327. ->alias('a')
  1328. ->join('设备_基本资料 b','a.设备编号 = b.设备编号')
  1329. ->join('工单_工艺资料 c', "a.工单编号 = c.Gy0_gdbh AND c.Gy0_sbbh LIKE CONCAT('%', a.设备编号, '%')")
  1330. ->join('工单_基本资料 d','a.工单编号 = d.Gd_gdbh')
  1331. ->field([
  1332. 'rtrim(a.开工时间)' => '开工时间',
  1333. 'rtrim(a.设备编号)' => '设备编号',
  1334. 'rtrim(a.工单编号)' => '工单编号',
  1335. 'rtrim(b.设备名称)' => '设备名称',
  1336. 'rtrim(c.Gy0_gxh)' => '工序号',
  1337. 'rtrim(c.Gy0_gxmc)' => '工序名称',
  1338. 'rtrim(d.Gd_cpmc)' => '产品名称'
  1339. ])
  1340. ->where('a.设备编号', $param['machine'])
  1341. ->order('a.UniqId desc')
  1342. ->find();
  1343. $data['machine'] = [
  1344. '日期' => $machineDetail['开工时间'],
  1345. '设备' => $machineDetail['设备编号'].'-->'.$machineDetail['设备名称'],
  1346. '工单' => $machineDetail['工单编号'].'-->'.$machineDetail['产品名称'],
  1347. '工艺' => ($machineDetail['工序号']<10?'0'.$machineDetail['工序号']:$machineDetail['工序号']).'--'.$machineDetail['工序名称']
  1348. ];
  1349. //机台状态时间
  1350. $startTime = \db('设备_产量采集')
  1351. ->where('设备编号',$param['machine'])
  1352. ->where('开工时间',$param['start'])
  1353. ->field('rtrim(时间) as 时间,当班产量,rtrim(当前状态) as 状态,MAX(时间) as 最大时间,MAX(当班产量) as 最大产量')
  1354. ->group('当前状态')
  1355. ->select();
  1356. if (!empty($startTime)){
  1357. foreach ($startTime as $key=>$value){
  1358. $data['timeDifference'][$key] = [
  1359. '时间' => round((strtotime($value['最大时间'])-strtotime($value['时间']))/3600,2),
  1360. '状态' => $value['状态'] = null?'待单':$value['状态'],
  1361. ];
  1362. if ($value['状态'] === '生产'){
  1363. $data['当班产量'] = $value['最大产量']-$value['当班产量'];
  1364. }
  1365. }
  1366. }else{
  1367. $data['timeDifference'][0] = [
  1368. '时间' => 0,
  1369. '状态' => '待单'
  1370. ];
  1371. $data['当班产量'] = 0;
  1372. }
  1373. //机台产能/时间明细
  1374. $row = \db('设备_产量采集')
  1375. ->where('设备编号',$param['machine'])
  1376. ->where('开工时间',$param['start'])
  1377. ->where('当班产量','<>',-1)
  1378. ->field('rtrim(时间) as 时间,rtrim(当班产量) as 产量,rtrim(当前状态) as 状态')
  1379. ->select();
  1380. if (empty($row)){
  1381. $data['row'] = [];
  1382. }
  1383. foreach ($row as $key=>$value){
  1384. $data['row'][$key]['时间'] = date('Y-m-d H:i',strtotime($value['时间']));
  1385. $data['row'][$key]['状态'] = $value['状态'];
  1386. if ($key<2){
  1387. $data['row'][$key]['产能'] = 0;
  1388. }else{
  1389. $data['row'][$key]['产能'] = ($row[$key-1]['产量']-$row[$key-2]['产量'])*60;
  1390. }
  1391. }
  1392. //机台状态
  1393. $status = end($row);
  1394. if (empty($status['状态'])){
  1395. $data['status'] = '待单';
  1396. }else{
  1397. $data['status'] = $status['状态'];
  1398. }
  1399. //检验数据
  1400. $list = \db('制程检验_记录')
  1401. ->where('开工时间',$param['start'])
  1402. ->where('设备编号',$param['machine'])
  1403. ->where('sys_rq','>',$param['start'])
  1404. ->where('工单编号',$machineDetail['工单编号'])
  1405. ->field('rtrim(类别) as 类别,提交时间')
  1406. ->select();
  1407. $data['首件'] = $data['自检'] = $data['IPQC'] = [];
  1408. if (!empty($list)){
  1409. foreach ($list as $key=>$value){
  1410. if ($value['类别'] == '首件与过程确认'){
  1411. array_push($data['首件'],$value['提交时间']);
  1412. }
  1413. if ($value['类别'] == '机台检验'){
  1414. array_push($data['自检'],$value['提交时间']);
  1415. }
  1416. if ($value['类别'] == 'IPQC检验'){
  1417. array_push($data['IPQC'],$value['提交时间']);
  1418. }
  1419. }
  1420. $data['首件'] = array_values(array_unique($data['首件']));
  1421. $data['自检'] = array_values(array_unique($data['自检']));
  1422. $data['IPQC'] = array_values(array_unique($data['IPQC']));
  1423. }else{
  1424. $data['首件'] = [];
  1425. $data['自检'] = [];
  1426. $data['IPQC'] = [];
  1427. }
  1428. $this->success('成功',$data);
  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 ProcessInspectionRecordsItem()
  1440. {
  1441. if ($this->request->isGet() === false){
  1442. $this->error('请求错误');
  1443. }
  1444. $param = $this->request->param();
  1445. if (empty($param)){
  1446. $this->error('参数错误');
  1447. }
  1448. $list = \db('制程检验_项目')
  1449. ->where('工序','like','%'.$param['process'].'%')
  1450. ->select();
  1451. if (empty($list)){
  1452. $this->success('未找到检测项目');
  1453. }
  1454. $data = [];
  1455. foreach ($list as $key=>$value){
  1456. $data['首件']['指标检验'][$key] = [
  1457. '检验项目' => rtrim($value['检测项目']),
  1458. '检测方法' => rtrim($value['检测方法']),
  1459. '检验频率' => rtrim($value['首件签样要求']),
  1460. '相关标准' => rtrim($value['技术要求'])
  1461. ];
  1462. $data['机台检验']['指标检验'][$key] = [
  1463. '检验项目' => rtrim($value['检测项目']),
  1464. '检测方法' => rtrim($value['检测方法']),
  1465. '检验频率' => rtrim($value['机台自检频率']),
  1466. '相关标准' => rtrim($value['技术要求'])
  1467. ];
  1468. $data['IPQC']['指标检验'][$key] = [
  1469. '检验项目' => rtrim($value['检测项目']),
  1470. '检测方法' => rtrim($value['检测方法']),
  1471. '检验频率' => rtrim($value['IPQC检验频率']),
  1472. '相关标准' => rtrim($value['技术要求'])
  1473. ];
  1474. }
  1475. $row = \db('制程检验_项目附加')
  1476. ->where('工序','like','%'.$param['process'].'%')
  1477. ->select();
  1478. foreach ($row as $key=>$value){
  1479. $data['首件']['附加'][$key] = [
  1480. '缺陷备注' => rtrim($value['缺陷备注']),
  1481. '编号' => rtrim($value['编号'])
  1482. ];
  1483. $data['机台检验']['附加'][$key] = [
  1484. '缺陷备注' => rtrim($value['缺陷备注']),
  1485. '编号' => rtrim($value['编号'])
  1486. ];
  1487. $data['IPQC']['附加'][$key] = [
  1488. '缺陷备注' => rtrim($value['缺陷备注']),
  1489. '编号' => rtrim($value['编号'])
  1490. ];
  1491. }
  1492. $this->success('成功',$data);
  1493. }
  1494. /**
  1495. * 车间报工
  1496. * 制程检验记录->检测记录添加
  1497. */
  1498. public function ProcessInspectionRecordsItemAdd(){
  1499. if (Request::instance()->isPost() === false){
  1500. $this->error('请求错误');
  1501. }
  1502. $param = Request::instance()->post();
  1503. if (empty($param)){
  1504. $this->error('参数错误');
  1505. }
  1506. $startID = \db('制程检验_记录')->order('UniqId desc')->value('UniqId');
  1507. if (empty($startID)){
  1508. $startID = 0;
  1509. }
  1510. $process = \db('工单_工艺资料')
  1511. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1512. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1513. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1514. ->find();
  1515. $startTime = \db('设备_产量采集')
  1516. ->where('设备编号', 'like', '%' . $param[0]['machine'] . '#%')
  1517. ->where('工单编号', $param[0]['workOrder'])
  1518. ->order('UniqId desc')
  1519. ->find();
  1520. // 解决车间因未更换班组,导致开工时间仍为前一个班次,导致下一个班组进行上报时数据录到了前一个班次中的问题
  1521. if (!$startTime) {
  1522. $this->error('未找到对应的开工时间');
  1523. }
  1524. /*
  1525. * 系统提交时间(应报工时间)和开工时间
  1526. */
  1527. // $startTime = $startTime['开工时间'];
  1528. $rqTime = isset($param[0]['rq']) ? $param[0]['rq'] : date('Y-m-d H:i:s');
  1529. //转换为时间戳
  1530. $rqTimestamp = strtotime($rqTime);
  1531. $startTimestamp = strtotime($startTime['开工时间']);
  1532. // 计算时间差(秒)
  1533. $timeDiff = abs($rqTimestamp - $startTimestamp); // 取绝对值,防止负数
  1534. /*
  1535. * 计算时间差
  1536. */
  1537. // 转换时间差为 天、小时、分钟、秒
  1538. $days = floor($timeDiff / 86400);
  1539. $hours = floor(($timeDiff % 86400) / 3600);
  1540. $minutes = floor(($timeDiff % 3600) / 60);
  1541. $seconds = $timeDiff % 60;
  1542. // 格式化时间差
  1543. $formattedDiff = "";
  1544. if ($days > 0) $formattedDiff .= $days . "天";
  1545. if ($hours > 0) $formattedDiff .= $hours . "小时";
  1546. if ($minutes > 0) $formattedDiff .= $minutes . "分钟";
  1547. if ($seconds > 0) $formattedDiff .= $seconds . "秒";
  1548. //测试进行时间比较,查看时间判断是否正确
  1549. // echo "<pre>";
  1550. // print_r("系统提交时间:" .$rqTime);
  1551. // print_r("\n当前开工时间:" . $startTime);
  1552. // print_r("\n时间差:" . $formattedDiff);
  1553. // echo "<pre>";
  1554. // 判断是否超过 12 小时(12 * 3600 = 43200 秒)
  1555. if ($timeDiff > 43200) {
  1556. $this->error('请先更换班组后,再提交数据');
  1557. }
  1558. if ((int)$process['gxh']<10){
  1559. $process['gxh'] = '0'.$process['gxh'];
  1560. }
  1561. if ($process['add_gxmc'] !== ''){
  1562. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1563. }else{
  1564. $printName = $process['gxh'].'-'.$process['gxmc'];
  1565. }
  1566. if (empty($process)){
  1567. $this->success('数据错误');
  1568. }
  1569. $data = [];
  1570. foreach ($param as $key=>$value){
  1571. $data[$key] = [
  1572. '类别' => $value['category'],
  1573. '工单编号' => $value['workOrder'],
  1574. '印件号' => $value['yjno'],
  1575. '工序名称' => $printName,
  1576. '流程单号' => $value['flow'],
  1577. '设备编号' => $value['machine'].'#',
  1578. '班组编号' => $startTime['班组编号'],
  1579. '检验项目' => $value['item'],
  1580. '相关标准' => $value['standard'],
  1581. '量测仪器' => $value['instrument'],
  1582. '检验结果' => $value['selected'],
  1583. '检验备注' => $value['remark'],
  1584. '提交时间' => date('Y-m-d H:i:s',time()),
  1585. '开工时间' => rtrim($startTime['开工时间']),
  1586. 'sys_id' => '',
  1587. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1588. 'mod_rq' => '0000-00-00 00:00:00',
  1589. 'UniqId' => $startID + $key +1
  1590. ];
  1591. }
  1592. $res = \db('制程检验_记录')->insertAll($data);
  1593. if ($res !== false){
  1594. $this->success('成功');
  1595. }else{
  1596. $this->error('失败');
  1597. }
  1598. }
  1599. /**
  1600. * 制程检验记录->附加检验记录添加
  1601. * @ApiMethod (POST)
  1602. * @param void
  1603. * @return void
  1604. * @throws \think\db\exception\DataNotFoundException
  1605. * @throws \think\db\exception\ModelNotFoundException
  1606. * @throws \think\exception\DbException
  1607. */
  1608. public function AdditionalInspectionRecordAdd()
  1609. {
  1610. if (Request::instance()->isPost() === false){
  1611. $this->error('请求错误');
  1612. }
  1613. $param = Request::instance()->post();
  1614. if (empty($param)){
  1615. $this->error('参数错误');
  1616. }
  1617. $startID = \db('制程检验_记录附加')->order('UniqId desc')->value('UniqId');
  1618. if (empty($startID)){
  1619. $startID = 0;
  1620. }
  1621. $process = \db('工单_工艺资料')
  1622. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1623. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1624. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1625. ->find();
  1626. $startTime = \db('设备_产量采集')
  1627. ->where('设备编号','like','%'.$param[0]['machine'].'#%')
  1628. ->where('工单编号',$param[0]['workOrder'])
  1629. ->order('UniqId desc')
  1630. ->find();
  1631. if ((int)$process['gxh']<10){
  1632. $process['gxh'] = '0'.$process['gxh'];
  1633. }
  1634. if ($process['add_gxmc'] !== ''){
  1635. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1636. }else{
  1637. $printName = $process['gxh'].'-'.$process['gxmc'];
  1638. }
  1639. if (empty($process)){
  1640. $this->success('数据错误');
  1641. }
  1642. $data = [];
  1643. foreach ($param as $key=>$value){
  1644. $data[$key] = [
  1645. '工单编号' => $value['workOrder'],
  1646. '印件号' => $value['yjno'],
  1647. '工序名称' => $printName,
  1648. '流程单号' => $value['flow'],
  1649. '设备编号' => $value['machine'],
  1650. '班组编号' => $startTime['班组编号'],
  1651. '缺陷备注' => $value['remark'],
  1652. '提交时间' => date('Y-m-d H:i:s',time()),
  1653. '开工时间' => rtrim($startTime['开工时间']),
  1654. 'sys_id' => '',
  1655. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1656. 'mod_rq' => '0000-00-00 00:00:00',
  1657. 'UniqId' => $startID + $key +1
  1658. ];
  1659. }
  1660. $res = \db('制程检验_记录附加')->insertAll($data);
  1661. if ($res !== false){
  1662. $this->success('成功');
  1663. }else{
  1664. $this->error('失败');
  1665. }
  1666. }
  1667. /**
  1668. * 客诉记录
  1669. * @ApiMethod (GET)
  1670. * @param void
  1671. * @return void
  1672. * @throws \think\db\exception\DataNotFoundException
  1673. * @throws \think\db\exception\ModelNotFoundException
  1674. * @throws \think\exception\DbException
  1675. */
  1676. public function ComplaintRecord()
  1677. {
  1678. if ($this->request->isGet() === false){
  1679. $this->error('请求错误');
  1680. }
  1681. $param = $this->request->param();
  1682. if (isset($param['productCode'])){
  1683. $where['产品编号'] = $param['productCode'];
  1684. }
  1685. $filed = "rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,rtrim(客诉日期) as 客诉日期,rtrim(客诉单号) as 客诉单号,
  1686. rtrim(客诉方式) as 客诉方式,rtrim(订单编号) as 订单编号,rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,
  1687. rtrim(客诉描述) as 客诉描述,rtrim(缺陷关键字) as 缺陷关键字,rtrim(客诉性质) as 客诉性质,rtrim(扣分) as 扣分,
  1688. rtrim(主要责任部门) as 主要责任部门,rtrim(次要责任部门) as 次要责任部门";
  1689. $list = \db('db_客诉记录')
  1690. ->where($where)
  1691. ->field($filed)
  1692. ->select();
  1693. if (empty($list)){
  1694. $this->success('未找到该产品客诉记录');
  1695. }
  1696. $this->success('成功',$list);
  1697. }
  1698. /**
  1699. * 设置机台班组信息
  1700. * @return void
  1701. * @throws \think\db\exception\DataNotFoundException
  1702. * @throws \think\db\exception\ModelNotFoundException
  1703. * @throws \think\exception\DbException
  1704. */
  1705. public function setMachineTeam()
  1706. {
  1707. if (Request::instance()->isPost() == false) {
  1708. $this->error('非法请求');
  1709. }
  1710. $params = Request::instance()->post();
  1711. if (!isset($params['machine']) || empty($params['machine'] )) {
  1712. $this->error('参数不能为空');
  1713. }
  1714. if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
  1715. $this->error('请先选择班组成员');
  1716. }
  1717. $machine = $params['machine'] . '#';
  1718. $data = [];
  1719. $lastData = \db('设备_产量采集')
  1720. ->order('UniqId desc')
  1721. ->find();
  1722. $id = $lastData['UniqId']+1;
  1723. $data['当前状态'] = $params['status'];
  1724. $data['时间'] = date('Y-m-d H:i:s');
  1725. $data['设备编号'] = $machine;
  1726. $data['工单编号'] = empty($params['order']) ? '':$params['order'];
  1727. $data['印件号'] = empty($params['yjno']) ? '':$params['yjno'];
  1728. $data['工序号'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
  1729. $data['工序名称'] = empty($params['gy_name']) ? '' : $params['gy_name'];
  1730. $data['当班产量'] = $params['production_now'];
  1731. $data['累计产量'] = $params['production_all'];
  1732. $data['班组编号'] = $params['sczl_bzdh'];
  1733. $data['班组ID'] = $params['team_id'];
  1734. // 获取当前时间
  1735. $current_time = time();
  1736. // 设置时间范围
  1737. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  1738. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  1739. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  1740. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  1741. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  1742. // 判断当前时间属于哪个时间范围
  1743. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  1744. $data['开工时间'] = date('Y-m-d') . ' 08:30:00';
  1745. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  1746. $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  1747. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  1748. $data['开工时间'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  1749. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  1750. $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  1751. }
  1752. if (!empty($params['order']) && !empty($params['yjno'])){
  1753. $option['Gy0_gdbh'] = $params['order'];
  1754. $option['Gy0_yjno'] = $params['yjno'];
  1755. $option['Gy0_gxh'] = $data['工序号'];
  1756. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  1757. }else{
  1758. $data['任务ID'] = '';
  1759. }
  1760. $data['UniqId'] = $id;
  1761. $sql = \db('设备_产量采集')->fetchSql(true)->insert($data);
  1762. $res = Db::query($sql);
  1763. if ($res === false) {
  1764. $this->error('设置失败');
  1765. } else {
  1766. $this->success('设置成功');
  1767. }
  1768. }
  1769. /**
  1770. * 首页数据
  1771. * @return void
  1772. * @throws \think\Exception
  1773. * @throws \think\db\exception\DataNotFoundException
  1774. * @throws \think\db\exception\ModelNotFoundException
  1775. * @throws \think\exception\DbException
  1776. */
  1777. public function index()
  1778. {
  1779. if ($this->request->isGet() === false){
  1780. $this->error('请求错误');
  1781. }
  1782. $nowTime = date('Y-m-d H:i:s',time());
  1783. $oldTime = (date('Y')-1).'-'.date('m-d H:i:s');
  1784. $where =[
  1785. 'Mod_rq' => ['between',[$oldTime,$nowTime]],
  1786. '行号' => '1'
  1787. ];
  1788. $data = [];
  1789. //按状态查询工单信息
  1790. $orderList = \db('工单_基本资料')
  1791. ->where($where)
  1792. ->field('count(Gd_gdbh) as 数量,rtrim(gd_statu) as 状态')
  1793. ->group('gd_statu')
  1794. ->select();
  1795. foreach ($orderList as $value){
  1796. if ($value['状态'] === '1-已完工'){
  1797. $data['workOrderData']['已完工'] = $value['数量'];
  1798. }
  1799. if ($value['状态'] === '3-计划中'){
  1800. $data['workOrderData']['计划中'] = $value['数量'];
  1801. }
  1802. }
  1803. $data['workOrderData']['排程中'] = db('工单_基本资料')->alias('a')
  1804. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  1805. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  1806. ->where([
  1807. 'a.gd_statu' => '2-生产中',
  1808. 'a.行号' => '1',
  1809. 'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
  1810. 'b.PD_WG' => '1900-01-01 00:00:00',
  1811. 'b.Gy0_sj1' => '1900-01-01 00:00:00',
  1812. 'c.状态' => '',
  1813. ])
  1814. ->group('a.Gd_gdbh')
  1815. ->count();
  1816. $data['workOrderData']['制程中'] = db('工单_基本资料')->alias('a')
  1817. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  1818. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  1819. ->where([
  1820. 'a.gd_statu' => '2-生产中',
  1821. 'a.行号' => '1',
  1822. 'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
  1823. 'b.PD_WG' => '1900-01-01 00:00:00',
  1824. 'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'],
  1825. 'c.状态' => '',
  1826. ])
  1827. ->group('a.Gd_gdbh')
  1828. ->count();
  1829. //按月份查询工单信息
  1830. $data['monthData'] = \db('工单_基本资料')
  1831. ->where('Mod_rq', 'between', [$oldTime, $nowTime])
  1832. ->field('DATE_FORMAT(Mod_rq, "%Y-%m") as month, COUNT(*) as count')
  1833. ->group('month')
  1834. ->order('month')
  1835. ->select();
  1836. //查询最近十条客诉信息
  1837. $data['customer'] = \db('db_客诉记录')
  1838. ->field('rtrim(客诉描述) as 客诉描述,DATE_FORMAT(客诉日期, "%Y-%m-%d") as 日期,rtrim(UniqID) as UniqId')
  1839. ->limit(10)
  1840. ->order('Sys_rq desc')
  1841. ->select();
  1842. $this->success('成功',$data);
  1843. }
  1844. /**
  1845. * 员工信息获取
  1846. * @return void
  1847. * @throws \think\db\exception\DataNotFoundException
  1848. * @throws \think\db\exception\ModelNotFoundException
  1849. * @throws \think\exception\DbException
  1850. */
  1851. public function EmployeeData()
  1852. {
  1853. if ($this->request->isGet() === false){
  1854. $this->error('请求错误');
  1855. }
  1856. $param = $this->request->param();
  1857. if (isset($param['code']) === false){
  1858. $this->error('参数错误');
  1859. }
  1860. $res = \db('人事_基本资料')
  1861. ->where('员工编号','like',$param['code'].'%')
  1862. ->field('rtrim(员工编号) as 员工编号,rtrim(员工姓名) as 员工姓名')
  1863. ->select();
  1864. if (empty($res)){
  1865. $this->success('未找到该员工');
  1866. }
  1867. $this->success('成功',$res);
  1868. }
  1869. /**
  1870. * 换型清场添加
  1871. * @return void
  1872. * @throws \think\db\exception\BindParamException
  1873. * @throws \think\exception\PDOException
  1874. */
  1875. public function remodelDataAdd()
  1876. {
  1877. if (Request::instance()->isPost() === false){
  1878. $this->error('请求错误');
  1879. }
  1880. $param = Request::instance()->post();
  1881. if (empty($param)){
  1882. $this->error('参数错误');
  1883. }
  1884. $lastId = \db('制程_换型清场')->order('UniqId desc')->value('UniqId');
  1885. $param['sys_id'] = '['.$param['机台编号'].']';
  1886. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  1887. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1888. $param['UniqId'] = $lastId + 1;
  1889. $sql = \db('制程_换型清场')->fetchSql(true)->insert($param);
  1890. $res = \db()->query($sql);
  1891. if ($res !== false){
  1892. $this->success('成功');
  1893. }else{
  1894. $this->error('失败');
  1895. }
  1896. }
  1897. /**
  1898. * 换型清场记录修改
  1899. * @return void
  1900. * @throws \think\Exception
  1901. * @throws \think\db\exception\BindParamException
  1902. * @throws \think\exception\PDOException
  1903. */
  1904. public function remodelDataEdit()
  1905. {
  1906. if (Request::instance()->isPost() === false){
  1907. $this->error('请求错误');
  1908. }
  1909. $param = Request::instance()->post();
  1910. if (empty($param)){
  1911. $this->error('参数错误');
  1912. }
  1913. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1914. $sql = \db('制程_换型清场')->fetchSql(true)->update($param);
  1915. $res = \db()->query($sql);
  1916. if ($res !== false){
  1917. $this->success('成功');
  1918. }else{
  1919. $this->error('失败');
  1920. }
  1921. }
  1922. /**
  1923. * 换型清场记录删除
  1924. * @return void
  1925. * @throws \think\Exception
  1926. * @throws \think\exception\PDOException
  1927. */
  1928. public function remodelDataDel()
  1929. {
  1930. if ($this->request->isGet() === false){
  1931. $this->error('请求错误');
  1932. }
  1933. $param = $this->request->param();
  1934. if (empty($param)){
  1935. $this->error('参数错误');
  1936. }
  1937. $res = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->delete();
  1938. if ($res !== false){
  1939. $this->success('删除成功');
  1940. }else{
  1941. $this->error('删除失败');
  1942. }
  1943. }
  1944. /**
  1945. * 印版领用记录添加
  1946. * @return void
  1947. * @throws \think\db\exception\BindParamException
  1948. * @throws \think\exception\PDOException
  1949. */
  1950. public function PrintDetailAdd()
  1951. {
  1952. if (Request::instance()->isPost() === false){
  1953. $this->error('请求错误');
  1954. }
  1955. $param = Request::instance()->post();
  1956. if (empty($param)){
  1957. $this->error('参数错误');
  1958. }
  1959. $lastId = \db('工单_印版领用记录')->order('UniqID desc')->value('UniqID');
  1960. foreach ($param as $key=>$value){
  1961. $param[$key]['Yb_领用日期'] = date('Y-m-d H:i:s',time());
  1962. $param[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  1963. $param[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  1964. }
  1965. $sql = \db('工单_印版领用记录')->fetchSql(true)->insertAll($param);
  1966. $res = \db()->query($sql);
  1967. if ($res !== false){
  1968. $this->success('添加成功');
  1969. }else{
  1970. $this->error('添加失败');
  1971. }
  1972. }
  1973. /**
  1974. * 印版领用记录退还
  1975. * @return void
  1976. * @throws \think\Exception
  1977. * @throws \think\db\exception\BindParamException
  1978. * @throws \think\exception\PDOException
  1979. */
  1980. public function PrintDetailEdit()
  1981. {
  1982. if ($this->request->isGet() === false){
  1983. $this->error('请求错误');
  1984. }
  1985. $param = $this->request->param();
  1986. if (empty($param) || !isset($param['id']) || !isset($param['number'])){
  1987. $this->error('参数错误');
  1988. }
  1989. $idList = explode(',',$param['id']);
  1990. $i = 0;
  1991. foreach ($idList as $key=>$value){
  1992. $data['Yb_退还日期'] = date('Y-m-d H:i:s',time());
  1993. $data['Mod_rq'] = date('Y-m-d H:i:s',time());
  1994. $data['Yb_印数'] = $param['number'];
  1995. $sql = \db('工单_印版领用记录')->where('UniqID',$value)->fetchSql(true)->update($data);
  1996. $res = \db()->query($sql);
  1997. if ($res === false){
  1998. $i++;
  1999. }
  2000. }
  2001. if ($i !== 0){
  2002. $this->error('退还失败');
  2003. }else{
  2004. $this->success('退还成功');
  2005. }
  2006. }
  2007. /**
  2008. * 当班产量明细修改
  2009. * @return void
  2010. * @throws \think\Exception
  2011. * @throws \think\db\exception\BindParamException
  2012. * @throws \think\exception\PDOException
  2013. */
  2014. public function chanliangEdit()
  2015. {
  2016. if (Request::instance()->isPost() === false){
  2017. $this->error('请求错误');
  2018. }
  2019. $param = Request::instance()->post();
  2020. if (empty($param['UniqId'])){
  2021. $this->error('参数错误');
  2022. }
  2023. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  2024. $data = $param;
  2025. unset($data['UniqId']);
  2026. unset($data['sczl_rq']);
  2027. $sql = \db('设备_产量计酬')
  2028. ->where('UniqId',$param['UniqId'])
  2029. ->fetchSql(true)
  2030. ->update($data);
  2031. $res = \db()->query($sql);
  2032. if ($res !== false){
  2033. $this->success('修改成功');
  2034. }else {
  2035. $this->error('修改失败');
  2036. }
  2037. }
  2038. /**
  2039. * 获取当日上报产量详细数据
  2040. * @return void
  2041. * @throws \think\db\exception\DataNotFoundException
  2042. * @throws \think\db\exception\ModelNotFoundException
  2043. * @throws \think\exception\DbException
  2044. */
  2045. public function MachineChanliangDetail()
  2046. {
  2047. if ($this->request->isGet() === false){
  2048. $this->error('请求错误');
  2049. }
  2050. $param = $this->request->param();
  2051. if (empty($param['UniqId'])){
  2052. $this->error('参数错误');
  2053. }
  2054. $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 联数,
  2055. rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,rtrim(sczl_zcfp) as 制程废品,
  2056. rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,
  2057. rtrim(sczl_装版总工时) as 装版总工时,rtrim(sczl_打样总工时) as 打样总工时,
  2058. rtrim(sczl_装版工时) as 装版工时,rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,
  2059. rtrim(sczl_异常停机工时) as 异常总工时,rtrim(sczl_设备运行工时) as 通电工时,
  2060. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,
  2061. rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度数,
  2062. rtrim(sczl_异常工时1) as 异常补时,rtrim(sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  2063. rtrim(sczl_装版工时) as 装版补产工时,rtrim(sczl_打样工时) as 打样补产工时,
  2064. sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,
  2065. sczl_rate2,sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
  2066. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId';
  2067. $list = \db('设备_产量计酬')->where('UniqId',$param['UniqId'])->field($field)->find();
  2068. if (empty($list)){
  2069. $this->success('未找到产量详情信息');
  2070. }
  2071. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$list['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  2072. $list['印件名称'] = $productName['cpmc'];
  2073. if (!empty($productName['成品名称'])){
  2074. $list['cpmc'] = $productName['成品名称'];
  2075. }elseif (empty($productName['成品名称']) && !empty($productName['cpmc'])){
  2076. $list['cpmc'] = $productName['cpmc'];
  2077. }else{
  2078. $list['cpmc'] = '';
  2079. }
  2080. for ($i=1;$i<11;$i++){
  2081. if (isset($list['sczl_bh'.$i])){
  2082. $name = \db('人事_基本资料')->where('员工编号',$list['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
  2083. if (isset($name['name'])){
  2084. $list['组员'.$i] = [
  2085. '编号' => $list['sczl_bh'.$i],
  2086. '姓名' => $name['name'],
  2087. '比例' => (float)$list['sczl_rate'.$i]
  2088. ];
  2089. }
  2090. }
  2091. if (empty($list['sczl_bh'.$i])){
  2092. $list['组员'.$i] = [
  2093. '编号' => '',
  2094. '姓名' => '',
  2095. '比例' => ''
  2096. ];
  2097. }
  2098. unset($list['sczl_bh'.$i],$list['sczl_rate'.$i]);
  2099. }
  2100. $list['拉料'] = [
  2101. '编号' => $list['sczl_bh98'],
  2102. '姓名' => \db('人事_基本资料')->where('员工编号',$list['sczl_bh98'])->value('rtrim(员工姓名)')
  2103. ];
  2104. unset($list['sczl_bh98']);
  2105. $this->success('成功',$list);
  2106. }
  2107. /**
  2108. * 当日上报产量详细数据修改
  2109. * @return void
  2110. * @throws \think\Exception
  2111. * @throws \think\db\exception\BindParamException
  2112. * @throws \think\exception\PDOException
  2113. */
  2114. public function MachineChanliangDetailEdit()
  2115. {
  2116. if (Request::instance()->isPost() === false){
  2117. $this->error('请求错误');
  2118. }
  2119. $param = Request::instance()->post();
  2120. if (empty($param['UniqId'])){
  2121. $this->error('参数错误');
  2122. }
  2123. $param['sczl_type'] = $param['sczl_gxmc'];
  2124. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  2125. $UnidId = $param['UniqId'];
  2126. unset($param['UniqId']);
  2127. unset($param['sczl_rq']);
  2128. $sql = \db('设备_产量计酬')->where('UniqId',$UnidId)->fetchSql(true)->update($param);
  2129. $res = \db()->query($sql);
  2130. if ($res !== false){
  2131. $this->success('修改成功');
  2132. }else{
  2133. $this->error('修改失败');
  2134. }
  2135. }
  2136. /**
  2137. * 产量上报数据删除
  2138. * @return void
  2139. * @throws \think\Exception
  2140. * @throws \think\exception\PDOException
  2141. */
  2142. public function ChanliangDel()
  2143. {
  2144. if ($this->request->isGet() === false){
  2145. $this->error('请求错误');
  2146. }
  2147. $param = $this->request->param();
  2148. if (empty($param['UniqId'])){
  2149. $this->error('参数错误');
  2150. }
  2151. $idList = explode(',',$param['UniqId']);
  2152. foreach ($idList as $key=>$value){
  2153. $res = \db('设备_产量计酬')
  2154. ->where('UniqId',$value)
  2155. ->delete();
  2156. }
  2157. if ($res !== false){
  2158. $this->success('删除成功');
  2159. }else{
  2160. $this->error('删除失败');
  2161. }
  2162. }
  2163. /**
  2164. * 日产量上报添加
  2165. * @return void
  2166. * @throws \think\db\exception\BindParamException
  2167. * @throws \think\exception\PDOException
  2168. */
  2169. public function ChanliangAdd()
  2170. {
  2171. if (Request::instance()->isPost() === false){
  2172. $this->error('请求错误');
  2173. }
  2174. $params = Request::instance()->post();
  2175. if (empty($params['sczl_gdbh'])){
  2176. $this->error('参数错误');
  2177. }
  2178. $lastId = \db('设备_产量计酬')->order('UniqId desc')->value('rtrim(UniqId)');
  2179. $massage = \db('工单_工艺资料')
  2180. ->where('Gy0_gdbh',$params['sczl_gdbh'])
  2181. ->where('Gy0_yjno',$params['sczl_yjno'])
  2182. ->where('Gy0_gxh',$params['sczl_gxh'])
  2183. ->count();
  2184. if ($massage === 0){
  2185. $this->error('请选择正确的工序');
  2186. }
  2187. $params['sczl_type'] = $params['sczl_gxmc'];
  2188. $params['sczl_wgsj'] = '1900-01-01 00:00:00';
  2189. $params['sczl_废品率系数'] = 0;
  2190. $params['sys_rq'] = date('Y-m-d H:i:s',time());
  2191. $params['mod_rq'] = date('Y-m-d H:i:s',time());
  2192. $params['UniqId'] = $lastId + 1;
  2193. $sql = \db('设备_产量计酬')->fetchSql(true)->insert($params);
  2194. $res = \db()->query($sql);
  2195. if ($res !== false){
  2196. $this->success('成功');
  2197. }else{
  2198. $this->error('失败');
  2199. }
  2200. }
  2201. /**
  2202. * 日产量上报添加获取工单信息
  2203. * @return void
  2204. * @throws \think\db\exception\DataNotFoundException
  2205. * @throws \think\db\exception\ModelNotFoundException
  2206. * @throws \think\exception\DbException
  2207. */
  2208. public function ChanliangWorkorder()
  2209. {
  2210. if ($this->request->isGet() === false)
  2211. {
  2212. $this->error('请求错误');
  2213. }
  2214. $param = $this->request->param();
  2215. if (empty($param)){
  2216. $this->error('参数错误');
  2217. }
  2218. // $where = [
  2219. // 'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
  2220. // ];
  2221. // if (!empty($param['machine'])){
  2222. // $where = [
  2223. // 'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
  2224. // ];
  2225. // }
  2226. if (!empty($param['search'])){
  2227. $where['b.Gy0_gdbh'] = ['like','%'.$param['search'].'%'];
  2228. }
  2229. $list = \db('工单_基本资料')
  2230. ->alias('a')
  2231. ->field('rtrim(Gd_gdbh) as gdbh,rtrim(成品名称) as cpmc')
  2232. ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh')
  2233. ->where($where)
  2234. ->select();
  2235. if (empty($list)){
  2236. $this->success('未找到相关工单');
  2237. }else{
  2238. $this->success('成功',$list);
  2239. }
  2240. }
  2241. /**
  2242. * 日产量上报工单印件资料
  2243. * @return void
  2244. * @throws \think\db\exception\DataNotFoundException
  2245. * @throws \think\db\exception\ModelNotFoundException
  2246. * @throws \think\exception\DbException
  2247. */
  2248. public function ChanliangPrintDetail()
  2249. {
  2250. if ($this->request->isGet() === false){
  2251. $this->error('请求错误');
  2252. }
  2253. $param = $this->request->param();
  2254. if (empty($param['gdbh'])){
  2255. $this->error('参数错误');
  2256. }
  2257. $where = [
  2258. 'Yj_Gdbh' => $param['gdbh']
  2259. ];
  2260. $list = \db('工单_印件资料')
  2261. ->where($where)
  2262. ->field('rtrim(yj_Yjno) as yjno,rtrim(yj_yjmc) as yjmc,rtrim(yj_ls) as ls')
  2263. ->select();
  2264. if (empty($list)){
  2265. $this->success('未找到印件资料');
  2266. }else{
  2267. $this->success('成功',$list);
  2268. }
  2269. }
  2270. /**
  2271. * 日产量上报工艺资料获取
  2272. * @return void
  2273. * @throws \think\db\exception\DataNotFoundException
  2274. * @throws \think\db\exception\ModelNotFoundException
  2275. * @throws \think\exception\DbException
  2276. */
  2277. public function ChanliangProcessDetail()
  2278. {
  2279. if ($this->request->isGet() === false){
  2280. $this->error('请求错误');
  2281. }
  2282. $param = $this->request->param();
  2283. if (empty($param['gdbh'])){
  2284. $this->error('参数错误');
  2285. }
  2286. // $sys_bh = \db('dic_lzde')->where('适用机型',$param['machine'])->value('sys_bh');
  2287. $list = \db('工单_工艺资料')
  2288. ->where('Gy0_gdbh',$param['gdbh'])
  2289. ->where('Gy0_yjno',$param['yjno'])
  2290. // ->where('Gy0_sbbh','like','%'.$param['machine'].'%')
  2291. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  2292. ->select();
  2293. if (empty($list)){
  2294. $this->success('未获取工序');
  2295. }
  2296. // $time = \db('设备_产量计酬')
  2297. // ->where('sczl_gdbh',$param['gdbh'])
  2298. // ->where('sczl_yjno',$param['yjno'])
  2299. // ->where('sczl_jtbh','like','%'.$param['machine'].'%')
  2300. // ->order('UniqId desc')
  2301. // ->value('sczl_sj2');
  2302. // $newTime = date('Y-m-d H:i:s');
  2303. // if ($newTime > date('Y-m-d 08:30:00') && $newTime < date('Y-m-d 20:30:00') && $time < date('Y-m-d 08:30:00')){
  2304. // $time = date('Y-m-d 08:30:00');
  2305. // }elseif ($newTime > date('Y-m-d 20:30:00') && $time < date('Y-m-d 20:30:00')){
  2306. // $time = date('Y-m-d 20:30:00');
  2307. // }
  2308. foreach ($list as $key=>$value){
  2309. if ((int)$value['gxh'] < 10){
  2310. $value['gxh'] = '0'.$value['gxh'];
  2311. }
  2312. if (empty($value['add_gxmc'])){
  2313. $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'];
  2314. }else{
  2315. $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  2316. }
  2317. unset( $list[$key]['add_gxmc']);
  2318. // $list[$key]['time'] = $time;
  2319. }
  2320. // $list['sys_bh'] = $sys_bh;
  2321. $this->success('成功',$list);
  2322. }
  2323. /**
  2324. * 工价系数修改
  2325. * @return void
  2326. * @throws \think\Exception
  2327. * @throws \think\db\exception\BindParamException
  2328. * @throws \think\exception\PDOException
  2329. */
  2330. public function CoefficientEdit()
  2331. {
  2332. if (Request::instance()->isPost() === false){
  2333. $this->error('请求错误');
  2334. }
  2335. $params = Request::instance()->post();
  2336. if (empty($params['id'])){
  2337. $this->error('参数错误');
  2338. }
  2339. $idList = explode(',',$params['id']);
  2340. $i=0;
  2341. foreach ($idList as $key=>$value){
  2342. $sql = \db('设备_产量计酬')
  2343. ->where('UniqId',$value)
  2344. ->fetchSql(true)
  2345. ->update(['sczl_工价系数'=>$params['工价系数']]);
  2346. $res = \db()->query($sql);
  2347. if ($res === false){
  2348. $i++;
  2349. }
  2350. }
  2351. if ($i!==0){
  2352. $this->error('修改失败');
  2353. }else{
  2354. $this->success('修改成功');
  2355. }
  2356. }
  2357. /**
  2358. * 色度系数修改
  2359. * @return void
  2360. * @throws \think\Exception
  2361. * @throws \think\db\exception\BindParamException
  2362. * @throws \think\exception\PDOException
  2363. */
  2364. public function ChromaDataEdit()
  2365. {
  2366. if (Request::instance()->isPost() === false){
  2367. $this->error('请求错误');
  2368. }
  2369. $params = Request::instance()->post();
  2370. if (empty($params['id'])){
  2371. $this->error('参数错误');
  2372. }
  2373. $idList = explode(',',$params['id']);
  2374. $i=0;
  2375. foreach ($idList as $key=>$value){
  2376. $sql = \db('设备_产量计酬')
  2377. ->where('UniqId',$value)
  2378. ->fetchSql(true)
  2379. ->update(['sczl_ms'=>$params['ms']]);
  2380. $res = \db()->query($sql);
  2381. if ($res === false){
  2382. $i++;
  2383. }
  2384. }
  2385. if ($i!==0){
  2386. $this->error('修改失败');
  2387. }else{
  2388. $this->success('修改成功');
  2389. }
  2390. }
  2391. /**
  2392. * 凹印版距修改
  2393. * @return void
  2394. * @throws \think\Exception
  2395. * @throws \think\db\exception\BindParamException
  2396. * @throws \think\exception\PDOException
  2397. */
  2398. public function PrintingModeDataEdit()
  2399. {
  2400. if (Request::instance()->isPost() === false){
  2401. $this->error('请求错误');
  2402. }
  2403. $params = Request::instance()->post();
  2404. if (empty($params['id'])){
  2405. $this->error('参数错误');
  2406. }
  2407. $idList = explode(',',$params['id']);
  2408. //获取工单印件工序
  2409. $orderList = \db('设备_产量计酬')
  2410. ->where('UniqId',$idList[0])
  2411. ->field('rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as 印件号,rtrim(sczl_gxh) as 工序号')
  2412. ->find();
  2413. //修改工艺资料
  2414. $sql = \db('工单_工艺资料')
  2415. ->where([
  2416. 'Gy0_gdbh'=>$orderList['工单编号'],
  2417. 'Gy0_yjno'=>$orderList['印件号'],
  2418. 'Gy0_gxh'=>$orderList['工序号']
  2419. ])
  2420. ->fetchSql(true)
  2421. ->update(['版距'=>$params['plate'],'印刷方式'=>$params['mode']]);
  2422. $res = \db()->query($sql);
  2423. if ($res === false){
  2424. $this->error('修改失败');
  2425. }else{
  2426. $this->success('修改成功');
  2427. }
  2428. }
  2429. /**
  2430. * 废品率系数批量修改
  2431. * @return void
  2432. * @throws \think\Exception
  2433. * @throws \think\db\exception\BindParamException
  2434. * @throws \think\exception\PDOException
  2435. */
  2436. public function RejectionEdit()
  2437. {
  2438. if (Request::instance()->isPost() === false){
  2439. $this->error('请求错误');
  2440. }
  2441. $params = Request::instance()->post();
  2442. if (empty($params['id'])){
  2443. $this->error('参数错误');
  2444. }
  2445. $idList = explode(',',$params['id']);
  2446. $i=0;
  2447. foreach ($idList as $key=>$value){
  2448. $sql = \db('设备_产量计酬')
  2449. ->where('UniqId',$value)
  2450. ->fetchSql(true)
  2451. ->update(['sczl_废品率系数'=>$params['rejection']]);
  2452. $res = \db()->query($sql);
  2453. if ($res === false){
  2454. $i++;
  2455. }
  2456. }
  2457. if ($i!==0){
  2458. $this->error('修改失败');
  2459. }else{
  2460. $this->success('修改成功');
  2461. }
  2462. }
  2463. /**
  2464. * 日产量上报班组信息批量修改
  2465. * @return void
  2466. * @throws \think\Exception
  2467. * @throws \think\db\exception\BindParamException
  2468. * @throws \think\db\exception\DataNotFoundException
  2469. * @throws \think\db\exception\ModelNotFoundException
  2470. * @throws \think\exception\DbException
  2471. * @throws \think\exception\PDOException
  2472. */
  2473. public function YieldTeamEdit()
  2474. {
  2475. if ($this->request->isGet() === false){
  2476. $this->error('请求错误');
  2477. }
  2478. $param = $this->request->param();
  2479. if (empty($param['Uniqid']) || empty($param['teamID'])){
  2480. $this->error('参数错误');
  2481. }
  2482. $idList = explode(',',$param['Uniqid']);
  2483. $teamList = \db('设备_班组资料')->where('UniqId',$param['teamID'])->find();
  2484. $data = [];
  2485. for ($i=1;$i<11;$i++){
  2486. $data['sczl_bh'.$i] = $teamList['sczl_bh'.$i];
  2487. $data['sczl_rate'.$i] = $teamList['sczl_rate'.$i];
  2488. $data['sczl_bzdh'] = $teamList['sczl_bzdh'];
  2489. }
  2490. $j = 0;
  2491. foreach ($idList as $key => $value){
  2492. $sql = \db('设备_产量计酬')
  2493. ->where('UniqId',$value)
  2494. ->fetchSql(true)
  2495. ->update($data);
  2496. $res = \db()->query($sql);
  2497. if ($res === false){
  2498. $j++;
  2499. }
  2500. }
  2501. if ($j === 0){
  2502. $this->success('修改成功');
  2503. }else{
  2504. $this->error('修改失败');
  2505. }
  2506. }
  2507. /**
  2508. * 检品机日产量上报数据修改
  2509. * @return void
  2510. * @throws \think\Exception
  2511. * @throws \think\db\exception\BindParamException
  2512. * @throws \think\exception\PDOException
  2513. */
  2514. public function JpChanliangEdit()
  2515. {
  2516. if (Request::instance()->isPost() == false){
  2517. $this->error('非法请求');
  2518. }
  2519. $params = Request::instance()->post();
  2520. if (empty($params['UniqId'])){
  2521. $this->error('参数错误');
  2522. }
  2523. $params['mod_rq'] = date('Y-m-d H:i:s');
  2524. $data = $params;
  2525. unset($data['UniqId']);
  2526. $sql = \db('设备_产量计酬')->where('UniqId',$params['UniqId'])->fetchSql(true)->update($data);
  2527. $res = \db()->query($sql);
  2528. if ($res === false){
  2529. $this->error('修改失败');
  2530. }else{
  2531. $this->success('成功');
  2532. }
  2533. }
  2534. /**
  2535. * 检品机日产量上报数据列表
  2536. * @return void
  2537. * @throws \think\db\exception\DataNotFoundException
  2538. * @throws \think\db\exception\ModelNotFoundException
  2539. * @throws \think\exception\DbException
  2540. */
  2541. public function JPmachineDetail()
  2542. {
  2543. if ($this->request->isGet() === false){
  2544. $this->error('请求错误');
  2545. }
  2546. $machine = input('machine');
  2547. $date = input('date');
  2548. $where = [
  2549. 'sczl_jtbh' => $machine,
  2550. 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
  2551. ];
  2552. $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_type) as 检验类型,rtrim(sczl_num) as num,rtrim(sczl_cl) as 计件箱数,
  2553. rtrim(sczl_Pgcl) as 每箱数量,rtrim(sczl_bzdh) as bzdh,IF(sczl_废品率系数 = 0, "",sczl_废品率系数) as 废品率系数,IF(sczl_装版工时 = 0, "",sczl_装版工时) as 换膜补时, IF(sczl_保养工时 = 0, "",sczl_保养工时) as 保养工时,IF(sczl_异常停机工时 = 0, "",sczl_异常停机工时) as 异常总工时,IF(sczl_设备运行工时 = 0, "",sczl_设备运行工时) as 通电工时,
  2554. rtrim(sys_id) as 用户,rtrim(mod_rq) as 更新时间,IF(sczl_异常工时1 = 0, "",sczl_异常工时1) as 异常补时,IF(sczl_异常类型1 = 0, "",sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  2555. 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,
  2556. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId,rtrim(sczl_工价系数) as 难度系数,rtrim(sczl_dedh) as 定额代号,sczl_rq,sczl_装版总工时 as 换膜总工时';
  2557. //机台信息
  2558. $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
  2559. //组员信息
  2560. $list = \db('设备_产量计酬')->where($where)->field($field)->select();
  2561. $totalA = \db('设备_产量计酬')
  2562. ->where($where)
  2563. ->where('sczl_bzdh','like','A%')
  2564. ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数,SUM(sczl_装版工时) as 总换膜补时,SUM(sczl_保养工时) as 总保养工时,SUM(sczl_异常停机工时) as 总异常总工时,SUM(sczl_设备运行工时) as 总通电工时')
  2565. ->group('检验类型')
  2566. ->select();
  2567. $totalB = \db('设备_产量计酬')
  2568. ->where($where)
  2569. ->where('sczl_bzdh','like','B%')
  2570. ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数,SUM(sczl_装版工时) as 总换膜补时,SUM(sczl_保养工时) as 总保养工时,SUM(sczl_异常停机工时) as 总异常总工时,SUM(sczl_设备运行工时) as 总通电工时')
  2571. ->group('检验类型')
  2572. ->select();
  2573. if (empty($list)){
  2574. $this->success('',[]);
  2575. }
  2576. foreach ($list as $key=>$value){
  2577. //产品名称
  2578. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$value['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  2579. if (!empty($productName)){
  2580. if (!empty($productName['成品名称'])){
  2581. $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['成品名称'];
  2582. $list[$key]['cpmc'] = $productName['成品名称'];
  2583. }else{
  2584. $list[$key]['产品名称'] = $value['工单编号'];
  2585. $list[$key]['cpmc'] = '';
  2586. }
  2587. }else{
  2588. $list[$key]['产品名称'] = $value['工单编号'];
  2589. $list[$key]['cpmc'] = '';
  2590. }
  2591. if (empty($value['定额代号'])){
  2592. $list[$key]['千件工价'] = '';
  2593. $list[$key]['日定额'] = '';
  2594. $list[$key]['补产标准'] = '';
  2595. }else{
  2596. $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
  2597. $list[$key]['千件工价'] = $row['千件工价'];
  2598. $list[$key]['日定额'] = $row['日定额'];
  2599. $list[$key]['补产标准'] = $row['补产标准'];
  2600. }
  2601. $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxh'].'-'.$list[$key]['gxmc'];
  2602. for ($i=1;$i<11;$i++){
  2603. if (isset($value['sczl_bh'.$i])){
  2604. $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('员工姓名 as name')->find();
  2605. if (isset($name['name'])){
  2606. $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
  2607. $list[$key]['sczl_name'.$i] = $name['name'];
  2608. }else{
  2609. $list[$key]['sczl_name'.$i] = '';
  2610. }
  2611. }
  2612. }
  2613. }
  2614. $list['totalA'] = $totalA;
  2615. $list['totalB'] = $totalB;
  2616. $this->success('成功',$list);
  2617. }
  2618. /**
  2619. * 检品机每日上报数据修改页面数据获取接口
  2620. * @return void
  2621. * @throws \think\db\exception\DataNotFoundException
  2622. * @throws \think\db\exception\ModelNotFoundException
  2623. * @throws \think\exception\DbException
  2624. */
  2625. public function JPchanliangDetailList()
  2626. {
  2627. if ($this->request->isGet() === false){
  2628. $this->error('请求错误');
  2629. }
  2630. $param = $this->request->param();
  2631. if (empty($param)){
  2632. $this->error('参数错误');
  2633. }
  2634. $list = \db('设备_产量计酬')
  2635. ->alias('a')
  2636. ->join('工单_基本资料 b','a.sczl_gdbh = b.Gd_gdbh AND a.sczl_yjno = b.行号')
  2637. ->field('rtrim(a.sczl_gdbh) as 工单编号,rtrim(a.sczl_dedh) as dedh,rtrim(a.sczl_yjno) as yjno,
  2638. rtrim(a.sczl_gxh) as gxh,rtrim(a.sczl_gxmc) as gxmc,rtrim(a.sczl_type) as 检验类型,rtrim(a.sczl_num) as num,
  2639. rtrim(a.sczl_cl) as 计件箱数,rtrim(a.sczl_Pgcl) as 每箱数量,rtrim(a.sczl_bzdh) as bzdh,
  2640. IF(a.sczl_废品率系数 = 0, "",a.sczl_废品率系数) as 废品率系数,IF(a.sczl_装版工时 = 0, "",a.sczl_装版工时) as 换膜补时,
  2641. IF(a.sczl_保养工时 = 0, "",a.sczl_保养工时) as 保养工时,IF(a.sczl_异常停机工时 = 0, "",a.sczl_异常停机工时) as 异常总工时,
  2642. IF(a.sczl_设备运行工时 = 0, "",a.sczl_设备运行工时) as 通电工时,rtrim(a.sys_id) as 用户,rtrim(a.mod_rq) as 更新时间,
  2643. IF(a.sczl_异常工时1 = 0, "",a.sczl_异常工时1) as 异常补时,IF(a.sczl_异常类型1 = 0, "",a.sczl_异常类型1) as 异常类型,
  2644. a.sczl_bh1,a.sczl_bh2,a.sczl_bh3,a.sczl_bh4,a.sczl_bh5,a.sczl_bh6,a.sczl_bh7,a.sczl_bh8,a.sczl_bh9,a.sczl_bh10,
  2645. a.sczl_rate1,a.sczl_rate2,a.sczl_rate3,a.sczl_rate4,a.sczl_rate5,a.sczl_rate6,a.sczl_rate7,a.sczl_rate8,
  2646. a.sczl_rate9,a.sczl_rate10,a.sczl_bh98,rtrim(a.UniqId) as UniqId,rtrim(a.sczl_工价系数) as 难度系数,
  2647. rtrim(a.sczl_dedh) as 定额代号,a.sczl_rq,a.sczl_装版总工时 as 换膜总工时,rtrim(b.Gd_cpmc) as 产品名称,rtrim(b.成品名称) as 成品名称')
  2648. ->where('a.UniqId',$param['UniqId'])
  2649. ->find();
  2650. for ($i=1;$i<11;$i++){
  2651. if (isset($list['sczl_bh'.$i])){
  2652. $name = \db('人事_基本资料')->where('员工编号',$list['sczl_bh'.$i])->field('员工姓名 as name')->find();
  2653. if (isset($name['name'])){
  2654. $list['组员'.$i] = $list['sczl_bh'.$i].$name['name'].'('.((float)$list['sczl_rate'.$i]*100).'%'.')';
  2655. $list['sczl_name'.$i] = $name['name'];
  2656. }else{
  2657. $list['sczl_name'.$i] = '';
  2658. }
  2659. }
  2660. }
  2661. if (!empty($list)){
  2662. $this->success('成功',$list);
  2663. }else{
  2664. $this->error('未找到数据');
  2665. }
  2666. }
  2667. /**
  2668. * 拉纸工数据导出
  2669. * @return void
  2670. * @throws \think\db\exception\DataNotFoundException
  2671. * @throws \think\db\exception\ModelNotFoundException
  2672. * @throws \think\exception\DbException
  2673. */
  2674. public function LazhiGongData()
  2675. {
  2676. if ($this->request->isGet() === false){
  2677. $this->error('请求错误');
  2678. }
  2679. $param = $this->request->param();
  2680. if (empty($param['mouth'])){
  2681. $this->error('请选择月份');
  2682. }
  2683. $filed = [
  2684. 'a.sczl_gdbh' => '工单编号',
  2685. 'b.yj_yjmc' => '产品名称',
  2686. 'a.sczl_num' => '流程单号',
  2687. 'a.sczl_yjno' => '印件号',
  2688. 'a.sczl_gxh' => '工序号',
  2689. 'a.sczl_jtbh' => '机台编号',
  2690. 'a.sczl_rq' => '日期',
  2691. 'a.sczl_type' => '工序名称',
  2692. 'a.sczl_cl' => '产量',
  2693. 'a.sczl_bh1' => '机长工号',
  2694. 'c1.员工姓名' => '机长姓名',
  2695. 'a.sczl_bh2' => '组员工号1',
  2696. 'c2.员工姓名' => '组员姓名1',
  2697. 'a.sczl_bh3' => '组员工号2',
  2698. 'c3.员工姓名' => '组员姓名2',
  2699. 'a.sczl_bh98' => '拉料工工号',
  2700. 'c4.员工姓名' => '拉料工姓名'
  2701. ];
  2702. $list = \db('设备_产量计酬')
  2703. ->alias('a')
  2704. ->join('工单_印件资料 b','a.sczl_gdbh = b.Yj_Gdbh AND a.sczl_yjno = b.yj_Yjno')
  2705. ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
  2706. ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
  2707. ->join('人事_基本资料 c3','a.sczl_bh3 = c3.员工编号','left')
  2708. ->join('人事_基本资料 c4','a.sczl_bh98 = c4.员工编号','left')
  2709. ->field($filed)
  2710. ->where('a.sczl_rq','like',$param['mouth'].'%')
  2711. ->where('a.sczl_bh98','<>','')
  2712. ->order('a.sczl_rq,a.sczl_jtbh')
  2713. ->select();
  2714. if (!empty($list)){
  2715. $this->success('成功',$list);
  2716. }else{
  2717. $this->error('未找到相关数据');
  2718. }
  2719. }
  2720. }