Facility.php 126 KB

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