ApplyOrderService.php 205 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565
  1. <?php
  2. namespace App\Service;
  3. use App\Model\ApplyOrder;
  4. use App\Model\ApplyOrderDetail;
  5. use App\Model\Box;
  6. use App\Model\BoxDetail;
  7. use App\Model\BoxWithDispatch;
  8. use App\Model\Dispatch;
  9. use App\Model\DispatchSub;
  10. use App\Model\Employee;
  11. use App\Model\EmployeeTeamPermission;
  12. use App\Model\Equipment;
  13. use App\Model\InOutRecord;
  14. use App\Model\OrdersProduct;
  15. use App\Model\Process;
  16. use App\Model\ReportMessage;
  17. use App\Model\ReportWorking;
  18. use App\Model\ReportWorkingDetail;
  19. use App\Model\SaleOrdersProduct;
  20. use App\Model\ScrappCount;
  21. use App\Model\Team;
  22. use App\Service\Box\BoxService;
  23. use Illuminate\Support\Facades\DB;
  24. class ApplyOrderService extends Service
  25. {
  26. public function MaterialEdit($data, $user){
  27. list($status,$msg) = $this->MaterialRule($data,false);
  28. if(!$status) return [$status,$msg];
  29. DB::beginTransaction();
  30. try{
  31. $time = time();
  32. $model = new ApplyOrder();
  33. $model = $model->where('id',$data['id'])->first();
  34. $model->apply_id = $data['apply_id'];
  35. $model->apply_time = $data['apply_time'] ;
  36. $model->mark = $data['mark'] ?? "";
  37. $model->storehouse_id = $data['storehouse_id'];
  38. $model->storehouse_title = $data['storehouse_title'] ?? "";
  39. $model->type = $data['type'];
  40. $model->save();
  41. $id = $model->id;
  42. ApplyOrderDetail::where('del_time',0)->where('apply_order_id',$id)->update([
  43. 'del_time' => $time
  44. ]);
  45. $detail_insert = [];
  46. foreach ($data['order_data'] as $v){
  47. $detail_insert[] = [
  48. 'apply_order_id' => $id,
  49. 'data_id' => $v['id'],
  50. 'quantity' => $v['quantity'] ?? 0,
  51. 'product_no' => $v['product_no'] ?? "",
  52. 'product_title' => $v['product_title'] ?? "",
  53. 'product_size' => $v['product_size'] ?? "",
  54. 'product_unit' => $v['product_unit'] ?? "",
  55. 'technology_name' => $v['technology_name'] ?? "", //颜色
  56. 'top_product_title' => $v['top_product_title'] ?? "",
  57. 'top_product_no' => $v['top_product_title'] ?? "",
  58. 'type' => $data['type'],
  59. 'storehouse_id' => $data['storehouse_id'],
  60. 'crt_time' => $time,
  61. ];
  62. }
  63. ApplyOrderDetail::insert($detail_insert);
  64. DB::commit();
  65. }catch (\Exception $e){
  66. DB::rollBack();
  67. return [false,$e->getMessage()];
  68. }
  69. return [true,''];
  70. }
  71. public function MaterialAdd($data,$user){
  72. list($status,$msg) = $this->MaterialRule($data);
  73. if(!$status) return [$status,$msg];
  74. DB::beginTransaction();
  75. try{
  76. $time = time();
  77. $model = new ApplyOrder();
  78. $model->order_number = $data['order_number'];
  79. $model->apply_id = $data['apply_id'];
  80. $model->apply_time = $data['apply_time'] ;
  81. $model->mark = $data['mark'] ?? "";
  82. $model->storehouse_id = $data['storehouse_id'];
  83. $model->storehouse_title = $data['storehouse_title'] ?? "";
  84. $model->type = $data['type'];
  85. $model->crt_id = $user['id'];
  86. $model->save();
  87. $id = $model->id;
  88. $detail_insert = [];
  89. foreach ($data['order_data'] as $v){
  90. $detail_insert[] = [
  91. 'apply_order_id' => $id,
  92. 'data_id' => $v['id'],
  93. 'quantity' => $v['quantity'] ?? 0,
  94. 'product_no' => $v['product_no'] ?? "",
  95. 'product_title' => $v['product_title'] ?? "",
  96. 'product_size' => $v['product_size'] ?? "",
  97. 'product_unit' => $v['product_unit'] ?? "",
  98. 'technology_name' => $v['technology_name'] ?? "", //颜色
  99. 'top_product_title' => $v['top_product_title'] ?? "",
  100. 'top_product_no' => $v['top_product_title'] ?? "",
  101. 'type' => $data['type'],
  102. 'storehouse_id' => $data['storehouse_id'],
  103. 'crt_time' => $time,
  104. ];
  105. }
  106. ApplyOrderDetail::insert($detail_insert);
  107. DB::commit();
  108. }catch (\Exception $e){
  109. DB::rollBack();
  110. return [false,$e->getMessage()];
  111. }
  112. return [true, ''];
  113. }
  114. public function MaterialDel($data){
  115. if($this->isEmpty($data,'id')) return [false,'ID必须!'];
  116. $apply = ApplyOrder::where('id',$data['id'])->first();
  117. if($apply->del_time > 0) return [false,'申请单不存在或已被删除'];
  118. if($apply->state != ApplyOrder::state_zero) return [false, '申请单已审核,删除失败'];
  119. $time = time();
  120. try {
  121. DB::beginTransaction();
  122. $apply->del_time = $time;
  123. $apply->save();
  124. ApplyOrderDetail::where('del_time', 0)->where('apply_order_id',$data['id'])->update([
  125. 'del_time'=>time()
  126. ]);
  127. DB::commit();
  128. }catch (\Throwable $exception){
  129. DB::rollBack();
  130. return [false, $exception->getMessage()];
  131. }
  132. return [true,''];
  133. }
  134. public function MaterialList($data){
  135. $model = ApplyOrder::where('del_time',0)
  136. ->select('*')
  137. ->orderBy('id','desc');
  138. if(isset($data['status'])) $model->where('status', $data['status']);
  139. if(! empty($data['type'])) $model->where('type', $data['type']);
  140. if(! empty($data['storehouse_title'])) $model->where('storehouse_title', 'LIKE', '%'.$data['storehouse_title'].'%');
  141. if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
  142. if(! empty($data['apply_id'])) $model->where('apply_id', $data['apply_id']);
  143. if(! empty($data['pc_number'])) {
  144. if(in_array($data['type'], [ApplyOrder::type_one,ApplyOrder::type_two])){
  145. $dispatch_id = DispatchSub::where('del_time',0)
  146. ->where('out_order_no', 'LIKE', '%'.$data['pc_number'].'%')
  147. ->select('id')
  148. ->get()->toArray();
  149. $dispatch_id = array_column($dispatch_id,'id');
  150. $detail = ApplyOrderDetail::where('del_time',0)
  151. ->where('type', $data['type'])
  152. ->whereIn('data_id', $dispatch_id)
  153. ->select('apply_order_id')
  154. ->get()->toArray();
  155. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  156. }elseif($data['type'] == ApplyOrder::type_five){
  157. $zj_id = ScrappCount::where('del_time',0)
  158. ->where('out_order_no', 'LIKE', '%'.$data['pc_number'].'%')
  159. ->select('id')
  160. ->get()->toArray();
  161. $zj_id = array_column($zj_id,'id');
  162. $detail = ApplyOrderDetail::where('del_time',0)
  163. ->where('type', $data['type'])
  164. ->whereIn('data_id', $zj_id)
  165. ->select('apply_order_id')
  166. ->get()->toArray();
  167. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  168. }else{
  169. $no = SaleOrdersProduct::where('del_time',0)
  170. ->where('out_order_no', 'LIKE', '%'.$data['pc_number'].'%')
  171. ->select('order_no')
  172. ->get()->toArray();
  173. $no = array_unique(array_column($no,'order_no'));
  174. $box_id = Box::where('del_time',0)
  175. ->whereIn('top_order_no', $no)
  176. ->select('id')
  177. ->get()->toArray();
  178. $box_id = array_column($box_id,'id');
  179. $detail = ApplyOrderDetail::where('del_time',0)
  180. ->where('type', $data['type'])
  181. ->whereIn('data_id', $box_id)
  182. ->select('apply_order_id')
  183. ->get()->toArray();
  184. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  185. }
  186. }
  187. if(! empty($data['crt_id'])) $model->where('crt_id', $data['crt_id']);
  188. if(! empty($data['apply_time'][0]) && ! empty($data['apply_time'][1])) $model->whereBetween('apply_time',[$data['apply_time'][0],$data['apply_time'][1]]);
  189. if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) $model->whereBetween('crt_time',[$data['crt_time'][0],$data['crt_time'][1]]);
  190. if(! empty($data['dispatch_no'])){
  191. $dispatch_id = DispatchSub::where('del_time',0)
  192. ->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%')
  193. ->select('id')
  194. ->get()->toArray();
  195. $dispatch_id = array_column($dispatch_id,'id');
  196. $detail = ApplyOrderDetail::where('del_time',0)
  197. ->where('type', $data['type'])
  198. ->whereIn('data_id', $dispatch_id)
  199. ->select('apply_order_id')
  200. ->get()->toArray();
  201. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  202. }
  203. if(! empty($data['box_no'])){
  204. $box_id = Box::where('del_time',0)
  205. ->where('order_no', 'LIKE', '%'.$data['box_no'].'%')
  206. ->select('id')
  207. ->get()->toArray();
  208. $box_id = array_column($box_id,'id');
  209. $detail = ApplyOrderDetail::where('del_time',0)
  210. ->where('type', $data['type'])
  211. ->whereIn('data_id', $box_id)
  212. ->select('apply_order_id')
  213. ->get()->toArray();
  214. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  215. }
  216. if(! empty($data['sale_order_number'])){
  217. if(in_array($data['type'], [ApplyOrder::type_one,ApplyOrder::type_two])){
  218. $dispatch_id = DispatchSub::where('del_time',0)
  219. ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
  220. ->select('id')
  221. ->get()->toArray();
  222. $dispatch_id = array_column($dispatch_id,'id');
  223. $detail = ApplyOrderDetail::where('del_time',0)
  224. ->where('type', $data['type'])
  225. ->whereIn('data_id', $dispatch_id)
  226. ->select('apply_order_id')
  227. ->get()->toArray();
  228. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  229. }elseif($data['type'] == ApplyOrder::type_five){
  230. $zj_id = ScrappCount::where('del_time',0)
  231. ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
  232. ->select('id')
  233. ->get()->toArray();
  234. $zj_id = array_column($zj_id,'id');
  235. $detail = ApplyOrderDetail::where('del_time',0)
  236. ->where('type', $data['type'])
  237. ->whereIn('data_id', $zj_id)
  238. ->select('apply_order_id')
  239. ->get()->toArray();
  240. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  241. }else{
  242. $no = SaleOrdersProduct::where('del_time',0)
  243. ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
  244. ->select('order_no')
  245. ->get()->toArray();
  246. $no = array_unique(array_column($no,'order_no'));
  247. $box_id = Box::where('del_time',0)
  248. ->whereIn('top_order_no', $no)
  249. ->select('id')
  250. ->get()->toArray();
  251. $box_id = array_column($box_id,'id');
  252. $detail = ApplyOrderDetail::where('del_time',0)
  253. ->where('type', $data['type'])
  254. ->whereIn('data_id', $box_id)
  255. ->select('apply_order_id')
  256. ->get()->toArray();
  257. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  258. }
  259. }
  260. $list = $this->limit($model,'',$data);
  261. $list = $this->fillData($list);
  262. return [true,$list];
  263. }
  264. public function fillData($data){
  265. if(empty($data['data'])) return $data;
  266. $emp = Employee::whereIn('id',array_merge_recursive(array_unique(array_column($data['data'],'crt_id')), array_unique(array_column($data['data'],'apply_id'))))
  267. ->pluck('emp_name','id')
  268. ->toArray();
  269. $array1 = $array2 = $array3 = [];
  270. foreach ($data['data'] as $value){
  271. if(in_array($value['type'], [ApplyOrder::type_one,ApplyOrder::type_two])){
  272. $array1[] = $value['id'];
  273. }elseif ($value['type'] == ApplyOrder::type_five){
  274. $array3[] = $value['id'];
  275. }else{
  276. $array2[] = $value['id'];
  277. }
  278. }
  279. $order1 = ApplyOrderDetail::whereIn('type',[ApplyOrder::type_one,ApplyOrder::type_two])
  280. ->whereIn('apply_order_id', $array1)
  281. ->select('data_id','apply_order_id')
  282. ->get()->toArray();
  283. $order1_map = [];
  284. foreach ($order1 as $value){
  285. $order1_map[$value['apply_order_id']][] = $value['data_id'];
  286. }
  287. $order2 = ApplyOrderDetail::whereNotIn('type',[ApplyOrder::type_one,ApplyOrder::type_two,ApplyOrder::type_five])
  288. ->whereIn('apply_order_id', $array2)
  289. ->select('data_id','apply_order_id')
  290. ->get()->toArray();
  291. $order2_map = [];
  292. foreach ($order2 as $value){
  293. $order2_map[$value['apply_order_id']][] = $value['data_id'];
  294. }
  295. $order3 = ApplyOrderDetail::whereIn('type',[ApplyOrder::type_five])
  296. ->whereIn('apply_order_id', $array3)
  297. ->select('data_id','apply_order_id')
  298. ->get()->toArray();
  299. $order3_map = [];
  300. foreach ($order3 as $value){
  301. $order3_map[$value['apply_order_id']][] = $value['data_id'];
  302. }
  303. $map1 = DispatchSub::whereIn('id', array_unique(array_column($order1,'data_id')))
  304. ->pluck('out_order_no','id')
  305. ->toArray();
  306. $map2 = Box::whereIn('id', array_unique(array_column($order2,'data_id')))
  307. ->pluck('top_order_no','id')
  308. ->toArray();
  309. $map2_fin = SaleOrdersProduct::whereIn('order_no',array_unique(array_values($map2)))
  310. ->pluck('out_order_no','order_no')
  311. ->toArray();
  312. $map3 = ScrappCount::whereIn('id', array_unique(array_column($order3,'data_id')))
  313. ->pluck('out_order_no','id')
  314. ->toArray();
  315. foreach ($data['data'] as $key => $value){
  316. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d',$value['crt_time']) : '';
  317. $data['data'][$key]['apply_time'] = $value['apply_time'] ? date('Y-m-d',$value['apply_time']) : '';
  318. $data['data'][$key]['status_title'] = ApplyOrder::$state_name[$value['status']] ?? "";
  319. $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
  320. $data['data'][$key]['apply_name'] = $emp[$value['apply_id']] ?? '';
  321. if(in_array($value['type'], [ApplyOrder::type_one,ApplyOrder::type_two])){
  322. $order_tmp = $order1_map[$value['id']] ?? [];
  323. $order_tmp = array_unique($order_tmp);
  324. $sale_order_number = [];
  325. foreach ($order_tmp as $v){
  326. $str = $map1[$v] ?? '';
  327. if(empty($str)) continue;
  328. $sale_order_number[] = $str;
  329. }
  330. $sale_order_number = array_unique($sale_order_number);
  331. $sale_order_number = implode(',',$sale_order_number);
  332. $data['data'][$key]['sale_order_number'] = $sale_order_number;
  333. }elseif ($value['type'] == ApplyOrder::type_five){
  334. $order_tmp = $order3_map[$value['id']] ?? [];
  335. $order_tmp = array_unique($order_tmp);
  336. $sale_order_number = [];
  337. foreach ($order_tmp as $v){
  338. $str = $map3[$v] ?? '';
  339. if(empty($str)) continue;
  340. $sale_order_number[] = $str;
  341. }
  342. $sale_order_number = array_unique($sale_order_number);
  343. $sale_order_number = implode(',',$sale_order_number);
  344. $data['data'][$key]['sale_order_number'] = $sale_order_number;
  345. }else{
  346. $order_tmp = $order2_map[$value['id']] ?? [];
  347. $order_tmp = array_unique($order_tmp);
  348. $sale_order_number = [];
  349. foreach ($order_tmp as $v){
  350. $m2_t = $map2[$v] ?? '';
  351. $m2_t = $map2_fin[$m2_t] ?? "";
  352. if(empty($m2_t)) continue;
  353. $sale_order_number[] = $m2_t;
  354. }
  355. $sale_order_number = array_unique($sale_order_number);
  356. $sale_order_number = implode(',',$sale_order_number);
  357. $data['data'][$key]['sale_order_number'] = $sale_order_number;
  358. }
  359. }
  360. return $data;
  361. }
  362. public function MaterialDetail($data){
  363. if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
  364. $id = $data['id'];
  365. $detail = ApplyOrder::where('del_time',0)
  366. ->where('id',$id)
  367. ->first();
  368. if(empty($detail)) return [false,'申请单不存在或已被删除'];
  369. $detail = $detail->toArray();
  370. $detail['apply_time'] = $detail['apply_time'] ? date('Y-m-d',$detail['apply_time']) : '';
  371. $detail['apply_title'] = Employee::where('id', $detail['apply_id'])->value('emp_name');
  372. $apply_d = ApplyOrderDetail::where('del_time', 0)
  373. ->where('apply_order_id', $id)
  374. ->get()->toArray();
  375. $apply_id = array_column($apply_d, 'data_id');
  376. $d = [];
  377. $out_order_no = "";
  378. if($detail['type'] == ApplyOrder::type_one){
  379. $d = DispatchSub::where('del_time',0)
  380. ->whereIn('id', $apply_id)
  381. ->select('id', 'dispatch_no as order_no', 'product_title','technology_name','wood_name','product_no','order_product_id','crt_time','out_order_no')
  382. ->get()->toArray();
  383. $out_order_no = $d[0]['out_order_no'] ?? "";
  384. $args = "";
  385. foreach ($d as $value){
  386. $args = "(order_product_id = {$value['order_product_id']} and crt_time = {$value['crt_time']}) OR ";
  387. }
  388. $args = rtrim($args, 'OR ');
  389. $d_no_map = [];
  390. $d_no = DispatchSub::where('del_time',0)
  391. ->whereRaw($args)
  392. ->select('dispatch_no as order_no','order_product_id','crt_time')
  393. ->get()->toArray();
  394. foreach ($d_no as $value){
  395. if(! isset($d_no_map[$value['order_product_id'] . $value['crt_time']])){
  396. $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
  397. }
  398. // if(isset($d_no_map[$value['order_product_id'] . $value['crt_time']])){
  399. // if(! in_array($value['order_no'], $d_no_map[$value['order_product_id'] . $value['crt_time']])) $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
  400. // }else{
  401. // $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
  402. // }
  403. }
  404. }elseif ($detail['type'] == ApplyOrder::type_two){
  405. $d = DispatchSub::where('del_time',0)
  406. ->whereIn('id', $apply_id)
  407. ->select('id','out_order_no', 'dispatch_no as order_no','technology_name','wood_name','order_product_id','crt_time')
  408. ->get()->toArray();
  409. $out_order_no = $d[0]['out_order_no'] ?? "";
  410. $args = "";
  411. foreach ($d as $value){
  412. $args = "(order_product_id = {$value['order_product_id']} and crt_time = {$value['crt_time']}) OR ";
  413. }
  414. $args = rtrim($args, 'OR ');
  415. $d_no_map = [];
  416. $d_no = DispatchSub::where('del_time',0)
  417. ->whereRaw($args)
  418. ->select('dispatch_no as order_no','order_product_id','crt_time')
  419. ->get()->toArray();
  420. foreach ($d_no as $value){
  421. if(! isset($d_no_map[$value['order_product_id'] . $value['crt_time']])){
  422. $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
  423. }
  424. // if(isset($d_no_map[$value['order_product_id'] . $value['crt_time']])){
  425. // if(! in_array($value['order_no'], $d_no_map[$value['order_product_id'] . $value['crt_time']])) $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
  426. // }else{
  427. // $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
  428. // }
  429. }
  430. }elseif ($detail['type'] == ApplyOrder::type_three){
  431. $d = Box::where('del_time',0)
  432. ->whereIn('id', $apply_id)
  433. ->select('id', 'order_no','top_order_no')
  434. ->get()->toArray();
  435. $map2_fin = SaleOrdersProduct::whereIn('order_no',array_column($d,'top_order_no'))
  436. ->pluck('out_order_no','order_no')
  437. ->toArray();
  438. foreach ($d as $value){
  439. $out_order_no = $map2_fin[$value['top_order_no']] ?? "";
  440. }
  441. }elseif ($detail['type'] == ApplyOrder::type_four){
  442. $d = Box::where('del_time',0)
  443. ->whereIn('id', $apply_id)
  444. ->select('id', 'order_no','top_order_no')
  445. ->get()->toArray();
  446. $map2_fin = SaleOrdersProduct::whereIn('order_no',array_column($d,'top_order_no'))
  447. ->pluck('out_order_no','order_no')
  448. ->toArray();
  449. foreach ($d as $value){
  450. $out_order_no = $map2_fin[$value['top_order_no']] ?? "";
  451. }
  452. }elseif ($detail['type'] == ApplyOrder::type_five){ //质检入库申请
  453. $d = ScrappCount::where('del_time',0)
  454. ->whereIn('id', $apply_id)
  455. ->select('id', 'out_order_no','order_number as order_no', 'product_title','technology_name','wood_name','product_no','order_product_id','crt_time')
  456. ->get()->toArray();
  457. $out_order_no = $d[0]['out_order_no'] ?? "";
  458. }elseif ($detail['type'] == ApplyOrder::type_six){
  459. $d = Box::where('del_time',0)
  460. ->whereIn('id', $apply_id)
  461. ->select('id', 'order_no','top_order_no')
  462. ->get()->toArray();
  463. $map2_fin = SaleOrdersProduct::whereIn('order_no',array_column($d,'top_order_no'))
  464. ->pluck('out_order_no','order_no')
  465. ->toArray();
  466. foreach ($d as $value){
  467. $out_order_no = $map2_fin[$value['top_order_no']] ?? "";
  468. }
  469. }
  470. $detail['sale_order_number'] = $out_order_no;
  471. $d_tmp = array_column($d,null,'id');
  472. $return = [];
  473. foreach ($apply_d as $t){
  474. $tmp = $d_tmp[$t['data_id']] ?? [];
  475. $technology_name = ! empty($t['technology_name']) ? $t['technology_name'] : $tmp['technology_name'] ?? "";
  476. $wood_name = ! empty($t['wood_name']) ? $t['wood_name'] : $tmp['wood_name'] ?? "";
  477. $top_product_title = ! empty($t['top_product_title']) ? $t['top_product_title'] : $tmp['product_title'] ?? "";
  478. $top_product_no = ! empty($t['top_product_no']) ? $t['top_product_no'] : $tmp['product_no'] ?? "";
  479. if(! empty($tmp['order_product_id']) && ! empty($tmp['crt_time']) && isset($d_no_map[$tmp['order_product_id'] . $tmp['crt_time']])){
  480. $order_no = implode(',', array_values($d_no_map[$tmp['order_product_id'] . $tmp['crt_time']]));
  481. }else{
  482. $order_no = $tmp['order_no'] ?? "";
  483. }
  484. if($t['type'] == ApplyOrder::type_two || $t['type'] == ApplyOrder::type_three){
  485. $product_unit = "吨";
  486. }else{
  487. $product_unit = $t['product_unit'] ?? "";
  488. }
  489. $return[] = [
  490. 'id' => $t['data_id'] ?? 0,
  491. 'quantity' => $t['quantity'] ?? 0,
  492. 'product_no' => $t['product_no'] ?? "",
  493. 'product_title' => $t['product_title'] ?? "",
  494. 'product_size' => $t['product_size'] ?? "",
  495. 'product_unit' => $product_unit,
  496. 'top_product_title' => $top_product_title,
  497. 'top_product_no' => $top_product_no,
  498. 'technology_name' => $technology_name, //颜色
  499. 'wood_name' => $wood_name,
  500. 'order_no' => $order_no,
  501. ];
  502. }
  503. $detail['order_data'] = $return;
  504. return [true, $detail];
  505. }
  506. public function MaterialRule(&$data,$is_add = true){
  507. if($this->isEmpty($data,'apply_id')) return [false,'申请人不能为空'];
  508. if($this->isEmpty($data,'apply_time')) return [false,'申请时间不能为空'];
  509. if($this->isEmpty($data,'storehouse_id')) return [false,'仓库不能为空'];
  510. if($this->isEmpty($data,'type')) return [false,'申请单类型不能为空'];
  511. if(empty($data['order_data'])) return [false, '申请单详细信息不能为空'];
  512. foreach ($data['order_data'] as $value){
  513. if(empty($value['id'])) return [false, '申请单详细信息ID不能为空'];
  514. if($data['type'] != ApplyOrder::type_three){
  515. if(empty($value['quantity'])) return [false, '申请单详细信息数量不能为空'];
  516. }
  517. }
  518. $id = array_unique(array_column($data['order_data'],'id'));
  519. if($data['type'] == ApplyOrder::type_one){
  520. $dispatch = DispatchSub::where('del_time',0)
  521. ->whereIn('id', $id)
  522. ->select('id', 'dispatch_no', 'status')
  523. ->get()->toArray();
  524. if(count($dispatch) != count($id)) return [false, '派工单信息错误,请重新选择'];
  525. }elseif ($data['type'] == ApplyOrder::type_two){
  526. $dispatch = DispatchSub::where('del_time',0)
  527. ->whereIn('id', $id)
  528. ->select('id', 'dispatch_no', 'status')
  529. ->get()->toArray();
  530. if(count($dispatch) != count($id)) return [false, '完工单信息错误,请重新选择'];
  531. }elseif ($data['type'] == ApplyOrder::type_three){
  532. $box = Box::where('del_time',0)
  533. ->whereIn('id', $id)
  534. ->select('id', 'order_no', 'status')
  535. ->get()->toArray();
  536. if(count($box) != count($id)) return [false, '包装单信息错误,请重新选择'];
  537. }elseif ($data['type'] == ApplyOrder::type_four){
  538. $box = Box::where('del_time',0)
  539. ->whereIn('id', $id)
  540. ->select('id', 'order_no', 'status')
  541. ->get()->toArray();
  542. if(count($box) != count($id)) return [false, '包装单信息错误,请重新选择'];
  543. }elseif ($data['type'] == ApplyOrder::type_five){
  544. $scrapp = ScrappCount::where('del_time',0)
  545. ->whereIn('id', $id)
  546. ->select('id', 'order_no', 'status')
  547. ->get()->toArray();
  548. if(count($scrapp) != count($id)) return [false, '质检单信息错误,请重新选择'];
  549. }else{
  550. return [false, '申请单类型错误'];
  551. }
  552. if($is_add){
  553. $data['order_number'] = $this->setOrderNO($data['type']);
  554. if(empty($data['order_number'])) return [false, '申请单唯一标识生成失败'];
  555. }else{
  556. if(empty($data['id'])) return [false, '申请单唯一标识不能为空'];
  557. if(empty($data['order_number'])) return [false, '申请单唯一标识不能为空'];
  558. $apply = ApplyOrder::where('id', $data['id'])->where('del_time', 0)->first();
  559. if(empty($apply)) return [false, '申请单不存在或已被删除'];
  560. if($apply->status != 0) return [false, '申请单已审核,编辑失败'];
  561. }
  562. return [true,''];
  563. }
  564. public function setOrderNO($type = "",$time = 0){
  565. if(empty($time)){
  566. $str = date('Ymd',time());
  567. }else{
  568. $str = date('Ymd',$time);
  569. }
  570. $order_number = ApplyOrder::where('order_number','Like','%'. $str . '%')
  571. ->where('type', $type)
  572. ->max('order_number');
  573. if(empty($order_number)){
  574. $number = str_pad(1,3,'0',STR_PAD_LEFT);
  575. $number = $str . $number;
  576. }else{
  577. $tmp = substr($order_number, -3);
  578. $tmp = $tmp + 1;
  579. //超过999
  580. // if(strlen($tmp) > 3) return '';
  581. $number = str_pad($tmp,3,'0',STR_PAD_LEFT);
  582. $number = $str . $number;
  583. }
  584. return $number;
  585. }
  586. public function createSQ($data, $user, $type = 0, $status = 1,$time = 0){
  587. if(empty($data) || empty($type)) return [false, '自动生成申请单参数不能为空'];
  588. if($type == ApplyOrder::type_one){
  589. $storehouse_id = "001";
  590. $storehouse_title = "原料仓";
  591. }elseif ($type == ApplyOrder::type_two){
  592. $storehouse_id = "004";
  593. $storehouse_title = "待清洗原材料仓";
  594. }elseif ($type == ApplyOrder::type_three){
  595. $storehouse_id = "002";
  596. $storehouse_title = "产成品仓";
  597. }elseif($type == ApplyOrder::type_four){
  598. $storehouse_id = "003";
  599. $storehouse_title = "包材、辅料仓" ;
  600. }elseif ($type == ApplyOrder::type_six){
  601. $storehouse_id = "004";
  602. $storehouse_title = "待清洗原材料仓";
  603. }
  604. try{
  605. DB::beginTransaction();
  606. $order_number = $this->setOrderNO($type, $time);
  607. // list($status,$msg) = $this->limitingSendRequestBackg("spAdd" . $order_number . $type);
  608. // if(! $status) return [false, $msg];
  609. if(empty($time)) $time = time();
  610. $model = new ApplyOrder();
  611. $model->order_number = $order_number;
  612. $model->apply_id = $user['id'];
  613. $model->apply_time = $time;
  614. $model->storehouse_id = $storehouse_id;
  615. $model->storehouse_title = $storehouse_title;
  616. $model->type = $type;
  617. $model->status = $status; //是否审核
  618. $model->save();
  619. $id = $model->id;
  620. $detail_insert = [];
  621. foreach ($data as $v){
  622. $detail_insert[] = [
  623. 'apply_order_id' => $id,
  624. 'data_id' => $v['id'],
  625. 'quantity' => $v['quantity'] ?? 0,
  626. 'product_no' => $v['product_no'] ?? "",
  627. 'product_title' => $v['product_title'] ?? "",
  628. 'product_size' => $v['product_size'] ?? "",
  629. 'product_unit' => $v['product_unit'] ?? "",
  630. 'technology_name' => $v['technology_name'] ?? "",
  631. 'wood_name' => $v['wood_name'] ?? "",
  632. 'top_product_no' => $v['top_product_no'] ?? "",
  633. 'top_product_title' => $v['top_product_title'] ?? "",
  634. 'type' => $type,
  635. 'storehouse_id' => $storehouse_id,
  636. 'crt_time' => $time,
  637. ];
  638. }
  639. ApplyOrderDetail::insert($detail_insert);
  640. DB::commit();
  641. }catch (\Exception $e){
  642. DB::rollBack();
  643. return [false,$e->getMessage()];
  644. }
  645. return [true, $id];
  646. }
  647. public function createSqFive($data, $user, $type = 0, $status = 1, $time = 0){
  648. if(empty($data) || empty($type)) return [false, '自动生成申请单参数不能为空'];
  649. try{
  650. DB::beginTransaction();
  651. if(empty($time)) $time = time();
  652. $first = $data[0] ?? [];
  653. $order_number = $this->setOrderNO($type, $time);
  654. $model = new ApplyOrder();
  655. $model->order_number = $order_number;
  656. $model->apply_id = $user['id'];
  657. $model->apply_time = $time;
  658. $model->storehouse_id = $first['storehouse_id'];
  659. $model->storehouse_title = $first['storehouse_title'];
  660. $model->type = $type;
  661. $model->status = $status; //是否审核
  662. $model->save();
  663. $id = $model->id;
  664. $insert = [];
  665. foreach ($data as $value){
  666. $insert[] = [
  667. 'apply_order_id' => $id,
  668. 'data_id' => $value['id'],
  669. 'quantity' => $value['quantity'] ?? 0,
  670. 'product_no' => $value['product_no'] ?? "",
  671. 'product_title' => $value['product_title'] ?? "",
  672. 'product_size' => $value['product_size'] ?? "",
  673. 'product_unit' => $value['product_unit'] ?? "",
  674. 'technology_name' => $value['technology_name'] ?? "",
  675. 'wood_name' => $value['wood_name'] ?? "",
  676. 'top_product_no' => $value['top_product_no'] ?? "",
  677. 'top_product_title' => $value['top_product_title'] ?? "",
  678. 'type' => $type,
  679. 'storehouse_id' => $value['storehouse_id'],
  680. 'crt_time' => $time,
  681. ];
  682. }
  683. ApplyOrderDetail::insert($insert);
  684. DB::commit();
  685. }catch (\Exception $e){
  686. DB::rollBack();
  687. return [false,$e->getMessage()];
  688. }
  689. return [true, ''];
  690. }
  691. //流水
  692. public function createRecord($id){return [true, ''];
  693. $record = ApplyOrderDetail::where('apply_order_id', $id)
  694. ->where('del_time',0)
  695. ->get()->toArray();
  696. if(empty($record)) return [false, '申请单明细数据不存在或已被删除'];
  697. try{
  698. DB::beginTransaction();
  699. $time = time();
  700. $insert = [];
  701. foreach ($record as $value){
  702. if(empty($value['product_no'])) continue;
  703. if($value['type'] == ApplyOrder::type_one){
  704. $number = - $value['quantity'];
  705. }else{
  706. $number = $value['quantity'];
  707. }
  708. $insert[] = [
  709. 'apply_order_id' => $id,
  710. 'product_no' => $value['product_no'],
  711. 'number' => $number,
  712. 'type' => $value['type'],
  713. 'storehouse_id' => $value['storehouse_id'],
  714. 'crt_time' => $time,
  715. ];
  716. }
  717. if(! empty($insert)) InOutRecord::insert($insert);
  718. DB::commit();
  719. }catch (\Exception $e){
  720. DB::rollBack();
  721. return [false,$e->getMessage()];
  722. }
  723. return [true, ''];
  724. }
  725. //报工
  726. public function reportWorkingEdit($data, $user){
  727. list($status,$msg) = $this->reportWorkingRule($data,$user,false);
  728. if(!$status) return [$status,$msg];
  729. DB::beginTransaction();
  730. try{
  731. $time = time();
  732. $model = new ReportWorking();
  733. $model = $model->where('id',$data['id'])->first();
  734. $model->report_time = $data['report_time'];
  735. $model->mark = $data['mark']?? "";
  736. $model->status = $data['auto'] ?? 0;
  737. $model->save();
  738. $id = $model->id;
  739. ReportWorkingDetail::where('del_time',0)->where('report_working_id',$id)->update([
  740. 'del_time' => $time
  741. ]);
  742. //班组下的人
  743. $team_man = [];
  744. $model_t = new EmployeeTeamPermission();
  745. $team_array = $model_t->select('employee_id', 'team_id')->get()->toArray();
  746. foreach ($team_array as $v){
  747. $team_man[$v['team_id']][] = $v['employee_id'];
  748. }
  749. $detail_insert = [];
  750. foreach ($data['order_data'] as $v){
  751. ReportMessage::insert([
  752. 'order_id' => $v['id'],
  753. 'quantity' => $v['quantity'] ?? 0,
  754. 'opt_case' => ReportMessage::type_one,
  755. 'crt_time' => $time,
  756. 'user_id' => $user['id'],
  757. ]);
  758. $t = $team_man[$v['team_id']] ?? [];
  759. if(! empty($t)){
  760. foreach ($t as $t_v){
  761. $detail_insert[] = [
  762. 'report_working_id' => $id,
  763. 'data_id' => $v['id'],
  764. 'quantity' => $v['quantity'] ?? 0,
  765. 'process_id' => $v['process_id'] ?? 0,
  766. 'finished_id' => $t_v,
  767. 'team_id' => $v['team_id'],
  768. 'crt_time' => $time,
  769. ];
  770. }
  771. }else{
  772. $detail_insert[] = [
  773. 'report_working_id' => $id,
  774. 'data_id' => $v['id'],
  775. 'quantity' => $v['quantity'] ?? 0,
  776. 'process_id' => $v['process_id'] ?? 0,
  777. 'finished_id' => 0,
  778. 'team_id' => $v['team_id'],
  779. 'crt_time' => $time,
  780. ];
  781. }
  782. }
  783. ReportWorkingDetail::insert($detail_insert);
  784. DB::commit();
  785. }catch (\Exception $e){
  786. DB::rollBack();
  787. return [false,$e->getMessage()];
  788. }
  789. return [true,''];
  790. }
  791. public function getReportRate($data, $user){
  792. if(empty($data['dispatch_id'])) return [false, '派工单id不能为空'];
  793. $dispatch = DispatchSub::where('id', $data['dispatch_id'])
  794. ->select('process_id','dispatch_quantity')
  795. ->get()->toArray();
  796. $array = $dispatch[0] ?? [];
  797. $process_id = $array['process_id'] ?? 0;
  798. $dispatch_quantity = $array['dispatch_quantity'] ?? 0;
  799. $process = Process::where('del_time',0)
  800. ->where('is_need_remain',1)
  801. ->select('id','zj_type','zj_rate')
  802. ->get()->toArray();
  803. $process_id_array = array_column($process,'id');
  804. $process_id_map = array_column($process,null,'id');
  805. if(in_array($process_id, $process_id_array)){
  806. $tmp = $process_id_map[$process_id] ?? [];
  807. if(! empty($tmp) && $tmp['zj_type'] == 2) {
  808. $num1 = ScrappCount::where('del_time',0)
  809. ->where('dispatch_sub_id',$data['dispatch_id'])
  810. ->count();
  811. $total = bcdiv($dispatch_quantity, 0.75);
  812. $num = bcmul($total, bcdiv($tmp['zj_rate'],100,2));
  813. dd($num,$num1,$total);
  814. }
  815. }else{
  816. return [true , ['type' => 1]]; // 不需要质检
  817. }
  818. return [true, ['type' => 0]]; // 错误 或者 全检
  819. }
  820. public function getReportInfo($data){
  821. if(empty($data)) return [];
  822. $process = Process::where('del_time',0)
  823. ->where('is_need_remain',1)
  824. ->select('id','zj_type','zj_rate')
  825. ->get()->toArray();
  826. $process_id_array = array_column($process,'id');
  827. $process_id_map = array_column($process,null,'id');
  828. $num1_map = ScrappCount::where('del_time',0)
  829. ->whereIn('dispatch_sub_id',array_column($data,'id'))
  830. ->select(DB::raw('count(*) as number'), 'dispatch_sub_id')
  831. ->groupBy('dispatch_sub_id')
  832. ->get()->toArray();
  833. $num1_map = array_column($num1_map,'number','dispatch_sub_id');
  834. $return = [];
  835. foreach ($data as $value){
  836. $tmp_1 = [
  837. 'zj_type' => 0,
  838. 'zj_rate' => 0,
  839. 'zj_num' => 0,
  840. 'total_num' => 0,
  841. ];
  842. if(in_array($value['process_id'], $process_id_array)){
  843. $tmp = $process_id_map[$value['process_id']] ?? [];
  844. if(! empty($tmp)) {
  845. $num1 = $num1_map[$value['id']] ?? 0;
  846. $total = bcdiv($value['dispatch_quantity'], 0.75);
  847. $total = $total < 1 ? 1 : $total;
  848. $num = bcmul($total, bcdiv($tmp['zj_rate'],100,2));
  849. $return[$value['id']] = [
  850. 'zj_type' => $tmp['zj_type'],
  851. 'zj_rate' => $tmp['zj_rate'],
  852. 'zj_num' => $num1,
  853. 'total_num' => $num,
  854. ];
  855. }
  856. }else{
  857. $return[$value['id']] = $tmp_1;
  858. }
  859. }
  860. return $return;
  861. }
  862. public function reportWorkingAdd($data,$user){
  863. list($status,$msg) = $this->reportWorkingRule($data,$user);
  864. if(!$status) return [$status,$msg];
  865. DB::beginTransaction();
  866. try{
  867. $time = time();
  868. $model = new ReportWorking();
  869. $model->order_number = $data['order_number'];
  870. $model->report_time = $data['report_time'];
  871. $model->mark = $data['mark']?? "";
  872. $model->crt_id = $user['id'];
  873. $model->status = $data['auto'] ?? 0;
  874. $model->save();
  875. $id = $model->id;
  876. //班组下的人
  877. $team_man = [];
  878. $model_t = new EmployeeTeamPermission();
  879. $team_array = $model_t->select('employee_id', 'team_id')->get()->toArray();
  880. foreach ($team_array as $v){
  881. $team_man[$v['team_id']][] = $v['employee_id'];
  882. }
  883. $process = Process::where('del_time',0)
  884. ->where('is_need_remain',1)
  885. ->select('id')
  886. ->get()->toArray();
  887. $process_id = array_column($process,'id');
  888. $detail_insert = [];
  889. foreach ($data['order_data'] as $v){
  890. if(in_array($v['process_id'], $process_id)){
  891. ReportMessage::insert([
  892. 'order_id' => $v['id'],
  893. 'quantity' => $v['quantity'] ?? 0,
  894. 'opt_case' => ReportMessage::type_one,
  895. 'crt_time' => $time,
  896. 'user_id' => $user['id'],
  897. ]);
  898. }
  899. $t = $team_man[$v['team_id']] ?? [];
  900. if(! empty($t)){
  901. foreach ($t as $t_v){
  902. $detail_insert[] = [
  903. 'report_working_id' => $id,
  904. 'data_id' => $v['id'],
  905. 'quantity' => $v['quantity'] ?? 0,
  906. 'process_id' => $v['process_id'] ?? 0,
  907. 'finished_id' => $t_v,
  908. 'team_id' => $v['team_id'],
  909. 'crt_time' => $time,
  910. ];
  911. }
  912. }else{
  913. $detail_insert[] = [
  914. 'report_working_id' => $id,
  915. 'data_id' => $v['id'],
  916. 'quantity' => $v['quantity'] ?? 0,
  917. 'process_id' => $v['process_id'] ?? 0,
  918. 'finished_id' => 0,
  919. 'team_id' => $v['team_id'],
  920. 'crt_time' => $time,
  921. ];
  922. }
  923. }
  924. ReportWorkingDetail::insert($detail_insert);
  925. DB::commit();
  926. }catch (\Exception $e){
  927. DB::rollBack();
  928. return [false,$e->getMessage()];
  929. }
  930. return [true, ''];
  931. }
  932. public function reportWorkingDel($data){
  933. if($this->isEmpty($data,'id')) return [false,'ID必须!'];
  934. $apply = ReportWorking::where('id',$data['id'])->first();
  935. if($apply->del_time > 0) return [false,'报工单不存在或已被删除'];
  936. if($apply->state != ReportWorking::state_zero) return [false, '报工单已审核,删除失败'];
  937. $time = time();
  938. try {
  939. DB::beginTransaction();
  940. $apply->del_time = $time;
  941. $apply->save();
  942. ReportWorkingDetail::where('del_time', 0)->where('report_working_id',$data['id'])->update([
  943. 'del_time'=>time()
  944. ]);
  945. DB::commit();
  946. }catch (\Throwable $exception){
  947. DB::rollBack();
  948. return [false, $exception->getMessage()];
  949. }
  950. return [true,''];
  951. }
  952. public function reportWorkingList($data){
  953. $model = ReportWorking::where('del_time',0)
  954. ->select('*')
  955. ->orderBy('id','desc');
  956. if(isset($data['status'])) $model->where('status', $data['status']);
  957. if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
  958. if(! empty($data['crt_id'])) $model->where('crt_id', $data['crt_id']);
  959. if(! empty($data['report_time'][0]) && ! empty($data['report_time'][1])) $model->whereBetween('report_time',[$data['report_time'][0],$data['report_time'][1]]);
  960. if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) $model->whereBetween('crt_time',[$data['crt_time'][0],$data['crt_time'][1]]);
  961. if(! empty($data['dispatch_no1'])) {
  962. $dispatch_id = DispatchSub::where('del_time',0)
  963. ->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no1'].'%')
  964. ->select('id')
  965. ->get()->toArray();
  966. $dispatch_id = array_column($dispatch_id,'id');
  967. $detail = ReportWorkingDetail::where('del_time',0)
  968. ->whereIn('data_id', $dispatch_id)
  969. ->select('report_working_id')
  970. ->get()->toArray();
  971. $model->whereIn('id', array_unique(array_column($detail,'report_working_id')));
  972. }
  973. if(! empty($data['dispatch_no'])) {
  974. $dispatch_id = DispatchSub::where('del_time',0)
  975. ->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%')
  976. ->select('id')
  977. ->get()->toArray();
  978. $dispatch_id = array_column($dispatch_id,'id');
  979. $detail = ReportWorkingDetail::where('del_time',0)
  980. ->whereIn('data_id', $dispatch_id)
  981. ->select('report_working_id')
  982. ->get()->toArray();
  983. $model->whereIn('id', array_unique(array_column($detail,'report_working_id')));
  984. }
  985. if(! empty($data['sale_order_number'])){
  986. $id = SaleOrdersProduct::where('del_time',0)
  987. ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
  988. ->select('id')
  989. ->get()->toArray();
  990. $dispatch_id = DispatchSub::where('del_time',0)
  991. ->whereIn('sale_orders_product_id',array_column($id,'id'))
  992. ->select('id')
  993. ->get()->toArray();
  994. $detail = ReportWorkingDetail::where('del_time',0)
  995. ->whereIn('data_id', $dispatch_id)
  996. ->select('report_working_id')
  997. ->get()->toArray();
  998. $model->whereIn('id', array_unique(array_column($detail,'report_working_id')));
  999. }
  1000. $list = $this->limit($model,'',$data);
  1001. $list = $this->reportWorkingfillData($list);
  1002. return [true,$list];
  1003. }
  1004. public function reportWorkingfillData($data){
  1005. if(empty($data['data'])) return $data;
  1006. $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
  1007. ->pluck('emp_name','id')
  1008. ->toArray();
  1009. $detail = ReportWorkingDetail::where('del_time',0)
  1010. ->whereIn('report_working_id', array_column($data['data'],'id'))
  1011. ->select('data_id','report_working_id')
  1012. ->get()->toArray();
  1013. $map = [];
  1014. foreach ($detail as $value){
  1015. $map[$value['data_id']] = $value['report_working_id'];
  1016. }
  1017. $dispatch = DispatchSub::whereIn('id',array_column($detail,'data_id'))
  1018. ->get()->toArray();
  1019. $map1 = [];
  1020. $team_map = Team::where("del_time",0)->pluck('title','id')->toArray();
  1021. $process_map = Process::where("del_time",0)->pluck('title','id')->toArray();
  1022. foreach ($dispatch as $value){
  1023. $report_working_id = $map[$value['id']] ?? 0;
  1024. $value['team_name'] = $team_map[$value['team_id']] ?? "";
  1025. $value['process_name'] = $process_map[$value['process_id']] ?? "";
  1026. $map1[$report_working_id][] = $value;
  1027. }
  1028. foreach ($data['data'] as $key => $value){
  1029. $data['data'][$key]['report_time'] = $value['report_time'] ? date('Y-m-d',$value['report_time']) : '';
  1030. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d',$value['crt_time']) : '';
  1031. $data['data'][$key]['status_title'] = ReportWorking::$state_name[$value['status']] ?? "";
  1032. $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
  1033. $data['data'][$key]['dispatch'] = $map1[$value['id']] ?? [];
  1034. }
  1035. return $data;
  1036. }
  1037. public function reportWorkingDetail($data){
  1038. if(empty($data['id']) && empty($data['order_number'])) return [false,'ID与OrderNumber不能为空!'];
  1039. $id = $data['id'] ?? 0;
  1040. $order_number = $data['order_number'] ?? "";
  1041. $detail = ReportWorking::where('del_time',0)
  1042. ->when(! empty($id), function ($query) use ($id){
  1043. return $query->where('id', $id);
  1044. })
  1045. ->when(! empty($order_number), function ($query) use ($order_number){
  1046. return $query->where('order_number', $order_number);
  1047. })
  1048. ->first();
  1049. if(empty($detail)) return [false,'报工单不存在或已被删除'];
  1050. $detail = $detail->toArray();
  1051. if(empty($id)) $id = $detail['id'];
  1052. $detail['report_time'] = $detail['report_time'] ? date('Y-m-d',$detail['report_time']) : '';
  1053. $apply_d = ReportWorkingDetail::where('del_time', 0)
  1054. ->where('report_working_id', $id)
  1055. ->get()->toArray();
  1056. $apply_id = array_column($apply_d, 'data_id');
  1057. //派工单
  1058. $d = DispatchSub::where('del_time',0)
  1059. ->whereIn('id', $apply_id)
  1060. ->select('id', 'dispatch_no as order_no', 'product_title','technology_name','wood_name','product_no','process_id','product_unit','price','product_size','device_id')
  1061. ->get()->toArray();
  1062. $d_tmp = array_column($d,null,'id');
  1063. $process_map = Process::whereIn('id',array_unique(array_column($d,'process_id')))
  1064. ->pluck('title','id')
  1065. ->toArray();
  1066. $team_map = Team::pluck('title','id')->toArray();
  1067. $device_map = Equipment::whereIn('id',array_unique(array_column($d,'device_id')))
  1068. ->pluck('title','id')
  1069. ->toArray();
  1070. $return = [];
  1071. foreach ($apply_d as $t){
  1072. $tmp = $d_tmp[$t['data_id']] ?? [];
  1073. $str = $t['data_id'] . $t['process_id'];
  1074. if(! isset($return[$str])){
  1075. $return[$str] = [
  1076. 'id' => $t['data_id'] ?? 0,
  1077. 'quantity' => $t['quantity'] ?? 0,
  1078. 'product_no' => $tmp['product_no'] ?? "",
  1079. 'product_title' => $tmp['product_title'] ?? "",
  1080. 'product_size' => $tmp['product_size'] ?? "",
  1081. 'product_unit' => $tmp['product_unit'] ?? "",
  1082. 'technology_name' => $tmp['technology_name'] ?? "",
  1083. 'wood_name' => $tmp['wood_name'] ?? "",
  1084. 'order_no' => $tmp['order_no'] ?? "",
  1085. 'process_id' => $tmp['process_id'] ?? 0,
  1086. 'process_name' => $process_map[$tmp['process_id']] ?? "",
  1087. 'team_id' => $t['team_id'] ?? 0,
  1088. 'team_title' => $team_map[$t['team_id']] ?? '',
  1089. 'device_id' => $tmp['device_id'] ?? 0,
  1090. 'device_title' => $device_map[$tmp['device_id']] ?? '',
  1091. ];
  1092. }
  1093. }
  1094. $detail['order_data'] = array_values($return);
  1095. return [true, $detail];
  1096. }
  1097. public function reportWorkingRule(&$data,$user, $is_add = true){
  1098. if($this->isEmpty($data,'report_time')) return [false,'报工时间不能为空'];
  1099. if(empty($data['order_data'])) return [false, '报工单详细信息不能为空'];
  1100. foreach ($data['order_data'] as $value){
  1101. if(empty($value['id'])) return [false, '报工单详细信息ID不能为空'];
  1102. if(empty($value['quantity'])) return [false, '报工单详细信息数量不能为空'];
  1103. if(empty($value['process_id'])) return [false, '报工单详细信息工序不能为空'];
  1104. if(empty($value['team_id'])) return [false, '报工单详细信息班组不能为空'];
  1105. }
  1106. $id = array_unique(array_column($data['order_data'],'id'));
  1107. $dispatch = DispatchSub::where('del_time',0)
  1108. ->whereIn('id', $id)
  1109. ->select('id', 'dispatch_no', 'status', 'dispatch_quantity','order_product_id')
  1110. ->get()->toArray();
  1111. if(count($dispatch) != count($id)) return [false, '派工单信息错误,请重新选择'];
  1112. $count = array_unique(array_column($dispatch,'order_product_id'));
  1113. if(count($count) > 1) return [false, '批量报工时请选择同一生产订单下的派工单'];
  1114. if($is_add){
  1115. $data['order_number'] = $this->setOrderNO2();
  1116. if(empty($data['order_number'])) return [false, '报工单唯一标识生成失败'];
  1117. }else{
  1118. if(empty($data['id'])) return [false, '报工单唯一标识不能为空'];
  1119. if(empty($data['order_number'])) return [false, '报工单唯一标识不能为空'];
  1120. $apply = ReportWorking::where('id', $data['id'])->where('del_time', 0)->first();
  1121. if(empty($apply)) return [false, '报工单不存在或已被删除'];
  1122. if($apply->status != 0) return [false, '报工单已审核,编辑失败'];
  1123. }
  1124. list($status, $msg) = $this->compareQuantity($dispatch, $data);
  1125. if(! $status) return [false, $msg];
  1126. $em = new EmployeeService();
  1127. $data['auto'] = $em->is_auto($user, "wgbg_auto");
  1128. return [true,''];
  1129. }
  1130. public function compareQuantity($dispatch, $data){
  1131. $id = $data['id'] ?? 0;
  1132. $result = ReportWorkingDetail::where('del_time',0)
  1133. ->when(! empty($id), function ($query) use ($id){
  1134. return $query->where('report_working_id', '<>', $id);
  1135. })
  1136. ->where('data_id', array_column($dispatch, 'id'))
  1137. ->select('data_id as dispatch_id','quantity')
  1138. ->get()
  1139. ->toArray();
  1140. $map1 = [];
  1141. foreach ($result as $value){
  1142. if(isset($map1[$value['dispatch_id']])){
  1143. $tmp = bcadd($map1[$value['dispatch_id']], $value['quantity'], 3);
  1144. $map1[$value['dispatch_id']] = $tmp;
  1145. }else{
  1146. $map1[$value['dispatch_id']] = $value['quantity'];
  1147. }
  1148. }
  1149. $map2 = array_column($dispatch,null,'id');
  1150. foreach ($data['order_data'] as $value){
  1151. $tmp = $map2[$value['id']] ?? [];
  1152. $total = $tmp['dispatch_quantity'] ?? 0;
  1153. $dispatch_no = $tmp['dispatch_no'] ?? "";
  1154. $save = $map1[$value['id']] ?? 0;
  1155. $save_total = bcadd($value['quantity'], $save, 3);
  1156. if($save_total >= $total) return [false, "派工单号:" . $dispatch_no . "的报工总数量不能超过" . $total . "吨,目前累计报工" . $save . "吨"];
  1157. }
  1158. return [true, ''];
  1159. }
  1160. public function setOrderNO2($time = 0){
  1161. if(empty($time)) {
  1162. $str = date('Ymd',time());
  1163. }else{
  1164. $str = date('Ymd', $time);
  1165. }
  1166. $model = new ReportWorking();
  1167. $order_number = $model->where('order_number','Like','%'. $str . '%')
  1168. ->max('order_number');
  1169. if(empty($order_number)){
  1170. $number = str_pad(1,3,'0',STR_PAD_LEFT);
  1171. $number = $str . $number;
  1172. }else{
  1173. $tmp = substr($order_number, -3);
  1174. $tmp = $tmp + 1;
  1175. //超过999
  1176. // if(strlen($tmp) > 3) return '';
  1177. $number = str_pad($tmp,3,'0',STR_PAD_LEFT);
  1178. $number = $str . $number;
  1179. }
  1180. return $number;
  1181. }
  1182. public function applyOrderReportList($data){
  1183. if(empty($data['apply_time'][0]) || empty($data['apply_time'][1])) return [false, '申请日期必须选择!'];
  1184. if(empty($data['type'])) return [false, 'TYPE不能为空!'];
  1185. $model = ApplyOrder::where('del_time',0)
  1186. ->where('apply_time',">=",$data['apply_time'][0])
  1187. ->where('apply_time',"<=",$data['apply_time'][1])
  1188. ->where('type',$data['type'])
  1189. ->select('id','order_number','apply_time','mark','status','storehouse_title')
  1190. ->orderBy('id','desc');
  1191. if(isset($data['status'])) $model->where('status', $data['status']);
  1192. if(! empty($data['pc_number'])) {
  1193. if(in_array($data['type'], [ApplyOrder::type_one,ApplyOrder::type_two])){
  1194. $dispatch_id = DispatchSub::where('del_time',0)
  1195. ->where('out_order_no', 'LIKE', '%'.$data['pc_number'].'%')
  1196. ->select('id')
  1197. ->get()->toArray();
  1198. $dispatch_id = array_column($dispatch_id,'id');
  1199. $detail = ApplyOrderDetail::where('del_time',0)
  1200. ->where('type', $data['type'])
  1201. ->whereIn('data_id', $dispatch_id)
  1202. ->select('apply_order_id')
  1203. ->get()->toArray();
  1204. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  1205. }elseif($data['type'] == ApplyOrder::type_five){
  1206. $zj_id = ScrappCount::where('del_time',0)
  1207. ->where('out_order_no', 'LIKE', '%'.$data['pc_number'].'%')
  1208. ->select('id')
  1209. ->get()->toArray();
  1210. $zj_id = array_column($zj_id,'id');
  1211. $detail = ApplyOrderDetail::where('del_time',0)
  1212. ->where('type', $data['type'])
  1213. ->whereIn('data_id', $zj_id)
  1214. ->select('apply_order_id')
  1215. ->get()->toArray();
  1216. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  1217. }else{
  1218. $no = SaleOrdersProduct::where('del_time',0)
  1219. ->where('out_order_no', 'LIKE', '%'.$data['pc_number'].'%')
  1220. ->select('order_no')
  1221. ->get()->toArray();
  1222. $no = array_unique(array_column($no,'order_no'));
  1223. $box_id = Box::where('del_time',0)
  1224. ->whereIn('top_order_no', $no)
  1225. ->select('id')
  1226. ->get()->toArray();
  1227. $box_id = array_column($box_id,'id');
  1228. $detail = ApplyOrderDetail::where('del_time',0)
  1229. ->where('type', $data['type'])
  1230. ->whereIn('data_id', $box_id)
  1231. ->select('apply_order_id')
  1232. ->get()->toArray();
  1233. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  1234. }
  1235. }
  1236. if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])){
  1237. $model->where('crt_time',">=",$data['crt_time'][0]);
  1238. $model->where('crt_time',"<=",$data['crt_time'][1]);
  1239. }
  1240. if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
  1241. if(! empty($data['storehouse_title'])) $model->where('storehouse_title', 'LIKE', '%'.$data['storehouse_title'].'%');
  1242. if(! empty($data['sale_order_number'])){
  1243. if(in_array($data['type'], [ApplyOrder::type_one,ApplyOrder::type_two])){
  1244. $dispatch_id = DispatchSub::where('del_time',0)
  1245. ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
  1246. ->select('id')
  1247. ->get()->toArray();
  1248. $dispatch_id = array_column($dispatch_id,'id');
  1249. $detail = ApplyOrderDetail::where('del_time',0)
  1250. ->where('type', $data['type'])
  1251. ->whereIn('data_id', $dispatch_id)
  1252. ->select('apply_order_id')
  1253. ->get()->toArray();
  1254. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  1255. }elseif($data['type'] == ApplyOrder::type_five){
  1256. $zj_id = ScrappCount::where('del_time',0)
  1257. ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
  1258. ->select('id')
  1259. ->get()->toArray();
  1260. $zj_id = array_column($zj_id,'id');
  1261. $detail = ApplyOrderDetail::where('del_time',0)
  1262. ->where('type', $data['type'])
  1263. ->whereIn('data_id', $zj_id)
  1264. ->select('apply_order_id')
  1265. ->get()->toArray();
  1266. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  1267. }else{
  1268. $no = SaleOrdersProduct::where('del_time',0)
  1269. ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
  1270. ->select('order_no')
  1271. ->get()->toArray();
  1272. $no = array_unique(array_column($no,'order_no'));
  1273. $box_id = Box::where('del_time',0)
  1274. ->whereIn('top_order_no', $no)
  1275. ->select('id')
  1276. ->get()->toArray();
  1277. $box_id = array_column($box_id,'id');
  1278. $detail = ApplyOrderDetail::where('del_time',0)
  1279. ->where('type', $data['type'])
  1280. ->whereIn('data_id', $box_id)
  1281. ->select('apply_order_id')
  1282. ->get()->toArray();
  1283. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  1284. }
  1285. }
  1286. if(! empty($data['dispatch_no'])){
  1287. $dispatch_id = DispatchSub::where('del_time',0)
  1288. ->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%')
  1289. ->select('id')
  1290. ->get()->toArray();
  1291. $dispatch_id = array_column($dispatch_id,'id');
  1292. $detail = ApplyOrderDetail::where('del_time',0)
  1293. ->where('type', $data['type'])
  1294. ->whereIn('data_id', $dispatch_id)
  1295. ->select('apply_order_id')
  1296. ->get()->toArray();
  1297. $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
  1298. }
  1299. $list = $model->get()->toArray();
  1300. if(empty($list)) return [true, []];
  1301. $apply_id = array_column($list, 'id');
  1302. //明细数据
  1303. $result = ApplyOrderDetail::where('del_time',0)
  1304. ->whereIn('apply_order_id', $apply_id)
  1305. ->get()->toArray();
  1306. if(empty($result)) return [true, []];
  1307. //组织主表需要的数据
  1308. $list_map = $this->makeListMap($list, $result, $data['type']);
  1309. $data_id = array_unique(array_column($result, 'data_id'));
  1310. list($d, $d_no_map) = $this->getDetailList($data_id, $data['type']);
  1311. $return = [];
  1312. $d_tmp = array_column($d,null,'id');
  1313. foreach ($result as $t){
  1314. $tmp = $d_tmp[$t['data_id']] ?? [];
  1315. $technology_name = ! empty($t['technology_name']) ? $t['technology_name'] : $tmp['technology_name'] ?? "";
  1316. $wood_name = ! empty($t['wood_name']) ? $t['wood_name'] : $tmp['wood_name'] ?? "";
  1317. $top_product_title = ! empty($t['top_product_title']) ? $t['top_product_title'] : $tmp['product_title'] ?? "";
  1318. $top_product_no = ! empty($t['top_product_no']) ? $t['top_product_no'] : $tmp['product_no'] ?? "";
  1319. if(! empty($tmp['order_product_id']) && ! empty($tmp['crt_time']) && isset($d_no_map[$tmp['order_product_id'] . $tmp['crt_time']])){
  1320. $order_no = implode(',', $d_no_map[$tmp['order_product_id'] . $tmp['crt_time']]);
  1321. }else{
  1322. $order_no = $tmp['order_no'] ?? "";
  1323. }
  1324. if($t['type'] == ApplyOrder::type_two || $t['type'] == ApplyOrder::type_three){
  1325. $product_unit = "吨";
  1326. }elseif($t['type'] == ApplyOrder::type_four){
  1327. $product_unit = "只";
  1328. }else{
  1329. $product_unit = $t['product_unit'] ?? "";
  1330. }
  1331. $tmp = $list_map[$t['apply_order_id']] ?? [];
  1332. $return[] = [
  1333. 'order_number' => $tmp['order_number'],
  1334. 'sale_order_number' => $tmp['sale_order_number'],
  1335. 'apply_time' => $tmp['apply_time'],
  1336. 'mark' => $tmp['mark'],
  1337. 'status_title' => $tmp['status_title'],
  1338. 'storehouse_title' => $tmp['storehouse_title'],
  1339. 'id' => $t['data_id'] ?? 0,
  1340. // 'main_id' => $t['id'],
  1341. 'quantity' => $t['quantity'] ?? 0,
  1342. 'product_no' => $t['product_no'] ?? "",
  1343. 'product_title' => $t['product_title'] ?? "",
  1344. 'product_size' => $t['product_size'] ?? "",
  1345. 'product_unit' => $product_unit,
  1346. 'top_product_title' => $top_product_title,
  1347. 'top_product_no' => $top_product_no,
  1348. 'technology_name' => $technology_name, //颜色
  1349. 'wood_name' => $wood_name,
  1350. 'order_no' => $order_no,
  1351. ];
  1352. }
  1353. return [true, array_values($return)];
  1354. }
  1355. private function getDetailList($apply_id, $type){
  1356. $d = $d_no_map = [];
  1357. if($type == ApplyOrder::type_one){
  1358. $d = DispatchSub::where('del_time',0)
  1359. ->whereIn('id', $apply_id)
  1360. ->select('id', 'dispatch_no as order_no', 'product_title','technology_name','wood_name','product_no','order_product_id','crt_time')
  1361. ->get()->toArray();
  1362. $args = "";
  1363. foreach ($d as $value){
  1364. $args = "(order_product_id = {$value['order_product_id']} and crt_time = {$value['crt_time']}) OR ";
  1365. }
  1366. $args = rtrim($args, 'OR ');
  1367. $d_no_map = [];
  1368. $d_no = DispatchSub::where('del_time',0)
  1369. ->whereRaw($args)
  1370. ->select('dispatch_no as order_no','order_product_id','crt_time')
  1371. ->get()->toArray();
  1372. foreach ($d_no as $value){
  1373. if(isset($d_no_map[$value['order_product_id'] . $value['crt_time']])){
  1374. if(! in_array($value['order_no'], $d_no_map[$value['order_product_id'] . $value['crt_time']])) $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
  1375. }else{
  1376. $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
  1377. }
  1378. }
  1379. }elseif ($type == ApplyOrder::type_two){
  1380. $d = DispatchSub::where('del_time',0)
  1381. ->whereIn('id', $apply_id)
  1382. ->select('id', 'dispatch_no as order_no','technology_name','wood_name','order_product_id','crt_time')
  1383. ->get()->toArray();
  1384. $args = "";
  1385. foreach ($d as $value){
  1386. $args = "(order_product_id = {$value['order_product_id']} and crt_time = {$value['crt_time']}) OR ";
  1387. }
  1388. $args = rtrim($args, 'OR ');
  1389. $d_no_map = [];
  1390. $d_no = DispatchSub::where('del_time',0)
  1391. ->whereRaw($args)
  1392. ->select('dispatch_no as order_no','order_product_id','crt_time')
  1393. ->get()->toArray();
  1394. foreach ($d_no as $value){
  1395. if(isset($d_no_map[$value['order_product_id'] . $value['crt_time']])){
  1396. if(! in_array($value['order_no'], $d_no_map[$value['order_product_id'] . $value['crt_time']])) $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
  1397. }else{
  1398. $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
  1399. }
  1400. }
  1401. }elseif ($type == ApplyOrder::type_three){
  1402. $d = Box::where('del_time',0)
  1403. ->whereIn('id', $apply_id)
  1404. ->select('id', 'order_no')
  1405. ->get()->toArray();
  1406. }elseif ($type == ApplyOrder::type_four){
  1407. $d = Box::where('del_time',0)
  1408. ->whereIn('id', $apply_id)
  1409. ->select('id', 'order_no')
  1410. ->get()->toArray();
  1411. }elseif($type == ApplyOrder::type_five){
  1412. $d = ScrappCount::where('del_time',0)
  1413. ->whereIn('id', $apply_id)
  1414. ->select('id', 'order_number as order_no', 'product_title','technology_name','wood_name','product_no','order_product_id','crt_time')
  1415. ->get()->toArray();
  1416. }
  1417. return [$d, $d_no_map];
  1418. }
  1419. private function makeListMap($data, $order, $type){
  1420. if(empty($data)) return [];
  1421. //申请单 所有的数据id
  1422. $order_map = $data_id = [];
  1423. foreach ($order as $value){
  1424. $order_map[$value['apply_order_id']][] = $value['data_id'];
  1425. $data_id[] = $value['data_id'];
  1426. }
  1427. if(in_array($type, [ApplyOrder::type_one,ApplyOrder::type_two])){
  1428. $map1 = DispatchSub::whereIn('id', array_unique($data_id))
  1429. ->pluck('out_order_no','id')
  1430. ->toArray();
  1431. }elseif($type == ApplyOrder::type_five){
  1432. $map3 = ScrappCount::whereIn('id', array_unique($data_id))
  1433. ->pluck('out_order_no','id')
  1434. ->toArray();
  1435. }else{
  1436. $map2 = Box::whereIn('id', array_unique($data_id))
  1437. ->pluck('top_order_no','id')
  1438. ->toArray();
  1439. $map2_fin = SaleOrdersProduct::whereIn('order_no',array_unique(array_values($map2)))
  1440. ->pluck('out_order_no','order_no')
  1441. ->toArray();
  1442. }
  1443. foreach ($data as $key => $value){
  1444. $data[$key]['apply_time'] = $value['apply_time'] ? date('Y-m-d',$value['apply_time']) : '';
  1445. $data[$key]['status_title'] = ApplyOrder::$state_name[$value['status']] ?? "";
  1446. $order_tmp = $order_map[$value['id']] ?? [];
  1447. $order_tmp = array_unique($order_tmp);
  1448. $sale_order_number = [];
  1449. if(in_array($type, [ApplyOrder::type_one,ApplyOrder::type_two])){
  1450. foreach ($order_tmp as $v){
  1451. $str = $map1[$v] ?? '';
  1452. if(empty($str)) continue;
  1453. $sale_order_number[] = $str;
  1454. }
  1455. $sale_order_number = array_unique($sale_order_number);
  1456. $sale_order_number = implode(',',$sale_order_number);
  1457. $data[$key]['sale_order_number'] = $sale_order_number;
  1458. }elseif ($type == ApplyOrder::type_five){
  1459. foreach ($order_tmp as $v){
  1460. $str = $map3[$v] ?? '';
  1461. if(empty($str)) continue;
  1462. $sale_order_number[] = $str;
  1463. }
  1464. $sale_order_number = array_unique($sale_order_number);
  1465. $sale_order_number = implode(',',$sale_order_number);
  1466. $data[$key]['sale_order_number'] = $sale_order_number;
  1467. }else{
  1468. foreach ($order_tmp as $v){
  1469. $m2_t = $map2[$v] ?? '';
  1470. $m2_t = $map2_fin[$m2_t] ?? "";
  1471. if(empty($m2_t)) continue;
  1472. $sale_order_number[] = $m2_t;
  1473. }
  1474. $sale_order_number = array_unique($sale_order_number);
  1475. $sale_order_number = implode(',',$sale_order_number);
  1476. $data[$key]['sale_order_number'] = $sale_order_number;
  1477. }
  1478. }
  1479. return array_column($data,null,'id');
  1480. }
  1481. public function editZj($data, $user){
  1482. list($status, $msg) = $this->editZjRule($data);
  1483. if(! $status) return [false, $msg];
  1484. $order_map = array_column($msg,null,'data_id');
  1485. try{
  1486. DB::beginTransaction();
  1487. $time = time();
  1488. $insert = [];
  1489. $max_id = $this->getDailyId();
  1490. list($status,$msg) = $this->limitingSendRequestBackg("quantity_id_" . $max_id);
  1491. if(! $status) return [false,$msg];
  1492. $get_order_number = $insert_wg = [];
  1493. foreach ($data['data'] as $value){
  1494. $order_t = $order_map[$value['data_id']] ?? [];
  1495. $order = $order_t['dispatch'] ?? [];
  1496. if(empty($value['waste'])){
  1497. $max_id += 1;
  1498. $order_number = date("Ymd") . str_pad($max_id,3,'0',STR_PAD_LEFT);
  1499. $get_order_number[] = $order_number;
  1500. $insert[] = [
  1501. 'sale_orders_product_id' => $order['sale_orders_product_id'],
  1502. 'order_product_id' => $order['order_product_id'],
  1503. 'dispatch_sub_id' => $order['id'],
  1504. 'out_order_no' => $order['out_order_no'],
  1505. 'order_no' => $order['order_no'],
  1506. 'customer_no' => $order['customer_no'],
  1507. 'customer_name' => $order['customer_name'],
  1508. 'product_no' => $order['product_no'],
  1509. 'product_title' => $order['product_title'],
  1510. 'product_size' => $order['product_size'],
  1511. 'product_unit' => $order['product_unit'],
  1512. 'technology_material' => $order['technology_material'],
  1513. 'technology_name' => $order['technology_name'],
  1514. 'wood_name' => $order['wood_name'],
  1515. 'price' => $order['price'],
  1516. 'process_mark' => $order['process_mark'],
  1517. 'table_body_mark' => $order['table_body_mark'],
  1518. 'table_header_mark' => $order['table_header_mark'],
  1519. 'crt_id' => $user['id'],
  1520. 'crt_time' => $time,
  1521. 'scrapp_num' => 0,
  1522. 'scrapp_id' => 0,
  1523. 'team_id' => $data['team_id'],
  1524. 'finished_id' => $user['id'],
  1525. 'equipment_id' => $data['equipment_id'],
  1526. 'order_number' => $order_number,
  1527. 'process_id' => $order['process_id'],
  1528. 'quantity' => $value['num'],
  1529. 'report_id' => $data['id'],
  1530. 'result' => 0,
  1531. 'warehouse_no' => "",
  1532. 'warehouse_title' => "",
  1533. 'daily_id' => $max_id,
  1534. ];
  1535. }else{
  1536. foreach ($value['waste'] as $v){
  1537. $max_id += 1;
  1538. $order_number = date("Ymd") . str_pad($max_id,3,'0',STR_PAD_LEFT);
  1539. $get_order_number[] = $order_number;
  1540. $insert[] = [
  1541. 'sale_orders_product_id' => $order['sale_orders_product_id'],
  1542. 'order_product_id' => $order['order_product_id'],
  1543. 'dispatch_sub_id' => $order['id'],
  1544. 'out_order_no' => $order['out_order_no'],
  1545. 'order_no' => $order['order_no'],
  1546. 'customer_no' => $order['customer_no'],
  1547. 'customer_name' => $order['customer_name'],
  1548. 'product_no' => $order['product_no'],
  1549. 'product_title' => $order['product_title'],
  1550. 'product_size' => $order['product_size'],
  1551. 'product_unit' => $order['product_unit'],
  1552. 'technology_material' => $order['technology_material'],
  1553. 'technology_name' => $order['technology_name'],
  1554. 'wood_name' => $order['wood_name'],
  1555. 'price' => $order['price'],
  1556. 'process_mark' => $order['process_mark'],
  1557. 'table_body_mark' => $order['table_body_mark'],
  1558. 'table_header_mark' => $order['table_header_mark'],
  1559. 'crt_id' => $user['id'],
  1560. 'crt_time' => $time,
  1561. 'scrapp_num' => $v['num'],
  1562. 'scrapp_id' => $v['scrapp_id'],
  1563. 'team_id' => $data['team_id'],
  1564. 'finished_id' => $user['id'],
  1565. 'equipment_id' => $data['equipment_id'],
  1566. 'order_number' => $order_number,
  1567. 'process_id' => $order['process_id'],
  1568. 'quantity' => $value['num'],
  1569. 'report_id' => $data['id'],
  1570. 'result' => $v['result'],
  1571. 'warehouse_no' => $v['warehouse_no'],
  1572. 'warehouse_title' => $v['warehouse_title'],
  1573. 'daily_id' => $max_id,
  1574. ];
  1575. }
  1576. }
  1577. if($value['num'] > 0) $insert_wg[] = [
  1578. 'dispatch_id' => $value['data_id'],
  1579. 'num' => $value['num']
  1580. ];
  1581. }
  1582. //质检单 不良品单 会记录报工单的id
  1583. if(! empty($insert)) ScrappCount::insert($insert);
  1584. //获取新增的单据
  1585. $result = ScrappCount::whereIn('order_number',$get_order_number)
  1586. ->select('scrapp_num as num','id','dispatch_sub_id','warehouse_no','warehouse_title','result','product_no')
  1587. ->get()->toArray();
  1588. //完工入库申请单 半成品
  1589. list($status, $msg) = $this->insertWg($insert_wg, $user);
  1590. if(! $status) return [false, $msg];
  1591. //获取写入的数据 写其它的业务逻辑
  1592. list($status, $msg) = $this->insertOther($result, $user, $time);
  1593. if(! $status) return [false, $msg];
  1594. //反写 根据质检单上的派工单id 反写上游单据
  1595. $this->writeDispatchQuantity(array_column($result,'dispatch_sub_id'));
  1596. DB::commit();
  1597. }catch (\Throwable $exception){
  1598. DB::rollBack();
  1599. return [false, $exception->getMessage() . '|' . $exception->getLine()];
  1600. }
  1601. return [true, ''];
  1602. }
  1603. public function editZjRule($data){
  1604. if(empty($data['id'])) return [false, '报工单ID不能为空'];
  1605. $order = ReportWorkingDetail::where('del_time',0)
  1606. ->where('report_working_id', $data['id'])
  1607. ->get()->toArray();
  1608. if(empty($order)) return [false, "报工单信息不存在或已被删除"];
  1609. $map = [];
  1610. foreach ($order as $value){
  1611. if(! isset($map[$value['data_id']])) $map[$value['data_id']] = $value['quantity'];
  1612. }
  1613. $sList = ScrappCount::where('del_time',0)
  1614. ->where('report_id', $data['id'])
  1615. ->select('dispatch_sub_id as dispatch_id','scrapp_num','quantity')
  1616. ->get()->toArray();
  1617. $sMap = [];
  1618. foreach ($sList as $value){
  1619. $num = bcadd($value['scrapp_num'], $value['quantity'],3);
  1620. if(isset($sMap[$value['dispatch_id']])){
  1621. $t = bcadd($sMap[$value['dispatch_id']], $num,3);
  1622. $sMap[$value['dispatch_id']] = $t;
  1623. }else{
  1624. $sMap[$value['dispatch_id']] = $num;
  1625. }
  1626. }
  1627. if(empty($data['team_id'])) return [false, '质检班组不能为空'];
  1628. if(empty($data['equipment_id'])) return [false, '设备不能为空'];
  1629. if(empty($data['data'])) return [false, '质检信息不能为空'];
  1630. $data_id = [];
  1631. foreach ($data['data'] as $value){
  1632. if(empty($value['data_id'])) return [false, 'dataID不能为空'];
  1633. if(! isset($value['num'])) return [false, 'num不能为空'];
  1634. $num = 0;
  1635. if(! empty($value['waste'])){
  1636. foreach ($value['waste'] as $v){
  1637. if(empty($v['num'])) return [false, "质检数量不能为空"];
  1638. if(empty($v['scrapp_id'])) return [false, "请选择质检原因"];
  1639. if(empty($v['result'])) return [false, '请选择质检产品处理结果'];
  1640. if($v['result'] == ReportWorking::type_two && (empty($v['warehouse_no']) || empty($v['warehouse_title']))) return [false, '请选择产品去向仓库'];
  1641. $num = bcadd($v['num'], $num, 3);
  1642. }
  1643. }
  1644. $total = bcadd($num, $value['num'],3);
  1645. $total2 = $map[$value['data_id']] ?? 0;
  1646. if($total > $total2) return [false, '总数量不能超过报工数量'];
  1647. $tmp = $sMap[$value['data_id']] ?? 0;
  1648. if($tmp >= $total) return [false, '报工单已完成报工质检'];
  1649. $data_id[] = $value['data_id'];
  1650. }
  1651. $dispatch = DispatchSub::whereIn('id',$data_id)->get()->toArray();
  1652. $dispatch_map = array_column($dispatch,null,'id');
  1653. foreach ($order as $key => $value){
  1654. if(! in_array($value['data_id'], $data_id)){
  1655. unset($order[$key]);
  1656. continue;
  1657. }
  1658. $order[$key]['dispatch'] = $dispatch_map[$value['data_id']] ?? [];
  1659. }
  1660. return [true, array_values($order)];
  1661. }
  1662. public function getDailyId($time = 0)
  1663. {
  1664. if(empty($time)) $time = time();
  1665. $today_start = strtotime(date("Y-m-d 00:00:00",$time));
  1666. $today_end = strtotime(date("Y-m-d 23:59:59",$time));
  1667. // 获取今天的最大daily_id
  1668. $maxDailyId = ScrappCount::where('crt_time', '>=', $today_start)
  1669. ->where('crt_time', '<=', $today_end)
  1670. ->max(DB::raw('daily_id + 0'));
  1671. return $maxDailyId ?? 0;
  1672. }
  1673. public function insertWg($all_data, $user){
  1674. if(empty($all_data)) return [true, ''];
  1675. $dispatchList = DispatchSub::whereIn('id', array_column($all_data,'dispatch_id'))->get()->toArray();
  1676. //是否最后一道工序
  1677. $orders = OrdersProduct::whereIn('id', array_unique(array_column($dispatchList, 'order_product_id')))
  1678. ->select('id','process_id')
  1679. ->get()->toArray();
  1680. $map = [];
  1681. foreach ($orders as $value){
  1682. $p = explode(",", $value['process_id']);
  1683. $lastElement = end($p);
  1684. $map[$value['id']] = $lastElement;
  1685. }
  1686. $all_data_map = array_column($all_data,null,'dispatch_id');
  1687. $need_insert = [];
  1688. foreach ($dispatchList as $value){
  1689. $num = $all_data_map[$value['id']] ?? [];
  1690. $num = $num['num'] ?? 0;
  1691. if(! $num) continue;
  1692. if(isset($map[$value['order_product_id']]) && $map[$value['order_product_id']] == $value['process_id']){
  1693. $tmp = [
  1694. 'id' => $value['id'],
  1695. 'quantity' => $num,
  1696. 'product_no' => $value['product_no'] ?? "",
  1697. 'product_title' => $value['product_title'] ?? "",
  1698. 'product_size' => $value['product_size'] ?? "",
  1699. 'product_unit' => $value['product_unit'] ?? "",
  1700. ];
  1701. $need_insert[] = $tmp;
  1702. }
  1703. }
  1704. //生成完工入库申请单
  1705. $service = new BoxService();
  1706. list($status, $msg) = $service->createWGSQ($need_insert, $user);
  1707. if(! $status) return [false, $msg];
  1708. return [true, ''];
  1709. }
  1710. public function insertOther($all_data, $user, $time){
  1711. try {
  1712. $result = [];
  1713. foreach ($all_data as $value){
  1714. if($value['result'] > 0) $result[] = $value;
  1715. }
  1716. if(empty($result)) return [true, ''];
  1717. $dispatchList = DispatchSub::whereIn('id', array_column($result,'dispatch_sub_id'))->get()->toArray();
  1718. $dispatch_map = array_column($dispatchList,null,'id');
  1719. //是否自动审核
  1720. $em = new EmployeeService();
  1721. $auto = $em->is_auto($user, "pg_auto");
  1722. $dispatch_no = (new DispatchService())->setOrderNO();
  1723. if(! $dispatch_no) return [false,'返工派工单号生成失败!'];
  1724. $prefix = substr($dispatch_no, 0, -3);// "20250611"
  1725. $startNum = (int)substr($dispatch_no, -3); // 7
  1726. $is_first = true;
  1727. $dispatch_main = $dispatch = $is_need_ll = $is_need_warehouse = [];
  1728. foreach ($result as $value){
  1729. //派工单
  1730. $t = $dispatch_map[$value['dispatch_sub_id']] ?? [];
  1731. if(! $is_first){
  1732. $startNum += 1;
  1733. $number = str_pad($startNum,3,'0',STR_PAD_LEFT);
  1734. $number = $prefix . $number;
  1735. $dispatch_no_t = $number;
  1736. }else{
  1737. $dispatch_no_t = $dispatch_no;
  1738. $is_first = false;
  1739. }
  1740. if($value['result'] == ReportWorking::type_one){
  1741. //重新入生产流程 需要生成返工派工单
  1742. }else{
  1743. //入仓库 那么需要生成质检入库申请单 生成领料申请单 生成返工派工单
  1744. //'id','dispatch_quantity as quantity',"product_no","order_product_id","product_no",'technology_name','crt_time'
  1745. $is_need_ll[] = $dispatch_no_t;
  1746. $is_need_warehouse[] = [
  1747. 'warehouse_no' => $value['warehouse_no'],
  1748. 'warehouse_title' => $value['warehouse_title'],
  1749. ];
  1750. }
  1751. $dispatch_main[] = ['dispatch_no' => $dispatch_no_t,'crt_time' => $time];
  1752. $dispatch[] = [
  1753. 'order_product_id' => $t['order_product_id'],
  1754. 'order_no' => $t['order_no'],
  1755. 'product_no' => $t['product_no'],
  1756. 'product_title' => $t['product_title'],
  1757. 'product_size' => $t['product_size'],
  1758. 'product_unit' => $t['product_unit'],
  1759. 'production_quantity' => $t['production_quantity'],
  1760. 'dispatch_quantity' => $value['num'],
  1761. 'technology_material' => $t['technology_material'],
  1762. 'technology_name' => $t['technology_name'],
  1763. 'wood_name' => $t['wood_name'],
  1764. 'process_mark' => $t['process_mark'],
  1765. 'table_body_mark' => $t['table_body_mark'],
  1766. 'table_header_mark' => $t['table_header_mark'],
  1767. 'crt_time' => $time,
  1768. 'status' => $auto,
  1769. 'dispatch_no' => $dispatch_no_t,
  1770. 'process_id' => $t['process_id'],
  1771. 'dispatch_time_start' => $t['dispatch_time_start'],
  1772. 'dispatch_time_end' => $t['dispatch_time_end'],
  1773. 'crt_id' => $user['id'],
  1774. 'sale_orders_product_id' => $t['sale_orders_product_id'],
  1775. 'out_order_no' => $t['out_order_no'],
  1776. 'out_order_no_time' => $t['out_order_no_time'],
  1777. 'price' => $t['price'],
  1778. 'customer_no' => $t['customer_no'],
  1779. 'customer_name' => $t['customer_name'],
  1780. 'pre_shipment_time' => $t['pre_shipment_time'],
  1781. 'team_id' => $t['team_id'],
  1782. 'device_id' => $t['device_id'],
  1783. 'type' => 1,
  1784. ];
  1785. }
  1786. Dispatch::insert($dispatch_main);
  1787. DispatchSub::insert($dispatch);
  1788. if(! empty($is_need_ll)){
  1789. //获取上一次插入订单的所有数据
  1790. $insert = DispatchSub::whereIn('dispatch_no', $is_need_ll)
  1791. ->where('crt_time',$time)
  1792. ->where('crt_id',$user['id'])
  1793. ->select('id','dispatch_quantity as quantity',"product_no")
  1794. ->get()->toArray();
  1795. //领料申请单
  1796. list($status, $msg) = (new DispatchService())->createSQ($insert, $user);
  1797. if(! $status) return [false, $msg];
  1798. //质检入库申请单 原材料
  1799. list($status, $msg) = $this->createZJSQ($all_data, $user, $is_need_warehouse);
  1800. if(! $status) return [false, $msg];
  1801. }
  1802. return [true, ''];
  1803. }catch (\Throwable $exception){
  1804. return [false, $exception->getMessage()];
  1805. }
  1806. }
  1807. public function createZJSQ($insert_data, $user, $warehouse, $time = 0){
  1808. try {
  1809. DB::beginTransaction();
  1810. //是否自动审核质检入库申请单
  1811. $em = new EmployeeService();
  1812. $auto = $em->is_auto($user, "zjsq_auto");
  1813. $return = [];
  1814. $product_no = array_unique(array_column($insert_data,'product_no'));
  1815. //获取原料
  1816. $service = new FyyOrderService();
  1817. list($status, $msg) = $service->getProductDataFromSqlServer(['product_no' => $product_no], $user);
  1818. if($status) $return = $msg;
  1819. //组织原材料写入数据
  1820. $insert = [];
  1821. foreach ($insert_data as $key => $value){
  1822. $quantity = 0;
  1823. if(! empty($value['quantity'])) {
  1824. $quantity = $value['quantity'];
  1825. }elseif (! empty($value['dispatch_quantity'])){
  1826. $quantity = $value['dispatch_quantity'];
  1827. }elseif (! empty($value['num'])){
  1828. $quantity = $value['num'];
  1829. }
  1830. $t = $return[$value['product_no']] ?? [];
  1831. $tmp = [
  1832. 'id' => $value['id'],
  1833. 'quantity' => $quantity,
  1834. 'product_no' => "",
  1835. 'product_title' => "",
  1836. 'product_size' => "",
  1837. 'product_unit' => "",
  1838. 'storehouse_id' => $warehouse[$key]['warehouse_no'] ?? "",
  1839. 'storehouse_title' => $warehouse[$key]['warehouse_title'] ?? "",
  1840. ];
  1841. if(! empty($t)){
  1842. foreach ($t as $v){
  1843. $tmp['product_no'] = $v['product_no'];
  1844. $tmp['product_title'] = $v['product_title'];
  1845. $tmp['product_size'] = $v['product_size'];
  1846. $tmp['product_unit'] = $v['product_unit'];
  1847. $insert[] = $tmp;
  1848. }
  1849. }else{
  1850. $tmp['quantity'] = 0;
  1851. $insert[] = $tmp;
  1852. }
  1853. }
  1854. //生成质检入库申请单
  1855. $service = new ApplyOrderService();
  1856. list($status, $msg) = $service->createSqFive($insert, $user, ApplyOrder::type_five, $auto, $time);
  1857. if(! $status) {
  1858. DB::rollBack();
  1859. return [false, $msg];
  1860. }
  1861. DB::commit();
  1862. }catch (\Throwable $exception){
  1863. DB::rollBack();
  1864. return [false, $exception->getFile() . $exception->getMessage() . $exception->getLine()];
  1865. }
  1866. return [true, ''];
  1867. }
  1868. //反写
  1869. public function writeDispatchQuantity($dispatch_id){
  1870. $result = ScrappCount::where('del_time',0)
  1871. ->whereIn('dispatch_sub_id', $dispatch_id)
  1872. ->select('dispatch_sub_id','quantity','scrapp_num','crt_time','process_id','order_product_id')
  1873. ->get()->toArray();
  1874. //是否最后一道工序
  1875. $orders = OrdersProduct::whereIn('id', array_unique(array_column($result, 'order_product_id')))
  1876. ->select('id','process_id')
  1877. ->get()->toArray();
  1878. $map = [];
  1879. foreach ($orders as $value){
  1880. $p = explode(",", $value['process_id']);
  1881. $lastElement = end($p);
  1882. $map[$value['id']] = $lastElement;
  1883. }
  1884. //汇总这个派工单一共质检良品数量 但是同一时间下的 只取一次
  1885. $update = $flag = $need_update = [];
  1886. foreach ($result as $value){
  1887. if(isset($map[$value['order_product_id']]) && $map[$value['order_product_id']] == $value['process_id'] && ! in_array($value['order_product_id'], $need_update)){
  1888. $need_update[] = [
  1889. 'order_product_id' => $value['order_product_id'],
  1890. 'process_id' => $value['process_id'],
  1891. ];
  1892. }
  1893. $key = $value['dispatch_sub_id'] . $value['crt_time'];
  1894. if(isset($flag[$key])) continue;
  1895. if(isset($update[$value['dispatch_sub_id']])){
  1896. $tmp = bcadd($value['quantity'], $update[$value['dispatch_sub_id']], 3);
  1897. $update[$value['dispatch_sub_id']] = $tmp;
  1898. }else{
  1899. $update[$value['dispatch_sub_id']] = $value['quantity'];
  1900. }
  1901. $flag[$key] = 1;
  1902. }
  1903. unset($flag);
  1904. //更新派工单完工数量----------------------------------------------------
  1905. foreach ($update as $id => $num){
  1906. DispatchSub::where('id', $id)->update([
  1907. 'finished_num' => $num,
  1908. 'wg_status' => 1,
  1909. ]);
  1910. }
  1911. if(! empty($need_update)){
  1912. //更新生产订单的完工数量--------------------------------------------------
  1913. $list = DispatchSub::where("del_time",0)
  1914. ->when(! empty($need_update), function ($query) use ($need_update) {
  1915. return $query->where(function ($q) use ($need_update) {
  1916. foreach ($need_update as $value) {
  1917. $order_product_id = $value['order_product_id'];
  1918. $process_id = $value['process_id'];
  1919. $q->orWhere(function ($subQ) use ($order_product_id, $process_id) {
  1920. $subQ->where('order_product_id', $order_product_id)
  1921. ->where('process_id', $process_id);
  1922. });
  1923. }
  1924. });
  1925. })
  1926. ->select('order_product_id', 'finished_num', 'sale_orders_product_id')
  1927. ->get()->toArray();
  1928. $map2 = [];
  1929. foreach ($list as $value){
  1930. if(isset($map2[$value['order_product_id']])){
  1931. $tmp = bcadd($map2[$value['order_product_id']], $value['finished_num'], 3);
  1932. $map2[$value['order_product_id']] = $tmp;
  1933. }else{
  1934. $map2[$value['order_product_id']] = $value['finished_num'];
  1935. }
  1936. }
  1937. foreach ($map2 as $id => $num){
  1938. OrdersProduct::where('id', $id)->update([
  1939. 'finished_num' => $num
  1940. ]);
  1941. }
  1942. //更新销售订单完工数量-------------------------------------------------------
  1943. $list2 = OrdersProduct::where('del_time',0)
  1944. ->whereIn('sale_orders_product_id', array_unique(array_column($list, 'sale_orders_product_id')))
  1945. ->select('finished_num','sale_orders_product_id')
  1946. ->get()->toArray();
  1947. $map3 = [];
  1948. foreach ($list2 as $value){
  1949. if(isset($map3[$value['sale_orders_product_id']])){
  1950. $tmp = bcadd($map3[$value['sale_orders_product_id']], $value['finished_num'], 3);
  1951. $map3[$value['sale_orders_product_id']] = $tmp;
  1952. }else{
  1953. $map3[$value['sale_orders_product_id']] = $value['finished_num'];
  1954. }
  1955. }
  1956. foreach ($map3 as $id => $num){
  1957. SaleOrdersProduct::where('id', $id)->update([
  1958. 'finished_num' => $num
  1959. ]);
  1960. }
  1961. }
  1962. }
  1963. public function orderSearchList($data){
  1964. if(empty($data['type'])) return [false, '单据联查类型不能为空'];
  1965. if(empty($data['data_id'])) return [false, '依据单据ID不能为空'];
  1966. //不管进来的是什么单据id 转换为销售订单
  1967. $result = $this->changeIdToOrderNew($data);
  1968. // $sales_id = $this->changeIdToOrder($data);
  1969. // list($status, $msg) = $this->forSearch($data, $sales_id);
  1970. return [true, $result];
  1971. }
  1972. private function changeIdToOrder($data)
  1973. {
  1974. $id = $data['data_id'];
  1975. $search_id = $result = [];
  1976. if ($data['type'] == 1) {
  1977. $result[] = [
  1978. 'id' => $id
  1979. ];
  1980. } elseif ($data['type'] == 2) {
  1981. $result = OrdersProduct::where('del_time', 0)
  1982. ->where('id', $id)
  1983. ->select('sale_orders_product_id as id')
  1984. ->get()->toArray();
  1985. } elseif ($data['type'] == 3) {
  1986. $result = DispatchSub::where('del_time', 0)
  1987. ->where('id', $data['data_id'])
  1988. ->select('sale_orders_product_id as id')
  1989. ->get()->toArray();
  1990. } elseif ($data['type'] == 4) {
  1991. $detail = ReportWorkingDetail::where('report_working_id', $id)
  1992. ->where('del_time', 0)
  1993. ->select('data_id')
  1994. ->get()->toArray();
  1995. $result = DispatchSub::where('del_time', 0)
  1996. ->whereIn('id', array_unique(array_column($detail, 'data_id')))
  1997. ->select('sale_orders_product_id as id')
  1998. ->get()->toArray();
  1999. } elseif ($data['type'] == 5) {
  2000. $result = DispatchSub::where('del_time', 0)
  2001. ->where('id', $id)
  2002. ->where('finished_num', '>', 0)
  2003. ->select('sale_orders_product_id as id')
  2004. ->get()->toArray();
  2005. } elseif ($data['type'] == 6) {
  2006. $first = Box::where('del_time', 0)
  2007. ->where('id', $id)
  2008. ->select("top_order_no", 'order_no')
  2009. ->first();
  2010. if (!empty($first)) {
  2011. $first = $first->toArray();
  2012. $box_detail = new BoxDetail(['channel' => $first['top_order_no']]);
  2013. $result = $box_detail->where('order_no', $first['order_no'])->select('top_id as id')->get()->toArray();
  2014. }
  2015. } elseif ($data['type'] == 7) {
  2016. $result = ScrappCount::where('del_time', 0)
  2017. ->where('id', $id)
  2018. ->select('sale_orders_product_id as id')
  2019. ->get()->toArray();
  2020. } elseif ($data['type'] == 8) {
  2021. $result = ScrappCount::where('del_time', 0)
  2022. ->where('id', $id)
  2023. ->where('scrapp_num', '>', 0)
  2024. ->select('sale_orders_product_id as id')
  2025. ->get()->toArray();
  2026. } elseif ($data['type'] == 9) {
  2027. $detail = ApplyOrderDetail::where('del_time', 0)
  2028. ->where('apply_order_id', $id)
  2029. ->where('type', ApplyOrder::type_one)
  2030. ->select('data_id as dispatch_id')
  2031. ->get()->toArray();
  2032. $result = DispatchSub::where('del_time', 0)
  2033. ->where('id', array_unique(array_column($detail, 'dispatch_id')))
  2034. ->select('sale_orders_product_id as id')
  2035. ->get()->toArray();
  2036. } elseif ($data['type'] == 10) {
  2037. $detail = ApplyOrderDetail::where('del_time', 0)
  2038. ->where('apply_order_id', $id)
  2039. ->where('type', ApplyOrder::type_two)
  2040. ->select('data_id as dispatch_id')
  2041. ->get()->toArray();
  2042. $result = DispatchSub::where('del_time', 0)
  2043. ->where('id', array_unique(array_column($detail, 'dispatch_id')))
  2044. ->select('sale_orders_product_id as id')
  2045. ->get()->toArray();
  2046. } elseif ($data['type'] == 11) {
  2047. $detail = ApplyOrderDetail::where('del_time', 0)
  2048. ->where('apply_order_id', $id)
  2049. ->where('type', ApplyOrder::type_four)
  2050. ->select('data_id as box_id')
  2051. ->get()->toArray();
  2052. $first = Box::where('del_time', 0)
  2053. ->whereIn('id', array_unique(array_column($detail, 'box_id')))
  2054. ->select("top_order_no", 'order_no')
  2055. ->get()->toArray();
  2056. if (!empty($first)) {
  2057. foreach ($first as $value) {
  2058. $box_detail = new BoxDetail(['channel' => $value['top_order_no']]);
  2059. $t = $box_detail->where('order_no', $value['order_no'])->select('top_id as id')->get()->toArray();
  2060. $result = array_merge($result, $t);
  2061. }
  2062. }
  2063. } elseif ($data['type'] == 12) {
  2064. $detail = ApplyOrderDetail::where('del_time', 0)
  2065. ->where('apply_order_id', $id)
  2066. ->where('type', ApplyOrder::type_three)
  2067. ->select('data_id as box_id')
  2068. ->get()->toArray();
  2069. $first = Box::where('del_time', 0)
  2070. ->whereIn('id', array_unique(array_column($detail, 'box_id')))
  2071. ->select("top_order_no", 'order_no')
  2072. ->get()->toArray();
  2073. if (!empty($first)) {
  2074. foreach ($first as $value) {
  2075. $box_detail = new BoxDetail(['channel' => $value['top_order_no']]);
  2076. $t = $box_detail->where('order_no', $value['order_no'])->select('top_id as id')->get()->toArray();
  2077. $result = array_merge($result, $t);
  2078. }
  2079. }
  2080. } elseif ($data['type'] == 13) {
  2081. $detail = ApplyOrderDetail::where('del_time', 0)
  2082. ->where('apply_order_id', $id)
  2083. ->where('type', ApplyOrder::type_five)
  2084. ->select('data_id as zj_id')
  2085. ->get()->toArray();
  2086. $result = ScrappCount::where('del_time', 0)
  2087. ->whereIn('id', array_unique(array_column($detail, 'zj_id')))
  2088. ->select('sale_orders_product_id as id')
  2089. ->get()->toArray();
  2090. }
  2091. foreach ($result as $value) {
  2092. if (!in_array($value['id'], $search_id)) {
  2093. $search_id[] = $value['id'];
  2094. }
  2095. }
  2096. return $search_id;
  2097. }
  2098. private function forSearch($data, $sales_id){
  2099. $result = [];
  2100. //通过销售订单查找所有业务单据
  2101. if($data['for_type'] == 1){
  2102. $result = SaleOrdersProduct::where('del_time',0)
  2103. ->whereIn('id', $sales_id)
  2104. ->select('id', 'out_order_no as order_no')
  2105. ->get()->toArray();
  2106. }elseif($data['for_type'] == 2){
  2107. $result = OrdersProduct::where('del_time',0)
  2108. ->whereIn('sale_orders_product_id', $sales_id)
  2109. ->select('id', 'production_no as order_no')
  2110. ->get()->toArray();
  2111. }elseif($data['for_type'] == 3){
  2112. $result = DispatchSub::where('del_time',0)
  2113. ->whereIn('sale_orders_product_id', $sales_id)
  2114. ->select('id', 'dispatch_no as order_no')
  2115. ->get()->toArray();
  2116. }elseif($data['for_type'] == 4){
  2117. $dispatch = DispatchSub::where('del_time',0)
  2118. ->whereIn('sale_orders_product_id', $sales_id)
  2119. ->select('id')
  2120. ->get()->toArray();
  2121. $detail = ReportWorkingDetail::whereIn('data_id', array_column($dispatch,'id'))
  2122. ->where('del_time',0)
  2123. ->select('report_working_id')
  2124. ->get()->toArray();
  2125. $result = ReportWorking::where('del_time',0)
  2126. ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
  2127. ->select('id', 'order_number as order_no')
  2128. ->get()->toArray();
  2129. }elseif($data['for_type'] == 5){
  2130. $result = DispatchSub::where('del_time',0)
  2131. ->whereIn('sale_orders_product_id', $sales_id)
  2132. ->where('finished_num','>',0)
  2133. ->select('id', 'dispatch_no as order_no')
  2134. ->get()->toArray();
  2135. }elseif($data['for_type'] == 6){
  2136. $sale = SaleOrdersProduct::whereIn('id', $sales_id)->select('order_no')->get()->toArray();
  2137. foreach ($sale as $value){
  2138. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2139. $box_detail_order = $box_detail->where('top_id',$data['data_id'])->select('order_no')->get()->toArray();
  2140. $tmp = Box::where('del_time',0)
  2141. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2142. ->select("id","order_no")
  2143. ->get()->toArray();
  2144. $result = array_merge($result, $tmp);
  2145. }
  2146. }elseif ($data['for_type'] == 7){
  2147. $result = ScrappCount::where('del_time',0)
  2148. ->whereIn('sale_orders_product_id', $sales_id)
  2149. ->select('id', 'order_number as order_no')
  2150. ->get()->toArray();
  2151. }elseif ($data['for_type'] == 8){
  2152. $result = ScrappCount::where('del_time',0)
  2153. ->whereIn('sale_orders_product_id', $sales_id)
  2154. ->where('scrapp_num','>', 0)
  2155. ->select('id', 'order_number as order_no')
  2156. ->get()->toArray();
  2157. }elseif ($data['for_type'] == 9){
  2158. $dispatch = DispatchSub::where('del_time',0)
  2159. ->whereIn('sale_orders_product_id', $sales_id)
  2160. ->select('id')
  2161. ->get()->toArray();
  2162. $detail = ApplyOrderDetail::where('del_time',0)
  2163. ->whereIn('data_id', array_column($dispatch,'id'))
  2164. ->where('type',ApplyOrder::type_one)
  2165. ->select('apply_order_id')
  2166. ->get()->toArray();
  2167. $result = ApplyOrder::where('del_time',0)
  2168. ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
  2169. ->select('id','order_number as order_no')
  2170. ->get()->toArray();
  2171. }elseif ($data['for_type'] == 10){
  2172. $dispatch = DispatchSub::where('del_time',0)
  2173. ->whereIn('sale_orders_product_id', $sales_id)
  2174. ->select('id')
  2175. ->get()->toArray();
  2176. $detail = ApplyOrderDetail::where('del_time',0)
  2177. ->whereIn('data_id', array_column($dispatch,'id'))
  2178. ->where('type',ApplyOrder::type_two)
  2179. ->select('apply_order_id')
  2180. ->get()->toArray();
  2181. $result = ApplyOrder::where('del_time',0)
  2182. ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
  2183. ->select('id','order_number as order_no')
  2184. ->get()->toArray();
  2185. }elseif($data['for_type'] == 11){
  2186. $sale = SaleOrdersProduct::whereIn('id', $sales_id)->select('order_no')->get()->toArray();
  2187. $ids = [];
  2188. foreach ($sale as $value){
  2189. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2190. $box_detail_order = $box_detail->where('top_id',$data['data_id'])->select('order_no')->get()->toArray();
  2191. $tmp = Box::where('del_time',0)
  2192. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2193. ->select("id")
  2194. ->get()->toArray();
  2195. $ids = array_merge($ids, $tmp);
  2196. }
  2197. $detail = ApplyOrderDetail::where('del_time',0)
  2198. ->whereIn('data_id', array_column($ids,'id'))
  2199. ->where('type',ApplyOrder::type_four)
  2200. ->select('apply_order_id')
  2201. ->get()->toArray();
  2202. $result = ApplyOrder::where('del_time',0)
  2203. ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
  2204. ->select('id','order_number as order_no')
  2205. ->get()->toArray();
  2206. }elseif($data['for_type'] == 12){
  2207. $sale = SaleOrdersProduct::whereIn('id', $sales_id)->select('order_no')->get()->toArray();
  2208. $ids = [];
  2209. foreach ($sale as $value){
  2210. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2211. $box_detail_order = $box_detail->where('top_id',$data['data_id'])->select('order_no')->get()->toArray();
  2212. $tmp = Box::where('del_time',0)
  2213. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2214. ->select("id")
  2215. ->get()->toArray();
  2216. $ids = array_merge($ids, $tmp);
  2217. }
  2218. $detail = ApplyOrderDetail::where('del_time',0)
  2219. ->whereIn('data_id', array_column($ids,'id'))
  2220. ->where('type',ApplyOrder::type_three)
  2221. ->select('apply_order_id')
  2222. ->get()->toArray();
  2223. $result = ApplyOrder::where('del_time',0)
  2224. ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
  2225. ->select('id','order_number as order_no')
  2226. ->get()->toArray();
  2227. }elseif($data['for_type'] == 13){
  2228. $zj_id = ScrappCount::where('del_time',0)
  2229. ->where('scrapp_num','>',0)
  2230. ->whereIn('sale_orders_product_id', $sales_id)
  2231. ->select('id')
  2232. ->get()->toArray();
  2233. $detail = ApplyOrderDetail::where('del_time',0)
  2234. ->whereIn('data_id', array_column($zj_id,'id'))
  2235. ->where('type',ApplyOrder::type_five)
  2236. ->select('apply_order_id')
  2237. ->get()->toArray();
  2238. $result = ApplyOrder::where('del_time',0)
  2239. ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
  2240. ->select('id','order_number as order_no')
  2241. ->get()->toArray();
  2242. }
  2243. return [true, $result];
  2244. }
  2245. private function changeIdToOrderNew1($data)
  2246. {
  2247. $id = $data['data_id'];
  2248. $search_id = $result = [];
  2249. if ($data['type'] == 1) {
  2250. } elseif ($data['type'] == 2) {
  2251. $result[1] = OrdersProduct::where('del_time', 0)
  2252. ->where('id', $id)
  2253. ->pluck('sale_orders_product_id')
  2254. ->toArray();
  2255. } elseif ($data['type'] == 3) {
  2256. $array = DispatchSub::where('del_time', 0)
  2257. ->where('id', $data['data_id'])
  2258. ->select('sale_orders_product_id', 'order_product_id')
  2259. ->get()->toArray();
  2260. foreach ($array as $value){
  2261. $result[1][] = $value['sale_orders_product_id'];
  2262. $result[2][] = $value['order_product_id'];
  2263. }
  2264. } elseif ($data['type'] == 4) {
  2265. $detail = ReportWorkingDetail::where('report_working_id', $id)
  2266. ->where('del_time', 0)
  2267. ->select('data_id')
  2268. ->get()->toArray();
  2269. $array = DispatchSub::where('del_time', 0)
  2270. ->whereIn('id', array_unique(array_column($detail, 'data_id')))
  2271. ->select('sale_orders_product_id', 'order_product_id','id')
  2272. ->get()->toArray();
  2273. foreach ($array as $value){
  2274. $result[1][] = $value['sale_orders_product_id'];
  2275. $result[2][] = $value['order_product_id'];
  2276. $result[3][] = $value['id'];
  2277. }
  2278. } elseif ($data['type'] == 5) {
  2279. $array = DispatchSub::where('del_time', 0)
  2280. ->where('id', $id)
  2281. ->where('finished_num', '>', 0)
  2282. ->select('sale_orders_product_id', 'order_product_id','id')
  2283. ->get()->toArray();
  2284. foreach ($array as $value){
  2285. $result[1][] = $value['sale_orders_product_id'];
  2286. $result[2][] = $value['order_product_id'];
  2287. $result[3][] = $value['id'];
  2288. }
  2289. $detail = ReportWorkingDetail::where('data_id', $id)
  2290. ->where('del_time', 0)
  2291. ->select('report_working_id')
  2292. ->get()->toArray();
  2293. foreach ($detail as $value){
  2294. $result[4][] = $value['report_working_id'];
  2295. }
  2296. } elseif ($data['type'] == 6) {
  2297. $first = Box::where('del_time', 0)
  2298. ->where('id', $id)
  2299. ->select("top_order_no", 'order_no','id')
  2300. ->first();
  2301. if (! empty($first)) {
  2302. $first = $first->toArray();
  2303. $boxArray = BoxWithDispatch::where('del_time',0)
  2304. ->where('box_id',$first['id'])
  2305. ->select('dispatch_id','num')
  2306. ->get()->toArray();
  2307. if(! empty($boxArray)){
  2308. $dispatch_id = array_column($boxArray,'dispatch_id');
  2309. $array = DispatchSub::where('del_time', 0)
  2310. ->whereIn('id',$dispatch_id)
  2311. ->select('sale_orders_product_id', 'order_product_id','id')
  2312. ->get()->toArray();
  2313. foreach ($array as $value){
  2314. $result[1][] = $value['sale_orders_product_id'];
  2315. $result[2][] = $value['order_product_id'];
  2316. $result[3][] = $value['id'];
  2317. }
  2318. $detail = ReportWorkingDetail::whereIn('data_id', $dispatch_id)
  2319. ->where('del_time', 0)
  2320. ->select('report_working_id')
  2321. ->get()->toArray();
  2322. foreach ($detail as $value){
  2323. $result[4][] = $value['report_working_id'];
  2324. }
  2325. $result[5] = $dispatch_id;
  2326. }else{
  2327. $array = [];
  2328. $box_detail = new BoxDetail(['channel' => $first['top_order_no']]);
  2329. $detail = $box_detail->where('order_no', $first['order_no'])->select('top_id as id')->get()->toArray();
  2330. foreach ($detail as $value){
  2331. if(! in_array($value['id'], $array)) $array[] = $value['id'];
  2332. }
  2333. $result[1] = $array;
  2334. $result[2] = OrdersProduct::where('del_time',0)
  2335. ->whereIn('sale_orders_product_id',$array)
  2336. ->pluck('id')->toArray();
  2337. }
  2338. }
  2339. } elseif ($data['type'] == 7) {
  2340. $result = ScrappCount::where('del_time', 0)
  2341. ->where('id', $id)
  2342. ->select('sale_orders_product_id as id')
  2343. ->get()->toArray();
  2344. } elseif ($data['type'] == 8) {
  2345. $result = ScrappCount::where('del_time', 0)
  2346. ->where('id', $id)
  2347. ->where('scrapp_num', '>', 0)
  2348. ->select('sale_orders_product_id as id')
  2349. ->get()->toArray();
  2350. } elseif ($data['type'] == 9) {
  2351. $detail = ApplyOrderDetail::where('del_time', 0)
  2352. ->where('apply_order_id', $id)
  2353. ->where('type', ApplyOrder::type_one)
  2354. ->select('data_id as dispatch_id')
  2355. ->get()->toArray();
  2356. $result = DispatchSub::where('del_time', 0)
  2357. ->where('id', array_unique(array_column($detail, 'dispatch_id')))
  2358. ->select('sale_orders_product_id as id')
  2359. ->get()->toArray();
  2360. } elseif ($data['type'] == 10) {
  2361. $detail = ApplyOrderDetail::where('del_time', 0)
  2362. ->where('apply_order_id', $id)
  2363. ->where('type', ApplyOrder::type_two)
  2364. ->select('data_id as dispatch_id')
  2365. ->get()->toArray();
  2366. $result = DispatchSub::where('del_time', 0)
  2367. ->where('id', array_unique(array_column($detail, 'dispatch_id')))
  2368. ->select('sale_orders_product_id as id')
  2369. ->get()->toArray();
  2370. } elseif ($data['type'] == 11) {
  2371. $detail = ApplyOrderDetail::where('del_time', 0)
  2372. ->where('apply_order_id', $id)
  2373. ->where('type', ApplyOrder::type_four)
  2374. ->select('data_id as box_id')
  2375. ->get()->toArray();
  2376. $first = Box::where('del_time', 0)
  2377. ->whereIn('id', array_unique(array_column($detail, 'box_id')))
  2378. ->select("top_order_no", 'order_no')
  2379. ->get()->toArray();
  2380. if (!empty($first)) {
  2381. foreach ($first as $value) {
  2382. $box_detail = new BoxDetail(['channel' => $value['top_order_no']]);
  2383. $t = $box_detail->where('order_no', $value['order_no'])->select('top_id as id')->get()->toArray();
  2384. $result = array_merge($result, $t);
  2385. }
  2386. }
  2387. } elseif ($data['type'] == 12) {
  2388. $detail = ApplyOrderDetail::where('del_time', 0)
  2389. ->where('apply_order_id', $id)
  2390. ->where('type', ApplyOrder::type_three)
  2391. ->select('data_id as box_id')
  2392. ->get()->toArray();
  2393. $first = Box::where('del_time', 0)
  2394. ->whereIn('id', array_unique(array_column($detail, 'box_id')))
  2395. ->select("top_order_no", 'order_no')
  2396. ->get()->toArray();
  2397. if (!empty($first)) {
  2398. foreach ($first as $value) {
  2399. $box_detail = new BoxDetail(['channel' => $value['top_order_no']]);
  2400. $t = $box_detail->where('order_no', $value['order_no'])->select('top_id as id')->get()->toArray();
  2401. $result = array_merge($result, $t);
  2402. }
  2403. }
  2404. } elseif ($data['type'] == 13) {
  2405. $detail = ApplyOrderDetail::where('del_time', 0)
  2406. ->where('apply_order_id', $id)
  2407. ->where('type', ApplyOrder::type_five)
  2408. ->select('data_id as zj_id')
  2409. ->get()->toArray();
  2410. $result = ScrappCount::where('del_time', 0)
  2411. ->whereIn('id', array_unique(array_column($detail, 'zj_id')))
  2412. ->select('sale_orders_product_id as id')
  2413. ->get()->toArray();
  2414. }
  2415. foreach ($result as $value) {
  2416. if (!in_array($value['id'], $search_id)) {
  2417. $search_id[] = $value['id'];
  2418. }
  2419. }
  2420. return $search_id;
  2421. }
  2422. private function changeIdToOrderNew($data)
  2423. {
  2424. $id = $data['data_id'];
  2425. $result = [];
  2426. $type = $data['type'];
  2427. $for_type = $data['for_type'];
  2428. if ($data['type'] == 1) {
  2429. $result = $this->typeOne($for_type, $id);
  2430. } elseif ($type == 2) {
  2431. $result = $this->typeTwo($for_type, $id);
  2432. } elseif ($type == 3) {
  2433. $result = $this->typeThree($for_type, $id);
  2434. } elseif ($type == 4) {
  2435. $result = $this->typeFour($for_type, $id);
  2436. } elseif ($type == 5) {
  2437. $result = $this->typeFive($for_type, $id);
  2438. } elseif ($type == 6) {
  2439. $result = $this->typeSix($for_type, $id);
  2440. } elseif ($type == 7) {
  2441. $result = $this->typeSeven($for_type, $id);
  2442. } elseif ($type == 8) {
  2443. $result = $this->typeEight($for_type, $id);
  2444. } elseif ($type == 9) {
  2445. $result = $this->typeNine($for_type, $id);
  2446. } elseif ($type == 10) {
  2447. $result = $this->typeTen($for_type, $id);
  2448. } elseif ($type == 11) {
  2449. $result = $this->typeEve($for_type, $id);
  2450. } elseif ($type == 12) {
  2451. $result = $this->typeTwl($for_type, $id);
  2452. } elseif ($type == 13) {
  2453. $result = $this->typeThi($for_type, $id);
  2454. } elseif ($type == 14) {
  2455. $result = $this->typeFourTeen($for_type, $id);
  2456. }
  2457. return $result;
  2458. }
  2459. private function typeOne($for_type, $id){
  2460. $result = [];
  2461. if($for_type == 2){
  2462. $result = OrdersProduct::where('del_time',0)
  2463. ->where('sale_orders_product_id', $id)
  2464. ->select('id', 'production_no as order_no')
  2465. ->get()->toArray();
  2466. }elseif ($for_type == 3){
  2467. $result = DispatchSub::where('del_time',0)
  2468. ->where('sale_orders_product_id', $id)
  2469. ->select('id', 'dispatch_no as order_no')
  2470. ->get()->toArray();
  2471. }elseif ($for_type == 4){
  2472. $dispatch = DispatchSub::where('del_time',0)
  2473. ->where('sale_orders_product_id', $id)
  2474. ->select('id')
  2475. ->get()->toArray();
  2476. $detail = ReportWorkingDetail::whereIn('data_id', array_column($dispatch,'id'))
  2477. ->where('del_time',0)
  2478. ->select('report_working_id')
  2479. ->get()->toArray();
  2480. $result = ReportWorking::where('del_time',0)
  2481. ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
  2482. ->select('id', 'order_number as order_no')
  2483. ->get()->toArray();
  2484. }elseif ($for_type == 5){
  2485. $result = DispatchSub::where('del_time',0)
  2486. ->where('sale_orders_product_id', $id)
  2487. ->where('finished_num','>',0)
  2488. ->select('id', 'dispatch_no as order_no')
  2489. ->get()->toArray();
  2490. }elseif ($for_type == 6){
  2491. $sale = SaleOrdersProduct::where('id', $id)->select('order_no')->get()->toArray();
  2492. foreach ($sale as $value){
  2493. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2494. $box_detail_order = $box_detail->where('top_id',$id)->select('order_no')->get()->toArray();
  2495. $tmp = Box::where('del_time',0)
  2496. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2497. ->select("id","order_no")
  2498. ->get()->toArray();
  2499. $result = array_merge($result, $tmp);
  2500. }
  2501. }elseif ($for_type == 7){
  2502. $process = Process::where('del_time',0)
  2503. ->where('is_need_remain',1)
  2504. ->pluck('id')
  2505. ->toArray();
  2506. $result = ScrappCount::where('del_time',0)
  2507. ->where('sale_orders_product_id', $id)
  2508. ->whereIn('process_id', $process)
  2509. ->select('id', 'order_number as order_no')
  2510. ->get()->toArray();
  2511. }elseif ($for_type == 8){
  2512. $result = ScrappCount::where('del_time',0)
  2513. ->where('sale_orders_product_id', $id)
  2514. ->where('scrapp_num','>', 0)
  2515. ->select('id', 'order_number as order_no')
  2516. ->get()->toArray();
  2517. }elseif ($for_type == 9){
  2518. $dispatch_id = DispatchSub::where('del_time',0)
  2519. ->where('sale_orders_product_id', $id)
  2520. ->pluck('id')
  2521. ->toArray();
  2522. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2523. ->whereIn('data_id', $dispatch_id)
  2524. ->where('type', ApplyOrder::type_one)
  2525. ->pluck('apply_order_id')
  2526. ->toArray();
  2527. $result = ApplyOrder::where('del_time', 0)
  2528. ->whereIn('id', $apply_order_id)
  2529. ->select('id','order_number as order_no')
  2530. ->get()->toArray();
  2531. }elseif ($for_type == 10){
  2532. $dispatch_id = DispatchSub::where('del_time',0)
  2533. ->where('sale_orders_product_id', $id)
  2534. ->pluck('id')
  2535. ->toArray();
  2536. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2537. ->whereIn('data_id', $dispatch_id)
  2538. ->where('type', ApplyOrder::type_two)
  2539. ->pluck('apply_order_id')
  2540. ->toArray();
  2541. $result = ApplyOrder::where('del_time', 0)
  2542. ->whereIn('id', $apply_order_id)
  2543. ->select('id','order_number as order_no')
  2544. ->get()->toArray();
  2545. }elseif ($for_type == 11){
  2546. $sale = SaleOrdersProduct::where('id', $id)->select('order_no','id')->get()->toArray();
  2547. $box_id = [];
  2548. foreach ($sale as $value){
  2549. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2550. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  2551. $tmp = Box::where('del_time',0)
  2552. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2553. ->pluck("id")
  2554. ->toArray();
  2555. $box_id = array_merge($box_id, $tmp);
  2556. }
  2557. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2558. ->whereIn('data_id', $box_id)
  2559. ->where('type', ApplyOrder::type_four)
  2560. ->pluck('apply_order_id')
  2561. ->toArray();
  2562. $result = ApplyOrder::where('del_time', 0)
  2563. ->whereIn('id', $apply_order_id)
  2564. ->select('id','order_number as order_no')
  2565. ->get()->toArray();
  2566. }elseif ($for_type == 12){
  2567. $sale = SaleOrdersProduct::where('id', $id)->select('order_no','id')->get()->toArray();
  2568. $box_id = [];
  2569. foreach ($sale as $value){
  2570. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2571. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  2572. $tmp = Box::where('del_time',0)
  2573. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2574. ->pluck("id")
  2575. ->toArray();
  2576. $box_id = array_merge($box_id, $tmp);
  2577. }
  2578. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2579. ->whereIn('data_id', $box_id)
  2580. ->where('type', ApplyOrder::type_three)
  2581. ->pluck('apply_order_id')
  2582. ->toArray();
  2583. $result = ApplyOrder::where('del_time', 0)
  2584. ->whereIn('id', $apply_order_id)
  2585. ->select('id','order_number as order_no')
  2586. ->get()->toArray();
  2587. }elseif ($for_type == 13){
  2588. $s_id = ScrappCount::where('del_time', 0)
  2589. ->where('sale_orders_product_id', $id)
  2590. ->pluck('id')
  2591. ->toArray();
  2592. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2593. ->whereIn('data_id', $s_id)
  2594. ->where('type', ApplyOrder::type_five)
  2595. ->pluck('apply_order_id')
  2596. ->toArray();
  2597. $result = ApplyOrder::where('del_time', 0)
  2598. ->whereIn('id', $apply_order_id)
  2599. ->select('id','order_number as order_no')
  2600. ->get()->toArray();
  2601. }elseif ($for_type == 14){
  2602. $sale = SaleOrdersProduct::where('id', $id)->select('order_no','id')->get()->toArray();
  2603. $box_id = [];
  2604. foreach ($sale as $value){
  2605. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2606. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  2607. $tmp = Box::where('del_time',0)
  2608. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2609. ->pluck("id")
  2610. ->toArray();
  2611. $box_id = array_merge($box_id, $tmp);
  2612. }
  2613. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2614. ->whereIn('data_id', $box_id)
  2615. ->where('type', ApplyOrder::type_six)
  2616. ->pluck('apply_order_id')
  2617. ->toArray();
  2618. $result = ApplyOrder::where('del_time', 0)
  2619. ->whereIn('id', $apply_order_id)
  2620. ->select('id','order_number as order_no')
  2621. ->get()->toArray();
  2622. }
  2623. return $result;
  2624. }
  2625. private function typeTwo($for_type, $id){
  2626. $result = [];
  2627. if($for_type == 1){
  2628. $sale_orders_product_id = OrdersProduct::where('del_time',0)
  2629. ->where('id', $id)
  2630. ->pluck('sale_orders_product_id')
  2631. ->toArray();
  2632. $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
  2633. ->where('del_time',0)
  2634. ->select('id','out_order_no as order_no')
  2635. ->get()->toArray();
  2636. }elseif ($for_type == 3){
  2637. $result = DispatchSub::where('del_time',0)
  2638. ->where('order_product_id', $id)
  2639. ->select('id', 'dispatch_no as order_no')
  2640. ->get()->toArray();
  2641. }elseif ($for_type == 4){
  2642. $dispatch = DispatchSub::where('del_time',0)
  2643. ->where('order_product_id', $id)
  2644. ->select('id')
  2645. ->get()->toArray();
  2646. $detail = ReportWorkingDetail::whereIn('data_id', array_column($dispatch,'id'))
  2647. ->where('del_time',0)
  2648. ->select('report_working_id')
  2649. ->get()->toArray();
  2650. $result = ReportWorking::where('del_time',0)
  2651. ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
  2652. ->select('id', 'order_number as order_no')
  2653. ->get()->toArray();
  2654. }elseif ($for_type == 5){
  2655. $result = DispatchSub::where('del_time',0)
  2656. ->where('order_product_id', $id)
  2657. ->where('finished_num','>',0)
  2658. ->select('id', 'dispatch_no as order_no')
  2659. ->get()->toArray();
  2660. }elseif ($for_type == 6){
  2661. $sale_orders_product_id = OrdersProduct::where('del_time',0)
  2662. ->where('id', $id)
  2663. ->pluck('sale_orders_product_id')
  2664. ->toArray();
  2665. $sale = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)->select('order_no','id')->get()->toArray();
  2666. foreach ($sale as $value){
  2667. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2668. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  2669. $tmp = Box::where('del_time',0)
  2670. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2671. ->select("id","order_no")
  2672. ->get()->toArray();
  2673. $result = array_merge($result, $tmp);
  2674. }
  2675. }elseif ($for_type == 7){
  2676. $process = Process::where('del_time',0)
  2677. ->where('is_need_remain',1)
  2678. ->pluck('id')
  2679. ->toArray();
  2680. $result = ScrappCount::where('del_time',0)
  2681. ->where('order_product_id', $id)
  2682. ->whereIn('process_id', $process)
  2683. ->select('id', 'order_number as order_no')
  2684. ->get()->toArray();
  2685. }elseif ($for_type == 8){
  2686. $result = ScrappCount::where('del_time',0)
  2687. ->where('order_product_id', $id)
  2688. ->where('scrapp_num','>', 0)
  2689. ->select('id', 'order_number as order_no')
  2690. ->get()->toArray();
  2691. }elseif ($for_type == 9){
  2692. $dispatch_id = DispatchSub::where('del_time',0)
  2693. ->where('order_product_id', $id)
  2694. ->pluck('id')
  2695. ->toArray();
  2696. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2697. ->whereIn('data_id', $dispatch_id)
  2698. ->where('type', ApplyOrder::type_one)
  2699. ->pluck('apply_order_id')
  2700. ->toArray();
  2701. $result = ApplyOrder::where('del_time', 0)
  2702. ->whereIn('id', $apply_order_id)
  2703. ->select('id','order_number as order_no')
  2704. ->get()->toArray();
  2705. }elseif ($for_type == 10){
  2706. $dispatch_id = DispatchSub::where('del_time',0)
  2707. ->where('order_product_id', $id)
  2708. ->pluck('id')
  2709. ->toArray();
  2710. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2711. ->whereIn('data_id', $dispatch_id)
  2712. ->where('type', ApplyOrder::type_two)
  2713. ->pluck('apply_order_id')
  2714. ->toArray();
  2715. $result = ApplyOrder::where('del_time', 0)
  2716. ->whereIn('id', $apply_order_id)
  2717. ->select('id','order_number as order_no')
  2718. ->get()->toArray();
  2719. }elseif ($for_type == 11){
  2720. $sale = OrdersProduct::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  2721. $box_id = [];
  2722. foreach ($sale as $value){
  2723. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2724. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  2725. $tmp = Box::where('del_time',0)
  2726. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2727. ->pluck("id")
  2728. ->toArray();
  2729. $box_id = array_merge($box_id, $tmp);
  2730. }
  2731. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2732. ->whereIn('data_id', $box_id)
  2733. ->where('type', ApplyOrder::type_four)
  2734. ->pluck('apply_order_id')
  2735. ->toArray();
  2736. $result = ApplyOrder::where('del_time', 0)
  2737. ->whereIn('id', $apply_order_id)
  2738. ->select('id','order_number as order_no')
  2739. ->get()->toArray();
  2740. }elseif ($for_type == 12){
  2741. $sale = OrdersProduct::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  2742. $box_id = [];
  2743. foreach ($sale as $value){
  2744. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2745. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  2746. $tmp = Box::where('del_time',0)
  2747. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2748. ->pluck("id")
  2749. ->toArray();
  2750. $box_id = array_merge($box_id, $tmp);
  2751. }
  2752. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2753. ->whereIn('data_id', $box_id)
  2754. ->where('type', ApplyOrder::type_three)
  2755. ->pluck('apply_order_id')
  2756. ->toArray();
  2757. $result = ApplyOrder::where('del_time', 0)
  2758. ->whereIn('id', $apply_order_id)
  2759. ->select('id','order_number as order_no')
  2760. ->get()->toArray();
  2761. }elseif ($for_type == 13){
  2762. $s_id = ScrappCount::where('del_time', 0)
  2763. ->where('order_product_id', $id)
  2764. ->pluck('id')
  2765. ->toArray();
  2766. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2767. ->whereIn('data_id', $s_id)
  2768. ->where('type', ApplyOrder::type_five)
  2769. ->pluck('apply_order_id')
  2770. ->toArray();
  2771. $result = ApplyOrder::where('del_time', 0)
  2772. ->whereIn('id', $apply_order_id)
  2773. ->select('id','order_number as order_no')
  2774. ->get()->toArray();
  2775. }elseif ($for_type == 14){
  2776. $sale = OrdersProduct::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  2777. $box_id = [];
  2778. foreach ($sale as $value){
  2779. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2780. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  2781. $tmp = Box::where('del_time',0)
  2782. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2783. ->pluck("id")
  2784. ->toArray();
  2785. $box_id = array_merge($box_id, $tmp);
  2786. }
  2787. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2788. ->whereIn('data_id', $box_id)
  2789. ->where('type', ApplyOrder::type_six)
  2790. ->pluck('apply_order_id')
  2791. ->toArray();
  2792. $result = ApplyOrder::where('del_time', 0)
  2793. ->whereIn('id', $apply_order_id)
  2794. ->select('id','order_number as order_no')
  2795. ->get()->toArray();
  2796. }
  2797. return $result;
  2798. }
  2799. private function typeThree($for_type, $id){
  2800. $result = [];
  2801. if($for_type == 1){
  2802. $sale_orders_product_id = DispatchSub::where('del_time',0)
  2803. ->where('id', $id)
  2804. ->pluck('sale_orders_product_id')
  2805. ->toArray();
  2806. $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
  2807. ->where('del_time',0)
  2808. ->select('id','out_order_no as order_no')
  2809. ->get()->toArray();
  2810. }elseif ($for_type == 2){
  2811. $order_product_id = DispatchSub::where('del_time',0)
  2812. ->where('id', $id)
  2813. ->pluck('order_product_id')
  2814. ->toArray();
  2815. $result = OrdersProduct::where('del_time',0)
  2816. ->whereIn('id', $order_product_id)
  2817. ->select('id', 'production_no as order_no')
  2818. ->get()->toArray();
  2819. }elseif ($for_type == 4){
  2820. $dispatch = DispatchSub::where('del_time',0)
  2821. ->where('id', $id)
  2822. ->select('id')
  2823. ->get()->toArray();
  2824. $detail = ReportWorkingDetail::whereIn('data_id', array_column($dispatch,'id'))
  2825. ->where('del_time',0)
  2826. ->select('report_working_id')
  2827. ->get()->toArray();
  2828. $result = ReportWorking::where('del_time',0)
  2829. ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
  2830. ->select('id', 'order_number as order_no')
  2831. ->get()->toArray();
  2832. }elseif ($for_type == 5){
  2833. $result = DispatchSub::where('del_time',0)
  2834. ->where('id', $id)
  2835. ->where('finished_num','>',0)
  2836. ->select('id', 'dispatch_no as order_no')
  2837. ->get()->toArray();
  2838. }elseif ($for_type == 6){
  2839. $sale_orders_product_id = DispatchSub::where('del_time',0)
  2840. ->where('id', $id)
  2841. ->pluck('sale_orders_product_id')
  2842. ->toArray();
  2843. $sale = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)->select('order_no','id')->get()->toArray();
  2844. foreach ($sale as $value){
  2845. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2846. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  2847. $tmp = Box::where('del_time',0)
  2848. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2849. ->select("id","order_no")
  2850. ->get()->toArray();
  2851. $result = array_merge($result, $tmp);
  2852. }
  2853. }elseif ($for_type == 7){
  2854. $process = Process::where('del_time',0)
  2855. ->where('is_need_remain',1)
  2856. ->pluck('id')
  2857. ->toArray();
  2858. $result = ScrappCount::where('del_time',0)
  2859. ->where('dispatch_sub_id', $id)
  2860. ->whereIn('process_id', $process)
  2861. ->select('id', 'order_number as order_no')
  2862. ->get()->toArray();
  2863. }elseif ($for_type == 8){
  2864. $result = ScrappCount::where('del_time',0)
  2865. ->where('dispatch_sub_id', $id)
  2866. ->where('scrapp_num','>', 0)
  2867. ->select('id', 'order_number as order_no')
  2868. ->get()->toArray();
  2869. }elseif ($for_type == 9){
  2870. $dispatch = DispatchSub::where('id',$id)
  2871. ->select('order_product_id','crt_time','product_no','technology_name')
  2872. ->first()->toArray();
  2873. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  2874. ->where('crt_time',$dispatch['crt_time'])
  2875. ->where('product_no',$dispatch['product_no'])
  2876. ->where('technology_name',$dispatch['technology_name'])
  2877. ->pluck('id')->toArray();
  2878. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2879. ->whereIn('data_id', $dispatch_id)
  2880. ->where('type', ApplyOrder::type_one)
  2881. ->pluck('apply_order_id')
  2882. ->toArray();
  2883. $result = ApplyOrder::where('del_time', 0)
  2884. ->whereIn('id', $apply_order_id)
  2885. ->select('id','order_number as order_no')
  2886. ->get()->toArray();
  2887. }elseif ($for_type == 10){
  2888. $dispatch = DispatchSub::where('id',$id)
  2889. ->select('order_product_id','crt_time','product_no','technology_name')
  2890. ->first()->toArray();
  2891. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  2892. ->where('crt_time',$dispatch['crt_time'])
  2893. ->where('product_no',$dispatch['product_no'])
  2894. ->where('technology_name',$dispatch['technology_name'])
  2895. ->pluck('id')->toArray();
  2896. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2897. ->whereIn('data_id', $dispatch_id)
  2898. ->where('type', ApplyOrder::type_two)
  2899. ->pluck('apply_order_id')
  2900. ->toArray();
  2901. $result = ApplyOrder::where('del_time', 0)
  2902. ->whereIn('id', $apply_order_id)
  2903. ->select('id','order_number as order_no')
  2904. ->get()->toArray();
  2905. }elseif ($for_type == 11){
  2906. $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  2907. $box_id = [];
  2908. foreach ($sale as $value){
  2909. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2910. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  2911. $tmp = Box::where('del_time',0)
  2912. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2913. ->pluck("id")
  2914. ->toArray();
  2915. $box_id = array_merge($box_id, $tmp);
  2916. }
  2917. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2918. ->whereIn('data_id', $box_id)
  2919. ->where('type', ApplyOrder::type_four)
  2920. ->pluck('apply_order_id')
  2921. ->toArray();
  2922. $result = ApplyOrder::where('del_time', 0)
  2923. ->whereIn('id', $apply_order_id)
  2924. ->select('id','order_number as order_no')
  2925. ->get()->toArray();
  2926. }elseif ($for_type == 12){
  2927. $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  2928. $box_id = [];
  2929. foreach ($sale as $value){
  2930. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2931. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  2932. $tmp = Box::where('del_time',0)
  2933. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2934. ->pluck("id")
  2935. ->toArray();
  2936. $box_id = array_merge($box_id, $tmp);
  2937. }
  2938. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2939. ->whereIn('data_id', $box_id)
  2940. ->where('type', ApplyOrder::type_three)
  2941. ->pluck('apply_order_id')
  2942. ->toArray();
  2943. $result = ApplyOrder::where('del_time', 0)
  2944. ->whereIn('id', $apply_order_id)
  2945. ->select('id','order_number as order_no')
  2946. ->get()->toArray();
  2947. }elseif ($for_type == 13){
  2948. $dispatch = DispatchSub::where('id',$id)
  2949. ->select('order_product_id','crt_time','product_no','technology_name')
  2950. ->first()->toArray();
  2951. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  2952. ->where('crt_time',$dispatch['crt_time'])
  2953. ->where('product_no',$dispatch['product_no'])
  2954. ->where('technology_name',$dispatch['technology_name'])
  2955. ->pluck('id')->toArray();
  2956. $s_id = ScrappCount::where('del_time', 0)
  2957. ->whereIn('dispatch_sub_id', $dispatch_id)
  2958. ->pluck('id')
  2959. ->toArray();
  2960. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2961. ->whereIn('data_id', $s_id)
  2962. ->where('type', ApplyOrder::type_five)
  2963. ->pluck('apply_order_id')
  2964. ->toArray();
  2965. $result = ApplyOrder::where('del_time', 0)
  2966. ->whereIn('id', $apply_order_id)
  2967. ->select('id','order_number as order_no')
  2968. ->get()->toArray();
  2969. }elseif ($for_type == 14){
  2970. $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  2971. $box_id = [];
  2972. foreach ($sale as $value){
  2973. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  2974. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  2975. $tmp = Box::where('del_time',0)
  2976. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  2977. ->pluck("id")
  2978. ->toArray();
  2979. $box_id = array_merge($box_id, $tmp);
  2980. }
  2981. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  2982. ->whereIn('data_id', $box_id)
  2983. ->where('type', ApplyOrder::type_four)
  2984. ->pluck('apply_order_id')
  2985. ->toArray();
  2986. $result = ApplyOrder::where('del_time', 0)
  2987. ->whereIn('id', $apply_order_id)
  2988. ->select('id','order_number as order_no')
  2989. ->get()->toArray();
  2990. }
  2991. return $result;
  2992. }
  2993. private function typeFour($for_type, $id){
  2994. $result = [];
  2995. if($for_type == 1){
  2996. $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
  2997. ->where('del_time',0)
  2998. ->pluck('data_id')
  2999. ->toArray();
  3000. $sale_orders_product_id = DispatchSub::where('del_time',0)
  3001. ->whereIn('id', $dispatch_id)
  3002. ->pluck('sale_orders_product_id')
  3003. ->toArray();
  3004. $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
  3005. ->where('del_time',0)
  3006. ->select('id','out_order_no as order_no')
  3007. ->get()->toArray();
  3008. }elseif ($for_type == 2){
  3009. $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
  3010. ->where('del_time',0)
  3011. ->pluck('data_id')
  3012. ->toArray();
  3013. $order_product_id = DispatchSub::where('del_time',0)
  3014. ->whereIn('id', $dispatch_id)
  3015. ->pluck('order_product_id')
  3016. ->toArray();
  3017. $result = OrdersProduct::where('del_time',0)
  3018. ->whereIn('id', $order_product_id)
  3019. ->select('id', 'production_no as order_no')
  3020. ->get()->toArray();
  3021. }elseif ($for_type == 3){
  3022. $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
  3023. ->where('del_time',0)
  3024. ->pluck('data_id')
  3025. ->toArray();
  3026. $result = DispatchSub::where('del_time',0)
  3027. ->whereIn('id', $dispatch_id)
  3028. ->select('id','dispatch_no as order_no')
  3029. ->get()->toArray();
  3030. }elseif ($for_type == 5){
  3031. $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
  3032. ->where('del_time',0)
  3033. ->pluck('data_id')
  3034. ->toArray();
  3035. $result = DispatchSub::where('del_time',0)
  3036. ->whereIn('id', $dispatch_id)
  3037. ->where('finished_num','>',0)
  3038. ->select('id', 'dispatch_no as order_no')
  3039. ->get()->toArray();
  3040. }elseif ($for_type == 6){
  3041. $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
  3042. ->where('del_time',0)
  3043. ->pluck('data_id')
  3044. ->toArray();
  3045. $sale_orders_product_id = DispatchSub::where('del_time',0)
  3046. ->whereIn('id', $dispatch_id)
  3047. ->pluck('sale_orders_product_id')
  3048. ->toArray();
  3049. $sale = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)->select('order_no','id')->get()->toArray();
  3050. $return = [];
  3051. foreach ($sale as $value){
  3052. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3053. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3054. $tmp = Box::where('del_time',0)
  3055. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3056. ->select("id","order_no")
  3057. ->get()->toArray();
  3058. $return = array_merge($return, $tmp);
  3059. }
  3060. $result[] = $return[0] ?? [];
  3061. }elseif ($for_type == 7){
  3062. $process = Process::where('del_time',0)
  3063. ->where('is_need_remain',1)
  3064. ->pluck('id')
  3065. ->toArray();
  3066. $result = ScrappCount::where('del_time',0)
  3067. ->where('report_id', $id)
  3068. ->whereIn('process_id',$process)
  3069. ->select('id', 'order_number as order_no')
  3070. ->get()->toArray();
  3071. }elseif ($for_type == 8){
  3072. $result = ScrappCount::where('del_time',0)
  3073. ->where('report_id', $id)
  3074. ->where('scrapp_num','>', 0)
  3075. ->select('id', 'order_number as order_no')
  3076. ->get()->toArray();
  3077. }elseif ($for_type == 9){
  3078. $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
  3079. ->where('del_time',0)
  3080. ->pluck('data_id')
  3081. ->toArray();
  3082. $dispatch_id = $dispatch_id[0] ?? 0;
  3083. $dispatch = DispatchSub::where('id',$dispatch_id)
  3084. ->select('order_product_id','crt_time','product_no','technology_name')
  3085. ->first()->toArray();
  3086. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  3087. ->where('crt_time',$dispatch['crt_time'])
  3088. ->where('product_no',$dispatch['product_no'])
  3089. ->where('technology_name',$dispatch['technology_name'])
  3090. ->pluck('id')->toArray();
  3091. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3092. ->whereIn('data_id', $dispatch_id)
  3093. ->where('type', ApplyOrder::type_one)
  3094. ->pluck('apply_order_id')
  3095. ->toArray();
  3096. $result = ApplyOrder::where('del_time', 0)
  3097. ->whereIn('id', $apply_order_id)
  3098. ->select('id','order_number as order_no')
  3099. ->get()->toArray();
  3100. }elseif ($for_type == 10){
  3101. $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
  3102. ->where('del_time',0)
  3103. ->pluck('data_id')
  3104. ->toArray();
  3105. $dispatch_id = $dispatch_id[0] ?? 0;
  3106. $dispatch = DispatchSub::where('id',$dispatch_id)
  3107. ->select('order_product_id','crt_time','product_no','technology_name')
  3108. ->first()->toArray();
  3109. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  3110. ->where('crt_time',$dispatch['crt_time'])
  3111. ->where('product_no',$dispatch['product_no'])
  3112. ->where('technology_name',$dispatch['technology_name'])
  3113. ->pluck('id')->toArray();
  3114. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3115. ->whereIn('data_id', $dispatch_id)
  3116. ->where('type', ApplyOrder::type_two)
  3117. ->pluck('apply_order_id')
  3118. ->toArray();
  3119. $return = ApplyOrder::where('del_time', 0)
  3120. ->whereIn('id', $apply_order_id)
  3121. ->select('id','order_number as order_no')
  3122. ->get()->toArray();
  3123. $result[] = $return[0] ?? [];
  3124. }elseif ($for_type == 11){
  3125. $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
  3126. ->where('del_time',0)
  3127. ->pluck('data_id')
  3128. ->toArray();
  3129. $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  3130. $box_id = [];
  3131. foreach ($sale as $value){
  3132. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3133. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3134. $tmp = Box::where('del_time',0)
  3135. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3136. ->pluck("id")
  3137. ->toArray();
  3138. $box_id = array_merge($box_id, $tmp);
  3139. }
  3140. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3141. ->whereIn('data_id', $box_id)
  3142. ->where('type', ApplyOrder::type_four)
  3143. ->pluck('apply_order_id')
  3144. ->toArray();
  3145. $return = ApplyOrder::where('del_time', 0)
  3146. ->whereIn('id', $apply_order_id)
  3147. ->select('id','order_number as order_no')
  3148. ->get()->toArray();
  3149. $result[] = $return[0] ?? [];
  3150. }elseif ($for_type == 12){
  3151. $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
  3152. ->where('del_time',0)
  3153. ->pluck('data_id')
  3154. ->toArray();
  3155. $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no', 'sale_orders_product_id as id')->get()->toArray();
  3156. $box_id = [];
  3157. foreach ($sale as $value){
  3158. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3159. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3160. $tmp = Box::where('del_time',0)
  3161. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3162. ->pluck("id")
  3163. ->toArray();
  3164. $box_id = array_merge($box_id, $tmp);
  3165. }
  3166. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3167. ->whereIn('data_id', $box_id)
  3168. ->where('type', ApplyOrder::type_three)
  3169. ->pluck('apply_order_id')
  3170. ->toArray();
  3171. $return = ApplyOrder::where('del_time', 0)
  3172. ->whereIn('id', $apply_order_id)
  3173. ->select('id','order_number as order_no')
  3174. ->get()->toArray();
  3175. $result[] = $return[0] ?? [];
  3176. }elseif ($for_type == 13){
  3177. $s_id = ScrappCount::where('del_time', 0)
  3178. ->where('report_id', $id)
  3179. ->pluck('id')
  3180. ->toArray();
  3181. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3182. ->whereIn('data_id', $s_id)
  3183. ->where('type', ApplyOrder::type_five)
  3184. ->pluck('apply_order_id')
  3185. ->toArray();
  3186. $result = ApplyOrder::where('del_time', 0)
  3187. ->whereIn('id', $apply_order_id)
  3188. ->select('id','order_number as order_no')
  3189. ->get()->toArray();
  3190. }elseif ($for_type == 14){
  3191. $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
  3192. ->where('del_time',0)
  3193. ->pluck('data_id')
  3194. ->toArray();
  3195. $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  3196. $box_id = [];
  3197. foreach ($sale as $value){
  3198. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3199. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3200. $tmp = Box::where('del_time',0)
  3201. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3202. ->pluck("id")
  3203. ->toArray();
  3204. $box_id = array_merge($box_id, $tmp);
  3205. }
  3206. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3207. ->whereIn('data_id', $box_id)
  3208. ->where('type', ApplyOrder::type_six)
  3209. ->pluck('apply_order_id')
  3210. ->toArray();
  3211. $return = ApplyOrder::where('del_time', 0)
  3212. ->whereIn('id', $apply_order_id)
  3213. ->select('id','order_number as order_no')
  3214. ->get()->toArray();
  3215. $result[] = $return[0] ?? [];
  3216. }
  3217. return $result;
  3218. }
  3219. private function typeFive($for_type, $id){
  3220. $result = [];
  3221. if($for_type == 1){
  3222. $sale_orders_product_id = DispatchSub::where('del_time',0)
  3223. ->where('id', $id)
  3224. ->pluck('sale_orders_product_id')
  3225. ->toArray();
  3226. $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
  3227. ->where('del_time',0)
  3228. ->select('id','out_order_no as order_no')
  3229. ->get()->toArray();
  3230. }elseif ($for_type == 2){
  3231. $order_product_id = DispatchSub::where('del_time',0)
  3232. ->where('id', $id)
  3233. ->pluck('order_product_id')
  3234. ->toArray();
  3235. $result = OrdersProduct::where('del_time',0)
  3236. ->whereIn('id', $order_product_id)
  3237. ->select('id', 'production_no as order_no')
  3238. ->get()->toArray();
  3239. }elseif ($for_type == 3){
  3240. $result = DispatchSub::where('del_time',0)
  3241. ->where('id', $id)
  3242. ->select('id', 'dispatch_no as order_no')
  3243. ->get()->toArray();
  3244. }elseif ($for_type == 4){
  3245. $dispatch = DispatchSub::where('del_time',0)
  3246. ->where('id', $id)
  3247. ->select('id')
  3248. ->get()->toArray();
  3249. $detail = ReportWorkingDetail::whereIn('data_id', array_column($dispatch,'id'))
  3250. ->where('del_time',0)
  3251. ->select('report_working_id')
  3252. ->get()->toArray();
  3253. $result = ReportWorking::where('del_time',0)
  3254. ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
  3255. ->select('id', 'order_number as order_no')
  3256. ->get()->toArray();
  3257. }elseif ($for_type == 6){
  3258. $box_id = BoxWithDispatch::where('del_time',0)
  3259. ->where('dispatch_id', $id)
  3260. ->pluck('box_id')
  3261. ->toArray();
  3262. $box_id = $box_id[0] ?? 0;
  3263. $result = Box::where('del_time',0)
  3264. ->where('id', $box_id)
  3265. ->select("id","order_no")
  3266. ->get()->toArray();
  3267. }elseif ($for_type == 7){
  3268. $process = Process::where('del_time',0)
  3269. ->where('is_need_remain',1)
  3270. ->pluck('id')
  3271. ->toArray();
  3272. $result = ScrappCount::where('del_time',0)
  3273. ->where('dispatch_sub_id', $id)
  3274. ->whereIn('process_id', $process)
  3275. ->select('id', 'order_number as order_no')
  3276. ->get()->toArray();
  3277. }elseif ($for_type == 8){
  3278. $result = ScrappCount::where('del_time',0)
  3279. ->where('dispatch_sub_id', $id)
  3280. ->where('scrapp_num','>', 0)
  3281. ->select('id', 'order_number as order_no')
  3282. ->get()->toArray();
  3283. }elseif ($for_type == 9){
  3284. $dispatch = DispatchSub::where('id',$id)
  3285. ->select('order_product_id','crt_time','product_no','technology_name')
  3286. ->first()->toArray();
  3287. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  3288. ->where('crt_time',$dispatch['crt_time'])
  3289. ->where('product_no',$dispatch['product_no'])
  3290. ->where('technology_name',$dispatch['technology_name'])
  3291. ->pluck('id')->toArray();
  3292. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3293. ->whereIn('data_id', $dispatch_id)
  3294. ->where('type', ApplyOrder::type_one)
  3295. ->pluck('apply_order_id')
  3296. ->toArray();
  3297. $result = ApplyOrder::where('del_time', 0)
  3298. ->whereIn('id', $apply_order_id)
  3299. ->select('id','order_number as order_no')
  3300. ->get()->toArray();
  3301. }elseif ($for_type == 10){
  3302. $dispatch = DispatchSub::where('id',$id)
  3303. ->select('order_product_id','crt_time','product_no','technology_name')
  3304. ->first()->toArray();
  3305. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  3306. ->where('crt_time',$dispatch['crt_time'])
  3307. ->where('product_no',$dispatch['product_no'])
  3308. ->where('technology_name',$dispatch['technology_name'])
  3309. ->pluck('id')->toArray();
  3310. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3311. ->whereIn('data_id', $dispatch_id)
  3312. ->where('type', ApplyOrder::type_two)
  3313. ->pluck('apply_order_id')
  3314. ->toArray();
  3315. $return = ApplyOrder::where('del_time', 0)
  3316. ->whereIn('id', $apply_order_id)
  3317. ->select('id','order_number as order_no')
  3318. ->get()->toArray();
  3319. $result[] = $return[0] ?? [];
  3320. }elseif ($for_type == 11){
  3321. $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  3322. $box_id = [];
  3323. foreach ($sale as $value){
  3324. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3325. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3326. $tmp = Box::where('del_time',0)
  3327. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3328. ->pluck("id")
  3329. ->toArray();
  3330. $box_id = array_merge($box_id, $tmp);
  3331. }
  3332. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3333. ->whereIn('data_id', $box_id)
  3334. ->where('type', ApplyOrder::type_four)
  3335. ->pluck('apply_order_id')
  3336. ->toArray();
  3337. $return = ApplyOrder::where('del_time', 0)
  3338. ->whereIn('id', $apply_order_id)
  3339. ->select('id','order_number as order_no')
  3340. ->get()->toArray();
  3341. $result[] = $return[0] ?? [];
  3342. }elseif ($for_type == 12){
  3343. $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  3344. $box_id = [];
  3345. foreach ($sale as $value){
  3346. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3347. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3348. $tmp = Box::where('del_time',0)
  3349. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3350. ->pluck("id")
  3351. ->toArray();
  3352. $box_id = array_merge($box_id, $tmp);
  3353. }
  3354. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3355. ->whereIn('data_id', $box_id)
  3356. ->where('type', ApplyOrder::type_three)
  3357. ->pluck('apply_order_id')
  3358. ->toArray();
  3359. $return = ApplyOrder::where('del_time', 0)
  3360. ->whereIn('id', $apply_order_id)
  3361. ->select('id','order_number as order_no')
  3362. ->get()->toArray();
  3363. $result[] = $return[0] ?? [];
  3364. }elseif ($for_type == 13){
  3365. $s_id = ScrappCount::where('del_time', 0)
  3366. ->where('dispatch_sub_id', $id)
  3367. ->pluck('id')
  3368. ->toArray();
  3369. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3370. ->whereIn('data_id', $s_id)
  3371. ->where('type', ApplyOrder::type_five)
  3372. ->pluck('apply_order_id')
  3373. ->toArray();
  3374. $result = ApplyOrder::where('del_time', 0)
  3375. ->whereIn('id', $apply_order_id)
  3376. ->select('id','order_number as order_no')
  3377. ->get()->toArray();
  3378. }elseif ($for_type == 14){
  3379. $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  3380. $box_id = [];
  3381. foreach ($sale as $value){
  3382. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3383. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3384. $tmp = Box::where('del_time',0)
  3385. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3386. ->pluck("id")
  3387. ->toArray();
  3388. $box_id = array_merge($box_id, $tmp);
  3389. }
  3390. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3391. ->whereIn('data_id', $box_id)
  3392. ->where('type', ApplyOrder::type_six)
  3393. ->pluck('apply_order_id')
  3394. ->toArray();
  3395. $return = ApplyOrder::where('del_time', 0)
  3396. ->whereIn('id', $apply_order_id)
  3397. ->select('id','order_number as order_no')
  3398. ->get()->toArray();
  3399. $result[] = $return[0] ?? [];
  3400. }
  3401. return $result;
  3402. }
  3403. private function typeSix($for_type, $id){
  3404. $result = [];
  3405. $box = Box::where('id', $id)->first();
  3406. if(empty($box)) return $result;
  3407. $top_order_no = $box->top_order_no;
  3408. $order_no = $box->order_no;
  3409. if($for_type == 1){
  3410. $box_detail = new BoxDetail(['channel'=> $top_order_no]);
  3411. $sale_orders_product_id = $box_detail->where('del_time',0)
  3412. ->where('order_no',$order_no)
  3413. ->pluck('top_id')
  3414. ->toArray();
  3415. $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
  3416. ->where('del_time',0)
  3417. ->select('id','out_order_no as order_no')
  3418. ->get()->toArray();
  3419. }elseif ($for_type == 2){
  3420. $box_detail = new BoxDetail(['channel'=> $top_order_no]);
  3421. $sale_orders_product_id = $box_detail->where('del_time',0)
  3422. ->where('order_no',$order_no)
  3423. ->pluck('top_id')
  3424. ->toArray();
  3425. $result = OrdersProduct::where('del_time',0)
  3426. ->whereIn('sale_orders_product_id', $sale_orders_product_id)
  3427. ->select('id', 'production_no as order_no')
  3428. ->get()->toArray();
  3429. }elseif ($for_type == 3){
  3430. $dispatch_id = BoxWithDispatch::where('del_time',0)
  3431. ->where('box_id', $id)
  3432. ->pluck('dispatch_id')
  3433. ->toArray();
  3434. $result = DispatchSub::where('del_time',0)
  3435. ->whereIn('id', $dispatch_id)
  3436. ->select('id', 'dispatch_no as order_no')
  3437. ->get()->toArray();
  3438. }elseif ($for_type == 4){
  3439. $dispatch_id = BoxWithDispatch::where('del_time',0)
  3440. ->where('box_id', $id)
  3441. ->pluck('dispatch_id')
  3442. ->toArray();
  3443. $detail = ReportWorkingDetail::whereIn('data_id', $dispatch_id)
  3444. ->where('del_time',0)
  3445. ->select('report_working_id')
  3446. ->get()->toArray();
  3447. $return = ReportWorking::where('del_time',0)
  3448. ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
  3449. ->select('id', 'order_number as order_no')
  3450. ->get()->toArray();
  3451. $result[] = $return[0] ?? [];
  3452. }elseif ($for_type == 5){
  3453. $dispatch_id = BoxWithDispatch::where('del_time',0)
  3454. ->where('box_id', $id)
  3455. ->pluck('dispatch_id')
  3456. ->toArray();
  3457. $result = DispatchSub::where('del_time',0)
  3458. ->whereIn('id', $dispatch_id)
  3459. ->select('id', 'dispatch_no as order_no')
  3460. ->get()->toArray();
  3461. }elseif ($for_type == 7){
  3462. $process = Process::where('del_time',0)
  3463. ->where('is_need_remain',1)
  3464. ->pluck('id')
  3465. ->toArray();
  3466. $dispatch_id = BoxWithDispatch::where('del_time',0)
  3467. ->where('box_id', $id)
  3468. ->pluck('dispatch_id')
  3469. ->toArray();
  3470. $report_working_id = ReportWorkingDetail::whereIn('data_id', $dispatch_id)
  3471. ->where('del_time',0)
  3472. ->pluck('report_working_id')
  3473. ->toArray();
  3474. $return = ScrappCount::where('del_time',0)
  3475. ->whereIn('report_id', $report_working_id)
  3476. ->whereIn('process_id', $process)
  3477. ->select('id', 'order_number as order_no')
  3478. ->get()->toArray();
  3479. $result[] = $return[0] ?? [];
  3480. }elseif ($for_type == 8){
  3481. $dispatch_id = BoxWithDispatch::where('del_time',0)
  3482. ->where('box_id', $id)
  3483. ->pluck('dispatch_id')
  3484. ->toArray();
  3485. $report_working_id = ReportWorkingDetail::whereIn('data_id', $dispatch_id)
  3486. ->where('del_time',0)
  3487. ->pluck('report_working_id')
  3488. ->toArray();
  3489. $return = ScrappCount::where('del_time',0)
  3490. ->whereIn('report_id', $report_working_id)
  3491. ->where('scrapp_num','>', 0)
  3492. ->select('id', 'order_number as order_no')
  3493. ->get()->toArray();
  3494. $result[] = $return[0] ?? [];
  3495. }elseif ($for_type == 9){
  3496. $dispatch_id = BoxWithDispatch::where('del_time',0)
  3497. ->where('box_id', $id)
  3498. ->select('dispatch_id')
  3499. ->first()->toArray();
  3500. $dispatch = DispatchSub::where('id',$dispatch_id['dispatch_id'])
  3501. ->select('order_product_id','crt_time','product_no','technology_name')
  3502. ->first()->toArray();
  3503. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  3504. ->where('crt_time',$dispatch['crt_time'])
  3505. ->where('product_no',$dispatch['product_no'])
  3506. ->where('technology_name',$dispatch['technology_name'])
  3507. ->pluck('id')->toArray();
  3508. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3509. ->whereIn('data_id', $dispatch_id)
  3510. ->where('type', ApplyOrder::type_one)
  3511. ->pluck('apply_order_id')
  3512. ->toArray();
  3513. $result = ApplyOrder::where('del_time', 0)
  3514. ->whereIn('id', $apply_order_id)
  3515. ->select('id','order_number as order_no')
  3516. ->get()->toArray();
  3517. }elseif ($for_type == 10){
  3518. $dispatch_id = BoxWithDispatch::where('del_time',0)
  3519. ->where('box_id', $id)
  3520. ->select('dispatch_id')
  3521. ->first()->toArray();
  3522. $dispatch = DispatchSub::where('id',$dispatch_id['dispatch_id'])
  3523. ->select('order_product_id','crt_time','product_no','technology_name')
  3524. ->first()->toArray();
  3525. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  3526. ->where('crt_time',$dispatch['crt_time'])
  3527. ->where('product_no',$dispatch['product_no'])
  3528. ->where('technology_name',$dispatch['technology_name'])
  3529. ->pluck('id')->toArray();
  3530. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3531. ->whereIn('data_id', $dispatch_id)
  3532. ->where('type', ApplyOrder::type_two)
  3533. ->pluck('apply_order_id')
  3534. ->toArray();
  3535. $return = ApplyOrder::where('del_time', 0)
  3536. ->whereIn('id', $apply_order_id)
  3537. ->select('id','order_number as order_no')
  3538. ->get()->toArray();
  3539. $result[] = $return[0] ?? [];
  3540. }elseif ($for_type == 11){
  3541. $dispatch_id = BoxWithDispatch::where('del_time',0)
  3542. ->where('box_id', $id)
  3543. ->pluck('dispatch_id')
  3544. ->toArray();
  3545. $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  3546. $box_id = [];
  3547. foreach ($sale as $value){
  3548. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3549. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3550. $tmp = Box::where('del_time',0)
  3551. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3552. ->pluck("id")
  3553. ->toArray();
  3554. $box_id = array_merge($box_id, $tmp);
  3555. }
  3556. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3557. ->whereIn('data_id', $box_id)
  3558. ->where('type', ApplyOrder::type_four)
  3559. ->pluck('apply_order_id')
  3560. ->toArray();
  3561. $return = ApplyOrder::where('del_time', 0)
  3562. ->whereIn('id', $apply_order_id)
  3563. ->select('id','order_number as order_no')
  3564. ->get()->toArray();
  3565. $result[] = $return[0] ?? [];
  3566. }elseif ($for_type == 12){
  3567. $dispatch_id = BoxWithDispatch::where('del_time',0)
  3568. ->where('box_id', $id)
  3569. ->pluck('dispatch_id')
  3570. ->toArray();
  3571. $sale = DispatchSub::where('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  3572. $box_id = [];
  3573. foreach ($sale as $value){
  3574. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3575. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3576. $tmp = Box::where('del_time',0)
  3577. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3578. ->pluck("id")
  3579. ->toArray();
  3580. $box_id = array_merge($box_id, $tmp);
  3581. }
  3582. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3583. ->whereIn('data_id', $box_id)
  3584. ->where('type', ApplyOrder::type_three)
  3585. ->pluck('apply_order_id')
  3586. ->toArray();
  3587. $return = ApplyOrder::where('del_time', 0)
  3588. ->whereIn('id', $apply_order_id)
  3589. ->select('id','order_number as order_no')
  3590. ->get()->toArray();
  3591. $result[] = $return[0] ?? [];
  3592. }elseif ($for_type == 13){
  3593. $dispatch_id = BoxWithDispatch::where('del_time',0)
  3594. ->where('box_id', $id)
  3595. ->select('dispatch_id')
  3596. ->first()->toArray();
  3597. $dispatch = DispatchSub::where('id',$dispatch_id['dispatch_id'])
  3598. ->select('order_product_id','crt_time','product_no','technology_name')
  3599. ->first()->toArray();
  3600. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  3601. ->where('crt_time',$dispatch['crt_time'])
  3602. ->where('product_no',$dispatch['product_no'])
  3603. ->where('technology_name',$dispatch['technology_name'])
  3604. ->pluck('id')->toArray();
  3605. $s_id = ScrappCount::where('del_time', 0)
  3606. ->whereIn('dispatch_sub_id', $dispatch_id)
  3607. ->pluck('id')
  3608. ->toArray();
  3609. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3610. ->whereIn('data_id', $s_id)
  3611. ->where('type', ApplyOrder::type_five)
  3612. ->pluck('apply_order_id')
  3613. ->toArray();
  3614. $result = ApplyOrder::where('del_time', 0)
  3615. ->whereIn('id', $apply_order_id)
  3616. ->select('id','order_number as order_no')
  3617. ->get()->toArray();
  3618. }elseif ($for_type == 14){
  3619. $dispatch_id = BoxWithDispatch::where('del_time',0)
  3620. ->where('box_id', $id)
  3621. ->pluck('dispatch_id')
  3622. ->toArray();
  3623. $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  3624. $box_id = [];
  3625. foreach ($sale as $value){
  3626. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3627. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3628. $tmp = Box::where('del_time',0)
  3629. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3630. ->pluck("id")
  3631. ->toArray();
  3632. $box_id = array_merge($box_id, $tmp);
  3633. }
  3634. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3635. ->whereIn('data_id', $box_id)
  3636. ->where('type', ApplyOrder::type_six)
  3637. ->pluck('apply_order_id')
  3638. ->toArray();
  3639. $return = ApplyOrder::where('del_time', 0)
  3640. ->whereIn('id', $apply_order_id)
  3641. ->select('id','order_number as order_no')
  3642. ->get()->toArray();
  3643. $result[] = $return[0] ?? [];
  3644. }
  3645. return $result;
  3646. }
  3647. private function typeSeven($for_type, $id){
  3648. $result = [];
  3649. if($for_type == 1){
  3650. $sale_orders_product_id = ScrappCount::where('del_time',0)
  3651. ->where('id', $id)
  3652. ->pluck('sale_orders_product_id')
  3653. ->toArray();
  3654. $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
  3655. ->where('del_time',0)
  3656. ->select('id','out_order_no as order_no')
  3657. ->get()->toArray();
  3658. }elseif ($for_type == 2){
  3659. $order_product_id = ScrappCount::where('del_time',0)
  3660. ->where('id', $id)
  3661. ->pluck('order_product_id')
  3662. ->toArray();
  3663. $result = OrdersProduct::where('del_time',0)
  3664. ->whereIn('id', $order_product_id)
  3665. ->select('id', 'production_no as order_no')
  3666. ->get()->toArray();
  3667. }elseif ($for_type == 3){
  3668. $dispatch_id = ScrappCount::where('del_time',0)
  3669. ->where('id', $id)
  3670. ->pluck('dispatch_sub_id')
  3671. ->toArray();
  3672. $result = DispatchSub::where('del_time',0)
  3673. ->where('id', $dispatch_id)
  3674. ->select('id', 'dispatch_no as order_no')
  3675. ->get()->toArray();
  3676. }elseif ($for_type == 4){
  3677. $report_id = ScrappCount::where('del_time',0)
  3678. ->where('id', $id)
  3679. ->pluck('report_id')
  3680. ->toArray();
  3681. $result = ReportWorking::where('del_time',0)
  3682. ->whereIn('id', $report_id)
  3683. ->select('id', 'order_number as order_no')
  3684. ->get()->toArray();
  3685. }elseif ($for_type == 5){
  3686. $dispatch_id = ScrappCount::where('del_time',0)
  3687. ->where('id', $id)
  3688. ->pluck('dispatch_sub_id')
  3689. ->toArray();
  3690. $result = DispatchSub::where('del_time',0)
  3691. ->where('id', $dispatch_id)
  3692. ->where('finished_num','>',0)
  3693. ->select('id', 'dispatch_no as order_no')
  3694. ->get()->toArray();
  3695. }elseif ($for_type == 6){
  3696. $sale_orders_product_id = ScrappCount::where('del_time',0)
  3697. ->where('id', $id)
  3698. ->pluck('sale_orders_product_id')
  3699. ->toArray();
  3700. $sale = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)->select('order_no','id')->get()->toArray();
  3701. $return = [];
  3702. foreach ($sale as $value){
  3703. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3704. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3705. $tmp = Box::where('del_time',0)
  3706. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3707. ->select("id","order_no")
  3708. ->get()->toArray();
  3709. $return = array_merge($return, $tmp);
  3710. }
  3711. $result[] = $return[0] ?? [];
  3712. }elseif ($for_type == 8){
  3713. $result = ScrappCount::where('del_time',0)
  3714. ->where('id', $id)
  3715. ->where('scrapp_num','>', 0)
  3716. ->select('id', 'order_number as order_no')
  3717. ->get()->toArray();
  3718. }elseif ($for_type == 9){
  3719. $dispatch_id = ScrappCount::where('del_time',0)
  3720. ->where('id', $id)
  3721. ->pluck('dispatch_sub_id')
  3722. ->toArray();
  3723. $dispatch_id = $dispatch_id[0] ?? 0;
  3724. $dispatch = DispatchSub::where('id',$dispatch_id)
  3725. ->select('order_product_id','crt_time','product_no','technology_name')
  3726. ->first()->toArray();
  3727. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  3728. ->where('crt_time',$dispatch['crt_time'])
  3729. ->where('product_no',$dispatch['product_no'])
  3730. ->where('technology_name',$dispatch['technology_name'])
  3731. ->pluck('id')->toArray();
  3732. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3733. ->whereIn('data_id', $dispatch_id)
  3734. ->where('type', ApplyOrder::type_one)
  3735. ->pluck('apply_order_id')
  3736. ->toArray();
  3737. $result = ApplyOrder::where('del_time', 0)
  3738. ->whereIn('id', $apply_order_id)
  3739. ->select('id','order_number as order_no')
  3740. ->get()->toArray();
  3741. }elseif ($for_type == 10){
  3742. $dispatch_id = ScrappCount::where('del_time',0)
  3743. ->where('id', $id)
  3744. ->pluck('dispatch_sub_id')
  3745. ->toArray();
  3746. $dispatch_id = $dispatch_id[0] ?? 0;
  3747. $dispatch = DispatchSub::where('id',$dispatch_id)
  3748. ->select('order_product_id','crt_time','product_no','technology_name')
  3749. ->first()->toArray();
  3750. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  3751. ->where('crt_time',$dispatch['crt_time'])
  3752. ->where('product_no',$dispatch['product_no'])
  3753. ->where('technology_name',$dispatch['technology_name'])
  3754. ->pluck('id')->toArray();
  3755. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3756. ->whereIn('data_id', $dispatch_id)
  3757. ->where('type', ApplyOrder::type_two)
  3758. ->pluck('apply_order_id')
  3759. ->toArray();
  3760. $return = ApplyOrder::where('del_time', 0)
  3761. ->whereIn('id', $apply_order_id)
  3762. ->select('id','order_number as order_no')
  3763. ->get()->toArray();
  3764. $result[] = $return[0] ?? [];
  3765. }elseif ($for_type == 11){
  3766. $dispatch_id = ScrappCount::where('del_time',0)
  3767. ->where('id', $id)
  3768. ->pluck('dispatch_sub_id')
  3769. ->toArray();
  3770. $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  3771. $box_id = [];
  3772. foreach ($sale as $value){
  3773. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3774. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3775. $tmp = Box::where('del_time',0)
  3776. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3777. ->pluck("id")
  3778. ->toArray();
  3779. $box_id = array_merge($box_id, $tmp);
  3780. }
  3781. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3782. ->whereIn('data_id', $box_id)
  3783. ->where('type', ApplyOrder::type_four)
  3784. ->pluck('apply_order_id')
  3785. ->toArray();
  3786. $return = ApplyOrder::where('del_time', 0)
  3787. ->whereIn('id', $apply_order_id)
  3788. ->select('id','order_number as order_no')
  3789. ->get()->toArray();
  3790. $result[] = $return[0] ?? [];
  3791. }elseif ($for_type == 12){
  3792. $dispatch_id = ScrappCount::where('del_time',0)
  3793. ->where('id', $id)
  3794. ->pluck('dispatch_sub_id')
  3795. ->toArray();
  3796. $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  3797. $box_id = [];
  3798. foreach ($sale as $value){
  3799. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3800. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3801. $tmp = Box::where('del_time',0)
  3802. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3803. ->pluck("id")
  3804. ->toArray();
  3805. $box_id = array_merge($box_id, $tmp);
  3806. }
  3807. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3808. ->whereIn('data_id', $box_id)
  3809. ->where('type', ApplyOrder::type_three)
  3810. ->pluck('apply_order_id')
  3811. ->toArray();
  3812. $return = ApplyOrder::where('del_time', 0)
  3813. ->whereIn('id', $apply_order_id)
  3814. ->select('id','order_number as order_no')
  3815. ->get()->toArray();
  3816. $result[] = $return[0] ?? [];
  3817. }elseif ($for_type == 13){
  3818. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3819. ->where('data_id', $id)
  3820. ->where('type', ApplyOrder::type_five)
  3821. ->pluck('apply_order_id')
  3822. ->toArray();
  3823. $result = ApplyOrder::where('del_time', 0)
  3824. ->whereIn('id', $apply_order_id)
  3825. ->select('id','order_number as order_no')
  3826. ->get()->toArray();
  3827. }elseif ($for_type == 14){
  3828. $dispatch_id = ScrappCount::where('del_time',0)
  3829. ->where('id', $id)
  3830. ->pluck('dispatch_sub_id')
  3831. ->toArray();
  3832. $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  3833. $box_id = [];
  3834. foreach ($sale as $value){
  3835. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3836. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3837. $tmp = Box::where('del_time',0)
  3838. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3839. ->pluck("id")
  3840. ->toArray();
  3841. $box_id = array_merge($box_id, $tmp);
  3842. }
  3843. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3844. ->whereIn('data_id', $box_id)
  3845. ->where('type', ApplyOrder::type_six)
  3846. ->pluck('apply_order_id')
  3847. ->toArray();
  3848. $return = ApplyOrder::where('del_time', 0)
  3849. ->whereIn('id', $apply_order_id)
  3850. ->select('id','order_number as order_no')
  3851. ->get()->toArray();
  3852. $result[] = $return[0] ?? [];
  3853. }
  3854. return $result;
  3855. }
  3856. private function typeEight($for_type, $id){
  3857. $result = [];
  3858. if($for_type == 1){
  3859. $sale_orders_product_id = ScrappCount::where('del_time',0)
  3860. ->where('id', $id)
  3861. ->pluck('sale_orders_product_id')
  3862. ->toArray();
  3863. $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
  3864. ->where('del_time',0)
  3865. ->select('id','out_order_no as order_no')
  3866. ->get()->toArray();
  3867. }elseif ($for_type == 2){
  3868. $order_product_id = ScrappCount::where('del_time',0)
  3869. ->where('id', $id)
  3870. ->pluck('order_product_id')
  3871. ->toArray();
  3872. $result = OrdersProduct::where('del_time',0)
  3873. ->whereIn('id', $order_product_id)
  3874. ->select('id', 'production_no as order_no')
  3875. ->get()->toArray();
  3876. }elseif ($for_type == 3){
  3877. $dispatch_id = ScrappCount::where('del_time',0)
  3878. ->where('id', $id)
  3879. ->pluck('dispatch_sub_id')
  3880. ->toArray();
  3881. $result = DispatchSub::where('del_time',0)
  3882. ->where('id', $dispatch_id)
  3883. ->select('id', 'dispatch_no as order_no')
  3884. ->get()->toArray();
  3885. }elseif ($for_type == 4){
  3886. $report_id = ScrappCount::where('del_time',0)
  3887. ->where('id', $id)
  3888. ->pluck('report_id')
  3889. ->toArray();
  3890. $result = ReportWorking::where('del_time',0)
  3891. ->whereIn('id', $report_id)
  3892. ->select('id', 'order_number as order_no')
  3893. ->get()->toArray();
  3894. }elseif ($for_type == 5){
  3895. $dispatch_id = ScrappCount::where('del_time',0)
  3896. ->where('id', $id)
  3897. ->pluck('dispatch_sub_id')
  3898. ->toArray();
  3899. $result = DispatchSub::where('del_time',0)
  3900. ->where('id', $dispatch_id)
  3901. ->where('finished_num','>',0)
  3902. ->select('id', 'dispatch_no as order_no')
  3903. ->get()->toArray();
  3904. }elseif ($for_type == 6){
  3905. $sale_orders_product_id = ScrappCount::where('del_time',0)
  3906. ->where('id', $id)
  3907. ->pluck('sale_orders_product_id')
  3908. ->toArray();
  3909. $sale = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)->select('order_no','id')->get()->toArray();
  3910. $return = [];
  3911. foreach ($sale as $value){
  3912. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3913. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3914. $tmp = Box::where('del_time',0)
  3915. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3916. ->select("id","order_no")
  3917. ->get()->toArray();
  3918. $return = array_merge($return, $tmp);
  3919. }
  3920. $result[] = $return[0] ?? [];
  3921. }elseif ($for_type == 7){
  3922. $process = Process::where('del_time',0)
  3923. ->where('is_need_remain',1)
  3924. ->pluck('id')
  3925. ->toArray();
  3926. $result = ScrappCount::where('del_time',0)
  3927. ->where('id', $id)
  3928. ->whereIn('process_id', $process)
  3929. ->select('id', 'order_number as order_no')
  3930. ->get()->toArray();
  3931. }elseif ($for_type == 9){
  3932. $dispatch_id = ScrappCount::where('del_time',0)
  3933. ->where('id', $id)
  3934. ->pluck('dispatch_sub_id')
  3935. ->toArray();
  3936. $dispatch_id = $dispatch_id[0] ?? 0;
  3937. $dispatch = DispatchSub::where('id',$dispatch_id)
  3938. ->select('order_product_id','crt_time','product_no','technology_name')
  3939. ->first()->toArray();
  3940. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  3941. ->where('crt_time',$dispatch['crt_time'])
  3942. ->where('product_no',$dispatch['product_no'])
  3943. ->where('technology_name',$dispatch['technology_name'])
  3944. ->pluck('id')->toArray();
  3945. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3946. ->whereIn('data_id', $dispatch_id)
  3947. ->where('type', ApplyOrder::type_one)
  3948. ->pluck('apply_order_id')
  3949. ->toArray();
  3950. $result = ApplyOrder::where('del_time', 0)
  3951. ->whereIn('id', $apply_order_id)
  3952. ->select('id','order_number as order_no')
  3953. ->get()->toArray();
  3954. }elseif ($for_type == 10){
  3955. $dispatch_id = ScrappCount::where('del_time',0)
  3956. ->where('id', $id)
  3957. ->pluck('dispatch_sub_id')
  3958. ->toArray();
  3959. $dispatch_id = $dispatch_id[0] ?? 0;
  3960. $dispatch = DispatchSub::where('id',$dispatch_id)
  3961. ->select('order_product_id','crt_time','product_no','technology_name')
  3962. ->first()->toArray();
  3963. $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
  3964. ->where('crt_time',$dispatch['crt_time'])
  3965. ->where('product_no',$dispatch['product_no'])
  3966. ->where('technology_name',$dispatch['technology_name'])
  3967. ->pluck('id')->toArray();
  3968. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3969. ->whereIn('data_id', $dispatch_id)
  3970. ->where('type', ApplyOrder::type_two)
  3971. ->pluck('apply_order_id')
  3972. ->toArray();
  3973. $return = ApplyOrder::where('del_time', 0)
  3974. ->whereIn('id', $apply_order_id)
  3975. ->select('id','order_number as order_no')
  3976. ->get()->toArray();
  3977. $result[] = $return[0] ?? [];
  3978. }elseif ($for_type == 11){
  3979. $dispatch_id = ScrappCount::where('del_time',0)
  3980. ->where('id', $id)
  3981. ->pluck('dispatch_sub_id')
  3982. ->toArray();
  3983. $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  3984. $box_id = [];
  3985. foreach ($sale as $value){
  3986. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  3987. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  3988. $tmp = Box::where('del_time',0)
  3989. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  3990. ->pluck("id")
  3991. ->toArray();
  3992. $box_id = array_merge($box_id, $tmp);
  3993. }
  3994. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  3995. ->whereIn('data_id', $box_id)
  3996. ->where('type', ApplyOrder::type_four)
  3997. ->pluck('apply_order_id')
  3998. ->toArray();
  3999. $return = ApplyOrder::where('del_time', 0)
  4000. ->whereIn('id', $apply_order_id)
  4001. ->select('id','order_number as order_no')
  4002. ->get()->toArray();
  4003. $result[] = $return[0] ?? [];
  4004. }elseif ($for_type == 12){
  4005. $dispatch_id = ScrappCount::where('del_time',0)
  4006. ->where('id', $id)
  4007. ->pluck('dispatch_sub_id')
  4008. ->toArray();
  4009. $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  4010. $box_id = [];
  4011. foreach ($sale as $value){
  4012. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  4013. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  4014. $tmp = Box::where('del_time',0)
  4015. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  4016. ->pluck("id")
  4017. ->toArray();
  4018. $box_id = array_merge($box_id, $tmp);
  4019. }
  4020. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  4021. ->whereIn('data_id', $box_id)
  4022. ->where('type', ApplyOrder::type_three)
  4023. ->pluck('apply_order_id')
  4024. ->toArray();
  4025. $return = ApplyOrder::where('del_time', 0)
  4026. ->whereIn('id', $apply_order_id)
  4027. ->select('id','order_number as order_no')
  4028. ->get()->toArray();
  4029. $result[] = $return[0] ?? [];
  4030. }elseif ($for_type == 13){
  4031. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  4032. ->where('data_id', $id)
  4033. ->where('type', ApplyOrder::type_five)
  4034. ->pluck('apply_order_id')
  4035. ->toArray();
  4036. $result = ApplyOrder::where('del_time', 0)
  4037. ->whereIn('id', $apply_order_id)
  4038. ->select('id','order_number as order_no')
  4039. ->get()->toArray();
  4040. }elseif ($for_type == 14){
  4041. $dispatch_id = ScrappCount::where('del_time',0)
  4042. ->where('id', $id)
  4043. ->pluck('dispatch_sub_id')
  4044. ->toArray();
  4045. $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
  4046. $box_id = [];
  4047. foreach ($sale as $value){
  4048. $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
  4049. $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
  4050. $tmp = Box::where('del_time',0)
  4051. ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
  4052. ->pluck("id")
  4053. ->toArray();
  4054. $box_id = array_merge($box_id, $tmp);
  4055. }
  4056. $apply_order_id = ApplyOrderDetail::where('del_time', 0)
  4057. ->whereIn('data_id', $box_id)
  4058. ->where('type', ApplyOrder::type_six)
  4059. ->pluck('apply_order_id')
  4060. ->toArray();
  4061. $return = ApplyOrder::where('del_time', 0)
  4062. ->whereIn('id', $apply_order_id)
  4063. ->select('id','order_number as order_no')
  4064. ->get()->toArray();
  4065. $result[] = $return[0] ?? [];
  4066. }
  4067. return $result;
  4068. }
  4069. private function typeNine($for_type, $id){
  4070. $data_id = ApplyOrderDetail::where('del_time', 0)
  4071. ->where('apply_order_id', $id)
  4072. ->where('type', ApplyOrder::type_one)
  4073. ->pluck('data_id')
  4074. ->toArray();
  4075. $result = DispatchSub::where('del_time',0)
  4076. ->whereIn('id', $data_id)
  4077. ->select('id', 'dispatch_no as order_no')
  4078. ->get()->toArray();
  4079. return $result;
  4080. }
  4081. private function typeTen($for_type, $id){
  4082. $data_id = ApplyOrderDetail::where('del_time', 0)
  4083. ->where('apply_order_id', $id)
  4084. ->where('type', ApplyOrder::type_two)
  4085. ->pluck('data_id')
  4086. ->toArray();
  4087. $detail = ReportWorkingDetail::whereIn('data_id', $data_id)
  4088. ->where('del_time',0)
  4089. ->select('report_working_id')
  4090. ->get()->toArray();
  4091. $return = ReportWorking::where('del_time',0)
  4092. ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
  4093. ->select('id', 'order_number as order_no')
  4094. ->get()->toArray();
  4095. $result[] = $return[0];
  4096. return $result;
  4097. }
  4098. private function typeEve($for_type, $id){
  4099. $detail = ApplyOrderDetail::where('del_time', 0)
  4100. ->where('apply_order_id', $id)
  4101. ->where('type', ApplyOrder::type_four)
  4102. ->select('data_id as box_id')
  4103. ->get()->toArray();
  4104. $result = Box::where('del_time', 0)
  4105. ->whereIn('id', array_unique(array_column($detail, 'box_id')))
  4106. ->select("id", 'order_no')
  4107. ->get()->toArray();
  4108. return $result;
  4109. }
  4110. private function typeTwl($for_type, $id){
  4111. $detail = ApplyOrderDetail::where('del_time', 0)
  4112. ->where('apply_order_id', $id)
  4113. ->where('type', ApplyOrder::type_three)
  4114. ->select('data_id as box_id')
  4115. ->get()->toArray();
  4116. $result = Box::where('del_time', 0)
  4117. ->whereIn('id', array_unique(array_column($detail, 'box_id')))
  4118. ->select("id", 'order_no')
  4119. ->get()->toArray();
  4120. return $result;
  4121. }
  4122. private function typeThi($for_type, $id){
  4123. $detail = ApplyOrderDetail::where('del_time', 0)
  4124. ->where('apply_order_id', $id)
  4125. ->where('type', ApplyOrder::type_five)
  4126. ->select('data_id as zj_id')
  4127. ->get()->toArray();
  4128. $result = ScrappCount::where('del_time', 0)
  4129. ->whereIn('id', array_unique(array_column($detail, 'zj_id')))
  4130. ->select('id','order_number as order_no')
  4131. ->get()->toArray();
  4132. return $result;
  4133. }
  4134. private function typeFourTeen($for_type, $id){
  4135. $detail = ApplyOrderDetail::where('del_time', 0)
  4136. ->where('apply_order_id', $id)
  4137. ->where('type', ApplyOrder::type_six)
  4138. ->select('data_id as box_id')
  4139. ->get()->toArray();
  4140. $result = Box::where('del_time', 0)
  4141. ->whereIn('id', array_unique(array_column($detail, 'box_id')))
  4142. ->select("id", 'order_no')
  4143. ->get()->toArray();
  4144. return $result;
  4145. }
  4146. public function reportList($data){
  4147. $model = ReportMessage::where('del_time',0)
  4148. ->select('id','order_id','opt_case','quantity','crt_time','user_id','is_use')
  4149. ->orderBy('id','desc');
  4150. $list = $this->limit($model,'',$data);
  4151. $list = $this->fillRData($list);
  4152. $count = ReportMessage::where('del_time',0)
  4153. ->where('is_use',0)
  4154. ->count();
  4155. return [true, ['list'=> $list, 'count' => $count]];
  4156. }
  4157. public function fillRData($data){
  4158. if(empty($data['data'])) return $data;
  4159. $dispatch = DispatchSub::whereIn('id',array_unique(array_column($data['data'],'order_id')))
  4160. ->select('id','dispatch_no','process_id')
  4161. ->get()->toArray();
  4162. $process = Process::where('del_time',0)
  4163. ->whereIn('id',array_unique(array_column($dispatch,'process_id')))
  4164. ->get()->toArray();
  4165. $process = array_column($process,null,'id');
  4166. $map = [];
  4167. foreach ($dispatch as $value){
  4168. $map[$value['id']] = $value;
  4169. }
  4170. $emp_map = Employee::whereIn('id',array_unique(array_column($data['data'],'user_id')))
  4171. ->pluck("emp_name",'id')
  4172. ->toArray();
  4173. foreach ($data['data'] as $key => $value){
  4174. $time = $value['crt_time'] ? date('Y-m-d',$value['crt_time']) : '';
  4175. $data['data'][$key]['crt_time'] = $time;
  4176. $t = $map[$value['order_id']] ?? [];
  4177. $e = $emp_map[$value['user_id']] ?? "";
  4178. $p = $process[$t['process_id']] ?? [];
  4179. $p_t = $p['title'] ?? "";
  4180. if($p['zj_type'] == 0){
  4181. $p_t .= ":无需质检";
  4182. }elseif($p['zj_type'] == 1){
  4183. $p_t .= ":全检";
  4184. }else{
  4185. $p_t .= ":抽检";
  4186. }
  4187. $data['data'][$key]['message'] = "派工单:" . $t['dispatch_no'] . "于" . $time . "由($e)完成工序($p_t)报工,请及时处理";
  4188. }
  4189. return $data;
  4190. }
  4191. public function reportRemainUpdate($data){
  4192. if(empty($data['id'])) return [false, 'ID不能为空'];
  4193. if(empty($data['type'])) return [false, 'type不能为空'];
  4194. $type = $data['type'];
  4195. if($type == 1){
  4196. ReportMessage::where('id', $data['id'])
  4197. ->update(['is_use' => 1]);
  4198. }else{
  4199. ReportMessage::where('id', $data['id'])
  4200. ->update(['del_time' => time()]);
  4201. }
  4202. return [true, ''];
  4203. }
  4204. public function filldatas(){
  4205. $box = Box::where('del_time',0)
  4206. ->where('crt_time','>=',1750727777)
  4207. ->select("top_order_no", 'order_no','id')
  4208. ->get()->toArray();
  4209. $box_id = [];
  4210. foreach ($box as $value) {
  4211. $box_detail = new BoxDetail(['channel' => $value['top_order_no']]);
  4212. $t = $box_detail->where('order_no', $value['order_no'])->where('del_time',0)->select('top_id as id')->first()->toArray();
  4213. $box_id[$value['id']] = $t['id'];
  4214. }
  4215. $result = DispatchSub::where('del_time',0)
  4216. ->whereIn('sale_orders_product_id', array_values($box_id))
  4217. ->where('process_id',14)
  4218. ->where('finished_num', '>', '0.000')
  4219. ->select('id','dispatch_quantity','finished_num','order_product_id','sale_orders_product_id','technology_name')
  4220. ->get()->toArray();
  4221. $map = [];
  4222. $return = [];
  4223. foreach ($result as $key => $value){
  4224. if($value['finished_num'] < 1){
  4225. $new_key = $value['order_product_id'] . $value['sale_orders_product_id'] . $value['technology_name'];
  4226. $tmp = bcsub(0.750,$value['finished_num'],3);
  4227. $map[$new_key][] = $tmp;
  4228. $return[] = $value;
  4229. }
  4230. }dump(count($return));
  4231. $return2= [];
  4232. foreach ($result as $key => $value){
  4233. if($value['finished_num'] >= 1){
  4234. $new_key = $value['order_product_id'] . $value['sale_orders_product_id'] . $value['technology_name'];
  4235. if(isset($map[$new_key])){
  4236. foreach ($map[$new_key] as $val){
  4237. $return[] = [
  4238. 'id' => $value['id'],
  4239. 'dispatch_quantity' => $val,
  4240. 'finished_num' => $val,
  4241. 'order_product_id' => $value['order_product_id'],
  4242. 'sale_orders_product_id' => $value['sale_orders_product_id'],
  4243. 'technology_name' => $value['technology_name'],
  4244. ];
  4245. $value['finished_num'] = bcsub($value['finished_num'], $val,3);
  4246. }
  4247. }
  4248. $return2[] = $value;
  4249. }
  4250. }
  4251. dd($return2);
  4252. }
  4253. }