1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880 |
- <?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['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 = [];
- 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')
- ->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 ($detail['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 ($detail['type'] == ApplyOrder::type_three){
- $d = Box::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'order_no')
- ->get()->toArray();
- }elseif ($detail['type'] == ApplyOrder::type_four){
- $d = Box::where('del_time',0)
- ->whereIn('id', $apply_id)
- ->select('id', 'order_no')
- ->get()->toArray();
- }elseif ($detail['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();
- }
- $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(',', $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'] ?? "";
- }
- $return[] = [
- 'id' => $t['data_id'] ?? 0,
- 'quantity' => $t['quantity'] ?? 0,
- '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 = "包材、辅料仓" ;
- }
- 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){
- $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 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'],
- ]);
- }
- $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, 2);
- 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['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'] ?? "";
- }
- if($t['type'] == ApplyOrder::type_two || $t['type'] == ApplyOrder::type_three){
- $product_unit = "吨";
- }elseif($t['type'] == ApplyOrder::type_four){
- $product_unit = "只";
- }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' => $t['quantity'] ?? 0,
- '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();
- }
- 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($total < $tmp) 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) {
- } elseif ($type == 10) {
- } elseif ($type == 11) {
- } elseif ($type == 12) {
- } elseif ($type == 13) {
- }
- 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){
- $result = ScrappCount::where('del_time',0)
- ->where('sale_orders_product_id', $id)
- ->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();
- }
- 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')
- ->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')->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){
- $result = ScrappCount::where('del_time',0)
- ->where('order_product_id', $id)
- ->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();
- }
- 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')
- ->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')->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){
- $result = ScrappCount::where('del_time',0)
- ->where('dispatch_sub_id', $id)
- ->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){
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->where('data_id', $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){
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->where('data_id', $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){
- $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();
- }
- 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')
- ->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')->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){
- $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time',0)
- ->pluck('data_id')
- ->toArray();
- $result = ScrappCount::where('del_time',0)
- ->whereIn('dispatch_sub_id', $dispatch_id)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 8){
- $dispatch_id = ReportWorkingDetail::where('report_working_id', $id)
- ->where('del_time',0)
- ->pluck('data_id')
- ->toArray();
- $result = ScrappCount::where('del_time',0)
- ->whereIn('dispatch_sub_id', $dispatch_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();
- $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();
- $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){
- $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();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }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();
- $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('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();
- }
- 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')
- ->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){
- $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')->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){
- $result = ScrappCount::where('del_time',0)
- ->where('dispatch_sub_id', $id)
- ->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){
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->where('data_id', $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){
- $apply_order_id = ApplyOrderDetail::where('del_time', 0)
- ->where('data_id', $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){
- $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();
- }
- return $result;
- }
- private function typeSix($for_type, $id){
- $result = [];
- $box = Box::where('id', $id)->select('top_order_no')->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')
- ->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();
- $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){
- $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){
- $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();
- $result = ScrappCount::where('del_time',0)
- ->whereIn('report_id', $report_working_id)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }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();
- $result = ScrappCount::where('del_time',0)
- ->whereIn('report_id', $report_working_id)
- ->where('scrapp_num','>', 0)
- ->select('id', 'order_number as order_no')
- ->get()->toArray();
- }elseif ($for_type == 9){
- $dispatch_id = BoxWithDispatch::where('del_time',0)
- ->where('box_id', $id)
- ->pluck('dispatch_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)
- ->pluck('dispatch_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){
- $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();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }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();
- $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_id = BoxWithDispatch::where('del_time',0)
- ->where('box_id', $id)
- ->pluck('dispatch_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();
- }
- 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')
- ->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){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $detail = ReportWorkingDetail::whereIn('data_id', $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){
- $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')->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 == 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();
- $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();
- $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){
- $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();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }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();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }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();
- }
- 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')
- ->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){
- $dispatch_id = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->pluck('dispatch_sub_id')
- ->toArray();
- $detail = ReportWorkingDetail::whereIn('data_id', $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){
- $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')->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){
- $result = ScrappCount::where('del_time',0)
- ->where('id', $id)
- ->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();
- $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();
- $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){
- $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();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }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();
- $result = ApplyOrder::where('del_time', 0)
- ->whereIn('id', $apply_order_id)
- ->select('id','order_number as order_no')
- ->get()->toArray();
- }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();
- }
- 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')
- ->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')))
- ->pluck('title','id')
- ->toArray();
- $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();
- foreach ($data['data'] as $key => $value){
- $time = $value['crt_time'] ? date('Y-m-d H:i:s',$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']] ?? "";
- $data['data'][$key]['message'] = "派工单:" . $t['dispatch_no'] . "于" . $time . "由($e)完成工序($p)报工,请及时处理";
- }
- 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);
- }
- }
|