123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668 |
- <?php
- namespace App\Service;
- use App\Model\ApplyOrder;
- use App\Model\ApplyOrderDetail;
- use App\Model\Box;
- use App\Model\BoxDetail;
- use App\Model\BoxWithDispatch;
- use App\Model\Dispatch;
- use App\Model\DispatchSub;
- use App\Model\Employee;
- use App\Model\EmployeeTeamPermission;
- use App\Model\Equipment;
- use App\Model\InOutRecord;
- use App\Model\OrdersProduct;
- use App\Model\Process;
- use App\Model\ReportMessage;
- use App\Model\ReportWorking;
- use App\Model\ReportWorkingDetail;
- use App\Model\SaleOrdersProduct;
- use App\Model\ScrappCount;
- use App\Model\Team;
- use App\Service\Box\BoxService;
- use Illuminate\Support\Facades\DB;
- class ApplyOrderService extends Service
- {
- public function MaterialEdit($data, $user){
- list($status,$msg) = $this->MaterialRule($data,false);
- if(!$status) return [$status,$msg];
- DB::beginTransaction();
- try{
- $time = time();
- $model = new ApplyOrder();
- $model = $model->where('id',$data['id'])->first();
- $model->apply_id = $data['apply_id'];
- $model->apply_time = $data['apply_time'] ;
- $model->mark = $data['mark'] ?? "";
- $model->storehouse_id = $data['storehouse_id'];
- $model->storehouse_title = $data['storehouse_title'] ?? "";
- $model->type = $data['type'];
- $model->save();
- $id = $model->id;
- ApplyOrderDetail::where('del_time',0)->where('apply_order_id',$id)->update([
- 'del_time' => $time
- ]);
- $detail_insert = [];
- foreach ($data['order_data'] as $v){
- $detail_insert[] = [
- 'apply_order_id' => $id,
- 'data_id' => $v['id'],
- 'quantity' => $v['quantity'] ?? 0,
- 'product_no' => $v['product_no'] ?? "",
- 'product_title' => $v['product_title'] ?? "",
- 'product_size' => $v['product_size'] ?? "",
- 'product_unit' => $v['product_unit'] ?? "",
- 'technology_name' => $v['technology_name'] ?? "", //颜色
- 'top_product_title' => $v['top_product_title'] ?? "",
- 'top_product_no' => $v['top_product_title'] ?? "",
- 'type' => $data['type'],
- 'storehouse_id' => $data['storehouse_id'],
- 'crt_time' => $time,
- ];
- }
- ApplyOrderDetail::insert($detail_insert);
- DB::commit();
- }catch (\Exception $e){
- DB::rollBack();
- return [false,$e->getMessage()];
- }
- return [true,''];
- }
- public function MaterialAdd($data,$user){
- list($status,$msg) = $this->MaterialRule($data);
- if(!$status) return [$status,$msg];
- DB::beginTransaction();
- try{
- $time = time();
- $model = new ApplyOrder();
- $model->order_number = $data['order_number'];
- $model->apply_id = $data['apply_id'];
- $model->apply_time = $data['apply_time'] ;
- $model->mark = $data['mark'] ?? "";
- $model->storehouse_id = $data['storehouse_id'];
- $model->storehouse_title = $data['storehouse_title'] ?? "";
- $model->type = $data['type'];
- $model->crt_id = $user['id'];
- $model->save();
- $id = $model->id;
- $detail_insert = [];
- foreach ($data['order_data'] as $v){
- $detail_insert[] = [
- 'apply_order_id' => $id,
- 'data_id' => $v['id'],
- 'quantity' => $v['quantity'] ?? 0,
- 'product_no' => $v['product_no'] ?? "",
- 'product_title' => $v['product_title'] ?? "",
- 'product_size' => $v['product_size'] ?? "",
- 'product_unit' => $v['product_unit'] ?? "",
- 'technology_name' => $v['technology_name'] ?? "", //颜色
- 'top_product_title' => $v['top_product_title'] ?? "",
- 'top_product_no' => $v['top_product_title'] ?? "",
- 'type' => $data['type'],
- 'storehouse_id' => $data['storehouse_id'],
- 'crt_time' => $time,
- ];
- }
- ApplyOrderDetail::insert($detail_insert);
- DB::commit();
- }catch (\Exception $e){
- DB::rollBack();
- return [false,$e->getMessage()];
- }
- return [true, ''];
- }
- public function MaterialDel($data){
- if($this->isEmpty($data,'id')) return [false,'ID必须!'];
- $apply = ApplyOrder::where('id',$data['id'])->first();
- if($apply->del_time > 0) return [false,'申请单不存在或已被删除'];
- if($apply->state != ApplyOrder::state_zero) return [false, '申请单已审核,删除失败'];
- $time = time();
- try {
- DB::beginTransaction();
- $apply->del_time = $time;
- $apply->save();
- ApplyOrderDetail::where('del_time', 0)->where('apply_order_id',$data['id'])->update([
- 'del_time'=>time()
- ]);
- DB::commit();
- }catch (\Throwable $exception){
- DB::rollBack();
- return [false, $exception->getMessage()];
- }
- return [true,''];
- }
- public function MaterialList($data){
- $model = ApplyOrder::where('del_time',0)
- ->select('*')
- ->orderBy('id','desc');
- if(isset($data['status'])) $model->where('status', $data['status']);
- if(! empty($data['type'])) $model->where('type', $data['type']);
- if(! empty($data['storehouse_title'])) $model->where('storehouse_title', 'LIKE', '%'.$data['storehouse_title'].'%');
- if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
- if(! empty($data['apply_id'])) $model->where('apply_id', $data['apply_id']);
- if(! empty($data['pc_number'])) {
- if(in_array($data['type'], [ApplyOrder::type_one,ApplyOrder::type_two])){
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['pc_number'].'%')
- ->select('id')
- ->get()->toArray();
- $dispatch_id = array_column($dispatch_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $dispatch_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }elseif($data['type'] == ApplyOrder::type_five){
- $zj_id = ScrappCount::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['pc_number'].'%')
- ->select('id')
- ->get()->toArray();
- $zj_id = array_column($zj_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $zj_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }else{
- $no = SaleOrdersProduct::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['pc_number'].'%')
- ->select('order_no')
- ->get()->toArray();
- $no = array_unique(array_column($no,'order_no'));
- $box_id = Box::where('del_time',0)
- ->whereIn('top_order_no', $no)
- ->select('id')
- ->get()->toArray();
- $box_id = array_column($box_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $box_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }
- }
- if(! empty($data['crt_id'])) $model->where('crt_id', $data['crt_id']);
- if(! empty($data['apply_time'][0]) && ! empty($data['apply_time'][1])) $model->whereBetween('apply_time',[$data['apply_time'][0],$data['apply_time'][1]]);
- if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) $model->whereBetween('crt_time',[$data['crt_time'][0],$data['crt_time'][1]]);
- if(! empty($data['dispatch_no'])){
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%')
- ->select('id')
- ->get()->toArray();
- $dispatch_id = array_column($dispatch_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $dispatch_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }
- if(! empty($data['box_no'])){
- $box_id = Box::where('del_time',0)
- ->where('order_no', 'LIKE', '%'.$data['box_no'].'%')
- ->select('id')
- ->get()->toArray();
- $box_id = array_column($box_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $box_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }
- if(! empty($data['sale_order_number'])){
- if(in_array($data['type'], [ApplyOrder::type_one,ApplyOrder::type_two])){
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
- ->select('id')
- ->get()->toArray();
- $dispatch_id = array_column($dispatch_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $dispatch_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }elseif($data['type'] == ApplyOrder::type_five){
- $zj_id = ScrappCount::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
- ->select('id')
- ->get()->toArray();
- $zj_id = array_column($zj_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $zj_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }else{
- $no = SaleOrdersProduct::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
- ->select('order_no')
- ->get()->toArray();
- $no = array_unique(array_column($no,'order_no'));
- $box_id = Box::where('del_time',0)
- ->whereIn('top_order_no', $no)
- ->select('id')
- ->get()->toArray();
- $box_id = array_column($box_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $box_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }
- }
- $list = $this->limit($model,'',$data);
- $list = $this->fillData($list);
- return [true,$list];
- }
- public function fillData($data){
- if(empty($data['data'])) return $data;
- $emp = Employee::whereIn('id',array_merge_recursive(array_unique(array_column($data['data'],'crt_id')), array_unique(array_column($data['data'],'apply_id'))))
- ->pluck('emp_name','id')
- ->toArray();
- $array1 = $array2 = $array3 = [];
- foreach ($data['data'] as $value){
- if(in_array($value['type'], [ApplyOrder::type_one,ApplyOrder::type_two])){
- $array1[] = $value['id'];
- }elseif ($value['type'] == ApplyOrder::type_five){
- $array3[] = $value['id'];
- }else{
- $array2[] = $value['id'];
- }
- }
- $order1 = ApplyOrderDetail::whereIn('type',[ApplyOrder::type_one,ApplyOrder::type_two])
- ->whereIn('apply_order_id', $array1)
- ->select('data_id','apply_order_id')
- ->get()->toArray();
- $order1_map = [];
- foreach ($order1 as $value){
- $order1_map[$value['apply_order_id']][] = $value['data_id'];
- }
- $order2 = ApplyOrderDetail::whereNotIn('type',[ApplyOrder::type_one,ApplyOrder::type_two,ApplyOrder::type_five])
- ->whereIn('apply_order_id', $array2)
- ->select('data_id','apply_order_id')
- ->get()->toArray();
- $order2_map = [];
- foreach ($order2 as $value){
- $order2_map[$value['apply_order_id']][] = $value['data_id'];
- }
- $order3 = ApplyOrderDetail::whereIn('type',[ApplyOrder::type_five])
- ->whereIn('apply_order_id', $array3)
- ->select('data_id','apply_order_id')
- ->get()->toArray();
- $order3_map = [];
- foreach ($order3 as $value){
- $order3_map[$value['apply_order_id']][] = $value['data_id'];
- }
- $map1 = DispatchSub::whereIn('id', array_unique(array_column($order1,'data_id')))
- ->pluck('out_order_no','id')
- ->toArray();
- $map2 = Box::whereIn('id', array_unique(array_column($order2,'data_id')))
- ->pluck('top_order_no','id')
- ->toArray();
- $map2_fin = SaleOrdersProduct::whereIn('order_no',array_unique(array_values($map2)))
- ->pluck('out_order_no','order_no')
- ->toArray();
- $map3 = ScrappCount::whereIn('id', array_unique(array_column($order3,'data_id')))
- ->pluck('out_order_no','id')
- ->toArray();
- foreach ($data['data'] as $key => $value){
- $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d',$value['crt_time']) : '';
- $data['data'][$key]['apply_time'] = $value['apply_time'] ? date('Y-m-d',$value['apply_time']) : '';
- $data['data'][$key]['status_title'] = ApplyOrder::$state_name[$value['status']] ?? "";
- $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
- $data['data'][$key]['apply_name'] = $emp[$value['apply_id']] ?? '';
- if(in_array($value['type'], [ApplyOrder::type_one,ApplyOrder::type_two])){
- $order_tmp = $order1_map[$value['id']] ?? [];
- $order_tmp = array_unique($order_tmp);
- $sale_order_number = [];
- foreach ($order_tmp as $v){
- $str = $map1[$v] ?? '';
- if(empty($str)) continue;
- $sale_order_number[] = $str;
- }
- $sale_order_number = array_unique($sale_order_number);
- $sale_order_number = implode(',',$sale_order_number);
- $data['data'][$key]['sale_order_number'] = $sale_order_number;
- }elseif ($value['type'] == ApplyOrder::type_five){
- $order_tmp = $order3_map[$value['id']] ?? [];
- $order_tmp = array_unique($order_tmp);
- $sale_order_number = [];
- foreach ($order_tmp as $v){
- $str = $map3[$v] ?? '';
- if(empty($str)) continue;
- $sale_order_number[] = $str;
- }
- $sale_order_number = array_unique($sale_order_number);
- $sale_order_number = implode(',',$sale_order_number);
- $data['data'][$key]['sale_order_number'] = $sale_order_number;
- }else{
- $order_tmp = $order2_map[$value['id']] ?? [];
- $order_tmp = array_unique($order_tmp);
- $sale_order_number = [];
- foreach ($order_tmp as $v){
- $m2_t = $map2[$v] ?? '';
- $m2_t = $map2_fin[$m2_t] ?? "";
- if(empty($m2_t)) continue;
- $sale_order_number[] = $m2_t;
- }
- $sale_order_number = array_unique($sale_order_number);
- $sale_order_number = implode(',',$sale_order_number);
- $data['data'][$key]['sale_order_number'] = $sale_order_number;
- }
- }
- return $data;
- }
- public function MaterialDetail($data){
- if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
- $id = $data['id'];
- $detail = ApplyOrder::where('del_time',0)
- ->where('id',$id)
- ->first();
- if(empty($detail)) return [false,'申请单不存在或已被删除'];
- $detail = $detail->toArray();
- $detail['apply_time'] = $detail['apply_time'] ? date('Y-m-d',$detail['apply_time']) : '';
- $detail['apply_title'] = Employee::where('id', $detail['apply_id'])->value('emp_name');
- $apply_d = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->get()->toArray();
- $apply_id = array_column($apply_d, 'data_id');
- $d = [];
- $out_order_no = "";
- if($detail['type'] == ApplyOrder::type_one){
- $d = DispatchSub::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'dispatch_no as order_no', 'product_title','technology_name','wood_name','product_no','order_product_id','crt_time','out_order_no')
- ->get()->toArray();
- $out_order_no = $d[0]['out_order_no'] ?? "";
- $args = "";
- foreach ($d as $value){
- $args = "(order_product_id = {$value['order_product_id']} and crt_time = {$value['crt_time']}) OR ";
- }
- $args = rtrim($args, 'OR ');
- $d_no_map = [];
- $d_no = DispatchSub::where('del_time',0)
- ->whereRaw($args)
- ->select('dispatch_no as order_no','order_product_id','crt_time')
- ->get()->toArray();
- foreach ($d_no as $value){
- if(! isset($d_no_map[$value['order_product_id'] . $value['crt_time']])){
- $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
- }
- // if(isset($d_no_map[$value['order_product_id'] . $value['crt_time']])){
- // 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'];
- // }else{
- // $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
- // }
- }
- }elseif ($detail['type'] == ApplyOrder::type_two){
- $d = DispatchSub::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id','out_order_no', 'dispatch_no as order_no','technology_name','wood_name','order_product_id','crt_time')
- ->get()->toArray();
- $out_order_no = $d[0]['out_order_no'] ?? "";
- $args = "";
- foreach ($d as $value){
- $args = "(order_product_id = {$value['order_product_id']} and crt_time = {$value['crt_time']}) OR ";
- }
- $args = rtrim($args, 'OR ');
- $d_no_map = [];
- $d_no = DispatchSub::where('del_time',0)
- ->whereRaw($args)
- ->select('dispatch_no as order_no','order_product_id','crt_time')
- ->get()->toArray();
- foreach ($d_no as $value){
- if(! isset($d_no_map[$value['order_product_id'] . $value['crt_time']])){
- $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
- }
- // if(isset($d_no_map[$value['order_product_id'] . $value['crt_time']])){
- // 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'];
- // }else{
- // $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
- // }
- }
- }elseif ($detail['type'] == ApplyOrder::type_three){
- $d = Box::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'order_no','top_order_no')
- ->get()->toArray();
- $map2_fin = SaleOrdersProduct::whereIn('order_no',array_column($d,'top_order_no'))
- ->pluck('out_order_no','order_no')
- ->toArray();
- foreach ($d as $value){
- $out_order_no = $map2_fin[$value['top_order_no']] ?? "";
- }
- }elseif ($detail['type'] == ApplyOrder::type_four){
- $d = Box::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'order_no','top_order_no')
- ->get()->toArray();
- $map2_fin = SaleOrdersProduct::whereIn('order_no',array_column($d,'top_order_no'))
- ->pluck('out_order_no','order_no')
- ->toArray();
- foreach ($d as $value){
- $out_order_no = $map2_fin[$value['top_order_no']] ?? "";
- }
- }elseif ($detail['type'] == ApplyOrder::type_five){ //质检入库申请
- $d = ScrappCount::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'out_order_no','order_number as order_no', 'product_title','technology_name','wood_name','product_no','order_product_id','crt_time')
- ->get()->toArray();
- $out_order_no = $d[0]['out_order_no'] ?? "";
- }elseif ($detail['type'] == ApplyOrder::type_six){
- $d = Box::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'order_no','top_order_no')
- ->get()->toArray();
- $map2_fin = SaleOrdersProduct::whereIn('order_no',array_column($d,'top_order_no'))
- ->pluck('out_order_no','order_no')
- ->toArray();
- foreach ($d as $value){
- $out_order_no = $map2_fin[$value['top_order_no']] ?? "";
- }
- }
- $detail['sale_order_number'] = $out_order_no;
- $d_tmp = array_column($d,null,'id');
- $return = [];
- foreach ($apply_d as $t){
- $tmp = $d_tmp[$t['data_id']] ?? [];
- $technology_name = ! empty($t['technology_name']) ? $t['technology_name'] : $tmp['technology_name'] ?? "";
- $wood_name = ! empty($t['wood_name']) ? $t['wood_name'] : $tmp['wood_name'] ?? "";
- $top_product_title = ! empty($t['top_product_title']) ? $t['top_product_title'] : $tmp['product_title'] ?? "";
- $top_product_no = ! empty($t['top_product_no']) ? $t['top_product_no'] : $tmp['product_no'] ?? "";
- if(! empty($tmp['order_product_id']) && ! empty($tmp['crt_time']) && isset($d_no_map[$tmp['order_product_id'] . $tmp['crt_time']])){
- $order_no = implode(',', array_values($d_no_map[$tmp['order_product_id'] . $tmp['crt_time']]));
- }else{
- $order_no = $tmp['order_no'] ?? "";
- }
- if($t['type'] == ApplyOrder::type_two || $t['type'] == ApplyOrder::type_three){
- $product_unit = "吨";
- }else{
- $product_unit = $t['product_unit'] ?? "";
- }
- $quantity = $t['quantity'] ?? 0;
- if($detail['type'] == ApplyOrder::type_four) $quantity = 1;
- $return[] = [
- 'id' => $t['data_id'] ?? 0,
- 'quantity' => $quantity,
- 'product_no' => $t['product_no'] ?? "",
- 'product_title' => $t['product_title'] ?? "",
- 'product_size' => $t['product_size'] ?? "",
- 'product_unit' => $product_unit,
- 'top_product_title' => $top_product_title,
- 'top_product_no' => $top_product_no,
- 'technology_name' => $technology_name, //颜色
- 'wood_name' => $wood_name,
- 'order_no' => $order_no,
- ];
- }
- $detail['order_data'] = $return;
- return [true, $detail];
- }
- public function MaterialRule(&$data,$is_add = true){
- if($this->isEmpty($data,'apply_id')) return [false,'申请人不能为空'];
- if($this->isEmpty($data,'apply_time')) return [false,'申请时间不能为空'];
- if($this->isEmpty($data,'storehouse_id')) return [false,'仓库不能为空'];
- if($this->isEmpty($data,'type')) return [false,'申请单类型不能为空'];
- if(empty($data['order_data'])) return [false, '申请单详细信息不能为空'];
- foreach ($data['order_data'] as $value){
- if(empty($value['id'])) return [false, '申请单详细信息ID不能为空'];
- if($data['type'] != ApplyOrder::type_three){
- if(empty($value['quantity'])) return [false, '申请单详细信息数量不能为空'];
- }
- }
- $id = array_unique(array_column($data['order_data'],'id'));
- if($data['type'] == ApplyOrder::type_one){
- $dispatch = DispatchSub::where('del_time',0)
- ->whereIn('id', $id)
- ->select('id', 'dispatch_no', 'status')
- ->get()->toArray();
- if(count($dispatch) != count($id)) return [false, '派工单信息错误,请重新选择'];
- }elseif ($data['type'] == ApplyOrder::type_two){
- $dispatch = DispatchSub::where('del_time',0)
- ->whereIn('id', $id)
- ->select('id', 'dispatch_no', 'status')
- ->get()->toArray();
- if(count($dispatch) != count($id)) return [false, '完工单信息错误,请重新选择'];
- }elseif ($data['type'] == ApplyOrder::type_three){
- $box = Box::where('del_time',0)
- ->whereIn('id', $id)
- ->select('id', 'order_no', 'status')
- ->get()->toArray();
- if(count($box) != count($id)) return [false, '包装单信息错误,请重新选择'];
- }elseif ($data['type'] == ApplyOrder::type_four){
- $box = Box::where('del_time',0)
- ->whereIn('id', $id)
- ->select('id', 'order_no', 'status')
- ->get()->toArray();
- if(count($box) != count($id)) return [false, '包装单信息错误,请重新选择'];
- }elseif ($data['type'] == ApplyOrder::type_five){
- $scrapp = ScrappCount::where('del_time',0)
- ->whereIn('id', $id)
- ->select('id', 'order_no', 'status')
- ->get()->toArray();
- if(count($scrapp) != count($id)) return [false, '质检单信息错误,请重新选择'];
- }else{
- return [false, '申请单类型错误'];
- }
- if($is_add){
- $data['order_number'] = $this->setOrderNO($data['type']);
- if(empty($data['order_number'])) return [false, '申请单唯一标识生成失败'];
- }else{
- if(empty($data['id'])) return [false, '申请单唯一标识不能为空'];
- if(empty($data['order_number'])) return [false, '申请单唯一标识不能为空'];
- $apply = ApplyOrder::where('id', $data['id'])->where('del_time', 0)->first();
- if(empty($apply)) return [false, '申请单不存在或已被删除'];
- if($apply->status != 0) return [false, '申请单已审核,编辑失败'];
- }
- return [true,''];
- }
- public function setOrderNO($type = "",$time = 0){
- if(empty($time)){
- $str = date('Ymd',time());
- }else{
- $str = date('Ymd',$time);
- }
- $order_number = ApplyOrder::where('order_number','Like','%'. $str . '%')
- ->where('type', $type)
- ->max('order_number');
- if(empty($order_number)){
- $number = str_pad(1,3,'0',STR_PAD_LEFT);
- $number = $str . $number;
- }else{
- $tmp = substr($order_number, -3);
- $tmp = $tmp + 1;
- //超过999
- // if(strlen($tmp) > 3) return '';
- $number = str_pad($tmp,3,'0',STR_PAD_LEFT);
- $number = $str . $number;
- }
- return $number;
- }
- public function createSQ($data, $user, $type = 0, $status = 1,$time = 0){
- if(empty($data) || empty($type)) return [false, '自动生成申请单参数不能为空'];
- if($type == ApplyOrder::type_one){
- $storehouse_id = "001";
- $storehouse_title = "原料仓";
- }elseif ($type == ApplyOrder::type_two){
- $storehouse_id = "004";
- $storehouse_title = "待清洗原材料仓";
- }elseif ($type == ApplyOrder::type_three){
- $storehouse_id = "002";
- $storehouse_title = "产成品仓";
- }elseif($type == ApplyOrder::type_four){
- $storehouse_id = "003";
- $storehouse_title = "包材、辅料仓" ;
- }elseif ($type == ApplyOrder::type_six){
- $storehouse_id = "004";
- $storehouse_title = "待清洗原材料仓";
- }
- try{
- DB::beginTransaction();
- $order_number = $this->setOrderNO($type, $time);
- // list($status,$msg) = $this->limitingSendRequestBackg("spAdd" . $order_number . $type);
- // if(! $status) return [false, $msg];
- if(empty($time)) $time = time();
- $model = new ApplyOrder();
- $model->order_number = $order_number;
- $model->apply_id = $user['id'];
- $model->apply_time = $time;
- $model->storehouse_id = $storehouse_id;
- $model->storehouse_title = $storehouse_title;
- $model->type = $type;
- $model->status = $status; //是否审核
- $model->save();
- $id = $model->id;
- $detail_insert = [];
- foreach ($data as $v){
- $detail_insert[] = [
- 'apply_order_id' => $id,
- 'data_id' => $v['id'],
- 'quantity' => $v['quantity'] ?? 0,
- 'product_no' => $v['product_no'] ?? "",
- 'product_title' => $v['product_title'] ?? "",
- 'product_size' => $v['product_size'] ?? "",
- 'product_unit' => $v['product_unit'] ?? "",
- 'technology_name' => $v['technology_name'] ?? "",
- 'wood_name' => $v['wood_name'] ?? "",
- 'top_product_no' => $v['top_product_no'] ?? "",
- 'top_product_title' => $v['top_product_title'] ?? "",
- 'type' => $type,
- 'storehouse_id' => $storehouse_id,
- 'crt_time' => $time,
- ];
- }
- ApplyOrderDetail::insert($detail_insert);
- DB::commit();
- }catch (\Exception $e){
- DB::rollBack();
- return [false,$e->getMessage()];
- }
- return [true, $id];
- }
- public function createSqFive($data, $user, $type = 0, $status = 1, $time = 0){
- if(empty($data) || empty($type)) return [false, '自动生成申请单参数不能为空'];
- try{
- DB::beginTransaction();
- if(empty($time)) $time = time();
- $first = $data[0] ?? [];
- $order_number = $this->setOrderNO($type, $time);
- $model = new ApplyOrder();
- $model->order_number = $order_number;
- $model->apply_id = $user['id'];
- $model->apply_time = $time;
- $model->storehouse_id = $first['storehouse_id'];
- $model->storehouse_title = $first['storehouse_title'];
- $model->type = $type;
- $model->status = $status; //是否审核
- $model->save();
- $id = $model->id;
- $insert = [];
- foreach ($data as $value){
- $insert[] = [
- 'apply_order_id' => $id,
- 'data_id' => $value['id'],
- 'quantity' => $value['quantity'] ?? 0,
- 'product_no' => $value['product_no'] ?? "",
- 'product_title' => $value['product_title'] ?? "",
- 'product_size' => $value['product_size'] ?? "",
- 'product_unit' => $value['product_unit'] ?? "",
- 'technology_name' => $value['technology_name'] ?? "",
- 'wood_name' => $value['wood_name'] ?? "",
- 'top_product_no' => $value['top_product_no'] ?? "",
- 'top_product_title' => $value['top_product_title'] ?? "",
- 'type' => $type,
- 'storehouse_id' => $value['storehouse_id'],
- 'crt_time' => $time,
- ];
- }
- ApplyOrderDetail::insert($insert);
- DB::commit();
- }catch (\Exception $e){
- DB::rollBack();
- return [false,$e->getMessage()];
- }
- return [true, ''];
- }
- //流水
- public function createRecord($id){return [true, ''];
- $record = ApplyOrderDetail::where('apply_order_id', $id)
- ->where('del_time',0)
- ->get()->toArray();
- if(empty($record)) return [false, '申请单明细数据不存在或已被删除'];
- try{
- DB::beginTransaction();
- $time = time();
- $insert = [];
- foreach ($record as $value){
- if(empty($value['product_no'])) continue;
- if($value['type'] == ApplyOrder::type_one){
- $number = - $value['quantity'];
- }else{
- $number = $value['quantity'];
- }
- $insert[] = [
- 'apply_order_id' => $id,
- 'product_no' => $value['product_no'],
- 'number' => $number,
- 'type' => $value['type'],
- 'storehouse_id' => $value['storehouse_id'],
- 'crt_time' => $time,
- ];
- }
- if(! empty($insert)) InOutRecord::insert($insert);
- DB::commit();
- }catch (\Exception $e){
- DB::rollBack();
- return [false,$e->getMessage()];
- }
- return [true, ''];
- }
- //报工
- public function reportWorkingEdit($data, $user){
- list($status,$msg) = $this->reportWorkingRule($data,$user,false);
- if(!$status) return [$status,$msg];
- DB::beginTransaction();
- try{
- $time = time();
- $model = new ReportWorking();
- $model = $model->where('id',$data['id'])->first();
- $model->report_time = $data['report_time'];
- $model->mark = $data['mark']?? "";
- $model->status = $data['auto'] ?? 0;
- $model->save();
- $id = $model->id;
- ReportWorkingDetail::where('del_time',0)->where('report_working_id',$id)->update([
- 'del_time' => $time
- ]);
- //班组下的人
- $team_man = [];
- $model_t = new EmployeeTeamPermission();
- $team_array = $model_t->select('employee_id', 'team_id')->get()->toArray();
- foreach ($team_array as $v){
- $team_man[$v['team_id']][] = $v['employee_id'];
- }
- $detail_insert = [];
- foreach ($data['order_data'] as $v){
- ReportMessage::insert([
- 'order_id' => $v['id'],
- 'quantity' => $v['quantity'] ?? 0,
- 'opt_case' => ReportMessage::type_one,
- 'crt_time' => $time,
- 'user_id' => $user['id'],
- 'report_working_id' => $id,
- ]);
- $t = $team_man[$v['team_id']] ?? [];
- if(! empty($t)){
- foreach ($t as $t_v){
- $detail_insert[] = [
- 'report_working_id' => $id,
- 'data_id' => $v['id'],
- 'quantity' => $v['quantity'] ?? 0,
- 'process_id' => $v['process_id'] ?? 0,
- 'finished_id' => $t_v,
- 'team_id' => $v['team_id'],
- 'crt_time' => $time,
- ];
- }
- }else{
- $detail_insert[] = [
- 'report_working_id' => $id,
- 'data_id' => $v['id'],
- 'quantity' => $v['quantity'] ?? 0,
- 'process_id' => $v['process_id'] ?? 0,
- 'finished_id' => 0,
- 'team_id' => $v['team_id'],
- 'crt_time' => $time,
- ];
- }
- }
- ReportWorkingDetail::insert($detail_insert);
- DB::commit();
- }catch (\Exception $e){
- DB::rollBack();
- return [false,$e->getMessage()];
- }
- return [true,''];
- }
- public function getReportRate($data, $user){
- if(empty($data['dispatch_id'])) return [false, '派工单id不能为空'];
- $dispatch = DispatchSub::where('id', $data['dispatch_id'])
- ->select('process_id','dispatch_quantity')
- ->get()->toArray();
- $array = $dispatch[0] ?? [];
- $process_id = $array['process_id'] ?? 0;
- $dispatch_quantity = $array['dispatch_quantity'] ?? 0;
- $process = Process::where('del_time',0)
- ->where('is_need_remain',1)
- ->select('id','zj_type','zj_rate')
- ->get()->toArray();
- $process_id_array = array_column($process,'id');
- $process_id_map = array_column($process,null,'id');
- if(in_array($process_id, $process_id_array)){
- $tmp = $process_id_map[$process_id] ?? [];
- if(! empty($tmp) && $tmp['zj_type'] == 2) {
- $num1 = ScrappCount::where('del_time',0)
- ->where('dispatch_sub_id',$data['dispatch_id'])
- ->count();
- $total = bcdiv($dispatch_quantity, 0.75);
- $num = bcmul($total, bcdiv($tmp['zj_rate'],100,2));
- dd($num,$num1,$total);
- }
- }else{
- return [true , ['type' => 1]]; // 不需要质检
- }
- return [true, ['type' => 0]]; // 错误 或者 全检
- }
- public function getReportInfo($data){
- if(empty($data)) return [];
- $process = Process::where('del_time',0)
- ->where('is_need_remain',1)
- ->select('id','zj_type','zj_rate')
- ->get()->toArray();
- $process_id_array = array_column($process,'id');
- $process_id_map = array_column($process,null,'id');
- $num1_map = ScrappCount::where('del_time',0)
- ->whereIn('dispatch_sub_id',array_column($data,'id'))
- ->select(DB::raw('count(*) as number'), 'dispatch_sub_id')
- ->groupBy('dispatch_sub_id')
- ->get()->toArray();
- $num1_map = array_column($num1_map,'number','dispatch_sub_id');
- $return = [];
- foreach ($data as $value){
- $tmp_1 = [
- 'zj_type' => 0,
- 'zj_rate' => 0,
- 'zj_num' => 0,
- 'total_num' => 0,
- ];
- if(in_array($value['process_id'], $process_id_array)){
- $tmp = $process_id_map[$value['process_id']] ?? [];
- if(! empty($tmp)) {
- $num1 = $num1_map[$value['id']] ?? 0;
- $total = bcdiv($value['dispatch_quantity'], 0.75);
- $total = $total < 1 ? 1 : $total;
- $num = bcmul($total, bcdiv($tmp['zj_rate'],100,2));
- $return[$value['id']] = [
- 'zj_type' => $tmp['zj_type'],
- 'zj_rate' => $tmp['zj_rate'],
- 'zj_num' => $num1,
- 'total_num' => $num,
- ];
- }
- }else{
- $return[$value['id']] = $tmp_1;
- }
- }
- return $return;
- }
- public function reportWorkingAdd($data,$user){
- list($status,$msg) = $this->reportWorkingRule($data,$user);
- if(!$status) return [$status,$msg];
- DB::beginTransaction();
- try{
- $time = time();
- $model = new ReportWorking();
- $model->order_number = $data['order_number'];
- $model->report_time = $data['report_time'];
- $model->mark = $data['mark']?? "";
- $model->crt_id = $user['id'];
- $model->status = $data['auto'] ?? 0;
- $model->save();
- $id = $model->id;
- //班组下的人
- $team_man = [];
- $model_t = new EmployeeTeamPermission();
- $team_array = $model_t->select('employee_id', 'team_id')->get()->toArray();
- foreach ($team_array as $v){
- $team_man[$v['team_id']][] = $v['employee_id'];
- }
- $process = Process::where('del_time',0)
- ->where('is_need_remain',1)
- ->select('id')
- ->get()->toArray();
- $process_id = array_column($process,'id');
- $detail_insert = [];
- foreach ($data['order_data'] as $v){
- if(in_array($v['process_id'], $process_id)){
- ReportMessage::insert([
- 'order_id' => $v['id'],
- 'quantity' => $v['quantity'] ?? 0,
- 'opt_case' => ReportMessage::type_one,
- 'crt_time' => $time,
- 'user_id' => $user['id'],
- 'report_working_id' => $id,
- ]);
- }
- $t = $team_man[$v['team_id']] ?? [];
- if(! empty($t)){
- foreach ($t as $t_v){
- $detail_insert[] = [
- 'report_working_id' => $id,
- 'data_id' => $v['id'],
- 'quantity' => $v['quantity'] ?? 0,
- 'process_id' => $v['process_id'] ?? 0,
- 'finished_id' => $t_v,
- 'team_id' => $v['team_id'],
- 'crt_time' => $time,
- ];
- }
- }else{
- $detail_insert[] = [
- 'report_working_id' => $id,
- 'data_id' => $v['id'],
- 'quantity' => $v['quantity'] ?? 0,
- 'process_id' => $v['process_id'] ?? 0,
- 'finished_id' => 0,
- 'team_id' => $v['team_id'],
- 'crt_time' => $time,
- ];
- }
- }
- ReportWorkingDetail::insert($detail_insert);
- DB::commit();
- }catch (\Exception $e){
- DB::rollBack();
- return [false,$e->getMessage()];
- }
- return [true, ''];
- }
- public function reportWorkingDel($data){
- if($this->isEmpty($data,'id')) return [false,'ID必须!'];
- $apply = ReportWorking::where('id',$data['id'])->first();
- if($apply->del_time > 0) return [false,'报工单不存在或已被删除'];
- if($apply->state != ReportWorking::state_zero) return [false, '报工单已审核,删除失败'];
- $time = time();
- try {
- DB::beginTransaction();
- $apply->del_time = $time;
- $apply->save();
- ReportWorkingDetail::where('del_time', 0)->where('report_working_id',$data['id'])->update([
- 'del_time'=>time()
- ]);
- DB::commit();
- }catch (\Throwable $exception){
- DB::rollBack();
- return [false, $exception->getMessage()];
- }
- return [true,''];
- }
- public function reportWorkingList($data){
- $model = ReportWorking::where('del_time',0)
- ->select('*')
- ->orderBy('id','desc');
- if(isset($data['status'])) $model->where('status', $data['status']);
- if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
- if(! empty($data['crt_id'])) $model->where('crt_id', $data['crt_id']);
- if(! empty($data['report_time'][0]) && ! empty($data['report_time'][1])) $model->whereBetween('report_time',[$data['report_time'][0],$data['report_time'][1]]);
- if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) $model->whereBetween('crt_time',[$data['crt_time'][0],$data['crt_time'][1]]);
- if(! empty($data['dispatch_no1'])) {
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no1'].'%')
- ->select('id')
- ->get()->toArray();
- $dispatch_id = array_column($dispatch_id,'id');
- $detail = ReportWorkingDetail::where('del_time',0)
- ->whereIn('data_id', $dispatch_id)
- ->select('report_working_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'report_working_id')));
- }
- if(! empty($data['dispatch_no'])) {
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%')
- ->select('id')
- ->get()->toArray();
- $dispatch_id = array_column($dispatch_id,'id');
- $detail = ReportWorkingDetail::where('del_time',0)
- ->whereIn('data_id', $dispatch_id)
- ->select('report_working_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'report_working_id')));
- }
- if(! empty($data['sale_order_number'])){
- $id = SaleOrdersProduct::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
- ->select('id')
- ->get()->toArray();
- $dispatch_id = DispatchSub::where('del_time',0)
- ->whereIn('sale_orders_product_id',array_column($id,'id'))
- ->select('id')
- ->get()->toArray();
- $detail = ReportWorkingDetail::where('del_time',0)
- ->whereIn('data_id', $dispatch_id)
- ->select('report_working_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'report_working_id')));
- }
- $list = $this->limit($model,'',$data);
- $list = $this->reportWorkingfillData($list);
- return [true,$list];
- }
- public function reportWorkingfillData($data){
- if(empty($data['data'])) return $data;
- $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
- ->pluck('emp_name','id')
- ->toArray();
- $detail = ReportWorkingDetail::where('del_time',0)
- ->whereIn('report_working_id', array_column($data['data'],'id'))
- ->select('data_id','report_working_id')
- ->get()->toArray();
- $map = [];
- foreach ($detail as $value){
- $map[$value['data_id']] = $value['report_working_id'];
- }
- $dispatch = DispatchSub::whereIn('id',array_column($detail,'data_id'))
- ->get()->toArray();
- $map1 = [];
- $team_map = Team::where("del_time",0)->pluck('title','id')->toArray();
- $process_map = Process::where("del_time",0)->pluck('title','id')->toArray();
- foreach ($dispatch as $value){
- $report_working_id = $map[$value['id']] ?? 0;
- $value['team_name'] = $team_map[$value['team_id']] ?? "";
- $value['process_name'] = $process_map[$value['process_id']] ?? "";
- $map1[$report_working_id][] = $value;
- }
- foreach ($data['data'] as $key => $value){
- $data['data'][$key]['report_time'] = $value['report_time'] ? date('Y-m-d',$value['report_time']) : '';
- $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d',$value['crt_time']) : '';
- $data['data'][$key]['status_title'] = ReportWorking::$state_name[$value['status']] ?? "";
- $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
- $data['data'][$key]['dispatch'] = $map1[$value['id']] ?? [];
- }
- return $data;
- }
- public function reportWorkingDetail($data){
- if(empty($data['id']) && empty($data['order_number'])) return [false,'ID与OrderNumber不能为空!'];
- $id = $data['id'] ?? 0;
- $order_number = $data['order_number'] ?? "";
- $detail = ReportWorking::where('del_time',0)
- ->when(! empty($id), function ($query) use ($id){
- return $query->where('id', $id);
- })
- ->when(! empty($order_number), function ($query) use ($order_number){
- return $query->where('order_number', $order_number);
- })
- ->first();
- if(empty($detail)) return [false,'报工单不存在或已被删除'];
- $detail = $detail->toArray();
- if(empty($id)) $id = $detail['id'];
- $detail['report_time'] = $detail['report_time'] ? date('Y-m-d',$detail['report_time']) : '';
- $apply_d = ReportWorkingDetail::where('del_time', 0)
- ->where('report_working_id', $id)
- ->get()->toArray();
- $apply_id = array_column($apply_d, 'data_id');
- //派工单
- $d = DispatchSub::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'dispatch_no as order_no', 'product_title','technology_name','wood_name','product_no','process_id','product_unit','price','product_size','device_id')
- ->get()->toArray();
- $d_tmp = array_column($d,null,'id');
- $process_map = Process::whereIn('id',array_unique(array_column($d,'process_id')))
- ->pluck('title','id')
- ->toArray();
- $team_map = Team::pluck('title','id')->toArray();
- $device_map = Equipment::whereIn('id',array_unique(array_column($d,'device_id')))
- ->pluck('title','id')
- ->toArray();
- $return = [];
- foreach ($apply_d as $t){
- $tmp = $d_tmp[$t['data_id']] ?? [];
- $str = $t['data_id'] . $t['process_id'];
- if(! isset($return[$str])){
- $return[$str] = [
- 'id' => $t['data_id'] ?? 0,
- 'quantity' => $t['quantity'] ?? 0,
- 'product_no' => $tmp['product_no'] ?? "",
- 'product_title' => $tmp['product_title'] ?? "",
- 'product_size' => $tmp['product_size'] ?? "",
- 'product_unit' => $tmp['product_unit'] ?? "",
- 'technology_name' => $tmp['technology_name'] ?? "",
- 'wood_name' => $tmp['wood_name'] ?? "",
- 'order_no' => $tmp['order_no'] ?? "",
- 'process_id' => $tmp['process_id'] ?? 0,
- 'process_name' => $process_map[$tmp['process_id']] ?? "",
- 'team_id' => $t['team_id'] ?? 0,
- 'team_title' => $team_map[$t['team_id']] ?? '',
- 'device_id' => $tmp['device_id'] ?? 0,
- 'device_title' => $device_map[$tmp['device_id']] ?? '',
- ];
- }
- }
- $detail['order_data'] = array_values($return);
- return [true, $detail];
- }
- public function reportWorkingRule(&$data,$user, $is_add = true){
- if($this->isEmpty($data,'report_time')) return [false,'报工时间不能为空'];
- if(empty($data['order_data'])) return [false, '报工单详细信息不能为空'];
- foreach ($data['order_data'] as $value){
- if(empty($value['id'])) return [false, '报工单详细信息ID不能为空'];
- if(empty($value['quantity'])) return [false, '报工单详细信息数量不能为空'];
- if(empty($value['process_id'])) return [false, '报工单详细信息工序不能为空'];
- if(empty($value['team_id'])) return [false, '报工单详细信息班组不能为空'];
- }
- $id = array_unique(array_column($data['order_data'],'id'));
- $dispatch = DispatchSub::where('del_time',0)
- ->whereIn('id', $id)
- ->select('id', 'dispatch_no', 'status', 'dispatch_quantity','order_product_id')
- ->get()->toArray();
- if(count($dispatch) != count($id)) return [false, '派工单信息错误,请重新选择'];
- $count = array_unique(array_column($dispatch,'order_product_id'));
- if(count($count) > 1) return [false, '批量报工时请选择同一生产订单下的派工单'];
- if($is_add){
- $data['order_number'] = $this->setOrderNO2();
- if(empty($data['order_number'])) return [false, '报工单唯一标识生成失败'];
- }else{
- if(empty($data['id'])) return [false, '报工单唯一标识不能为空'];
- if(empty($data['order_number'])) return [false, '报工单唯一标识不能为空'];
- $apply = ReportWorking::where('id', $data['id'])->where('del_time', 0)->first();
- if(empty($apply)) return [false, '报工单不存在或已被删除'];
- if($apply->status != 0) return [false, '报工单已审核,编辑失败'];
- }
- list($status, $msg) = $this->compareQuantity($dispatch, $data);
- if(! $status) return [false, $msg];
- $em = new EmployeeService();
- $data['auto'] = $em->is_auto($user, "wgbg_auto");
- return [true,''];
- }
- public function compareQuantity($dispatch, $data){
- $id = $data['id'] ?? 0;
- $result = ReportWorkingDetail::where('del_time',0)
- ->when(! empty($id), function ($query) use ($id){
- return $query->where('report_working_id', '<>', $id);
- })
- ->where('data_id', array_column($dispatch, 'id'))
- ->select('data_id as dispatch_id','quantity')
- ->get()
- ->toArray();
- $map1 = [];
- foreach ($result as $value){
- if(isset($map1[$value['dispatch_id']])){
- $tmp = bcadd($map1[$value['dispatch_id']], $value['quantity'], 3);
- $map1[$value['dispatch_id']] = $tmp;
- }else{
- $map1[$value['dispatch_id']] = $value['quantity'];
- }
- }
- $map2 = array_column($dispatch,null,'id');
- foreach ($data['order_data'] as $value){
- $tmp = $map2[$value['id']] ?? [];
- $total = $tmp['dispatch_quantity'] ?? 0;
- $dispatch_no = $tmp['dispatch_no'] ?? "";
- $save = $map1[$value['id']] ?? 0;
- $save_total = bcadd($value['quantity'], $save, 3);
- if($save_total >= $total) return [false, "派工单号:" . $dispatch_no . "的报工总数量不能超过" . $total . "吨,目前累计报工" . $save . "吨"];
- }
- return [true, ''];
- }
- public function setOrderNO2($time = 0){
- if(empty($time)) {
- $str = date('Ymd',time());
- }else{
- $str = date('Ymd', $time);
- }
- $model = new ReportWorking();
- $order_number = $model->where('order_number','Like','%'. $str . '%')
- ->max('order_number');
- if(empty($order_number)){
- $number = str_pad(1,3,'0',STR_PAD_LEFT);
- $number = $str . $number;
- }else{
- $tmp = substr($order_number, -3);
- $tmp = $tmp + 1;
- //超过999
- // if(strlen($tmp) > 3) return '';
- $number = str_pad($tmp,3,'0',STR_PAD_LEFT);
- $number = $str . $number;
- }
- return $number;
- }
- public function applyOrderReportList($data){
- if(empty($data['apply_time'][0]) || empty($data['apply_time'][1])) return [false, '申请日期必须选择!'];
- if(empty($data['type'])) return [false, 'TYPE不能为空!'];
- $model = ApplyOrder::where('del_time',0)
- ->where('apply_time',">=",$data['apply_time'][0])
- ->where('apply_time',"<=",$data['apply_time'][1])
- ->where('type',$data['type'])
- ->select('id','order_number','apply_time','mark','status','storehouse_title')
- ->orderBy('id','desc');
- if(isset($data['status'])) $model->where('status', $data['status']);
- if(! empty($data['pc_number'])) {
- if(in_array($data['type'], [ApplyOrder::type_one,ApplyOrder::type_two])){
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['pc_number'].'%')
- ->select('id')
- ->get()->toArray();
- $dispatch_id = array_column($dispatch_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $dispatch_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }elseif($data['type'] == ApplyOrder::type_five){
- $zj_id = ScrappCount::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['pc_number'].'%')
- ->select('id')
- ->get()->toArray();
- $zj_id = array_column($zj_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $zj_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }else{
- $no = SaleOrdersProduct::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['pc_number'].'%')
- ->select('order_no')
- ->get()->toArray();
- $no = array_unique(array_column($no,'order_no'));
- $box_id = Box::where('del_time',0)
- ->whereIn('top_order_no', $no)
- ->select('id')
- ->get()->toArray();
- $box_id = array_column($box_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $box_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }
- }
- if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])){
- $model->where('crt_time',">=",$data['crt_time'][0]);
- $model->where('crt_time',"<=",$data['crt_time'][1]);
- }
- if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
- if(! empty($data['storehouse_title'])) $model->where('storehouse_title', 'LIKE', '%'.$data['storehouse_title'].'%');
- if(! empty($data['sale_order_number'])){
- if(in_array($data['type'], [ApplyOrder::type_one,ApplyOrder::type_two])){
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
- ->select('id')
- ->get()->toArray();
- $dispatch_id = array_column($dispatch_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $dispatch_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }elseif($data['type'] == ApplyOrder::type_five){
- $zj_id = ScrappCount::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
- ->select('id')
- ->get()->toArray();
- $zj_id = array_column($zj_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $zj_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }else{
- $no = SaleOrdersProduct::where('del_time',0)
- ->where('out_order_no', 'LIKE', '%'.$data['sale_order_number'].'%')
- ->select('order_no')
- ->get()->toArray();
- $no = array_unique(array_column($no,'order_no'));
- $box_id = Box::where('del_time',0)
- ->whereIn('top_order_no', $no)
- ->select('id')
- ->get()->toArray();
- $box_id = array_column($box_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $box_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }
- }
- if(! empty($data['dispatch_no'])){
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('dispatch_no', 'LIKE', '%'.$data['dispatch_no'].'%')
- ->select('id')
- ->get()->toArray();
- $dispatch_id = array_column($dispatch_id,'id');
- $detail = ApplyOrderDetail::where('del_time',0)
- ->where('type', $data['type'])
- ->whereIn('data_id', $dispatch_id)
- ->select('apply_order_id')
- ->get()->toArray();
- $model->whereIn('id', array_unique(array_column($detail,'apply_order_id')));
- }
- $list = $model->get()->toArray();
- if(empty($list)) return [true, []];
- $apply_id = array_column($list, 'id');
- //明细数据
- $result = ApplyOrderDetail::where('del_time',0)
- ->whereIn('apply_order_id', $apply_id)
- ->get()->toArray();
- if(empty($result)) return [true, []];
- //组织主表需要的数据
- $list_map = $this->makeListMap($list, $result, $data['type']);
- $data_id = array_unique(array_column($result, 'data_id'));
- list($d, $d_no_map) = $this->getDetailList($data_id, $data['type']);
- $return = [];
- $d_tmp = array_column($d,null,'id');
- foreach ($result as $t){
- $tmp = $d_tmp[$t['data_id']] ?? [];
- $technology_name = ! empty($t['technology_name']) ? $t['technology_name'] : $tmp['technology_name'] ?? "";
- $wood_name = ! empty($t['wood_name']) ? $t['wood_name'] : $tmp['wood_name'] ?? "";
- $top_product_title = ! empty($t['top_product_title']) ? $t['top_product_title'] : $tmp['product_title'] ?? "";
- $top_product_no = ! empty($t['top_product_no']) ? $t['top_product_no'] : $tmp['product_no'] ?? "";
- if(! empty($tmp['order_product_id']) && ! empty($tmp['crt_time']) && isset($d_no_map[$tmp['order_product_id'] . $tmp['crt_time']])){
- $order_no = implode(',', $d_no_map[$tmp['order_product_id'] . $tmp['crt_time']]);
- }else{
- $order_no = $tmp['order_no'] ?? "";
- }
- $quantity = $t['quantity'] ?? 0;
- if($t['type'] == ApplyOrder::type_two || $t['type'] == ApplyOrder::type_three){
- $product_unit = "吨";
- }elseif($t['type'] == ApplyOrder::type_four){
- $product_unit = "只";
- $quantity = 1;
- }else{
- $product_unit = $t['product_unit'] ?? "";
- }
- $tmp = $list_map[$t['apply_order_id']] ?? [];
- $return[] = [
- 'order_number' => $tmp['order_number'],
- 'sale_order_number' => $tmp['sale_order_number'],
- 'apply_time' => $tmp['apply_time'],
- 'mark' => $tmp['mark'],
- 'status_title' => $tmp['status_title'],
- 'storehouse_title' => $tmp['storehouse_title'],
- 'id' => $t['data_id'] ?? 0,
- // 'main_id' => $t['id'],
- 'quantity' => $quantity,
- 'product_no' => $t['product_no'] ?? "",
- 'product_title' => $t['product_title'] ?? "",
- 'product_size' => $t['product_size'] ?? "",
- 'product_unit' => $product_unit,
- 'top_product_title' => $top_product_title,
- 'top_product_no' => $top_product_no,
- 'technology_name' => $technology_name, //颜色
- 'wood_name' => $wood_name,
- 'order_no' => $order_no,
- ];
- }
- return [true, array_values($return)];
- }
- private function getDetailList($apply_id, $type){
- $d = $d_no_map = [];
- if($type == ApplyOrder::type_one){
- $d = DispatchSub::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'dispatch_no as order_no', 'product_title','technology_name','wood_name','product_no','order_product_id','crt_time')
- ->get()->toArray();
- $args = "";
- foreach ($d as $value){
- $args = "(order_product_id = {$value['order_product_id']} and crt_time = {$value['crt_time']}) OR ";
- }
- $args = rtrim($args, 'OR ');
- $d_no_map = [];
- $d_no = DispatchSub::where('del_time',0)
- ->whereRaw($args)
- ->select('dispatch_no as order_no','order_product_id','crt_time')
- ->get()->toArray();
- foreach ($d_no as $value){
- if(isset($d_no_map[$value['order_product_id'] . $value['crt_time']])){
- 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'];
- }else{
- $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
- }
- }
- }elseif ($type == ApplyOrder::type_two){
- $d = DispatchSub::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'dispatch_no as order_no','technology_name','wood_name','order_product_id','crt_time')
- ->get()->toArray();
- $args = "";
- foreach ($d as $value){
- $args = "(order_product_id = {$value['order_product_id']} and crt_time = {$value['crt_time']}) OR ";
- }
- $args = rtrim($args, 'OR ');
- $d_no_map = [];
- $d_no = DispatchSub::where('del_time',0)
- ->whereRaw($args)
- ->select('dispatch_no as order_no','order_product_id','crt_time')
- ->get()->toArray();
- foreach ($d_no as $value){
- if(isset($d_no_map[$value['order_product_id'] . $value['crt_time']])){
- 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'];
- }else{
- $d_no_map[$value['order_product_id'] . $value['crt_time']][] = $value['order_no'];
- }
- }
- }elseif ($type == ApplyOrder::type_three){
- $d = Box::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'order_no')
- ->get()->toArray();
- }elseif ($type == ApplyOrder::type_four){
- $d = Box::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'order_no')
- ->get()->toArray();
- }elseif($type == ApplyOrder::type_five){
- $d = ScrappCount::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'order_number as order_no', 'product_title','technology_name','wood_name','product_no','order_product_id','crt_time')
- ->get()->toArray();
- }elseif ($type == ApplyOrder::type_six){
- $d = Box::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'order_no')
- ->get()->toArray();
- }
- return [$d, $d_no_map];
- }
- private function makeListMap($data, $order, $type){
- if(empty($data)) return [];
- //申请单 所有的数据id
- $order_map = $data_id = [];
- foreach ($order as $value){
- $order_map[$value['apply_order_id']][] = $value['data_id'];
- $data_id[] = $value['data_id'];
- }
- if(in_array($type, [ApplyOrder::type_one,ApplyOrder::type_two])){
- $map1 = DispatchSub::whereIn('id', array_unique($data_id))
- ->pluck('out_order_no','id')
- ->toArray();
- }elseif($type == ApplyOrder::type_five){
- $map3 = ScrappCount::whereIn('id', array_unique($data_id))
- ->pluck('out_order_no','id')
- ->toArray();
- }else{
- $map2 = Box::whereIn('id', array_unique($data_id))
- ->pluck('top_order_no','id')
- ->toArray();
- $map2_fin = SaleOrdersProduct::whereIn('order_no',array_unique(array_values($map2)))
- ->pluck('out_order_no','order_no')
- ->toArray();
- }
- foreach ($data as $key => $value){
- $data[$key]['apply_time'] = $value['apply_time'] ? date('Y-m-d',$value['apply_time']) : '';
- $data[$key]['status_title'] = ApplyOrder::$state_name[$value['status']] ?? "";
- $order_tmp = $order_map[$value['id']] ?? [];
- $order_tmp = array_unique($order_tmp);
- $sale_order_number = [];
- if(in_array($type, [ApplyOrder::type_one,ApplyOrder::type_two])){
- foreach ($order_tmp as $v){
- $str = $map1[$v] ?? '';
- if(empty($str)) continue;
- $sale_order_number[] = $str;
- }
- $sale_order_number = array_unique($sale_order_number);
- $sale_order_number = implode(',',$sale_order_number);
- $data[$key]['sale_order_number'] = $sale_order_number;
- }elseif ($type == ApplyOrder::type_five){
- foreach ($order_tmp as $v){
- $str = $map3[$v] ?? '';
- if(empty($str)) continue;
- $sale_order_number[] = $str;
- }
- $sale_order_number = array_unique($sale_order_number);
- $sale_order_number = implode(',',$sale_order_number);
- $data[$key]['sale_order_number'] = $sale_order_number;
- }else{
- foreach ($order_tmp as $v){
- $m2_t = $map2[$v] ?? '';
- $m2_t = $map2_fin[$m2_t] ?? "";
- if(empty($m2_t)) continue;
- $sale_order_number[] = $m2_t;
- }
- $sale_order_number = array_unique($sale_order_number);
- $sale_order_number = implode(',',$sale_order_number);
- $data[$key]['sale_order_number'] = $sale_order_number;
- }
- }
- return array_column($data,null,'id');
- }
- public function editZj($data, $user){
- list($status, $msg) = $this->editZjRule($data);
- if(! $status) return [false, $msg];
- $order_map = array_column($msg,null,'data_id');
- try{
- DB::beginTransaction();
- $time = time();
- $insert = [];
- $max_id = $this->getDailyId();
- list($status,$msg) = $this->limitingSendRequestBackg("quantity_id_" . $max_id);
- if(! $status) return [false,$msg];
- $get_order_number = $insert_wg = [];
- foreach ($data['data'] as $value){
- $order_t = $order_map[$value['data_id']] ?? [];
- $order = $order_t['dispatch'] ?? [];
- if(empty($value['waste'])){
- $max_id += 1;
- $order_number = date("Ymd") . str_pad($max_id,3,'0',STR_PAD_LEFT);
- $get_order_number[] = $order_number;
- $insert[] = [
- 'sale_orders_product_id' => $order['sale_orders_product_id'],
- 'order_product_id' => $order['order_product_id'],
- 'dispatch_sub_id' => $order['id'],
- 'out_order_no' => $order['out_order_no'],
- 'order_no' => $order['order_no'],
- 'customer_no' => $order['customer_no'],
- 'customer_name' => $order['customer_name'],
- 'product_no' => $order['product_no'],
- 'product_title' => $order['product_title'],
- 'product_size' => $order['product_size'],
- 'product_unit' => $order['product_unit'],
- 'technology_material' => $order['technology_material'],
- 'technology_name' => $order['technology_name'],
- 'wood_name' => $order['wood_name'],
- 'price' => $order['price'],
- 'process_mark' => $order['process_mark'],
- 'table_body_mark' => $order['table_body_mark'],
- 'table_header_mark' => $order['table_header_mark'],
- 'crt_id' => $user['id'],
- 'crt_time' => $time,
- 'scrapp_num' => 0,
- 'scrapp_id' => 0,
- 'team_id' => $data['team_id'],
- 'finished_id' => $user['id'],
- 'equipment_id' => $data['equipment_id'],
- 'order_number' => $order_number,
- 'process_id' => $order['process_id'],
- 'quantity' => $value['num'],
- 'report_id' => $data['id'],
- 'result' => 0,
- 'warehouse_no' => "",
- 'warehouse_title' => "",
- 'daily_id' => $max_id,
- ];
- }else{
- foreach ($value['waste'] as $v){
- $max_id += 1;
- $order_number = date("Ymd") . str_pad($max_id,3,'0',STR_PAD_LEFT);
- $get_order_number[] = $order_number;
- $insert[] = [
- 'sale_orders_product_id' => $order['sale_orders_product_id'],
- 'order_product_id' => $order['order_product_id'],
- 'dispatch_sub_id' => $order['id'],
- 'out_order_no' => $order['out_order_no'],
- 'order_no' => $order['order_no'],
- 'customer_no' => $order['customer_no'],
- 'customer_name' => $order['customer_name'],
- 'product_no' => $order['product_no'],
- 'product_title' => $order['product_title'],
- 'product_size' => $order['product_size'],
- 'product_unit' => $order['product_unit'],
- 'technology_material' => $order['technology_material'],
- 'technology_name' => $order['technology_name'],
- 'wood_name' => $order['wood_name'],
- 'price' => $order['price'],
- 'process_mark' => $order['process_mark'],
- 'table_body_mark' => $order['table_body_mark'],
- 'table_header_mark' => $order['table_header_mark'],
- 'crt_id' => $user['id'],
- 'crt_time' => $time,
- 'scrapp_num' => $v['num'],
- 'scrapp_id' => $v['scrapp_id'],
- 'team_id' => $data['team_id'],
- 'finished_id' => $user['id'],
- 'equipment_id' => $data['equipment_id'],
- 'order_number' => $order_number,
- 'process_id' => $order['process_id'],
- 'quantity' => $value['num'],
- 'report_id' => $data['id'],
- 'result' => $v['result'],
- 'warehouse_no' => $v['warehouse_no'],
- 'warehouse_title' => $v['warehouse_title'],
- 'daily_id' => $max_id,
- ];
- }
- }
- if($value['num'] > 0) $insert_wg[] = [
- 'dispatch_id' => $value['data_id'],
- 'num' => $value['num']
- ];
- }
- //质检单 不良品单 会记录报工单的id
- if(! empty($insert)) ScrappCount::insert($insert);
- //获取新增的单据
- $result = ScrappCount::whereIn('order_number',$get_order_number)
- ->select('scrapp_num as num','id','dispatch_sub_id','warehouse_no','warehouse_title','result','product_no')
- ->get()->toArray();
- //完工入库申请单 半成品
- list($status, $msg) = $this->insertWg($insert_wg, $user);
- if(! $status) return [false, $msg];
- //获取写入的数据 写其它的业务逻辑
- list($status, $msg) = $this->insertOther($result, $user, $time);
- if(! $status) return [false, $msg];
- //反写 根据质检单上的派工单id 反写上游单据
- $this->writeDispatchQuantity(array_column($result,'dispatch_sub_id'));
- DB::commit();
- }catch (\Throwable $exception){
- DB::rollBack();
- return [false, $exception->getMessage() . '|' . $exception->getLine()];
- }
- return [true, ''];
- }
- public function editZjRule($data){
- if(empty($data['id'])) return [false, '报工单ID不能为空'];
- $order = ReportWorkingDetail::where('del_time',0)
- ->where('report_working_id', $data['id'])
- ->get()->toArray();
- if(empty($order)) return [false, "报工单信息不存在或已被删除"];
- $map = [];
- foreach ($order as $value){
- if(! isset($map[$value['data_id']])) $map[$value['data_id']] = $value['quantity'];
- }
- $sList = ScrappCount::where('del_time',0)
- ->where('report_id', $data['id'])
- ->select('dispatch_sub_id as dispatch_id','scrapp_num','quantity')
- ->get()->toArray();
- $sMap = [];
- foreach ($sList as $value){
- $num = bcadd($value['scrapp_num'], $value['quantity'],3);
- if(isset($sMap[$value['dispatch_id']])){
- $t = bcadd($sMap[$value['dispatch_id']], $num,3);
- $sMap[$value['dispatch_id']] = $t;
- }else{
- $sMap[$value['dispatch_id']] = $num;
- }
- }
- if(empty($data['team_id'])) return [false, '质检班组不能为空'];
- if(empty($data['equipment_id'])) return [false, '设备不能为空'];
- if(empty($data['data'])) return [false, '质检信息不能为空'];
- $data_id = [];
- foreach ($data['data'] as $value){
- if(empty($value['data_id'])) return [false, 'dataID不能为空'];
- if(! isset($value['num'])) return [false, 'num不能为空'];
- $num = 0;
- if(! empty($value['waste'])){
- foreach ($value['waste'] as $v){
- if(empty($v['num'])) return [false, "质检数量不能为空"];
- if(empty($v['scrapp_id'])) return [false, "请选择质检原因"];
- if(empty($v['result'])) return [false, '请选择质检产品处理结果'];
- if($v['result'] == ReportWorking::type_two && (empty($v['warehouse_no']) || empty($v['warehouse_title']))) return [false, '请选择产品去向仓库'];
- $num = bcadd($v['num'], $num, 3);
- }
- }
- $total = bcadd($num, $value['num'],3);
- $total2 = $map[$value['data_id']] ?? 0;
- if($total > $total2) return [false, '总数量不能超过报工数量'];
- $tmp = $sMap[$value['data_id']] ?? 0;
- if($tmp >= $total) return [false, '报工单已完成报工质检'];
- $data_id[] = $value['data_id'];
- }
- $dispatch = DispatchSub::whereIn('id',$data_id)->get()->toArray();
- $dispatch_map = array_column($dispatch,null,'id');
- foreach ($order as $key => $value){
- if(! in_array($value['data_id'], $data_id)){
- unset($order[$key]);
- continue;
- }
- $order[$key]['dispatch'] = $dispatch_map[$value['data_id']] ?? [];
- }
- return [true, array_values($order)];
- }
- public function getDailyId($time = 0)
- {
- if(empty($time)) $time = time();
- $today_start = strtotime(date("Y-m-d 00:00:00",$time));
- $today_end = strtotime(date("Y-m-d 23:59:59",$time));
- // 获取今天的最大daily_id
- $maxDailyId = ScrappCount::where('crt_time', '>=', $today_start)
- ->where('crt_time', '<=', $today_end)
- ->max(DB::raw('daily_id + 0'));
- return $maxDailyId ?? 0;
- }
- public function insertWg($all_data, $user){
- if(empty($all_data)) return [true, ''];
- $dispatchList = DispatchSub::whereIn('id', array_column($all_data,'dispatch_id'))->get()->toArray();
- //是否最后一道工序
- $orders = OrdersProduct::whereIn('id', array_unique(array_column($dispatchList, 'order_product_id')))
- ->select('id','process_id')
- ->get()->toArray();
- $map = [];
- foreach ($orders as $value){
- $p = explode(",", $value['process_id']);
- $lastElement = end($p);
- $map[$value['id']] = $lastElement;
- }
- $all_data_map = array_column($all_data,null,'dispatch_id');
- $need_insert = [];
- foreach ($dispatchList as $value){
- $num = $all_data_map[$value['id']] ?? [];
- $num = $num['num'] ?? 0;
- if(! $num) continue;
- if(isset($map[$value['order_product_id']]) && $map[$value['order_product_id']] == $value['process_id']){
- $tmp = [
- 'id' => $value['id'],
- 'quantity' => $num,
- 'product_no' => $value['product_no'] ?? "",
- 'product_title' => $value['product_title'] ?? "",
- 'product_size' => $value['product_size'] ?? "",
- 'product_unit' => $value['product_unit'] ?? "",
- ];
- $need_insert[] = $tmp;
- }
- }
- //生成完工入库申请单
- $service = new BoxService();
- list($status, $msg) = $service->createWGSQ($need_insert, $user);
- if(! $status) return [false, $msg];
- return [true, ''];
- }
- public function insertOther($all_data, $user, $time){
- try {
- $result = [];
- foreach ($all_data as $value){
- if($value['result'] > 0) $result[] = $value;
- }
- if(empty($result)) return [true, ''];
- $dispatchList = DispatchSub::whereIn('id', array_column($result,'dispatch_sub_id'))->get()->toArray();
- $dispatch_map = array_column($dispatchList,null,'id');
- //是否自动审核
- $em = new EmployeeService();
- $auto = $em->is_auto($user, "pg_auto");
- $dispatch_no = (new DispatchService())->setOrderNO();
- if(! $dispatch_no) return [false,'返工派工单号生成失败!'];
- $prefix = substr($dispatch_no, 0, -3);// "20250611"
- $startNum = (int)substr($dispatch_no, -3); // 7
- $is_first = true;
- $dispatch_main = $dispatch = $is_need_ll = $is_need_warehouse = [];
- foreach ($result as $value){
- //派工单
- $t = $dispatch_map[$value['dispatch_sub_id']] ?? [];
- if(! $is_first){
- $startNum += 1;
- $number = str_pad($startNum,3,'0',STR_PAD_LEFT);
- $number = $prefix . $number;
- $dispatch_no_t = $number;
- }else{
- $dispatch_no_t = $dispatch_no;
- $is_first = false;
- }
- if($value['result'] == ReportWorking::type_one){
- //重新入生产流程 需要生成返工派工单
- }else{
- //入仓库 那么需要生成质检入库申请单 生成领料申请单 生成返工派工单
- //'id','dispatch_quantity as quantity',"product_no","order_product_id","product_no",'technology_name','crt_time'
- $is_need_ll[] = $dispatch_no_t;
- $is_need_warehouse[] = [
- 'warehouse_no' => $value['warehouse_no'],
- 'warehouse_title' => $value['warehouse_title'],
- ];
- }
- $dispatch_main[] = ['dispatch_no' => $dispatch_no_t,'crt_time' => $time];
- $dispatch[] = [
- 'order_product_id' => $t['order_product_id'],
- 'order_no' => $t['order_no'],
- 'product_no' => $t['product_no'],
- 'product_title' => $t['product_title'],
- 'product_size' => $t['product_size'],
- 'product_unit' => $t['product_unit'],
- 'production_quantity' => $t['production_quantity'],
- 'dispatch_quantity' => $value['num'],
- 'technology_material' => $t['technology_material'],
- 'technology_name' => $t['technology_name'],
- 'wood_name' => $t['wood_name'],
- 'process_mark' => $t['process_mark'],
- 'table_body_mark' => $t['table_body_mark'],
- 'table_header_mark' => $t['table_header_mark'],
- 'crt_time' => $time,
- 'status' => $auto,
- 'dispatch_no' => $dispatch_no_t,
- 'process_id' => $t['process_id'],
- 'dispatch_time_start' => $t['dispatch_time_start'],
- 'dispatch_time_end' => $t['dispatch_time_end'],
- 'crt_id' => $user['id'],
- 'sale_orders_product_id' => $t['sale_orders_product_id'],
- 'out_order_no' => $t['out_order_no'],
- 'out_order_no_time' => $t['out_order_no_time'],
- 'price' => $t['price'],
- 'customer_no' => $t['customer_no'],
- 'customer_name' => $t['customer_name'],
- 'pre_shipment_time' => $t['pre_shipment_time'],
- 'team_id' => $t['team_id'],
- 'device_id' => $t['device_id'],
- 'type' => 1,
- ];
- }
- Dispatch::insert($dispatch_main);
- DispatchSub::insert($dispatch);
- if(! empty($is_need_ll)){
- //获取上一次插入订单的所有数据
- $insert = DispatchSub::whereIn('dispatch_no', $is_need_ll)
- ->where('crt_time',$time)
- ->where('crt_id',$user['id'])
- ->select('id','dispatch_quantity as quantity',"product_no")
- ->get()->toArray();
- //领料申请单
- list($status, $msg) = (new DispatchService())->createSQ($insert, $user);
- if(! $status) return [false, $msg];
- //质检入库申请单 原材料
- list($status, $msg) = $this->createZJSQ($all_data, $user, $is_need_warehouse);
- if(! $status) return [false, $msg];
- }
- return [true, ''];
- }catch (\Throwable $exception){
- return [false, $exception->getMessage()];
- }
- }
- public function createZJSQ($insert_data, $user, $warehouse, $time = 0){
- try {
- DB::beginTransaction();
- //是否自动审核质检入库申请单
- $em = new EmployeeService();
- $auto = $em->is_auto($user, "zjsq_auto");
- $return = [];
- $product_no = array_unique(array_column($insert_data,'product_no'));
- //获取原料
- $service = new FyyOrderService();
- list($status, $msg) = $service->getProductDataFromSqlServer(['product_no' => $product_no], $user);
- if($status) $return = $msg;
- //组织原材料写入数据
- $insert = [];
- foreach ($insert_data as $key => $value){
- $quantity = 0;
- if(! empty($value['quantity'])) {
- $quantity = $value['quantity'];
- }elseif (! empty($value['dispatch_quantity'])){
- $quantity = $value['dispatch_quantity'];
- }elseif (! empty($value['num'])){
- $quantity = $value['num'];
- }
- $t = $return[$value['product_no']] ?? [];
- $tmp = [
- 'id' => $value['id'],
- 'quantity' => $quantity,
- 'product_no' => "",
- 'product_title' => "",
- 'product_size' => "",
- 'product_unit' => "",
- 'storehouse_id' => $warehouse[$key]['warehouse_no'] ?? "",
- 'storehouse_title' => $warehouse[$key]['warehouse_title'] ?? "",
- ];
- if(! empty($t)){
- foreach ($t as $v){
- $tmp['product_no'] = $v['product_no'];
- $tmp['product_title'] = $v['product_title'];
- $tmp['product_size'] = $v['product_size'];
- $tmp['product_unit'] = $v['product_unit'];
- $insert[] = $tmp;
- }
- }else{
- $tmp['quantity'] = 0;
- $insert[] = $tmp;
- }
- }
- //生成质检入库申请单
- $service = new ApplyOrderService();
- list($status, $msg) = $service->createSqFive($insert, $user, ApplyOrder::type_five, $auto, $time);
- if(! $status) {
- DB::rollBack();
- return [false, $msg];
- }
- DB::commit();
- }catch (\Throwable $exception){
- DB::rollBack();
- return [false, $exception->getFile() . $exception->getMessage() . $exception->getLine()];
- }
- return [true, ''];
- }
- //反写
- public function writeDispatchQuantity($dispatch_id){
- $result = ScrappCount::where('del_time',0)
- ->whereIn('dispatch_sub_id', $dispatch_id)
- ->select('dispatch_sub_id','quantity','scrapp_num','crt_time','process_id','order_product_id')
- ->get()->toArray();
- //是否最后一道工序
- $orders = OrdersProduct::whereIn('id', array_unique(array_column($result, 'order_product_id')))
- ->select('id','process_id')
- ->get()->toArray();
- $map = [];
- foreach ($orders as $value){
- $p = explode(",", $value['process_id']);
- $lastElement = end($p);
- $map[$value['id']] = $lastElement;
- }
- //汇总这个派工单一共质检良品数量 但是同一时间下的 只取一次
- $update = $flag = $need_update = [];
- foreach ($result as $value){
- if(isset($map[$value['order_product_id']]) && $map[$value['order_product_id']] == $value['process_id'] && ! in_array($value['order_product_id'], $need_update)){
- $need_update[] = [
- 'order_product_id' => $value['order_product_id'],
- 'process_id' => $value['process_id'],
- ];
- }
- $key = $value['dispatch_sub_id'] . $value['crt_time'];
- if(isset($flag[$key])) continue;
- if(isset($update[$value['dispatch_sub_id']])){
- $tmp = bcadd($value['quantity'], $update[$value['dispatch_sub_id']], 3);
- $update[$value['dispatch_sub_id']] = $tmp;
- }else{
- $update[$value['dispatch_sub_id']] = $value['quantity'];
- }
- $flag[$key] = 1;
- }
- unset($flag);
- //更新派工单完工数量----------------------------------------------------
- foreach ($update as $id => $num){
- DispatchSub::where('id', $id)->update([
- 'finished_num' => $num,
- 'wg_status' => 1,
- ]);
- }
- if(! empty($need_update)){
- //更新生产订单的完工数量--------------------------------------------------
- $list = DispatchSub::where("del_time",0)
- ->when(! empty($need_update), function ($query) use ($need_update) {
- return $query->where(function ($q) use ($need_update) {
- foreach ($need_update as $value) {
- $order_product_id = $value['order_product_id'];
- $process_id = $value['process_id'];
- $q->orWhere(function ($subQ) use ($order_product_id, $process_id) {
- $subQ->where('order_product_id', $order_product_id)
- ->where('process_id', $process_id);
- });
- }
- });
- })
- ->select('order_product_id', 'finished_num', 'sale_orders_product_id')
- ->get()->toArray();
- $map2 = [];
- foreach ($list as $value){
- if(isset($map2[$value['order_product_id']])){
- $tmp = bcadd($map2[$value['order_product_id']], $value['finished_num'], 3);
- $map2[$value['order_product_id']] = $tmp;
- }else{
- $map2[$value['order_product_id']] = $value['finished_num'];
- }
- }
- foreach ($map2 as $id => $num){
- OrdersProduct::where('id', $id)->update([
- 'finished_num' => $num
- ]);
- }
- //更新销售订单完工数量-------------------------------------------------------
- $list2 = OrdersProduct::where('del_time',0)
- ->whereIn('sale_orders_product_id', array_unique(array_column($list, 'sale_orders_product_id')))
- ->select('finished_num','sale_orders_product_id')
- ->get()->toArray();
- $map3 = [];
- foreach ($list2 as $value){
- if(isset($map3[$value['sale_orders_product_id']])){
- $tmp = bcadd($map3[$value['sale_orders_product_id']], $value['finished_num'], 3);
- $map3[$value['sale_orders_product_id']] = $tmp;
- }else{
- $map3[$value['sale_orders_product_id']] = $value['finished_num'];
- }
- }
- foreach ($map3 as $id => $num){
- SaleOrdersProduct::where('id', $id)->update([
- 'finished_num' => $num
- ]);
- }
- }
- }
- public function orderSearchList($data){
- if(empty($data['type'])) return [false, '单据联查类型不能为空'];
- if(empty($data['data_id'])) return [false, '依据单据ID不能为空'];
- //不管进来的是什么单据id 转换为销售订单
- $result = $this->changeIdToOrderNew($data);
- // $sales_id = $this->changeIdToOrder($data);
- // list($status, $msg) = $this->forSearch($data, $sales_id);
- return [true, $result];
- }
- private function changeIdToOrder($data)
- {
- $id = $data['data_id'];
- $search_id = $result = [];
- if ($data['type'] == 1) {
- $result[] = [
- 'id' => $id
- ];
- } elseif ($data['type'] == 2) {
- $result = OrdersProduct::where('del_time', 0)
- ->where('id', $id)
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- } elseif ($data['type'] == 3) {
- $result = DispatchSub::where('del_time', 0)
- ->where('id', $data['data_id'])
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- } elseif ($data['type'] == 4) {
- $detail = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time', 0)
- ->select('data_id')
- ->get()->toArray();
- $result = DispatchSub::where('del_time', 0)
- ->whereIn('id', array_unique(array_column($detail, 'data_id')))
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- } elseif ($data['type'] == 5) {
- $result = DispatchSub::where('del_time', 0)
- ->where('id', $id)
- ->where('finished_num', '>', 0)
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- } elseif ($data['type'] == 6) {
- $first = Box::where('del_time', 0)
- ->where('id', $id)
- ->select("top_order_no", 'order_no')
- ->first();
- if (!empty($first)) {
- $first = $first->toArray();
- $box_detail = new BoxDetail(['channel' => $first['top_order_no']]);
- $result = $box_detail->where('order_no', $first['order_no'])->select('top_id as id')->get()->toArray();
- }
- } elseif ($data['type'] == 7) {
- $result = ScrappCount::where('del_time', 0)
- ->where('id', $id)
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- } elseif ($data['type'] == 8) {
- $result = ScrappCount::where('del_time', 0)
- ->where('id', $id)
- ->where('scrapp_num', '>', 0)
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- } elseif ($data['type'] == 9) {
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_one)
- ->select('data_id as dispatch_id')
- ->get()->toArray();
- $result = DispatchSub::where('del_time', 0)
- ->where('id', array_unique(array_column($detail, 'dispatch_id')))
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- } elseif ($data['type'] == 10) {
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_two)
- ->select('data_id as dispatch_id')
- ->get()->toArray();
- $result = DispatchSub::where('del_time', 0)
- ->where('id', array_unique(array_column($detail, 'dispatch_id')))
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- } elseif ($data['type'] == 11) {
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_four)
- ->select('data_id as box_id')
- ->get()->toArray();
- $first = Box::where('del_time', 0)
- ->whereIn('id', array_unique(array_column($detail, 'box_id')))
- ->select("top_order_no", 'order_no')
- ->get()->toArray();
- if (!empty($first)) {
- foreach ($first as $value) {
- $box_detail = new BoxDetail(['channel' => $value['top_order_no']]);
- $t = $box_detail->where('order_no', $value['order_no'])->select('top_id as id')->get()->toArray();
- $result = array_merge($result, $t);
- }
- }
- } elseif ($data['type'] == 12) {
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_three)
- ->select('data_id as box_id')
- ->get()->toArray();
- $first = Box::where('del_time', 0)
- ->whereIn('id', array_unique(array_column($detail, 'box_id')))
- ->select("top_order_no", 'order_no')
- ->get()->toArray();
- if (!empty($first)) {
- foreach ($first as $value) {
- $box_detail = new BoxDetail(['channel' => $value['top_order_no']]);
- $t = $box_detail->where('order_no', $value['order_no'])->select('top_id as id')->get()->toArray();
- $result = array_merge($result, $t);
- }
- }
- } elseif ($data['type'] == 13) {
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_five)
- ->select('data_id as zj_id')
- ->get()->toArray();
- $result = ScrappCount::where('del_time', 0)
- ->whereIn('id', array_unique(array_column($detail, 'zj_id')))
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- }
- foreach ($result as $value) {
- if (!in_array($value['id'], $search_id)) {
- $search_id[] = $value['id'];
- }
- }
- return $search_id;
- }
- private function forSearch($data, $sales_id){
- $result = [];
- //通过销售订单查找所有业务单据
- if($data['for_type'] == 1){
- $result = SaleOrdersProduct::where('del_time',0)
- ->whereIn('id', $sales_id)
- ->select('id', 'out_order_no as order_no')
- ->get()->toArray();
- }elseif($data['for_type'] == 2){
- $result = OrdersProduct::where('del_time',0)
- ->whereIn('sale_orders_product_id', $sales_id)
- ->select('id', 'production_no as order_no')
- ->get()->toArray();
- }elseif($data['for_type'] == 3){
- $result = DispatchSub::where('del_time',0)
- ->whereIn('sale_orders_product_id', $sales_id)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif($data['for_type'] == 4){
- $dispatch = DispatchSub::where('del_time',0)
- ->whereIn('sale_orders_product_id', $sales_id)
- ->select('id')
- ->get()->toArray();
- $detail = ReportWorkingDetail::whereIn('data_id', array_column($dispatch,'id'))
- ->where('del_time',0)
- ->select('report_working_id')
- ->get()->toArray();
- $result = ReportWorking::where('del_time',0)
- ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif($data['for_type'] == 5){
- $result = DispatchSub::where('del_time',0)
- ->whereIn('sale_orders_product_id', $sales_id)
- ->where('finished_num','>',0)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif($data['for_type'] == 6){
- $sale = SaleOrdersProduct::whereIn('id', $sales_id)->select('order_no')->get()->toArray();
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$data['data_id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->select("id","order_no")
- ->get()->toArray();
- $result = array_merge($result, $tmp);
- }
- }elseif ($data['for_type'] == 7){
- $result = ScrappCount::where('del_time',0)
- ->whereIn('sale_orders_product_id', $sales_id)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($data['for_type'] == 8){
- $result = ScrappCount::where('del_time',0)
- ->whereIn('sale_orders_product_id', $sales_id)
- ->where('scrapp_num','>', 0)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($data['for_type'] == 9){
- $dispatch = DispatchSub::where('del_time',0)
- ->whereIn('sale_orders_product_id', $sales_id)
- ->select('id')
- ->get()->toArray();
- $detail = ApplyOrderDetail::where('del_time',0)
- ->whereIn('data_id', array_column($dispatch,'id'))
- ->where('type',ApplyOrder::type_one)
- ->select('apply_order_id')
- ->get()->toArray();
- $result = ApplyOrder::where('del_time',0)
- ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($data['for_type'] == 10){
- $dispatch = DispatchSub::where('del_time',0)
- ->whereIn('sale_orders_product_id', $sales_id)
- ->select('id')
- ->get()->toArray();
- $detail = ApplyOrderDetail::where('del_time',0)
- ->whereIn('data_id', array_column($dispatch,'id'))
- ->where('type',ApplyOrder::type_two)
- ->select('apply_order_id')
- ->get()->toArray();
- $result = ApplyOrder::where('del_time',0)
- ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif($data['for_type'] == 11){
- $sale = SaleOrdersProduct::whereIn('id', $sales_id)->select('order_no')->get()->toArray();
- $ids = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$data['data_id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->select("id")
- ->get()->toArray();
- $ids = array_merge($ids, $tmp);
- }
- $detail = ApplyOrderDetail::where('del_time',0)
- ->whereIn('data_id', array_column($ids,'id'))
- ->where('type',ApplyOrder::type_four)
- ->select('apply_order_id')
- ->get()->toArray();
- $result = ApplyOrder::where('del_time',0)
- ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif($data['for_type'] == 12){
- $sale = SaleOrdersProduct::whereIn('id', $sales_id)->select('order_no')->get()->toArray();
- $ids = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$data['data_id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->select("id")
- ->get()->toArray();
- $ids = array_merge($ids, $tmp);
- }
- $detail = ApplyOrderDetail::where('del_time',0)
- ->whereIn('data_id', array_column($ids,'id'))
- ->where('type',ApplyOrder::type_three)
- ->select('apply_order_id')
- ->get()->toArray();
- $result = ApplyOrder::where('del_time',0)
- ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif($data['for_type'] == 13){
- $zj_id = ScrappCount::where('del_time',0)
- ->where('scrapp_num','>',0)
- ->whereIn('sale_orders_product_id', $sales_id)
- ->select('id')
- ->get()->toArray();
- $detail = ApplyOrderDetail::where('del_time',0)
- ->whereIn('data_id', array_column($zj_id,'id'))
- ->where('type',ApplyOrder::type_five)
- ->select('apply_order_id')
- ->get()->toArray();
- $result = ApplyOrder::where('del_time',0)
- ->whereIn('id', array_unique(array_column($detail,'apply_order_id')))
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }
- return [true, $result];
- }
- private function changeIdToOrderNew1($data)
- {
- $id = $data['data_id'];
- $search_id = $result = [];
- if ($data['type'] == 1) {
- } elseif ($data['type'] == 2) {
- $result[1] = OrdersProduct::where('del_time', 0)
- ->where('id', $id)
- ->pluck('sale_orders_product_id')
- ->toArray();
- } elseif ($data['type'] == 3) {
- $array = DispatchSub::where('del_time', 0)
- ->where('id', $data['data_id'])
- ->select('sale_orders_product_id', 'order_product_id')
- ->get()->toArray();
- foreach ($array as $value){
- $result[1][] = $value['sale_orders_product_id'];
- $result[2][] = $value['order_product_id'];
- }
- } elseif ($data['type'] == 4) {
- $detail = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time', 0)
- ->select('data_id')
- ->get()->toArray();
- $array = DispatchSub::where('del_time', 0)
- ->whereIn('id', array_unique(array_column($detail, 'data_id')))
- ->select('sale_orders_product_id', 'order_product_id','id')
- ->get()->toArray();
- foreach ($array as $value){
- $result[1][] = $value['sale_orders_product_id'];
- $result[2][] = $value['order_product_id'];
- $result[3][] = $value['id'];
- }
- } elseif ($data['type'] == 5) {
- $array = DispatchSub::where('del_time', 0)
- ->where('id', $id)
- ->where('finished_num', '>', 0)
- ->select('sale_orders_product_id', 'order_product_id','id')
- ->get()->toArray();
- foreach ($array as $value){
- $result[1][] = $value['sale_orders_product_id'];
- $result[2][] = $value['order_product_id'];
- $result[3][] = $value['id'];
- }
- $detail = ReportWorkingDetail::where('data_id', $id)
- ->where('del_time', 0)
- ->select('report_working_id')
- ->get()->toArray();
- foreach ($detail as $value){
- $result[4][] = $value['report_working_id'];
- }
- } elseif ($data['type'] == 6) {
- $first = Box::where('del_time', 0)
- ->where('id', $id)
- ->select("top_order_no", 'order_no','id')
- ->first();
- if (! empty($first)) {
- $first = $first->toArray();
- $boxArray = BoxWithDispatch::where('del_time',0)
- ->where('box_id',$first['id'])
- ->select('dispatch_id','num')
- ->get()->toArray();
- if(! empty($boxArray)){
- $dispatch_id = array_column($boxArray,'dispatch_id');
- $array = DispatchSub::where('del_time', 0)
- ->whereIn('id',$dispatch_id)
- ->select('sale_orders_product_id', 'order_product_id','id')
- ->get()->toArray();
- foreach ($array as $value){
- $result[1][] = $value['sale_orders_product_id'];
- $result[2][] = $value['order_product_id'];
- $result[3][] = $value['id'];
- }
- $detail = ReportWorkingDetail::whereIn('data_id', $dispatch_id)
- ->where('del_time', 0)
- ->select('report_working_id')
- ->get()->toArray();
- foreach ($detail as $value){
- $result[4][] = $value['report_working_id'];
- }
- $result[5] = $dispatch_id;
- }else{
- $array = [];
- $box_detail = new BoxDetail(['channel' => $first['top_order_no']]);
- $detail = $box_detail->where('order_no', $first['order_no'])->select('top_id as id')->get()->toArray();
- foreach ($detail as $value){
- if(! in_array($value['id'], $array)) $array[] = $value['id'];
- }
- $result[1] = $array;
- $result[2] = OrdersProduct::where('del_time',0)
- ->whereIn('sale_orders_product_id',$array)
- ->pluck('id')->toArray();
- }
- }
- } elseif ($data['type'] == 7) {
- $result = ScrappCount::where('del_time', 0)
- ->where('id', $id)
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- } elseif ($data['type'] == 8) {
- $result = ScrappCount::where('del_time', 0)
- ->where('id', $id)
- ->where('scrapp_num', '>', 0)
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- } elseif ($data['type'] == 9) {
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_one)
- ->select('data_id as dispatch_id')
- ->get()->toArray();
- $result = DispatchSub::where('del_time', 0)
- ->where('id', array_unique(array_column($detail, 'dispatch_id')))
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- } elseif ($data['type'] == 10) {
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_two)
- ->select('data_id as dispatch_id')
- ->get()->toArray();
- $result = DispatchSub::where('del_time', 0)
- ->where('id', array_unique(array_column($detail, 'dispatch_id')))
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- } elseif ($data['type'] == 11) {
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_four)
- ->select('data_id as box_id')
- ->get()->toArray();
- $first = Box::where('del_time', 0)
- ->whereIn('id', array_unique(array_column($detail, 'box_id')))
- ->select("top_order_no", 'order_no')
- ->get()->toArray();
- if (!empty($first)) {
- foreach ($first as $value) {
- $box_detail = new BoxDetail(['channel' => $value['top_order_no']]);
- $t = $box_detail->where('order_no', $value['order_no'])->select('top_id as id')->get()->toArray();
- $result = array_merge($result, $t);
- }
- }
- } elseif ($data['type'] == 12) {
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_three)
- ->select('data_id as box_id')
- ->get()->toArray();
- $first = Box::where('del_time', 0)
- ->whereIn('id', array_unique(array_column($detail, 'box_id')))
- ->select("top_order_no", 'order_no')
- ->get()->toArray();
- if (!empty($first)) {
- foreach ($first as $value) {
- $box_detail = new BoxDetail(['channel' => $value['top_order_no']]);
- $t = $box_detail->where('order_no', $value['order_no'])->select('top_id as id')->get()->toArray();
- $result = array_merge($result, $t);
- }
- }
- } elseif ($data['type'] == 13) {
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_five)
- ->select('data_id as zj_id')
- ->get()->toArray();
- $result = ScrappCount::where('del_time', 0)
- ->whereIn('id', array_unique(array_column($detail, 'zj_id')))
- ->select('sale_orders_product_id as id')
- ->get()->toArray();
- }
- foreach ($result as $value) {
- if (!in_array($value['id'], $search_id)) {
- $search_id[] = $value['id'];
- }
- }
- return $search_id;
- }
- private function changeIdToOrderNew($data)
- {
- $id = $data['data_id'];
- $result = [];
- $type = $data['type'];
- $for_type = $data['for_type'];
- if ($data['type'] == 1) {
- $result = $this->typeOne($for_type, $id);
- } elseif ($type == 2) {
- $result = $this->typeTwo($for_type, $id);
- } elseif ($type == 3) {
- $result = $this->typeThree($for_type, $id);
- } elseif ($type == 4) {
- $result = $this->typeFour($for_type, $id);
- } elseif ($type == 5) {
- $result = $this->typeFive($for_type, $id);
- } elseif ($type == 6) {
- $result = $this->typeSix($for_type, $id);
- } elseif ($type == 7) {
- $result = $this->typeSeven($for_type, $id);
- } elseif ($type == 8) {
- $result = $this->typeEight($for_type, $id);
- } elseif ($type == 9) {
- $result = $this->typeNine($for_type, $id);
- } elseif ($type == 10) {
- $result = $this->typeTen($for_type, $id);
- } elseif ($type == 11) {
- $result = $this->typeEve($for_type, $id);
- } elseif ($type == 12) {
- $result = $this->typeTwl($for_type, $id);
- } elseif ($type == 13) {
- $result = $this->typeThi($for_type, $id);
- } elseif ($type == 14) {
- $result = $this->typeFourTeen($for_type, $id);
- }
- return $result;
- }
- private function typeOne($for_type, $id){
- $result = [];
- if($for_type == 2){
- $result = OrdersProduct::where('del_time',0)
- ->where('sale_orders_product_id', $id)
- ->select('id', 'production_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 3){
- $result = DispatchSub::where('del_time',0)
- ->where('sale_orders_product_id', $id)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 4){
- $dispatch = DispatchSub::where('del_time',0)
- ->where('sale_orders_product_id', $id)
- ->select('id')
- ->get()->toArray();
- $detail = ReportWorkingDetail::whereIn('data_id', array_column($dispatch,'id'))
- ->where('del_time',0)
- ->select('report_working_id')
- ->get()->toArray();
- $result = ReportWorking::where('del_time',0)
- ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 5){
- $result = DispatchSub::where('del_time',0)
- ->where('sale_orders_product_id', $id)
- ->where('finished_num','>',0)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 6){
- $sale = SaleOrdersProduct::where('id', $id)->select('order_no')->get()->toArray();
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$id)->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->select("id","order_no")
- ->get()->toArray();
- $result = array_merge($result, $tmp);
- }
- }elseif ($for_type == 7){
- $process = Process::where('del_time',0)
- ->where('is_need_remain',1)
- ->pluck('id')
- ->toArray();
- $result = ScrappCount::where('del_time',0)
- ->where('sale_orders_product_id', $id)
- ->whereIn('process_id', $process)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 8){
- $result = ScrappCount::where('del_time',0)
- ->where('sale_orders_product_id', $id)
- ->where('scrapp_num','>', 0)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 9){
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('sale_orders_product_id', $id)
- ->pluck('id')
- ->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_one)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 10){
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('sale_orders_product_id', $id)
- ->pluck('id')
- ->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_two)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 11){
- $sale = SaleOrdersProduct::where('id', $id)->select('order_no','id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_four)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 12){
- $sale = SaleOrdersProduct::where('id', $id)->select('order_no','id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_three)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 13){
- $s_id = ScrappCount::where('del_time', 0)
- ->where('sale_orders_product_id', $id)
- ->pluck('id')
- ->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $s_id)
- ->where('type', ApplyOrder::type_five)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 14){
- $sale = SaleOrdersProduct::where('id', $id)->select('order_no','id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_six)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }
- return $result;
- }
- private function typeTwo($for_type, $id){
- $result = [];
- if($for_type == 1){
- $sale_orders_product_id = OrdersProduct::where('del_time',0)
- ->where('id', $id)
- ->pluck('sale_orders_product_id')
- ->toArray();
- $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
- ->where('del_time',0)
- ->select('id','out_order_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 3){
- $result = DispatchSub::where('del_time',0)
- ->where('order_product_id', $id)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 4){
- $dispatch = DispatchSub::where('del_time',0)
- ->where('order_product_id', $id)
- ->select('id')
- ->get()->toArray();
- $detail = ReportWorkingDetail::whereIn('data_id', array_column($dispatch,'id'))
- ->where('del_time',0)
- ->select('report_working_id')
- ->get()->toArray();
- $result = ReportWorking::where('del_time',0)
- ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 5){
- $result = DispatchSub::where('del_time',0)
- ->where('order_product_id', $id)
- ->where('finished_num','>',0)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 6){
- $sale_orders_product_id = OrdersProduct::where('del_time',0)
- ->where('id', $id)
- ->pluck('sale_orders_product_id')
- ->toArray();
- $sale = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)->select('order_no','id')->get()->toArray();
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->select("id","order_no")
- ->get()->toArray();
- $result = array_merge($result, $tmp);
- }
- }elseif ($for_type == 7){
- $process = Process::where('del_time',0)
- ->where('is_need_remain',1)
- ->pluck('id')
- ->toArray();
- $result = ScrappCount::where('del_time',0)
- ->where('order_product_id', $id)
- ->whereIn('process_id', $process)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 8){
- $result = ScrappCount::where('del_time',0)
- ->where('order_product_id', $id)
- ->where('scrapp_num','>', 0)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 9){
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('order_product_id', $id)
- ->pluck('id')
- ->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_one)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 10){
- $dispatch_id = DispatchSub::where('del_time',0)
- ->where('order_product_id', $id)
- ->pluck('id')
- ->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_two)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 11){
- $sale = OrdersProduct::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_four)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 12){
- $sale = OrdersProduct::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_three)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 13){
- $s_id = ScrappCount::where('del_time', 0)
- ->where('order_product_id', $id)
- ->pluck('id')
- ->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $s_id)
- ->where('type', ApplyOrder::type_five)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 14){
- $sale = OrdersProduct::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_six)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }
- return $result;
- }
- private function typeThree($for_type, $id){
- $result = [];
- if($for_type == 1){
- $sale_orders_product_id = DispatchSub::where('del_time',0)
- ->where('id', $id)
- ->pluck('sale_orders_product_id')
- ->toArray();
- $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
- ->where('del_time',0)
- ->select('id','out_order_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 2){
- $order_product_id = DispatchSub::where('del_time',0)
- ->where('id', $id)
- ->pluck('order_product_id')
- ->toArray();
- $result = OrdersProduct::where('del_time',0)
- ->whereIn('id', $order_product_id)
- ->select('id', 'production_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 4){
- $dispatch = DispatchSub::where('del_time',0)
- ->where('id', $id)
- ->select('id')
- ->get()->toArray();
- $detail = ReportWorkingDetail::whereIn('data_id', array_column($dispatch,'id'))
- ->where('del_time',0)
- ->select('report_working_id')
- ->get()->toArray();
- $result = ReportWorking::where('del_time',0)
- ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 5){
- $result = DispatchSub::where('del_time',0)
- ->where('id', $id)
- ->where('finished_num','>',0)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 6){
- $sale_orders_product_id = DispatchSub::where('del_time',0)
- ->where('id', $id)
- ->pluck('sale_orders_product_id')
- ->toArray();
- $sale = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)->select('order_no','id')->get()->toArray();
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->select("id","order_no")
- ->get()->toArray();
- $result = array_merge($result, $tmp);
- }
- }elseif ($for_type == 7){
- $process = Process::where('del_time',0)
- ->where('is_need_remain',1)
- ->pluck('id')
- ->toArray();
- $result = ScrappCount::where('del_time',0)
- ->where('dispatch_sub_id', $id)
- ->whereIn('process_id', $process)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 8){
- $result = ScrappCount::where('del_time',0)
- ->where('dispatch_sub_id', $id)
- ->where('scrapp_num','>', 0)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 9){
- $dispatch = DispatchSub::where('id',$id)
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_one)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }
- }elseif ($for_type == 10){
- $dispatch = DispatchSub::where('id',$id)
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_two)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }
- }elseif ($for_type == 11){
- $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_four)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 12){
- $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_three)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 13){
- $dispatch = DispatchSub::where('id',$id)
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $s_id = ScrappCount::where('del_time', 0)
- ->whereIn('dispatch_sub_id', $dispatch_id)
- ->pluck('id')
- ->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $s_id)
- ->where('type', ApplyOrder::type_five)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }
- }elseif ($for_type == 14){
- $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_four)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }
- return $result;
- }
- private function typeFour($for_type, $id){
- $result = [];
- if($for_type == 1){
- $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time',0)
- ->pluck('data_id')
- ->toArray();
- $sale_orders_product_id = DispatchSub::where('del_time',0)
- ->whereIn('id', $dispatch_id)
- ->pluck('sale_orders_product_id')
- ->toArray();
- $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
- ->where('del_time',0)
- ->select('id','out_order_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 2){
- $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time',0)
- ->pluck('data_id')
- ->toArray();
- $order_product_id = DispatchSub::where('del_time',0)
- ->whereIn('id', $dispatch_id)
- ->pluck('order_product_id')
- ->toArray();
- $result = OrdersProduct::where('del_time',0)
- ->whereIn('id', $order_product_id)
- ->select('id', 'production_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 3){
- $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time',0)
- ->pluck('data_id')
- ->toArray();
- $result = DispatchSub::where('del_time',0)
- ->whereIn('id', $dispatch_id)
- ->select('id','dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 5){
- $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time',0)
- ->pluck('data_id')
- ->toArray();
- $result = DispatchSub::where('del_time',0)
- ->whereIn('id', $dispatch_id)
- ->where('finished_num','>',0)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 6){
- $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time',0)
- ->pluck('data_id')
- ->toArray();
- $sale_orders_product_id = DispatchSub::where('del_time',0)
- ->whereIn('id', $dispatch_id)
- ->pluck('sale_orders_product_id')
- ->toArray();
- $sale = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)->select('order_no','id')->get()->toArray();
- $return = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->select("id","order_no")
- ->get()->toArray();
- $return = array_merge($return, $tmp);
- }
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 7){
- $process = Process::where('del_time',0)
- ->where('is_need_remain',1)
- ->pluck('id')
- ->toArray();
- $result = ScrappCount::where('del_time',0)
- ->where('report_id', $id)
- ->whereIn('process_id',$process)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 8){
- $result = ScrappCount::where('del_time',0)
- ->where('report_id', $id)
- ->where('scrapp_num','>', 0)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 9){
- $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time',0)
- ->pluck('data_id')
- ->toArray();
- $dispatch_id = $dispatch_id[0] ?? 0;
- $dispatch = DispatchSub::where('id',$dispatch_id)
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_one)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }
- }elseif ($for_type == 10){
- $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time',0)
- ->pluck('data_id')
- ->toArray();
- $dispatch_id = $dispatch_id[0] ?? 0;
- $dispatch = DispatchSub::where('id',$dispatch_id)
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_two)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }
- }elseif ($for_type == 11){
- $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time',0)
- ->pluck('data_id')
- ->toArray();
- $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_four)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 12){
- $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time',0)
- ->pluck('data_id')
- ->toArray();
- $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no', 'sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_three)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 13){
- $s_id = ScrappCount::where('del_time', 0)
- ->where('report_id', $id)
- ->pluck('id')
- ->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $s_id)
- ->where('type', ApplyOrder::type_five)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 14){
- $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time',0)
- ->pluck('data_id')
- ->toArray();
- $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_six)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }
- return $result;
- }
- private function typeFive($for_type, $id){
- $result = [];
- if($for_type == 1){
- $sale_orders_product_id = DispatchSub::where('del_time',0)
- ->where('id', $id)
- ->pluck('sale_orders_product_id')
- ->toArray();
- $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
- ->where('del_time',0)
- ->select('id','out_order_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 2){
- $order_product_id = DispatchSub::where('del_time',0)
- ->where('id', $id)
- ->pluck('order_product_id')
- ->toArray();
- $result = OrdersProduct::where('del_time',0)
- ->whereIn('id', $order_product_id)
- ->select('id', 'production_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 3){
- $result = DispatchSub::where('del_time',0)
- ->where('id', $id)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 4){
- $dispatch = DispatchSub::where('del_time',0)
- ->where('id', $id)
- ->select('id')
- ->get()->toArray();
- $detail = ReportWorkingDetail::whereIn('data_id', array_column($dispatch,'id'))
- ->where('del_time',0)
- ->select('report_working_id')
- ->get()->toArray();
- $result = ReportWorking::where('del_time',0)
- ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 6){
- $box_id = BoxWithDispatch::where('del_time',0)
- ->where('dispatch_id', $id)
- ->pluck('box_id')
- ->toArray();
- $box_id = $box_id[0] ?? 0;
- $result = Box::where('del_time',0)
- ->where('id', $box_id)
- ->select("id","order_no")
- ->get()->toArray();
- }elseif ($for_type == 7){
- $process = Process::where('del_time',0)
- ->where('is_need_remain',1)
- ->pluck('id')
- ->toArray();
- $result = ScrappCount::where('del_time',0)
- ->where('dispatch_sub_id', $id)
- ->whereIn('process_id', $process)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 8){
- $result = ScrappCount::where('del_time',0)
- ->where('dispatch_sub_id', $id)
- ->where('scrapp_num','>', 0)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 9){
- $dispatch = DispatchSub::where('id',$id)
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_one)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }
- }elseif ($for_type == 10){
- $dispatch = DispatchSub::where('id',$id)
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_two)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }
- }elseif ($for_type == 11){
- $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_four)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 12){
- $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_three)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 13){
- $s_id = ScrappCount::where('del_time', 0)
- ->where('dispatch_sub_id', $id)
- ->pluck('id')
- ->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $s_id)
- ->where('type', ApplyOrder::type_five)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 14){
- $sale = DispatchSub::where('id', $id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_six)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }
- return $result;
- }
- private function typeSix($for_type, $id){
- $result = [];
- $box = Box::where('id', $id)->first();
- if(empty($box)) return $result;
- $top_order_no = $box->top_order_no;
- $order_no = $box->order_no;
- if($for_type == 1){
- $box_detail = new BoxDetail(['channel'=> $top_order_no]);
- $sale_orders_product_id = $box_detail->where('del_time',0)
- ->where('order_no',$order_no)
- ->pluck('top_id')
- ->toArray();
- $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
- ->where('del_time',0)
- ->select('id','out_order_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 2){
- $box_detail = new BoxDetail(['channel'=> $top_order_no]);
- $sale_orders_product_id = $box_detail->where('del_time',0)
- ->where('order_no',$order_no)
- ->pluck('top_id')
- ->toArray();
- $result = OrdersProduct::where('del_time',0)
- ->whereIn('sale_orders_product_id', $sale_orders_product_id)
- ->select('id', 'production_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 3){
- $dispatch_id = BoxWithDispatch::where('del_time',0)
- ->where('box_id', $id)
- ->pluck('dispatch_id')
- ->toArray();
- $result = DispatchSub::where('del_time',0)
- ->whereIn('id', $dispatch_id)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 4){
- $dispatch_id = BoxWithDispatch::where('del_time',0)
- ->where('box_id', $id)
- ->pluck('dispatch_id')
- ->toArray();
- $detail = ReportWorkingDetail::whereIn('data_id', $dispatch_id)
- ->where('del_time',0)
- ->select('report_working_id')
- ->get()->toArray();
- $return = ReportWorking::where('del_time',0)
- ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 5){
- $dispatch_id = BoxWithDispatch::where('del_time',0)
- ->where('box_id', $id)
- ->pluck('dispatch_id')
- ->toArray();
- $result = DispatchSub::where('del_time',0)
- ->whereIn('id', $dispatch_id)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 7){
- $process = Process::where('del_time',0)
- ->where('is_need_remain',1)
- ->pluck('id')
- ->toArray();
- $dispatch_id = BoxWithDispatch::where('del_time',0)
- ->where('box_id', $id)
- ->pluck('dispatch_id')
- ->toArray();
- $report_working_id = ReportWorkingDetail::whereIn('data_id', $dispatch_id)
- ->where('del_time',0)
- ->pluck('report_working_id')
- ->toArray();
- $return = ScrappCount::where('del_time',0)
- ->whereIn('report_id', $report_working_id)
- ->whereIn('process_id', $process)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 8){
- $dispatch_id = BoxWithDispatch::where('del_time',0)
- ->where('box_id', $id)
- ->pluck('dispatch_id')
- ->toArray();
- $report_working_id = ReportWorkingDetail::whereIn('data_id', $dispatch_id)
- ->where('del_time',0)
- ->pluck('report_working_id')
- ->toArray();
- $return = ScrappCount::where('del_time',0)
- ->whereIn('report_id', $report_working_id)
- ->where('scrapp_num','>', 0)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 9){
- $dispatch_id = BoxWithDispatch::where('del_time',0)
- ->where('box_id', $id)
- ->select('dispatch_id')
- ->first();
- if(! empty($dispatch_id)){
- $dispatch_id = $dispatch_id->toArray();
- $dispatch = DispatchSub::where('id',$dispatch_id['dispatch_id'])
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_one)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }
- }
- }elseif ($for_type == 10){
- $dispatch_id = BoxWithDispatch::where('del_time',0)
- ->where('box_id', $id)
- ->select('dispatch_id')
- ->first();
- if(! empty($dispatch_id)){
- $dispatch_id = $dispatch_id->toArray();
- $dispatch = DispatchSub::where('id',$dispatch_id['dispatch_id'])
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_two)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }
- }
- }elseif ($for_type == 11){
- $dispatch_id = BoxWithDispatch::where('del_time',0)
- ->where('box_id', $id)
- ->pluck('dispatch_id')
- ->toArray();
- $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_four)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 12){
- $dispatch_id = BoxWithDispatch::where('del_time',0)
- ->where('box_id', $id)
- ->pluck('dispatch_id')
- ->toArray();
- $sale = DispatchSub::where('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_three)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 13){
- $dispatch_id = BoxWithDispatch::where('del_time',0)
- ->where('box_id', $id)
- ->select('dispatch_id')
- ->first();
- if(! empty($dispatch_id)){
- $dispatch_id = $dispatch_id->toArray();
- $dispatch = DispatchSub::where('id',$dispatch_id['dispatch_id'])
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $s_id = ScrappCount::where('del_time', 0)
- ->whereIn('dispatch_sub_id', $dispatch_id)
- ->pluck('id')
- ->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $s_id)
- ->where('type', ApplyOrder::type_five)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }
- }
- }elseif ($for_type == 14){
- $dispatch_id = BoxWithDispatch::where('del_time',0)
- ->where('box_id', $id)
- ->pluck('dispatch_id')
- ->toArray();
- $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_six)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }
- return $result;
- }
- private function typeSeven($for_type, $id){
- $result = [];
- if($for_type == 1){
- $sale_orders_product_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('sale_orders_product_id')
- ->toArray();
- $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
- ->where('del_time',0)
- ->select('id','out_order_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 2){
- $order_product_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('order_product_id')
- ->toArray();
- $result = OrdersProduct::where('del_time',0)
- ->whereIn('id', $order_product_id)
- ->select('id', 'production_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 3){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $result = DispatchSub::where('del_time',0)
- ->where('id', $dispatch_id)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 4){
- $report_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('report_id')
- ->toArray();
- $result = ReportWorking::where('del_time',0)
- ->whereIn('id', $report_id)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 5){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $result = DispatchSub::where('del_time',0)
- ->where('id', $dispatch_id)
- ->where('finished_num','>',0)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 6){
- $sale_orders_product_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('sale_orders_product_id')
- ->toArray();
- $sale = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)->select('order_no','id')->get()->toArray();
- $return = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->select("id","order_no")
- ->get()->toArray();
- $return = array_merge($return, $tmp);
- }
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 8){
- $result = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->where('scrapp_num','>', 0)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 9){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $dispatch_id = $dispatch_id[0] ?? 0;
- $dispatch = DispatchSub::where('id',$dispatch_id)
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_one)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }
- }elseif ($for_type == 10){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $dispatch_id = $dispatch_id[0] ?? 0;
- $dispatch = DispatchSub::where('id',$dispatch_id)
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_two)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }
- }elseif ($for_type == 11){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_four)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 12){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_three)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 13){
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->where('data_id', $id)
- ->where('type', ApplyOrder::type_five)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 14){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_six)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }
- return $result;
- }
- private function typeEight($for_type, $id){
- $result = [];
- if($for_type == 1){
- $sale_orders_product_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('sale_orders_product_id')
- ->toArray();
- $result = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)
- ->where('del_time',0)
- ->select('id','out_order_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 2){
- $order_product_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('order_product_id')
- ->toArray();
- $result = OrdersProduct::where('del_time',0)
- ->whereIn('id', $order_product_id)
- ->select('id', 'production_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 3){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $result = DispatchSub::where('del_time',0)
- ->where('id', $dispatch_id)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 4){
- $report_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('report_id')
- ->toArray();
- $result = ReportWorking::where('del_time',0)
- ->whereIn('id', $report_id)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 5){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $result = DispatchSub::where('del_time',0)
- ->where('id', $dispatch_id)
- ->where('finished_num','>',0)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- }elseif ($for_type == 6){
- $sale_orders_product_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('sale_orders_product_id')
- ->toArray();
- $sale = SaleOrdersProduct::whereIn('id', $sale_orders_product_id)->select('order_no','id')->get()->toArray();
- $return = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->select("id","order_no")
- ->get()->toArray();
- $return = array_merge($return, $tmp);
- }
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 7){
- $process = Process::where('del_time',0)
- ->where('is_need_remain',1)
- ->pluck('id')
- ->toArray();
- $result = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->whereIn('process_id', $process)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 9){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $dispatch_id = $dispatch_id[0] ?? 0;
- $dispatch = DispatchSub::where('id',$dispatch_id)
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_one)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }
- }elseif ($for_type == 10){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $dispatch_id = $dispatch_id[0] ?? 0;
- $dispatch = DispatchSub::where('id',$dispatch_id)
- ->select('order_product_id','crt_time','product_no','technology_name')
- ->first();
- if(! empty($dispatch)){
- $dispatch = $dispatch->toArray();
- $dispatch_id = DispatchSub::where('order_product_id', $dispatch['order_product_id'])
- ->where('crt_time',$dispatch['crt_time'])
- ->where('product_no',$dispatch['product_no'])
- ->where('technology_name',$dispatch['technology_name'])
- ->pluck('id')->toArray();
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $dispatch_id)
- ->where('type', ApplyOrder::type_two)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }
- }elseif ($for_type == 11){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_four)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 12){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_three)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }elseif ($for_type == 13){
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->where('data_id', $id)
- ->where('type', ApplyOrder::type_five)
- ->pluck('apply_order_id')
- ->toArray();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 14){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $sale = DispatchSub::whereIn('id', $dispatch_id)->select('order_no','sale_orders_product_id as id')->get()->toArray();
- $box_id = [];
- foreach ($sale as $value){
- $box_detail = new BoxDetail(['channel'=> $value['order_no']]);
- $box_detail_order = $box_detail->where('top_id',$value['id'])->select('order_no')->get()->toArray();
- $tmp = Box::where('del_time',0)
- ->whereIn('order_no',array_unique(array_column($box_detail_order, 'order_no')))
- ->pluck("id")
- ->toArray();
- $box_id = array_merge($box_id, $tmp);
- }
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->whereIn('data_id', $box_id)
- ->where('type', ApplyOrder::type_six)
- ->pluck('apply_order_id')
- ->toArray();
- $return = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- $t = $return[0] ?? [];
- if(! empty($t)) $result[] = $t;
- }
- return $result;
- }
- private function typeNine($for_type, $id){
- $data_id = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_one)
- ->pluck('data_id')
- ->toArray();
- $result = DispatchSub::where('del_time',0)
- ->whereIn('id', $data_id)
- ->select('id', 'dispatch_no as order_no')
- ->get()->toArray();
- return $result;
- }
- private function typeTen($for_type, $id){
- $data_id = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_two)
- ->pluck('data_id')
- ->toArray();
- $detail = ReportWorkingDetail::whereIn('data_id', $data_id)
- ->where('del_time',0)
- ->select('report_working_id')
- ->get()->toArray();
- $return = ReportWorking::where('del_time',0)
- ->whereIn('id', array_unique(array_column($detail,'report_working_id')))
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- $result[] = $return[0];
- return $result;
- }
- private function typeEve($for_type, $id){
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_four)
- ->select('data_id as box_id')
- ->get()->toArray();
- $result = Box::where('del_time', 0)
- ->whereIn('id', array_unique(array_column($detail, 'box_id')))
- ->select("id", 'order_no')
- ->get()->toArray();
- return $result;
- }
- private function typeTwl($for_type, $id){
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_three)
- ->select('data_id as box_id')
- ->get()->toArray();
- $result = Box::where('del_time', 0)
- ->whereIn('id', array_unique(array_column($detail, 'box_id')))
- ->select("id", 'order_no')
- ->get()->toArray();
- return $result;
- }
- private function typeThi($for_type, $id){
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_five)
- ->select('data_id as zj_id')
- ->get()->toArray();
- $result = ScrappCount::where('del_time', 0)
- ->whereIn('id', array_unique(array_column($detail, 'zj_id')))
- ->select('id','order_number as order_no')
- ->get()->toArray();
- return $result;
- }
- private function typeFourTeen($for_type, $id){
- $detail = ApplyOrderDetail::where('del_time', 0)
- ->where('apply_order_id', $id)
- ->where('type', ApplyOrder::type_six)
- ->select('data_id as box_id')
- ->get()->toArray();
- $result = Box::where('del_time', 0)
- ->whereIn('id', array_unique(array_column($detail, 'box_id')))
- ->select("id", 'order_no')
- ->get()->toArray();
- return $result;
- }
- public function reportList($data){
- $model = ReportMessage::where('del_time',0)
- ->select('id','order_id','opt_case','quantity','crt_time','user_id','is_use','report_working_id')
- ->orderBy('id','desc');
- $list = $this->limit($model,'',$data);
- $list = $this->fillRData($list);
- $count = ReportMessage::where('del_time',0)
- ->where('is_use',0)
- ->count();
- return [true, ['list'=> $list, 'count' => $count]];
- }
- public function fillRData($data){
- if(empty($data['data'])) return $data;
- $dispatch = DispatchSub::whereIn('id',array_unique(array_column($data['data'],'order_id')))
- ->select('id','dispatch_no','process_id')
- ->get()->toArray();
- $process = Process::where('del_time',0)
- ->whereIn('id',array_unique(array_column($dispatch,'process_id')))
- ->get()->toArray();
- $process = array_column($process,null,'id');
- $map = [];
- foreach ($dispatch as $value){
- $map[$value['id']] = $value;
- }
- $emp_map = Employee::whereIn('id',array_unique(array_column($data['data'],'user_id')))
- ->pluck("emp_name",'id')
- ->toArray();
- $order_map = ReportWorking::whereIn('id',array_filter(array_column($data['data'],'report_working_id')))
- ->pluck('order_number','id')
- ->toArray();
- foreach ($data['data'] as $key => $value){
- $time = $value['crt_time'] ? date('Y-m-d',$value['crt_time']) : '';
- $data['data'][$key]['crt_time'] = $time;
- $t = $map[$value['order_id']] ?? [];
- $e = $emp_map[$value['user_id']] ?? "";
- $p = $process[$t['process_id']] ?? [];
- $p_t = $p['title'] ?? "";
- if($p['zj_type'] == 0){
- $p_t .= ":无需质检";
- }elseif($p['zj_type'] == 1){
- $p_t .= ":全检";
- }else{
- $p_t .= ":抽检";
- }
- if(empty($value['report_working_id'])){
- $str = "派工单:" . $t['dispatch_no'] . "于" . $time . "由($e)完成工序($p_t)报工,数量{$value['quantity']}吨,请及时处理";
- }else{
- $tmp = $order_map[$value['report_working_id']] ?? "";
- if(empty($tmp)){
- $str = "派工单:" . $t['dispatch_no'] . "于" . $time . "由($e)完成工序($p_t)报工,数量{$value['quantity']}吨,请及时处理";
- }else{
- $str = "派工单:" . $t['dispatch_no'] . "于" . $time . "由($e)完成工序($p_t)报工({$tmp}),数量{$value['quantity']}吨,请及时处理";
- }
- }
- $data['data'][$key]['message'] = $str;
- }
- return $data;
- }
- public function reportRemainUpdate($data){
- if(empty($data['id'])) return [false, 'ID不能为空'];
- if(empty($data['type'])) return [false, 'type不能为空'];
- $type = $data['type'];
- if($type == 1){
- ReportMessage::where('id', $data['id'])
- ->update(['is_use' => 1]);
- }else{
- ReportMessage::where('id', $data['id'])
- ->update(['del_time' => time()]);
- }
- return [true, ''];
- }
- public function filldatas(){
- $box = Box::where('del_time',0)
- ->where('crt_time','>=',1750727777)
- ->select("top_order_no", 'order_no','id')
- ->get()->toArray();
- $box_id = [];
- foreach ($box as $value) {
- $box_detail = new BoxDetail(['channel' => $value['top_order_no']]);
- $t = $box_detail->where('order_no', $value['order_no'])->where('del_time',0)->select('top_id as id')->first()->toArray();
- $box_id[$value['id']] = $t['id'];
- }
- $result = DispatchSub::where('del_time',0)
- ->whereIn('sale_orders_product_id', array_values($box_id))
- ->where('process_id',14)
- ->where('finished_num', '>', '0.000')
- ->select('id','dispatch_quantity','finished_num','order_product_id','sale_orders_product_id','technology_name')
- ->get()->toArray();
- $map = [];
- $return = [];
- foreach ($result as $key => $value){
- if($value['finished_num'] < 1){
- $new_key = $value['order_product_id'] . $value['sale_orders_product_id'] . $value['technology_name'];
- $tmp = bcsub(0.750,$value['finished_num'],3);
- $map[$new_key][] = $tmp;
- $return[] = $value;
- }
- }dump(count($return));
- $return2= [];
- foreach ($result as $key => $value){
- if($value['finished_num'] >= 1){
- $new_key = $value['order_product_id'] . $value['sale_orders_product_id'] . $value['technology_name'];
- if(isset($map[$new_key])){
- foreach ($map[$new_key] as $val){
- $return[] = [
- 'id' => $value['id'],
- 'dispatch_quantity' => $val,
- 'finished_num' => $val,
- 'order_product_id' => $value['order_product_id'],
- 'sale_orders_product_id' => $value['sale_orders_product_id'],
- 'technology_name' => $value['technology_name'],
- ];
- $value['finished_num'] = bcsub($value['finished_num'], $val,3);
- }
- }
- $return2[] = $value;
- }
- }
- dd($return2);
- }
- }
|