Facility.php 160 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853
  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. $data = [];
  29. $date = date('Y-m-d 00:00:00',time()-3888000);
  30. $department = \db('设备_基本资料')
  31. ->distinct(true)
  32. ->where('使用部门','<>','研发中心')
  33. ->where('设备编组','<>','')
  34. ->where('sys_sbID','<>','')
  35. ->order('设备编组')
  36. ->column('rtrim(使用部门) as 使用部门');
  37. if (empty($department)){
  38. $this->success('为获取到机台数据');
  39. }
  40. $list = \db('设备_产量计酬')
  41. ->field([
  42. 'DISTINCT(sczl_rq)' => '时间',
  43. 'rtrim(sczl_jtbh)' => '机台编号'
  44. ])
  45. ->where('sczl_rq','>',$date)
  46. ->order('sczl_rq desc')
  47. ->select();
  48. if (empty($list)){
  49. $this->success('未找到机台生产记录');
  50. }
  51. foreach ($department as $value){
  52. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->order('设备编号')->select();
  53. foreach ($machine as $k=>$v){
  54. $data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']] = [];
  55. foreach ($list as $kk=>$vv){
  56. if ($v['设备编号'] === $vv['机台编号']){
  57. array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],date('Y-m-d',strtotime($vv['时间'])));
  58. }
  59. }
  60. }
  61. }
  62. $this->success('成功',$data);
  63. }
  64. /**
  65. * 机台每日产量
  66. * @ApiMethod (GET)
  67. * @param string $machine 机台编号
  68. * @param string $date 日期
  69. * @return void
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. * @throws \think\exception\DbException
  73. */
  74. public function chanLiang()
  75. {
  76. if ($this->request->isGet() === false){
  77. $this->error('请求错误');
  78. }
  79. $machine = input('machine');
  80. $date = input('date');
  81. $where = [
  82. 'sczl_jtbh' => $machine,
  83. 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
  84. ];
  85. $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_dedh) as dedh,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxh) as gxh,
  86. rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as num,rtrim(sczl_sj1) as sj1,
  87. rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,IF(sczl_zcfp = 0, "",sczl_zcfp) as 制程废品,
  88. IF(sczl_zccp = 0, "",sczl_zccp) as 制程次品,IF(sczl_前工序废 = 0, "",sczl_前工序废) as 前工序废,
  89. IF(sczl_来料少数 = 0, "",sczl_来料少数) as 来料异常,IF(sczl_装版总工时 = 0, "",sczl_装版总工时) as 装版总工时,
  90. IF(sczl_打样总工时 = 0, "",sczl_打样总工时) as 打样总工时,
  91. IF(sczl_装版工时 = 0, "",sczl_装版工时) as 装版工时, IF(sczl_保养工时 = 0, "",sczl_保养工时) as 保养工时,
  92. IF(sczl_打样工时 = 0, "",sczl_打样工时) as 打样工时,IF(sczl_异常停机工时 = 0, "",sczl_异常停机工时) as 异常总工时,
  93. IF(sczl_设备运行工时 = 0, "",sczl_设备运行工时) as 通电工时,
  94. IF(码开始行 = 0, "",码开始行) as 码开始行,IF(码结束行 = 0, "",码结束行) as 码结束行,
  95. IF(码包 = 0, "",码包) as 码包,IF(主电表 = 0, "",主电表) as 主电表,IF(辅电表 = 0, "",辅电表) as 辅电表,
  96. IF(sczl_ms = 0, "",sczl_ms) as 色度数,
  97. rtrim(sys_id) as 用户,rtrim(sys_rq) as 更新时间,IF(sczl_异常工时1 = 0, "",sczl_异常工时1) as 异常补时,
  98. IF(sczl_异常类型1 = 0, "",sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  99. sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,sczl_rate2,
  100. sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
  101. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId,rtrim(sczl_工价系数) as 难度系数,
  102. rtrim(sczl_dedh) as 定额代号';
  103. //机台信息
  104. $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
  105. //组员信息
  106. $list = \db('设备_产量计酬')->where($where)->field($field)->select();
  107. $totalA = \db('设备_产量计酬')
  108. ->where($where)
  109. ->where('sczl_bzdh','like','A%')
  110. ->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 前工序废')
  111. ->select();
  112. $totalB = \db('设备_产量计酬')
  113. ->where($where)
  114. ->where('sczl_bzdh','like','B%')
  115. ->field('SUM(sczl_cl) as 产量, SUM(sczl_zcfp) as 制程废品, SUM(sczl_zccp) as 制程次品, SUM(sczl_来料少数) as 来料异常, SUM(sczl_装版工时) as 装版工时, SUM(sczl_保养工时) as 保养工时, SUM(sczl_打样工时) as 打样工时,SUM(sczl_异常停机工时) as 异常工时,SUM(sczl_异常工时1) as 异常补时工时,SUM(sczl_设备运行工时) as 通电工时,SUM(sczl_前工序废) as 前工序废')
  116. ->select();
  117. if (empty($list)){
  118. $this->success('',[]);
  119. }
  120. foreach ($list as $key=>$value){
  121. //产品名称
  122. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$value['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  123. if (!empty($productName)){
  124. if (!empty($productName['成品名称'])){
  125. $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['成品名称'];
  126. $list[$key]['cpmc'] = $productName['成品名称'];
  127. }else{
  128. $list[$key]['产品名称'] = $value['工单编号'];
  129. $list[$key]['cpmc'] = '';
  130. }
  131. }else{
  132. $list[$key]['产品名称'] = $value['工单编号'];
  133. $list[$key]['cpmc'] = '';
  134. }
  135. $process = \db('工单_工艺资料')
  136. ->where('Gy0_gdbh',$value['工单编号'])
  137. ->where('Gy0_yjno',$value['yjno'])
  138. ->where('Gy0_gxh',$value['gxh'])
  139. ->field('rtrim(工价系数) as 工价系数,rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距')
  140. ->find();
  141. if (!empty($process)){
  142. if ($value['难度系数'] == 0){
  143. $list[$key]['难度系数'] = $process['工价系数'];
  144. }else{
  145. $list[$key]['难度系数'] = $process['工价系数'].'x'.$value['难度系数'];
  146. }
  147. $list[$key]['印刷方式'] = $process['印刷方式'].' '.$process['版距'];
  148. }else{
  149. $list[$key]['难度系数'] = '';
  150. $list[$key]['印刷方式'] = '';
  151. }
  152. if ($value['yjno']<10){
  153. $list[$key]['yjno'] = '0'.$value['yjno'];
  154. }
  155. if (empty($value['定额代号'])){
  156. $list[$key]['千件工价'] = '';
  157. $list[$key]['日定额'] = '';
  158. $list[$key]['补产标准'] = '';
  159. }else{
  160. $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
  161. $list[$key]['千件工价'] = $row['千件工价'];
  162. $list[$key]['日定额'] = $row['日定额'];
  163. $list[$key]['补产标准'] = $row['补产标准'];
  164. }
  165. $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
  166. $list[$key]['备注'] = $value['bzdh'].'('.$value['num'].')'.date('H:i',strtotime($value['sj1'])).'<-->'.date('H:i',strtotime($value['sj2']));
  167. for ($i=1;$i<11;$i++){
  168. if (isset($value['sczl_bh'.$i])){
  169. $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
  170. if (isset($name['name'])){
  171. $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
  172. }
  173. }
  174. unset($list[$key]['sczl_bh'.$i],$list[$key]['sczl_rate'.$i]);
  175. }
  176. $list[$key]['换版类型'] = $list[$key]['换版联拼数'] = '';
  177. if (!empty($value['装版总工时']) && $value['装版总工时'] !== 0){
  178. $pridata = \db('设备_装版工时')
  179. ->field('换版联拼数,换版类型')
  180. ->where('yieldUid',$value['UniqId'])
  181. ->order('Uniqid desc')
  182. ->find();
  183. if (!empty($pridata)){
  184. $list[$key]['换版类型'] = $pridata['换版类型'];
  185. $list[$key]['换版联拼数'] = $pridata['换版联拼数'];
  186. }
  187. }
  188. }
  189. $list['totalA'] = $totalA[0]['产量'];
  190. $list['totalB'] = $totalB[0]['产量'];
  191. $list['制程废品A'] = $totalA[0]['制程废品'];
  192. $list['制程废品B'] = $totalB[0]['制程废品'];
  193. $list['制程次品A'] = $totalA[0]['制程次品'];
  194. $list['制程次品B'] = $totalB[0]['制程次品'];
  195. $list['来料异常A'] = $totalA[0]['来料异常'];
  196. $list['来料异常B'] = $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. $this->success('成功',$list);
  212. }
  213. /**
  214. * 当日制程检验记录
  215. * @ApiMethod (GET)
  216. * @param string $machine 机台编号
  217. * @param string $date 日期
  218. * @return void
  219. * @throws \think\db\exception\DataNotFoundException
  220. * @throws \think\db\exception\ModelNotFoundException
  221. * @throws \think\exception\DbException
  222. */
  223. public function Inspect()
  224. {
  225. if ($this->request->isGet() === false){
  226. $this->error('请求错误');
  227. }
  228. $machine = input('machine');
  229. // 获取当前时间
  230. $current_time = time();
  231. // 设置时间范围
  232. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  233. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  234. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  235. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  236. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  237. // 判断当前时间属于哪个时间范围
  238. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  239. $startTime = date('Y-m-d') . ' 08:30:00';
  240. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  241. $startTime = date('Y-m-d') . ' 20:30:00';
  242. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  243. $startTime = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  244. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  245. $startTime = date('Y-m-d') . ' 20:30:00';
  246. }
  247. if (empty($machine)){
  248. $this->error('参数错误');
  249. }
  250. $where = [
  251. '设备编号' => $machine,
  252. '开工时间' => $startTime,
  253. '类别' => ['in',['IPQC检验','机台检验']],
  254. ];
  255. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,提交时间,rtrim(检验项目) as 检验项目';
  256. $list = \db('制程检验_记录')
  257. ->where($where)
  258. ->field($field)
  259. ->select();
  260. if (empty($list)){
  261. $this->success('未找到检验记录');
  262. }
  263. $data = [];
  264. foreach ($list as $key=>$value)
  265. {
  266. $data['item'][$key] = $value['检验项目'];
  267. $data['InspectionTime'][$key] = date('H:i',strtotime($value['提交时间']));
  268. $data['工单编号'][$key] = $value['工单编号'];
  269. }
  270. $data['item'] = array_unique($data['item']);
  271. $data['InspectionTime'] = array_values(array_unique($data['InspectionTime']));
  272. $data['工单编号'] = array_values(array_unique($data['工单编号']));
  273. foreach ($data['工单编号'] as $key => $value){
  274. foreach ($data['item'] as $k=>$v){
  275. $time = '';
  276. foreach ($list as $kk=>$vv){
  277. if ($vv['工单编号'] === $value && $vv['检验项目'] === $v){
  278. $time = $time.date('H:i',strtotime($vv['提交时间'])).',';
  279. $data['row'][$key][$k] = [
  280. '工单编号' => $value,
  281. '印件号' => $vv['印件号'],
  282. '工序名称' => $vv['工序名称'],
  283. '检验项目' => $v,
  284. 'time' => substr($time,0,-1),
  285. ];
  286. }
  287. }
  288. }
  289. $data['row'][$key] = array_values($data['row'][$key]);
  290. }
  291. unset($data['item'],$data['工单编号']);
  292. $this->success('成功',$data);
  293. }
  294. /**
  295. * 设备生产中工单信息
  296. * @ApiMethod (GET)
  297. * @param string $machine 机台编号
  298. * @return void
  299. * @throws \think\Exception
  300. * @throws \think\db\exception\DataNotFoundException
  301. * @throws \think\db\exception\ModelNotFoundException
  302. * @throws \think\exception\DbException
  303. */
  304. public function Production()
  305. {
  306. if (Request::instance()->isGet() == false) {
  307. $this->error('非法请求');
  308. }
  309. $params = Request::instance()->param();
  310. if (!isset($params['machine']) || empty($params['machine'])) {
  311. $this->error('参数错误');
  312. }
  313. $machine = $params['machine'];
  314. $machineCode = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
  315. $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  316. $list = [];
  317. $row = [];
  318. if (!empty($data['工单编号'])){
  319. $endTime = \db('工单_工艺资料')
  320. ->where('Gy0_gdbh',$data['工单编号'])
  321. ->where('Gy0_yjno',$data['印件号'])
  322. ->where('Gy0_gxh',$data['工序号'])
  323. ->find();
  324. $list['工单编号'] = $data['工单编号'];
  325. if (!empty($endTime)){
  326. $list['印件号'] = $data['印件号'];
  327. $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
  328. $code = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品代号');
  329. $list['产品名称'] = rtrim($name);
  330. $list['产品代号'] = rtrim($code);
  331. $list['工序名称'] = $data['工序名称'];
  332. }
  333. $list['状态'] = rtrim($data['当前状态']);
  334. $list['开工时间'] = $data['开工时间'];
  335. }else{
  336. $list['工单编号'] = '';
  337. $list['印件号'] = 0;
  338. $list['产品名称'] = '';
  339. $list['工序名称'] = '';
  340. $list['产品代号'] = '';
  341. $list['状态'] = '';
  342. $list['开工时间'] = '';
  343. }
  344. $list['班组编号'] = rtrim($data['班组编号']);
  345. $list['班组Id'] = rtrim($data['班组ID']);
  346. $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,
  347. 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,
  348. rtrim(sczl_bh10) as bh10")->find();
  349. if (!empty($class)){
  350. for ($i=1;$i<11;$i++) {
  351. if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
  352. $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
  353. $row[$i] = [
  354. '编号' => $class['bh' . $i],
  355. '姓名' => $name['姓名']
  356. ];
  357. }
  358. }
  359. $row = array_values($row);
  360. }
  361. $list['班组成员'] = $row;
  362. $list['定额代号'] = $machineCode;
  363. $this->success('成功',$list);
  364. }
  365. /**
  366. * 设备工作清单
  367. * @ApiMethod (GET)
  368. * @param string $machine 机台编号
  369. * @return void
  370. * @throws \think\db\exception\DataNotFoundException
  371. * @throws \think\db\exception\ModelNotFoundException
  372. * @throws \think\exception\DbException
  373. */
  374. public function EquipmentWorklist()
  375. {
  376. if ($this->request->isGet() === false){
  377. $this->error('请求错误');
  378. }
  379. $machine = input('machine');
  380. if (empty($machine)){
  381. $this->error('参数错误');
  382. }
  383. $orderList = \db('工单_工艺资料')
  384. ->alias('a')
  385. ->join('工单_基本资料 c','a.Gy0_gdbh = c.Gd_gdbh')
  386. ->join('工单_印件资料 d','a.Gy0_gdbh = d.Yj_Gdbh AND a.Gy0_yjno = d.yj_Yjno')
  387. ->field('a.Gy0_gdbh as gdbh,rtrim(a.质量要求) as 质量信息,a.Gy0_yjno as yjno,a.Gy0_gxh as gxh,a.Gy0_sbbh as sbbh,
  388. rtrim(a.Gy0_gxmc) as gxmc,rtrim(a.Add_gxmc) as add_gxmc,a.Gy0_辅助工时 as 装版工时,a.Gy0_小时产能 as 工序产能,a.Gy0_生产工时 as 计划工时,
  389. a.Gy0_sj1 as sj1,a.Gy0_sj2 as sj2,rtrim(a.工序备注) as 排产备注,d.yj_yjmc as 印件名称,c.成品名称 as 产品名称,c.成品代号 as 产品代号,
  390. a.Gy0_计划接货数 as 计划接货数,a.Gy0_ls as ls,a.Gy0_班次安排 as 班组,a.UniqId as UniqId,a.Gy0_最早开工时间 as 最早开工时间')
  391. ->where('a.Gy0_sbbh','like','%'.$machine.'%')
  392. ->where('a.PD_WG','1900-01-01 00:00:00')
  393. ->where('a.Gy0_sj1','<>','1900-01-01 00:00:00')
  394. ->where('c.gd_statu','2-生产中')
  395. ->group('a.Gy0_gdbh,a.Gy0_yjno,a.Gy0_gxh')
  396. ->order('a.Gy0_sj1')
  397. ->select();
  398. if (!empty($orderList)){
  399. $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  400. foreach ($orderList as $key=>$value){
  401. $machineList = explode(' ',$value['sbbh']);
  402. $cl_data = \db('设备_产量计酬')
  403. ->field('SUM(sczl_cl) as 已完成,SUM(sczl_zcfp) as 制程废品')
  404. ->where('sczl_gdbh',$value['gdbh'])
  405. ->where('sczl_yjno',$value['yjno'])
  406. ->where('sczl_gxh',$value['gxh'])
  407. ->select();
  408. $orderList[$key]['status'] = 0;
  409. if (!empty($data)){
  410. if ($value['gdbh'] === $data['工单编号'] && $value['yjno'] === $data['印件号'] && $value['gxh'] === $data['工序号']) {
  411. $orderList[$key]['status'] = 1;
  412. }
  413. }
  414. $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
  415. $orderList[$key]['印件号'] = $value['yjno'];
  416. $orderList[$key]['工序号'] = $value['gxh'];
  417. if ($value['yjno']<10){
  418. $orderList[$key]['yjno'] = '0'.$value['yjno'];
  419. }
  420. if ($value['gxh']<10){
  421. $orderList[$key]['gxh'] = '0'.$value['gxh'];
  422. }
  423. $orderList[$key]['印件资料'] = $orderList[$key]['yjno'].'-'.$value['印件名称'];
  424. $orderList[$key]['工序名称'] = $orderList[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  425. if ((int)$cl_data[0]['制程废品'] === 0){
  426. $orderList[$key]['计划产量/已完成'] = (int)$value['计划接货数'].'/'.$cl_data[0]['已完成']=null?'':(int)$cl_data[0]['已完成'];
  427. }else{
  428. $orderList[$key]['计划产量/已完成'] = (int)$value['计划接货数'].'/'.$cl_data[0]['已完成']=null?'':(int)$cl_data[0]['已完成'].'('.$cl_data[0]['制程废品'].')';
  429. }
  430. $orderList[$key]['计划生产时段'] =substr($value['sj1'],5,5).' '.substr($value['sj1'],11,5).'<-->'.substr($value['sj2'],5,5).' '.substr($value['sj2'],11,5);
  431. 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]['制程废品']);
  432. if (in_array($machine,$machineList) === false){
  433. unset($orderList[$key]);
  434. }
  435. }
  436. $data = array_values($orderList);
  437. $this->success('成功',$data);
  438. }else{
  439. $this->error('未找到数据');
  440. }
  441. }
  442. /**
  443. * 工序、印件、完成数量
  444. * @ApiMethod (GET)
  445. * @param string $workOrder 工单编号
  446. * @return void
  447. * @throws \think\Exception
  448. * @throws \think\db\exception\DataNotFoundException
  449. * @throws \think\db\exception\ModelNotFoundException
  450. * @throws \think\exception\DbException
  451. */
  452. public function Procedure()
  453. {
  454. if ($this->request->isGet() === false){
  455. $this->error('请求错误');
  456. }
  457. $workOrder = input('Gd_gdbh');
  458. $data = [];
  459. if (!empty($workOrder)){
  460. //右边工艺及完成数量
  461. $Process = \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  462. ->distinct(true)->order('sczl_gxh')
  463. ->column('sczl_gxh');
  464. foreach ($Process as $k=>$v){
  465. $res= \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
  466. ->where('sczl_gxh',$v)
  467. ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
  468. ->find();
  469. if ($res['sczl_yjno']<10){
  470. $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
  471. }
  472. $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
  473. $processList['completed'] = \db('设备_产量计酬')
  474. ->where('sczl_gdbh',$workOrder)
  475. ->where('sczl_gxh',$v)
  476. ->count('DISTINCT sczl_num');
  477. array_push($data,$processList);
  478. }
  479. }
  480. $this->success('成功',$data);
  481. }
  482. /**
  483. * 班组人员及分配比例
  484. * @ApiMethod (GET)
  485. * @param string $machine 机台编号
  486. * @return void
  487. * @throws \think\db\exception\DataNotFoundException
  488. * @throws \think\db\exception\ModelNotFoundException
  489. * @throws \think\exception\DbException
  490. */
  491. public function Team()
  492. {
  493. if ($this->request->isGet() === false){
  494. $this->error('请求错误');
  495. }
  496. $machine = input('machine');
  497. if (empty($machine)){
  498. $this->error('参数错误');
  499. }
  500. $where = [
  501. 'sczl_jtbh' => $machine,
  502. ];
  503. $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,
  504. 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,
  505. 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,
  506. rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,
  507. rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10,rtrim(UniqId) as ID';
  508. $team = \db('设备_产量计酬')
  509. ->where('sczl_jtbh',$machine)
  510. ->field($field)
  511. ->order('UniqId desc')
  512. ->find();
  513. $list = \db('设备_班组资料')->where($where)->field($field)->select();
  514. $data = [];
  515. foreach ($list as $k=>$v){
  516. if ($team == $v){
  517. $data[$k]['status'] = 1;
  518. }else{
  519. $data[$k]['status'] = 0;
  520. }
  521. $data[$k]['ID'] = $v['ID'];
  522. $data[$k]['班组号'] = $v['班组号'];
  523. for ($i=1;$i<11;$i++){
  524. if ($v['bh'.$i] != ''){
  525. $name = \db('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
  526. if ($v['rate'.$i] > 0){
  527. $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
  528. }else{
  529. $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' (0.00%'.')';
  530. }
  531. }
  532. }
  533. }
  534. $this->success('成功',$data);
  535. }
  536. /**
  537. * 当班产量明细
  538. * @ApiMethod (GET)
  539. * @param string $machine 机台编号
  540. * @param string $workOrder 工单编号
  541. * @param string $team 班次
  542. * @return void
  543. * @throws \think\db\exception\DataNotFoundException
  544. * @throws \think\db\exception\ModelNotFoundException
  545. * @throws \think\exception\DbException
  546. */
  547. public function OutputDetail()
  548. {
  549. if ($this->request->isGet() === false){
  550. $this->error('请求错误');
  551. }
  552. $machine = input('machine');
  553. $workOrder = input('Gd_gdbh');
  554. $team = substr(input('team'),0,1);
  555. if (empty($machine) || empty($team)){
  556. $this->success('');
  557. }
  558. $sczlTime = date('Y-m-d H:i:s',time());
  559. if ($sczlTime>date('Y-m-d 00:00:00') && $sczlTime<date('Y-m-d 08:30:00')){
  560. $time = date('Y-m-d 00:00:00',time()-86400);
  561. }else{
  562. $time = date('Y-m-d 00:00:00');
  563. }
  564. $where = [
  565. 'sczl_jtbh' => $machine,
  566. 'sczl_bzdh' => ['like',$team.'%'],
  567. 'sczl_rq' => $time,
  568. ];
  569. $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 产量,
  570. rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,rtrim(sczl_装版工时) as 装版工时,
  571. rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常停机工时,rtrim(sczl_设备运行工时) as 通电工时,
  572. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
  573. rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2,rtrim(UniqId) as UniqId,rtrim(sczl_bh98) as 拉料,rtrim(sczl_ls) as ls';
  574. $list = \db('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
  575. if (!empty($list)){
  576. foreach ($list as $k=>$v){
  577. $name = \db('工单_印件资料')->where('Yj_Gdbh',$v['工单编号'])->where('yj_Yjno',$v['yjno'])->field('rtrim(yj_yjmc) as cpmc')->find();
  578. if ($v['yjno']<10){
  579. $list[$k]['yjno'] = '0'.$v['yjno'];
  580. }
  581. if (!empty($v['拉料'])){
  582. $list[$k]['拉料姓名'] = \db('人事_基本资料')->where('员工编号',$v['拉料'])->value('rtrim(员工姓名) as 员工姓名');
  583. }
  584. if (isset($list[$k]['拉料姓名']) === false){
  585. $list[$k]['拉料姓名'] = '';
  586. }
  587. $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
  588. $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
  589. $list[$k]['产品名称'] = $name['cpmc'];
  590. }
  591. $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
  592. SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
  593. SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
  594. SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
  595. $total = \db('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
  596. $total[0]['版数'] = count($list);
  597. $list['total'] = $total[0];
  598. }
  599. $this->success('成功',$list);
  600. }
  601. /**
  602. * 检验记录
  603. * @ApiMethod (GET)
  604. * @param string $machine 机台编号
  605. * @param string $workOrder 工单编号
  606. * @param string $team 班次
  607. * @return void
  608. * @throws \think\db\exception\DataNotFoundException
  609. * @throws \think\db\exception\ModelNotFoundException
  610. * @throws \think\exception\DbException
  611. */
  612. public function InspectionRecord()
  613. {
  614. if ($this->request->isGet() === false){
  615. $this->error('请求失败');
  616. }
  617. $machine = input('machine');
  618. $workOrder = input('Gd_gdbh');
  619. $team = input('team');
  620. if (empty($machine) || empty($workOrder) || empty($team)){
  621. $this->success('');
  622. }
  623. $where = [
  624. '设备编号' => $machine,
  625. '工单编号' => $workOrder,
  626. '班组编号' => $team,
  627. '类别' => ['in',['IPQC检验','机台检验']],
  628. ];
  629. //检验项目筛选
  630. $item = \db('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
  631. //检验时间
  632. $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
  633. foreach ($InspectionTime as $k=>$v){
  634. $InspectionTime[$k] = date('H:i',strtotime($v));
  635. }
  636. //检测记录详情
  637. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
  638. $nameDetail = \db('制程检验_记录')->where($where)->field($field)->find();
  639. $data = [];
  640. //检测数据
  641. foreach ($item as $key=>$value){
  642. $SubmissionTime = \db('制程检验_记录')->where($where)
  643. ->where('检验项目',$value)
  644. ->where('检验结果','合格')
  645. ->field('rtrim(提交时间) as 提交时间')
  646. ->select();
  647. $time = [];
  648. foreach ($SubmissionTime as $k=>$v){
  649. $time[$k] = date('H:i',strtotime($v['提交时间']));
  650. }
  651. $data[$key] = [
  652. '工单编号' => $nameDetail['工单编号'],
  653. '印件号' => $nameDetail['印件号'],
  654. '工序名称' => $nameDetail['工序名称'],
  655. '检验项目' => $value,
  656. 'inspectresult' => implode(',',$time),
  657. ];
  658. }
  659. $data['inspectiontime'] = $InspectionTime;
  660. $this->success('成功',$data);
  661. }
  662. /**
  663. * 班组维护->班组添加
  664. * @ApiMethod (GET)
  665. * @param void
  666. * @return void
  667. * @throws \think\db\exception\DataNotFoundException
  668. * @throws \think\db\exception\ModelNotFoundException
  669. * @throws \think\exception\DbException
  670. */
  671. public function MachineTeamAdd()
  672. {
  673. if (Request::instance()->isPost() === false ){
  674. $this->error('请求错误');
  675. }
  676. $param = Request::instance()->post();
  677. if (empty($param)){
  678. $this->error('参数错误');
  679. }
  680. $lastId = \db('设备_班组资料')
  681. ->order('UniqId desc')
  682. ->value('UniqId');
  683. if (empty($lastId)){
  684. $lastId = 0;
  685. }
  686. for($i=1;$i<11;$i++){
  687. if (!empty($param['sczl_bh'.$i]) || $param['sczl_bh'.$i] != 0){
  688. $name = \db('人事_基本资料')->where('员工编号',$param['sczl_bh'.$i])->value('员工编号');
  689. if (empty($name)){
  690. $this->error('未找到编号'.$param['sczl_bh'.$i].'员工信息,无法添加,请输入正确的员工编号');
  691. }
  692. }
  693. }
  694. $operator = $this->facilityLogOperator($param);
  695. unset($param['sys_id'], $param['Sys_id']);
  696. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  697. $param['UniqId'] = $lastId + 1;
  698. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  699. $sql = \db('设备_班组资料')->fetchSql(true)->insert($param);
  700. $res = \db()->query($sql);
  701. if ($res !== false){
  702. $this->saveFacilityOperateLog([[
  703. '业务表' => '设备_班组资料',
  704. '操作类型' => '新增',
  705. '方法名' => 'MachineTeamAdd',
  706. 'RecordUniqid' => $param['UniqId'],
  707. '设备编号' => isset($param['sczl_jtbh']) ? $param['sczl_jtbh'] : '',
  708. '班组编号' => isset($param['sczl_bzdh']) ? $param['sczl_bzdh'] : '',
  709. '修改后' => $this->facilityTeamMemberText($param),
  710. 'sys_id' => $operator,
  711. ]]);
  712. $this->success('成功');
  713. }else{
  714. $this->error('失败');
  715. }
  716. }
  717. /**
  718. * 机台编号列表
  719. * @ApiMethod (GET)
  720. * @return void
  721. */
  722. public function MachineList()
  723. {
  724. if ($this->request->isGet() === false){
  725. $this->error('请求错误');
  726. }
  727. $list = \db('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  728. if (empty($list)){
  729. $this->success('未找到机台编号');
  730. }
  731. $data = [];
  732. foreach ($list as $key=>$value){
  733. $data[$key] = $value['设备编号'] . '||' . $value['设备名称'];
  734. }
  735. $this->success('成功',$data);
  736. }
  737. /**
  738. * 删除班组信息
  739. * @ApiMethod (GET)
  740. * @param void
  741. * @return void
  742. * @throws \think\Exception
  743. * @throws \think\exception\PDOException
  744. */
  745. public function teamDel()
  746. {
  747. if (Request::instance()->isPost() === false){
  748. $this->error('请求错误');
  749. }
  750. $param = Request::instance()->post();
  751. if (empty($param)){
  752. $this->error('参数错误');
  753. }
  754. $teamRow = \db('设备_班组资料')
  755. ->where('UniqId',$param['UniqId'])
  756. ->find();
  757. $machine = isset($teamRow['sczl_jtbh']) ? $teamRow['sczl_jtbh'] : '';
  758. $teamId = \db('设备_产量采集')
  759. ->where('设备编号',$machine)
  760. ->order('UniqId desc')
  761. ->value('班组ID');
  762. if ($teamId === (int)$param['UniqId']){
  763. $this->success('无法删除正在生产的班组资料,请先切换班组');
  764. }
  765. $res = \db('设备_班组资料')
  766. ->where('UniqId',$param['UniqId'])
  767. ->delete();
  768. if ($res !== false){
  769. if ($res && !empty($teamRow)) {
  770. $this->saveFacilityOperateLog([[
  771. '业务表' => '设备_班组资料',
  772. '操作类型' => '删除',
  773. '方法名' => 'teamDel',
  774. 'RecordUniqid' => $param['UniqId'],
  775. '设备编号' => $machine,
  776. '班组编号' => isset($teamRow['sczl_bzdh']) ? $teamRow['sczl_bzdh'] : '',
  777. '修改前' => $this->facilityTeamMemberText($teamRow),
  778. 'sys_id' => $this->facilityLogOperator($param),
  779. ]]);
  780. }
  781. $this->success('成功');
  782. }else{
  783. $this->error('失败');
  784. }
  785. }
  786. /**
  787. * 管理人员现场巡检记录->展示
  788. * @ApiMethod (GET)
  789. * @param void
  790. * @return void
  791. * @throws \think\db\exception\DataNotFoundException
  792. * @throws \think\db\exception\ModelNotFoundException
  793. * @throws \think\exception\DbException
  794. */
  795. public function FieldInspectionRecord()
  796. {
  797. if ($this->request->isGet() === false){
  798. $this->error('请求错误');
  799. }
  800. $param = $this->request->param();
  801. if (empty($param)){
  802. $this->error('参数错误');
  803. }
  804. // 获取当前时间
  805. $current_time = time();
  806. // 设置时间范围
  807. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  808. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  809. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  810. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  811. $start_time4 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 00:00:00');
  812. // 判断当前时间属于哪个时间范围
  813. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  814. $startTime = date('Y-m-d') . ' 08:30:00';
  815. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  816. $startTime = date('Y-m-d') . ' 20:30:00';
  817. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  818. $startTime = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
  819. }elseif ($current_time > $start_time4 && $current_time <= $start_time3){
  820. $startTime = date('Y-m-d') . ' 20:30:00';
  821. }
  822. $where = [
  823. '工单编号' => $param['workOrder'],
  824. '开工时间' => $startTime,
  825. '类别' => '现场巡查记录',
  826. '班组编号' => ['like',substr($param['team'],0,1).'%']
  827. ];
  828. $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
  829. rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
  830. rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
  831. $list = \db('制程检验_记录')->where($where)
  832. ->field($filed)
  833. ->select();
  834. if (empty($list)){
  835. $this->success('',[]);
  836. }
  837. foreach ($list as $key=>$value){
  838. $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
  839. $list[$key]['归属时段'] = $value['开工时间'];
  840. $list[$key]['分钟差数'] = $number;
  841. if ($number != 0){
  842. $list[$key]['归属时段'] = date('Y-m-d H:i:s',strtotime($value['开工时间'])+$number*15*60);
  843. }
  844. }
  845. $this->success('成功',$list);
  846. }
  847. /**
  848. * 管理人员现场巡检记录->添加
  849. * @ApiMethod (POST)
  850. * @param void
  851. * @return void
  852. */
  853. public function FieldInspectionRecordAdd()
  854. {
  855. if (Request::instance()->isPost() === false){
  856. $this->error('请求错误');
  857. }
  858. $param = Request::instance()->post();
  859. if (empty($param)){
  860. $this->error('参数错误');
  861. }
  862. if ($param['processCode']<10){
  863. $param['processCode'] = '0'.$param['processCode'];
  864. }
  865. $date = date('Y-m-d H:i:s',time());
  866. $startTime = date('Y-m-d 08:30:00',time());
  867. if ($date<$startTime){
  868. $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
  869. }
  870. $data = [
  871. '类别' => $param['category'],
  872. '工单编号' => $param['workOrder'],
  873. '印件号' => $param['printCode'],
  874. '工序名称' => $param['processCode'].'-'.$param['process'],
  875. '流程单号' => $param['flowCode'],
  876. '设备编号' => $param['machine'],
  877. '班组编号' => $param['team'],
  878. '检验项目' => '['.$param['employeeCode'].'/'.$param['employeeName'].']',
  879. '相关标准' => '',
  880. '量测仪器' => '',
  881. '检验结果' => '',
  882. '检验备注' => $param['remark'],
  883. '提交时间' => date('Y-m-d H:i:s',time()),
  884. '开工时间' => $startTime,
  885. 'sys_id' => '',
  886. 'sys_rq' => date('Y-m-d H:i:s',time()),
  887. 'mod_rq' => '0000-00-00 00:00:00',
  888. 'UniqId' => \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
  889. ];
  890. $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
  891. $res = Db::query($sql);
  892. if ($res !== false){
  893. $this->saveFacilityOperateLog([[
  894. '业务表' => '制程检验_记录',
  895. '操作类型' => '新增',
  896. '方法名' => 'FieldInspectionRecordAdd',
  897. 'RecordUniqid' => $data['UniqId'],
  898. '设备编号' => $data['设备编号'],
  899. '班组编号' => $data['班组编号'],
  900. '工单编号' => $data['工单编号'],
  901. '印件号' => $data['印件号'],
  902. '工序号' => $param['processCode'],
  903. '工序名称' => $data['工序名称'],
  904. '修改后' => '类别='.$data['类别'].';检验人='.$data['检验项目'].';备注='.$data['检验备注'],
  905. 'sys_id' => $this->facilityLogOperator($param),
  906. '备注' => '检验人='.$param['employeeCode'].'/'.$param['employeeName'],
  907. ]]);
  908. $this->success('成功');
  909. }else{
  910. $this->error('失败');
  911. }
  912. }
  913. /**
  914. * 设备点检->左侧菜单栏
  915. * @ApiMethod (GET)
  916. * @param void
  917. * @return void
  918. */
  919. public function SpotCheckItem()
  920. {
  921. if ($this->request->isGet() === false){
  922. $this->error('请求错误');
  923. }
  924. $param = $this->request->param();
  925. if (empty($param)){
  926. $this->error('参数错误');
  927. }
  928. $list = \db('设备_点检项目')
  929. ->where('适用机型','LIKE','%;'.$param['machine'].';%')
  930. ->distinct(true)
  931. ->column('部件名称','部件编号');
  932. if (empty($list)){
  933. $this->success('');
  934. }
  935. $this->success('成功',$list);
  936. }
  937. /**
  938. * 设备点检->检测项目
  939. * @ApiMethod (GET)
  940. * @param void
  941. * @return void
  942. * @throws \think\db\exception\DataNotFoundException
  943. * @throws \think\db\exception\ModelNotFoundException
  944. * @throws \think\exception\DbException
  945. */
  946. public function InspectionItem()
  947. {
  948. if ($this->request->isGet() === false){
  949. $this->error('请求错误');
  950. }
  951. $param = $this->request->param();
  952. if (empty($param)){
  953. $this->error('参数错误');
  954. }
  955. $list = \db('设备_点检项目')
  956. ->where('部件名称',$param['unitName'])
  957. ->where('适用机型','like','%'.$param['machine'].'#%')
  958. ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
  959. ->select();
  960. if (empty($list)){
  961. $this->success('未找到检测项目');
  962. }
  963. $this->success('成功',$list);
  964. }
  965. /**
  966. * 设备点检->检测记录添加
  967. * @ApiMethod (POST)
  968. * @param void
  969. * @return void
  970. * @throws \think\db\exception\DataNotFoundException
  971. * @throws \think\db\exception\ModelNotFoundException
  972. * @throws \think\exception\DbException
  973. */
  974. public function InspectionItemAdd()
  975. {
  976. if (!Request::instance()->isPost()) {
  977. $this->error('请求错误');
  978. }
  979. $param = Request::instance()->post();
  980. if (empty($param)) {
  981. $this->error('参数错误');
  982. }
  983. $row = [];
  984. foreach ($param as $value) {
  985. $unitCode = \db('设备_点检项目')
  986. ->where('部件名称', $value['unitName'])
  987. ->field('rtrim(部件编号) as 部件编号')
  988. ->find();
  989. $row[] = [
  990. '日期' => date('Y-m-d 00:00:00'),
  991. '班组编号' => $value['team'],
  992. '点检设备' => $value['machine'],
  993. '部件编号' => $unitCode['部件编号'] ?? '',
  994. '部件名称' => $value['unitName'],
  995. '检验项目' => $value['itemName'],
  996. '判定标准' => $value['standard'],
  997. '点检方法' => $value['method'],
  998. '点检结果' => $value['status'],
  999. '备注说明' => $value['remark'],
  1000. 'Sys_rq' => date('Y-m-d H:i:s')
  1001. ];
  1002. }
  1003. $res = \db('设备_点检记录')->insertAll($row);
  1004. if ($res !== false) {
  1005. $logs = [];
  1006. foreach ($row as $item) {
  1007. $logs[] = [
  1008. '业务表' => '设备_点检记录',
  1009. '操作类型' => '新增',
  1010. '方法名' => 'InspectionItemAdd',
  1011. '设备编号' => $item['点检设备'],
  1012. '班组编号' => $item['班组编号'],
  1013. '修改后' => '部件='.$item['部件名称'].';项目='.$item['检验项目'].';结果='.$item['点检结果'],
  1014. 'sys_id' => $this->facilityLogOperator($param),
  1015. '备注' => '本次提交'.count($row).'条',
  1016. ];
  1017. }
  1018. $this->saveFacilityOperateLog($logs);
  1019. $this->success('添加成功,添加了' . count($row) . '条记录');
  1020. } else {
  1021. $this->error('添加失败');
  1022. }
  1023. }
  1024. /**
  1025. * 机台印版领用->左侧菜单
  1026. * @ApiMethod (GET)
  1027. * @param void
  1028. * @return void
  1029. */
  1030. public function PrintGetTab()
  1031. {
  1032. if ($this->request->isGet() === false){
  1033. $this->error('请求错误');
  1034. }
  1035. $param = $this->request->param();
  1036. if (empty($param)){
  1037. $this->error('参数错误');
  1038. }
  1039. $productCode = $param['productCode'];
  1040. $sql = "SELECT DISTINCT(RTRIM(b.`名称`)) as `印版分类`,RTRIM(b.`编号`) as `编号` FROM `产品_印版资料` as a
  1041. JOIN `物料_存货结构` as b ON b.`编号` = SUBSTRING(a.`存货编码`,1,4)
  1042. WHERE a.YB_Cpdh = '{$productCode}'";
  1043. $res = Db::query($sql);
  1044. if (empty($res)){
  1045. $this->success('');
  1046. }
  1047. $this->success('成功',$res);
  1048. }
  1049. /**
  1050. * 机台印版领用记录->数据详情
  1051. * @ApiMethod (GET)
  1052. * @param void
  1053. * @return void
  1054. */
  1055. public function PrintDetail()
  1056. {
  1057. if (!$this->request->isGet()) {
  1058. $this->error('请求失败');
  1059. }
  1060. $param = $this->request->param();
  1061. if (empty($param)) {
  1062. $this->error('参数错误');
  1063. }
  1064. // 分页参数(带默认值)
  1065. $page = isset($param['page']) ? max(1, intval($param['page'])) : 1;
  1066. $limit = isset($param['limit']) ? min(max(1, intval($param['limit'])), 100) : 10;
  1067. $productCode = $param['productCode'];
  1068. $code = $param['code'] . '%';
  1069. $workOrder = $param['workOrder'];
  1070. // 1. 先查询总数
  1071. $countSql = "SELECT COUNT(*) AS total FROM (
  1072. SELECT
  1073. b.`供方批号`
  1074. FROM `产品_印版资料` a
  1075. JOIN `物料_存货编码` c ON c.`物料代码` = a.`存货编码`
  1076. JOIN `物料_存货结构` e ON e.`编号` = (
  1077. CASE
  1078. WHEN a.`存货编码` REGEXP '[A-Za-z]'
  1079. THEN SUBSTRING(a.`存货编码`, 1, 5)
  1080. ELSE SUBSTRING(a.`存货编码`, 1, 4)
  1081. END
  1082. )
  1083. JOIN `工单_基本资料` f ON a.YB_Cpdh = f.Gd_cpdh
  1084. LEFT JOIN `产品_印版库` b ON b.`存货编码` = a.`存货编码`
  1085. AND b.`报废日期` = '1900-01-01 00:00:00'
  1086. LEFT JOIN `工单_印版领用记录` d ON d.`Yb_供方批号` = b.`供方批号`
  1087. AND d.`Yb_工单编号` IS NOT NULL
  1088. WHERE
  1089. a.YB_Cpdh = '{$productCode}'
  1090. AND a.`存货编码` LIKE '{$code}'
  1091. AND f.Gd_gdbh = '{$workOrder}'
  1092. GROUP BY
  1093. a.`存货编码`,
  1094. b.`供方批号`
  1095. ) AS t";
  1096. $total = Db::query($countSql)[0]['total'] ?? 0;
  1097. // 2. 查询分页数据
  1098. $dataSql = "SELECT
  1099. RTRIM(a.`存货编码`) AS `存货编码`,
  1100. RTRIM(c.`物料名称`) AS `存货名称`,
  1101. RTRIM(b.`印版名称`) AS `印版名称`,
  1102. RTRIM(b.`供方批号`) AS `供方批号`,
  1103. RTRIM(b.`制造日期`) AS `制造日期`,
  1104. SUM(d.`Yb_印数`) AS `印数`,
  1105. RTRIM(e.`名称`) AS `印版类别`,
  1106. SUBSTRING(a.YB_Cpdh, 1, 4) AS `客户编号`,
  1107. RTRIM(f.`Gd_客户名称`) AS `客户名称`,
  1108. RTRIM(a.YB_Cpdh) AS `产品编号`,
  1109. RTRIM(f.Gd_cpmc) AS `产品名称`,
  1110. MAX(d.UniqID) AS UniqId,
  1111. MAX(CASE
  1112. WHEN d.`Yb_领用日期` IS NOT NULL AND d.`Yb_退还日期` IS NULL
  1113. THEN d.`Yb_工单编号`
  1114. ELSE NULL
  1115. END) AS `工单编号`
  1116. FROM `产品_印版资料` a
  1117. JOIN `物料_存货编码` c ON c.`物料代码` = a.`存货编码`
  1118. JOIN `物料_存货结构` e ON e.`编号` = (
  1119. CASE
  1120. WHEN a.`存货编码` REGEXP '[A-Za-z]'
  1121. THEN SUBSTRING(a.`存货编码`, 1, 5)
  1122. ELSE SUBSTRING(a.`存货编码`, 1, 4)
  1123. END
  1124. )
  1125. JOIN `工单_基本资料` f ON a.YB_Cpdh = f.Gd_cpdh
  1126. LEFT JOIN `产品_印版库` b ON b.`存货编码` = a.`存货编码`
  1127. AND b.`报废日期` = '1900-01-01 00:00:00'
  1128. LEFT JOIN `工单_印版领用记录` d ON d.`Yb_供方批号` = b.`供方批号`
  1129. AND d.`Yb_工单编号` IS NOT NULL
  1130. WHERE
  1131. a.YB_Cpdh = '{$productCode}'
  1132. AND a.`存货编码` LIKE '{$code}'
  1133. AND f.Gd_gdbh = '{$workOrder}'
  1134. GROUP BY
  1135. a.`存货编码`,
  1136. c.`物料名称`,
  1137. b.`印版名称`,
  1138. b.`供方批号`,
  1139. b.`制造日期`,
  1140. e.`名称`,
  1141. f.`Gd_客户名称`,
  1142. a.YB_Cpdh,
  1143. f.Gd_cpmc
  1144. ORDER BY a.`存货编码`
  1145. LIMIT " . ($page - 1) * $limit . ", " . $limit;
  1146. $list = Db::query($dataSql);
  1147. $this->success('成功', [
  1148. 'data' => $list ?: [],
  1149. 'total' => $total,
  1150. ]);
  1151. }
  1152. /**
  1153. * 换型清场->左侧菜单栏
  1154. * @ApiMethod (GET)
  1155. * @param void
  1156. * @return void
  1157. */
  1158. public function remodelGetTab()
  1159. {
  1160. if ($this->request->isGet() === false){
  1161. $this->error('请求错误');
  1162. }
  1163. $date = date('Y-m-d 00:00:00',time()-3456000);
  1164. $nowTime = date('Y-m-d H:i:s',time());
  1165. $list = \db('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
  1166. if (empty($list)){
  1167. $this->error('失败');
  1168. }
  1169. $sql = "SELECT RTRIM(a.`设备编号`) as `设备编号`,RTRIM(b.`日期`) as `日期`,RTRIM(b.UniqId) as UniqId
  1170. FROM `设备_基本资料` as a
  1171. LEFT JOIN `制程_换型清场` as b ON b.`机台编号` = a.`设备编号`
  1172. WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' AND b.`工单编号A` <> '' AND b.`工单编号B` <> '' ORDER BY b.`UniqId`";
  1173. $res = Db::query($sql);
  1174. $data = $result = [];
  1175. foreach ($list as $key=>$value){
  1176. $data[$value] = $result[$value]= $time = [];
  1177. foreach ($res as $k=>$v){
  1178. if ($value === $v['设备编号']){
  1179. $row = [
  1180. '日期' => $v['日期'],
  1181. 'id' => $v['UniqId']
  1182. ];
  1183. array_push($data[$value],$row);
  1184. }
  1185. }
  1186. foreach ($data[$value] as $m=>$n){
  1187. $time[$m] = $n['日期'];
  1188. }
  1189. $time = array_values(array_unique($time));
  1190. foreach ($time as $kk=>$vv){
  1191. $i=1;
  1192. foreach ($data[$value] as $kkk=>$vvv){
  1193. if ($kkk>=$kk && $vv === $vvv['日期']){
  1194. array_push($result[$value],date('Y-m-d',strtotime($vv)).'第'.$i.'次换型/'.$vvv['id']);
  1195. $i++;
  1196. }
  1197. }
  1198. }
  1199. }
  1200. $this->success('成功',$result);
  1201. }
  1202. /**
  1203. * 换型清场->详情
  1204. * @return void
  1205. * @throws \think\db\exception\DataNotFoundException
  1206. * @throws \think\db\exception\ModelNotFoundException
  1207. * @throws \think\exception\DbException
  1208. */
  1209. public function RemodelDetail()
  1210. {
  1211. if ($this->request->isGet() === false){
  1212. $this->error('请求错误');
  1213. }
  1214. $param = $this->request->param();
  1215. if (empty($param)){
  1216. $this->error('参数错误');
  1217. }
  1218. $field = 'rtrim(日期) as 日期,rtrim(班组) as 班组,rtrim(机台编号) as 机台编号,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1219. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包B,
  1220. rtrim(清场项目A) as 项目1,rtrim(清场项目B) as 项目2,rtrim(清场项目C) as 项目3,rtrim(清场项目D) as 项目4,rtrim(清场项目E) as 项目5,
  1221. rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
  1222. $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
  1223. if (empty($list)){
  1224. $this->success('未找到该条清场记录');
  1225. }
  1226. $list['日期'] = date('Y-m-d',strtotime($list['日期']));
  1227. $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find();
  1228. if (empty($printNameA)){
  1229. $list['印件名称A'] = '';
  1230. }else{
  1231. $list['印件名称A'] = $printNameA['yjmc'];
  1232. }
  1233. $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find();
  1234. if (empty($printNameB)){
  1235. $list['印件名称B'] = '';
  1236. }else{
  1237. $list['印件名称B'] = $printNameB['yjmc'];
  1238. }
  1239. $this->success('成功',$list);
  1240. }
  1241. /**
  1242. * 换型清场->根据机台获取设备_产量采集最新两个工单
  1243. * 返回工单编号、印件号、工序名称,以及关联工单_印件资料得到的印件名称(yj_yjmc)
  1244. * @ApiMethod (GET)
  1245. * @param string $machine 设备编号
  1246. * @return void
  1247. */
  1248. public function RemodelLastOrders()
  1249. {
  1250. if ($this->request->isGet() === false){
  1251. $this->error('请求错误');
  1252. }
  1253. $machine = rtrim(trim($this->request->param('machine')), '#');
  1254. if (empty($machine)){
  1255. $this->error('参数错误');
  1256. }
  1257. // 设备_产量采集中的设备编号有的带 # 后缀(如 JP01#),有的不带,统一兼容
  1258. $rows = \db('设备_产量采集')
  1259. ->where('设备编号', 'in', [$machine, $machine . '#'])
  1260. ->where('工单编号', '<>', '')
  1261. ->field('工单编号, 印件号, 工序名称, MAX(UniqId) AS latest')
  1262. ->group('工单编号, 印件号, 工序名称')
  1263. ->order('latest desc')
  1264. ->limit(2)
  1265. ->select();
  1266. $list = [];
  1267. foreach ($rows as $row) {
  1268. $gdbh = rtrim($row['工单编号']);
  1269. $yjno = rtrim($row['印件号']);
  1270. $printName = \db('工单_印件资料')
  1271. ->where('Yj_Gdbh', $gdbh)
  1272. ->where('yj_Yjno', $yjno)
  1273. ->value('yj_yjmc');
  1274. $list[] = [
  1275. '工单编号' => $gdbh,
  1276. '印件号' => $yjno,
  1277. '工序名称' => rtrim($row['工序名称']),
  1278. '印件名称' => $printName ? rtrim($printName) : '',
  1279. ];
  1280. }
  1281. $this->success('成功', $list);
  1282. }
  1283. /**
  1284. * 换型清场->当前设备清场记录
  1285. * @ApiMethod (GET)
  1286. * @param void
  1287. * @return void
  1288. * @throws \think\db\exception\DataNotFoundException
  1289. * @throws \think\db\exception\ModelNotFoundException
  1290. * @throws \think\exception\DbException
  1291. */
  1292. public function ModelChangeRecord()
  1293. {
  1294. if ($this->request->isGet() === false){
  1295. $this->error('请求错误');
  1296. }
  1297. $param = $this->request->param();
  1298. if (empty($param)){
  1299. $this->error('参数错误');
  1300. }
  1301. $date = date('Y-m-d 00:00:00',time()-3888000);
  1302. $nowTime = date('Y-m-d H:i:s',time());
  1303. $where = [
  1304. '日期' =>['between',[$date,$nowTime]],
  1305. '机台编号' => $param['machine'],
  1306. '工单编号A' => ['<>',''],
  1307. '工单编号B' => ['<>',''],
  1308. ];
  1309. $field = "rtrim(日期) as 日期,rtrim(机台编号) as 机台编号,rtrim(班组) as 班组,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
  1310. rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包号B,rtrim(清场项目A) as 清场项目A,
  1311. rtrim(清场项目B) as 清场项目B,rtrim(清场项目C) as 清场项目C,rtrim(清场项目D) as 清场项目D,rtrim(清场项目E) as 清场项目E,rtrim(机长) as 机长,
  1312. rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员,rtrim(sys_rq) as 创建时间,rtrim(UniqId) as UNIQID";
  1313. $list = \db('制程_换型清场')
  1314. ->where($where)
  1315. ->field($field)
  1316. ->select();
  1317. if (empty($list)){
  1318. $this->success('未找到换型记录');
  1319. }
  1320. foreach ($list as $key=>$value){
  1321. $printNameA = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号A'])->value('rtrim(yj_yjmc) as yjmc');
  1322. if (empty($printNameA)){
  1323. $list[$key]['印件名称A'] = '';
  1324. }else{
  1325. $list[$key]['印件名称A'] = $printNameA;
  1326. }
  1327. $printNameB = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号B'])->value('rtrim(yj_yjmc) as yjmc');
  1328. if (empty($printNameB)){
  1329. $list[$key]['印件名称B'] = '';
  1330. }else{
  1331. $list[$key]['印件名称B'] = $printNameB;
  1332. }
  1333. }
  1334. $this->success('成功',$list);
  1335. }
  1336. /**
  1337. * 车间机台状态列表展示
  1338. * @ApiMethod (GET)
  1339. * @param void
  1340. * @return void
  1341. * @throws \think\db\exception\BindParamException
  1342. * @throws \think\exception\PDOException
  1343. */
  1344. public function MachineDetailList()
  1345. {
  1346. if ($this->request->isGet() === false){
  1347. $this->error('请求错误');
  1348. }
  1349. $param = $this->request->param();
  1350. if (empty($param)){
  1351. $this->error('参数错误');
  1352. }
  1353. $workshop = $param['workshop'];
  1354. $sql = "SELECT
  1355. RTRIM( a.`设备编号` ) AS 设备编号,
  1356. RTRIM( a.`设备名称` ) AS 设备名称,
  1357. RTRIM( d.`当前状态` ) AS 状态
  1358. FROM
  1359. `设备_基本资料` AS a
  1360. JOIN (
  1361. SELECT
  1362. b.`设备编号`,
  1363. b.`当前状态`,
  1364. b.`开工时间`
  1365. FROM
  1366. `设备_产量采集` AS b
  1367. JOIN ( SELECT `设备编号`, MAX( `UniqId` ) AS `UniqId` FROM `设备_产量采集` GROUP BY `设备编号` ) AS c ON b.`设备编号` = c.`设备编号`
  1368. AND b.`UniqId` = c.`UniqId`
  1369. ) AS d ON a.`设备编号` = d.`设备编号`
  1370. WHERE
  1371. a.`使用部门` = '{$workshop}'
  1372. GROUP BY
  1373. a.`设备编号`
  1374. ORDER BY
  1375. a.UniqId";
  1376. $list = \db()->query($sql);
  1377. foreach ($list as $key=>$value){
  1378. if ($value['状态'] == ''){
  1379. $list[$key]['状态'] = '待单';
  1380. }
  1381. }
  1382. $this->success('成功',$list);
  1383. }
  1384. /**
  1385. * 机台当前参数展示
  1386. * @ApiMethod (GET)
  1387. * @return void
  1388. * @throws \think\db\exception\DataNotFoundException
  1389. * @throws \think\db\exception\ModelNotFoundException
  1390. * @throws \think\exception\DbException
  1391. */
  1392. public function MachineDetail()
  1393. {
  1394. if ($this->request->isGet() === false){
  1395. $this->error('请求错误');
  1396. }
  1397. $param = $this->request->param();
  1398. if (empty($param)){
  1399. $this->error('参数错误');
  1400. }
  1401. $data = [];
  1402. if ($param['start'] === ''){
  1403. 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())){
  1404. $param['start'] = date('Y-m-d 08:30:00',time());
  1405. }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())){
  1406. $param['start'] = date('Y-m-d 20:30:00',time());
  1407. }else{
  1408. $param['start'] = date('Y-m-d 20:30:00',time()-86400);
  1409. }
  1410. }
  1411. $machineDetail = \db('设备_产量采集')
  1412. ->alias('a')
  1413. ->join('设备_基本资料 b','a.设备编号 = b.设备编号')
  1414. ->join('工单_工艺资料 c', "a.工单编号 = c.Gy0_gdbh AND c.Gy0_sbbh LIKE CONCAT('%', a.设备编号, '%')")
  1415. ->join('工单_基本资料 d','a.工单编号 = d.Gd_gdbh')
  1416. ->field([
  1417. 'rtrim(a.开工时间)' => '开工时间',
  1418. 'rtrim(a.设备编号)' => '设备编号',
  1419. 'rtrim(a.工单编号)' => '工单编号',
  1420. 'rtrim(b.设备名称)' => '设备名称',
  1421. 'rtrim(c.Gy0_gxh)' => '工序号',
  1422. 'rtrim(c.Gy0_gxmc)' => '工序名称',
  1423. 'rtrim(d.Gd_cpmc)' => '产品名称'
  1424. ])
  1425. ->where('a.设备编号', $param['machine'])
  1426. ->order('a.UniqId desc')
  1427. ->find();
  1428. $data['machine'] = [
  1429. '日期' => $machineDetail['开工时间'],
  1430. '设备' => $machineDetail['设备编号'].'-->'.$machineDetail['设备名称'],
  1431. '工单' => $machineDetail['工单编号'].'-->'.$machineDetail['产品名称'],
  1432. '工艺' => ($machineDetail['工序号']<10?'0'.$machineDetail['工序号']:$machineDetail['工序号']).'--'.$machineDetail['工序名称']
  1433. ];
  1434. //机台状态时间
  1435. $startTime = \db('设备_产量采集')
  1436. ->where('设备编号',$param['machine'])
  1437. ->where('开工时间',$param['start'])
  1438. ->field('rtrim(时间) as 时间,当班产量,rtrim(当前状态) as 状态,MAX(时间) as 最大时间,MAX(当班产量) as 最大产量')
  1439. ->group('当前状态')
  1440. ->select();
  1441. if (!empty($startTime)){
  1442. foreach ($startTime as $key=>$value){
  1443. $data['timeDifference'][$key] = [
  1444. '时间' => round((strtotime($value['最大时间'])-strtotime($value['时间']))/3600,2),
  1445. '状态' => $value['状态'] = null?'待单':$value['状态'],
  1446. ];
  1447. if ($value['状态'] === '生产'){
  1448. $data['当班产量'] = $value['最大产量']-$value['当班产量'];
  1449. }
  1450. }
  1451. }else{
  1452. $data['timeDifference'][0] = [
  1453. '时间' => 0,
  1454. '状态' => '待单'
  1455. ];
  1456. $data['当班产量'] = 0;
  1457. }
  1458. //机台产能/时间明细
  1459. $row = \db('设备_产量采集')
  1460. ->where('设备编号',$param['machine'])
  1461. ->where('开工时间',$param['start'])
  1462. ->where('当班产量','<>',-1)
  1463. ->field('rtrim(时间) as 时间,rtrim(当班产量) as 产量,rtrim(当前状态) as 状态')
  1464. ->select();
  1465. $outputList = db('设备_产量计酬')
  1466. ->where('sczl_jtbh',$param['machine'])
  1467. ->where('开工时间',$param['start'])
  1468. ->field('sys_rq,sczl_cl')
  1469. ->select();
  1470. if (empty($outputList)){
  1471. $data['row'] = [];
  1472. }
  1473. foreach ($outputList as $key=>$value){
  1474. $data['row'][$key]['时间'] = date('Y-m-d H:i',strtotime($value['sys_rq']));
  1475. $data['row'][$key]['产能'] = $value['sczl_cl'];
  1476. }
  1477. //机台状态
  1478. $status = end($row);
  1479. if (empty($status['状态'])){
  1480. $data['status'] = '待单';
  1481. }else{
  1482. $data['status'] = $status['状态'];
  1483. }
  1484. //检验数据
  1485. $list = \db('制程检验_记录')
  1486. ->where('开工时间',$param['start'])
  1487. ->where('设备编号',$param['machine'])
  1488. ->where('sys_rq','>',$param['start'])
  1489. // ->where('工单编号',$machineDetail['工单编号'])
  1490. ->field('rtrim(类别) as 类别,提交时间')
  1491. ->select();
  1492. $data['首件'] = $data['自检'] = $data['IPQC'] = $data['现场巡查记录'] = [];
  1493. if (!empty($list)){
  1494. foreach ($list as $key=>$value){
  1495. if ($value['类别'] == '首件与过程确认'){
  1496. array_push($data['首件'],$value['提交时间']);
  1497. }
  1498. if ($value['类别'] == '机台检验'){
  1499. array_push($data['自检'],$value['提交时间']);
  1500. }
  1501. if ($value['类别'] == 'IPQC检验'){
  1502. array_push($data['IPQC'],$value['提交时间']);
  1503. }
  1504. if ($value['类别'] == '现场巡查记录'){
  1505. array_push($data['现场巡查记录'],$value['提交时间']);
  1506. }
  1507. }
  1508. $data['首件'] = array_values(array_unique($data['首件']));
  1509. $data['自检'] = array_values(array_unique($data['自检']));
  1510. $data['IPQC'] = array_values(array_unique($data['IPQC']));
  1511. $data['现场巡查记录'] = array_values(array_unique($data['现场巡查记录']));
  1512. }else{
  1513. $data['首件'] = [];
  1514. $data['自检'] = [];
  1515. $data['IPQC'] = [];
  1516. $data['现场巡查记录'] = [];
  1517. }
  1518. $this->success('成功',$data);
  1519. }
  1520. /**
  1521. * 制程检验记录->检验项目
  1522. * @ApiMethod (GET)
  1523. * @param void
  1524. * @return void
  1525. * @throws \think\db\exception\DataNotFoundException
  1526. * @throws \think\db\exception\ModelNotFoundException
  1527. * @throws \think\exception\DbException
  1528. */
  1529. public function ProcessInspectionRecordsItem()
  1530. {
  1531. if ($this->request->isGet() === false){
  1532. $this->error('请求错误');
  1533. }
  1534. $param = $this->request->param();
  1535. if (empty($param)){
  1536. $this->error('参数错误');
  1537. }
  1538. $list = \db('制程检验_项目')
  1539. ->where('工序','like','%'.$param['process'].'%')
  1540. ->select();
  1541. if (empty($list)){
  1542. $this->success('未找到检测项目');
  1543. }
  1544. $data = [];
  1545. foreach ($list as $key=>$value){
  1546. $data['首件']['指标检验'][$key] = [
  1547. '检验项目' => rtrim($value['检测项目']),
  1548. '检测方法' => rtrim($value['检测方法']),
  1549. '检验频率' => rtrim($value['首件签样要求']),
  1550. '相关标准' => rtrim($value['技术要求'])
  1551. ];
  1552. $data['机台检验']['指标检验'][$key] = [
  1553. '检验项目' => rtrim($value['检测项目']),
  1554. '检测方法' => rtrim($value['检测方法']),
  1555. '检验频率' => rtrim($value['机台自检频率']),
  1556. '相关标准' => rtrim($value['技术要求'])
  1557. ];
  1558. $data['IPQC']['指标检验'][$key] = [
  1559. '检验项目' => rtrim($value['检测项目']),
  1560. '检测方法' => rtrim($value['检测方法']),
  1561. '检验频率' => rtrim($value['IPQC检验频率']),
  1562. '相关标准' => rtrim($value['技术要求'])
  1563. ];
  1564. }
  1565. $row = \db('制程检验_项目附加')
  1566. ->where('工序','like','%'.$param['process'].'%')
  1567. ->select();
  1568. foreach ($row as $key=>$value){
  1569. $data['首件']['附加'][$key] = [
  1570. '缺陷备注' => rtrim($value['缺陷备注']),
  1571. '编号' => rtrim($value['编号'])
  1572. ];
  1573. $data['机台检验']['附加'][$key] = [
  1574. '缺陷备注' => rtrim($value['缺陷备注']),
  1575. '编号' => rtrim($value['编号'])
  1576. ];
  1577. $data['IPQC']['附加'][$key] = [
  1578. '缺陷备注' => rtrim($value['缺陷备注']),
  1579. '编号' => rtrim($value['编号'])
  1580. ];
  1581. }
  1582. $this->success('成功',$data);
  1583. }
  1584. /**
  1585. * 车间报工
  1586. * 制程检验记录->检测记录添加
  1587. */
  1588. public function ProcessInspectionRecordsItemAdd(){
  1589. if (Request::instance()->isPost() === false){
  1590. $this->error('请求错误');
  1591. }
  1592. $param = Request::instance()->post();
  1593. if (empty($param)){
  1594. $this->error('参数错误');
  1595. }
  1596. $startID = \db('制程检验_记录')->order('UniqId desc')->value('UniqId');
  1597. if (empty($startID)){
  1598. $startID = 0;
  1599. }
  1600. $process = \db('工单_工艺资料')
  1601. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1602. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1603. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1604. ->find();
  1605. $startTime = \db('设备_产量采集')
  1606. ->where('设备编号', 'like', '%' . $param[0]['machine'] . '#%')
  1607. ->where('工单编号', $param[0]['workOrder'])
  1608. ->order('UniqId desc')
  1609. ->find();
  1610. // 解决车间因未更换班组,导致开工时间仍为前一个班次,导致下一个班组进行上报时数据录到了前一个班次中的问题
  1611. if (!$startTime) {
  1612. $this->error('未找到对应的开工时间');
  1613. }
  1614. /*
  1615. * 系统提交时间(应报工时间)和开工时间
  1616. */
  1617. $rqTime = isset($param[0]['rq']) ? $param[0]['rq'] : date('Y-m-d H:i:s');
  1618. //转换为时间戳
  1619. $rqTimestamp = strtotime($rqTime);
  1620. $startTimestamp = strtotime($startTime['开工时间']);
  1621. // 计算时间差(秒)
  1622. $timeDiff = abs($rqTimestamp - $startTimestamp); // 取绝对值,防止负数
  1623. /*
  1624. * 计算时间差
  1625. */
  1626. // 转换时间差为 天、小时、分钟、秒
  1627. $days = floor($timeDiff / 86400);
  1628. $hours = floor(($timeDiff % 86400) / 3600);
  1629. $minutes = floor(($timeDiff % 3600) / 60);
  1630. $seconds = $timeDiff % 60;
  1631. // 格式化时间差
  1632. $formattedDiff = "";
  1633. if ($days > 0) $formattedDiff .= $days . "天";
  1634. if ($hours > 0) $formattedDiff .= $hours . "小时";
  1635. if ($minutes > 0) $formattedDiff .= $minutes . "分钟";
  1636. if ($seconds > 0) $formattedDiff .= $seconds . "秒";
  1637. // 判断是否超过 12 小时(12 * 3600 = 43200 秒)
  1638. if ($timeDiff > 43200) {
  1639. $this->error('请先更换班组后,再提交数据');
  1640. }
  1641. if ((int)$process['gxh']<10){
  1642. $process['gxh'] = '0'.$process['gxh'];
  1643. }
  1644. if ($process['add_gxmc'] !== ''){
  1645. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1646. }else{
  1647. $printName = $process['gxh'].'-'.$process['gxmc'];
  1648. }
  1649. if (empty($process)){
  1650. $this->success('数据错误');
  1651. }
  1652. $data = [];
  1653. foreach ($param as $key=>$value){
  1654. $data[$key] = [
  1655. '类别' => $value['category'],
  1656. '工单编号' => $value['workOrder'],
  1657. '印件号' => $value['yjno'],
  1658. '工序名称' => $printName,
  1659. '流程单号' => $value['flow'],
  1660. '设备编号' => $value['machine'].'#',
  1661. '班组编号' => $startTime['班组编号'],
  1662. '检验项目' => $value['item'],
  1663. '相关标准' => $value['standard'],
  1664. '量测仪器' => $value['instrument'],
  1665. '检验结果' => $value['selected'],
  1666. '检验备注' => $value['remark'],
  1667. '提交时间' => date('Y-m-d H:i:s',time()),
  1668. '开工时间' => rtrim($startTime['开工时间']),
  1669. 'sys_id' => '',
  1670. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1671. 'mod_rq' => '0000-00-00 00:00:00',
  1672. 'UniqId' => $startID + $key +1
  1673. ];
  1674. }
  1675. $res = \db('制程检验_记录')->insertAll($data);
  1676. if ($res !== false){
  1677. $operator = $this->facilityLogOperator(isset($param[0]) ? $param[0] : $param);
  1678. $logs = [];
  1679. foreach ($data as $item) {
  1680. $logs[] = [
  1681. '业务表' => '制程检验_记录',
  1682. '操作类型' => '新增',
  1683. '方法名' => 'ProcessInspectionRecordsItemAdd',
  1684. 'RecordUniqid' => $item['UniqId'],
  1685. '设备编号' => $item['设备编号'],
  1686. '班组编号' => $item['班组编号'],
  1687. '工单编号' => $item['工单编号'],
  1688. '印件号' => $item['印件号'],
  1689. '工序号' => $process['gxh'],
  1690. '工序名称' => $item['工序名称'],
  1691. '修改后' => '类别='.$item['类别'].';项目='.$item['检验项目'].';结果='.$item['检验结果'],
  1692. 'sys_id' => $operator,
  1693. '备注' => '本次提交'.count($data).'条',
  1694. ];
  1695. }
  1696. $this->saveFacilityOperateLog($logs);
  1697. $this->success('成功');
  1698. }else{
  1699. $this->error('失败');
  1700. }
  1701. }
  1702. /**
  1703. * 制程检验记录->附加检验记录添加
  1704. * @ApiMethod (POST)
  1705. * @param void
  1706. * @return void
  1707. * @throws \think\db\exception\DataNotFoundException
  1708. * @throws \think\db\exception\ModelNotFoundException
  1709. * @throws \think\exception\DbException
  1710. */
  1711. public function AdditionalInspectionRecordAdd()
  1712. {
  1713. if (Request::instance()->isPost() === false){
  1714. $this->error('请求错误');
  1715. }
  1716. $param = Request::instance()->post();
  1717. if (empty($param)){
  1718. $this->error('参数错误');
  1719. }
  1720. $startID = \db('制程检验_记录附加')->order('UniqId desc')->value('UniqId');
  1721. if (empty($startID)){
  1722. $startID = 0;
  1723. }
  1724. $process = \db('工单_工艺资料')
  1725. ->where('Gy0_gdbh',$param[0]['workOrder'])
  1726. ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
  1727. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  1728. ->find();
  1729. $startTime = \db('设备_产量采集')
  1730. ->where('设备编号','like','%'.$param[0]['machine'].'#%')
  1731. ->where('工单编号',$param[0]['workOrder'])
  1732. ->order('UniqId desc')
  1733. ->find();
  1734. if ((int)$process['gxh']<10){
  1735. $process['gxh'] = '0'.$process['gxh'];
  1736. }
  1737. if ($process['add_gxmc'] !== ''){
  1738. $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
  1739. }else{
  1740. $printName = $process['gxh'].'-'.$process['gxmc'];
  1741. }
  1742. if (empty($process)){
  1743. $this->success('数据错误');
  1744. }
  1745. $data = [];
  1746. foreach ($param as $key=>$value){
  1747. $data[$key] = [
  1748. '工单编号' => $value['workOrder'],
  1749. '印件号' => $value['yjno'],
  1750. '工序名称' => $printName,
  1751. '流程单号' => $value['flow'],
  1752. '设备编号' => $value['machine'],
  1753. '班组编号' => $startTime['班组编号'],
  1754. '缺陷备注' => $value['remark'],
  1755. '提交时间' => date('Y-m-d H:i:s',time()),
  1756. '开工时间' => rtrim($startTime['开工时间']),
  1757. 'sys_id' => '',
  1758. 'sys_rq' => date('Y-m-d H:i:s',time()),
  1759. 'mod_rq' => '0000-00-00 00:00:00',
  1760. 'UniqId' => $startID + $key +1
  1761. ];
  1762. }
  1763. $res = \db('制程检验_记录附加')->insertAll($data);
  1764. if ($res !== false){
  1765. $operator = $this->facilityLogOperator(isset($param[0]) ? $param[0] : $param);
  1766. $logs = [];
  1767. foreach ($data as $item) {
  1768. $logs[] = [
  1769. '业务表' => '制程检验_记录附加',
  1770. '操作类型' => '新增',
  1771. '方法名' => 'AdditionalInspectionRecordAdd',
  1772. 'RecordUniqid' => $item['UniqId'],
  1773. '设备编号' => $item['设备编号'],
  1774. '班组编号' => $item['班组编号'],
  1775. '工单编号' => $item['工单编号'],
  1776. '印件号' => $item['印件号'],
  1777. '工序号' => $process['gxh'],
  1778. '工序名称' => $item['工序名称'],
  1779. '修改后' => '缺陷备注='.$item['缺陷备注'],
  1780. 'sys_id' => $operator,
  1781. '备注' => '本次提交'.count($data).'条',
  1782. ];
  1783. }
  1784. $this->saveFacilityOperateLog($logs);
  1785. $this->success('成功');
  1786. }else{
  1787. $this->error('失败');
  1788. }
  1789. }
  1790. /**
  1791. * 客诉记录
  1792. * @ApiMethod (GET)
  1793. * @param void
  1794. * @return void
  1795. * @throws \think\db\exception\DataNotFoundException
  1796. * @throws \think\db\exception\ModelNotFoundException
  1797. * @throws \think\exception\DbException
  1798. */
  1799. public function ComplaintRecord()
  1800. {
  1801. if ($this->request->isGet() === false){
  1802. $this->error('请求错误');
  1803. }
  1804. $param = $this->request->param();
  1805. if (isset($param['productCode'])){
  1806. $where['产品编号'] = $param['productCode'];
  1807. }
  1808. $filed = "rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,rtrim(客诉日期) as 客诉日期,rtrim(客诉单号) as 客诉单号,
  1809. rtrim(客诉方式) as 客诉方式,rtrim(订单编号) as 订单编号,rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,
  1810. rtrim(客诉描述) as 客诉描述,rtrim(缺陷关键字) as 缺陷关键字,rtrim(客诉性质) as 客诉性质,rtrim(扣分) as 扣分,
  1811. rtrim(主要责任部门) as 主要责任部门,rtrim(次要责任部门) as 次要责任部门";
  1812. $list = \db('db_客诉记录')
  1813. ->where($where)
  1814. ->field($filed)
  1815. ->select();
  1816. if (empty($list)){
  1817. $this->success('未找到该产品客诉记录');
  1818. }
  1819. $this->success('成功',$list);
  1820. }
  1821. /**
  1822. * 设置机台班组信息
  1823. * @return void
  1824. * @throws \think\db\exception\DataNotFoundException
  1825. * @throws \think\db\exception\ModelNotFoundException
  1826. * @throws \think\exception\DbException
  1827. */
  1828. public function setMachineTeam()
  1829. {
  1830. if (Request::instance()->isPost() == false) {
  1831. $this->error('非法请求');
  1832. }
  1833. $params = Request::instance()->post();
  1834. if (!isset($params['machine']) || empty($params['machine'] )) {
  1835. $this->error('参数不能为空');
  1836. }
  1837. if (empty($params['team_id']) || empty($params['sczl_bzdh'])){
  1838. $this->error('请先选择班组成员');
  1839. }
  1840. $machine = $params['machine'] . '#';
  1841. $data = [];
  1842. $lastData = \db('设备_产量采集')
  1843. ->order('UniqId desc')
  1844. ->find();
  1845. $id = $lastData['UniqId']+1;
  1846. $data['当前状态'] = $params['status'];
  1847. $data['时间'] = date('Y-m-d H:i:s');
  1848. $data['设备编号'] = $machine;
  1849. $data['工单编号'] = empty($params['order']) ? '':$params['order'];
  1850. $data['印件号'] = empty($params['yjno']) ? '':$params['yjno'];
  1851. $data['工序号'] = empty($params['gy_name']) ? '' : (int)substr($params['gy_name'], 0, 2);
  1852. $data['工序名称'] = empty($params['gy_name']) ? '' : $params['gy_name'];
  1853. $data['当班产量'] = $params['production_now'];
  1854. $data['累计产量'] = $params['production_all'];
  1855. $data['班组编号'] = $params['sczl_bzdh'];
  1856. $data['班组ID'] = $params['team_id'];
  1857. // 获取当前时间
  1858. $current_time = time();
  1859. $today = date('Y-m-d');
  1860. $tomorrow = date('Y-m-d', strtotime('+1 day'));
  1861. $morning_start = strtotime("$today 08:30:00");
  1862. $evening_start = strtotime("$today 20:30:00");
  1863. $next_morning = strtotime("$tomorrow 08:30:00");
  1864. // 逻辑判断
  1865. if ($current_time < $morning_start) {
  1866. // 当天8:30之前,使用前一天的20:30
  1867. $data['开工时间'] = date('Y-m-d', strtotime('-1 day')) . ' 20:30:00';
  1868. } elseif ($current_time <= $evening_start) {
  1869. // 8:30-20:30之间,使用当天8:30
  1870. $data['开工时间'] = "$today 08:30:00";
  1871. } elseif ($current_time < $next_morning) {
  1872. // 20:30到次日8:30之间,使用当天20:30
  1873. $data['开工时间'] = "$today 20:30:00";
  1874. } else {
  1875. // 次日8:30之后,使用次日8:30
  1876. $data['开工时间'] = "$tomorrow 08:30:00";
  1877. }
  1878. if (!empty($params['order']) && !empty($params['yjno'])){
  1879. $option['Gy0_gdbh'] = $params['order'];
  1880. $option['Gy0_yjno'] = $params['yjno'];
  1881. $option['Gy0_gxh'] = $data['工序号'];
  1882. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  1883. }else{
  1884. $data['任务ID'] = '';
  1885. }
  1886. $data['UniqId'] = $id;
  1887. $sql = \db('设备_产量采集')->fetchSql(true)->insert($data);
  1888. $res = Db::query($sql);
  1889. if ($res === false) {
  1890. $this->error('设置失败');
  1891. } else {
  1892. $this->saveFacilityOperateLog([[
  1893. '业务表' => '设备_产量采集',
  1894. '操作类型' => '新增',
  1895. '方法名' => 'setMachineTeam',
  1896. 'RecordUniqid' => $data['UniqId'],
  1897. '设备编号' => $data['设备编号'],
  1898. '班组编号' => $data['班组编号'],
  1899. '工单编号' => $data['工单编号'],
  1900. '印件号' => $data['印件号'],
  1901. '工序号' => $data['工序号'],
  1902. '工序名称' => $data['工序名称'],
  1903. '修改后' => '状态='.$data['当前状态'].';当班产量='.$data['当班产量'].';累计产量='.$data['累计产量'].';开工时间='.$data['开工时间'],
  1904. 'sys_id' => $this->facilityLogOperator($params),
  1905. ]]);
  1906. $this->success('设置成功');
  1907. }
  1908. }
  1909. /**
  1910. * 首页数据
  1911. * @return void
  1912. * @throws \think\Exception
  1913. * @throws \think\db\exception\DataNotFoundException
  1914. * @throws \think\db\exception\ModelNotFoundException
  1915. * @throws \think\exception\DbException
  1916. */
  1917. public function index()
  1918. {
  1919. if ($this->request->isGet() === false){
  1920. $this->error('请求错误');
  1921. }
  1922. $nowTime = date('Y-m-d H:i:s',time());
  1923. $oldTime = (date('Y')-1).'-'.date('m-d H:i:s');
  1924. $where =[
  1925. 'Mod_rq' => ['between',[$oldTime,$nowTime]],
  1926. '行号' => '1'
  1927. ];
  1928. $data = [];
  1929. //按状态查询工单信息
  1930. $orderList = \db('工单_基本资料')
  1931. ->where($where)
  1932. ->field('count(Gd_gdbh) as 数量,rtrim(gd_statu) as 状态')
  1933. ->group('gd_statu')
  1934. ->select();
  1935. foreach ($orderList as $value){
  1936. if ($value['状态'] === '1-已完工'){
  1937. $data['workOrderData']['已完工'] = $value['数量'];
  1938. }
  1939. if ($value['状态'] === '3-计划中'){
  1940. $data['workOrderData']['计划中'] = $value['数量'];
  1941. }
  1942. }
  1943. $data['workOrderData']['排程中'] = db('工单_基本资料')->alias('a')
  1944. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  1945. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  1946. ->where([
  1947. 'a.gd_statu' => '2-生产中',
  1948. 'a.行号' => '1',
  1949. 'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
  1950. 'b.PD_WG' => '1900-01-01 00:00:00',
  1951. 'b.Gy0_sj1' => '1900-01-01 00:00:00',
  1952. 'c.状态' => '',
  1953. ])
  1954. ->group('a.Gd_gdbh')
  1955. ->count();
  1956. $data['workOrderData']['制程中'] = db('工单_基本资料')->alias('a')
  1957. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  1958. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  1959. ->where([
  1960. 'a.gd_statu' => '2-生产中',
  1961. 'a.行号' => '1',
  1962. 'a.Mod_rq' => ['between',[$oldTime,$nowTime]],
  1963. 'b.PD_WG' => '1900-01-01 00:00:00',
  1964. 'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'],
  1965. 'c.状态' => '',
  1966. ])
  1967. ->group('a.Gd_gdbh')
  1968. ->count();
  1969. //按月份查询工单信息
  1970. $data['monthData'] = \db('工单_基本资料')
  1971. ->where('Mod_rq', 'between', [$oldTime, $nowTime])
  1972. ->field('DATE_FORMAT(Mod_rq, "%Y-%m") as month, COUNT(*) as count')
  1973. ->group('month')
  1974. ->order('month')
  1975. ->select();
  1976. //查询最近十条客诉信息
  1977. $data['customer'] = \db('db_客诉记录')
  1978. ->field('rtrim(客诉描述) as 客诉描述,DATE_FORMAT(客诉日期, "%Y-%m-%d") as 日期,rtrim(UniqID) as UniqId')
  1979. ->limit(10)
  1980. ->order('Sys_rq desc')
  1981. ->select();
  1982. $this->success('成功',$data);
  1983. }
  1984. /**
  1985. * 员工信息获取
  1986. * @return void
  1987. * @throws \think\db\exception\DataNotFoundException
  1988. * @throws \think\db\exception\ModelNotFoundException
  1989. * @throws \think\exception\DbException
  1990. */
  1991. public function EmployeeData()
  1992. {
  1993. if ($this->request->isGet() === false){
  1994. $this->error('请求错误');
  1995. }
  1996. $param = $this->request->param();
  1997. if (isset($param['code']) === false){
  1998. $this->error('参数错误');
  1999. }
  2000. $res = \db('人事_基本资料')
  2001. ->where('员工编号','like',$param['code'].'%')
  2002. ->field('rtrim(员工编号) as 员工编号,rtrim(员工姓名) as 员工姓名')
  2003. ->select();
  2004. if (empty($res)){
  2005. $this->success('未找到该员工');
  2006. }
  2007. $this->success('成功',$res);
  2008. }
  2009. /**
  2010. * 换型清场添加
  2011. * @return void
  2012. * @throws \think\db\exception\BindParamException
  2013. * @throws \think\exception\PDOException
  2014. */
  2015. public function remodelDataAdd()
  2016. {
  2017. if (Request::instance()->isPost() === false){
  2018. $this->error('请求错误');
  2019. }
  2020. $param = Request::instance()->post();
  2021. if (empty($param)){
  2022. $this->error('参数错误');
  2023. }
  2024. $lastId = \db('制程_换型清场')->order('UniqId desc')->value('UniqId');
  2025. $operator = $this->facilityLogOperator($param);
  2026. $param['sys_id'] = '['.$param['机台编号'].']';
  2027. $param['sys_rq'] = date('Y-m-d H:i:s',time());
  2028. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  2029. $param['UniqId'] = $lastId + 1;
  2030. $sql = \db('制程_换型清场')->fetchSql(true)->insert($param);
  2031. $res = \db()->query($sql);
  2032. if ($res !== false){
  2033. $this->saveFacilityOperateLog([[
  2034. '业务表' => '制程_换型清场',
  2035. '操作类型' => '新增',
  2036. '方法名' => 'remodelDataAdd',
  2037. 'RecordUniqid' => $param['UniqId'],
  2038. '设备编号' => isset($param['机台编号']) ? $param['机台编号'] : '',
  2039. '班组编号' => isset($param['班组']) ? $param['班组'] : '',
  2040. '工单编号' => isset($param['工单编号A']) ? $param['工单编号A'] : '',
  2041. '工序名称' => isset($param['印件工序A']) ? $param['印件工序A'] : '',
  2042. '修改后' => '工单A='.(isset($param['工单编号A']) ? $param['工单编号A'] : '').';工单B='.(isset($param['工单编号B']) ? $param['工单编号B'] : '').';机长='.(isset($param['机长']) ? $param['机长'] : ''),
  2043. 'sys_id' => $operator,
  2044. '备注' => '业务表sys_id记为机台编号'.$param['sys_id'],
  2045. ]]);
  2046. $this->success('成功');
  2047. }else{
  2048. $this->error('失败');
  2049. }
  2050. }
  2051. /**
  2052. * 换型清场记录修改
  2053. * @return void
  2054. * @throws \think\Exception
  2055. * @throws \think\db\exception\BindParamException
  2056. * @throws \think\exception\PDOException
  2057. */
  2058. public function remodelDataEdit()
  2059. {
  2060. if (Request::instance()->isPost() === false){
  2061. $this->error('请求错误');
  2062. }
  2063. $param = Request::instance()->post();
  2064. if (empty($param)){
  2065. $this->error('参数错误');
  2066. }
  2067. $operator = $this->facilityLogOperator($param);
  2068. $uniqId = '';
  2069. if (isset($param['UniqId'])) {
  2070. $uniqId = $param['UniqId'];
  2071. } elseif (isset($param['UniqID'])) {
  2072. $uniqId = $param['UniqID'];
  2073. }
  2074. $before = [];
  2075. if ($uniqId !== '') {
  2076. $before = \db('制程_换型清场')->where('UniqId', $uniqId)->find();
  2077. if (empty($before)) {
  2078. $before = [];
  2079. }
  2080. }
  2081. $param['mod_rq'] = date('Y-m-d H:i:s',time());
  2082. $sql = \db('制程_换型清场')->fetchSql(true)->update($param);
  2083. $res = \db()->query($sql);
  2084. if ($res !== false){
  2085. $base = [
  2086. '业务表' => '制程_换型清场',
  2087. '操作类型' => '修改',
  2088. '方法名' => 'remodelDataEdit',
  2089. 'RecordUniqid' => $uniqId,
  2090. '设备编号' => isset($before['机台编号']) ? $before['机台编号'] : (isset($param['机台编号']) ? $param['机台编号'] : ''),
  2091. '班组编号' => isset($before['班组']) ? $before['班组'] : (isset($param['班组']) ? $param['班组'] : ''),
  2092. '工单编号' => isset($before['工单编号A']) ? $before['工单编号A'] : (isset($param['工单编号A']) ? $param['工单编号A'] : ''),
  2093. '工序名称' => isset($before['印件工序A']) ? $before['印件工序A'] : (isset($param['印件工序A']) ? $param['印件工序A'] : ''),
  2094. 'sys_id' => $operator,
  2095. ];
  2096. $this->saveFacilityOperateLog($this->facilityChangedLogs($base, $before, $param));
  2097. $this->success('成功');
  2098. }else{
  2099. $this->error('失败');
  2100. }
  2101. }
  2102. /**
  2103. * 换型清场记录删除
  2104. * @return void
  2105. * @throws \think\Exception
  2106. * @throws \think\exception\PDOException
  2107. */
  2108. public function remodelDataDel()
  2109. {
  2110. if ($this->request->isGet() === false){
  2111. $this->error('请求错误');
  2112. }
  2113. $param = $this->request->param();
  2114. if (empty($param)){
  2115. $this->error('参数错误');
  2116. }
  2117. $before = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->find();
  2118. $res = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->delete();
  2119. if ($res !== false){
  2120. if ($res && !empty($before)) {
  2121. $this->saveFacilityOperateLog([[
  2122. '业务表' => '制程_换型清场',
  2123. '操作类型' => '删除',
  2124. '方法名' => 'remodelDataDel',
  2125. 'RecordUniqid' => $param['UniqId'],
  2126. '设备编号' => isset($before['机台编号']) ? $before['机台编号'] : '',
  2127. '班组编号' => isset($before['班组']) ? $before['班组'] : '',
  2128. '工单编号' => isset($before['工单编号A']) ? $before['工单编号A'] : '',
  2129. '工序名称' => isset($before['印件工序A']) ? $before['印件工序A'] : '',
  2130. '修改前' => '工单A='.trim((string)$before['工单编号A']).';工单B='.trim((string)$before['工单编号B']).';机长='.trim((string)$before['机长']),
  2131. 'sys_id' => $this->facilityLogOperator($param),
  2132. ]]);
  2133. }
  2134. $this->success('删除成功');
  2135. }else{
  2136. $this->error('删除失败');
  2137. }
  2138. }
  2139. /**
  2140. * 印版领用记录添加
  2141. * @return void
  2142. * @throws \think\db\exception\BindParamException
  2143. * @throws \think\exception\PDOException
  2144. */
  2145. public function PrintDetailAdd()
  2146. {
  2147. if (Request::instance()->isPost() === false){
  2148. $this->error('请求错误');
  2149. }
  2150. $param = Request::instance()->post();
  2151. if (empty($param)){
  2152. $this->error('参数错误');
  2153. }
  2154. $lastId = \db('工单_印版领用记录')->order('UniqID desc')->value('UniqID');
  2155. foreach ($param as $key=>$value){
  2156. $param[$key]['Yb_领用日期'] = date('Y-m-d H:i:s',time());
  2157. $param[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  2158. $param[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  2159. }
  2160. $sql = \db('工单_印版领用记录')->fetchSql(true)->insertAll($param);
  2161. $res = \db()->query($sql);
  2162. if ($res !== false){
  2163. $logs = [];
  2164. foreach ($param as $item) {
  2165. if (!is_array($item)) {
  2166. continue;
  2167. }
  2168. $logs[] = [
  2169. '业务表' => '工单_印版领用记录',
  2170. '操作类型' => '新增',
  2171. '方法名' => 'PrintDetailAdd',
  2172. 'RecordUniqid' => isset($item['UniqID']) ? $item['UniqID'] : (isset($item['UniqId']) ? $item['UniqId'] : ''),
  2173. '工单编号' => isset($item['Yb_工单编号']) ? $item['Yb_工单编号'] : '',
  2174. '修改后' => '供方批号='.(isset($item['Yb_供方批号']) ? $item['Yb_供方批号'] : '').';领用日期='.$item['Yb_领用日期'],
  2175. 'sys_id' => $this->facilityLogOperator($item),
  2176. '备注' => '本次领用'.count($param).'条',
  2177. ];
  2178. }
  2179. $this->saveFacilityOperateLog($logs);
  2180. $this->success('添加成功');
  2181. }else{
  2182. $this->error('添加失败');
  2183. }
  2184. }
  2185. /**
  2186. * 印版领用记录退还
  2187. * @return void
  2188. * @throws \think\Exception
  2189. * @throws \think\db\exception\BindParamException
  2190. * @throws \think\exception\PDOException
  2191. */
  2192. public function PrintDetailEdit()
  2193. {
  2194. if ($this->request->isGet() === false){
  2195. $this->error('请求错误');
  2196. }
  2197. $param = $this->request->param();
  2198. if (empty($param) || !isset($param['id']) || !isset($param['number'])){
  2199. $this->error('参数错误');
  2200. }
  2201. $idList = explode(',',$param['id']);
  2202. $operator = $this->facilityLogOperator($param);
  2203. $i = 0;
  2204. $logs = [];
  2205. foreach ($idList as $key=>$value){
  2206. $before = \db('工单_印版领用记录')->where('UniqID',$value)->find();
  2207. if (empty($before)) {
  2208. $before = [];
  2209. }
  2210. $data['Yb_退还日期'] = date('Y-m-d H:i:s',time());
  2211. $data['Mod_rq'] = date('Y-m-d H:i:s',time());
  2212. $data['Yb_印数'] = $param['number'];
  2213. $sql = \db('工单_印版领用记录')->where('UniqID',$value)->fetchSql(true)->update($data);
  2214. $res = \db()->query($sql);
  2215. if ($res === false){
  2216. $i++;
  2217. } else {
  2218. $base = [
  2219. '业务表' => '工单_印版领用记录',
  2220. '操作类型' => '修改',
  2221. '方法名' => 'PrintDetailEdit',
  2222. 'RecordUniqid' => $value,
  2223. '工单编号' => isset($before['Yb_工单编号']) ? $before['Yb_工单编号'] : '',
  2224. 'sys_id' => $operator,
  2225. '备注' => '印版退还',
  2226. ];
  2227. $logs = array_merge($logs, $this->facilityChangedLogs($base, $before, $data));
  2228. }
  2229. }
  2230. $this->saveFacilityOperateLog($logs);
  2231. if ($i !== 0){
  2232. $this->error('退还失败');
  2233. }else{
  2234. $this->success('退还成功');
  2235. }
  2236. }
  2237. /**
  2238. * 当班产量明细修改
  2239. * @return void
  2240. * @throws \think\Exception
  2241. * @throws \think\db\exception\BindParamException
  2242. * @throws \think\exception\PDOException
  2243. */
  2244. public function chanliangEdit()
  2245. {
  2246. // 使用更简洁的请求判断方式
  2247. if (!Request::instance()->isPost()) {
  2248. $this->error('请使用POST请求');
  2249. }
  2250. // 获取并过滤POST参数
  2251. $param = Request::instance()->post();
  2252. // 更严格的参数验证
  2253. if (empty($param['UniqId'])) {
  2254. $this->error('缺少必要参数: UniqId');
  2255. }
  2256. // 整理更新数据
  2257. $updateData = [
  2258. 'mod_rq' => date('Y-m-d H:i:s')
  2259. ];
  2260. // 合并其他参数(排除不需要的字段)
  2261. $excludeFields = ['UniqId', 'sczl_rq', 'sczl_装版总工时', 'sczl_换版联拼数', '换版类型'];
  2262. foreach ($param as $key => $value) {
  2263. if (!in_array($key, $excludeFields)) {
  2264. $updateData[$key] = $value;
  2265. }
  2266. }
  2267. $uniqId = $param['UniqId'];
  2268. $operator = $this->facilityLogOperator($param);
  2269. $beforeYield = \db('设备_产量计酬')->where('UniqId', $uniqId)->find();
  2270. $beforePlate = \db('设备_装版工时')->where('yieldUid', $uniqId)->order('Uniqid desc')->find();
  2271. if (empty($beforeYield)) {
  2272. $beforeYield = [];
  2273. }
  2274. if (empty($beforePlate)) {
  2275. $beforePlate = [];
  2276. }
  2277. $success = false;
  2278. $plateData = [];
  2279. try {
  2280. // 处理装版工时数据(如果存在)
  2281. if (!empty($param['sczl_装版总工时']) && $param['sczl_装版总工时'] != 0) {
  2282. $priData = [
  2283. '换版总工时' => $param['sczl_装版总工时'],
  2284. '换版联拼数' => $param['sczl_换版联拼数'] ?? 0,
  2285. '换版类型' => $param['换版类型'] ?? '',
  2286. '装版补产工时' => $param['sczl_装版工时'] ?? ''
  2287. ];
  2288. $plateData = $priData;
  2289. $priSql = \db('设备_装版工时')->where('yieldUid', $uniqId)->fetchSql(true)->update($priData);
  2290. \db()->query($priSql);
  2291. }
  2292. // 更新产量计酬数据
  2293. $rowSql = \db('设备_产量计酬')->where('UniqId', $uniqId)->fetchSql(true)->update($updateData);
  2294. $rowCount = \db()->query($rowSql);
  2295. $success = $rowCount !== false;
  2296. } catch (\Exception $e) {
  2297. // 记录错误日志
  2298. \think\Log::error('修改产量详情失败: ' . $e->getMessage() . ' 堆栈: ' . $e->getTraceAsString());
  2299. $this->error('操作失败: ' . $e->getMessage());
  2300. }
  2301. if ($success) {
  2302. $logs = $this->facilityChangedLogs($this->facilityYieldLogBase($beforeYield, '修改', 'chanliangEdit', $operator), $beforeYield, $updateData);
  2303. if (!empty($plateData)) {
  2304. $plateBase = $this->facilityYieldLogBase($beforeYield, '修改', 'chanliangEdit', $operator);
  2305. $plateBase['业务表'] = '设备_装版工时';
  2306. $plateBase['RecordUniqid'] = $uniqId;
  2307. $logs = array_merge($logs, $this->facilityChangedLogs($plateBase, $beforePlate, $plateData));
  2308. }
  2309. $this->saveFacilityOperateLog($logs);
  2310. $this->success('修改成功');
  2311. } else {
  2312. $this->error('修改失败,未更新任何数据');
  2313. }
  2314. }
  2315. /**
  2316. * 获取当日上报产量详细数据
  2317. * @return void
  2318. * @throws \think\db\exception\DataNotFoundException
  2319. * @throws \think\db\exception\ModelNotFoundException
  2320. * @throws \think\exception\DbException
  2321. */
  2322. public function MachineChanliangDetail()
  2323. {
  2324. if ($this->request->isGet() === false){
  2325. $this->error('请求错误');
  2326. }
  2327. $param = $this->request->param();
  2328. if (empty($param['UniqId'])){
  2329. $this->error('参数错误');
  2330. }
  2331. $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 联数,
  2332. rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,rtrim(sczl_zcfp) as 制程废品,
  2333. rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,
  2334. rtrim(sczl_装版总工时) as 装版总工时,rtrim(sczl_打样总工时) as 打样总工时,
  2335. rtrim(sczl_装版工时) as 装版工时,rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,
  2336. rtrim(sczl_异常停机工时) as 异常总工时,rtrim(sczl_设备运行工时) as 通电工时,
  2337. rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,
  2338. rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度数,
  2339. rtrim(sczl_异常工时1) as 异常补时,rtrim(sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
  2340. rtrim(sczl_装版工时) as 装版补产工时,rtrim(sczl_打样工时) as 打样补产工时,rtrim(开工时间) as 开工时间,
  2341. sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,
  2342. sczl_rate2,sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
  2343. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId';
  2344. $list = \db('设备_产量计酬')->where('UniqId',$param['UniqId'])->field($field)->find();
  2345. $pridata = \db('设备_装版工时')
  2346. ->field('换版联拼数,换版类型,Uniqid,coefficient')
  2347. ->where('yieldUid',$param['UniqId'])
  2348. ->order('Uniqid desc')
  2349. ->find();
  2350. if (empty($list)){
  2351. $this->success('未找到产量详情信息');
  2352. }
  2353. $list['换版联拼数'] = '';
  2354. $list['换版类型'] = '';
  2355. $list['Uid'] = '';
  2356. $list['系数'] = '';
  2357. if (!empty($pridata)){
  2358. $list['换版联拼数'] = $pridata['换版联拼数'];
  2359. $list['换版类型'] = $pridata['换版类型'];
  2360. $list['Uid'] = $pridata['Uniqid'];
  2361. $list['系数'] = $pridata['coefficient'];
  2362. }
  2363. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$list['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  2364. $list['印件名称'] = $productName['cpmc'];
  2365. if (!empty($productName['成品名称'])){
  2366. $list['cpmc'] = $productName['成品名称'];
  2367. }elseif (empty($productName['成品名称']) && !empty($productName['cpmc'])){
  2368. $list['cpmc'] = $productName['cpmc'];
  2369. }else{
  2370. $list['cpmc'] = '';
  2371. }
  2372. for ($i=1;$i<11;$i++){
  2373. if (isset($list['sczl_bh'.$i])){
  2374. $name = \db('人事_基本资料')->where('员工编号',$list['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
  2375. if (isset($name['name'])){
  2376. $list['组员'.$i] = [
  2377. '编号' => $list['sczl_bh'.$i],
  2378. '姓名' => $name['name'],
  2379. '比例' => (float)$list['sczl_rate'.$i]
  2380. ];
  2381. }
  2382. }
  2383. if (empty($list['sczl_bh'.$i])){
  2384. $list['组员'.$i] = [
  2385. '编号' => '',
  2386. '姓名' => '',
  2387. '比例' => ''
  2388. ];
  2389. }
  2390. unset($list['sczl_bh'.$i],$list['sczl_rate'.$i]);
  2391. }
  2392. $list['拉料'] = [
  2393. '编号' => $list['sczl_bh98'],
  2394. '姓名' => \db('人事_基本资料')->where('员工编号',$list['sczl_bh98'])->value('rtrim(员工姓名)')
  2395. ];
  2396. unset($list['sczl_bh98']);
  2397. $this->success('成功',$list);
  2398. }
  2399. /**
  2400. * 当日上报产量详细数据修改
  2401. * @return void
  2402. * @throws \think\Exception
  2403. * @throws \think\db\exception\BindParamException
  2404. * @throws \think\exception\PDOException
  2405. */
  2406. public function MachineChanliangDetailEdit()
  2407. {
  2408. // 使用更简洁的请求判断方式
  2409. if (!Request::instance()->isPost()) {
  2410. $this->error('请使用POST请求');
  2411. }
  2412. // 获取并过滤POST参数
  2413. $param = Request::instance()->post();
  2414. // 更严格的参数验证
  2415. if (empty($param['UniqId'])) {
  2416. $this->error('缺少必要参数: UniqId');
  2417. }
  2418. // 整理更新数据
  2419. $updateData = [
  2420. 'sczl_type' => $param['sczl_gxmc'] ?? '',
  2421. 'mod_rq' => date('Y-m-d H:i:s')
  2422. ];
  2423. // 合并其他参数(排除不需要的字段)
  2424. $excludeFields = ['UniqId', 'sczl_rq', 'sczl_换版联拼数', '换版类型'];
  2425. foreach ($param as $key => $value) {
  2426. if (!in_array($key, $excludeFields)) {
  2427. $updateData[$key] = $value;
  2428. }
  2429. }
  2430. $uniqId = $param['UniqId'];
  2431. $operator = $this->facilityLogOperator($param);
  2432. $beforeYield = \db('设备_产量计酬')->where('UniqId', $uniqId)->find();
  2433. $beforePlate = \db('设备_装版工时')->where('yieldUid', $uniqId)->order('Uniqid desc')->find();
  2434. if (empty($beforeYield)) {
  2435. $beforeYield = [];
  2436. }
  2437. if (empty($beforePlate)) {
  2438. $beforePlate = [];
  2439. }
  2440. $success = false;
  2441. $plateData = [];
  2442. try {
  2443. // 处理装版工时数据(如果存在)
  2444. if (!empty($param['sczl_装版总工时']) && $param['sczl_装版总工时'] != 0) {
  2445. $priData = [
  2446. 'gdbh' => $param['sczl_gdbh'] ?? '',
  2447. 'yjno' => $param['sczl_yjno'] ?? '',
  2448. 'gxh' => $param['sczl_gxh'] ?? '',
  2449. 'jtbh' => $param['sczl_jtbh'] ?? '',
  2450. 'startTime' => $param['sczl_sj1'] ?? '',
  2451. 'endTime' => $param['sczl_sj2'] ?? '',
  2452. '换版总工时' => $param['sczl_装版总工时'],
  2453. '换版联拼数' => $param['sczl_换版联拼数'] ?? 0,
  2454. '换版类型' => $param['换版类型'] ?? '',
  2455. '装版补产工时' => $param['sczl_装版工时'] ?? ''
  2456. ];
  2457. $plateData = $priData;
  2458. $priSql = \db('设备_装版工时')->where('yieldUid', $uniqId)->fetchSql(true)->update($priData);
  2459. \db()->query($priSql);
  2460. }
  2461. // 更新产量计酬数据
  2462. $rowSql = \db('设备_产量计酬')->where('UniqId', $uniqId)->fetchSql(true)->update($updateData);
  2463. $rowCount = \db()->query($rowSql);
  2464. $success = $rowCount !== false;
  2465. } catch (\Exception $e) {
  2466. // 记录错误日志
  2467. \think\Log::error('修改产量详情失败: ' . $e->getMessage() . ' 堆栈: ' . $e->getTraceAsString());
  2468. $this->error('操作失败: ' . $e->getMessage());
  2469. }
  2470. if ($success) {
  2471. $logs = $this->facilityChangedLogs($this->facilityYieldLogBase($beforeYield, '修改', 'MachineChanliangDetailEdit', $operator), $beforeYield, $updateData);
  2472. if (!empty($plateData)) {
  2473. $plateBase = $this->facilityYieldLogBase($beforeYield, '修改', 'MachineChanliangDetailEdit', $operator);
  2474. $plateBase['业务表'] = '设备_装版工时';
  2475. $plateBase['RecordUniqid'] = $uniqId;
  2476. $logs = array_merge($logs, $this->facilityChangedLogs($plateBase, $beforePlate, $plateData));
  2477. }
  2478. $this->saveFacilityOperateLog($logs);
  2479. $this->success('修改成功');
  2480. } else {
  2481. $this->error('修改失败,未更新任何数据');
  2482. }
  2483. }
  2484. /**
  2485. * 产量上报数据删除
  2486. * @return void
  2487. * @throws \think\Exception
  2488. * @throws \think\exception\PDOException
  2489. */
  2490. public function ChanliangDel()
  2491. {
  2492. if ($this->request->isGet() === false){
  2493. $this->error('请求错误');
  2494. }
  2495. $param = $this->request->param();
  2496. if (empty($param['UniqId'])){
  2497. $this->error('参数错误');
  2498. }
  2499. $idList = explode(',',$param['UniqId']);
  2500. $operator = $this->facilityLogOperator($param);
  2501. $logs = [];
  2502. foreach ($idList as $key=>$value){
  2503. $before = \db('设备_产量计酬')->where('UniqId',$value)->find();
  2504. $res = \db('设备_产量计酬')
  2505. ->where('UniqId',$value)
  2506. ->delete();
  2507. if ($res && !empty($before)) {
  2508. $item = $this->facilityYieldLogBase($before, '删除', 'ChanliangDel', $operator);
  2509. $item['修改前'] = '产量='.trim((string)$before['sczl_cl']).';制程废品='.trim((string)$before['sczl_zcfp']);
  2510. $logs[] = $item;
  2511. }
  2512. }
  2513. $this->saveFacilityOperateLog($logs);
  2514. if ($res !== false){
  2515. $this->success('删除成功');
  2516. }else{
  2517. $this->error('删除失败');
  2518. }
  2519. }
  2520. /**
  2521. * 日产量上报添加
  2522. * @return void
  2523. * @throws \think\db\exception\BindParamException
  2524. * @throws \think\exception\PDOException
  2525. */
  2526. public function ChanliangAdd()
  2527. {
  2528. // 1. 请求验证
  2529. if (!Request::instance()->isPost()) {
  2530. $this->error('请求错误');
  2531. }
  2532. $params = Request::instance()->post();
  2533. // 2. 参数验证
  2534. if (empty($params['sczl_gdbh'])) {
  2535. $this->error('参数错误');
  2536. }
  2537. // 3. 获取最新ID
  2538. $lastId = db('设备_产量计酬')->order('UniqId desc')->value('rtrim(UniqId)');
  2539. // 4. 验证工序存在性
  2540. $massage = db('工单_工艺资料')
  2541. ->where('Gy0_gdbh', $params['sczl_gdbh'])
  2542. ->where('Gy0_yjno', $params['sczl_yjno'])
  2543. ->where('Gy0_gxh', $params['sczl_gxh'])
  2544. ->count();
  2545. if ($massage === 0) {
  2546. $this->error('请选择正确的工序');
  2547. }
  2548. // 5. 准备基础数据
  2549. $currentTime = date('Y-m-d H:i:s');
  2550. $params['sczl_type'] = $params['sczl_gxmc'];
  2551. $params['sczl_wgsj'] = '1900-01-01 00:00:00';
  2552. $params['sczl_废品率系数'] = 0;
  2553. $params['sys_rq'] = $currentTime;
  2554. $params['mod_rq'] = $currentTime;
  2555. $params['UniqId'] = $lastId + 1;
  2556. // 6. 处理装版工时记录(如果有)
  2557. if (!empty($params['sczl_装版总工时']) && $params['sczl_装版总工时'] != 0) {
  2558. if (!isset($params['sczl_sj1']) || empty($params['sczl_sj1'])) {
  2559. $params['sczl_sj1'] = date('Y-m-d H:i:s',time());
  2560. }
  2561. if (!isset($params['sczl_sj2']) || empty($params['sczl_sj2'])) {
  2562. $params['sczl_sj2'] = date('Y-m-d H:i:s',time());
  2563. }
  2564. $plateData = [
  2565. 'gdbh' => $params['sczl_gdbh'],
  2566. 'yjno' => $params['sczl_yjno'],
  2567. 'gxh' => $params['sczl_gxh'],
  2568. 'jtbh' => $params['sczl_jtbh'],
  2569. 'startTime' => $params['sczl_sj1'],
  2570. 'endTime' => $params['sczl_sj2'],
  2571. 'yieldUid' => $params['UniqId'],
  2572. '换版总工时' => $params['sczl_装版总工时'],
  2573. '换版联拼数' => $params['sczl_换版联拼数'],
  2574. '换版类型' => $params['换版类型'],
  2575. 'sys_rq' => $currentTime,
  2576. 'sys_id' => $params['sys_id']
  2577. ];
  2578. $chSql = db('设备_装版工时')->fetchSql(true)->insert($plateData);
  2579. $chRes = \db()->query($chSql);
  2580. if ($chRes === false) {
  2581. $this->error('装版工时记录保存失败');
  2582. }
  2583. $plateBase = $this->facilityYieldLogBase($params, '新增', 'ChanliangAdd', isset($params['sys_id']) ? $params['sys_id'] : '');
  2584. $plateBase['业务表'] = '设备_装版工时';
  2585. $plateBase['修改后'] = '换版总工时='.$plateData['换版总工时'].';换版类型='.$plateData['换版类型'].';换版联拼数='.$plateData['换版联拼数'];
  2586. $this->saveFacilityOperateLog([$plateBase]);
  2587. }
  2588. // 7. 移除不需要的字段
  2589. unset($params['sczl_换版联拼数'], $params['换版类型']);
  2590. // 8. 保存主记录
  2591. $sql = db('设备_产量计酬')->fetchSql(true)->insert($params);
  2592. $res = db()->query($sql);
  2593. if ($res !== false) {
  2594. $yieldLog = $this->facilityYieldLogBase($params, '新增', 'ChanliangAdd', isset($params['sys_id']) ? $params['sys_id'] : '');
  2595. $yieldLog['修改后'] = '产量='.(isset($params['sczl_cl']) ? $params['sczl_cl'] : '').';制程废品='.(isset($params['sczl_zcfp']) ? $params['sczl_zcfp'] : '');
  2596. $this->saveFacilityOperateLog([$yieldLog]);
  2597. $this->success('成功');
  2598. } else {
  2599. $this->error('失败');
  2600. }
  2601. }
  2602. /**
  2603. * 日产量上报添加获取工单信息
  2604. * @return void
  2605. * @throws \think\db\exception\DataNotFoundException
  2606. * @throws \think\db\exception\ModelNotFoundException
  2607. * @throws \think\exception\DbException
  2608. */
  2609. public function ChanliangWorkorder()
  2610. {
  2611. if ($this->request->isGet() === false)
  2612. {
  2613. $this->error('请求错误');
  2614. }
  2615. $param = $this->request->param();
  2616. if (empty($param)){
  2617. $this->error('参数错误');
  2618. }
  2619. if (!empty($param['search'])){
  2620. $where['b.Gy0_gdbh'] = ['like','%'.$param['search'].'%'];
  2621. }
  2622. $list = \db('工单_基本资料')
  2623. ->alias('a')
  2624. ->field('rtrim(Gd_gdbh) as gdbh,rtrim(成品名称) as cpmc')
  2625. ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh')
  2626. ->where($where)
  2627. ->select();
  2628. if (empty($list)){
  2629. $this->success('未找到相关工单');
  2630. }else{
  2631. $this->success('成功',$list);
  2632. }
  2633. }
  2634. /**
  2635. * 日产量上报工单印件资料
  2636. * @return void
  2637. * @throws \think\db\exception\DataNotFoundException
  2638. * @throws \think\db\exception\ModelNotFoundException
  2639. * @throws \think\exception\DbException
  2640. */
  2641. public function ChanliangPrintDetail()
  2642. {
  2643. if ($this->request->isGet() === false){
  2644. $this->error('请求错误');
  2645. }
  2646. $param = $this->request->param();
  2647. if (empty($param['gdbh'])){
  2648. $this->error('参数错误');
  2649. }
  2650. $where = [
  2651. 'Yj_Gdbh' => $param['gdbh']
  2652. ];
  2653. $list = \db('工单_印件资料')
  2654. ->where($where)
  2655. ->field('rtrim(yj_Yjno) as yjno,rtrim(yj_yjmc) as yjmc,rtrim(yj_ls) as ls')
  2656. ->select();
  2657. if (empty($list)){
  2658. $this->success('未找到印件资料');
  2659. }else{
  2660. $this->success('成功',$list);
  2661. }
  2662. }
  2663. /**
  2664. * 日产量上报工艺资料获取
  2665. * @return void
  2666. * @throws \think\db\exception\DataNotFoundException
  2667. * @throws \think\db\exception\ModelNotFoundException
  2668. * @throws \think\exception\DbException
  2669. */
  2670. public function ChanliangProcessDetail()
  2671. {
  2672. if ($this->request->isGet() === false){
  2673. $this->error('请求错误');
  2674. }
  2675. $param = $this->request->param();
  2676. if (empty($param['gdbh'])){
  2677. $this->error('参数错误');
  2678. }
  2679. $list = \db('工单_工艺资料')
  2680. ->where('Gy0_gdbh',$param['gdbh'])
  2681. ->where('Gy0_yjno',$param['yjno'])
  2682. ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
  2683. ->select();
  2684. if (empty($list)){
  2685. $this->success('未获取工序');
  2686. }
  2687. foreach ($list as $key=>$value){
  2688. if ((int)$value['gxh'] < 10){
  2689. $value['gxh'] = '0'.$value['gxh'];
  2690. }
  2691. if (empty($value['add_gxmc'])){
  2692. $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'];
  2693. }else{
  2694. $list[$key]['name'] = $value['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  2695. }
  2696. unset( $list[$key]['add_gxmc']);
  2697. }
  2698. $this->success('成功',$list);
  2699. }
  2700. /**
  2701. * 工价系数修改
  2702. * @return void
  2703. * @throws \think\Exception
  2704. * @throws \think\db\exception\BindParamException
  2705. * @throws \think\exception\PDOException
  2706. */
  2707. public function CoefficientEdit()
  2708. {
  2709. if (Request::instance()->isPost() === false){
  2710. $this->error('请求错误');
  2711. }
  2712. $params = Request::instance()->post();
  2713. if (empty($params['id'])){
  2714. $this->error('参数错误');
  2715. }
  2716. $idList = explode(',',$params['id']);
  2717. $operator = $this->facilityLogOperator($params);
  2718. $oldMap = [];
  2719. $oldList = \db('设备_产量计酬')->where('UniqId','in',$idList)->select();
  2720. foreach ($oldList as $oldRow) {
  2721. $oldMap[trim($oldRow['UniqId'])] = $oldRow;
  2722. }
  2723. $logs = [];
  2724. $i=0;
  2725. foreach ($idList as $key=>$value){
  2726. $sql = \db('设备_产量计酬')
  2727. ->where('UniqId',$value)
  2728. ->fetchSql(true)
  2729. ->update(['sczl_工价系数'=>$params['工价系数']]);
  2730. $res = \db()->query($sql);
  2731. if ($res === false){
  2732. $i++;
  2733. } else {
  2734. $before = isset($oldMap[trim($value)]) ? $oldMap[trim($value)] : [];
  2735. $logs = array_merge($logs, $this->facilityChangedLogs(
  2736. $this->facilityYieldLogBase($before, '修改', 'CoefficientEdit', $operator),
  2737. $before,
  2738. ['sczl_工价系数' => $params['工价系数']]
  2739. ));
  2740. }
  2741. }
  2742. $this->saveFacilityOperateLog($logs);
  2743. if ($i!==0){
  2744. $this->error('修改失败');
  2745. }
  2746. // 同步标记 AI 校验结果:已按推荐系数修正,避免刷新后仍显示 ❌
  2747. // 下次定时校验会重新用最新工价系数比对并覆盖本状态
  2748. try {
  2749. \db('agent_难度系数校验结果')
  2750. ->where('UniqId','in',$idList)
  2751. ->update([
  2752. 'audit_result' => '✅已修正',
  2753. 'audit_note' => '已按推荐系数修正为 '.$params['工价系数'],
  2754. ]);
  2755. } catch (\Exception $e) {
  2756. // 校验结果表异常不影响工价系数修改主流程
  2757. }
  2758. $this->success('修改成功');
  2759. }
  2760. /**
  2761. * 难度系数校验 - 左侧菜单(车间→日期两级,日期为最近30天)
  2762. * @ApiMethod (GET)
  2763. * @return void
  2764. */
  2765. public function getCoefTab()
  2766. {
  2767. if ($this->request->isGet() === false){
  2768. $this->error('请求错误');
  2769. }
  2770. // 近30天有校验结果的日期(从 agent 表取,只看有校验的)
  2771. $startDate = date('Y-m-d 00:00:00', strtotime('-30 days'));
  2772. // 先从 agent 表拿到 UniqId,再关联产量计酬表取机台和日期
  2773. $agentUids = \db('agent_难度系数校验结果')
  2774. ->where('难度系数校验','>=',$startDate)
  2775. ->column('UniqId');
  2776. if (empty($agentUids)){
  2777. $this->success('成功',[]);
  2778. }
  2779. $list = \db('设备_产量计酬')
  2780. ->where('UniqId','in',$agentUids)
  2781. ->where('sczl_rq','>=',$startDate)
  2782. ->distinct(true)
  2783. ->field('rtrim(sczl_jtbh) as 机台编号,DATE(sczl_rq) as sczl_date')
  2784. ->select();
  2785. if (empty($list)){
  2786. $this->success('成功',[]);
  2787. }
  2788. $machineCodes = array_values(array_unique(array_column($list,'机台编号')));
  2789. // 机台所属车间
  2790. $machines = \db('设备_基本资料')
  2791. ->whereIn('设备编号',$machineCodes)
  2792. ->where('使用部门','<>','研发中心')
  2793. ->where('sys_sbID','<>','')
  2794. ->column('rtrim(使用部门)','rtrim(设备编号)');
  2795. // 按 车间 → 日期 分组
  2796. $data = [];
  2797. foreach ($list as $row){
  2798. $workshop = isset($machines[$row['机台编号']]) ? $machines[$row['机台编号']] : '未知车间';
  2799. $date = $row['sczl_date'];
  2800. if (!isset($data[$workshop])){
  2801. $data[$workshop] = [];
  2802. }
  2803. $data[$workshop][$date] = true;
  2804. }
  2805. // 排序:日期倒序
  2806. foreach ($data as &$dates){
  2807. krsort($dates);
  2808. $dates = array_keys($dates);
  2809. }
  2810. $this->success('成功',$data);
  2811. }
  2812. /**
  2813. * 难度系数校验 - 按日期查询产量数据(带推荐系数和校验结果)
  2814. * @ApiMethod (GET)
  2815. * @param string $date 日期 YYYY-MM-DD
  2816. * @return void
  2817. */
  2818. public function getCoefList()
  2819. {
  2820. if ($this->request->isGet() === false){
  2821. $this->error('请求错误');
  2822. }
  2823. $date = input('date');
  2824. if (empty($date)){
  2825. $this->error('参数错误');
  2826. }
  2827. // 先拿 agent 表中该日期的 UniqId
  2828. $startDay = $date.' 00:00:00';
  2829. $endDay = $date.' 23:59:59';
  2830. $agentList = \db('agent_难度系数校验结果')
  2831. ->where('sczc_rq','>=',$startDay)
  2832. ->where('sczc_rq','<=',$endDay)
  2833. ->field('UniqId,suggested_wage_coef,audit_result,audit_note')
  2834. ->select();
  2835. if (empty($agentList)){
  2836. $this->success('成功',[]);
  2837. }
  2838. $agentRows = [];
  2839. $uniqIds = [];
  2840. foreach ($agentList as $agent){
  2841. $uid = trim($agent['UniqId']);
  2842. $agentRows[$uid] = $agent;
  2843. $uniqIds[] = $uid;
  2844. }
  2845. $uniqIds = array_values(array_unique($uniqIds));
  2846. $field = 'rtrim(sczl_jtbh) as 机台编号,rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,
  2847. rtrim(sczl_gxh) as gxh,rtrim(sczl_gxmc) as gxmc,
  2848. rtrim(sczl_bzdh) as bzdh,rtrim(UniqId) as UniqId,
  2849. rtrim(sczl_工价系数) as 难度系数,
  2850. sczl_bh1,sczl_bh2,sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10';
  2851. $list = \db('设备_产量计酬')
  2852. ->where('UniqId','in',$uniqIds)
  2853. ->field($field)
  2854. ->select();
  2855. if (empty($list)){
  2856. $this->success('成功',[]);
  2857. }
  2858. // 过滤:只保留 agent 表有的 UniqId(产量表可能有多条同 UniqId,其实是 1:1)
  2859. $list = array_values(array_filter($list,function($row) use ($agentRows){
  2860. return isset($agentRows[trim($row['UniqId'])]);
  2861. }));
  2862. if (empty($list)){
  2863. $this->success('成功',[]);
  2864. }
  2865. // 批量取产品名称
  2866. $gdbhs = array_values(array_unique(array_column($list,'工单编号')));
  2867. $productMap = [];
  2868. $productList = \db('工单_基本资料')
  2869. ->whereIn('Gd_gdbh',$gdbhs)
  2870. ->field('rtrim(Gd_gdbh) as gdbh,rtrim(成品名称) as 成品名称')
  2871. ->select();
  2872. foreach ($productList as $product){
  2873. $productMap[trim($product['gdbh'])] = $product['成品名称'];
  2874. }
  2875. // 批量取工价系数
  2876. $processMap = [];
  2877. $processList = \db('工单_工艺资料')
  2878. ->whereIn('Gy0_gdbh',$gdbhs)
  2879. ->field('rtrim(Gy0_gdbh) as gdbh,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(工价系数) as 工价系数')
  2880. ->select();
  2881. foreach ($processList as $process){
  2882. $processMap[trim($process['gdbh']).'|'.trim($process['yjno']).'|'.trim($process['gxh'])] = $process['工价系数'];
  2883. }
  2884. // 批量取组员姓名
  2885. $memberCodes = [];
  2886. foreach ($list as $row){
  2887. for ($i=1;$i<11;$i++){
  2888. if (!empty($row['sczl_bh'.$i])){
  2889. $memberCodes[] = $row['sczl_bh'.$i];
  2890. }
  2891. }
  2892. }
  2893. $memberCodes = array_values(array_unique($memberCodes));
  2894. $memberMap = [];
  2895. if (!empty($memberCodes)){
  2896. $memberList = \db('人事_基本资料')
  2897. ->whereIn('员工编号',$memberCodes)
  2898. ->field('rtrim(员工编号) as 员工编号,rtrim(员工姓名) as 员工姓名')
  2899. ->select();
  2900. foreach ($memberList as $member){
  2901. $memberMap[trim($member['员工编号'])] = $member['员工姓名'];
  2902. }
  2903. }
  2904. foreach ($list as $key=>$value){
  2905. $gdbh = trim($value['工单编号']);
  2906. // 产品名称(带工单编号)
  2907. $productName = isset($productMap[$gdbh]) && $productMap[$gdbh] !== '' ? $productMap[$gdbh] : $gdbh;
  2908. $list[$key]['产品名称'] = $gdbh.' '.$productName;
  2909. // 难度系数 = 基础工价系数 x 计酬难度系数
  2910. $processKey = $gdbh.'|'.trim($value['yjno']).'|'.trim($value['gxh']);
  2911. if (isset($processMap[$processKey])){
  2912. if ($value['难度系数'] == 0){
  2913. $list[$key]['难度系数'] = $processMap[$processKey];
  2914. }else{
  2915. $list[$key]['难度系数'] = $processMap[$processKey].'x'.$value['难度系数'];
  2916. }
  2917. }else{
  2918. $list[$key]['难度系数'] = '';
  2919. }
  2920. // 工序展示
  2921. if ($value['yjno']<10){
  2922. $yjno = '0'.$value['yjno'];
  2923. }else{
  2924. $yjno = $value['yjno'];
  2925. }
  2926. $list[$key]['工序'] = $yjno.'-'.$value['gxmc'];
  2927. // 组员
  2928. $codes = [];
  2929. $names = [];
  2930. for ($i=1;$i<11;$i++){
  2931. $bh = 'sczl_bh'.$i;
  2932. if (!empty($value[$bh])){
  2933. $codes[] = $value[$bh];
  2934. $names[] = $value[$bh].(isset($memberMap[$value[$bh]]) ? $memberMap[$value[$bh]] : '');
  2935. }
  2936. unset($list[$key][$bh]);
  2937. }
  2938. $list[$key]['组员编码'] = $codes;
  2939. $list[$key]['组员姓名'] = $names;
  2940. $list[$key]['组员文本'] = implode(',',$names);
  2941. // AI 推荐系数 + 审核结果
  2942. $agent = $agentRows[trim($value['UniqId'])];
  2943. $list[$key]['推荐系数'] = $agent['suggested_wage_coef'];
  2944. $auditResult = trim((string)$agent['audit_result']);
  2945. $auditNote = trim((string)$agent['audit_note']);
  2946. $list[$key]['结果'] = $auditResult.($auditNote !== '' ? ':'.$auditNote : '');
  2947. }
  2948. $this->success('成功',$list);
  2949. }
  2950. /**
  2951. * 色度系数修改
  2952. * @return void
  2953. * @throws \think\Exception
  2954. * @throws \think\db\exception\BindParamException
  2955. * @throws \think\exception\PDOException
  2956. */
  2957. public function ChromaDataEdit()
  2958. {
  2959. if (Request::instance()->isPost() === false){
  2960. $this->error('请求错误');
  2961. }
  2962. $params = Request::instance()->post();
  2963. if (empty($params['id'])){
  2964. $this->error('参数错误');
  2965. }
  2966. $idList = explode(',',$params['id']);
  2967. $operator = $this->facilityLogOperator($params);
  2968. $oldMap = [];
  2969. $oldList = \db('设备_产量计酬')->where('UniqId','in',$idList)->select();
  2970. foreach ($oldList as $oldRow) {
  2971. $oldMap[trim($oldRow['UniqId'])] = $oldRow;
  2972. }
  2973. $logs = [];
  2974. $i=0;
  2975. foreach ($idList as $key=>$value){
  2976. $sql = \db('设备_产量计酬')
  2977. ->where('UniqId',$value)
  2978. ->fetchSql(true)
  2979. ->update(['sczl_ms'=>$params['ms']]);
  2980. $res = \db()->query($sql);
  2981. if ($res === false){
  2982. $i++;
  2983. } else {
  2984. $before = isset($oldMap[trim($value)]) ? $oldMap[trim($value)] : [];
  2985. $logs = array_merge($logs, $this->facilityChangedLogs(
  2986. $this->facilityYieldLogBase($before, '修改', 'ChromaDataEdit', $operator),
  2987. $before,
  2988. ['sczl_ms' => $params['ms']]
  2989. ));
  2990. }
  2991. }
  2992. $this->saveFacilityOperateLog($logs);
  2993. if ($i!==0){
  2994. $this->error('修改失败');
  2995. }else{
  2996. $this->success('修改成功');
  2997. }
  2998. }
  2999. /**
  3000. * 凹印版距修改
  3001. * @return void
  3002. * @throws \think\Exception
  3003. * @throws \think\db\exception\BindParamException
  3004. * @throws \think\exception\PDOException
  3005. */
  3006. public function PrintingModeDataEdit()
  3007. {
  3008. if (Request::instance()->isPost() === false){
  3009. $this->error('请求错误');
  3010. }
  3011. $params = Request::instance()->post();
  3012. if (empty($params['id'])){
  3013. $this->error('参数错误');
  3014. }
  3015. $idList = explode(',',$params['id']);
  3016. //获取工单印件工序
  3017. $orderList = \db('设备_产量计酬')
  3018. ->where('UniqId',$idList[0])
  3019. ->field('rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as 印件号,rtrim(sczl_gxh) as 工序号,rtrim(sczl_jtbh) as 设备编号,rtrim(sczl_gxmc) as 工序名称')
  3020. ->find();
  3021. $where = [
  3022. 'Gy0_gdbh'=>$orderList['工单编号'],
  3023. 'Gy0_yjno'=>$orderList['印件号'],
  3024. 'Gy0_gxh'=>$orderList['工序号']
  3025. ];
  3026. $before = \db('工单_工艺资料')->where($where)->find();
  3027. if (empty($before)) {
  3028. $before = [];
  3029. }
  3030. //修改工艺资料
  3031. $after = ['版距'=>$params['plate'],'印刷方式'=>$params['mode']];
  3032. $sql = \db('工单_工艺资料')
  3033. ->where($where)
  3034. ->fetchSql(true)
  3035. ->update($after);
  3036. $res = \db()->query($sql);
  3037. if ($res === false){
  3038. $this->error('修改失败');
  3039. }else{
  3040. $this->saveFacilityOperateLog($this->facilityChangedLogs([
  3041. '业务表' => '工单_工艺资料',
  3042. '操作类型' => '修改',
  3043. '方法名' => 'PrintingModeDataEdit',
  3044. 'RecordUniqid' => isset($before['UniqId']) ? $before['UniqId'] : '',
  3045. '设备编号' => $orderList['设备编号'],
  3046. '工单编号' => $orderList['工单编号'],
  3047. '印件号' => $orderList['印件号'],
  3048. '工序号' => $orderList['工序号'],
  3049. '工序名称' => $orderList['工序名称'],
  3050. 'sys_id' => $this->facilityLogOperator($params),
  3051. ], $before, $after));
  3052. $this->success('修改成功');
  3053. }
  3054. }
  3055. /**
  3056. * 废品率系数批量修改
  3057. * @return void
  3058. * @throws \think\Exception
  3059. * @throws \think\db\exception\BindParamException
  3060. * @throws \think\exception\PDOException
  3061. */
  3062. public function RejectionEdit()
  3063. {
  3064. if (Request::instance()->isPost() === false){
  3065. $this->error('请求错误');
  3066. }
  3067. $params = Request::instance()->post();
  3068. if (empty($params['id'])){
  3069. $this->error('参数错误');
  3070. }
  3071. $idList = explode(',',$params['id']);
  3072. $operator = $this->facilityLogOperator($params);
  3073. $oldMap = [];
  3074. $oldList = \db('设备_产量计酬')->where('UniqId','in',$idList)->select();
  3075. foreach ($oldList as $oldRow) {
  3076. $oldMap[trim($oldRow['UniqId'])] = $oldRow;
  3077. }
  3078. $logs = [];
  3079. $i=0;
  3080. foreach ($idList as $key=>$value){
  3081. $sql = \db('设备_产量计酬')
  3082. ->where('UniqId',$value)
  3083. ->fetchSql(true)
  3084. ->update(['sczl_废品率系数'=>$params['rejection']]);
  3085. $res = \db()->query($sql);
  3086. if ($res === false){
  3087. $i++;
  3088. } else {
  3089. $before = isset($oldMap[trim($value)]) ? $oldMap[trim($value)] : [];
  3090. $logs = array_merge($logs, $this->facilityChangedLogs(
  3091. $this->facilityYieldLogBase($before, '修改', 'RejectionEdit', $operator),
  3092. $before,
  3093. ['sczl_废品率系数' => $params['rejection']]
  3094. ));
  3095. }
  3096. }
  3097. $this->saveFacilityOperateLog($logs);
  3098. if ($i!==0){
  3099. $this->error('修改失败');
  3100. }else{
  3101. $this->success('修改成功');
  3102. }
  3103. }
  3104. /**
  3105. * 日产量上报班组信息批量修改
  3106. * @return void
  3107. * @throws \think\Exception
  3108. * @throws \think\db\exception\BindParamException
  3109. * @throws \think\db\exception\DataNotFoundException
  3110. * @throws \think\db\exception\ModelNotFoundException
  3111. * @throws \think\exception\DbException
  3112. * @throws \think\exception\PDOException
  3113. */
  3114. public function YieldTeamEdit()
  3115. {
  3116. if ($this->request->isGet() === false){
  3117. $this->error('请求错误');
  3118. }
  3119. $param = $this->request->param();
  3120. if (empty($param['Uniqid']) || empty($param['teamID'])){
  3121. $this->error('参数错误');
  3122. }
  3123. $idList = explode(',',$param['Uniqid']);
  3124. $operator = $this->facilityLogOperator($param);
  3125. $teamList = \db('设备_班组资料')->where('UniqId',$param['teamID'])->find();
  3126. $data = [];
  3127. for ($i=1;$i<11;$i++){
  3128. $data['sczl_bh'.$i] = $teamList['sczl_bh'.$i];
  3129. $data['sczl_rate'.$i] = $teamList['sczl_rate'.$i];
  3130. $data['sczl_bzdh'] = $teamList['sczl_bzdh'];
  3131. }
  3132. $oldMap = [];
  3133. $oldList = \db('设备_产量计酬')->where('UniqId','in',$idList)->select();
  3134. foreach ($oldList as $oldRow) {
  3135. $oldMap[trim($oldRow['UniqId'])] = $oldRow;
  3136. }
  3137. $logs = [];
  3138. $j = 0;
  3139. foreach ($idList as $key => $value){
  3140. $sql = \db('设备_产量计酬')
  3141. ->where('UniqId',$value)
  3142. ->fetchSql(true)
  3143. ->update($data);
  3144. $res = \db()->query($sql);
  3145. if ($res === false){
  3146. $j++;
  3147. } else {
  3148. $before = isset($oldMap[trim($value)]) ? $oldMap[trim($value)] : [];
  3149. $logs = array_merge($logs, $this->facilityChangedLogs(
  3150. $this->facilityYieldLogBase($before, '修改', 'YieldTeamEdit', $operator),
  3151. $before,
  3152. $data
  3153. ));
  3154. }
  3155. }
  3156. $this->saveFacilityOperateLog($logs);
  3157. if ($j === 0){
  3158. $this->success('修改成功');
  3159. }else{
  3160. $this->error('修改失败');
  3161. }
  3162. }
  3163. /**
  3164. * 检品机日产量上报数据修改
  3165. * @return void
  3166. * @throws \think\Exception
  3167. * @throws \think\db\exception\BindParamException
  3168. * @throws \think\exception\PDOException
  3169. */
  3170. public function JpChanliangEdit()
  3171. {
  3172. if (Request::instance()->isPost() == false){
  3173. $this->error('非法请求');
  3174. }
  3175. $params = Request::instance()->post();
  3176. if (empty($params['UniqId'])){
  3177. $this->error('参数错误');
  3178. }
  3179. $before = \db('设备_产量计酬')->where('UniqId',$params['UniqId'])->find();
  3180. if (empty($before)) {
  3181. $before = [];
  3182. }
  3183. $operator = $this->facilityLogOperator($params);
  3184. $params['mod_rq'] = date('Y-m-d H:i:s');
  3185. $data = $params;
  3186. unset($data['UniqId']);
  3187. $sql = \db('设备_产量计酬')->where('UniqId',$params['UniqId'])->fetchSql(true)->update($data);
  3188. $res = \db()->query($sql);
  3189. if ($res === false){
  3190. $this->error('修改失败');
  3191. }else{
  3192. $this->saveFacilityOperateLog($this->facilityChangedLogs(
  3193. $this->facilityYieldLogBase($before, '修改', 'JpChanliangEdit', $operator),
  3194. $before,
  3195. $data
  3196. ));
  3197. $this->success('成功');
  3198. }
  3199. }
  3200. /**
  3201. * 检品机日产量上报数据列表
  3202. * @return void
  3203. * @throws \think\db\exception\DataNotFoundException
  3204. * @throws \think\db\exception\ModelNotFoundException
  3205. * @throws \think\exception\DbException
  3206. */
  3207. public function JPmachineDetail()
  3208. {
  3209. if ($this->request->isGet() === false){
  3210. $this->error('请求错误');
  3211. }
  3212. $machine = input('machine');
  3213. $date = input('date');
  3214. $where = [
  3215. 'sczl_jtbh' => $machine,
  3216. 'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
  3217. ];
  3218. $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 计件箱数,
  3219. 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 通电工时,
  3220. 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,
  3221. 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,
  3222. sczl_rate8,sczl_rate9,sczl_rate10,sczl_bh98,rtrim(UniqId) as UniqId,rtrim(sczl_工价系数) as 难度系数,rtrim(sczl_dedh) as 定额代号,sczl_rq,sczl_装版总工时 as 换膜总工时';
  3223. //机台信息
  3224. $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
  3225. //组员信息
  3226. $list = \db('设备_产量计酬')->where($where)->field($field)->select();
  3227. $totalA = \db('设备_产量计酬')
  3228. ->where($where)
  3229. ->where('sczl_bzdh','like','A%')
  3230. ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数,SUM(sczl_装版工时) as 总换膜补时,SUM(sczl_保养工时) as 总保养工时,SUM(sczl_异常停机工时) as 总异常总工时,SUM(sczl_设备运行工时) as 总通电工时')
  3231. ->group('检验类型')
  3232. ->select();
  3233. $totalB = \db('设备_产量计酬')
  3234. ->where($where)
  3235. ->where('sczl_bzdh','like','B%')
  3236. ->field('sczl_type as 检验类型,SUM(sczl_cl) as 箱数,SUM(sczl_装版工时) as 总换膜补时,SUM(sczl_保养工时) as 总保养工时,SUM(sczl_异常停机工时) as 总异常总工时,SUM(sczl_设备运行工时) as 总通电工时')
  3237. ->group('检验类型')
  3238. ->select();
  3239. if (empty($list)){
  3240. $this->success('',[]);
  3241. }
  3242. foreach ($list as $key=>$value){
  3243. //产品名称
  3244. $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$value['工单编号'])->field('rtrim(成品名称) as 成品名称,rtrim(Gd_cpmc) as cpmc')->find();
  3245. if (!empty($productName)){
  3246. if (!empty($productName['成品名称'])){
  3247. $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['成品名称'];
  3248. $list[$key]['cpmc'] = $productName['成品名称'];
  3249. }else{
  3250. $list[$key]['产品名称'] = $value['工单编号'];
  3251. $list[$key]['cpmc'] = '';
  3252. }
  3253. }else{
  3254. $list[$key]['产品名称'] = $value['工单编号'];
  3255. $list[$key]['cpmc'] = '';
  3256. }
  3257. if (empty($value['定额代号'])){
  3258. $list[$key]['千件工价'] = '';
  3259. $list[$key]['日定额'] = '';
  3260. $list[$key]['补产标准'] = '';
  3261. }else{
  3262. $row = \db('dic_lzde')->where('sys_bh',$value['定额代号'])->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额,rtrim(补产标准) as 补产标准')->find();
  3263. $list[$key]['千件工价'] = $row['千件工价'];
  3264. $list[$key]['日定额'] = $row['日定额'];
  3265. $list[$key]['补产标准'] = $row['补产标准'];
  3266. }
  3267. $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxh'].'-'.$list[$key]['gxmc'];
  3268. for ($i=1;$i<11;$i++){
  3269. if (isset($value['sczl_bh'.$i])){
  3270. $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('员工姓名 as name')->find();
  3271. if (isset($name['name'])){
  3272. $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
  3273. $list[$key]['sczl_name'.$i] = $name['name'];
  3274. }else{
  3275. $list[$key]['sczl_name'.$i] = '';
  3276. }
  3277. }
  3278. }
  3279. }
  3280. $list['totalA'] = $totalA;
  3281. $list['totalB'] = $totalB;
  3282. $this->success('成功',$list);
  3283. }
  3284. /**
  3285. * 检品机每日上报数据修改页面数据获取接口
  3286. * @return void
  3287. * @throws \think\db\exception\DataNotFoundException
  3288. * @throws \think\db\exception\ModelNotFoundException
  3289. * @throws \think\exception\DbException
  3290. */
  3291. public function JPchanliangDetailList()
  3292. {
  3293. if ($this->request->isGet() === false){
  3294. $this->error('请求错误');
  3295. }
  3296. $param = $this->request->param();
  3297. if (empty($param)){
  3298. $this->error('参数错误');
  3299. }
  3300. $list = \db('设备_产量计酬')
  3301. ->alias('a')
  3302. ->join('工单_基本资料 b','a.sczl_gdbh = b.Gd_gdbh AND a.sczl_yjno = b.行号')
  3303. ->field('rtrim(a.sczl_gdbh) as 工单编号,rtrim(a.sczl_dedh) as dedh,rtrim(a.sczl_yjno) as yjno,
  3304. rtrim(a.sczl_gxh) as gxh,rtrim(a.sczl_gxmc) as gxmc,rtrim(a.sczl_type) as 检验类型,rtrim(a.sczl_num) as num,
  3305. rtrim(a.sczl_cl) as 计件箱数,rtrim(a.sczl_Pgcl) as 每箱数量,rtrim(a.sczl_bzdh) as bzdh,
  3306. IF(a.sczl_废品率系数 = 0, "",a.sczl_废品率系数) as 废品率系数,IF(a.sczl_装版工时 = 0, "",a.sczl_装版工时) as 换膜补时,
  3307. IF(a.sczl_保养工时 = 0, "",a.sczl_保养工时) as 保养工时,IF(a.sczl_异常停机工时 = 0, "",a.sczl_异常停机工时) as 异常总工时,
  3308. IF(a.sczl_设备运行工时 = 0, "",a.sczl_设备运行工时) as 通电工时,rtrim(a.sys_id) as 用户,rtrim(a.mod_rq) as 更新时间,
  3309. IF(a.sczl_异常工时1 = 0, "",a.sczl_异常工时1) as 异常补时,IF(a.sczl_异常类型1 = 0, "",a.sczl_异常类型1) as 异常类型,
  3310. 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,
  3311. a.sczl_rate1,a.sczl_rate2,a.sczl_rate3,a.sczl_rate4,a.sczl_rate5,a.sczl_rate6,a.sczl_rate7,a.sczl_rate8,
  3312. a.sczl_rate9,a.sczl_rate10,a.sczl_bh98,rtrim(a.UniqId) as UniqId,rtrim(a.sczl_工价系数) as 难度系数,
  3313. rtrim(a.sczl_dedh) as 定额代号,a.sczl_rq,a.sczl_装版总工时 as 换膜总工时,rtrim(b.Gd_cpmc) as 产品名称,rtrim(b.成品名称) as 成品名称')
  3314. ->where('a.UniqId',$param['UniqId'])
  3315. ->find();
  3316. for ($i=1;$i<11;$i++){
  3317. if (isset($list['sczl_bh'.$i])){
  3318. $name = \db('人事_基本资料')->where('员工编号',$list['sczl_bh'.$i])->field('员工姓名 as name')->find();
  3319. if (isset($name['name'])){
  3320. $list['组员'.$i] = $list['sczl_bh'.$i].$name['name'].'('.((float)$list['sczl_rate'.$i]*100).'%'.')';
  3321. $list['sczl_name'.$i] = $name['name'];
  3322. }else{
  3323. $list['sczl_name'.$i] = '';
  3324. }
  3325. }
  3326. }
  3327. if (!empty($list)){
  3328. $this->success('成功',$list);
  3329. }else{
  3330. $this->error('未找到数据');
  3331. }
  3332. }
  3333. /**
  3334. * 拉纸工数据导出
  3335. * @return void
  3336. * @throws \think\db\exception\DataNotFoundException
  3337. * @throws \think\db\exception\ModelNotFoundException
  3338. * @throws \think\exception\DbException
  3339. */
  3340. public function LazhiGongData()
  3341. {
  3342. if ($this->request->isGet() === false){
  3343. $this->error('请求错误');
  3344. }
  3345. $param = $this->request->param();
  3346. if (empty($param['mouth'])){
  3347. $this->error('请选择月份');
  3348. }
  3349. $filed = [
  3350. 'a.sczl_gdbh' => '工单编号',
  3351. 'b.yj_yjmc' => '产品名称',
  3352. 'a.sczl_num' => '流程单号',
  3353. 'a.sczl_yjno' => '印件号',
  3354. 'a.sczl_gxh' => '工序号',
  3355. 'a.sczl_jtbh' => '机台编号',
  3356. 'a.sczl_rq' => '日期',
  3357. 'a.sczl_type' => '工序名称',
  3358. 'a.sczl_cl' => '产量',
  3359. 'a.sczl_bh1' => '机长工号',
  3360. 'c1.员工姓名' => '机长姓名',
  3361. 'a.sczl_bh2' => '组员工号1',
  3362. 'c2.员工姓名' => '组员姓名1',
  3363. 'a.sczl_bh3' => '组员工号2',
  3364. 'c3.员工姓名' => '组员姓名2',
  3365. 'a.sczl_bh98' => '拉料工工号',
  3366. 'c4.员工姓名' => '拉料工姓名'
  3367. ];
  3368. $list = \db('设备_产量计酬')
  3369. ->alias('a')
  3370. ->join('工单_印件资料 b','a.sczl_gdbh = b.Yj_Gdbh AND a.sczl_yjno = b.yj_Yjno')
  3371. ->join('人事_基本资料 c1','a.sczl_bh1 = c1.员工编号','left')
  3372. ->join('人事_基本资料 c2','a.sczl_bh2 = c2.员工编号','left')
  3373. ->join('人事_基本资料 c3','a.sczl_bh3 = c3.员工编号','left')
  3374. ->join('人事_基本资料 c4','a.sczl_bh98 = c4.员工编号','left')
  3375. ->field($filed)
  3376. ->where('a.sczl_rq','like',$param['mouth'].'%')
  3377. ->where('a.sczl_bh98','<>','')
  3378. ->order('a.sczl_rq,a.sczl_jtbh')
  3379. ->select();
  3380. if (!empty($list)){
  3381. $this->success('成功',$list);
  3382. }else{
  3383. $this->error('未找到相关数据');
  3384. }
  3385. }
  3386. /**
  3387. * 检验记录
  3388. * @ApiMethod (GET)
  3389. * @param string $machine 机台编号
  3390. * @param string $workOrder 工单编号
  3391. * @param string $team 班次
  3392. * @return void
  3393. * @throws \think\db\exception\DataNotFoundException
  3394. * @throws \think\db\exception\ModelNotFoundException
  3395. * @throws \think\exception\DbException
  3396. */
  3397. public function ProcessInspectionRecord()
  3398. {
  3399. if ($this->request->isGet() === false){
  3400. $this->error('请求失败');
  3401. }
  3402. $machine = input('machine');
  3403. $date = input('date');
  3404. $team = input('team');
  3405. if (empty($machine) || empty($team) || empty($date)){
  3406. $this->success('');
  3407. }
  3408. $where = [
  3409. '设备编号' => $machine,
  3410. '班组编号' => ['like',$team.'%'],
  3411. '开工时间' => ['like',$date.'%'],
  3412. '类别' => ['in',['IPQC检验','机台检验','首件与过程确认']],
  3413. ];
  3414. //检测记录详情
  3415. $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(类别) as 类别,rtrim(流程单号) as 流程单号,
  3416. rtrim(检验项目) as 检验项目,rtrim(检验结果) as 检验结果,rtrim(量测仪器) as 量测仪器,rtrim(提交时间) as 提交时间';
  3417. $data = \db('制程检验_记录')->where($where)->field($field)->select();
  3418. $this->success('成功',$data);
  3419. }
  3420. /**
  3421. * 现场管理巡查统计左侧菜单
  3422. */
  3423. public function ManagementInspectionMenu()
  3424. {
  3425. if ($this->request->isGet() === false){
  3426. $this->error('请求错误');
  3427. }
  3428. $param = $this->request->param();
  3429. $where = [];
  3430. if (isset($param['machine'])){
  3431. $where['设备编号'] = $param['machine'];
  3432. }
  3433. // 添加最近一个月的时间条件
  3434. $oneMonthAgo = date('Y-m-d H:i:s', strtotime('-1 month'));
  3435. $where['提交时间'] = ['>=', $oneMonthAgo];
  3436. $rows = \db('制程检验_记录')->where($where)->field('设备编号,提交时间')->select();
  3437. // 机台 --> 使用部门 / 设备名称 映射
  3438. $machineInfo = [];
  3439. $machines = \db('设备_基本资料')
  3440. ->where('sys_sbID','<>','')
  3441. ->where('使用部门','<>','研发中心')
  3442. ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称,rtrim(使用部门) as 使用部门')
  3443. ->select();
  3444. foreach ($machines as $m) {
  3445. $machineInfo[$m['设备编号']] = $m;
  3446. }
  3447. // 使用部门 => 机台 => 日期列表
  3448. $data = [];
  3449. foreach ($rows as $row) {
  3450. $machine = trim($row['设备编号']);
  3451. if ($machine === ''){
  3452. continue;
  3453. }
  3454. $info = isset($machineInfo[$machine]) ? $machineInfo[$machine] : null;
  3455. $department = $info ? $info['使用部门'] : '未分类';
  3456. if ($department === ''){
  3457. $department = '未分类';
  3458. }
  3459. $machineName = $info ? $info['设备名称'] : '';
  3460. $machineLabel = ($machineName === '' || $machineName === null) ? $machine : $machine . '-->' . $machineName;
  3461. $date = date('Y-m-d', strtotime($row['提交时间']));
  3462. $data[$department][$machineLabel][$date] = $date;
  3463. }
  3464. // 部门按业务顺序:胶印车间 → 凹丝印车间 → 印后车间 → 其余按名称
  3465. $deptOrder = ['胶印车间' => 1, '凹丝印车间' => 2, '印后车间' => 3];
  3466. uksort($data, function ($a, $b) use ($deptOrder) {
  3467. $pa = isset($deptOrder[$a]) ? $deptOrder[$a] : 999;
  3468. $pb = isset($deptOrder[$b]) ? $deptOrder[$b] : 999;
  3469. if ($pa === $pb) {
  3470. return strcmp($a, $b);
  3471. }
  3472. return $pa <=> $pb;
  3473. });
  3474. foreach ($data as $department => &$machineList) {
  3475. ksort($machineList);
  3476. foreach ($machineList as $label => &$dates) {
  3477. $dates = array_values($dates);
  3478. rsort($dates);
  3479. }
  3480. unset($dates);
  3481. }
  3482. unset($machineList);
  3483. $this->success('成功',$data);
  3484. }
  3485. /**
  3486. * 管理巡查统计列表
  3487. */
  3488. public function ManagementInspectionList()
  3489. {
  3490. if ($this->request->isGet() === false){
  3491. $this->error('请求错误');
  3492. }
  3493. $param = $this->request->param();
  3494. if (empty($param['machine']) || empty($param['date']))
  3495. {
  3496. $this->error('参数错误');
  3497. }
  3498. $where = [
  3499. // '类别' => '现场巡查记录',
  3500. '设备编号' => $param['machine'],
  3501. '提交时间' => ['like',$param['date'].'%'],
  3502. ];
  3503. $field = '类别,工单编号,印件号,工序名称,流程单号,班组编号,检验项目,检验备注,提交时间,检验结果,相关标准 as 修改标准';
  3504. $rows = \db('制程检验_记录')->where($where)->field($field)->order('提交时间')->select();
  3505. // 按 提交时间 分组合并(与 ProductionLot::ProcessInspection 口径保持一致)
  3506. $grouped = [];
  3507. $orderKey = [];
  3508. foreach ($rows as $row) {
  3509. $key = (string)$row['提交时间'];
  3510. if (!isset($grouped[$key])) {
  3511. $grouped[$key] = [
  3512. '类别' => $row['类别'],
  3513. '工单编号' => $row['工单编号'],
  3514. '印件号' => $row['印件号'],
  3515. '工序名称' => $row['工序名称'],
  3516. '流程单号' => $row['流程单号'],
  3517. '班组编号' => $row['班组编号'],
  3518. '检验项目' => $row['检验项目'],
  3519. '检验备注' => $row['检验备注'],
  3520. '提交时间' => $row['提交时间'],
  3521. 'items' => [], // 这一次提交的所有项目
  3522. ];
  3523. $orderKey[] = $key;
  3524. }
  3525. $grouped[$key]['items'][] = $row;
  3526. }
  3527. // 检验项目:只放首个 + "共N项"
  3528. $result = [];
  3529. foreach ($orderKey as $key) {
  3530. $g = $grouped[$key];
  3531. $cnt = count($g['items']);
  3532. if ($cnt > 1) {
  3533. $g['检验项目'] = $g['items'][0]['检验项目'] . ' ... (共' . $cnt . '项)';
  3534. }
  3535. $result[] = $g;
  3536. }
  3537. $this->success('成功',$result);
  3538. }
  3539. /**
  3540. * 写入设备报工操作日志。日志失败不影响报工结果。
  3541. * @param array $rows
  3542. * @return void
  3543. */
  3544. protected function saveFacilityOperateLog(array $rows)
  3545. {
  3546. if (empty($rows)) {
  3547. return;
  3548. }
  3549. $now = date('Y-m-d H:i:s');
  3550. $logs = [];
  3551. foreach ($rows as $row) {
  3552. $logs[] = [
  3553. '业务表' => $this->facilityLogCut(isset($row['业务表']) ? $row['业务表'] : '', 50),
  3554. '操作类型' => $this->facilityLogCut(isset($row['操作类型']) ? $row['操作类型'] : '', 20),
  3555. '方法名' => $this->facilityLogCut(isset($row['方法名']) ? $row['方法名'] : '', 50),
  3556. 'RecordUniqid' => $this->facilityLogCut(isset($row['RecordUniqid']) ? $row['RecordUniqid'] : '', 50),
  3557. '设备编号' => $this->facilityLogCut(isset($row['设备编号']) ? $row['设备编号'] : '', 50),
  3558. '班组编号' => $this->facilityLogCut(isset($row['班组编号']) ? $row['班组编号'] : '', 50),
  3559. '工单编号' => $this->facilityLogCut(isset($row['工单编号']) ? $row['工单编号'] : '', 50),
  3560. '印件号' => $this->facilityLogCut(isset($row['印件号']) ? $row['印件号'] : '', 20),
  3561. '工序号' => $this->facilityLogCut(isset($row['工序号']) ? $row['工序号'] : '', 20),
  3562. '工序名称' => $this->facilityLogCut(isset($row['工序名称']) ? $row['工序名称'] : '', 100),
  3563. '字段名' => $this->facilityLogCut(isset($row['字段名']) ? $row['字段名'] : '', 50),
  3564. '修改前' => isset($row['修改前']) ? (string)$row['修改前'] : '',
  3565. '修改后' => isset($row['修改后']) ? (string)$row['修改后'] : '',
  3566. 'sys_id' => $this->facilityLogCut(isset($row['sys_id']) ? $row['sys_id'] : '', 50),
  3567. 'sys_rq' => $now,
  3568. '备注' => $this->facilityLogCut(isset($row['备注']) ? $row['备注'] : '', 500),
  3569. ];
  3570. }
  3571. try {
  3572. \db('设备报工操作日志')->insertAll($logs);
  3573. } catch (\Exception $e) {
  3574. Log::write('记录设备报工操作日志失败: ' . $e->getMessage());
  3575. }
  3576. }
  3577. /**
  3578. * 从请求中取操作人。业务表没有该字段时只用于日志。
  3579. * @param array|null $source
  3580. * @return string
  3581. */
  3582. protected function facilityLogOperator($source = null)
  3583. {
  3584. if (is_array($source)) {
  3585. foreach (['sys_id', 'Sys_id'] as $key) {
  3586. if (isset($source[$key]) && $source[$key] !== '' && $source[$key] !== null) {
  3587. return trim((string)$source[$key]);
  3588. }
  3589. }
  3590. }
  3591. $operator = input('sys_id');
  3592. if ($operator === null || $operator === '') {
  3593. $operator = input('Sys_id');
  3594. }
  3595. if ($operator === null || $operator === '' || is_array($operator)) {
  3596. return '';
  3597. }
  3598. return trim((string)$operator);
  3599. }
  3600. /**
  3601. * @param mixed $value
  3602. * @param int $length
  3603. * @return string
  3604. */
  3605. protected function facilityLogCut($value, $length)
  3606. {
  3607. $value = trim((string)$value);
  3608. if ($value === '') {
  3609. return '';
  3610. }
  3611. if (function_exists('mb_substr')) {
  3612. return mb_substr($value, 0, $length, 'UTF-8');
  3613. }
  3614. return substr($value, 0, $length);
  3615. }
  3616. /**
  3617. * 按字段对比,只保留有变化的项
  3618. * @param array $base
  3619. * @param array $before
  3620. * @param array $after
  3621. * @param array $skip
  3622. * @return array
  3623. */
  3624. protected function facilityChangedLogs(array $base, array $before, array $after, array $skip = [])
  3625. {
  3626. $skip = array_merge(['mod_rq', 'Mod_rq', 'sys_rq', 'Sys_rq', 'UniqId', 'UniqID', 'Uniqid', 'sys_id', 'Sys_id'], $skip);
  3627. $logs = [];
  3628. foreach ($after as $field => $newValue) {
  3629. if (in_array($field, $skip, true) || is_array($newValue)) {
  3630. continue;
  3631. }
  3632. $oldText = array_key_exists($field, $before) ? trim((string)$before[$field]) : '';
  3633. $newText = trim((string)$newValue);
  3634. if ($oldText === $newText) {
  3635. continue;
  3636. }
  3637. $item = $base;
  3638. $item['字段名'] = $field;
  3639. $item['修改前'] = $oldText;
  3640. $item['修改后'] = $newText;
  3641. $logs[] = $item;
  3642. }
  3643. return $logs;
  3644. }
  3645. /**
  3646. * @param array $row
  3647. * @return string
  3648. */
  3649. protected function facilityTeamMemberText(array $row)
  3650. {
  3651. $members = [];
  3652. for ($i = 1; $i < 11; $i++) {
  3653. $code = isset($row['sczl_bh'.$i]) ? trim((string)$row['sczl_bh'.$i]) : '';
  3654. if ($code !== '' && $code !== '0') {
  3655. $members[] = $code;
  3656. }
  3657. }
  3658. $teamCode = isset($row['sczl_bzdh']) ? trim((string)$row['sczl_bzdh']) : '';
  3659. return '班组编号='.$teamCode.';成员='.implode(',', $members);
  3660. }
  3661. /**
  3662. * @param array $row
  3663. * @param string $action
  3664. * @param string $method
  3665. * @param string $operator
  3666. * @return array
  3667. */
  3668. protected function facilityYieldLogBase(array $row, $action, $method, $operator)
  3669. {
  3670. $uniqid = '';
  3671. if (isset($row['UniqId'])) {
  3672. $uniqid = $row['UniqId'];
  3673. } elseif (isset($row['UniqID'])) {
  3674. $uniqid = $row['UniqID'];
  3675. }
  3676. return [
  3677. '业务表' => '设备_产量计酬',
  3678. '操作类型' => $action,
  3679. '方法名' => $method,
  3680. 'RecordUniqid' => trim((string)$uniqid),
  3681. '设备编号' => isset($row['sczl_jtbh']) ? trim((string)$row['sczl_jtbh']) : '',
  3682. '班组编号' => isset($row['sczl_bzdh']) ? trim((string)$row['sczl_bzdh']) : '',
  3683. '工单编号' => isset($row['sczl_gdbh']) ? trim((string)$row['sczl_gdbh']) : '',
  3684. '印件号' => isset($row['sczl_yjno']) ? trim((string)$row['sczl_yjno']) : '',
  3685. '工序号' => isset($row['sczl_gxh']) ? trim((string)$row['sczl_gxh']) : '',
  3686. '工序名称' => isset($row['sczl_gxmc']) ? trim((string)$row['sczl_gxmc']) : '',
  3687. 'sys_id' => $operator,
  3688. ];
  3689. }
  3690. }