ApplyOrderService.php 206 KB

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