Facility.php 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116
  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()) {
  954. $this->error('请求错误');
  955. }
  956. $param = Request::instance()->post();
  957. if (empty($param)) {
  958. $this->error('参数错误');
  959. }
  960. $row = [];
  961. foreach ($param as $value) {
  962. $unitCode = \db('设备_点检项目')
  963. ->where('部件名称', $value['unitName'])
  964. ->field('rtrim(部件编号) as 部件编号')
  965. ->find();
  966. $row[] = [
  967. '日期' => date('Y-m-d 00:00:00'),
  968. '班组编号' => $value['team'],
  969. '点检设备' => $value['machine'],
  970. '部件编号' => $unitCode['部件编号'] ?? '',
  971. '部件名称' => $value['unitName'],
  972. '检验项目' => $value['itemName'],
  973. '判定标准' => $value['standard'],
  974. '点检方法' => $value['method'],
  975. '点检结果' => $value['status'],
  976. '备注说明' => $value['remark'],
  977. 'Sys_rq' => date('Y-m-d H:i:s')
  978. ];
  979. }
  980. $res = \db('设备_点检记录')->insertAll($row);
  981. if ($res !== false) {
  982. $this->success('添加成功,添加了' . count($row) . '条记录');
  983. } else {
  984. $this->error('添加失败');
  985. }
  986. }
  987. /**
  988. * 机台印版领用->左侧菜单
  989. * @ApiMethod (GET)
  990. * @param void
  991. * @return void
  992. */
  993. public function PrintGetTab()
  994. {
  995. if ($this->request->isGet() === false){
  996. $this->error('请求错误');
  997. }
  998. $param = $this->request->param();
  999. if (empty($param)){
  1000. $this->error('参数错误');
  1001. }
  1002. $productCode = $param['productCode'];
  1003. $sql = "SELECT DISTINCT(RTRIM(b.`名称`)) as `印版分类`,RTRIM(b.`编号`) as `编号` FROM `产品_印版资料` as a
  1004. JOIN `物料_存货结构` as b ON b.`编号` = SUBSTRING(a.`存货编码`,1,4)
  1005. WHERE a.YB_Cpdh = '{$productCode}'";
  1006. $res = Db::query($sql);
  1007. if (empty($res)){
  1008. $this->success('');
  1009. }
  1010. $this->success('成功',$res);
  1011. }
  1012. /**
  1013. * 机台印版领用记录->数据详情
  1014. * @ApiMethod (GET)
  1015. * @param void
  1016. * @return void
  1017. */
  1018. public function PrintDetail()
  1019. {
  1020. if (!$this->request->isGet()) {
  1021. $this->error('请求失败');
  1022. }
  1023. $param = $this->request->param();
  1024. if (empty($param)) {
  1025. $this->error('参数错误');
  1026. }
  1027. // 分页参数(带默认值)
  1028. $page = isset($param['page']) ? max(1, intval($param['page'])) : 1;
  1029. $limit = isset($param['limit']) ? min(max(1, intval($param['limit'])), 100) : 10;
  1030. $productCode = $param['productCode'];
  1031. $code = $param['code'] . '%';
  1032. $workOrder = $param['workOrder'];
  1033. // 1. 先查询总数
  1034. $countSql = "SELECT COUNT(*) AS total FROM (
  1035. SELECT
  1036. b.`供方批号`
  1037. FROM `产品_印版资料` a
  1038. JOIN `物料_存货编码` c ON c.`物料代码` = a.`存货编码`
  1039. JOIN `物料_存货结构` e ON e.`编号` = (
  1040. CASE
  1041. WHEN a.`存货编码` REGEXP '[A-Za-z]'
  1042. THEN SUBSTRING(a.`存货编码`, 1, 5)
  1043. ELSE SUBSTRING(a.`存货编码`, 1, 4)
  1044. END
  1045. )
  1046. JOIN `工单_基本资料` f ON a.YB_Cpdh = f.Gd_cpdh
  1047. LEFT JOIN `产品_印版库` b ON b.`存货编码` = a.`存货编码`
  1048. AND b.`报废日期` = '1900-01-01 00:00:00'
  1049. LEFT JOIN `工单_印版领用记录` d ON d.`Yb_供方批号` = b.`供方批号`
  1050. AND d.`Yb_工单编号` IS NOT NULL
  1051. WHERE
  1052. a.YB_Cpdh = '{$productCode}'
  1053. AND a.`存货编码` LIKE '{$code}'
  1054. AND f.Gd_gdbh = '{$workOrder}'
  1055. GROUP BY
  1056. a.`存货编码`,
  1057. b.`供方批号`
  1058. ) AS t";
  1059. $total = Db::query($countSql)[0]['total'] ?? 0;
  1060. // 2. 查询分页数据
  1061. $dataSql = "SELECT
  1062. RTRIM(a.`存货编码`) AS `存货编码`,
  1063. RTRIM(c.`物料名称`) AS `存货名称`,
  1064. RTRIM(b.`印版名称`) AS `印版名称`,
  1065. RTRIM(b.`供方批号`) AS `供方批号`,
  1066. RTRIM(b.`制造日期`) AS `制造日期`,
  1067. SUM(d.`Yb_印数`) AS `印数`,
  1068. RTRIM(e.`名称`) AS `印版类别`,
  1069. SUBSTRING(a.YB_Cpdh, 1, 4) AS `客户编号`,
  1070. RTRIM(f.`Gd_客户名称`) AS `客户名称`,
  1071. RTRIM(a.YB_Cpdh) AS `产品编号`,
  1072. RTRIM(f.Gd_cpmc) AS `产品名称`,
  1073. MAX(d.UniqID) AS UniqId,
  1074. MAX(CASE
  1075. WHEN d.`Yb_领用日期` IS NOT NULL AND d.`Yb_退还日期` IS NULL
  1076. THEN d.`Yb_工单编号`
  1077. ELSE NULL
  1078. END) AS `工单编号`
  1079. FROM `产品_印版资料` a
  1080. JOIN `物料_存货编码` c ON c.`物料代码` = a.`存货编码`
  1081. JOIN `物料_存货结构` e ON e.`编号` = (
  1082. CASE
  1083. WHEN a.`存货编码` REGEXP '[A-Za-z]'
  1084. THEN SUBSTRING(a.`存货编码`, 1, 5)
  1085. ELSE SUBSTRING(a.`存货编码`, 1, 4)
  1086. END
  1087. )
  1088. JOIN `工单_基本资料` f ON a.YB_Cpdh = f.Gd_cpdh
  1089. LEFT JOIN `产品_印版库` b ON b.`存货编码` = a.`存货编码`
  1090. AND b.`报废日期` = '1900-01-01 00:00:00'
  1091. LEFT JOIN `工单_印版领用记录` d ON d.`Yb_供方批号` = b.`供方批号`
  1092. AND d.`Yb_工单编号` IS NOT NULL
  1093. WHERE
  1094. a.YB_Cpdh = '{$productCode}'
  1095. AND a.`存货编码` LIKE '{$code}'
  1096. AND f.Gd_gdbh = '{$workOrder}'
  1097. GROUP BY
  1098. a.`存货编码`,
  1099. c.`物料名称`,
  1100. b.`印版名称`,
  1101. b.`供方批号`,
  1102. b.`制造日期`,
  1103. e.`名称`,
  1104. f.`Gd_客户名称`,
  1105. a.YB_Cpdh,
  1106. f.Gd_cpmc
  1107. ORDER BY a.`存货编码`
  1108. LIMIT " . ($page - 1) * $limit . ", " . $limit;
  1109. $list = Db::query($dataSql);
  1110. $this->success('成功', [
  1111. 'data' => $list ?: [],
  1112. 'total' => $total,
  1113. ]);
  1114. }
  1115. /**
  1116. * 换型清场->左侧菜单栏
  1117. * @ApiMethod (GET)
  1118. * @param void
  1119. * @return void
  1120. */
  1121. public function remodelGetTab()
  1122. {
  1123. if ($this->request->isGet() === false){
  1124. $this->error('请求错误');
  1125. }
  1126. $date = date('Y-m-d 00:00:00',time()-3456000);
  1127. $nowTime = date('Y-m-d H:i:s',time());
  1128. $list = \db('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
  1129. if (empty($list)){
  1130. $this->error('失败');
  1131. }
  1132. $sql = "SELECT RTRIM(a.`设备编号`) as `设备编号`,RTRIM(b.`日期`) as `日期`,RTRIM(b.UniqId) as UniqId
  1133. FROM `设备_基本资料` as a
  1134. LEFT JOIN `制程_换型清场` as b ON b.`机台编号` = a.`设备编号`
  1135. WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' AND b.`工单编号A` <> '' AND b.`工单编号B` <> '' ORDER BY b.`UniqId`";
  1136. $res = Db::query($sql);
  1137. $data = $result = [];
  1138. foreach ($list as $key=>$value){
  1139. $data[$value] = $result[$value]= $time = [];
  1140. foreach ($res as $k=>$v){
  1141. if ($value === $v['设备编号']){
  1142. $row = [
  1143. '日期' => $v['日期'],
  1144. 'id' => $v['UniqId']
  1145. ];
  1146. array_push($data[$value],$row);
  1147. }
  1148. }
  1149. foreach ($data[$value] as $m=>$n){
  1150. $time[$m] = $n['日期'];
  1151. }
  1152. $time = array_values(array_unique($time));
  1153. foreach ($time as $kk=>$vv){
  1154. $i=1;
  1155. foreach ($data[$value] as $kkk=>$vvv){
  1156. if ($kkk>=$kk && $vv === $vvv['日期']){
  1157. array_push($result[$value],date('Y-m-d',strtotime($vv)).'第'.$i.'次换型/'.$vvv['id']);
  1158. $i++;
  1159. }
  1160. }
  1161. }
  1162. }
  1163. $this->success('成功',$result);
  1164. }
  1165. /**
  1166. * 换型清场->详情
  1167. * @return void
  1168. * @throws \think\db\exception\DataNotFoundException
  1169. * @throws \think\db\exception\ModelNotFoundException
  1170. * @throws \think\exception\DbException
  1171. */
  1172. public function RemodelDetail()
  1173. {
  1174. if ($this->request->isGet() === false){
  1175. $this->error('请求错误');
  1176. }
  1177. $param = $this->request->param();
  1178. if (empty($param)){
  1179. $this->error('参数错误');
  1180. }
  1181. $field = 'rtrim(日期) as 日期,rtrim(班组) as 班组,rtrim(机台编号) as 机台编号,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1182. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包B,
  1183. rtrim(清场项目A) as 项目1,rtrim(清场项目B) as 项目2,rtrim(清场项目C) as 项目3,rtrim(清场项目D) as 项目4,rtrim(清场项目E) as 项目5,
  1184. rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
  1185. $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
  1186. if (empty($list)){
  1187. $this->success('未找到该条清场记录');
  1188. }
  1189. $list['日期'] = date('Y-m-d',strtotime($list['日期']));
  1190. $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find();
  1191. if (empty($printNameA)){
  1192. $list['印件名称A'] = '';
  1193. }else{
  1194. $list['印件名称A'] = $printNameA['yjmc'];
  1195. }
  1196. $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find();
  1197. if (empty($printNameB)){
  1198. $list['印件名称B'] = '';
  1199. }else{
  1200. $list['印件名称B'] = $printNameB['yjmc'];
  1201. }
  1202. $this->success('成功',$list);
  1203. }
  1204. /**
  1205. * 换型清场->当前设备清场记录
  1206. * @ApiMethod (GET)
  1207. * @param void
  1208. * @return void
  1209. * @throws \think\db\exception\DataNotFoundException
  1210. * @throws \think\db\exception\ModelNotFoundException
  1211. * @throws \think\exception\DbException
  1212. */
  1213. public function ModelChangeRecord()
  1214. {
  1215. if ($this->request->isGet() === false){
  1216. $this->error('请求错误');
  1217. }
  1218. $param = $this->request->param();
  1219. if (empty($param)){
  1220. $this->error('参数错误');
  1221. }
  1222. $date = date('Y-m-d 00:00:00',time()-3888000);
  1223. $nowTime = date('Y-m-d H:i:s',time());
  1224. $where = [
  1225. '日期' =>['between',[$date,$nowTime]],
  1226. '机台编号' => $param['machine'],
  1227. '工单编号A' => ['<>',''],
  1228. '工单编号B' => ['<>',''],
  1229. ];
  1230. $field = "rtrim(日期) as 日期,rtrim(机台编号) as 机台编号,rtrim(班组) as 班组,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1231. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包号B,rtrim(清场项目A) as 清场项目A,
  1232. rtrim(清场项目B) as 清场项目B,rtrim(清场项目C) as 清场项目C,rtrim(清场项目D) as 清场项目D,rtrim(清场项目E) as 清场项目E,rtrim(机长) as 机长,
  1233. rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员,rtrim(sys_rq) as 创建时间,rtrim(UniqId) as UNIQID";
  1234. $list = \db('制程_换型清场')
  1235. ->where($where)
  1236. ->field($field)
  1237. ->select();
  1238. if (empty($list)){
  1239. $this->success('未找到换型记录');
  1240. }
  1241. foreach ($list as $key=>$value){
  1242. $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号A'])->value('rtrim(yj_yjmc) as yjmc');
  1243. if (empty($printNameA)){
  1244. $list[$key]['印件名称A'] = '';
  1245. }else{
  1246. $list[$key]['印件名称A'] = $printNameA;
  1247. }
  1248. $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号B'])->value('rtrim(yj_yjmc) as yjmc');
  1249. if (empty($printNameB)){
  1250. $list[$key]['印件名称B'] = '';
  1251. }else{
  1252. $list[$key]['印件名称B'] = $printNameB;
  1253. }
  1254. }
  1255. $this->success('成功',$list);
  1256. }
  1257. /**
  1258. * 车间机台状态列表展示
  1259. * @ApiMethod (GET)
  1260. * @param void
  1261. * @return void
  1262. * @throws \think\db\exception\BindParamException
  1263. * @throws \think\exception\PDOException
  1264. */
  1265. public function MachineDetailList()
  1266. {
  1267. if ($this->request->isGet() === false){
  1268. $this->error('请求错误');
  1269. }
  1270. $param = $this->request->param();
  1271. if (empty($param)){
  1272. $this->error('参数错误');
  1273. }
  1274. $workshop = $param['workshop'];
  1275. $sql = "SELECT
  1276. RTRIM( a.`设备编号` ) AS 设备编号,
  1277. RTRIM( a.`设备名称` ) AS 设备名称,
  1278. RTRIM( d.`当前状态` ) AS 状态
  1279. FROM
  1280. `设备_基本资料` AS a
  1281. JOIN (
  1282. SELECT
  1283. b.`设备编号`,
  1284. b.`当前状态`,
  1285. b.`开工时间`
  1286. FROM
  1287. `设备_产量采集` AS b
  1288. JOIN ( SELECT `设备编号`, MAX( `UniqId` ) AS `UniqId` FROM `设备_产量采集` GROUP BY `设备编号` ) AS c ON b.`设备编号` = c.`设备编号`
  1289. AND b.`UniqId` = c.`UniqId`
  1290. ) AS d ON a.`设备编号` = d.`设备编号`
  1291. WHERE
  1292. a.`使用部门` = '{$workshop}'
  1293. GROUP BY
  1294. a.`设备编号`
  1295. ORDER BY
  1296. a.UniqId";
  1297. $list = \db()->query($sql);
  1298. foreach ($list as $key=>$value){
  1299. if ($value['状态'] == ''){
  1300. $list[$key]['状态'] = '待单';
  1301. }
  1302. }
  1303. $this->success('成功',$list);
  1304. }
  1305. /**
  1306. * 机台当前参数展示
  1307. * @ApiMethod (GET)
  1308. * @return void
  1309. * @throws \think\db\exception\DataNotFoundException
  1310. * @throws \think\db\exception\ModelNotFoundException
  1311. * @throws \think\exception\DbException
  1312. */
  1313. public function MachineDetail()
  1314. {
  1315. if ($this->request->isGet() === false){
  1316. $this->error('请求错误');
  1317. }
  1318. $param = $this->request->param();
  1319. if (empty($param)){
  1320. $this->error('参数错误');
  1321. }
  1322. $data = [];
  1323. if ($param['start'] === ''){
  1324. 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())){
  1325. $param['start'] = date('Y-m-d 08:30:00',time());
  1326. }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())){
  1327. $param['start'] = date('Y-m-d 20:30:00',time());
  1328. }else{
  1329. $param['start'] = date('Y-m-d 20:30:00',time()-86400);
  1330. }
  1331. }
  1332. $machineDetail = \db('设备_产量采集')
  1333. ->alias('a')
  1334. ->join('设备_基本资料 b','a.设备编号 = b.设备编号')
  1335. ->join('工单_工艺资料 c', "a.工单编号 = c.Gy0_gdbh AND c.Gy0_sbbh LIKE CONCAT('%', a.设备编号, '%')")
  1336. ->join('工单_基本资料 d','a.工单编号 = d.Gd_gdbh')
  1337. ->field([
  1338. 'rtrim(a.开工时间)' => '开工时间',
  1339. 'rtrim(a.设备编号)' => '设备编号',
  1340. 'rtrim(a.工单编号)' => '工单编号',
  1341. 'rtrim(b.设备名称)' => '设备名称',
  1342. 'rtrim(c.Gy0_gxh)' => '工序号',
  1343. 'rtrim(c.Gy0_gxmc)' => '工序名称',
  1344. 'rtrim(d.Gd_cpmc)' => '产品名称'
  1345. ])
  1346. ->where('a.设备编号', $param['machine'])
  1347. ->order('a.UniqId desc')
  1348. ->find();
  1349. $data['machine'] = [
  1350. '日期' => $machineDetail['开工时间'],
  1351. '设备' => $machineDetail['设备编号'].'-->'.$machineDetail['设备名称'],
  1352. '工单' => $machineDetail['工单编号'].'-->'.$machineDetail['产品名称'],
  1353. '工艺' => ($machineDetail['工序号']<10?'0'.$machineDetail['工序号']:$machineDetail['工序号']).'--'.$machineDetail['工序名称']
  1354. ];
  1355. //机台状态时间
  1356. $startTime = \db('设备_产量采集')
  1357. ->where('设备编号',$param['machine'])
  1358. ->where('开工时间',$param['start'])
  1359. ->field('rtrim(时间) as 时间,当班产量,rtrim(当前状态) as 状态,MAX(时间) as 最大时间,MAX(当班产量) as 最大产量')
  1360. ->group('当前状态')
  1361. ->select();
  1362. if (!empty($startTime)){
  1363. foreach ($startTime as $key=>$value){
  1364. $data['timeDifference'][$key] = [
  1365. '时间' => round((strtotime($value['最大时间'])-strtotime($value['时间']))/3600,2),
  1366. '状态' => $value['状态'] = null?'待单':$value['状态'],
  1367. ];
  1368. if ($value['状态'] === '生产'){
  1369. $data['当班产量'] = $value['最大产量']-$value['当班产量'];
  1370. }
  1371. }
  1372. }else{
  1373. $data['timeDifference'][0] = [
  1374. '时间' => 0,
  1375. '状态' => '待单'
  1376. ];
  1377. $data['当班产量'] = 0;
  1378. }
  1379. //机台产能/时间明细
  1380. $row = \db('设备_产量采集')
  1381. ->where('设备编号',$param['machine'])
  1382. ->where('开工时间',$param['start'])
  1383. ->where('当班产量','<>',-1)
  1384. ->field('rtrim(时间) as 时间,rtrim(当班产量) as 产量,rtrim(当前状态) as 状态')
  1385. ->select();
  1386. if (empty($row)){
  1387. $data['row'] = [];
  1388. }
  1389. foreach ($row as $key=>$value){
  1390. $data['row'][$key]['时间'] = date('Y-m-d H:i',strtotime($value['时间']));
  1391. $data['row'][$key]['状态'] = $value['状态'];
  1392. if ($key<2){
  1393. $data['row'][$key]['产能'] = 0;
  1394. }else{
  1395. $data['row'][$key]['产能'] = ($row[$key-1]['产量']-$row[$key-2]['产量'])*60;
  1396. }
  1397. }
  1398. //机台状态
  1399. $status = end($row);
  1400. if (empty($status['状态'])){
  1401. $data['status'] = '待单';
  1402. }else{
  1403. $data['status'] = $status['状态'];
  1404. }
  1405. //检验数据
  1406. $list = \db('制程检验_记录')
  1407. ->where('开工时间',$param['start'])
  1408. ->where('设备编号',$param['machine'])
  1409. ->where('sys_rq','>',$param['start'])
  1410. ->where('工单编号',$machineDetail['工单编号'])
  1411. ->field('rtrim(类别) as 类别,提交时间')
  1412. ->select();
  1413. $data['首件'] = $data['自检'] = $data['IPQC'] = [];
  1414. if (!empty($list)){
  1415. foreach ($list as $key=>$value){
  1416. if ($value['类别'] == '首件与过程确认'){
  1417. array_push($data['首件'],$value['提交时间']);
  1418. }
  1419. if ($value['类别'] == '机台检验'){
  1420. array_push($data['自检'],$value['提交时间']);
  1421. }
  1422. if ($value['类别'] == 'IPQC检验'){
  1423. array_push($data['IPQC'],$value['提交时间']);
  1424. }
  1425. }
  1426. $data['首件'] = array_values(array_unique($data['首件']));
  1427. $data['自检'] = array_values(array_unique($data['自检']));
  1428. $data['IPQC'] = array_values(array_unique($data['IPQC']));
  1429. }else{
  1430. $data['首件'] = [];
  1431. $data['自检'] = [];
  1432. $data['IPQC'] = [];
  1433. }
  1434. $this->success('成功',$data);
  1435. }
  1436. /**
  1437. * 制程检验记录->检验项目
  1438. * @ApiMethod (GET)
  1439. * @param void
  1440. * @return void
  1441. * @throws \think\db\exception\DataNotFoundException
  1442. * @throws \think\db\exception\ModelNotFoundException
  1443. * @throws \think\exception\DbException
  1444. */
  1445. public function ProcessInspectionRecordsItem()
  1446. {
  1447. if ($this->request->isGet() === false){
  1448. $this->error('请求错误');
  1449. }
  1450. $param = $this->request->param();
  1451. if (empty($param)){
  1452. $this->error('参数错误');
  1453. }
  1454. $list = \db('制程检验_项目')
  1455. ->where('工序','like','%'.$param['process'].'%')
  1456. ->select();
  1457. if (empty($list)){
  1458. $this->success('未找到检测项目');
  1459. }
  1460. $data = [];
  1461. foreach ($list as $key=>$value){
  1462. $data['首件']['指标检验'][$key] = [
  1463. '检验项目' => rtrim($value['检测项目']),
  1464. '检测方法' => rtrim($value['检测方法']),
  1465. '检验频率' => rtrim($value['首件签样要求']),
  1466. '相关标准' => rtrim($value['技术要求'])
  1467. ];
  1468. $data['机台检验']['指标检验'][$key] = [
  1469. '检验项目' => rtrim($value['检测项目']),
  1470. '检测方法' => rtrim($value['检测方法']),
  1471. '检验频率' => rtrim($value['机台自检频率']),
  1472. '相关标准' => rtrim($value['技术要求'])
  1473. ];
  1474. $data['IPQC']['指标检验'][$key] = [
  1475. '检验项目' => rtrim($value['检测项目']),
  1476. '检测方法' => rtrim($value['检测方法']),
  1477. '检验频率' => rtrim($value['IPQC检验频率']),
  1478. '相关标准' => rtrim($value['技术要求'])
  1479. ];
  1480. }
  1481. $row = \db('制程检验_项目附加')
  1482. ->where('工序','like','%'.$param['process'].'%')
  1483. ->select();
  1484. foreach ($row as $key=>$value){
  1485. $data['首件']['附加'][$key] = [
  1486. '缺陷备注' => rtrim($value['缺陷备注']),
  1487. '编号' => rtrim($value['编号'])
  1488. ];
  1489. $data['机台检验']['附加'][$key] = [
  1490. '缺陷备注' => rtrim($value['缺陷备注']),
  1491. '编号' => rtrim($value['编号'])
  1492. ];
  1493. $data['IPQC']['附加'][$key] = [
  1494. '缺陷备注' => rtrim($value['缺陷备注']),
  1495. '编号' => rtrim($value['编号'])
  1496. ];
  1497. }
  1498. $this->success('成功',$data);
  1499. }
  1500. /**
  1501. * 车间报工
  1502. * 制程检验记录->检测记录添加
  1503. */
  1504. public function ProcessInspectionRecordsItemAdd(){
  1505. if (Request::instance()->isPost() === false){
  1506. $this->error('请求错误');
  1507. }
  1508. $param = Request::instance()->post();
  1509. if (empty($param)){
  1510. $this->error('参数错误');
  1511. }
  1512. $startID = \db('制程检验_记录')->order('UniqId desc')->value('UniqId');
  1513. if (empty($startID)){
  1514. $startID = 0;
  1515. }
  1516. $process = \db('工单_工艺资料')
  1517. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1518. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1519. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1520. ->find();
  1521. $startTime = \db('设备_产量采集')
  1522. ->where('设备编号', 'like', '%' . $param[0]['machine'] . '#%')
  1523. ->where('工单编号', $param[0]['workOrder'])
  1524. ->order('UniqId desc')
  1525. ->find();
  1526. // 解决车间因未更换班组,导致开工时间仍为前一个班次,导致下一个班组进行上报时数据录到了前一个班次中的问题
  1527. if (!$startTime) {
  1528. $this->error('未找到对应的开工时间');
  1529. }
  1530. /*
  1531. * 系统提交时间(应报工时间)和开工时间
  1532. */
  1533. // $startTime = $startTime['开工时间'];
  1534. $rqTime = isset($param[0]['rq']) ? $param[0]['rq'] : date('Y-m-d H:i:s');
  1535. //转换为时间戳
  1536. $rqTimestamp = strtotime($rqTime);
  1537. $startTimestamp = strtotime($startTime['开工时间']);
  1538. // 计算时间差(秒)
  1539. $timeDiff = abs($rqTimestamp - $startTimestamp); // 取绝对值,防止负数
  1540. /*
  1541. * 计算时间差
  1542. */
  1543. // 转换时间差为 天、小时、分钟、秒
  1544. $days = floor($timeDiff / 86400);
  1545. $hours = floor(($timeDiff % 86400) / 3600);
  1546. $minutes = floor(($timeDiff % 3600) / 60);
  1547. $seconds = $timeDiff % 60;
  1548. // 格式化时间差
  1549. $formattedDiff = "";
  1550. if ($days > 0) $formattedDiff .= $days . "天";
  1551. if ($hours > 0) $formattedDiff .= $hours . "小时";
  1552. if ($minutes > 0) $formattedDiff .= $minutes . "分钟";
  1553. if ($seconds > 0) $formattedDiff .= $seconds . "秒";
  1554. //测试进行时间比较,查看时间判断是否正确
  1555. // echo "<pre>";
  1556. // print_r("系统提交时间:" .$rqTime);
  1557. // print_r("\n当前开工时间:" . $startTime);
  1558. // print_r("\n时间差:" . $formattedDiff);
  1559. // echo "<pre>";
  1560. // 判断是否超过 12 小时(12 * 3600 = 43200 秒)
  1561. if ($timeDiff > 43200) {
  1562. $this->error('请先更换班组后,再提交数据');
  1563. }
  1564. if ((int)$process['gxh']<10){
  1565. $process['gxh'] = '0'.$process['gxh'];
  1566. }
  1567. if ($process['add_gxmc'] !== ''){
  1568. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1569. }else{
  1570. $printName = $process['gxh'].'-'.$process['gxmc'];
  1571. }
  1572. if (empty($process)){
  1573. $this->success('数据错误');
  1574. }
  1575. $data = [];
  1576. foreach ($param as $key=>$value){
  1577. $data[$key] = [
  1578. '类别' => $value['category'],
  1579. '工单编号' => $value['workOrder'],
  1580. '印件号' => $value['yjno'],
  1581. '工序名称' => $printName,
  1582. '流程单号' => $value['flow'],
  1583. '设备编号' => $value['machine'].'#',
  1584. '班组编号' => $startTime['班组编号'],
  1585. '检验项目' => $value['item'],
  1586. '相关标准' => $value['standard'],
  1587. '量测仪器' => $value['instrument'],
  1588. '检验结果' => $value['selected'],
  1589. '检验备注' => $value['remark'],
  1590. '提交时间' => date('Y-m-d H:i:s',time()),
  1591. '开工时间' => rtrim($startTime['开工时间']),
  1592. 'sys_id' => '',
  1593. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1594. 'mod_rq' => '0000-00-00 00:00:00',
  1595. 'UniqId' => $startID + $key +1
  1596. ];
  1597. }
  1598. $res = \db('制程检验_记录')->insertAll($data);
  1599. if ($res !== false){
  1600. $this->success('成功');
  1601. }else{
  1602. $this->error('失败');
  1603. }
  1604. }
  1605. /**
  1606. * 制程检验记录->附加检验记录添加
  1607. * @ApiMethod (POST)
  1608. * @param void
  1609. * @return void
  1610. * @throws \think\db\exception\DataNotFoundException
  1611. * @throws \think\db\exception\ModelNotFoundException
  1612. * @throws \think\exception\DbException
  1613. */
  1614. public function AdditionalInspectionRecordAdd()
  1615. {
  1616. if (Request::instance()->isPost() === false){
  1617. $this->error('请求错误');
  1618. }
  1619. $param = Request::instance()->post();
  1620. if (empty($param)){
  1621. $this->error('参数错误');
  1622. }
  1623. $startID = \db('制程检验_记录附加')->order('UniqId desc')->value('UniqId');
  1624. if (empty($startID)){
  1625. $startID = 0;
  1626. }
  1627. $process = \db('工单_工艺资料')
  1628. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1629. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1630. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1631. ->find();
  1632. $startTime = \db('设备_产量采集')
  1633. ->where('设备编号','like','%'.$param[0]['machine'].'#%')
  1634. ->where('工单编号',$param[0]['workOrder'])
  1635. ->order('UniqId desc')
  1636. ->find();
  1637. if ((int)$process['gxh']<10){
  1638. $process['gxh'] = '0'.$process['gxh'];
  1639. }
  1640. if ($process['add_gxmc'] !== ''){
  1641. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1642. }else{
  1643. $printName = $process['gxh'].'-'.$process['gxmc'];
  1644. }
  1645. if (empty($process)){
  1646. $this->success('数据错误');
  1647. }
  1648. $data = [];
  1649. foreach ($param as $key=>$value){
  1650. $data[$key] = [
  1651. '工单编号' => $value['workOrder'],
  1652. '印件号' => $value['yjno'],
  1653. '工序名称' => $printName,
  1654. '流程单号' => $value['flow'],
  1655. '设备编号' => $value['machine'],
  1656. '班组编号' => $startTime['班组编号'],
  1657. '缺陷备注' => $value['remark'],
  1658. '提交时间' => date('Y-m-d H:i:s',time()),
  1659. '开工时间' => rtrim($startTime['开工时间']),
  1660. 'sys_id' => '',
  1661. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1662. 'mod_rq' => '0000-00-00 00:00:00',
  1663. 'UniqId' => $startID + $key +1
  1664. ];
  1665. }
  1666. $res = \db('制程检验_记录附加')->insertAll($data);
  1667. if ($res !== false){
  1668. $this->success('成功');
  1669. }else{
  1670. $this->error('失败');
  1671. }
  1672. }
  1673. /**
  1674. * 客诉记录
  1675. * @ApiMethod (GET)
  1676. * @param void
  1677. * @return void
  1678. * @throws \think\db\exception\DataNotFoundException
  1679. * @throws \think\db\exception\ModelNotFoundException
  1680. * @throws \think\exception\DbException
  1681. */
  1682. public function ComplaintRecord()
  1683. {
  1684. if ($this->request->isGet() === false){
  1685. $this->error('请求错误');
  1686. }
  1687. $param = $this->request->param();
  1688. if (isset($param['productCode'])){
  1689. $where['产品编号'] = $param['productCode'];
  1690. }
  1691. $filed = "rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,rtrim(客诉日期) as 客诉日期,rtrim(客诉单号) as 客诉单号,
  1692. rtrim(客诉方式) as 客诉方式,rtrim(订单编号) as 订单编号,rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,
  1693. rtrim(客诉描述) as 客诉描述,rtrim(缺陷关键字) as 缺陷关键字,rtrim(客诉性质) as 客诉性质,rtrim(扣分) as 扣分,
  1694. rtrim(主要责任部门) as 主要责任部门,rtrim(次要责任部门) as 次要责任部门";
  1695. $list = \db('db_客诉记录')
  1696. ->where($where)
  1697. ->field($filed)
  1698. ->select();
  1699. if (empty($list)){
  1700. $this->success('未找到该产品客诉记录');
  1701. }
  1702. $this->success('成功',$list);
  1703. }
  1704. /**
  1705. * 设置机台班组信息
  1706. * @return void
  1707. * @throws \think\db\exception\DataNotFoundException
  1708. * @throws \think\db\exception\ModelNotFoundException
  1709. * @throws \think\exception\DbException
  1710. */
  1711. public function setMachineTeam()
  1712. {
  1713. if (Request::instance()->isPost() == false) {
  1714. $this->error('非法请求');
  1715. }
  1716. $params = Request::instance()->post();
  1717. if (!isset($params['machine']) || empty($params['machine'] )) {
  1718. $this->error('参数不能为空');
  1719. }
  1720. if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
  1721. $this->error('请先选择班组成员');
  1722. }
  1723. $machine = $params['machine'] . '#';
  1724. $data = [];
  1725. $lastData = \db('设备_产量采集')
  1726. ->order('UniqId desc')
  1727. ->find();
  1728. $id = $lastData['UniqId']+1;
  1729. $data['当前状态'] = $params['status'];
  1730. $data['时间'] = date('Y-m-d H:i:s');
  1731. $data['设备编号'] = $machine;
  1732. $data['工单编号'] = empty($params['order']) ? '':$params['order'];
  1733. $data['印件号'] = empty($params['yjno']) ? '':$params['yjno'];
  1734. $data['工序号'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
  1735. $data['工序名称'] = empty($params['gy_name']) ? '' : $params['gy_name'];
  1736. $data['当班产量'] = $params['production_now'];
  1737. $data['累计产量'] = $params['production_all'];
  1738. $data['班组编号'] = $params['sczl_bzdh'];
  1739. $data['班组ID'] = $params['team_id'];
  1740. // // 获取当前时间
  1741. // $current_time = time();
  1742. // // 设置时间范围
  1743. // $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  1744. // $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  1745. // $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  1746. // $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  1747. // $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  1748. // // 判断当前时间属于哪个时间范围
  1749. // if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  1750. // $data['开工时间'] = date('Y-m-d') . ' 08:30:00';
  1751. // } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  1752. // $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  1753. // } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  1754. // $data['开工时间'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  1755. // }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  1756. // $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  1757. // }
  1758. $current_time = time();
  1759. $today = date('Y-m-d');
  1760. $tomorrow = date('Y-m-d', strtotime('+1 day'));
  1761. $morning_start = strtotime("$today 08:30:00");
  1762. $evening_start = strtotime("$today 20:30:00");
  1763. $next_morning = strtotime("$tomorrow 08:30:00");
  1764. // 逻辑判断
  1765. if ($current_time < $morning_start) {
  1766. // 当天8:30之前,使用前一天的20:30
  1767. $data['开工时间'] = date('Y-m-d', strtotime('-1 day')) . ' 20:30:00';
  1768. } elseif ($current_time <= $evening_start) {
  1769. // 8:30-20:30之间,使用当天8:30
  1770. $data['开工时间'] = "$today 08:30:00";
  1771. } elseif ($current_time < $next_morning) {
  1772. // 20:30到次日8:30之间,使用当天20:30
  1773. $data['开工时间'] = "$today 20:30:00";
  1774. } else {
  1775. // 次日8:30之后,使用次日8:30
  1776. $data['开工时间'] = "$tomorrow 08:30:00";
  1777. }
  1778. if (!empty($params['order']) && !empty($params['yjno'])){
  1779. $option['Gy0_gdbh'] = $params['order'];
  1780. $option['Gy0_yjno'] = $params['yjno'];
  1781. $option['Gy0_gxh'] = $data['工序号'];
  1782. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  1783. }else{
  1784. $data['任务ID'] = '';
  1785. }
  1786. $data['UniqId'] = $id;
  1787. $sql = \db('设备_产量采集')->fetchSql(true)->insert($data);
  1788. $res = Db::query($sql);
  1789. if ($res === false) {
  1790. $this->error('设置失败');
  1791. } else {
  1792. $this->success('设置成功');
  1793. }
  1794. }
  1795. /**
  1796. * 首页数据
  1797. * @return void
  1798. * @throws \think\Exception
  1799. * @throws \think\db\exception\DataNotFoundException
  1800. * @throws \think\db\exception\ModelNotFoundException
  1801. * @throws \think\exception\DbException
  1802. */
  1803. public function index()
  1804. {
  1805. if ($this->request->isGet() === false){
  1806. $this->error('请求错误');
  1807. }
  1808. $nowTime = date('Y-m-d H:i:s',time());
  1809. $oldTime = (date('Y')-1).'-'.date('m-d H:i:s');
  1810. $where =[
  1811. 'Mod_rq' => ['between',[$oldTime,$nowTime]],
  1812. '行号' => '1'
  1813. ];
  1814. $data = [];
  1815. //按状态查询工单信息
  1816. $orderList = \db('工单_基本资料')
  1817. ->where($where)
  1818. ->field('count(Gd_gdbh) as 数量,rtrim(gd_statu) as 状态')
  1819. ->group('gd_statu')
  1820. ->select();
  1821. foreach ($orderList as $value){
  1822. if ($value['状态'] === '1-已完工'){
  1823. $data['workOrderData']['已完工'] = $value['数量'];
  1824. }
  1825. if ($value['状态'] === '3-计划中'){
  1826. $data['workOrderData']['计划中'] = $value['数量'];
  1827. }
  1828. }
  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. $data['workOrderData']['制程中'] = db('工单_基本资料')->alias('a')
  1843. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  1844. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  1845. ->where([
  1846. 'a.gd_statu' => '2-生产中',
  1847. 'a.行号' => '1',
  1848. 'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
  1849. 'b.PD_WG' => '1900-01-01 00:00:00',
  1850. 'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'],
  1851. 'c.状态' => '',
  1852. ])
  1853. ->group('a.Gd_gdbh')
  1854. ->count();
  1855. //按月份查询工单信息
  1856. $data['monthData'] = \db('工单_基本资料')
  1857. ->where('Mod_rq', 'between', [$oldTime, $nowTime])
  1858. ->field('DATE_FORMAT(Mod_rq, "%Y-%m") as month, COUNT(*) as count')
  1859. ->group('month')
  1860. ->order('month')
  1861. ->select();
  1862. //查询最近十条客诉信息
  1863. $data['customer'] = \db('db_客诉记录')
  1864. ->field('rtrim(客诉描述) as 客诉描述,DATE_FORMAT(客诉日期, "%Y-%m-%d") as 日期,rtrim(UniqID) as UniqId')
  1865. ->limit(10)
  1866. ->order('Sys_rq desc')
  1867. ->select();
  1868. $this->success('成功',$data);
  1869. }
  1870. /**
  1871. * 员工信息获取
  1872. * @return void
  1873. * @throws \think\db\exception\DataNotFoundException
  1874. * @throws \think\db\exception\ModelNotFoundException
  1875. * @throws \think\exception\DbException
  1876. */
  1877. public function EmployeeData()
  1878. {
  1879. if ($this->request->isGet() === false){
  1880. $this->error('请求错误');
  1881. }
  1882. $param = $this->request->param();
  1883. if (isset($param['code']) === false){
  1884. $this->error('参数错误');
  1885. }
  1886. $res = \db('人事_基本资料')
  1887. ->where('员工编号','like',$param['code'].'%')
  1888. ->field('rtrim(员工编号) as 员工编号,rtrim(员工姓名) as 员工姓名')
  1889. ->select();
  1890. if (empty($res)){
  1891. $this->success('未找到该员工');
  1892. }
  1893. $this->success('成功',$res);
  1894. }
  1895. /**
  1896. * 换型清场添加
  1897. * @return void
  1898. * @throws \think\db\exception\BindParamException
  1899. * @throws \think\exception\PDOException
  1900. */
  1901. public function remodelDataAdd()
  1902. {
  1903. if (Request::instance()->isPost() === false){
  1904. $this->error('请求错误');
  1905. }
  1906. $param = Request::instance()->post();
  1907. if (empty($param)){
  1908. $this->error('参数错误');
  1909. }
  1910. $lastId = \db('制程_换型清场')->order('UniqId desc')->value('UniqId');
  1911. $param['sys_id'] = '['.$param['机台编号'].']';
  1912. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  1913. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1914. $param['UniqId'] = $lastId + 1;
  1915. $sql = \db('制程_换型清场')->fetchSql(true)->insert($param);
  1916. $res = \db()->query($sql);
  1917. if ($res !== false){
  1918. $this->success('成功');
  1919. }else{
  1920. $this->error('失败');
  1921. }
  1922. }
  1923. /**
  1924. * 换型清场记录修改
  1925. * @return void
  1926. * @throws \think\Exception
  1927. * @throws \think\db\exception\BindParamException
  1928. * @throws \think\exception\PDOException
  1929. */
  1930. public function remodelDataEdit()
  1931. {
  1932. if (Request::instance()->isPost() === false){
  1933. $this->error('请求错误');
  1934. }
  1935. $param = Request::instance()->post();
  1936. if (empty($param)){
  1937. $this->error('参数错误');
  1938. }
  1939. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  1940. $sql = \db('制程_换型清场')->fetchSql(true)->update($param);
  1941. $res = \db()->query($sql);
  1942. if ($res !== false){
  1943. $this->success('成功');
  1944. }else{
  1945. $this->error('失败');
  1946. }
  1947. }
  1948. /**
  1949. * 换型清场记录删除
  1950. * @return void
  1951. * @throws \think\Exception
  1952. * @throws \think\exception\PDOException
  1953. */
  1954. public function remodelDataDel()
  1955. {
  1956. if ($this->request->isGet() === false){
  1957. $this->error('请求错误');
  1958. }
  1959. $param = $this->request->param();
  1960. if (empty($param)){
  1961. $this->error('参数错误');
  1962. }
  1963. $res = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->delete();
  1964. if ($res !== false){
  1965. $this->success('删除成功');
  1966. }else{
  1967. $this->error('删除失败');
  1968. }
  1969. }
  1970. /**
  1971. * 印版领用记录添加
  1972. * @return void
  1973. * @throws \think\db\exception\BindParamException
  1974. * @throws \think\exception\PDOException
  1975. */
  1976. public function PrintDetailAdd()
  1977. {
  1978. if (Request::instance()->isPost() === false){
  1979. $this->error('请求错误');
  1980. }
  1981. $param = Request::instance()->post();
  1982. if (empty($param)){
  1983. $this->error('参数错误');
  1984. }
  1985. $lastId = \db('工单_印版领用记录')->order('UniqID desc')->value('UniqID');
  1986. foreach ($param as $key=>$value){
  1987. $param[$key]['Yb_领用日期'] = date('Y-m-d H:i:s',time());
  1988. $param[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  1989. $param[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  1990. }
  1991. $sql = \db('工单_印版领用记录')->fetchSql(true)->insertAll($param);
  1992. $res = \db()->query($sql);
  1993. if ($res !== false){
  1994. $this->success('添加成功');
  1995. }else{
  1996. $this->error('添加失败');
  1997. }
  1998. }
  1999. /**
  2000. * 印版领用记录退还
  2001. * @return void
  2002. * @throws \think\Exception
  2003. * @throws \think\db\exception\BindParamException
  2004. * @throws \think\exception\PDOException
  2005. */
  2006. public function PrintDetailEdit()
  2007. {
  2008. if ($this->request->isGet() === false){
  2009. $this->error('请求错误');
  2010. }
  2011. $param = $this->request->param();
  2012. if (empty($param) || !isset($param['id']) || !isset($param['number'])){
  2013. $this->error('参数错误');
  2014. }
  2015. $idList = explode(',',$param['id']);
  2016. $i = 0;
  2017. foreach ($idList as $key=>$value){
  2018. $data['Yb_退还日期'] = date('Y-m-d H:i:s',time());
  2019. $data['Mod_rq'] = date('Y-m-d H:i:s',time());
  2020. $data['Yb_印数'] = $param['number'];
  2021. $sql = \db('工单_印版领用记录')->where('UniqID',$value)->fetchSql(true)->update($data);
  2022. $res = \db()->query($sql);
  2023. if ($res === false){
  2024. $i++;
  2025. }
  2026. }
  2027. if ($i !== 0){
  2028. $this->error('退还失败');
  2029. }else{
  2030. $this->success('退还成功');
  2031. }
  2032. }
  2033. /**
  2034. * 当班产量明细修改
  2035. * @return void
  2036. * @throws \think\Exception
  2037. * @throws \think\db\exception\BindParamException
  2038. * @throws \think\exception\PDOException
  2039. */
  2040. // public function chanliangEdit()
  2041. // {
  2042. // if (Request::instance()->isPost() === false){
  2043. // $this->error('请求错误');
  2044. // }
  2045. // $param = Request::instance()->post();
  2046. // if (empty($param['UniqId'])){
  2047. // $this->error('参数错误');
  2048. // }
  2049. // $param['mod_rq'] = date('Y-m-d H:i:s',time());
  2050. // $data = $param;
  2051. // unset($data['UniqId']);
  2052. // unset($data['sczl_rq']);
  2053. // $sql = \db('设备_产量计酬')
  2054. // ->where('UniqId',$param['UniqId'])
  2055. // ->fetchSql(true)
  2056. // ->update($data);
  2057. // $res = \db()->query($sql);
  2058. // if ($res !== false){
  2059. // $this->success('修改成功');
  2060. // }else {
  2061. // $this->error('修改失败');
  2062. // }
  2063. // }
  2064. public function chanliangEdit()
  2065. {
  2066. // 使用更简洁的请求判断方式
  2067. if (!Request::instance()->isPost()) {
  2068. $this->error('请使用POST请求');
  2069. }
  2070. // 获取并过滤POST参数
  2071. $param = Request::instance()->post();
  2072. // 更严格的参数验证
  2073. if (empty($param['UniqId'])) {
  2074. $this->error('缺少必要参数: UniqId');
  2075. }
  2076. // 整理更新数据
  2077. $updateData = [
  2078. 'mod_rq' => date('Y-m-d H:i:s')
  2079. ];
  2080. // 合并其他参数(排除不需要的字段)
  2081. $excludeFields = ['UniqId', 'sczl_rq', 'sczl_装版总工时', 'sczl_换版联拼数', '换版类型'];
  2082. foreach ($param as $key => $value) {
  2083. if (!in_array($key, $excludeFields)) {
  2084. $updateData[$key] = $value;
  2085. }
  2086. }
  2087. $uniqId = $param['UniqId'];
  2088. $success = false;
  2089. try {
  2090. // 处理装版工时数据(如果存在)
  2091. if (!empty($param['sczl_装版总工时']) && $param['sczl_装版总工时'] != 0) {
  2092. $priData = [
  2093. '换版总工时' => $param['sczl_装版总工时'],
  2094. '换版联拼数' => $param['sczl_换版联拼数'] ?? 0,
  2095. '换版类型' => $param['换版类型'] ?? '',
  2096. '装版补产工时' => $param['sczl_装版工时'] ?? ''
  2097. ];
  2098. $priSql = \db('设备_装版工时')->where('yieldUid', $uniqId)->fetchSql(true)->update($priData);
  2099. \db()->query($priSql);
  2100. }
  2101. // 更新产量计酬数据
  2102. $rowSql = \db('设备_产量计酬')->where('UniqId', $uniqId)->fetchSql(true)->update($updateData);
  2103. $rowCount = \db()->query($rowSql);
  2104. $success = $rowCount !== false;
  2105. } catch (\Exception $e) {
  2106. // 记录错误日志
  2107. \think\Log::error('修改产量详情失败: ' . $e->getMessage() . ' 堆栈: ' . $e->getTraceAsString());
  2108. $this->error('操作失败: ' . $e->getMessage());
  2109. }
  2110. if ($success) {
  2111. $this->success('修改成功');
  2112. } else {
  2113. $this->error('修改失败,未更新任何数据');
  2114. }
  2115. }
  2116. /**
  2117. * 获取当日上报产量详细数据
  2118. * @return void
  2119. * @throws \think\db\exception\DataNotFoundException
  2120. * @throws \think\db\exception\ModelNotFoundException
  2121. * @throws \think\exception\DbException
  2122. */
  2123. public function MachineChanliangDetail()
  2124. {
  2125. if ($this->request->isGet() === false){
  2126. $this->error('请求错误');
  2127. }
  2128. $param = $this->request->param();
  2129. if (empty($param['UniqId'])){
  2130. $this->error('参数错误');
  2131. }
  2132. $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 联数,
  2133. rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,rtrim(sczl_zcfp) as 制程废品,
  2134. rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,
  2135. rtrim(sczl_装版总工时) as 装版总工时,rtrim(sczl_打样总工时) as 打样总工时,
  2136. rtrim(sczl_装版工时) as 装版工时,rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,
  2137. rtrim(sczl_异常停机工时) as 异常总工时,rtrim(sczl_设备运行工时) as 通电工时,
  2138. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,
  2139. rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度数,
  2140. rtrim(sczl_异常工时1) as 异常补时,rtrim(sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  2141. rtrim(sczl_装版工时) as 装版补产工时,rtrim(sczl_打样工时) as 打样补产工时,
  2142. sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,
  2143. sczl_rate2,sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
  2144. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId';
  2145. $list = \db('设备_产量计酬')->where('UniqId',$param['UniqId'])->field($field)->find();
  2146. $pridata = \db('设备_装版工时')
  2147. ->field('换版联拼数,换版类型,Uniqid,coefficient')
  2148. ->where('yieldUid',$param['UniqId'])
  2149. ->order('Uniqid desc')
  2150. ->find();
  2151. if (empty($list)){
  2152. $this->success('未找到产量详情信息');
  2153. }
  2154. $list['换版联拼数'] = '';
  2155. $list['换版类型'] = '';
  2156. $list['Uid'] = '';
  2157. $list['系数'] = '';
  2158. if (!empty($pridata)){
  2159. $list['换版联拼数'] = $pridata['换版联拼数'];
  2160. $list['换版类型'] = $pridata['换版类型'];
  2161. $list['Uid'] = $pridata['Uniqid'];
  2162. $list['系数'] = $pridata['coefficient'];
  2163. }
  2164. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$list['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  2165. $list['印件名称'] = $productName['cpmc'];
  2166. if (!empty($productName['成品名称'])){
  2167. $list['cpmc'] = $productName['成品名称'];
  2168. }elseif (empty($productName['成品名称']) && !empty($productName['cpmc'])){
  2169. $list['cpmc'] = $productName['cpmc'];
  2170. }else{
  2171. $list['cpmc'] = '';
  2172. }
  2173. for ($i=1;$i<11;$i++){
  2174. if (isset($list['sczl_bh'.$i])){
  2175. $name = \db('人事_基本资料')->where('员工编号',$list['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
  2176. if (isset($name['name'])){
  2177. $list['组员'.$i] = [
  2178. '编号' => $list['sczl_bh'.$i],
  2179. '姓名' => $name['name'],
  2180. '比例' => (float)$list['sczl_rate'.$i]
  2181. ];
  2182. }
  2183. }
  2184. if (empty($list['sczl_bh'.$i])){
  2185. $list['组员'.$i] = [
  2186. '编号' => '',
  2187. '姓名' => '',
  2188. '比例' => ''
  2189. ];
  2190. }
  2191. unset($list['sczl_bh'.$i],$list['sczl_rate'.$i]);
  2192. }
  2193. $list['拉料'] = [
  2194. '编号' => $list['sczl_bh98'],
  2195. '姓名' => \db('人事_基本资料')->where('员工编号',$list['sczl_bh98'])->value('rtrim(员工姓名)')
  2196. ];
  2197. unset($list['sczl_bh98']);
  2198. $this->success('成功',$list);
  2199. }
  2200. /**
  2201. * 当日上报产量详细数据修改
  2202. * @return void
  2203. * @throws \think\Exception
  2204. * @throws \think\db\exception\BindParamException
  2205. * @throws \think\exception\PDOException
  2206. */
  2207. // public function MachineChanliangDetailEdit()
  2208. // {
  2209. // if (Request::instance()->isPost() === false){
  2210. // $this->error('请求错误');
  2211. // }
  2212. // $param = Request::instance()->post();
  2213. // if (empty($param['UniqId'])){
  2214. // $this->error('参数错误');
  2215. // }
  2216. // $param['sczl_type'] = $param['sczl_gxmc'];
  2217. // $param['mod_rq'] = date('Y-m-d H:i:s',time());
  2218. // $UnidId = $param['UniqId'];
  2219. // unset($param['UniqId']);
  2220. // unset($param['sczl_rq']);
  2221. // if (!empty($param['sczl_装版总工时']) && $param['sczl_装版总工时'] !== 0){
  2222. // $data = [
  2223. // 'gdbh' => $param['sczl_gdbh'],
  2224. // 'yjno' => $param['sczl_yjno'],
  2225. // 'gxh' => $param['sczl_gxh'],
  2226. // 'jtbh' => $param['sczl_jtbh'],
  2227. // 'startTime' => $param['sczl_sj1'],
  2228. // 'endTime' => $param['sczl_sj2'],
  2229. // '换版总工时' => $param['sczl_装版总工时'],
  2230. // '换版联拼数' => $param['sczl_换版联拼数'],
  2231. // '换版类型' => $param['换版类型']
  2232. // ];
  2233. // $priSql = \db('设备_装版工时')->where('yieldUid')->fetchSql(true)->update($data);
  2234. // $priRes = \db()->query($priSql);
  2235. //
  2236. // }
  2237. // $sql = \db('设备_产量计酬')->where('UniqId',$UnidId)->fetchSql(true)->update($param);
  2238. // $res = \db()->query($sql);
  2239. // if ($res !== false){
  2240. // $this->success('修改成功');
  2241. // }else{
  2242. // $this->error('修改失败');
  2243. // }
  2244. // }
  2245. public function MachineChanliangDetailEdit()
  2246. {
  2247. // 使用更简洁的请求判断方式
  2248. if (!Request::instance()->isPost()) {
  2249. $this->error('请使用POST请求');
  2250. }
  2251. // 获取并过滤POST参数
  2252. $param = Request::instance()->post();
  2253. // 更严格的参数验证
  2254. if (empty($param['UniqId'])) {
  2255. $this->error('缺少必要参数: UniqId');
  2256. }
  2257. // 整理更新数据
  2258. $updateData = [
  2259. 'sczl_type' => $param['sczl_gxmc'] ?? '',
  2260. 'mod_rq' => date('Y-m-d H:i:s')
  2261. ];
  2262. // 合并其他参数(排除不需要的字段)
  2263. $excludeFields = ['UniqId', 'sczl_rq', 'sczl_换版联拼数', '换版类型'];
  2264. foreach ($param as $key => $value) {
  2265. if (!in_array($key, $excludeFields)) {
  2266. $updateData[$key] = $value;
  2267. }
  2268. }
  2269. $uniqId = $param['UniqId'];
  2270. $success = false;
  2271. try {
  2272. // 处理装版工时数据(如果存在)
  2273. if (!empty($param['sczl_装版总工时']) && $param['sczl_装版总工时'] != 0) {
  2274. $priData = [
  2275. 'gdbh' => $param['sczl_gdbh'] ?? '',
  2276. 'yjno' => $param['sczl_yjno'] ?? '',
  2277. 'gxh' => $param['sczl_gxh'] ?? '',
  2278. 'jtbh' => $param['sczl_jtbh'] ?? '',
  2279. 'startTime' => $param['sczl_sj1'] ?? '',
  2280. 'endTime' => $param['sczl_sj2'] ?? '',
  2281. '换版总工时' => $param['sczl_装版总工时'],
  2282. '换版联拼数' => $param['sczl_换版联拼数'] ?? 0,
  2283. '换版类型' => $param['换版类型'] ?? '',
  2284. '装版补产工时' => $param['sczl_装版工时'] ?? ''
  2285. ];
  2286. $priSql = \db('设备_装版工时')->where('yieldUid', $uniqId)->fetchSql(true)->update($priData);
  2287. \db()->query($priSql);
  2288. }
  2289. // 更新产量计酬数据
  2290. $rowSql = \db('设备_产量计酬')->where('UniqId', $uniqId)->fetchSql(true)->update($updateData);
  2291. $rowCount = \db()->query($rowSql);
  2292. $success = $rowCount !== false;
  2293. } catch (\Exception $e) {
  2294. // 记录错误日志
  2295. \think\Log::error('修改产量详情失败: ' . $e->getMessage() . ' 堆栈: ' . $e->getTraceAsString());
  2296. $this->error('操作失败: ' . $e->getMessage());
  2297. }
  2298. if ($success) {
  2299. $this->success('修改成功');
  2300. } else {
  2301. $this->error('修改失败,未更新任何数据');
  2302. }
  2303. }
  2304. /**
  2305. * 产量上报数据删除
  2306. * @return void
  2307. * @throws \think\Exception
  2308. * @throws \think\exception\PDOException
  2309. */
  2310. public function ChanliangDel()
  2311. {
  2312. if ($this->request->isGet() === false){
  2313. $this->error('请求错误');
  2314. }
  2315. $param = $this->request->param();
  2316. if (empty($param['UniqId'])){
  2317. $this->error('参数错误');
  2318. }
  2319. $idList = explode(',',$param['UniqId']);
  2320. foreach ($idList as $key=>$value){
  2321. $res = \db('设备_产量计酬')
  2322. ->where('UniqId',$value)
  2323. ->delete();
  2324. }
  2325. if ($res !== false){
  2326. $this->success('删除成功');
  2327. }else{
  2328. $this->error('删除失败');
  2329. }
  2330. }
  2331. /**
  2332. * 日产量上报添加
  2333. * @return void
  2334. * @throws \think\db\exception\BindParamException
  2335. * @throws \think\exception\PDOException
  2336. */
  2337. // public function ChanliangAdd()
  2338. // {
  2339. // if (Request::instance()->isPost() === false){
  2340. // $this->error('请求错误');
  2341. // }
  2342. // $params = Request::instance()->post();
  2343. // if (empty($params['sczl_gdbh'])){
  2344. // $this->error('参数错误');
  2345. // }
  2346. // $lastId = \db('设备_产量计酬')->order('UniqId desc')->value('rtrim(UniqId)');
  2347. // $massage = \db('工单_工艺资料')
  2348. // ->where('Gy0_gdbh',$params['sczl_gdbh'])
  2349. // ->where('Gy0_yjno',$params['sczl_yjno'])
  2350. // ->where('Gy0_gxh',$params['sczl_gxh'])
  2351. // ->count();
  2352. // if ($massage === 0){
  2353. // $this->error('请选择正确的工序');
  2354. // }
  2355. // $params['sczl_type'] = $params['sczl_gxmc'];
  2356. // $params['sczl_wgsj'] = '1900-01-01 00:00:00';
  2357. // $params['sczl_废品率系数'] = 0;
  2358. // $params['sys_rq'] = date('Y-m-d H:i:s',time());
  2359. // $params['mod_rq'] = date('Y-m-d H:i:s',time());
  2360. // $params['UniqId'] = $lastId + 1;
  2361. // if (!empty($params['sczl_装版总工时']) && $params['sczl_装版总工时'] !== 0){
  2362. // $data = [
  2363. // 'gdbh' => $params['sczl_gdbh'],
  2364. // 'yjno' => $params['sczl_yjno'],
  2365. // 'gxh' => $params['sczl_gxh'],
  2366. // 'jtbh' => $params['sczl_jtbh'],
  2367. // 'startTime' => $params['sczl_sj1'],
  2368. // 'endTime' => $params['sczl_sj2'],
  2369. // 'yieldUid' => $params['UniqId'],
  2370. // '换版总工时' => $params['sczl_装版总工时'],
  2371. // '换版联拼数' => $params['sczl_换版联拼数'],
  2372. // '换版类型' => $params['换版类型'],
  2373. // 'sys_rq' => date('Y-m-d H:i:s',time()),
  2374. // 'sys_id' => $params['sys_id']
  2375. // ];
  2376. // $chSql = \db('设备_装版工时')->fetchSql(true)->insert($data);
  2377. // $chRes = \db()->query($chSql);
  2378. // }
  2379. // unset($params['sczl_换版联拼数'],$params['换版类型']);
  2380. // $sql = \db('设备_产量计酬')->fetchSql(true)->insert($params);
  2381. // $res = \db()->query($sql);
  2382. // if ($res !== false){
  2383. // $this->success('成功');
  2384. // }else{
  2385. // $this->error('失败');
  2386. // }
  2387. // }
  2388. public function ChanliangAdd()
  2389. {
  2390. // 1. 请求验证
  2391. if (!Request::instance()->isPost()) {
  2392. $this->error('请求错误');
  2393. }
  2394. $params = Request::instance()->post();
  2395. // 2. 参数验证
  2396. if (empty($params['sczl_gdbh'])) {
  2397. $this->error('参数错误');
  2398. }
  2399. // 3. 获取最新ID
  2400. $lastId = db('设备_产量计酬')->order('UniqId desc')->value('rtrim(UniqId)');
  2401. // 4. 验证工序存在性
  2402. $massage = db('工单_工艺资料')
  2403. ->where('Gy0_gdbh', $params['sczl_gdbh'])
  2404. ->where('Gy0_yjno', $params['sczl_yjno'])
  2405. ->where('Gy0_gxh', $params['sczl_gxh'])
  2406. ->count();
  2407. if ($massage === 0) {
  2408. $this->error('请选择正确的工序');
  2409. }
  2410. // 5. 准备基础数据
  2411. $currentTime = date('Y-m-d H:i:s');
  2412. $params['sczl_type'] = $params['sczl_gxmc'];
  2413. $params['sczl_wgsj'] = '1900-01-01 00:00:00';
  2414. $params['sczl_废品率系数'] = 0;
  2415. $params['sys_rq'] = $currentTime;
  2416. $params['mod_rq'] = $currentTime;
  2417. $params['UniqId'] = $lastId + 1;
  2418. // 6. 处理装版工时记录(如果有)
  2419. if (!empty($params['sczl_装版总工时']) && $params['sczl_装版总工时'] != 0) {
  2420. if (!isset($params['sczl_sj1']) || empty($params['sczl_sj1'])) {
  2421. $params['sczl_sj1'] = date('Y-m-d H:i:s',time());
  2422. }
  2423. if (!isset($params['sczl_sj2']) || empty($params['sczl_sj2'])) {
  2424. $params['sczl_sj2'] = date('Y-m-d H:i:s',time());
  2425. }
  2426. $plateData = [
  2427. 'gdbh' => $params['sczl_gdbh'],
  2428. 'yjno' => $params['sczl_yjno'],
  2429. 'gxh' => $params['sczl_gxh'],
  2430. 'jtbh' => $params['sczl_jtbh'],
  2431. 'startTime' => $params['sczl_sj1'],
  2432. 'endTime' => $params['sczl_sj2'],
  2433. 'yieldUid' => $params['UniqId'],
  2434. '换版总工时' => $params['sczl_装版总工时'],
  2435. '换版联拼数' => $params['sczl_换版联拼数'],
  2436. '换版类型' => $params['换版类型'],
  2437. 'sys_rq' => $currentTime,
  2438. 'sys_id' => $params['sys_id']
  2439. ];
  2440. $chSql = db('设备_装版工时')->fetchSql(true)->insert($plateData);
  2441. $chRes = \db()->query($chSql);
  2442. if ($chRes === false) {
  2443. $this->error('装版工时记录保存失败');
  2444. }
  2445. }
  2446. // 7. 移除不需要的字段
  2447. unset($params['sczl_换版联拼数'], $params['换版类型']);
  2448. // 8. 保存主记录
  2449. $sql = db('设备_产量计酬')->fetchSql(true)->insert($params);
  2450. $res = db()->query($sql);
  2451. if ($res !== false) {
  2452. $this->success('成功');
  2453. } else {
  2454. $this->error('失败');
  2455. }
  2456. }
  2457. /**
  2458. * 日产量上报添加获取工单信息
  2459. * @return void
  2460. * @throws \think\db\exception\DataNotFoundException
  2461. * @throws \think\db\exception\ModelNotFoundException
  2462. * @throws \think\exception\DbException
  2463. */
  2464. public function ChanliangWorkorder()
  2465. {
  2466. if ($this->request->isGet() === false)
  2467. {
  2468. $this->error('请求错误');
  2469. }
  2470. $param = $this->request->param();
  2471. if (empty($param)){
  2472. $this->error('参数错误');
  2473. }
  2474. // $where = [
  2475. // 'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
  2476. // ];
  2477. // if (!empty($param['machine'])){
  2478. // $where = [
  2479. // 'b.Gy0_sbbh' => ['like','%'.$param['machine'].'%'],
  2480. // ];
  2481. // }
  2482. if (!empty($param['search'])){
  2483. $where['b.Gy0_gdbh'] = ['like','%'.$param['search'].'%'];
  2484. }
  2485. $list = \db('工单_基本资料')
  2486. ->alias('a')
  2487. ->field('rtrim(Gd_gdbh) as gdbh,rtrim(成品名称) as cpmc')
  2488. ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh')
  2489. ->where($where)
  2490. ->select();
  2491. if (empty($list)){
  2492. $this->success('未找到相关工单');
  2493. }else{
  2494. $this->success('成功',$list);
  2495. }
  2496. }
  2497. /**
  2498. * 日产量上报工单印件资料
  2499. * @return void
  2500. * @throws \think\db\exception\DataNotFoundException
  2501. * @throws \think\db\exception\ModelNotFoundException
  2502. * @throws \think\exception\DbException
  2503. */
  2504. public function ChanliangPrintDetail()
  2505. {
  2506. if ($this->request->isGet() === false){
  2507. $this->error('请求错误');
  2508. }
  2509. $param = $this->request->param();
  2510. if (empty($param['gdbh'])){
  2511. $this->error('参数错误');
  2512. }
  2513. $where = [
  2514. 'Yj_Gdbh' => $param['gdbh']
  2515. ];
  2516. $list = \db('工单_印件资料')
  2517. ->where($where)
  2518. ->field('rtrim(yj_Yjno) as yjno,rtrim(yj_yjmc) as yjmc,rtrim(yj_ls) as ls')
  2519. ->select();
  2520. if (empty($list)){
  2521. $this->success('未找到印件资料');
  2522. }else{
  2523. $this->success('成功',$list);
  2524. }
  2525. }
  2526. /**
  2527. * 日产量上报工艺资料获取
  2528. * @return void
  2529. * @throws \think\db\exception\DataNotFoundException
  2530. * @throws \think\db\exception\ModelNotFoundException
  2531. * @throws \think\exception\DbException
  2532. */
  2533. public function ChanliangProcessDetail()
  2534. {
  2535. if ($this->request->isGet() === false){
  2536. $this->error('请求错误');
  2537. }
  2538. $param = $this->request->param();
  2539. if (empty($param['gdbh'])){
  2540. $this->error('参数错误');
  2541. }
  2542. // $sys_bh = \db('dic_lzde')->where('适用机型',$param['machine'])->value('sys_bh');
  2543. $list = \db('工单_工艺资料')
  2544. ->where('Gy0_gdbh',$param['gdbh'])
  2545. ->where('Gy0_yjno',$param['yjno'])
  2546. // ->where('Gy0_sbbh','like','%'.$param['machine'].'%')
  2547. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  2548. ->select();
  2549. if (empty($list)){
  2550. $this->success('未获取工序');
  2551. }
  2552. // $time = \db('设备_产量计酬')
  2553. // ->where('sczl_gdbh',$param['gdbh'])
  2554. // ->where('sczl_yjno',$param['yjno'])
  2555. // ->where('sczl_jtbh','like','%'.$param['machine'].'%')
  2556. // ->order('UniqId desc')
  2557. // ->value('sczl_sj2');
  2558. // $newTime = date('Y-m-d H:i:s');
  2559. // 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')){
  2560. // $time = date('Y-m-d 08:30:00');
  2561. // }elseif ($newTime > date('Y-m-d 20:30:00') && $time < date('Y-m-d 20:30:00')){
  2562. // $time = date('Y-m-d 20:30:00');
  2563. // }
  2564. foreach ($list as $key=>$value){
  2565. if ((int)$value['gxh'] < 10){
  2566. $value['gxh'] = '0'.$value['gxh'];
  2567. }
  2568. if (empty($value['add_gxmc'])){
  2569. $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'];
  2570. }else{
  2571. $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  2572. }
  2573. unset( $list[$key]['add_gxmc']);
  2574. // $list[$key]['time'] = $time;
  2575. }
  2576. // $list['sys_bh'] = $sys_bh;
  2577. $this->success('成功',$list);
  2578. }
  2579. /**
  2580. * 工价系数修改
  2581. * @return void
  2582. * @throws \think\Exception
  2583. * @throws \think\db\exception\BindParamException
  2584. * @throws \think\exception\PDOException
  2585. */
  2586. public function CoefficientEdit()
  2587. {
  2588. if (Request::instance()->isPost() === false){
  2589. $this->error('请求错误');
  2590. }
  2591. $params = Request::instance()->post();
  2592. if (empty($params['id'])){
  2593. $this->error('参数错误');
  2594. }
  2595. $idList = explode(',',$params['id']);
  2596. $i=0;
  2597. foreach ($idList as $key=>$value){
  2598. $sql = \db('设备_产量计酬')
  2599. ->where('UniqId',$value)
  2600. ->fetchSql(true)
  2601. ->update(['sczl_工价系数'=>$params['工价系数']]);
  2602. $res = \db()->query($sql);
  2603. if ($res === false){
  2604. $i++;
  2605. }
  2606. }
  2607. if ($i!==0){
  2608. $this->error('修改失败');
  2609. }else{
  2610. $this->success('修改成功');
  2611. }
  2612. }
  2613. /**
  2614. * 色度系数修改
  2615. * @return void
  2616. * @throws \think\Exception
  2617. * @throws \think\db\exception\BindParamException
  2618. * @throws \think\exception\PDOException
  2619. */
  2620. public function ChromaDataEdit()
  2621. {
  2622. if (Request::instance()->isPost() === false){
  2623. $this->error('请求错误');
  2624. }
  2625. $params = Request::instance()->post();
  2626. if (empty($params['id'])){
  2627. $this->error('参数错误');
  2628. }
  2629. $idList = explode(',',$params['id']);
  2630. $i=0;
  2631. foreach ($idList as $key=>$value){
  2632. $sql = \db('设备_产量计酬')
  2633. ->where('UniqId',$value)
  2634. ->fetchSql(true)
  2635. ->update(['sczl_ms'=>$params['ms']]);
  2636. $res = \db()->query($sql);
  2637. if ($res === false){
  2638. $i++;
  2639. }
  2640. }
  2641. if ($i!==0){
  2642. $this->error('修改失败');
  2643. }else{
  2644. $this->success('修改成功');
  2645. }
  2646. }
  2647. /**
  2648. * 凹印版距修改
  2649. * @return void
  2650. * @throws \think\Exception
  2651. * @throws \think\db\exception\BindParamException
  2652. * @throws \think\exception\PDOException
  2653. */
  2654. public function PrintingModeDataEdit()
  2655. {
  2656. if (Request::instance()->isPost() === false){
  2657. $this->error('请求错误');
  2658. }
  2659. $params = Request::instance()->post();
  2660. if (empty($params['id'])){
  2661. $this->error('参数错误');
  2662. }
  2663. $idList = explode(',',$params['id']);
  2664. //获取工单印件工序
  2665. $orderList = \db('设备_产量计酬')
  2666. ->where('UniqId',$idList[0])
  2667. ->field('rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as 印件号,rtrim(sczl_gxh) as 工序号')
  2668. ->find();
  2669. //修改工艺资料
  2670. $sql = \db('工单_工艺资料')
  2671. ->where([
  2672. 'Gy0_gdbh'=>$orderList['工单编号'],
  2673. 'Gy0_yjno'=>$orderList['印件号'],
  2674. 'Gy0_gxh'=>$orderList['工序号']
  2675. ])
  2676. ->fetchSql(true)
  2677. ->update(['版距'=>$params['plate'],'印刷方式'=>$params['mode']]);
  2678. $res = \db()->query($sql);
  2679. if ($res === false){
  2680. $this->error('修改失败');
  2681. }else{
  2682. $this->success('修改成功');
  2683. }
  2684. }
  2685. /**
  2686. * 废品率系数批量修改
  2687. * @return void
  2688. * @throws \think\Exception
  2689. * @throws \think\db\exception\BindParamException
  2690. * @throws \think\exception\PDOException
  2691. */
  2692. public function RejectionEdit()
  2693. {
  2694. if (Request::instance()->isPost() === false){
  2695. $this->error('请求错误');
  2696. }
  2697. $params = Request::instance()->post();
  2698. if (empty($params['id'])){
  2699. $this->error('参数错误');
  2700. }
  2701. $idList = explode(',',$params['id']);
  2702. $i=0;
  2703. foreach ($idList as $key=>$value){
  2704. $sql = \db('设备_产量计酬')
  2705. ->where('UniqId',$value)
  2706. ->fetchSql(true)
  2707. ->update(['sczl_废品率系数'=>$params['rejection']]);
  2708. $res = \db()->query($sql);
  2709. if ($res === false){
  2710. $i++;
  2711. }
  2712. }
  2713. if ($i!==0){
  2714. $this->error('修改失败');
  2715. }else{
  2716. $this->success('修改成功');
  2717. }
  2718. }
  2719. /**
  2720. * 日产量上报班组信息批量修改
  2721. * @return void
  2722. * @throws \think\Exception
  2723. * @throws \think\db\exception\BindParamException
  2724. * @throws \think\db\exception\DataNotFoundException
  2725. * @throws \think\db\exception\ModelNotFoundException
  2726. * @throws \think\exception\DbException
  2727. * @throws \think\exception\PDOException
  2728. */
  2729. public function YieldTeamEdit()
  2730. {
  2731. if ($this->request->isGet() === false){
  2732. $this->error('请求错误');
  2733. }
  2734. $param = $this->request->param();
  2735. if (empty($param['Uniqid']) || empty($param['teamID'])){
  2736. $this->error('参数错误');
  2737. }
  2738. $idList = explode(',',$param['Uniqid']);
  2739. $teamList = \db('设备_班组资料')->where('UniqId',$param['teamID'])->find();
  2740. $data = [];
  2741. for ($i=1;$i<11;$i++){
  2742. $data['sczl_bh'.$i] = $teamList['sczl_bh'.$i];
  2743. $data['sczl_rate'.$i] = $teamList['sczl_rate'.$i];
  2744. $data['sczl_bzdh'] = $teamList['sczl_bzdh'];
  2745. }
  2746. $j = 0;
  2747. foreach ($idList as $key => $value){
  2748. $sql = \db('设备_产量计酬')
  2749. ->where('UniqId',$value)
  2750. ->fetchSql(true)
  2751. ->update($data);
  2752. $res = \db()->query($sql);
  2753. if ($res === false){
  2754. $j++;
  2755. }
  2756. }
  2757. if ($j === 0){
  2758. $this->success('修改成功');
  2759. }else{
  2760. $this->error('修改失败');
  2761. }
  2762. }
  2763. /**
  2764. * 检品机日产量上报数据修改
  2765. * @return void
  2766. * @throws \think\Exception
  2767. * @throws \think\db\exception\BindParamException
  2768. * @throws \think\exception\PDOException
  2769. */
  2770. public function JpChanliangEdit()
  2771. {
  2772. if (Request::instance()->isPost() == false){
  2773. $this->error('非法请求');
  2774. }
  2775. $params = Request::instance()->post();
  2776. if (empty($params['UniqId'])){
  2777. $this->error('参数错误');
  2778. }
  2779. $params['mod_rq'] = date('Y-m-d H:i:s');
  2780. $data = $params;
  2781. unset($data['UniqId']);
  2782. $sql = \db('设备_产量计酬')->where('UniqId',$params['UniqId'])->fetchSql(true)->update($data);
  2783. $res = \db()->query($sql);
  2784. if ($res === false){
  2785. $this->error('修改失败');
  2786. }else{
  2787. $this->success('成功');
  2788. }
  2789. }
  2790. /**
  2791. * 检品机日产量上报数据列表
  2792. * @return void
  2793. * @throws \think\db\exception\DataNotFoundException
  2794. * @throws \think\db\exception\ModelNotFoundException
  2795. * @throws \think\exception\DbException
  2796. */
  2797. public function JPmachineDetail()
  2798. {
  2799. if ($this->request->isGet() === false){
  2800. $this->error('请求错误');
  2801. }
  2802. $machine = input('machine');
  2803. $date = input('date');
  2804. $where = [
  2805. 'sczl_jtbh' => $machine,
  2806. 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
  2807. ];
  2808. $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 计件箱数,
  2809. 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 通电工时,
  2810. 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,
  2811. 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,
  2812. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId,rtrim(sczl_工价系数) as 难度系数,rtrim(sczl_dedh) as 定额代号,sczl_rq,sczl_装版总工时 as 换膜总工时';
  2813. //机台信息
  2814. $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
  2815. //组员信息
  2816. $list = \db('设备_产量计酬')->where($where)->field($field)->select();
  2817. $totalA = \db('设备_产量计酬')
  2818. ->where($where)
  2819. ->where('sczl_bzdh','like','A%')
  2820. ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数,SUM(sczl_装版工时) as 总换膜补时,SUM(sczl_保养工时) as 总保养工时,SUM(sczl_异常停机工时) as 总异常总工时,SUM(sczl_设备运行工时) as 总通电工时')
  2821. ->group('检验类型')
  2822. ->select();
  2823. $totalB = \db('设备_产量计酬')
  2824. ->where($where)
  2825. ->where('sczl_bzdh','like','B%')
  2826. ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数,SUM(sczl_装版工时) as 总换膜补时,SUM(sczl_保养工时) as 总保养工时,SUM(sczl_异常停机工时) as 总异常总工时,SUM(sczl_设备运行工时) as 总通电工时')
  2827. ->group('检验类型')
  2828. ->select();
  2829. if (empty($list)){
  2830. $this->success('',[]);
  2831. }
  2832. foreach ($list as $key=>$value){
  2833. //产品名称
  2834. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$value['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  2835. if (!empty($productName)){
  2836. if (!empty($productName['成品名称'])){
  2837. $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['成品名称'];
  2838. $list[$key]['cpmc'] = $productName['成品名称'];
  2839. }else{
  2840. $list[$key]['产品名称'] = $value['工单编号'];
  2841. $list[$key]['cpmc'] = '';
  2842. }
  2843. }else{
  2844. $list[$key]['产品名称'] = $value['工单编号'];
  2845. $list[$key]['cpmc'] = '';
  2846. }
  2847. if (empty($value['定额代号'])){
  2848. $list[$key]['千件工价'] = '';
  2849. $list[$key]['日定额'] = '';
  2850. $list[$key]['补产标准'] = '';
  2851. }else{
  2852. $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
  2853. $list[$key]['千件工价'] = $row['千件工价'];
  2854. $list[$key]['日定额'] = $row['日定额'];
  2855. $list[$key]['补产标准'] = $row['补产标准'];
  2856. }
  2857. $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxh'].'-'.$list[$key]['gxmc'];
  2858. for ($i=1;$i<11;$i++){
  2859. if (isset($value['sczl_bh'.$i])){
  2860. $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('员工姓名 as name')->find();
  2861. if (isset($name['name'])){
  2862. $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
  2863. $list[$key]['sczl_name'.$i] = $name['name'];
  2864. }else{
  2865. $list[$key]['sczl_name'.$i] = '';
  2866. }
  2867. }
  2868. }
  2869. }
  2870. $list['totalA'] = $totalA;
  2871. $list['totalB'] = $totalB;
  2872. $this->success('成功',$list);
  2873. }
  2874. /**
  2875. * 检品机每日上报数据修改页面数据获取接口
  2876. * @return void
  2877. * @throws \think\db\exception\DataNotFoundException
  2878. * @throws \think\db\exception\ModelNotFoundException
  2879. * @throws \think\exception\DbException
  2880. */
  2881. public function JPchanliangDetailList()
  2882. {
  2883. if ($this->request->isGet() === false){
  2884. $this->error('请求错误');
  2885. }
  2886. $param = $this->request->param();
  2887. if (empty($param)){
  2888. $this->error('参数错误');
  2889. }
  2890. $list = \db('设备_产量计酬')
  2891. ->alias('a')
  2892. ->join('工单_基本资料 b','a.sczl_gdbh = b.Gd_gdbh AND a.sczl_yjno = b.行号')
  2893. ->field('rtrim(a.sczl_gdbh) as 工单编号,rtrim(a.sczl_dedh) as dedh,rtrim(a.sczl_yjno) as yjno,
  2894. rtrim(a.sczl_gxh) as gxh,rtrim(a.sczl_gxmc) as gxmc,rtrim(a.sczl_type) as 检验类型,rtrim(a.sczl_num) as num,
  2895. rtrim(a.sczl_cl) as 计件箱数,rtrim(a.sczl_Pgcl) as 每箱数量,rtrim(a.sczl_bzdh) as bzdh,
  2896. IF(a.sczl_废品率系数 = 0, "",a.sczl_废品率系数) as 废品率系数,IF(a.sczl_装版工时 = 0, "",a.sczl_装版工时) as 换膜补时,
  2897. IF(a.sczl_保养工时 = 0, "",a.sczl_保养工时) as 保养工时,IF(a.sczl_异常停机工时 = 0, "",a.sczl_异常停机工时) as 异常总工时,
  2898. IF(a.sczl_设备运行工时 = 0, "",a.sczl_设备运行工时) as 通电工时,rtrim(a.sys_id) as 用户,rtrim(a.mod_rq) as 更新时间,
  2899. IF(a.sczl_异常工时1 = 0, "",a.sczl_异常工时1) as 异常补时,IF(a.sczl_异常类型1 = 0, "",a.sczl_异常类型1) as 异常类型,
  2900. 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,
  2901. a.sczl_rate1,a.sczl_rate2,a.sczl_rate3,a.sczl_rate4,a.sczl_rate5,a.sczl_rate6,a.sczl_rate7,a.sczl_rate8,
  2902. a.sczl_rate9,a.sczl_rate10,a.sczl_bh98,rtrim(a.UniqId) as UniqId,rtrim(a.sczl_工价系数) as 难度系数,
  2903. rtrim(a.sczl_dedh) as 定额代号,a.sczl_rq,a.sczl_装版总工时 as 换膜总工时,rtrim(b.Gd_cpmc) as 产品名称,rtrim(b.成品名称) as 成品名称')
  2904. ->where('a.UniqId',$param['UniqId'])
  2905. ->find();
  2906. for ($i=1;$i<11;$i++){
  2907. if (isset($list['sczl_bh'.$i])){
  2908. $name = \db('人事_基本资料')->where('员工编号',$list['sczl_bh'.$i])->field('员工姓名 as name')->find();
  2909. if (isset($name['name'])){
  2910. $list['组员'.$i] = $list['sczl_bh'.$i].$name['name'].'('.((float)$list['sczl_rate'.$i]*100).'%'.')';
  2911. $list['sczl_name'.$i] = $name['name'];
  2912. }else{
  2913. $list['sczl_name'.$i] = '';
  2914. }
  2915. }
  2916. }
  2917. if (!empty($list)){
  2918. $this->success('成功',$list);
  2919. }else{
  2920. $this->error('未找到数据');
  2921. }
  2922. }
  2923. /**
  2924. * 拉纸工数据导出
  2925. * @return void
  2926. * @throws \think\db\exception\DataNotFoundException
  2927. * @throws \think\db\exception\ModelNotFoundException
  2928. * @throws \think\exception\DbException
  2929. */
  2930. public function LazhiGongData()
  2931. {
  2932. if ($this->request->isGet() === false){
  2933. $this->error('请求错误');
  2934. }
  2935. $param = $this->request->param();
  2936. if (empty($param['mouth'])){
  2937. $this->error('请选择月份');
  2938. }
  2939. $filed = [
  2940. 'a.sczl_gdbh' => '工单编号',
  2941. 'b.yj_yjmc' => '产品名称',
  2942. 'a.sczl_num' => '流程单号',
  2943. 'a.sczl_yjno' => '印件号',
  2944. 'a.sczl_gxh' => '工序号',
  2945. 'a.sczl_jtbh' => '机台编号',
  2946. 'a.sczl_rq' => '日期',
  2947. 'a.sczl_type' => '工序名称',
  2948. 'a.sczl_cl' => '产量',
  2949. 'a.sczl_bh1' => '机长工号',
  2950. 'c1.员工姓名' => '机长姓名',
  2951. 'a.sczl_bh2' => '组员工号1',
  2952. 'c2.员工姓名' => '组员姓名1',
  2953. 'a.sczl_bh3' => '组员工号2',
  2954. 'c3.员工姓名' => '组员姓名2',
  2955. 'a.sczl_bh98' => '拉料工工号',
  2956. 'c4.员工姓名' => '拉料工姓名'
  2957. ];
  2958. $list = \db('设备_产量计酬')
  2959. ->alias('a')
  2960. ->join('工单_印件资料 b','a.sczl_gdbh = b.Yj_Gdbh AND a.sczl_yjno = b.yj_Yjno')
  2961. ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
  2962. ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
  2963. ->join('人事_基本资料 c3','a.sczl_bh3 = c3.员工编号','left')
  2964. ->join('人事_基本资料 c4','a.sczl_bh98 = c4.员工编号','left')
  2965. ->field($filed)
  2966. ->where('a.sczl_rq','like',$param['mouth'].'%')
  2967. ->where('a.sczl_bh98','<>','')
  2968. ->order('a.sczl_rq,a.sczl_jtbh')
  2969. ->select();
  2970. if (!empty($list)){
  2971. $this->success('成功',$list);
  2972. }else{
  2973. $this->error('未找到相关数据');
  2974. }
  2975. }
  2976. }