Facility.php 142 KB

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