Sale.php 295 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664
  1. <?php
  2. namespace app\admin\controller;
  3. use app\abutment\model\SupplierRelationUser;
  4. use app\abutment\model\SupplierUser;
  5. use app\admin\model\CgdPrice;use app\admin\model\ConsultTemp;use app\admin\model\DataGroup as DataGroupModel;
  6. use app\admin\model\GoodLog;
  7. use app\admin\model\GoodPlatform;use app\admin\model\GoodStockInfo;
  8. use app\admin\model\GoodTax;use app\admin\model\OrderOutChild;use app\admin\model\OrderTax;use app\admin\model\ProcessOrder;
  9. use app\admin\model\SaleCgdPrice;use app\admin\model\SaleInfo;
  10. use app\bbc\model\BbcFill;use app\model\TaxCategory;use app\model\TaxRelation;use Exception;
  11. use think\App;
  12. use think\facade\Cache;
  13. use think\facade\Config;
  14. use think\facade\Db;
  15. use app\admin\model\ActionLog;
  16. use think\facade\Validate;
  17. //销售单
  18. class Sale extends Base
  19. {
  20. public $noble = [];
  21. public function __construct(App $app)
  22. {
  23. parent::__construct($app);
  24. $this->noble = \think\facade\Config::get("noble");
  25. }
  26. public function create()
  27. {
  28. $orderCode = makeNo("QR");
  29. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  30. if ($customer_code == "") {
  31. return error_show(1002, "客户customer_code不能为空");
  32. }
  33. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  34. $userCommon = \app\admin\common\User::getIns();
  35. $tmp = $userCommon->handle('getCodeAndName',['code'=>[$customer_code,$supplierNo]]);
  36. if(!isset($tmp['code']) || $tmp['code']!=0) return json_show($tmp['code'],$tmp['message'],$tmp['data']);
  37. if(!isset($tmp['data'][$customer_code])) return json_show(1004, "未找到客户数据");
  38. if(!isset($tmp['data'][$supplierNo])) return json_show(1004, '未找到平台供应商数据');
  39. $goodtype = isset($this->post['goodtype']) && $this->post['goodtype'] !== "" ? intval($this->post['goodtype']) : "1";
  40. $order_type = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type']) : "1";
  41. $sendtype = isset($this->post['sendtype']) && $this->post['sendtype'] !== "" ? intval($this->post['sendtype']) : "";
  42. if ($sendtype === '') {
  43. return error_show(1004, "参数sendtype不能为空");
  44. }
  45. $platform_id = isset($this->post['platform_id']) && $this->post['platform_id'] !== "" ? intval($this->post['platform_id']) : "";
  46. if ($platform_id == '') {
  47. return error_show(1004, "参数platform_id不能为空");
  48. }
  49. $platforminfo = Db::name("platform")->where(["id"=> $platform_id,"is_del"=>0])->findOrEmpty();
  50. if (empty($platforminfo)) return error_show(1004, "平台信息未找到");
  51. if ($platforminfo['status'] != 1) return error_show(1004, "平台信息已禁用");
  52. if($platforminfo['is_select_pay_rate']==1 && channel_is_company($platform_id,$supplierNo))return error_show(1004, "平台渠道包含当前业务公司 {$tmp['data'][$supplierNo]}");
  53. $platform_order = isset($this->post['platform_order']) && $this->post['platform_order'] !== "" ? trim($this->post['platform_order']) : "";
  54. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  55. if ($good_code == '') {
  56. return error_show(1004, "参数good_code不能为空");
  57. }
  58. $good_num = isset($this->post['good_num']) && $this->post['good_num'] !== "" ? intval($this->post['good_num']) : "";
  59. if ($good_num === '') {
  60. return error_show(1004, "参数good_num不能为空");
  61. }
  62. $arrtime = isset($this->post['arrtime']) && $this->post['arrtime'] != "" ? $this->post['arrtime'] : "";
  63. if ($arrtime == "") {
  64. return error_show(1004, "参数arrtime不能为空");
  65. }
  66. $manager = isset($this->post['manager']) && $this->post['manager'] != '' ? $this->post['manager'] :$this->uname;
  67. $managerid = isset($this->post['managerid']) && $this->post['managerid'] != '' ? $this->post['managerid'] :$this->uid;
  68. $paytime = isset($this->post['paytime']) && $this->post['paytime'] != "" ? $this->post['paytime'] : "";
  69. $workNo = isset($this->post['workNo']) && $this->post['workNo'] != "" ? trim($this->post['workNo']) : "";
  70. $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  71. ->where(['a.skuCode' => $good_code])->field("b.*,a.skuCode,a.platform_code,a.plat_code,a.is_fixed")
  72. ->findOrEmpty();
  73. if (empty($ct)) {
  74. return error_show(1002, "未找到商品数据");
  75. }
  76. $holder_id=0;
  77. $holder_name='';
  78. $supplier_name=$ct['supplierName'];
  79. if($ct['is_combind']==0){
  80. $supplier_temp =$userCommon->handle('sInfo',['code'=>$ct['supplierNo']]);
  81. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,'采购单供应商不存在');
  82. $holder_id=$supplier_temp['data']['personid']??0;
  83. $holder_name=$supplier_temp['data']['person']??'';
  84. $supplier_name=$supplier_temp['data']['name']??'';
  85. }
  86. $goodinfo = $ct;
  87. $is_stock = $ct['is_stock'];
  88. $spuCode = $ct['spuCode'];
  89. $skuCode = $ct['skuCode'];
  90. $is_activity = isset($this->post['is_activity']) && $this->post['is_activity'] !== "" ? $this->post['is_activity'] : "";
  91. $actcode = isset($this->post['act_code']) && $this->post['act_code'] !== "" ? trim($this->post['act_code']) : "";
  92. if ($order_type == 1) {
  93. if ($is_activity === "") {
  94. return error_show(1002, "参数is_activity不能为空");
  95. }
  96. if ($is_activity == 1 && $actcode == "") {
  97. return error_show(1002, "参数act_code不能为空");
  98. }
  99. }
  100. $origin = Db::name('good_nake')->where([['spuCode', '=', $spuCode], ['min_num', '<=', $good_num], ['is_del', '=', 0]])->order('min_num desc')->find();
  101. $origin_price = $origin['nake_total']??0;
  102. $cgd_origin_price = $origin['supplier_origin_price']??0;
  103. if ($goodinfo['is_stock'] == 1) {
  104. $stock_num = Db::name("good")->where(["spuCode"=> $spuCode])->value("usable_stock",0);
  105. if($stock_num < $good_num){
  106. return error_show(1003, "商品可用库存数量不足");
  107. }
  108. $origin_price = 0;
  109. }else{
  110. if ($origin == false) {
  111. return error_show(1003, '未找到相关阶梯成本价格');
  112. }
  113. }
  114. $sale_price = isset($this->post['good_price']) && $this->post['good_price'] !== "" ? floatval($this->post['good_price']) : '';
  115. $ct['cgd_gold_price'] = 0;
  116. if ($goodtype == 1) {
  117. if ($is_activity == 1) {
  118. $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b", "a.activity_code=b.activity_code")
  119. ->where(["a.skuCode" => $skuCode, "a.activity_code" => $actcode, "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])
  120. ->find();
  121. if ($act == false) {
  122. return error_show(1003, "未找到相关活动价");
  123. }
  124. if ($act['moq_num'] > $good_num) {
  125. return error_show(1003, "商品不满足活动价起订量{$act['moq_num']}");
  126. }
  127. if ($act['activity_stock'] < $good_num) {
  128. return error_show(1003, "商品活动库存剩余{$act['activity_stock']}");
  129. }
  130. $sale_price = $sale_price !== "" ? $sale_price : $act['activity_price'];
  131. $origin_price = $act['cost_price'];
  132. } else {
  133. $good = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->where([["min_num", "<=", $good_num]])->order("min_num desc")->find();
  134. if ($good == false) {
  135. return error_show(1003, "未找到相关阶梯价格");
  136. }
  137. $sale_price = $sale_price !== "" ? $sale_price : $good['sale_price'];
  138. if ($ct['is_gold_price'] == 1 && $is_stock != 1) {
  139. $gold = Db::name("gold_price1")
  140. ->field('id,price')
  141. ->where(["type" => $ct['noble_metal'], "is_del" => 0, "status" => 1])
  142. ->order("addtime desc")
  143. ->find();
  144. if($ct['is_fixed']==0) $origin['nake_fee']=0;
  145. //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
  146. $sale_price = $sale_price !== "" ? $sale_price : ($ct['demo_fee'] / $good_num + $ct['open_fee'] / $good_num
  147. + $ct['noble_weight'] * $gold["price"] + $good['cost_fee'] * $ct['noble_weight'] + $origin['package_fee'] + $origin['mark_fee'] + $origin['cert_fee'] + $origin['nake_fee'] + $origin['delivery_fee']);
  148. $ct['cgd_gold_price'] = $gold["price"];
  149. }
  150. }
  151. } else {
  152. $sale_price = 0;
  153. }
  154. $cgd = [
  155. "supplierNo" => $ct['supplierNo'],
  156. "supplierName" => $supplier_name,
  157. "companyNo" => $supplierNo,
  158. "companyName" => $tmp['data'][$supplierNo]??"",
  159. "orderCode" => $orderCode,
  160. "spuCode" => $ct['spuCode'],
  161. "skuCode" => $ct['skuCode'],
  162. "good_name" => $ct['good_name'],
  163. "sale_price" => $origin_price,
  164. "total_fee" => $origin_price * $good_num,
  165. "pakge_fee" => isset($origin['package_fee']) ? $origin['package_fee'] : 0,
  166. "cert_fee" => isset($origin['cert_fee']) ? $origin['cert_fee'] : 0,
  167. "open_fee" => $ct['open_fee'],
  168. "cost_fee" => isset($origin['cost_fee']) ? $origin['cost_fee'] : 0,
  169. "mark_fee" => isset($origin['mark_fee']) ? $origin['mark_fee'] : 0,
  170. "nake_fee" => isset($origin['nake_fee']) ? $origin['nake_fee'] : 0,
  171. "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
  172. "demo_fee" => $ct['demo_fee'],
  173. "good_num" => $good_num,
  174. "good_type" => $goodtype,
  175. "weight" => $ct['noble_weight'],
  176. "gold_price" => isset($ct['cgd_gold_price']) ? $ct['cgd_gold_price'] : 0,
  177. "order_type" => $is_stock == 1 ? 1 : 2,
  178. "order_source" => 1,//1直接下单
  179. "createrid" =>$holder_id,
  180. "creater" =>$holder_name,
  181. 'send_way' => 2,
  182. "open_type"=>$ct['open_type'],
  183. 'good_createrid' => $goodinfo['createrid'],
  184. 'good_creater' => $goodinfo['creater'],//商品创建人
  185. 'supplier_origin_price'=>$cgd_origin_price,//供应商采购成本
  186. 'cgd_supplier_code'=>$goodinfo['cgd_supplier_code'],//采购供应商编号
  187. 'cgd_supplier_name'=>$goodinfo['cgd_supplier_name'],//采购供应商编号
  188. 'cgd_apply_id'=>$goodinfo['cgd_apply_id'],//竞单人
  189. 'cgd_apply_name'=>$goodinfo['cgd_apply_name'],//竞单人
  190. ];
  191. $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !== "" ? $this->post['addrlist'] : "";
  192. $send_num = 0;
  193. if ($sendtype == 1) {
  194. if ($addrlist == "" || empty($addrlist) || !is_array($addrlist)) {
  195. return error_show(1004, "参数addrlist不能为空");
  196. }
  197. $send_num = array_sum(array_column($addrlist, "receipt_quantity"));
  198. }
  199. if ($send_num > $good_num) {
  200. return error_show(1004, "发货数量超出订单总数量");
  201. }
  202. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  203. $proof_id = isset($this->post['proof_id']) && $this->post['proof_id'] !== "" ? intval($this->post['proof_id']) : 0;
  204. $rm = $this->uid;
  205. $ri = $this->uname;
  206. Db::startTrans();
  207. try {
  208. $goodStock = Db::name("good")->where(["spuCode"=> $spuCode])->lock(true)->field("spuCode,usable_stock")
  209. ->findOrEmpty();
  210. if(empty($goodStock)) throw new Exception("未找到商品数据");
  211. $data = [
  212. "orderCode" => $orderCode,
  213. "good_code" => $spuCode,
  214. "skuCode" => $skuCode,
  215. "customer_code" => $customer_code,
  216. "customerName" =>$tmp['data'][$customer_code]??"",
  217. "good_name" => isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '' ? $goodinfo['good_name'] : '',
  218. "good_num" => $good_num,
  219. "cat_id" => $goodinfo['cat_id'],
  220. "apply_id" => $rm,
  221. "apply_name" => $ri,
  222. "origin_price" => $origin_price,
  223. "sale_price" => $sale_price,
  224. "post_fee" => 0,
  225. "status" => 0,
  226. "send_num" => 0,
  227. "wsend_num" => $good_num,
  228. "send_status" => 1,
  229. "good_type" => $goodtype,
  230. "send_type" => $sendtype,
  231. "supplierNo" => $supplierNo,
  232. "supplierName" => $tmp['data'][$supplierNo]??"",
  233. "supName" => $supplier_name,
  234. "supNo" => $ct['supplierNo'],
  235. "is_del" => 0,
  236. "zxNo" => "",
  237. "platform_order" => $platform_order,
  238. "platform_id" => $platform_id,
  239. "remark" => $remark,
  240. "is_stock" => $is_stock,
  241. "is_activity" => $is_activity === "" ? 0 : $is_activity,
  242. "activity_code" => $actcode,
  243. "order_type" => $is_stock == 1 ? 1 : 2,
  244. "order_source" => 1,//1直接下单
  245. 'good_weight' => $ct['noble_weight'],
  246. 'gold_price' => isset($ct['cgd_gold_price']) ? $ct['cgd_gold_price'] : 0,
  247. 'cost_price' => isset($good['cost_fee']) ? $good['cost_fee'] : 0,
  248. 'diff_weight' => 0,
  249. 'diff_fee' => 0,
  250. "workNo" => $workNo,
  251. 'open_type'=>$ct['open_type'],
  252. "addtime" => date("Y-m-d H:i:s"),
  253. "updatetime" => date("Y-m-d H:i:s"),
  254. 'total_price' => round($sale_price * $good_num, 2),
  255. 'proof_id' => $proof_id,
  256. 'cgderid' => $holder_id,
  257. 'cgder' => $holder_name,//采购员(供应商负责人)
  258. 'good_createrid' => $goodinfo['createrid'],
  259. 'good_creater' => $goodinfo['creater'],//商品创建人
  260. 'manager' => $manager,
  261. 'managerid' => $managerid,//商品创建人
  262. ];
  263. $paytime == "" ? "" : $data['paytime'] = $paytime;
  264. $datainfo = Db::name('sale')->insert($data, true);
  265. if ($datainfo > 0) {
  266. $taxInfo = OrderTax::SpuCat($spuCode);
  267. if (!empty($taxInfo)) {
  268. (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
  269. $temp=[];
  270. $temp['code']=$orderCode;
  271. $temp['spuCode']=$item['spuCode'];
  272. $temp['tax_code']=$item['cat_code'];
  273. $temp['tax_name']=$item['cat_name'];
  274. $temp['tax_short_name']=$item['short_name'];
  275. $temp['inv_tax']=$item['tax'];
  276. $temp['inv_good_name']=$item['inv_good_name'];
  277. return $temp;
  278. },$taxInfo));
  279. }
  280. //修改状态,添加待办
  281. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  282. "order_code" => $orderCode,//销售单code
  283. "status" => 0,//这里的status是之前的值
  284. "action_remark" => '',//备注
  285. "action_type" => "create"//新建create,编辑edit,更改状态status
  286. ], "XSQRD", 0, $this->post);
  287. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  288. "order_type" => 'XSQRD',
  289. "order_code" => $orderCode,//销售单code
  290. "order_id" => $datainfo,
  291. "order_status" => 0,
  292. "before_status" => 0,
  293. 'holder_id' => $data['apply_id']
  294. ]);
  295. if ($is_activity == 1) {
  296. $actup = [
  297. "activity_stock" => $act['activity_stock'] - $good_num,
  298. "updatetime" => date("Y-m-d H:i:s")
  299. ];
  300. $actupp = Db::name("activity_info")->where(["skuCode" => $skuCode, "activity_code" => $actcode,
  301. "is_del" => 0, "status" => 1])->save($actup);
  302. if ($actupp == false) {
  303. throw new Exception("活动库存修改失败");
  304. }
  305. }
  306. $outstatus = 0;
  307. $standing_book_da = ['sale_id' => $datainfo, 'customer_code' => $customer_code, 'skuCode' => $skuCode, 'updatetime' => date('Y-m-d H:i:s')];
  308. if ($is_stock == 0) {
  309. $bol = $this->createCgd($cgd, $standing_book_da);
  310. if ($bol == false) {
  311. throw new Exception("订单创建失败");
  312. }
  313. } else {
  314. $outstatus = 1;
  315. $stockUp =[
  316. "usable_stock"=>$goodStock['usable_stock']-$good_num,
  317. "updatetime"=>date("Y-m-d H:i:s"),
  318. ];
  319. $goodStockUp = Db::name("good")->where($goodStock)->update($stockUp);
  320. if($goodStockUp==false) throw new Exception("商品可用库存更新失败");
  321. SaleCgdPrice::GetPrice($datainfo);
  322. }
  323. if ($sendtype == 1) {
  324. $i=1;
  325. foreach ($addrlist as $value) {
  326. $temp = [];
  327. $addrs = [];
  328. if ($value['addr_code'] !== '' && is_array($value['addr_code']) && !empty($value['addr_code'])) {
  329. $addrs['provice_code'] = $value['addr_code'][0];
  330. $addrs['city_code'] = $value['addr_code'][1];
  331. $addrs['area_code'] = $value['addr_code'][2];
  332. $addr = json_encode($addrs);
  333. } else {
  334. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  335. }
  336. if($value['receipt_quantity']<=0) throw new Exception('地址发货数量不能小于1');
  337. $temp['orderCode'] = $orderCode;
  338. $temp['contactor'] = $value['contactor'];
  339. $temp['mobile'] = $value['mobile'];
  340. $temp['addr'] = $value['addr'];
  341. $temp['addr_code'] = $addr;
  342. $temp['customer_code'] = $customer_code;
  343. $temp['receipt_quantity'] = $value['receipt_quantity'];
  344. $temp['post_fee'] = 0;
  345. $temp['is_del'] = 0;
  346. $temp['addtime'] = date("Y-m-d H:i:s");
  347. $temp['updatetime'] = date("Y-m-d H:i:s");
  348. $temp['arrive_time'] = $arrtime;
  349. $vmp = Db::name('order_addr')->insert($temp, true);
  350. if ($vmp > 0) {
  351. $num = $value['receipt_quantity'];
  352. $outCode = makeNo("DF");
  353. //改变编码规则,将原来的outCode后两位换成序列号
  354. //str_pad字符串填充
  355. $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  356. $i++;
  357. if($is_stock!=1) {
  358. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  359. ->lock(true)->find();
  360. if ($order == false) {
  361. throw new Exception("未找到可以发货得采购单数据");
  362. }
  363. $tep = [
  364. "cgdNo" => $order['cgdNo'],
  365. "outCode" => $outCode,
  366. "send_num" => $num,
  367. "status" => 1,
  368. "addtime" => date("Y-m-d H:i:s"),
  369. "updatetime" => date("Y-m-d H:i:s")
  370. ];
  371. $sen = Db::name("order_send")->save($tep);
  372. if ($sen == false) {
  373. throw new Exception("发货地址添加创建失败");
  374. }
  375. $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
  376. if ($cgdinfo == false) {
  377. throw new Exception("未匹配到采购数据");
  378. }
  379. }
  380. $out = [
  381. "orderCode" => $orderCode,
  382. "outCode" => $outCode,
  383. "apply_id" => $rm,
  384. "apply_name" => $ri,
  385. "addrid" => $vmp,
  386. "post_name" => "",
  387. "post_code" => "",
  388. "post_fee" => 0,
  389. "sendtime" => date("Y-m-d H:i:s"),
  390. "send_num" => $num,
  391. "check_num" => 0,
  392. "error_num" => 0,
  393. "wsm_code" => $is_stock == 1 ?'':$cgdinfo['wsm_code'],
  394. "order_type" => $is_stock == 1 ? 1 : 2,
  395. "send_status" => $outstatus,
  396. "status" => $outstatus,
  397. "addtime" => date("Y-m-d H:i:s"),
  398. "updatetime" => date("Y-m-d H:i:s")
  399. ];
  400. $ou = Db::name("order_out")->insertGetId($out);
  401. if ($ou == false) {
  402. throw new Exception("发货地址添加创建失败");
  403. // return error_show(1002, "发货地址添加创建失败");
  404. } else {
  405. if($is_stock==1) OrderOutChild::makeChild($outCode);//库存品拆单
  406. //修改状态,添加待办
  407. ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
  408. "order_code" => $outCode,//出库单号
  409. "status" => $out['status'],//这里的status是之前的值
  410. "action_remark" => '',//备注
  411. "action_type" => "create"//新建create,编辑edit,更改状态status
  412. ], "CKD", $out['status'], $out);
  413. if($out['status']==1 ){
  414. //节点1待库管发货
  415. if($data['is_stock']==0){
  416. //非库存品,推给供应商负责人
  417. // $supp = Db::name('supplier')
  418. // ->field('person,personid')
  419. // ->where('code',$ct['supplierNo'])
  420. // ->findOrEmpty();
  421. ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], [
  422. "order_type" => 'CKD',
  423. "order_code" => $outCode,//出库单号
  424. "order_id" => $ou,
  425. "order_status" => $out['status'],
  426. "before_status" => $out['status'],
  427. 'wait_id'=>$holder_id,
  428. 'wait_name'=>$holder_name,
  429. ]);
  430. }else{
  431. //库存品,推给31库管和41库管-张凯旋
  432. $uids = Db::name('user_role')
  433. ->where(['is_del' => 0, 'roleid' => config('app.wsm_cgder_role'), 'status' => 1])
  434. ->column('uid');
  435. ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], [
  436. "order_type" => 'CKD',
  437. "order_code" => $outCode,//出库单号
  438. "order_id" => $ou,
  439. "order_status" => $out['status'],
  440. "before_status" => $out['status'],
  441. 'handle_user_list' => implode(',', $uids),
  442. ]);
  443. }
  444. }else{
  445. ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], [
  446. "order_type" => 'CKD',
  447. "order_code" => $outCode,//出库单号
  448. "order_id" => $ou,
  449. "order_status" => $out['status'],
  450. "before_status" => $out['status'],
  451. 'holder_id'=>$out['apply_id'],
  452. ]);
  453. }
  454. // $standing_book_da['outCode'] = $outCode;
  455. if (isset($standing_book_da['outCode'])) $standing_book_da['outCode'][] = $outCode;
  456. else $standing_book_da['outCode'] = [$outCode];
  457. }
  458. }
  459. else {
  460. throw new Exception("发货地址添加创建失败");
  461. // return error_show(1002, "发货地址添加创建失败");
  462. }
  463. }
  464. }
  465. //处理台账
  466. if (isset($standing_book_da['outCode'])) $standing_book_da['outCode'] = implode(',', $standing_book_da['outCode']);//发货单号拼接
  467. Db::name('standing_book')->insert(array_merge($standing_book_da, ['addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo('IO')]));
  468. Db::commit();
  469. return app_show(0, "订单创建成功", ["order_code" => $orderCode]);
  470. }else{
  471. throw new Exception("订单创建失败");
  472. }
  473. } catch (\Exception $e) {
  474. Db::rollback();
  475. return error_show(1005, $e->getMessage());
  476. }
  477. }
  478. //采购单
  479. public function createCgd($data, array &$standing_book_da = [])
  480. {
  481. $cgdCode = makeNo("CG");
  482. $wsm = Db::name("warehouse_info")->where(["supplierNo" => $data["supplierNo"], "companyNo" => $data['companyNo'], "wsm_type" => 2, "is_del" => 0])->find();
  483. if ($wsm == false) {
  484. $wsm_code = makeNo("WSM");
  485. $inwsm = [
  486. "wsm_code" => $wsm_code,
  487. "name" => $data['supplierName'],
  488. "wsm_type" => 2,
  489. "supplierNo" => $data['supplierNo'],
  490. "supplierName" => $data['supplierName'],
  491. "addr" => "",
  492. "addrs_code" => "",
  493. "contactor" => $data['createrid'] ,
  494. "contactor_name" => $data['creater'] ,
  495. "mobile" => "",
  496. "position" => "",
  497. "companyNo" => $data['companyNo'],
  498. "companyName" => $data['companyName'],
  499. "status" => 1,
  500. "is_del" => 0,
  501. "addtime" => date("Y-m-d H:i:s"),
  502. "updatetime" => date("Y-m-d H:i:s"),
  503. 'createrid' => $this->uid,
  504. 'creater' => $this->uname,
  505. 'updaterid' => $this->uid,
  506. 'updater' => $this->uname,
  507. ];
  508. $in = Db::name("warehouse_info")->insert($inwsm);
  509. if ($in == false) {
  510. throw new Exception("虚拟供应商仓库创建失败");
  511. }
  512. } else {
  513. $wsm_code = $wsm['wsm_code'];
  514. }
  515. //判断该供应商是否开通了供应商账号
  516. $from_tag=checkHasAccountBySupplierNos([$data['supplierNo']]);
  517. $cg = [
  518. "cgdNo" => $cgdCode,
  519. "bkcode" => "",
  520. "wsm_code" => $wsm_code,
  521. "cgder" => $data['creater'],
  522. "cgder_id" => $data['createrid'],
  523. "spuCode" => $data['spuCode'],
  524. "skuCode" => $data['skuCode'],
  525. "good_name" => $data['good_name'],
  526. "good_num" => $data['good_num'],
  527. "good_price" => $data['sale_price'],
  528. "total_fee" => round($data['sale_price'] * $data['good_num'], 2),
  529. "origin_total" => round($data['sale_price'] * $data['good_num'], 2),
  530. "pakge_fee" => $data['pakge_fee'],
  531. "cert_fee" => $data['cert_fee'],
  532. "open_fee" => $data['open_fee'],
  533. "teach_fee" => $data['cost_fee'],
  534. "mark_fee" => $data['mark_fee'],
  535. "demo_fee" => $data['demo_fee'],
  536. "nake_fee" => $data['nake_fee'],
  537. "weight" => $data['weight'],
  538. "delivery_fee" => $data['delivery_fee'],
  539. "gold_price" => $data['gold_price'],
  540. "diff_weight" => "0",
  541. "diff_fee" => "0",
  542. "supplierNo" => $data['supplierNo'],
  543. "supplier_name" => $data['supplierName'],
  544. "companyNo" => $data['companyNo'],
  545. "companyName" => $data['companyName'],
  546. "send_status" => 1,
  547. "send_num" => 0,
  548. "wsend_num" => $data['good_num'],
  549. "remark" => "",
  550. "status" => 0,//0初始化
  551. "lasttime" => date("Y-m-d H:i:s"),
  552. "is_del" => 0,
  553. 'open_type'=>$data['open_type'],
  554. "order_type" => $data['order_type'],
  555. "order_source" => $data['order_source'],
  556. "good_type" => $data['good_type'],
  557. "addtime" => date("Y-m-d H:i:s"),
  558. "updatetime" => date("Y-m-d H:i:s"),
  559. 'good_createrid' => $data['good_createrid'],
  560. 'good_creater' => $data['good_creater'],//商品创建人
  561. 'from_tag' => isset($from_tag[$data['supplierNo']]) ? 2 : 1,//来源标签:1采销(默认),2供应商端
  562. 'supplier_origin_price'=>$data['supplier_origin_price'],//供应商采购成本
  563. 'cgd_supplier_code'=>$data['cgd_supplier_code'],//采购供应商编号
  564. 'cgd_supplier_name'=>$data['cgd_supplier_name'],//采购供应商编号
  565. 'cgd_apply_id'=>$data['cgd_apply_id'],//竞单人
  566. 'cgd_apply_name'=>$data['cgd_apply_name'],//竞单人
  567. ];
  568. $up = Db::name("purchease_order")->insert($cg, true);
  569. if ($up) {
  570. $taxInfo = OrderTax::SpuCat($data['spuCode'],1,1);
  571. if (!empty($taxInfo)) {
  572. (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($cgdCode){
  573. $temp=[];
  574. $temp['code']=$cgdCode;
  575. $temp['spuCode']=$item['spuCode'];
  576. $temp['tax_code']=$item['cat_code'];
  577. $temp['tax_name']=$item['cat_name'];
  578. $temp['tax_short_name']=$item['short_name'];
  579. $temp['inv_tax']=$item['tax'];
  580. $temp['inv_good_name']=$item['inv_good_name'];
  581. return $temp;
  582. },$taxInfo));
  583. }
  584. //修改状态,添加待办
  585. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  586. "order_code" => $cg['cgdNo'],//销售单code
  587. "status" => 0,//这里的status是之前的值
  588. "action_remark" => '',//备注
  589. "action_type" => "create"//新建create,编辑edit,更改状态status
  590. ], "CGD", $cg['status'], $cg);
  591. //当节点是0待与供应商确认,推给供应商负责人
  592. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  593. "order_type" => 'CGD',
  594. "order_code" => $cg['cgdNo'],//销售单code
  595. "order_id" => $up,
  596. "order_status" => $cg['status'],
  597. "before_status" => 0,
  598. 'holder_id' => $data['createrid'],
  599. 'wait_id'=>$data['createrid'],
  600. 'wait_name'=>$data['creater'],
  601. ]);
  602. $standing_book_da = array_merge($standing_book_da, [
  603. 'orderCode' => $data['orderCode'],
  604. 'cgdNo' => $cgdCode,
  605. 'spuCode' => $data['spuCode'],
  606. 'skuCode' => $data['skuCode'],
  607. 'order_type' => $data['order_type'],
  608. 'order_source' => $data['order_source'],
  609. 'supplierNo' => $data['supplierNo'],
  610. "companyNo" => $data['companyNo'],
  611. ]);
  612. $rela = [
  613. "orderCode" => $data['orderCode'],
  614. "cgdNo" => $cgdCode,
  615. "spuCode" => $data['spuCode'],
  616. "good_num" => $data['good_num'],
  617. "wsend_num" => $data['good_num'],
  618. "send_num" => 0,
  619. "wait_num" => 0,
  620. "status" => 1,
  621. "source" => 2
  622. ];
  623. $re = Db::name("order_num")->save($rela);
  624. if ($re == false) {
  625. throw new Exception("采购单销售单关联失败");
  626. } else {
  627. $stokc = Db::name("good_stock")->where(['spuCode' => $data['spuCode'], "wsm_code" => $wsm_code, "is_del" => 0])->find();
  628. if ($stokc == false) {
  629. $stokc = [
  630. "spuCode" => $data['spuCode'],
  631. "wsm_code" => $wsm_code,
  632. "wait_in_stock" => $data['good_num'],
  633. "wait_out_stock" => 0,
  634. "usable_stock" => 0,
  635. "intra_stock" => 0,
  636. "total_stock" => 0,
  637. "status" => 1,
  638. "addtime" => date("Y-m-d H:i:s"),
  639. "updatetime" => date("Y-m-d H:i:s")
  640. ];
  641. } else {
  642. $stokc['wait_in_stock'] += $data['good_num'];
  643. $stokc['updatetime'] = date("Y-m-d H:i:s");
  644. }
  645. $stoc = Db::name("good_stock")->save($stokc);
  646. if ($stoc == false) {
  647. throw new Exception("商品待入库存更新失败");
  648. }
  649. $good_data[] = ['good_log_code' => $cgdCode, "stock_id" => isset($stoc['id']) ? $stoc['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1,
  650. 'stock' => $data['good_num'], "stock_name" => "wait_in_stock"];
  651. GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname], $good_data, "CGD");
  652. return true;
  653. }
  654. } else {
  655. throw new Exception("采购单生成失败");
  656. }
  657. }
  658. public function addAddr()
  659. {
  660. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
  661. $etid = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->find();
  662. if (empty($etid)) {
  663. return error_show(1002, "未找到数据");
  664. }
  665. $retrun = Db::name("sale_return")->where([["orderCode", "=", $orderCode], ["is_del", "=", 0], ["status", "in", [1, 2, 3,
  666. 7, 9,8, 10, 11, 12]]])->count('id');
  667. if ($retrun > 0) {
  668. return error_show(1005, "存在未完成退货订单数据");
  669. }
  670. $arrtime = isset($this->post['arrtime']) && $this->post['arrtime'] != "" ? $this->post['arrtime'] : "";
  671. $rm = $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  672. $ri = $this->uname;//isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  673. $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !== "" ? $this->post['addrlist'] : "";
  674. if ($addrlist == "" || empty($addrlist) || !is_array($addrlist)) {
  675. return error_show(1004, "参数addrlist不能为空");
  676. }
  677. // $userCommon = \app\admin\common\User::getIns();
  678. Db::startTrans();
  679. try {
  680. // $GoodModel = Db::name("good");
  681. // if (in_array($etid['order_type'], [3, 4])) {
  682. // $GoodModel = Db::name("good_zixun");
  683. // }
  684. // $goodStock=$GoodModel->where(["spuCode"=>$etid['good_code']])->lock(true)->findOrEmpty();
  685. $i = 1;
  686. // $goodStock_num =$goodStock['usable_stock']??0;
  687. $total_num = array_sum(array_column($addrlist, "receipt_quantity"));
  688. $goodStock_num = Db::name('good_stock')->alias("a")
  689. ->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")
  690. ->where(['a.is_del' => 0, 'a.spuCode' =>$etid['good_code'],"b.wsm_type"=>[2,5]])->sum('usable_stock');
  691. if ($goodStock_num < $total_num && $etid['is_stock'] == 1) throw new Exception("库存品库存数不足发货");
  692. foreach ($addrlist as $value) {
  693. $temp = [];
  694. $addrs = [];
  695. if ($value['addr_code'] !== '' && is_array($value['addr_code']) && !empty($value['addr_code'])) {
  696. $addrs['provice_code'] = $value['addr_code'][0];
  697. $addrs['city_code'] = $value['addr_code'][1];
  698. $addrs['area_code'] = $value['addr_code'][2];
  699. $addr = json_encode($addrs);
  700. } else {
  701. $addr = isset($value['addr_code']) && $value['addr_code'] !== '' ? $value['addr_code'] : '';
  702. }
  703. if($value['receipt_quantity']<=0) throw new Exception('地址发货数量不能小于1');
  704. $temp['orderCode'] = $orderCode;
  705. $temp['contactor'] = $value['contactor'];
  706. $temp['mobile'] = $value['mobile'];
  707. $temp['addr'] = $value['addr'];
  708. $temp['addr_code'] = $addr;
  709. $temp['customer_code'] = $etid['customer_code'];
  710. $temp['receipt_quantity'] = $value['receipt_quantity'];
  711. $temp['post_fee'] = 0;
  712. $temp['is_del'] = 0;
  713. $temp['addtime'] = date("Y-m-d H:i:s");
  714. $temp['updatetime'] = date("Y-m-d H:i:s");
  715. if ($arrtime != "") {
  716. $temp['arrive_time'] = $arrtime;
  717. }
  718. $vmp = Db::name('order_addr')->insert($temp, true);
  719. if ($vmp > 0) {
  720. $num = $value['receipt_quantity'];
  721. $outCode = makeNo("DF");
  722. //改变编码规则,将原来的outCode后两位换成序列号
  723. //str_pad字符串填充
  724. $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  725. $i++;
  726. //维护商品所在仓库的库存 --- start
  727. if ($etid['is_stock'] != 1) {
  728. //查找关联采购单
  729. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->findOrEmpty();
  730. if (empty($order)) {
  731. throw new Exception("未找到可以发货得采购单数据");
  732. }
  733. $tep = [
  734. "cgdNo" => $order['cgdNo'],
  735. "outCode" => $outCode,
  736. "send_num" => $num,
  737. "status" => 1,
  738. "addtime" => date("Y-m-d H:i:s"),
  739. "updatetime" => date("Y-m-d H:i:s")
  740. ];
  741. $sen = Db::name("order_send")->save($tep);
  742. if ($sen == false) {
  743. throw new Exception("发货地址添加创建失败");
  744. }
  745. $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
  746. if ($cgdinfo == false) {
  747. throw new Exception("采购单数据不存在");
  748. }
  749. if ($goodStock_num == 0) {
  750. $status = 0;
  751. } else {
  752. if (($goodStock_num - $num) < 0) throw new Exception("非库存品可用库存不足");
  753. $goodStock_num -= $num;
  754. $status = 1;
  755. }
  756. } else {
  757. if ($goodStock_num == 0 || ($goodStock_num - $num) < 0) throw new Exception("库存品可用库存不足");
  758. $goodStock_num -= $num;
  759. $status = 1;
  760. }
  761. $out = [
  762. "orderCode" => $orderCode,
  763. "outCode" => $outCode,
  764. "apply_id" => $rm,
  765. "apply_name" => $ri,
  766. "addrid" => $vmp,
  767. "post_name" => "",
  768. "post_code" => "",
  769. "post_fee" => 0,
  770. "sendtime" => date("Y-m-d H:i:s"),
  771. "send_num" => $num,
  772. "check_num" => 0,
  773. "error_num" => 0,
  774. "wsm_code" => $cgdinfo['wsm_code'] ?? '',
  775. "order_type" => $etid['order_type'],
  776. "send_status" => $status,
  777. "status" => $status,
  778. "addtime" => date("Y-m-d H:i:s"),
  779. "updatetime" => date("Y-m-d H:i:s")
  780. ];
  781. $ou = Db::name("order_out")->insertGetId($out);
  782. if ($ou == false) throw new Exception("发货单创建失败");
  783. else {
  784. if ($out['send_status'] == 1) OrderOutChild::makeChild($outCode);
  785. //修改状态,添加待办
  786. // ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
  787. // "order_code" => $outCode,//出库单号
  788. // "status" => 0,//这里的status是之前的值
  789. // "action_remark" => '',//备注
  790. // "action_type" => "create"//新建create,编辑edit,更改状态status
  791. // ], "CKD", 0, $out);
  792. //区分是否是库存品订单
  793. $process = [];
  794. // if($status == 1){
  795. // //库存品,推给库管和库管-张凯旋
  796. // if($etid['is_stock']==1){
  797. // $roleid = config('app.wsm_cgder_role');
  798. // $uids = Db::name('user_role')
  799. // ->where('is_del', 0)
  800. // ->whereIn('roleid', $roleid)
  801. // ->column('uid');
  802. // $process=[
  803. // "order_type" => 'CKD',
  804. // "order_code" => $outCode,//出库单号
  805. // "order_id" => $ou,
  806. // "order_status" => $status,
  807. // "before_status" => 0,
  808. //// 'holder_id'=>$out['apply_id'],
  809. // 'handle_user_list' => implode(',', $uids)
  810. // ];
  811. // }else{
  812. // //推给供应商负责人
  813. //// $supplier = Db::name('supplier')
  814. //// ->field('person,personid')
  815. //// ->where('code',$cgdinfo['supplierNo'])
  816. //// ->findOrEmpty();
  817. //
  818. // $supplier_temp =$userCommon->handle("sInfo",["code"=>$cgdinfo['supplierNo']]);
  819. // if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"采购单供应商不存在");
  820. // $holder_id=$supplier_temp['data']['personid']??0;
  821. // $holder_name=$supplier_temp['data']['person']??'';
  822. // $supplier_name=$supplier_temp['data']['name']??'';
  823. // $process = [
  824. // "order_type" => 'CKD',
  825. // "order_code" => $outCode,//出库单号
  826. // "order_id" => $ou,
  827. // "order_status" => $status,
  828. // "before_status" => 0,
  829. // 'wait_id'=>$holder_id,
  830. // 'wait_name'=>$holder_name,
  831. // 'holder_id'=>$holder_id,
  832. // ];
  833. // }
  834. // }
  835. // if(empty($process)) $process=[
  836. // "order_type" => 'CKD',
  837. // "order_code" => $outCode,//出库单号
  838. // "order_id" => $ou,
  839. // "order_status" => $status,
  840. // "before_status" => 0,
  841. // 'holder_id'=>$out['apply_id'],
  842. // ];
  843. //
  844. // ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri],$process);
  845. //处理台账-既然是根据orderCode更新的数据,那么肯定是有数据的,只需要更新就行了
  846. Db::execute("UPDATE `wsm_standing_book` SET `outCode`=CONCAT(IFNULL(`outCode`,''),',{$outCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `orderCode`='{$orderCode}'");
  847. }
  848. //维护商品所在仓库的库存 --- end
  849. } else {
  850. Db::rollback();
  851. return error_show(1002, "发货地址添加创建失败");
  852. }
  853. }
  854. // $usable = $GoodModel->where($goodStock)->update(["usable_stock"=>$goodStock_num,"updatetime"=>date("Y-m-d H:i:s")]);
  855. // if($usable==false) throw new Exception("商品可用库存数更新失败");
  856. Db::commit();
  857. return app_show(0, "发货地址添加完成");
  858. } catch (\Exception $e) {
  859. Db::rollback();
  860. return error_show(1002, $e->getMessage());
  861. }
  862. }
  863. public function consultOrder()
  864. {
  865. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] != "" ? trim($this->post['bidNo']) : "";
  866. if ($bidNo == "") {
  867. return error_show(1003, "参数bidNo不能为空");
  868. }
  869. $zxinfo = Db::name("consult_bids")->where(["bidNo" => $bidNo, "is_del" => 0])->find();
  870. if ($zxinfo == false) {
  871. return error_show(1003, "未找到咨询单商品信息");
  872. }
  873. $bargaininfo =Db::name("bargain_order")->where(["bidsNo" => $bidNo,"is_del"=>0,"status"=>0])->findOrEmpty();
  874. $zx = Db::name("consult_info")->where(["infoNo" => $zxinfo['infoNo'], "is_del" => 0])->find();
  875. if ($zx == false) {
  876. return error_show(1003, "未找到咨询单信息");
  877. }
  878. $manager = isset($this->post['manager']) && $this->post['manager'] != '' ? $this->post['manager'] :$this->uname;
  879. $managerid = isset($this->post['managerid']) && $this->post['managerid'] != '' ? $this->post['managerid'] :$this->uid;
  880. $zxorder = Db::name("consult_order")->where(["zxNo" => $zx["zxNo"], "is_del" => 0])->find();
  881. if ($zxorder == false) {
  882. return error_show(1003, "未找到咨询单信息");
  883. }
  884. $good_num = isset($this->post['good_num']) && $this->post['good_num'] != "" ? intval($this->post['good_num']) : "";
  885. if ($good_num === "") {
  886. return error_show(1003, "参数 good_num 不能为空");
  887. }
  888. $sale_price = isset($this->post['sale_price']) && $this->post['sale_price'] != "" ? floatval($this->post['sale_price']) : "";
  889. if ($sale_price === "") {
  890. return error_show(1003, "参数 sale_price 销售单价 不能为空");
  891. }
  892. if ($sale_price < $zxinfo['sale_price']) {
  893. return error_show(1003, "修改的销售单价不能低于原来的销售单价");
  894. }
  895. $goodtype = isset($this->post['goodtype']) && $this->post['goodtype'] !== '' ? intval($this->post['goodtype']) : '1';
  896. $sendtype = isset($this->post['sendtype']) && $this->post['sendtype'] != "" ? intval($this->post['sendtype']) : "";
  897. if ($sendtype == "") {
  898. return error_show(1003, "参数sendtype不能为空");
  899. }
  900. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] != "" ? trim($this->post['companyNo']) : "";
  901. if ($companyNo == "") {
  902. return error_show(1003, "参数 companyNo 不能为空");
  903. }
  904. $userCommon = \app\admin\common\User::getIns();
  905. // }
  906. $remark = isset($this->post['remark']) && $this->post['remark'] != "" ? trim($this->post['remark']) : "";
  907. $tmp = $userCommon->handle('sInfo',['code'=>$zxinfo['supplierNo']]);
  908. if(!isset($tmp['code']) || $tmp['code']!=0) return json_show($tmp['code'],$tmp['message'],$tmp['data']);
  909. $companyinfo = $userCommon->handle('getCodeAndName',['code'=>[$companyNo,$zxorder['khNo']]]);
  910. if(!isset($companyinfo['code']) || $companyinfo['code']!=0) return json_show($companyinfo['code'],$companyinfo['message'],$companyinfo['data']);
  911. $supplier_temp_info = $tmp['data'];
  912. $platforminfo = Db::name("platform")->where(["id"=> $zxorder['platform_code'],"is_del"=>0])->findOrEmpty();
  913. if (empty($platforminfo)) return error_show(1004, "平台信息未找到");
  914. if ($platforminfo['status'] != 1) return error_show(1004, "平台信息已禁用");
  915. if($platforminfo['is_select_pay_rate']==1 && channel_is_company($zxorder['platform_code'],$companyNo))return error_show(1004, "平台渠道含有 {$companyinfo['data'][$companyNo]}");
  916. $orderCode = makeNo("QR");
  917. $spuCode = $zxinfo['spuCode'];
  918. $skuCode = "";
  919. $is_stock = 0;
  920. $cgd = [
  921. "supplierNo" => $zxinfo['supplierNo'],
  922. "supplierName" => $supplier_temp_info['name'],
  923. "companyNo" => $companyNo,
  924. "companyName" => $companyinfo['data'][$companyNo]??"",
  925. "spuCode" => $spuCode,
  926. "skuCode" => $skuCode,
  927. "orderCode" => $orderCode,
  928. "good_name" => $zxinfo['good_name'],
  929. "sale_price" => $zxinfo['total_fee'],
  930. "total_fee" => round($zxinfo['total_fee'] * $good_num, 2),
  931. "pakge_fee" => $zxinfo['pakge_fee'],
  932. "cert_fee" => $zxinfo['cert_fee'],
  933. "open_fee" => $zxinfo['open_fee'],
  934. "cost_fee" => $zxinfo['cost_fee'],
  935. "mark_fee" => $zxinfo['mark_fee'],
  936. "demo_fee" => $zxinfo['demo_fee'],
  937. "nake_fee" => $zxinfo['nake_fee'],
  938. "delivery_fee" => $zxinfo['delivery_fee'],
  939. "good_num" => $good_num,
  940. "createrid" =>$supplier_temp_info['personid'],
  941. "creater" =>$supplier_temp_info['person'],
  942. "good_type" => 1,
  943. "open_type"=>$zxinfo["open_type"],
  944. "weight" => $zxinfo['good_weight'],
  945. "gold_price" => $zxinfo['gold_price'],
  946. "is_diff" => $zxinfo['is_diff'],
  947. "order_type" => 3,
  948. "order_source" => 2,//咨询
  949. 'send_way' => $zxinfo['send_way'],
  950. 'good_createrid' => $zxinfo['createrid'],
  951. 'good_creater' => $zxinfo['creater'],//商品创建人id
  952. 'supplier_origin_price'=>$zxinfo['supplier_origin_price'],//供应商采购成本
  953. 'cgd_supplier_code'=>$zxinfo['cgd_supplier_code'],//采购供应商编号
  954. 'cgd_supplier_name'=>$zxinfo['cgd_supplier_name'],//采购供应商编号
  955. 'cgd_apply_id'=>$zxinfo['cgd_apply_id'],//竞单人
  956. 'cgd_apply_name'=>$zxinfo['cgd_apply_name'],//竞单人
  957. ];
  958. $rm = $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  959. $ri = $this->uname;//isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  960. $va = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  961. $send_num = 0;
  962. if ($sendtype == 1) {
  963. if ($va == "") {
  964. return error_show(1002, "参数order_addr不能为空");
  965. }
  966. $send_num = array_sum(array_column($va, "receipt_quantity"));
  967. }
  968. if ($good_num < $send_num) {
  969. return error_show(1002, "发货数量不能超过购买数量");
  970. }
  971. $arrtime = isset($this->post['arrtime']) && $this->post['arrtime'] != "" ? $this->post['arrtime'] : "";
  972. if ($arrtime == "") {
  973. return error_show(1002, "参数arrtime不能为空");
  974. }
  975. //新加字段
  976. $platform_order = isset($this->post['platform_order']) && $this->post['platform_order'] != "" ? $this->post['platform_order'] : "";
  977. $workNo = isset($this->post['workNo']) && $this->post['workNo'] != "" ? $this->post['workNo'] : "";
  978. $proof_type = isset($this->post['proof_type']) && $this->post['proof_type'] != "" ? intval($this->post['proof_type']) : 0;
  979. $proof_url = isset($this->post['proof_url']) && $this->post['proof_url'] != "" ? trim($this->post['proof_url']) : '';
  980. if($proof_url=="")return error_show(1002, '参数 proof_url 不能为空');
  981. if($proof_type==0)return error_show(1002, '参数 proof_type 不能为空');
  982. Db::startTrans();
  983. try {
  984. $zx = Db::name("consult_info")->where(["infoNo" => $zxinfo['infoNo'], "is_del" => 0])->lock(true)->find();
  985. if ($zx == false) {
  986. Db::rollback();
  987. return error_show(1003, "未找到咨询单信息");
  988. }
  989. if ($companyNo != $zxorder['companyNo']) {
  990. $zxord = Db::name("consult_order")->where($zxorder)->update(["companyNo" => $companyNo, "updatetime" => date("Y-m-d H:i:s")]);
  991. if ($zxord == false) {
  992. Db::rollback();
  993. return error_show(1003, "咨询单更新业务公司失败");
  994. }
  995. }
  996. if(!empty($bargaininfo)){
  997. $bargaininfo['status']=4;
  998. $bargaininfo['updatetime']=date("Y-m-d H:i:s");
  999. $branip =Db::name("bargain_order")->save($bargaininfo);
  1000. if($branip==false) throw new Exception("未完成的议价单取消失败");
  1001. }
  1002. $bidsup =[
  1003. "status"=>6,
  1004. "updatetime"=>date("Y-m-d H:i:s")
  1005. ];
  1006. $updateinfp =Db::name("consult_bids")->where(["bidNo" => $bidNo, "is_del" => 0])->update($bidsup);
  1007. if($updateinfp==false) throw new Exception("反馈单转单失败");
  1008. $data = [
  1009. "orderCode" => $orderCode,
  1010. "good_code" => $spuCode,
  1011. "skuCode" => $skuCode,
  1012. "customer_code" => $zxorder['khNo'],
  1013. "customerName" => $companyinfo['data'][$zxorder['khNo']]??"",
  1014. "good_name" => isset($zxinfo['good_name']) && $zxinfo['good_name'] !== '' ? $zxinfo['good_name'] : '',
  1015. "good_num" => $good_num,
  1016. "cat_id" => $zxinfo['cat_id'],
  1017. "apply_id" => $rm,
  1018. "apply_name" => $ri,
  1019. "origin_price" => $zxinfo['total_fee'],
  1020. "sale_price" => $sale_price,//销售单价支持修改
  1021. "post_fee" => 0,
  1022. "status" => 0,
  1023. "send_num" => 0,
  1024. "wsend_num" => $good_num,
  1025. "send_status" => 1,
  1026. "good_type" =>$goodtype,
  1027. "send_type" => $sendtype,
  1028. "supplierNo" => $companyNo,
  1029. "supplierName" =>$companyinfo['data'][$companyNo]??"",
  1030. "is_del" => 0,
  1031. "supNo" => $zxinfo['supplierNo'],
  1032. "supName" =>$supplier_temp_info['name'],
  1033. "zxNo" => $bidNo,
  1034. "platform_order" => $platform_order,
  1035. "platform_id" => $zxorder['platform_code'],
  1036. "remark" => $remark,
  1037. "arrive_time" => $arrtime,
  1038. "is_stock" => 0,
  1039. "is_activity" => 0,
  1040. "activity_code" => '',
  1041. "proof_id" => 0,
  1042. "order_type" => 3,
  1043. "order_source" => 2,//2咨询
  1044. 'good_weight' => $zxinfo['good_weight'],
  1045. 'gold_price' => $zxinfo['gold_price'],
  1046. 'cost_price' => $zxinfo['sale_cost_fee'],
  1047. 'diff_weight' => 0,
  1048. 'open_type'=>$zxinfo['open_type'],
  1049. 'diff_fee' => 0,
  1050. "addtime" => date("Y-m-d H:i:s"),
  1051. "updatetime" => date("Y-m-d H:i:s"),
  1052. 'total_price' => round($sale_price * $good_num, 2),
  1053. 'workNo' => $workNo,
  1054. 'cgderid' => $supplier_temp_info['personid'],
  1055. 'cgder' => $supplier_temp_info['person'],//采购员(采购单对应的供应商负责人)
  1056. 'good_createrid' => $zxinfo['createrid'],
  1057. 'good_creater' => $zxinfo['creater'],//商品创建人id
  1058. "manager"=>$manager,
  1059. "managerid"=>$managerid,
  1060. ];
  1061. $datainfo = Db::name('sale')->insert($data, true);
  1062. if ($datainfo > 0) {
  1063. $standing_book_data = [
  1064. 'sale_id' => $datainfo,
  1065. 'infoNo' => $zxinfo['infoNo'],
  1066. 'updatetime' => date('Y-m-d H:i:s')
  1067. ];
  1068. //修改状态,添加待办
  1069. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1070. "order_code" => $orderCode,//销售单code
  1071. "status" => 0,//这里的status是之前的值
  1072. "action_remark" => '',//备注
  1073. "action_type" => "create"//新建create,编辑edit,更改状态status
  1074. ], "XSQRD", $data['status'], $data);
  1075. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1076. "order_type" => 'XSQRD',
  1077. "order_code" => $orderCode,//销售单code
  1078. "order_id" => $datainfo,
  1079. "order_status" => $data['status'],
  1080. "before_status" => 0,
  1081. 'holder_id' => $data['apply_id'],
  1082. ]);
  1083. $old_zx_status = $zx['status'];
  1084. $sa = Db::name("consult_info")->where($zx)->save(["status" => 5, "updatetime" => date("Y-m-d H:i:s")]);
  1085. if ($sa == false) {
  1086. Db::rollback();
  1087. return error_show(1002, "咨询单修改失败");
  1088. } else {
  1089. //修改状态,添加待办
  1090. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1091. "order_code" => $zx['infoNo'],//咨询单详情编号
  1092. "status" => $old_zx_status,//这里的status是之前的值
  1093. "action_remark" => '',//备注
  1094. "action_type" => "status"//新建create,编辑edit,更改状态status
  1095. ], "ZXD", 5, $zx);
  1096. }
  1097. $limt = [
  1098. "spuCode" => $zxinfo['spuCode'],
  1099. "good_name" => $zxinfo['good_name'],
  1100. "brand_id" => $zxinfo['brand_id'],
  1101. "good_unit" => $zxinfo['unit_id'],
  1102. "cat_id" => $zxinfo['cat_id'],
  1103. "good_type" => 0,
  1104. "moq" => 1,
  1105. "customized" => $zxinfo['work_day'],
  1106. "tax" => $zxinfo['tax'],
  1107. "supplierNo" => $zxinfo["supplierNo"],
  1108. "supplierName" =>$supplier_temp_info['name'],
  1109. "is_auth" => 0,
  1110. "craft_desc" => $zxinfo['good_name'],
  1111. "good_remark" => "",
  1112. "platform_id" => $zxorder['platform_id'],
  1113. "good_img" => $zxinfo['good_img'],
  1114. "good_thumb_img" => "",
  1115. "good_info_img" => "",
  1116. "specinfo" => $zxinfo['specinfo'],
  1117. "work_day" => $zxinfo['work_day'],
  1118. "noble_metal" => $zxinfo['metal_id'],
  1119. "is_gold_price" => $zxinfo['is_gold_price'],
  1120. "config" => $zxinfo['config'],
  1121. "other_config" => $zxinfo['other_config'],
  1122. "weight" => $zxinfo['weight'],
  1123. "good_weight" => $zxinfo['good_weight'],
  1124. "is_diff" => $zxinfo['is_diff'],
  1125. "supply_area" => $zxinfo['supply_area'],
  1126. "pay_way" => $zxinfo['pay_way'],
  1127. "send_way" => $zxinfo['send_way'],
  1128. "companyNo" => $companyNo,
  1129. "companyName" =>$companyinfo['data'][$companyNo]??"",
  1130. 'sale_price' => $sale_price,
  1131. "status" => 1,
  1132. "is_combind" => $zxinfo['is_combind'],
  1133. "open_type"=>$zxinfo['open_type'],
  1134. "is_del" => 0,
  1135. 'order_type' => 3,
  1136. 'order_source' => 2,
  1137. "createrid" => $zxinfo['createrid'],
  1138. "creater" => $zxinfo['creater'],
  1139. "order_createrid" => $this->uid,
  1140. "order_creater" => $this->uname,
  1141. "addtime" => date("Y-m-d H:i:s"),
  1142. "updatetime" => date("Y-m-d H:i:s"),
  1143. 'proof_type' => $proof_type,//凭证类型
  1144. 'proof_url' => $proof_url,//凭证文件
  1145. ];
  1146. $good = Db::name("good_zixun")->insert($limt);
  1147. if (!$good) {
  1148. Db::rollback();
  1149. return error_show(1006, "咨询商品录入失败");
  1150. }
  1151. if($zxinfo['is_combind']==1){
  1152. $marage=[
  1153. "parent_code"=>$zxinfo['spuCode'],
  1154. "parent_name"=>$zxinfo['good_name'],
  1155. 'order_type' => 3,
  1156. 'order_source' => 2,
  1157. 'good_type' => 0,
  1158. 'moq' => 1,
  1159. 'good_thumb_img' => '',
  1160. 'good_info_img' => '',
  1161. "is_auth" => 0,
  1162. 'good_remark' => '',
  1163. 'createrid' => $zxinfo['createrid'],
  1164. 'creater' => $zxinfo['creater'],
  1165. 'order_createrid' => $this->uid,
  1166. 'order_creater' => $this->uname,
  1167. 'proof_type' => $proof_type,//凭证类型
  1168. 'proof_url' => $proof_url,//凭证文件
  1169. 'platform_id' => $zxorder['platform_id'],
  1170. ];
  1171. (new ConsultTemp())->CreateGood($zxinfo['bidNo'],$marage);
  1172. }
  1173. if($zxinfo['open_type']==1){
  1174. $data = [
  1175. 'spuCode'=>$zxinfo['spuCode'],
  1176. 'companyNo'=>$companyNo,
  1177. 'tax_id'=>$zxinfo['tax_id'],
  1178. 'inv_good_name'=>$zxinfo['inv_good_name'],
  1179. 'open_type'=>$zxinfo['open_type'],
  1180. 'tax'=>$zxinfo['tax'],
  1181. 'createrid' => $zxinfo['createrid'],
  1182. 'creater' => $zxinfo['creater'],
  1183. ];
  1184. GoodTax::create($data);
  1185. }
  1186. $taxInfo = OrderTax::SpuCat($spuCode);
  1187. if (!empty($taxInfo)) {
  1188. (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
  1189. $temp=[];
  1190. $temp['code']=$orderCode;
  1191. $temp['spuCode']=$item['spuCode'];
  1192. $temp['tax_code']=$item['cat_code'];
  1193. $temp['tax_name']=$item['cat_name'];
  1194. $temp['tax_short_name']=$item['short_name'];
  1195. $temp['inv_tax']=$item['tax'];
  1196. $temp['inv_good_name']=$item['inv_good_name'];
  1197. return $temp;
  1198. },$taxInfo));
  1199. }
  1200. $bol = $this->createCgd($cgd, $standing_book_data);
  1201. if ($bol == false) {
  1202. Db::rollback();
  1203. return error_show(1002, '咨询订单创建失败');
  1204. }
  1205. if (!empty($va)) {
  1206. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  1207. ->find();
  1208. if ($order == false) {
  1209. Db::rollback();
  1210. return error_show(1006, "采购单关联数据未找到");
  1211. }
  1212. $i = 1;
  1213. foreach ($va as $value) {
  1214. $temp = [];
  1215. $addrs = [];
  1216. if ($value['addr_code'] !== '' && is_array($value['addr_code']) && !empty($value['addr_code'])) {
  1217. $addrs['provice_code'] = $value['addr_code'][0];
  1218. $addrs['city_code'] = $value['addr_code'][1];
  1219. $addrs['area_code'] = $value['addr_code'][2];
  1220. $addr = json_encode($addrs);
  1221. } else {
  1222. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  1223. }
  1224. if($value['receipt_quantity']<=0) throw new Exception("地址发货数量不能小于1");
  1225. $temp['orderCode'] = $orderCode;
  1226. $temp['contactor'] = $value['contactor'];
  1227. $temp['mobile'] = $value['mobile'];
  1228. $temp['addr'] = $value['addr'];
  1229. $temp['addr_code'] = $addr;
  1230. $temp['customer_code'] = $zxorder['khNo'];
  1231. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1232. $temp['post_fee'] = 0;
  1233. $temp['is_del'] = 0;
  1234. $temp['addtime'] = date("Y-m-d H:i:s");
  1235. $temp['updatetime'] = date("Y-m-d H:i:s");
  1236. $temp['arrive_time'] = $arrtime;
  1237. $vmp = Db::name('order_addr')->insert($temp, true);
  1238. if ($vmp > 0) {
  1239. $outCode = makeNo("DF");
  1240. //改变编码规则,将原来的outCode后两位换成序列号
  1241. //str_pad字符串填充
  1242. $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  1243. $i++;
  1244. $out = [
  1245. "orderCode" => $orderCode,
  1246. "outCode" => $outCode,
  1247. "apply_id" => $rm,
  1248. "apply_name" => $ri,
  1249. "addrid" => $vmp,
  1250. "post_name" => "",
  1251. "post_code" => "",
  1252. "post_fee" => 0,
  1253. "sendtime" => date("Y-m-d H:i:s"),
  1254. "send_num" => $value['receipt_quantity'],
  1255. "check_num" => 0,
  1256. "error_num" => 0,
  1257. "wsm_code" => "",
  1258. "order_type" => 3,
  1259. "status" => 0,
  1260. "addtime" => date("Y-m-d H:i:s"),
  1261. "updatetime" => date("Y-m-d H:i:s")
  1262. ];
  1263. $ou = Db::name("order_out")->insertGetId($out);
  1264. if ($ou == false) {
  1265. Db::rollback();
  1266. return error_show(1002, "发货地址添加创建失败");
  1267. } else {
  1268. // OrderOutChild::makeChild($outCode); //非库存品下单无法立即分单
  1269. //修改状态,添加待办
  1270. ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
  1271. "order_code" => $outCode,//出库单号
  1272. "status" => 0,//这里的status是之前的值
  1273. "action_remark" => '',//备注
  1274. "action_type" => "create"//新建create,编辑edit,更改状态status
  1275. ], "CKD", 0, $out);
  1276. ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], [
  1277. "order_type" => 'CKD',
  1278. "order_code" => $outCode,//出库单号
  1279. "order_id" => $ou,
  1280. "order_status" => 0,
  1281. "before_status" => 0,
  1282. 'holder_id'=>$out['apply_id'],
  1283. 'wait_id'=>$supplier_temp_info['personid'],
  1284. 'wait_name'=>$supplier_temp_info['person'],
  1285. ]);
  1286. //将发货编号添加到台账中
  1287. $standing_book_data['outCode'][] = $outCode;
  1288. }
  1289. $tep = [
  1290. "cgdNo" => $order['cgdNo'],
  1291. "outCode" => $outCode,
  1292. "send_num" => $value['receipt_quantity'],
  1293. "status" => 1,
  1294. "addtime" => date("Y-m-d H:i:s"),
  1295. "updatetime" => date("Y-m-d H:i:s")
  1296. ];
  1297. $sen = Db::name("order_send")->save($tep);
  1298. if ($sen == false) {
  1299. Db::rollback();
  1300. return error_show(1002, "发货地址添加创建失败");
  1301. }
  1302. } else {
  1303. Db::rollback();
  1304. return error_show(1002, "发货地址添加创建失败");
  1305. }
  1306. }
  1307. }
  1308. //处理台账
  1309. if (isset($standing_book_data['outCode'])) {
  1310. Db::execute("UPDATE `wsm_standing_book` SET `outCode`=CONCAT(IFNULL(`outCode`,''),'," . implode(',', $standing_book_data['outCode']) . "'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `infoNo`='{$standing_book_data['infoNo']}'");
  1311. unset($standing_book_data['outCode']);
  1312. }
  1313. Db::name('standing_book')->where('infoNo', $standing_book_data['infoNo'])->update($standing_book_data);
  1314. Db::commit();
  1315. return error_show(0, "咨询订单创建成功", ["order_code" => $orderCode]);
  1316. }
  1317. Db::rollback();
  1318. return error_show(1002, "咨询订单创建失败");
  1319. } catch (\Exception $e) {
  1320. Db::rollback();
  1321. return error_show(1003, $e->getMessage());
  1322. }
  1323. }
  1324. /**
  1325. * @return \think\response\Json|void
  1326. * @throws \think\db\exception\DataNotFoundException
  1327. * @throws \think\db\exception\DbException
  1328. * @throws \think\db\exception\ModelNotFoundException
  1329. */
  1330. public function projectCreate()
  1331. {
  1332. $planNo = isset($this->post['planNo']) && $this->post['planNo'] != "" ? trim($this->post['planNo']) : "";
  1333. if ($planNo == "") {
  1334. return error_show(1004, "参数planNo不能为空");
  1335. }
  1336. $plan = Db::name("project_plan")->where(["planNo" => $planNo, "is_del" => 0])->find();
  1337. if ($plan == false) {
  1338. return error_show(1004, "未找到方案信息");
  1339. }
  1340. $feedbackid = Db::name("project_plan_rela")->where(["planNo" => $planNo, "is_del" => 0])->column("feedback_id,sale_price,sale_num");
  1341. if ($feedbackid == false) {
  1342. return error_show(1004, "未找到方案反馈信息");
  1343. }
  1344. $project = Db::name("project")->where(["projectNo" => $plan['projectNo'], "is_del" => 0])->find();
  1345. if ($project == false) {
  1346. return error_show(1004, "未找到方案信息");
  1347. }
  1348. $arrtime = isset($this->post['arrtime']) && $this->post['arrtime'] != "" ? $this->post['arrtime'] : "";
  1349. if ($arrtime == "") {
  1350. return error_show(1002, "参数arrtime不能为空");
  1351. }
  1352. $planinfo = isset($this->post['planinfo']) && !empty($this->post['planinfo']) ? $this->post['planinfo'] : "";
  1353. if ($planinfo == "") {
  1354. return error_show(1002, "参数planinfo不能为空");
  1355. }
  1356. $userCommon = \app\admin\common\User::getIns();
  1357. $names = $userCommon->handle('getCodeAndName', ['code' =>[$project['companyNo'],$project['khNo']]]);
  1358. if($names['code']!=0 || empty($names['data']) ) return error_show($names['code'],$names['message']);
  1359. $platforminfo = Db::name("platform")->where(["id"=> $project['platform_id'],"is_del"=>0])->findOrEmpty();
  1360. if (empty($platforminfo)) return error_show(1004, "平台信息未找到");
  1361. if ($platforminfo['status'] != 1) return error_show(1004, "平台信息已禁用");
  1362. if($platforminfo['is_select_pay_rate']==1 && channel_is_company($project['platform_id'],$project['companyNo']))return error_show(1004, "平台渠道含有 {$names['data'][$project['companyNo']]}");
  1363. $rm = $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1364. $ri = $this->uname;//isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1365. $manager = isset($this->post['manager']) && $this->post['manager'] != '' ? $this->post['manager'] :$this->uname;
  1366. $managerid = isset($this->post['managerid']) && $this->post['managerid'] != '' ? $this->post['managerid'] :$this->uid;
  1367. Db::startTrans();
  1368. try {
  1369. $plan = Db::name("project_plan")->where(["planNo" => $planNo, "is_del" => 0])->lock(true)->find();
  1370. if ($plan == false) {
  1371. throw new Exception("未找到方案信息");
  1372. // return error_show(1004, "未找到方案信息");
  1373. }
  1374. $feedid = array_column($feedbackid, "feedback_id");
  1375. $feedbacks = Db::name("project_feedback")
  1376. ->where(["id" => $feedid, "projectNo" => $plan['projectNo'], "is_del" => 0])
  1377. ->column("*","id");
  1378. foreach ($planinfo as $key => $value) {
  1379. $good = [];
  1380. $feedback = $feedbacks[$value['feedback_id']]??[];
  1381. if (empty($feedback)) {
  1382. throw new Exception("反馈数据未找到");
  1383. // return error_show(1002, "反馈数据未找到");
  1384. }
  1385. $key = array_search($feedback['id'], $feedid);
  1386. $price = $feedbackid[$key];
  1387. $good['spuCode'] = $feedback['spuCode'];
  1388. $good['skuCode'] = $feedback['skuCode'];
  1389. $good['good_num'] = $price['sale_num'];
  1390. $good['sendtype'] = $value['sendtype'];
  1391. $good['sale_price'] = $price['sale_price'];
  1392. $good['origin_price'] = $feedback['origin_price'];
  1393. $good['companyNo'] = $project['companyNo'];
  1394. $good['companyName'] =$names['data'][$project['companyNo']]??'';
  1395. $good['customerNo'] = $project['khNo'];
  1396. $good['customerName'] =$names['data'][$project['khNo']]??'';
  1397. $good['pgNo'] = $feedback['pgNo'];
  1398. $good['platform_id'] = $project['platform_id'];
  1399. $good['arrtime'] = $arrtime;
  1400. $good['rm'] = $rm;
  1401. $good['ri'] = $ri;
  1402. $good['manager'] = $manager;
  1403. $good['managerid'] = $managerid;
  1404. $good['send_num'] = 0;
  1405. $standing_book_data = ['projectNo' => $plan['projectNo'], 'updatetime' => date('Y-m-d H:i:s')];
  1406. if ($value['sendtype'] == 1) {
  1407. if (!isset($value['addrlist']) || empty($value['addrlist'])) {
  1408. throw new Exception("订单地址不能为空");
  1409. // return error_show(1002, "订单地址不能为空");
  1410. }
  1411. $good['addrlist'] = $value['addrlist'];
  1412. $good['send_num'] = array_sum(array_column($value['addrlist'], "receipt_quantity"));
  1413. }
  1414. if ($feedback['data_source'] == 1) {
  1415. $feed = $this->project_good($good, $standing_book_data);
  1416. if ($feed !== true) {
  1417. throw new Exception("订单生成失败");
  1418. // return error_show(1002, $msg);
  1419. }
  1420. } else {
  1421. $feed = $this->project_zx($good, $standing_book_data);
  1422. if ($feed == false) {
  1423. throw new Exception("咨询订单生成失败");
  1424. // return error_show(1002, "咨询订单生成失败");
  1425. }
  1426. }
  1427. $old_fk_status = $feedback['status'];
  1428. $fed = Db::name("project_feedback")->where($feedback)->save(['status' => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1429. if ($fed == false) {
  1430. throw new Exception("项目反馈更新失败");
  1431. // return error_show(1002, "项目订单生成失败");
  1432. }
  1433. //处理台账(一个项目会生成多个销售订单,第一个更新,其余的新增)
  1434. //项目创建时已有供应商和企业,不能修改
  1435. if (isset($standing_book_data['companyNo'])) unset($standing_book_data['companyNo']);
  1436. if (isset($standing_book_data['customer_code'])) unset($standing_book_data['customer_code']);
  1437. if (isset($standing_book_data['outCode'])) $standing_book_data['outCode'] = implode(',', $standing_book_data['outCode']);
  1438. //普通商品
  1439. if ($feedback['data_source'] == 1) {
  1440. if ($key == 0) Db::name('standing_book')->where('projectNo', $plan['projectNo'])->update($standing_book_data);
  1441. else {
  1442. $temp = Db::name('standing_book')->where('projectNo', $plan['projectNo'])->find();
  1443. if (!empty($temp)) {
  1444. unset($temp['id']);
  1445. $temp = array_merge($temp, $standing_book_data);
  1446. $temp['standBookNo'] = makeNo('IO');
  1447. Db::name('standing_book')->insert($temp);
  1448. }
  1449. }
  1450. } else {
  1451. //项目类竞价单
  1452. Db::name('standing_book')->where(['projectNo' => $plan['projectNo'], 'infoNo' => $standing_book_data['infoNo']])->update($standing_book_data);
  1453. }
  1454. }
  1455. $old_plan_status = $plan['status'];
  1456. // $plan['status']=2;
  1457. // $plan['updatetime']=date("Y-m-d H:i:s");
  1458. $in = Db::name("project_plan")->where($plan)->save(['status' => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1459. if ($in == false) {
  1460. throw new Exception("项目方案状态更新失败");
  1461. // return error_show(1002, "项目订单生成失败");
  1462. } else {
  1463. //修改状态,添加待办,只记录动作
  1464. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1465. "order_code" => $planNo,//编码
  1466. "status" => $old_plan_status,//这里的status是之前的值
  1467. "action_remark" => '',//备注
  1468. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1469. ], "PRP", 2, $plan);
  1470. }
  1471. $old_project_status = $project["status"];
  1472. // $project["status"]=6;
  1473. // $project['updatetime']=date("Y-m-d H:i:s");
  1474. $pr = Db::name("project")->where($project)->save(["updatetime" => date("Y-m-d H:i:s"), "status" => 6]);
  1475. if ($pr == false) {
  1476. throw new Exception("项目状态更新失败");
  1477. // return error_show(1002, "项目订单生成失败");
  1478. } else {
  1479. //修改状态,添加待办
  1480. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1481. "order_code" => $project['projectNo'],//项目编码
  1482. "status" => $old_project_status,//这里的status是之前的值
  1483. "action_remark" => '',//备注
  1484. "action_type" => "status"//新建create,编辑edit,更改状态status
  1485. ], "PRO", 6, $project);
  1486. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1487. "order_type" => 'PRO',
  1488. "order_code" => $project['projectNo'],
  1489. "order_id" => $project['id'],
  1490. "order_status" => 6,
  1491. "before_status" => $old_project_status,
  1492. 'holder_id'=>$project['createrid']
  1493. ]);
  1494. }
  1495. //修改状态,添加待办,只记录动作
  1496. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1497. "order_code" => $project['projectNo'],//编码,这里是project的编码
  1498. "status" => 1,//这里的status是之前的值
  1499. "action_remark" => '',//备注
  1500. "action_type" => "create"//新建create,编辑edit,更改状态status
  1501. ], "PRT", 2, $this->post);
  1502. $process = ["order_code" => $project['projectNo'], "order_id" => $project['id'], "order_status" => 2, "order_type" => "PRT", "before_status" => 1];
  1503. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $process);
  1504. Db::commit();
  1505. return app_show(0, "咨询订单生成成功");
  1506. } catch (\Exception $e) {
  1507. Db::rollback();
  1508. return error_show(1002, $e->getMessage());
  1509. }
  1510. }
  1511. /**
  1512. * @param $data
  1513. * @return false
  1514. * @throws \think\db\exception\DataNotFoundException
  1515. * @throws \think\db\exception\DbException
  1516. * @throws \think\db\exception\ModelNotFoundException
  1517. *
  1518. */
  1519. public function project_zx($data, array &$standing_book_data = [])
  1520. {
  1521. $goodinfo = Db::name("consult_bids")->where(["spuCode" => $data['spuCode'], "is_del" => 0])->find();
  1522. if ($goodinfo == false) {
  1523. throw new Exception("咨询商品未找到");
  1524. }
  1525. $bargaininfo =Db::name("bargain_order")->where(["bidsNo" => $goodinfo["bidNo"],"is_del"=>0,"status"=>0])
  1526. ->findOrEmpty();
  1527. if(!empty($bargaininfo)){
  1528. $bargaininfo['status']=4;
  1529. $bargaininfo['updatetime']=date("Y-m-d H:i:s");
  1530. $branip =Db::name("bargain_order")->save($bargaininfo);
  1531. if($branip==false) throw new Exception("未完成的议价单取消失败");
  1532. }
  1533. $orderCode = makeNo("QR");
  1534. $userCommon= \app\admin\common\User::getIns();
  1535. $supplier_temp =$userCommon->handle("sInfo",["code"=>$goodinfo['supplierNo']]);
  1536. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception("采购单供应商不存在");
  1537. $holder_id=$supplier_temp['data']['personid']??0;
  1538. $holder_name=$supplier_temp['data']['person']??'';
  1539. $supplierName=$supplier_temp['data']['name']??'';
  1540. $cgd = [
  1541. "supplierNo" => $goodinfo['supplierNo'],
  1542. "supplierName" => $supplierName,
  1543. "companyNo" => $data['companyNo'],
  1544. "companyName" => $data['companyName'],
  1545. "spuCode" => $data['spuCode'],
  1546. "skuCode" => "",
  1547. "orderCode" => $orderCode,
  1548. "good_name" => $goodinfo['good_name'],
  1549. "sale_price" => $goodinfo['total_fee'],
  1550. "total_fee" => round($goodinfo['total_fee'] * $data['good_num'], 2),
  1551. "pakge_fee" => $goodinfo['pakge_fee'],
  1552. "cert_fee" => $goodinfo['cert_fee'],
  1553. "open_fee" => $goodinfo['open_fee'],
  1554. "cost_fee" => $goodinfo['cost_fee'],
  1555. "mark_fee" => $goodinfo['mark_fee'],
  1556. "demo_fee" => $goodinfo['demo_fee'],
  1557. "nake_fee" => $goodinfo['nake_fee'],
  1558. "good_num" => $data['good_num'],
  1559. "delivery_fee" => $goodinfo['delivery_fee'],
  1560. "createrid" =>$holder_id,
  1561. "creater" =>$holder_name,
  1562. "weight" => $goodinfo['good_weight'],
  1563. "gold_price" => $goodinfo['gold_price'],
  1564. 'open_type'=>$goodinfo['open_type'],
  1565. "good_type" => 1,
  1566. "order_type" => 3,//3咨询商品
  1567. "order_source" => 3,//项目
  1568. "send_way" => $goodinfo['send_way'],
  1569. 'good_createrid' => $goodinfo['createrid'],
  1570. 'good_creater' => $goodinfo['creater'],//商品创建人
  1571. 'supplier_origin_price'=>$goodinfo['supplier_origin_price'],//供应商采购成本
  1572. 'cgd_supplier_code'=>$goodinfo['cgd_supplier_code'],//采购供应商编号
  1573. 'cgd_supplier_name'=>$goodinfo['cgd_supplier_name'],//采购供应商编号
  1574. 'cgd_apply_id'=>$goodinfo['cgd_apply_id'],//竞单人
  1575. 'cgd_apply_name'=>$goodinfo['cgd_apply_name'],//竞单人
  1576. ];
  1577. $datas = [
  1578. "orderCode" => $orderCode,
  1579. "good_code" => $data['spuCode'],
  1580. "skuCode" => "",
  1581. "customer_code" => $data['customerNo'],
  1582. "customerName" => $data['customerName'],
  1583. "good_name" => isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '' ? $goodinfo['good_name'] : '',
  1584. "good_num" => $data['good_num'],
  1585. "cat_id" => $goodinfo['cat_id'],
  1586. "apply_id" => $data['rm'],
  1587. "apply_name" => $data['ri'],
  1588. "origin_price" => $goodinfo['total_fee'],
  1589. "sale_price" => $data['sale_price'],
  1590. "post_fee" => 0,
  1591. "status" => 0,
  1592. "send_num" => 0,
  1593. "wsend_num" => $data['good_num'],
  1594. "send_status" => 1,
  1595. "good_type" => 1,
  1596. "send_type" => $data['sendtype'],
  1597. "supplierNo" => $data['companyNo'],
  1598. "supplierName" => $data['companyName'],
  1599. "supNo" =>$goodinfo['supplierNo'],
  1600. "supName" => $supplierName,
  1601. "is_del" => 0,
  1602. "zxNo" => $data["pgNo"],
  1603. "platform_order" => "",
  1604. "platform_id" => $data['platform_id'],
  1605. 'open_type'=>$goodinfo['open_type'],
  1606. "remark" => "",
  1607. "is_stock" => 0,
  1608. "is_activity" => 0,
  1609. "activity_code" => '',
  1610. "proof_id" => 0,
  1611. "order_type" => 3,//咨询商品
  1612. "order_source" => 3,//项目
  1613. 'good_weight' => $goodinfo['good_weight'],
  1614. 'gold_price' => $goodinfo['gold_price'],
  1615. 'cost_price' => $goodinfo['sale_cost_fee'],
  1616. 'diff_weight' => 0,
  1617. 'diff_fee' => 0,
  1618. "addtime" => date("Y-m-d H:i:s"),
  1619. "updatetime" => date("Y-m-d H:i:s"),
  1620. 'total_price' => round($data['sale_price'] * $data['good_num'], 2),
  1621. 'cgderid' => $holder_id,
  1622. 'cgder' => $holder_name,//采购员(供应商负责人)
  1623. 'good_createrid' => $goodinfo['createrid'],
  1624. 'good_creater' => $goodinfo['creater'],//商品创建人
  1625. "manager"=>$data['manager'],
  1626. "managerid"=>$data['managerid'],
  1627. ];
  1628. $datainfo = Db::name('sale')->insert($datas, true);
  1629. if ($datainfo > 0) {
  1630. $standing_book_data['sale_id'] = $datainfo;
  1631. $standing_book_data['customer_code'] = $datas['customer_code'];
  1632. $standing_book_data['infoNo'] = $goodinfo['infoNo'];
  1633. //修改状态,添加待办
  1634. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1635. "order_code" => $orderCode,//项目编码
  1636. "status" => 0,//这里的status是之前的值
  1637. "action_remark" => '',//备注
  1638. "action_type" => "status"//新建create,编辑edit,更改状态status
  1639. ], "XSQRD", 0, $datas);
  1640. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1641. "order_type" => 'XSQRD',
  1642. "order_code" => $orderCode,
  1643. "order_id" => $datainfo,
  1644. "order_status" => 0,
  1645. "before_status" => 0,
  1646. 'holder_id' => $datas['apply_id']
  1647. ]);
  1648. $bidstatus = $goodinfo['status'];
  1649. $goodinfo['status'] = 6;
  1650. $goodinfo['updatetime'] = date("Y-m-d H:i:s");
  1651. $sa = Db::name("consult_bids")->save($goodinfo);
  1652. if ($sa == false) {
  1653. throw new Exception("咨询反馈单更新失败");
  1654. }
  1655. $goodinfo['status'] = 5;
  1656. $goodinfo['updatetime'] = date("Y-m-d H:i:s");
  1657. $saa = Db::name("consult_info")->where(["infoNo"=>$goodinfo['infoNo']])->update(["status"=>5,
  1658. "updatetime"=>date("Y-m-d H:i:s")]);
  1659. if ($saa == false) {
  1660. throw new Exception("咨询单更新失败");
  1661. }
  1662. //修改状态,添加待办
  1663. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1664. "order_code" => $goodinfo['bidNo'],//项目编码
  1665. "status" => $bidstatus,//这里的status是之前的值
  1666. "action_remark" => '',//备注
  1667. "action_type" => "status"//新建create,编辑edit,更改状态status
  1668. ], "FKD", 6, $datas);
  1669. $zxorder = Db::name("consult_order")->where(["zxNo" => $goodinfo["zxNo"], "is_del" => 0])->find();
  1670. if ($zxorder == false) {
  1671. throw new Exception("咨询单为找到");
  1672. }
  1673. $limt = [
  1674. "spuCode" => $goodinfo['spuCode'],
  1675. "good_name" => $goodinfo['good_name'],
  1676. "brand_id" => $goodinfo['brand_id'],
  1677. "good_unit" => $goodinfo['unit_id'],
  1678. "cat_id" => $goodinfo['cat_id'],
  1679. "good_type" => 0,
  1680. "moq" => 1,
  1681. "customized" => $goodinfo['work_day'],
  1682. "tax" => $goodinfo['tax'],
  1683. "supplierNo" => $goodinfo["supplierNo"],
  1684. "supplierName" => $supplierName,
  1685. "is_auth" => 0,
  1686. "craft_desc" => $goodinfo['good_name'],
  1687. "good_remark" => "",
  1688. "good_img" => $goodinfo['good_img'],
  1689. "good_thumb_img" => "",
  1690. "good_info_img" => "",
  1691. "platform_id" => $zxorder['platform_id'],
  1692. "specinfo" => $goodinfo['specinfo'],
  1693. "work_day" => $goodinfo['work_day'],
  1694. "noble_metal" => $goodinfo['metal_id'],
  1695. "is_gold_price" => $goodinfo['is_gold_price'],
  1696. "good_weight" => $goodinfo['good_weight'],
  1697. "companyNo" => $data['companyNo'],
  1698. "companyName" => $data['companyName'],
  1699. "config" => $goodinfo['config'],
  1700. "other_config" => $goodinfo['other_config'],
  1701. "weight" => $goodinfo['weight'],
  1702. "is_diff" => $goodinfo['is_diff'],
  1703. "supply_area" => $goodinfo['supply_area'],
  1704. "pay_way" => $goodinfo['pay_way'],
  1705. "send_way" => $goodinfo['send_way'],
  1706. 'sale_price' => $data['sale_price'],
  1707. 'open_type'=>$goodinfo['open_type'],
  1708. "status" => 1,
  1709. "is_del" => 0,
  1710. "order_type" => 3,
  1711. 'order_source' => 3,
  1712. 'order_createrid' => $data['rm'],
  1713. 'order_creater' => $data['ri'],
  1714. "createrid" => $goodinfo['createrid'],
  1715. "creater" => $goodinfo['creater'],
  1716. "addtime" => date("Y-m-d H:i:s"),
  1717. "updatetime" => date("Y-m-d H:i:s")
  1718. ];
  1719. $good = Db::name("good_zixun")->insert($limt);
  1720. if (!$good) {
  1721. throw new Exception("咨询商品录入失败");
  1722. }
  1723. if($goodinfo['is_combind']==1){
  1724. $marage=[
  1725. 'parent_code'=>$goodinfo['spuCode'],
  1726. 'parent_name'=>$goodinfo['good_name'],
  1727. 'order_type' => 3,
  1728. 'order_source' =>3,
  1729. 'good_type' => 0,
  1730. 'moq' => 1,
  1731. 'good_thumb_img' => '',
  1732. 'good_info_img' => '',
  1733. 'is_auth' => 0,
  1734. 'good_remark' => '',
  1735. 'createrid' => $goodinfo['createrid'],
  1736. 'creater' => $goodinfo['creater'],
  1737. 'order_createrid' => $data['rm'],
  1738. 'order_creater' => $data['ri'],
  1739. 'platform_id' => $zxorder['platform_id'],
  1740. ];
  1741. (new ConsultTemp())->CreateGood($goodinfo['bidNo'],$marage);
  1742. }
  1743. if($goodinfo['open_type']==1){
  1744. $data = [
  1745. 'spuCode'=>$goodinfo['spuCode'],
  1746. 'companyNo'=>$data['companyNo'],
  1747. 'tax_id'=>$goodinfo['tax_id'],
  1748. 'open_type'=>$goodinfo['open_type'],
  1749. 'inv_good_name'=>$goodinfo['inv_good_name'],
  1750. 'tax'=>$goodinfo['tax'],
  1751. 'createrid' => $goodinfo['createrid'],
  1752. 'creater' => $goodinfo['creater'],
  1753. ];
  1754. GoodTax::create($data);
  1755. }
  1756. $taxInfo = OrderTax::SpuCat( $data['spuCode']);
  1757. if (!empty($taxInfo)) {
  1758. (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
  1759. $temp=[];
  1760. $temp['code']=$orderCode;
  1761. $temp['spuCode']=$item['spuCode'];
  1762. $temp['tax_code']=$item['cat_code'];
  1763. $temp['tax_name']=$item['cat_name'];
  1764. $temp['tax_short_name']=$item['short_name'];
  1765. $temp['inv_tax']=$item['tax'];
  1766. $temp['inv_good_name']=$item['inv_good_name'];
  1767. return $temp;
  1768. },$taxInfo));
  1769. }
  1770. $bol = $this->createCgd($cgd, $standing_book_data);
  1771. if ($bol == false) {
  1772. throw new Exception('采购单生成失败');
  1773. }
  1774. if ($data['sendtype'] == 1 && !empty($data['addrlist'])) {
  1775. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])
  1776. ->find();
  1777. if ($order == false) {
  1778. throw new Exception("关联采购单信息未找到");
  1779. }
  1780. $i = 1;
  1781. foreach ($data['addrlist'] as $value) {
  1782. $temp = [];
  1783. $addrs = [];
  1784. if ($value['addr_code'] !== '' && is_array($value['addr_code']) && !empty($value['addr_code'])) {
  1785. $addrs['provice_code'] = $value['addr_code'][0];
  1786. $addrs['city_code'] = $value['addr_code'][1];
  1787. $addrs['area_code'] = $value['addr_code'][2];
  1788. $addr = json_encode($addrs);
  1789. } else {
  1790. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  1791. }
  1792. if($value['receipt_quantity']<=0) throw new Exception('地址发货数量不能小于1');
  1793. $temp['orderCode'] = $orderCode;
  1794. $temp['contactor'] = $value['contactor'];
  1795. $temp['mobile'] = $value['mobile'];
  1796. $temp['addr'] = $value['addr'];
  1797. $temp['addr_code'] = $addr;
  1798. $temp['customer_code'] = $data['companyNo'];
  1799. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1800. $temp['post_fee'] = 0;
  1801. $temp['is_del'] = 0;
  1802. $temp['addtime'] = date("Y-m-d H:i:s");
  1803. $temp['updatetime'] = date("Y-m-d H:i:s");
  1804. $temp['arrive_time'] = $data['arrtime'];
  1805. $vmp = Db::name('order_addr')->insert($temp, true);
  1806. if ($vmp > 0) {
  1807. $outCode = makeNo("DF");
  1808. //改变编码规则,将原来的outCode后两位换成序列号
  1809. //str_pad字符串填充
  1810. $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  1811. $i++;
  1812. $out = [
  1813. "orderCode" => $orderCode,
  1814. "outCode" => $outCode,
  1815. "apply_id" => $data['rm'],
  1816. "apply_name" => $data['ri'],
  1817. "addrid" => $vmp,
  1818. "post_name" => "",
  1819. "post_code" => "",
  1820. "post_fee" => 0,
  1821. "sendtime" => date("Y-m-d H:i:s"),
  1822. "send_num" => $value['receipt_quantity'],
  1823. "check_num" => 0,
  1824. "error_num" => 0,
  1825. "wsm_code" => "",
  1826. "order_type" => 3,//3咨询商品
  1827. "status" => 0,
  1828. "addtime" => date("Y-m-d H:i:s"),
  1829. "updatetime" => date("Y-m-d H:i:s")
  1830. ];
  1831. $ou = Db::name("order_out")->insertGetId($out);
  1832. if ($ou == false) {
  1833. throw new Exception("发货单生成失败");
  1834. }
  1835. // OrderOutChild::makeChild($outCode);
  1836. //修改状态,添加待办
  1837. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1838. "order_code" => $outCode,//项目编码
  1839. "status" => 0,//这里的status是之前的值
  1840. "action_remark" => '',//备注
  1841. "action_type" => "status"//新建create,编辑edit,更改状态status
  1842. ], "CKD", 0, $out);
  1843. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1844. "order_type" => 'CKD',
  1845. "order_code" => $outCode,
  1846. "order_id" => $ou,
  1847. "order_status" => 0,
  1848. "before_status" => 0,
  1849. 'holder_id'=>$data['rm'],
  1850. 'wait_id'=>$holder_id,
  1851. 'wait_name'=>$holder_name,
  1852. ]);
  1853. $tep = [
  1854. "cgdNo" => $order['cgdNo'],
  1855. "outCode" => $outCode,
  1856. "send_num" => $value['receipt_quantity'],
  1857. "status" => 1,
  1858. "addtime" => date("Y-m-d H:i:s"),
  1859. "updatetime" => date("Y-m-d H:i:s")
  1860. ];
  1861. $sen = Db::name("order_send")->save($tep);
  1862. if ($sen == false) {
  1863. throw new Exception("发货单关联采购单生成失败");
  1864. }
  1865. $standing_book_data['outCode'][] = $outCode;
  1866. } else {
  1867. throw new Exception("地址录入失败");
  1868. }
  1869. }
  1870. }
  1871. }
  1872. return true;
  1873. }
  1874. /**
  1875. * @param $data
  1876. * @return bool
  1877. * @throws \think\db\exception\DataNotFoundException
  1878. * @throws \think\db\exception\DbException
  1879. * @throws \think\db\exception\ModelNotFoundException
  1880. */
  1881. public function project_good($data, array &$standing_book_data = [])
  1882. {
  1883. $good = Db::name('good')
  1884. ->alias("a")
  1885. ->leftJoin("good_platform b", "a.spuCode=b.spuCode")
  1886. ->where(["b.skuCode" => $data['skuCode'], "a.is_del" => 0, "b.is_del" => 0])
  1887. ->field("a.*,b.skuCode,b.platform_code,b.is_fixed")->find();
  1888. if ($good == false) {
  1889. // return 4; //商品信息未找到
  1890. throw new Exception("商品信息未找到");
  1891. }
  1892. $goodlass = Db::name("good_ladder")->where(["skuCode" => $data['skuCode'], "is_del" => 0, "status" => 1])->where([["min_num", "<=", $data['good_num']]])->order("min_num desc")->find();
  1893. if ($goodlass == false) {
  1894. // /return 4;//商品信息未找到
  1895. throw new Exception("商品售价信息未找到");
  1896. }
  1897. $sale_price = $goodlass['sale_price'];
  1898. $origin = Db::name('good_nake')->where([['spuCode', '=', $data['spuCode']], ['min_num', '<=', $data['good_num']],
  1899. ['is_del', '=', 0]])->order('min_num desc')->find();
  1900. if ($origin == false && $good['is_stock'] ==0) {
  1901. throw new Exception('商品成本售价信息未找到');
  1902. }
  1903. $origin_price = $good['is_stock'] == 0?($origin['nake_total']??0):0;
  1904. $cgd_origin_price = $origin['supplier_origin_price']??0;
  1905. if ($good['is_gold_price'] == 1 && $good['is_stock'] == 0) {
  1906. $gold = Db::name("gold_price1")
  1907. ->field('id,price')
  1908. ->where(["type" => $good['noble_metal'], "is_del" => 0, "status" => 1])
  1909. ->order("addtime desc")
  1910. ->find();
  1911. if($good['is_fixed']==0) $origin['nake_fee']=0;
  1912. //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
  1913. $sale_price = $good['demo_fee'] / $data['good_num'] + $good['open_fee'] / $data['good_num'] + $good['noble_weight'] * $gold["price"] + $goodlass['cost_fee'] * $good['noble_weight'] + $origin['package_fee'] + $origin['mark_fee'] + $origin['cert_fee'] + $origin['nake_fee'] + $origin['delivery_fee'];
  1914. $good['cgd_gold_price'] = $gold["price"];
  1915. }
  1916. $orderCode = makeNo("QR");
  1917. $supplier_temp_info =[];
  1918. if($good['supplierNo']!=''){
  1919. $userCommon= \app\admin\common\User::getIns();
  1920. $supplier_temp =$userCommon->handle('sInfo',['code'=>$good['supplierNo']]);
  1921. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('供应商不存在');
  1922. $supplier_temp_info = $supplier_temp['data'];
  1923. }
  1924. $datas = [
  1925. "orderCode" => $orderCode,
  1926. "good_code" => $data['spuCode'],
  1927. "skuCode" => $data['skuCode'],
  1928. "customer_code" => $data['customerNo'],
  1929. "customerName" => $data['customerName'],
  1930. "good_name" => isset($good['good_name']) && $good['good_name'] !== '' ? $good['good_name'] : '',
  1931. "good_num" => $data['good_num'],
  1932. "cat_id" => $good['cat_id'],
  1933. "apply_id" => $data['rm'],
  1934. "apply_name" => $data['ri'],
  1935. "origin_price" => $origin_price,
  1936. "sale_price" => $sale_price,
  1937. "post_fee" => 0,
  1938. "status" => 0,
  1939. "send_num" => 0,
  1940. "wsend_num" => $data['good_num'],
  1941. "send_status" => 1,
  1942. "good_type" => 1,
  1943. "send_type" => $data['sendtype'],
  1944. "supplierNo" => $data['companyNo'],
  1945. "supplierName" => $data['companyName'],
  1946. "supName" => $good['supplierName'],
  1947. "supNo" => $good['supplierNo'],
  1948. "is_del" => 0,
  1949. "zxNo" => $data["pgNo"],
  1950. "platform_order" => "",
  1951. "platform_id" => $data['platform_id'],
  1952. "remark" => "",
  1953. "is_stock" => $good['is_stock'],
  1954. 'open_type'=>$good['open_type'],
  1955. "is_activity" => 0,
  1956. "activity_code" => '',
  1957. "proof_id" => 0,
  1958. "order_type" => $good['is_stock'] == 1 ? 1 : 2,//1备库,2非库存品
  1959. 'order_source' => 3,//3项目
  1960. 'good_weight' => $good['noble_weight'],
  1961. 'gold_price' => isset($good['cgd_gold_price']) ? $good['cgd_gold_price'] : 0,
  1962. 'cost_price' => $goodlass['cost_fee'],
  1963. 'diff_weight' => 0,
  1964. 'diff_fee' => 0,
  1965. "addtime" => date("Y-m-d H:i:s"),
  1966. "updatetime" => date("Y-m-d H:i:s"),
  1967. 'total_price' => round($sale_price * $data['good_num'], 2),
  1968. 'cgderid' => $supplier_temp_info['personid']??"0",
  1969. 'cgder' => $supplier_temp_info['person']??"",//采购员(供应商负责人)
  1970. 'good_createrid' => $good['createrid'],
  1971. 'good_creater' => $good['creater'],//商品创建人
  1972. "manager"=>$data['manager'],
  1973. "managerid"=>$data['managerid'],
  1974. ];
  1975. $datainfo = Db::name('sale')->insert($datas, true);
  1976. if ($datainfo > 0) {
  1977. $standing_book_data['sale_id'] = $datainfo;
  1978. //修改状态,添加待办
  1979. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1980. "order_code" => $orderCode,//项目编码
  1981. "status" => 0,//这里的status是之前的值
  1982. "action_remark" => '',//备注
  1983. "action_type" => "status"//新建create,编辑edit,更改状态status
  1984. ], "XSQRD", 0, $datas);
  1985. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1986. "order_type" => 'XSQRD',
  1987. "order_code" => $orderCode,
  1988. "order_id" => $datainfo,
  1989. "order_status" => 0,
  1990. "before_status" => 0,
  1991. 'holder_id' => $datas['apply_id']
  1992. ]);
  1993. $cgd = [
  1994. "supplierNo" => $good['supplierNo'],
  1995. "supplierName" =>$good['supplierName'],
  1996. "companyNo" => $data['companyNo'],
  1997. "companyName" => $data['companyName'],
  1998. "orderCode" => $orderCode,
  1999. "spuCode" => $good['spuCode'],
  2000. "skuCode" => $good['skuCode'],
  2001. "good_name" => $good['good_name'],
  2002. "sale_price" => $origin_price,
  2003. "total_fee" => $origin_price * $data['good_num'],
  2004. "pakge_fee" => isset($origin['package_fee']) ? $origin['package_fee'] : 0,
  2005. "cert_fee" => isset($origin['cert_fee']) ? $origin['cert_fee'] : 0,
  2006. "open_fee" => $good['open_fee'],
  2007. "cost_fee" => isset($origin['cost_fee']) ? $origin['cost_fee'] : 0,
  2008. "mark_fee" => isset($origin['mark_fee']) ? $origin['mark_fee'] : 0,
  2009. "demo_fee" => $good['demo_fee'],
  2010. "nake_fee" => isset($origin['nake_fee']) ? $origin['nake_fee'] : 0,
  2011. "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
  2012. "good_num" => $data['good_num'],
  2013. "good_type" => 1,
  2014. "weight" => $good['noble_weight'],
  2015. "gold_price" => isset($good['cgd_gold_price']) ? $good['cgd_gold_price'] : 0,
  2016. "createrid" => $supplier_temp_info['personid']??0,
  2017. "creater" => $supplier_temp_info['person']??"",
  2018. "order_type" => $good['is_stock'] == 1 ? 1 : 2,
  2019. 'open_type'=>$good['open_type'],
  2020. 'order_source' => 3,//3项目
  2021. 'send_way' => 2,
  2022. 'good_createrid' => $good['createrid'],
  2023. 'good_creater' => $good['creater'],//商品创建人
  2024. 'supplier_origin_price'=>$cgd_origin_price,//供应商采购成本
  2025. 'cgd_supplier_code'=>$good['cgd_supplier_code'],//采购供应商编号
  2026. 'cgd_supplier_name'=>$good['cgd_supplier_name'],//采购供应商编号
  2027. 'cgd_apply_id'=>$good['cgd_apply_id'],//竞单人
  2028. 'cgd_apply_name'=>$good['cgd_apply_name'],//竞单人
  2029. ];
  2030. $taxInfo = OrderTax::SpuCat( $data['spuCode']);
  2031. if (!empty($taxInfo)) {
  2032. (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
  2033. $temp=[];
  2034. $temp['code']=$orderCode;
  2035. $temp['spuCode']=$item['spuCode'];
  2036. $temp['tax_code']=$item['cat_code'];
  2037. $temp['tax_name']=$item['cat_name'];
  2038. $temp['tax_short_name']=$item['short_name'];
  2039. $temp['inv_tax']=$item['tax'];
  2040. $temp['inv_good_name']=$item['inv_good_name'];
  2041. return $temp;
  2042. },$taxInfo));
  2043. }
  2044. if ($good['is_stock'] == 0) {
  2045. $bol = $this->createCgd($cgd, $standing_book_data);
  2046. if ($bol == false) {
  2047. // return 3;//关联采购失败
  2048. throw new Exception("采购单生成失败");
  2049. }
  2050. } else {
  2051. if($good['usable_stock'] < $data['good_num']){
  2052. throw new Exception("可用库存数不足");
  2053. }
  2054. $stockUp =[
  2055. "usable_stock"=>$good['usable_stock']-$data['good_num'],
  2056. "updatetime"=>date("Y-m-d H:i:s"),
  2057. ];
  2058. $goodStockUp = Db::name("good")->where(['spuCode'=>$good['spuCode'],"usable_stock"=>$good['usable_stock']])->update
  2059. ($stockUp);
  2060. if($goodStockUp==false) throw new Exception("商品可用库存更新失败");
  2061. SaleCgdPrice::GetPrice($datainfo);
  2062. }
  2063. if ($data['sendtype'] == 1 && !empty($data['addrlist'])) {
  2064. $i = 1;
  2065. foreach ($data['addrlist'] as $value) {
  2066. $temp = [];
  2067. $addrs = [];
  2068. if ($value['addr_code'] !== '' && is_array($value['addr_code']) && !empty($value['addr_code'])) {
  2069. $addrs['provice_code'] = $value['addr_code'][0];
  2070. $addrs['city_code'] = $value['addr_code'][1];
  2071. $addrs['area_code'] = $value['addr_code'][2];
  2072. $addr = json_encode($addrs);
  2073. } else {
  2074. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  2075. }
  2076. if($value['receipt_quantity']<=0) throw new Exception('地址发货数量不能小于1');
  2077. $temp['orderCode'] = $orderCode;
  2078. $temp['contactor'] = $value['contactor'];
  2079. $temp['mobile'] = $value['mobile'];
  2080. $temp['addr'] = $value['addr'];
  2081. $temp['addr_code'] = $addr;
  2082. $temp['customer_code'] = $data['companyNo'];
  2083. $temp['receipt_quantity'] = $value['receipt_quantity'];
  2084. $temp['post_fee'] = 0;
  2085. $temp['is_del'] = 0;
  2086. $temp['addtime'] = date("Y-m-d H:i:s");
  2087. $temp['updatetime'] = date("Y-m-d H:i:s");
  2088. $temp['arrive_time'] = $data['arrtime'];
  2089. $vmp = Db::name('order_addr')->insert($temp, true);
  2090. if ($vmp > 0) {
  2091. $standing_book_data['customer_code'] = $temp['customer_code'];
  2092. $num = $value['receipt_quantity'];
  2093. $outCode = makeNo("DF");
  2094. $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  2095. $i++;
  2096. if ($good['is_stock'] != 1) {
  2097. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])
  2098. ->find();
  2099. if ($order == false) {
  2100. throw new Exception("关联采购单信息未找到");
  2101. }
  2102. $tep = [
  2103. "cgdNo" => $order['cgdNo'],
  2104. "outCode" => $outCode,
  2105. "send_num" => $num,
  2106. "status" => 1,
  2107. "addtime" => date("Y-m-d H:i:s"),
  2108. "updatetime" => date("Y-m-d H:i:s")
  2109. ];
  2110. $sen = Db::name("order_send")->save($tep);
  2111. if ($sen == false) {
  2112. throw new Exception("发货单关联采购单信息失败");
  2113. }
  2114. $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
  2115. if ($cgdinfo == false) {
  2116. throw new Exception("采购单信息未找到");
  2117. }
  2118. }
  2119. $out = [
  2120. "orderCode" => $orderCode,
  2121. "outCode" => $outCode,
  2122. "apply_id" => $data['rm'],
  2123. "apply_name" => $data['ri'],
  2124. "addrid" => $vmp,
  2125. "post_name" => "",
  2126. "post_code" => "",
  2127. "post_fee" => 0,
  2128. "sendtime" => date("Y-m-d H:i:s"),
  2129. "send_num" => $num,
  2130. "check_num" => 0,
  2131. "error_num" => 0,
  2132. "wsm_code" => $good['is_stock'] == 1 ?'':$cgdinfo['wsm_code'],
  2133. "order_type" => 1,
  2134. "status" => $good['is_stock'] == 1 ? 1 : 0,
  2135. "addtime" => date("Y-m-d H:i:s"),
  2136. "updatetime" => date("Y-m-d H:i:s")
  2137. ];
  2138. $ou = Db::name("order_out")->insertGetId($out);
  2139. if ($ou == false) {
  2140. throw new Exception("发货单生成失败");
  2141. } else {
  2142. if($good['is_stock'] == 1)OrderOutChild::makeChild($outCode);//非库存品无法立即分单
  2143. $standing_book_data['outCode'][] = $outCode;
  2144. //修改状态,添加待办
  2145. if($good['is_stock'] == 1){
  2146. $roleid = config('app.wsm_cgder_role');
  2147. $uids = Db::name('user_role')
  2148. ->where('is_del', 0)
  2149. ->whereIn('roleid', $roleid)
  2150. ->column('uid');
  2151. $handle_user_list=implode(',', $uids);
  2152. }
  2153. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  2154. "order_code" => $outCode,//出库单号
  2155. "status" => 0,//这里的status是之前的值
  2156. "action_remark" => '',//备注
  2157. "action_type" => "create"//新建create,编辑edit,更改状态status
  2158. ], "CKD", 0, $out);
  2159. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  2160. "order_type" => 'CKD',
  2161. "order_code" => $outCode,//出库单号
  2162. "order_id" => $ou,
  2163. "order_status" => $good['is_stock'] == 1 ? 1 : 0,
  2164. "before_status" => 0,
  2165. 'holder_id'=>$out['apply_id'],
  2166. 'handle_user_list' =>$handle_user_list??""
  2167. ]);
  2168. }
  2169. } else {
  2170. throw new Exception("地址录入失败");
  2171. }
  2172. }
  2173. }
  2174. // }
  2175. }
  2176. return true;
  2177. }
  2178. public function list()
  2179. {
  2180. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2181. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2182. $where[] = ['s.is_del', "=", 0];
  2183. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  2184. if ($orderCode !== "") {
  2185. $where[] = ['s.orderCode', "like", "%$orderCode%"];
  2186. }
  2187. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name']) : "";
  2188. if ($apply_name !== "") {
  2189. $where[] = ['s.apply_name', "like", "%$apply_name%"];
  2190. }
  2191. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  2192. if ($good_name !== "") {
  2193. $where[] = ['s.good_name', "like", "%$good_name%"];
  2194. }
  2195. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  2196. if ($good_code !== "") {
  2197. $where[] = ['s.good_code', "like", "%$good_code%"];
  2198. }
  2199. $platform_order = isset($this->post['platform_order']) && $this->post['platform_order'] !== '' ? trim
  2200. ($this->post['platform_order']) : '';
  2201. if ($platform_order !== '') {
  2202. $where[] = ['s.platform_order', 'like', "%$platform_order%"];
  2203. }
  2204. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  2205. if ($customer_code !== "") {
  2206. $where[] = ['s.customer_code', "like", "%$customer_code%"];
  2207. }
  2208. $customer_name = isset($this->post['customer_name']) && $this->post['customer_name'] !== '' ? trim($this->post['customer_name']) : '';
  2209. if ($customer_name !== '') {
  2210. $where[] = ['s.customerName', 'like', "%$customer_name%"];
  2211. }
  2212. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  2213. if ($supplierNo !== "") {
  2214. $where[] = ['s.supplierNo', "=", $supplierNo];
  2215. }
  2216. $relaComNo = trim($this->post['relaComNo']??'');
  2217. if ($relaComNo !== "") {
  2218. $where[] = ['s.supplierNo', "=", $relaComNo];
  2219. }
  2220. $ordertype = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type']) : "";
  2221. if ($ordertype !== "") {
  2222. $where[] = ['s.order_type', "=", $ordertype];
  2223. }
  2224. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  2225. if ($status !== "") {
  2226. $where[] = ['s.status', "=", $status];
  2227. }
  2228. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  2229. if ($start != "") {
  2230. $where[] = ["s.addtime", '>=', $start];
  2231. }
  2232. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  2233. if ($end != "") {
  2234. $end .= " 23:59:59";
  2235. $where[] = ["s.addtime", '<=', $end];
  2236. }
  2237. $use_type = $this->post['use_type']??'';
  2238. if($use_type!=='') $where[]=['e.use_type','=',$use_type];
  2239. $platform_id = $this->post['platform_id']??'';
  2240. if($platform_id!=='') $where[]=['s.platform_id','=',$platform_id];
  2241. $role = $this->checkDataShare();
  2242. $hand = resign_hand_user($this->uid,0);
  2243. if (!empty($role[DataGroupModel::$type_全部])) {
  2244. $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
  2245. $where[] = ['s.apply_id', 'in',$arr];
  2246. }
  2247. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  2248. if ($company_name !== "") $where[] = ["s.apply_id", 'in', get_company_item_user_by_name($company_name)];
  2249. $order_source = isset($this->post['order_source']) && $this->post['order_source'] !== "" ? trim($this->post['order_source']) : "";
  2250. if ($order_source !== "") $where[] = ["s.order_source", '=', $order_source];
  2251. $count = Db::name('sale')
  2252. ->alias('s')
  2253. ->leftJoin('order_num b','b.orderCode=s.orderCode')
  2254. // ->leftJoin('order_use c','c.id=s.use_order')
  2255. ->leftJoin('purchease_order d','d.cgdNo=b.cgdNo')
  2256. ->leftJoin('platform e','e.id=s.platform_id')
  2257. ->where($where)
  2258. ->count();
  2259. $total = ceil($count / $size);
  2260. $page = $page >= $total ? $total : $page;
  2261. $list = Db::name('sale')
  2262. ->alias('s')
  2263. ->field('s.*,b.cgdNo,s.use_order useage,d.status cgd_status,e.use_type,e.platform_name')
  2264. ->leftJoin('order_num b','b.orderCode=s.orderCode')
  2265. // ->leftJoin('order_use c','c.id=s.use_order')
  2266. ->leftJoin('purchease_order d','d.cgdNo=b.cgdNo')
  2267. ->leftJoin('platform e','e.id=s.platform_id')
  2268. ->order("s.addtime desc")
  2269. ->page($page, $size)
  2270. ->where($where)
  2271. ->select()
  2272. ->toArray();
  2273. $all_createrid = array_unique(array_column($list, 'apply_id'));
  2274. $item = get_company_name_by_uid($all_createrid);
  2275. $useAddr = \app\admin\model\OrderUse::where(["is_del"=>1])->column("order_use","id");
  2276. $data = [];
  2277. foreach ($list as $value) {
  2278. $value['useage'] = $useAddr[$value['useage']]??"";
  2279. if ($value['order_type'] == 3 ||$value['order_type']==4) {
  2280. $var = Db::name("good_zixun")->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
  2281. $value["speclist"] = isset($var['specinfo']) && $var['specinfo'] != "" ? json_decode($var['specinfo'], true) : "";
  2282. } else {
  2283. $var = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2284. ->where(['a.skuCode' => $value['skuCode']])->find();
  2285. $spec = Db::name("good_spec")->where(["spuCode" => $var['spuCode'], "is_del" => 0])->select()->toArray();
  2286. $speclist = [];
  2287. if (!empty($spec)) {
  2288. foreach ($spec as $val) {
  2289. $temp = [];
  2290. $temp['id'] = $val['id'];
  2291. $temp['spuCode'] = $val['spuCode'];
  2292. $temp['spec_id'] = $val['spec_id'];
  2293. $temp['spec_value_id'] = $val['spec_value_id'];
  2294. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  2295. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  2296. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  2297. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  2298. $speclist[] = $temp;
  2299. }
  2300. }
  2301. $value["speclist"] = empty($speclist) ? [] : $speclist;
  2302. }
  2303. $value['can'] = isset($var['cat_id']) && $var['cat_id'] != 0 ? made($var['cat_id']) : [];
  2304. $value['good_num'] -= $value['th_num'];
  2305. $value['send_num'] -= $value['th_num'];
  2306. $value['total_price'] = round($value['total_price'] - $value['th_fee'], 2);
  2307. $value['company_name'] = $item[$value['apply_id']]??'';
  2308. //是否具有编辑权限
  2309. $value['is_allow_update'] = 0;
  2310. if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  2311. $data[] = $value;
  2312. }
  2313. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  2314. }
  2315. public function edit()
  2316. {
  2317. // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2318. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  2319. if ($id == "") {
  2320. return error_show(1002, "参数id不能为空");
  2321. }
  2322. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  2323. if (empty($etid)) {
  2324. return error_show(1002, "未找到数据");
  2325. }
  2326. // $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  2327. // if($orderCode==""){
  2328. // return error_show(1002,"销售单code不能为空");
  2329. // }
  2330. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  2331. if ($good_code == "") {
  2332. return error_show(1002, "商品code不能为空");
  2333. }
  2334. $ct = Db::name('good')->alias('a')->join('good_type b', 'b.good_code=a.good_code', 'left')
  2335. ->where(['b.type_code' => $good_code])->find();
  2336. if ($ct == "") {
  2337. return error_show(1002, "未找到商品数据");
  2338. }
  2339. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  2340. if ($customer_code == "") {
  2341. return error_show(1002, "客户code不能为空");
  2342. }
  2343. // $customer = Db::name("customer_info")->where(["companyNo" => $customer_code])->find();
  2344. // if ($customer == false) {
  2345. // return error_show(1004, "未找到客户数据");
  2346. // }
  2347. $supplierNo = $this->post['supplierNo'] && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  2348. if ($supplierNo == "") {
  2349. return error_show(1002, "参数supplierNo不能为空");
  2350. }
  2351. // $supplier = Db::name("supplier")->where(["code" => $supplierNo])->find();
  2352. // if ($supplier == false) {
  2353. // return error_show(1004, "未找到平台供应商数据");
  2354. // }
  2355. // $apply_id = GetUserInfo($token);
  2356. // if (empty($apply_id) || $apply_id['code'] != 0) {
  2357. // return error_show(1002, "申请人数据不存在");
  2358. // }
  2359. $rm = $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2360. $ri = $this->uname;//isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  2361. // $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim
  2362. //($this->post['good_name']) : "";
  2363. // $good_num = isset($this->post['good_num']) && $this->post['good_num'] !== "" ? intval
  2364. //($this->post['good_num']) : "";
  2365. // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !== "" ? intval
  2366. // ($this->post['origin_price']) : "";
  2367. // $sale_price = isset($this->post['sale_price']) && $this->post['sale_price'] !== "" ? trim($this->post['sale_price']) : "";
  2368. // $total_price = isset($this->post['total_price']) && $this->post['total_price'] !== "" ? trim($this->post['total_price']) : "";
  2369. // $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? trim($this->post['post_fee']) : "";
  2370. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  2371. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  2372. if ($vr == "") {
  2373. return error_show(1002, "参数order_addr不能为空");
  2374. }
  2375. $vi = isset($this->post['good_stock']) && $this->post['good_stock'] !== "" ? $this->post['good_stock'] : "";
  2376. if ($vi == "") {
  2377. return error_show(1002, "参数good_stock不能为空");
  2378. }
  2379. $good_num = intval(array_sum(array_column($vi, "num")));
  2380. Db::startTrans();
  2381. try {
  2382. $datn = [
  2383. "id" => $id,
  2384. "good_code" => $good_code,
  2385. "customer_code" => $customer_code,
  2386. "good_num" => $good_num,
  2387. "supplierNo" => $supplierNo,
  2388. "apply_id" => $rm,
  2389. "apply_name" => $ri,
  2390. "is_del" => 0,
  2391. "updatetime" => date("Y-m-d H:i:s")
  2392. ];
  2393. $datninfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($datn);
  2394. if ($datninfo > 0) {
  2395. $stn = ["order_code" => $etid['orderCode'], "status" => $etid['status'], "action_remark" => '', "action_type" => "edit"];
  2396. ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], $stn, "XSQRD", $etid['status'], $datn);
  2397. // $order=["order_type"=>'XSQRD',"order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$etid['status'],"before_status"=> 0];
  2398. // ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$order);
  2399. //更新台账
  2400. Db::name('standing_book')
  2401. ->where('orderCode', $etid['orderCode'])
  2402. ->update([
  2403. 'customer_code' => $customer_code,
  2404. 'supplierNo' => $supplierNo,
  2405. 'updatetime' => date("Y-m-d H:i:s")
  2406. ]);
  2407. foreach ($vi as $ion) {
  2408. $iten = [];
  2409. isset($ion['id']) && $ion['id'] !== "" ? $iten['id'] = $ion['id'] : '';
  2410. $iten['orderCode'] = $etid['orderCode'];
  2411. $iten['wsm_code'] = $ion['wsm_code'];
  2412. $iten['stock_id'] = 0;
  2413. $iten['num'] = $ion['num'];
  2414. $iten['status'] = 1;
  2415. $iten['sale_price'] = $ct['original_price'];
  2416. isset($ion['id']) && $ion['id'] !== "" ? '' : $iten['addtime'] = date("Y-m-d H:i:s");
  2417. $iten['updatetime'] = date("Y-m-d H:i:s");
  2418. $vp = Db::name('sale_info')->save($iten);
  2419. if ($vp == false) {
  2420. Db::rollback();
  2421. return error_show(1002, "更新失败");
  2422. }
  2423. }
  2424. foreach ($vr as $value) {
  2425. $temp = [];
  2426. isset($value['id']) && $value['id'] !== "" ? $temp['id'] = $value['id'] : '';
  2427. $temp['orderCode'] = $etid['orderCode'];
  2428. $temp['contactor'] = $value['contactor'];
  2429. $temp['mobile'] = $value['mobile'];
  2430. $temp['addr'] = $value['addr'];
  2431. $temp['addr_code'] = $value['addr_code'];
  2432. $temp['customer_code'] = $customer_code;
  2433. $temp['receipt_quantity'] = $value['receipt_quantity'];
  2434. $temp['post_fee'] = 0;
  2435. $temp['is_del'] = $value['is_del'];
  2436. isset($value['id']) && $value['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  2437. $temp['updatetime'] = date("Y-m-d H:i:s");
  2438. $temp['arrive_time'] = date("Y-m-d H:i:s");
  2439. $dat = Db::name('order_addr')->save($temp);
  2440. if ($dat == false) {
  2441. Db::rollback();
  2442. return error_show(1002, "更新失败");
  2443. }
  2444. }
  2445. Db::commit();
  2446. return error_show(0, "更新成功");
  2447. }
  2448. Db::rollback();
  2449. return error_show(1002, "更新失败");
  2450. } catch (Exception $e) {
  2451. Db::rollback();
  2452. return error_show(1005, $e->getMessage());
  2453. }
  2454. }
  2455. public function info()
  2456. {
  2457. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2458. if ($id == "") {
  2459. return error_show(1002, "参数id不能为空");
  2460. }
  2461. $einfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  2462. if (empty($einfo)) {
  2463. return error_show(1002, "未找到销售订单数据");
  2464. }
  2465. if ($einfo['order_type'] == 3 || $einfo['order_type']==4) {
  2466. $goon = Db::name("good_zixun")->where(["spuCode" => $einfo['good_code'], "is_del" => 0])->find();
  2467. } else {
  2468. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')->where(['a.skuCode' => $einfo['skuCode']])->find();
  2469. }
  2470. if ($goon == false) {
  2471. return error_show(1003, "未找到商品数据");
  2472. } else {
  2473. $taxInfo=OrderTax::where(['code'=>$einfo['orderCode']])->findOrEmpty();
  2474. $einfo['tax_name'] = $taxInfo['tax_name']??'';
  2475. $einfo['tax_short_name'] =$taxInfo['tax_short_name']??'';
  2476. $einfo['tax_code'] =$taxInfo['tax_code']??'';
  2477. $einfo['tax']=$taxInfo['inv_tax']??'';
  2478. $einfo['inv_good_name']=$taxInfo['inv_good_name']??'';
  2479. $goon['exclusive'] = isset($goon['is_exclusive']) ? makeExcluse($goon['is_exclusive']) : "";
  2480. $unit = Db::name("unit")->where(["id" => $goon['good_unit']])->find();
  2481. $goon['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2482. $spec = Db::name("good_spec")->where(["spuCode" => $goon['spuCode'], "is_del" => 0])->select()->toArray();
  2483. $speclist = [];
  2484. if (!empty($spec)) {
  2485. foreach ($spec as $value) {
  2486. $temp = [];
  2487. $temp['id'] = $value['id'];
  2488. $temp['spuCode'] = $value['spuCode'];
  2489. $temp['spec_id'] = $value['spec_id'];
  2490. $temp['spec_value_id'] = $value['spec_value_id'];
  2491. $temp['is_del'] = $value['is_del'];
  2492. $sp = Db::name("specs")->where(["id" => $value['spec_id']])->find();
  2493. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  2494. $spv = Db::name("spec_value")->where(["id" => $value['spec_value_id']])->find();
  2495. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  2496. $speclist[] = $temp;
  2497. }
  2498. }
  2499. $goon["speclist"] = empty($speclist) ? [] : $speclist;
  2500. $proof = Db::name("good_proof")->where(["spuCode" => $goon['spuCode'], "is_del" => 0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  2501. $goon['proof'] = isset($proof) && $proof != false ? $proof : [];
  2502. $goon['origin_place_cn'] = "";
  2503. $goon['delivery_place_cn'] = "";
  2504. if (isset($goon['delivery_place']) && $goon['delivery_place'] !== "") {
  2505. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2506. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $goon['delivery_place']);
  2507. $goon['delivery_place_cn'] = GetAddr(json_encode($place));
  2508. }
  2509. if (isset($goon['delivery_place']) && $goon['origin_place'] !== "") {
  2510. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2511. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $goon['origin_place']);
  2512. $goon['origin_place_cn'] = GetAddr(json_encode($place));
  2513. }
  2514. if ($goon['brand_id'] != 0) {
  2515. $brand = Db::name("brand")->where(["id" => $goon['brand_id']])->find();
  2516. $goon["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2517. } else {
  2518. $goon["brand_name"] = "";
  2519. $goon["brand_id"] = "";
  2520. }
  2521. $userCommon = \app\admin\common\User::getIns();
  2522. $names = $userCommon->handle('getCodeAndName',['code'=>[
  2523. $goon['supplierNo'],
  2524. $goon['companyNo'],
  2525. $einfo['customer_code'],
  2526. $einfo['supplierNo']
  2527. ]]);
  2528. $goon['supplierName'] = $names['data'][$goon['supplierNo']]??'';//isset($supplier['name']) ? $supplier['name'] : "";
  2529. $goon['noble_name'] = isset($goon['noble_metal']) && $goon['noble_metal'] != 0 ? $this->noble[$goon['noble_metal']] : "";
  2530. $goon['company'] = $names['data'][$goon['companyNo']]??'';//isset($company['company']) ? $company['company'] : "";
  2531. }
  2532. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  2533. // $in = Db::name('customer_info')->where(['companyNo' => $einfo['customer_code']])->field('companyName')->find();
  2534. $einfo['supplierName'] = '';
  2535. if ($einfo['supplierNo'] != "") {
  2536. $einfo['supplierName'] = $names['data'][$einfo['supplierNo']]??'';//isset($supplier['company']) ? $supplier['company'] : "";
  2537. }
  2538. $addr_sum = Db::name('order_addr')->where(['orderCode' => $einfo['orderCode'],"is_del"=>0])->sum('receipt_quantity');
  2539. $einfo['addr_sum']=$addr_sum;
  2540. $addrs = [];
  2541. $einfo['useage'] = "";
  2542. if ($einfo['use_order'] != 0) {
  2543. $use = Db::name("order_use")->where(["id" => $einfo['use_order']])->find();
  2544. $einfo['useage'] = isset($use['order_use']) ? $use['order_use'] : "";
  2545. } else {
  2546. $einfo['use_order'] = '';
  2547. }
  2548. $einfo['platform_name'] = '';
  2549. if ($einfo['platform_id'] != 0) {
  2550. $plat = Db::name("platform")->where(['id' => $einfo['platform_id']])->find();
  2551. $einfo['platform_name'] = isset($plat['platform_name']) ? $plat['platform_name'] : "";
  2552. }
  2553. $einfo['companyName'] = $names['data'][$einfo['customer_code']]??'';//isset($in['companyName']) ? $in['companyName'] : "";
  2554. $einfo['addrs'] = $addrs;
  2555. $einfo['can'] = $int;
  2556. $einfo['goodinfo'] = $goon;
  2557. $einfo['good_num'] -= $einfo['th_num'];
  2558. $einfo['send_num'] -= $einfo['th_num'];
  2559. $einfo['total_price'] = round($einfo['total_price'] - $einfo['th_fee'], 2);
  2560. //处理凭证
  2561. if ($einfo['order_type'] == 1 || $einfo['order_type'] == 2) {
  2562. $proof = Db::name('good_proof')
  2563. ->field('id,proof_type,proof_url')
  2564. ->where(['id' => $einfo['proof_id'], 'is_del' => 0])
  2565. ->find();
  2566. $einfo['proof_type'] = isset($proof['proof_type']) ? $proof['proof_type'] : '';
  2567. $einfo['proof_url'] = isset($proof['proof_url']) ? $proof['proof_url'] : '';
  2568. } elseif ($einfo['order_type'] == 3 ||$einfo['order_type']==4) {
  2569. $einfo['proof_type'] = isset($goon['proof_type']) ? $goon['proof_type'] : '';
  2570. $einfo['proof_url'] = isset($goon['proof_url']) ? $goon['proof_url'] : '';
  2571. } else {
  2572. $einfo['proof_type'] = '';
  2573. $einfo['proof_url'] = '';
  2574. }
  2575. if (empty($einfo)) {
  2576. return error_show(1002, "未找到销售订单数据");
  2577. } else {
  2578. return app_show(0, "获取成功", $einfo);
  2579. }
  2580. }
  2581. public function del()
  2582. {
  2583. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2584. if ($id === "") {
  2585. return error_show(1002, "参数id不能为空");
  2586. }
  2587. $ed = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  2588. if (empty($ed)) {
  2589. return error_show(1002, "未找到销售订单数据");
  2590. }
  2591. $str = Db::name('sale')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  2592. if ($str) {
  2593. $stc = ["order_code" => $id, "status" => $ed['status'], "action_remark" => '', "action_type" => "delete"];
  2594. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stc, "XSQRD", $ed['status'], ['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  2595. $order = ["order_type" => 'XSQRD', "order_code" => $ed['orderCode'], "order_id" => $id, "order_status" => $ed['status'],'holder_id' => $ed['apply_id']
  2596. ];
  2597. ProcessOrder::workdel($order);
  2598. return error_show(0, "删除成功");
  2599. } else {
  2600. return error_show(1002, "删除失败");
  2601. }
  2602. }
  2603. //废弃接口
  2604. public function status()
  2605. {
  2606. // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2607. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2608. if ($id == "") {
  2609. return error_show(1002, "参数id不能为空");
  2610. }
  2611. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  2612. if ($status == "") {
  2613. return error_show(1002, "订单状态不能为空");
  2614. }
  2615. $dio = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  2616. if (empty($dio)) {
  2617. return error_show(1002, "销售单信息未找到");
  2618. }
  2619. if ($status == 1 && $dio['order_type'] == 2) {
  2620. $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
  2621. if ($zxinfo == false) {
  2622. return error_show(1004, "未找到咨询单数据");
  2623. }
  2624. $gold['price'] = 0;
  2625. if ($zxinfo['zx_type'] == 2) {
  2626. if ($zxinfo['metals'] == "") {
  2627. return error_show(1004, "未找到咨询单贵金属类型数据");
  2628. }
  2629. $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
  2630. $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
  2631. if (empty($gold)) {
  2632. return error_show(1004, "未找到咨询单贵金属类型数据");
  2633. }
  2634. $dio['gold_price'] = $gold['price'];
  2635. }
  2636. $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
  2637. if (empty($wsm)) {
  2638. return error_show(1002, "供应商仓库未找到");
  2639. }
  2640. }
  2641. // $apply_id = GetUserInfo($token);
  2642. // if (empty($apply_id) || $apply_id['code'] != 0) {
  2643. // return error_show(1002, "申请人数据不存在");
  2644. // }
  2645. $rm = $this->uid;
  2646. $ri = $this->uname;
  2647. Db::startTrans();
  2648. try {
  2649. $vmp = $dio['status'];
  2650. $dio['status'] = $status;
  2651. $dio['updatetime'] = date("Y-m-d H:i:s");
  2652. $st = Db::name('sale')->save($dio);
  2653. if ($st) {
  2654. $stn = ["order_code" => $dio['orderCode'], "status" => $vmp, "action_remark" => '', "action_type" => "status"];
  2655. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stn, $dio['order_type'] == 2 ? "ZXQRD" : "XSQRD", $dio['status'], $dio);
  2656. $order = ["order_type" => "XSQRD", "order_code" => $dio['orderCode'], "order_id" => $id, "order_status" => $dio['status'], "before_status" => 1,'holder_id' => $dio['apply_id']];
  2657. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
  2658. if ($status == 3 && $dio['order_type'] == 1) {
  2659. $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
  2660. foreach ($dn as $value) {
  2661. $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
  2662. if ($dm == "") {
  2663. Db::rollback();
  2664. return error_show(1003, "未找到商品数据");
  2665. }
  2666. if ($value['num'] > $dm['usable_stock']) {
  2667. Db::rollback();
  2668. return error_show(1002, "超出库存数量");
  2669. }
  2670. $dm['usable_stock'] -= $value['num'];
  2671. $dm['wait_out_stock'] += $value['num'];
  2672. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], "is_del" => 0])->sum("send_num");
  2673. $value['send_num'] = $send ?? 0;
  2674. $value['wsend_num'] = $value['num'] - $value['send_num'];
  2675. $Db = Db::name('good_stock')->update($dm);
  2676. $Db['updatetime'] = date('Y-m-d H:i:s');
  2677. if ($Db == false) {
  2678. Db::rollback();
  2679. return error_show(1002, "状态更新失败");
  2680. }
  2681. }
  2682. }
  2683. if ($status == 1 && $dio['order_type'] == 2) {
  2684. $cgd = makeNo("CG");
  2685. $clll = [
  2686. "cgdNo" => $cgd,
  2687. "bkcode" => $dio['orderCode'],
  2688. "wsm_code" => $wsm['wsm_code'],
  2689. "cgder_id" => Db::name('depart_user')->where('nickname', $zxinfo['saler'])->value('uid') ?? 0,//重名以及多个账号的话…………
  2690. "cgder" => $zxinfo['saler'],
  2691. "good_code" => "GD-" . $zxinfo['cpNo'],
  2692. "good_name" => $zxinfo['cpName'],
  2693. "good_type_code" => $zxinfo['cpNo'],
  2694. "good_num" => $dio['good_num'],
  2695. "good_price" => $zxinfo['total_fee'],
  2696. "total_fee" => round($zxinfo['total_fee'] * $dio['good_num'], 2),
  2697. "pakge_fee" => $zxinfo['package_fee'],
  2698. "cert_fee" => $zxinfo['cert_fee'],
  2699. "open_fee" => $zxinfo['open_fee'],
  2700. "delivery_fee" => $zxinfo['delivery_fee'],
  2701. "mark_fee" => $zxinfo['mark_fee'],
  2702. "teach_fee" => $zxinfo['cost_fee'],
  2703. "demo_fee" => $zxinfo['demo_fee'],
  2704. "nake_fee" => $zxinfo['bare_fee'],
  2705. "weight" => isset($zxinfo['weight']) ? $zxinfo['weight'] : 0,
  2706. "supplierNo" => $zxinfo['gysNo'],
  2707. "supplier_name" => $zxinfo['gysname'],
  2708. "gold_price" => $gold['price'],
  2709. "send_num" => 0,
  2710. "wsend_num" => $dio['good_num'],
  2711. "remark" => '',
  2712. "lasttime" => date("Y-m-d H:i:s"),
  2713. "is_del" => 0,
  2714. "status" => $dio['send_type'] == 1 ? 3 : 0,
  2715. "order_type" => 2,
  2716. "order_source" => 3,//3项目,废弃接口???
  2717. "addtime" => date("Y-m-d H:i:s"),
  2718. "updatetime" => date("Y-m-d H:i:s")
  2719. ];
  2720. $cgin = Db::name("purchease_order")->insert($clll);
  2721. // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
  2722. if ($cgin == false) {
  2723. $stb = ["order_code" => $cgd, "status" => $clll['status'], "action_remark" => '', "action_type" => "create"];
  2724. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stb, "xsd", $clll['status'], $stb);
  2725. Db::rollback();
  2726. return error_show(1002, "咨询采购单创建商品失败");
  2727. }
  2728. if ($dio['send_type'] == 1) {
  2729. $addr = Db::name('order_addr')->where(["orderCode" => $dio['orderCode'], 'is_del' => 0])->select();
  2730. $i = 1;
  2731. foreach ($addr as $value) {
  2732. $outCode = makeNo("DF");
  2733. //改变编码规则,将原来的outCode后两位换成序列号
  2734. //str_pad字符串填充
  2735. $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  2736. $i++;
  2737. $data = [
  2738. "wsm_code" => $wsm['wsm_code'],
  2739. "orderCode" => $dio['orderCode'],
  2740. "outCode" => $outCode,
  2741. "order_type" => $dio['order_type'],
  2742. "apply_id" => $rm,
  2743. "apply_name" => $ri,
  2744. "addrid" => $value['id'],
  2745. "post_name" => '',
  2746. "post_code" => '',
  2747. "post_fee" => '',
  2748. "sendtime" => date("Y-m-d H:i:s"),
  2749. "send_num" => $value['receipt_quantity'],
  2750. "check_num" => 0,
  2751. "error_num" => 0,
  2752. "status" => 0,
  2753. "addtime" => date("Y-m-d H:i:s"),
  2754. "updatetime" => date("Y-m-d H:i:s")
  2755. ];
  2756. $datainfo = Db::name('order_out')->insertGetId($data);
  2757. if (!$datainfo) {
  2758. $sti = ["order_code" => $dio['orderCode'], "status" => 0, "action_remark" => '', "action_type" => "create"];
  2759. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $sti, "xsd", 0, $sti);
  2760. Db::rollback();
  2761. return error_show(1003, "创建失败");
  2762. } else {
  2763. //修改状态,添加待办
  2764. ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
  2765. "order_code" => $outCode,//出库单号
  2766. "status" => 0,//这里的status是之前的值
  2767. "action_remark" => '',//备注
  2768. "action_type" => "create"//新建create,编辑edit,更改状态status
  2769. ], "CKD", 0, $data);
  2770. ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], [
  2771. "order_type" => 'CKD',
  2772. "order_code" => $outCode,//出库单号
  2773. "order_id" => $datainfo,
  2774. "order_status" => 0,
  2775. "before_status" => 0,
  2776. 'holder_id'=>$data['apply_id'],
  2777. ]);
  2778. }
  2779. }
  2780. $wsm_in_code = makeNo("CF");
  2781. $orin = [
  2782. "wsm_in_code" => $wsm_in_code,
  2783. "cgdNo" => $cgd,
  2784. "wsm_code" => $wsm['wsm_code'],
  2785. "wsm_reaper" => "",
  2786. "send_num" => $dio['good_num'],
  2787. "post_company" => '',
  2788. "post_code" => '',
  2789. "post_fee" => '',
  2790. "sendtime" => date("Y-m-d H:i:s"),
  2791. "apply_id" => $rm,
  2792. "apply_name" => $ri,
  2793. "wait_num" => 0,
  2794. "status" => 4,
  2795. "addtime" => date("Y-m-d H:i:s"),
  2796. "updatetime" => date("Y-m-d H:i:s")
  2797. ];
  2798. $win = Db::name("purchease_in")->insert($orin);
  2799. if (!$win) {
  2800. $stv = ["order_code" => $wsm_in_code, "status" => 4, "action_remark" => '', "action_type" => "create"];
  2801. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stv, "xsd", 4, $stv);
  2802. Db::rollback();
  2803. return error_show(1003, "创建失败");
  2804. }
  2805. //维护台账
  2806. Db::execute("UPDATE `wsm_standing_book` SET `wsm_in_code`=CONCAT(IFNULL(`wsm_in_code`,''),',{$wsm_in_code}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `cgdNo`='{$cgd}'");
  2807. $good = Db::name("good_stock")->where(["wsm_code" => $wsm['wsm_code'], "good_type_code" => $zxinfo['cpNo'], "is_del" => 0])->find();
  2808. if (empty($good)) {
  2809. $good = [
  2810. "good_type_code" => $zxinfo['cpNo'],
  2811. "wsm_code" => $wsm['wsm_code'],
  2812. "usable_stock" => 0,
  2813. "wait_out_stock" => 0,
  2814. "total_stock" => 0,
  2815. "addtime" => date("Y-m-d H:i:s"),
  2816. "updatetime" => date("Y-m-d H:i:s"),
  2817. ];
  2818. }
  2819. $good['wait_out_stock'] += $dio['good_num'];
  2820. $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
  2821. $good['updatetime'] = date("Y-m-d H:i:s");
  2822. $upd = Db::name("good_stock")->save($good);
  2823. if (!$upd) {
  2824. $ste = ["order_code" => $zxinfo['cpNo'], "status" => 0, "action_remark" => '', "action_type" => "create"];
  2825. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $ste, "xsd", 0, $ste);
  2826. Db::rollback();
  2827. return error_show(1003, "创建失败");
  2828. }
  2829. }
  2830. }
  2831. }
  2832. Db::commit();
  2833. return error_show(0, "订单状态更新成功");
  2834. } catch (Exception $e) {
  2835. Db::rollback();
  2836. return error_show(1005, $e->getMessage());
  2837. }
  2838. }
  2839. public function fee()
  2840. {
  2841. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  2842. if ($id == "") {
  2843. return error_show(1002, "参数id不能为空");
  2844. }
  2845. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  2846. if (empty($etid)) {
  2847. return error_show(1002, "未找到数据");
  2848. }
  2849. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  2850. if ($vr == "") {
  2851. return error_show(1002, "参数order_addr不能为空");
  2852. }
  2853. Db::startTrans();
  2854. try {
  2855. $data = [
  2856. "id" => $id,
  2857. "status" => 2,
  2858. "is_del" => 0,
  2859. "updatetime" => date("Y-m-d H:i:s")
  2860. ];
  2861. $datainfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($data);
  2862. if ($datainfo) {
  2863. $stx = ["order_code" => $etid['orderCode'], "status" => $etid['status'], "action_remark" => '', "action_type" => "edit"];
  2864. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, "XSQRD", 2, $data);
  2865. $order = ["order_type" => "XSQRD", "order_code" => $etid['orderCode'], "order_id" => $id, "order_status" => $data['status'], "before_status" => 0,'holder_id'=>$etid['apply_id']];
  2866. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
  2867. foreach ($vr as $value) {
  2868. $tm = [];
  2869. $tm['id'] = $value['id'];
  2870. $tm['orderCode'] = $etid['orderCode'];
  2871. $tm['post_fee'] = $value['post_fee'];
  2872. $tm['updatetime'] = date("Y-m-d H:i:s");
  2873. $dn = Db::name('order_addr')->save($tm);
  2874. if ($dn == false) {
  2875. Db::rollback();
  2876. return error_show(1002, "更新失败");
  2877. }
  2878. }
  2879. Db::commit();
  2880. return error_show(0, "更新成功");
  2881. }
  2882. Db::rollback();
  2883. return error_show(1003, "更新失败");
  2884. } catch (Exception $e) {
  2885. Db::rollback();
  2886. return error_show(1005, $e->getMessage());
  2887. }
  2888. }
  2889. // 废弃
  2890. public function out()
  2891. {
  2892. // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2893. $outCode = makeNo("DF");
  2894. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  2895. if ($orderCode == "") {
  2896. return error_show(1002, "参数orderCoder不能为空");
  2897. }
  2898. $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
  2899. if ($der == "") {
  2900. return error_show(1002, "未找到出库订单单号");
  2901. }
  2902. // $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  2903. // if ($wsm_code == "") {
  2904. // return error_show(1002, "参数wsm_code不能为空");
  2905. // }
  2906. // $wsm = Db::name('sale_info')->where(['wsm_code' => $wsm_code, 'orderCode' => $der['orderCode']])->find();
  2907. // if ($wsm == "") {
  2908. // return error_show(1002, "未找到仓库编码");
  2909. // }
  2910. $post_name = isset($this->post['post_name']) && $this->post['post_name'] !== "" ? trim($this->post['post_name']) : "";
  2911. if ($post_name == "") {
  2912. return error_show(1002, "物流公司不能为空");
  2913. }
  2914. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
  2915. if ($post_code == "") {
  2916. return error_show(1002, "物流单号不能为空");
  2917. }
  2918. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
  2919. if ($post_fee == "") {
  2920. return error_show(1002, "物流费不能为空");
  2921. }
  2922. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  2923. if ($send_num == "") {
  2924. return error_show(1002, "发货数量不能为空");
  2925. }
  2926. if ($send_num > $der['wsend_num']) {
  2927. return error_show(1002, "超出可发货数量");
  2928. }
  2929. // $apply_id = GetUserInfo($token);
  2930. // if (empty($apply_id) || $apply_id['code'] != 0) {
  2931. // return error_show(1002, "申请人数据不存在");
  2932. // }
  2933. $rm = $this->uid;
  2934. $ri = $this->uname;
  2935. $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
  2936. $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
  2937. if (empty($dr)) {
  2938. return error_show(1003, "收货人信息未找到");
  2939. }
  2940. if ($dr['orderCode'] !== $orderCode) {
  2941. return error_show(1002, "订单code不存在");
  2942. }
  2943. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  2944. // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
  2945. // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
  2946. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "1";
  2947. //$order_type = isset($this->post['order_type']) && $this->post['order_type'] !=="" ? $this->post['order_type'] :"1";
  2948. //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
  2949. Db::startTrans();
  2950. try {
  2951. $data = [
  2952. "wsm_code" => "",
  2953. "orderCode" => $orderCode,
  2954. "outCode" => $outCode,
  2955. "order_type" => $der['order_type'],
  2956. "apply_id" => $rm,
  2957. "apply_name" => $ri,
  2958. "addrid" => $dr['id'],
  2959. "post_name" => $post_name,
  2960. "post_code" => $post_code,
  2961. "post_fee" => $post_fee,
  2962. "sendtime" => $sendtime,
  2963. "send_num" => $send_num,
  2964. "check_num" => 0,
  2965. "error_num" => 0,
  2966. "status" => $status,
  2967. "addtime" => date("Y-m-d H:i:s"),
  2968. "updatetime" => date("Y-m-d H:i:s")
  2969. ];
  2970. $datainfo = Db::name('order_out')->insert($data, true);
  2971. if ($datainfo > 0) {
  2972. $stx = ["order_code" => $outCode, "status" => $status, "action_remark" => '', "action_type" => "create"];
  2973. ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], $stx, $der['order_type'] == 1 ? "CKD" : 'ZXCKD', $status, $data);
  2974. //是否库存品,待办数据推送到的人有区别,
  2975. //库存品——>推到库管,非库存品——>推送供应商负责人
  2976. $order=[];
  2977. if($data['status'] == 1){
  2978. if($der['is_stock'] == 1){
  2979. //库存品,推给库管和库管-张凯旋
  2980. $roleid = config('app.wsm_cgder_role');
  2981. $uids = Db::name('user_role')
  2982. ->where('is_del', 0)
  2983. ->whereIn('roleid', $roleid)
  2984. ->column('uid');
  2985. $order = ["order_type" => "CKD", "order_code" => $outCode, "order_id" => $datainfo, "order_status" => $data['status'], "before_status" => 0, 'handle_user_list' => implode(',', $uids)];
  2986. }else{
  2987. //推给供应商负责人 ###todo::接口废弃
  2988. $supplier = Db::name('supplier')
  2989. ->alias('a')
  2990. ->field('a.id,a.person,a.personid')
  2991. ->leftJoin('purchease_order b', 'b.is_del=0 AND b.supplierNo=a.code')
  2992. ->leftJoin('order_num c', 'c.cgdNo=b.cgdNo')
  2993. ->where('c.orderCode', $orderCode)
  2994. ->findOrEmpty();
  2995. $order = ["order_type" => "CKD", "order_code" => $outCode, "order_id" => $datainfo, "order_status" => $data['status'], "before_status" => 0, 'holder_id' => $data['apply_id'], 'wait_id' => $supplier['personid'] ?? 0, 'wait_name' => $supplier['person'] ?? ''];
  2996. }
  2997. }
  2998. if(empty($order)) $order = ["order_type" => "CKD", "order_code" => $outCode, "order_id" => $datainfo, "order_status" => $data['status'], "before_status" => 0, 'holder_id' => $data['apply_id']];
  2999. ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], $order);
  3000. if ($status == 1) {
  3001. $item = $der['status'];
  3002. $der['send_num'] += $send_num;
  3003. $der['wsend_num'] -= $send_num;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  3004. $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
  3005. $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
  3006. $der['updatetime'] = date("Y-m-d H:i:s");
  3007. $si = Db::name('sale')->save($der);
  3008. if ($si == false) {
  3009. Db::rollback();
  3010. return error_show(1003, "更新失败");
  3011. }
  3012. $stx = ["order_code" => $orderCode, "status" => $item, "action_remark" => '', "action_type" => "edit"];
  3013. ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], $stx, "XSQRD", $der['status'], $der);
  3014. $order = ["order_type" => "XSQRD", "order_code" => $orderCode, "order_id" => $der['id'], "order_status" => $data['status'], "before_status" => 0,'holder_id'=>$der['apply_id']];
  3015. ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], $order);
  3016. }
  3017. Db::commit();
  3018. return error_show(0, "创建成功");
  3019. } else {
  3020. Db::rollback();
  3021. return error_show(1003, "创建失败");
  3022. }
  3023. } catch (Exception $e) {
  3024. Db::rollback();
  3025. return error_show(1005, $e->getMessage());
  3026. }
  3027. }
  3028. // 废弃
  3029. public function customer()
  3030. {
  3031. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  3032. if (empty($outCode)) {
  3033. return error_show(1002, "销售订单编号不能为空");
  3034. }
  3035. $codeinfo = Db::name('order_out')->where(['outCode' => $outCode])->find();
  3036. if ($codeinfo == "") {
  3037. return error_show(1003, "未找到订单数据");
  3038. }
  3039. // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  3040. // if($orderCode==""){
  3041. // return error_show(1002,"参数orderCoder不能为空");
  3042. // }
  3043. $dr = Db::name('sale')->where(['orderCode' => $codeinfo['orderCode']])->find();
  3044. if ($dr == "") {
  3045. return error_show(1002, "未找到销售订单");
  3046. }
  3047. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "";
  3048. if ($status == "") {
  3049. return error_show(10002, "状态不能为空");
  3050. }
  3051. Db::startTrans();
  3052. try {
  3053. $time = $codeinfo['status'];
  3054. $codeinfo['status'] = $status;
  3055. $codeinfo['updatetime'] = date("Y-m-d H:i:s");
  3056. $cust = Db::name('order_out')->save($codeinfo);
  3057. if ($cust) {
  3058. $stx = ["order_code" => $outCode, "status" => $time, "action_remark" => '', "action_type" => "status"];
  3059. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, "CKD", $codeinfo['status'], $codeinfo);
  3060. $order = [];
  3061. if ($status == 1) {
  3062. //推给供应商负责人#todo::接口废弃
  3063. if ($dr['is_stock'] == 0) {
  3064. $supplier = Db::name('supplier')
  3065. ->alias('a')
  3066. ->field('a.id,a.person,a.personid')
  3067. ->leftJoin('purchease_order b', 'b.is_del=0 AND b.supplierNo=a.code')
  3068. ->leftJoin('order_num c', 'c.cgdNo=b.cgdNo')
  3069. ->where('c.orderCode', $codeinfo['orderCode'])
  3070. ->findOrEmpty();
  3071. $order = ["order_type" => "CKD", "order_code" => $outCode, "order_id" => $codeinfo['id'], "order_status" => $codeinfo['status'], "before_status" => 0, 'holder_id' => $codeinfo['apply_id'], 'wait_id' => $supplier['personid'] ?? 0, 'wait_name' => $supplier['person'] ?? ''];
  3072. } else{
  3073. $roleid = config('app.wsm_cgder_role');
  3074. $uids = Db::name('user_role')
  3075. ->where('is_del', 0)
  3076. ->whereIn('roleid', $roleid)
  3077. ->column('uid');
  3078. $order = ["order_type" => "CKD", "order_code" => $outCode, "order_id" => $codeinfo['id'], "order_status" => $codeinfo['status'], "before_status" => 0, 'handle_user_list' => implode(',', $uids)];
  3079. }
  3080. }
  3081. if (empty($order)) $order = ["order_type" => "CKD", "order_code" => $outCode, "order_id" => $codeinfo['id'], "order_status" => $codeinfo['status'], "before_status" => 0, 'holder_id' => $codeinfo['apply_id']];
  3082. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
  3083. if ($status == 1) {
  3084. $stokc = Db::name("good_stock")->where(['spuCode' => $codeinfo['spuCode'], "wsm_code" => $codeinfo['wsm_code'],
  3085. "is_del" => 0])->find();
  3086. if ($stokc == false) {
  3087. Db::rollback();
  3088. return error_show(1002, "未找库存到数据");
  3089. } else {
  3090. if ($codeinfo['send_num'] > $stokc['usable_stock']) {
  3091. Db::rollback();
  3092. return error_show(1002, "超出库存数量");
  3093. }
  3094. $stokc['wait_out_stock'] += $codeinfo['send_num'];
  3095. $stokc['usable_stock'] -= $codeinfo['send_num'];
  3096. $stokc['updatetime'] = date("Y-m-d H:i:s");
  3097. }
  3098. $stoc = Db::name("good_stock")->save($stokc);
  3099. if ($stoc == false) {
  3100. Db::rollback();
  3101. return error_show(1002, "库存更新失败");
  3102. }
  3103. $item = $dr['status'];
  3104. $dr['send_num'] += $codeinfo['send_num'];
  3105. $dr['wsend_num'] -= $codeinfo['send_num'];//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  3106. $dr['send_status'] = $dr['send_num'] == 0 ? 1 : $dr['wsend_num'] == 0 ? 3 : 2;
  3107. $dr['status'] = $dr['send_num'] == 0 ? 3 : $dr['wsend_num'] == 0 ? 5 : 4;
  3108. $dr['updatetime'] = date("Y-m-d H:i:s");
  3109. $si = Db::name('sale')->save($dr);
  3110. if ($si == false) {
  3111. Db::rollback();
  3112. return error_show(1003, "更新失败");
  3113. }
  3114. $stx = ["order_code" => $dr['orderCode'], "status" => $item, "action_remark" => '', "action_type" => "edit"];
  3115. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, $dr['order_type'] == 2 ? "ZXQRD" : "XSQRD", $dr['status'],$dr);
  3116. $order = ["order_type" => "XSQRD", "order_code" => $dr['orderCode'], "order_id" => $dr['id'], "order_status" => $dr['status'], "before_status" => 0, 'holder_id' => $dr['apply_id']];
  3117. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
  3118. //商品变动日志表,good_log_code字段存储销售订单编号
  3119. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stoc['id'], "type" => 1, 'stock' => $codeinfo['send_num'], "stock_name" => "wait_out_stock"];
  3120. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stoc['id'], "type" => 2, 'stock' => $codeinfo['send_num'], "stock_name" => "usable_stock"];
  3121. GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname], $good_data, 'CKD');
  3122. }
  3123. if ($status == 3) {
  3124. $var = Db::name('good_stock')->where(['wsm_code' => $codeinfo['wsm_code'], 'good_type_code' => $dr['good_code']])->find();
  3125. if ($var == false) {
  3126. Db::rollback();
  3127. return error_show(1002, "未找到商品数据");
  3128. }
  3129. if ($codeinfo['send_num'] > $var['intra_stock']) {
  3130. Db::rollback();
  3131. return error_show(1003, "超出在途库存数量");
  3132. }
  3133. $var['intra_stock'] -= $codeinfo['send_num'];
  3134. $var['updatetime'] = date("Y-m-d H:i:s");
  3135. $stre = Db::name('good_stock')->save($var);
  3136. //商品变动日志表,good_log_code字段存储销售订单编号
  3137. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $var['id'], "type" => 2, 'stock' => $codeinfo['send_num'], "stock_name" => "intra_stock"];
  3138. GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname], $good_data, $codeinfo['order_type'] == 2 ? "ZXCKD" : "CKD");
  3139. if ($stre == false) {
  3140. Db::rollback();
  3141. return error_show(1002, "状态更新失败");
  3142. }
  3143. }
  3144. Db::commit();
  3145. return error_show(0, "出库订单更新成功");
  3146. } else {
  3147. Db::rollback();
  3148. return error_show(1003, "出库订单更新失败");
  3149. }
  3150. } catch (Exception $e) {
  3151. Db::rollback();
  3152. return error_show(1005, $e->getMessage());
  3153. }
  3154. }
  3155. public function difflist()
  3156. {
  3157. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  3158. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  3159. $where = [];
  3160. $cgdNo = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
  3161. if ($cgdNo != "") {
  3162. $where[] = ['a.orderCode', "like", "%$cgdNo%"];
  3163. }
  3164. $diffNo = isset($this->post['diffCode']) && $this->post['diffCode'] != "" ? trim($this->post['diffCode']) : "";
  3165. if ($diffNo != "") {
  3166. $where[] = ['a.diffCode', "like", "%$diffNo%"];
  3167. }
  3168. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  3169. if ($status !== "") {
  3170. $where[] = ['a.status', "=", $status];
  3171. }
  3172. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  3173. if ($start != "") {
  3174. $where[] = ["a.addtime", '>=', $start];
  3175. }
  3176. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  3177. if ($end != "") {
  3178. $where[] = ["a.addtime", '<=', $end];
  3179. }
  3180. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  3181. if ($companyNo != "") {
  3182. $where[] = ['a.companyNo', "like", "%$companyNo%"];
  3183. }
  3184. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  3185. if ($customer_code != "") {
  3186. $where[] = ['a.customerNo', "like", "%$customer_code%"];
  3187. }
  3188. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  3189. if ($supplierNo != "") {
  3190. $where[] = ['a.supplierNo', "like", "%$supplierNo%"];
  3191. }
  3192. $relaComNo = trim($this->post['relaComNo'] ?? '');
  3193. if ($relaComNo !== "") {
  3194. $where[] = ['a.companyNo', "=", $relaComNo];
  3195. }
  3196. $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? trim($this->post['order_source']) : "";
  3197. if ($order_source !== "") {
  3198. $where[] = ['c.order_source', "=", $order_source];
  3199. }
  3200. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] != "" ? trim($this->post['is_stock']) : "";
  3201. if ($is_stock !== "") {
  3202. $where[] = ['c.is_stock', "=", $is_stock];
  3203. }
  3204. // $role=$this->checkRole();
  3205. // if(!empty($role['write'])){
  3206. // $where[]=["apply_id","in",$role['write']];
  3207. // }
  3208. // $role = $this->checkDataShare();
  3209. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['c.apply_id', 'in', $role[DataGroupModel::$type_全部]];
  3210. $role = $this->checkDataShare();
  3211. $hand = resign_hand_user($this->uid, 0);
  3212. if (!empty($role[DataGroupModel::$type_全部])) {
  3213. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  3214. $where[] = ['c.apply_id', 'in', $arr];
  3215. }
  3216. // if(!empty($role['platform']) ){
  3217. // $where[]=["c.platform_id","in",$role['platform']];
  3218. // }
  3219. $count = Db::name('sale_diff')
  3220. ->alias('a')
  3221. ->join("sale c", "c.orderCode=a.orderCode", "left")
  3222. // ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  3223. ->where($where)
  3224. ->count();
  3225. $total = ceil($count / $size);
  3226. $page = $page >= $total ? intval($total) : $page;
  3227. $list = Db::name('sale_diff')
  3228. ->alias('a')
  3229. ->field("a.*,c.skuCode,c.order_type,c.apply_id,c.order_source,c.is_stock")
  3230. ->join("sale c", "c.orderCode=a.orderCode", "left")
  3231. // ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  3232. ->where($where)
  3233. ->page($page, $size)
  3234. ->order("a.addtime desc")
  3235. ->select()
  3236. ->toArray();
  3237. $data = [];
  3238. // $userCommon = \app\admin\common\User::getIns();
  3239. // $names = $userCommon->handle('getCodeAndName',['code'=>array_merge(array_column($list,'supplierNo'),array_column($list,'customer_code'))]);
  3240. foreach ($list as $value) {
  3241. if (in_array($value['order_type'], [3, 4])) {
  3242. $goon = Db::name("good_zixun")->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
  3243. } else {
  3244. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  3245. ->where(['a.skuCode' => $value['skuCode']])->find();
  3246. }
  3247. $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  3248. // $wsm = Db::name("business")->where(['companyNo' => $value['supplierNo']])->find();
  3249. // $value['supplierNo'] = $value['supplierNo'];//isset($wsm['companyNo']) ? $wsm['companyNo'] : "";
  3250. // $value['supplierName'] = $names['data'][$value['supplierNo']] ?? '';//isset($wsm['company']) ? $wsm['company'] : "";
  3251. // $value['customer_name'] = $names['data'][$value['customer_code']] ?? '';//isset($wsm['company']) ? $wsm['company'] : "";
  3252. //是否具有编辑权限
  3253. $value['is_allow_update'] = 0;
  3254. if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  3255. $data[] = $value;
  3256. }
  3257. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  3258. }
  3259. /**
  3260. * @return \think\response\Json|void
  3261. * @throws \think\db\exception\DataNotFoundException
  3262. * @throws \think\db\exception\DbException
  3263. * @throws \think\db\exception\ModelNotFoundException
  3264. */
  3265. //工差单审核
  3266. public function diffcheck()
  3267. {
  3268. // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  3269. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  3270. if ($id === "") {
  3271. return error_show(1004, "参数id不能为空");
  3272. }
  3273. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  3274. if (empty($info)) {
  3275. return error_show(1004, "订单数据未找到");
  3276. }
  3277. $sale = Db::name("sale")->where(["orderCode" => $info["orderCode"]])->find();
  3278. if ($sale == false) {
  3279. return error_show(1004, "订单数据未找到");
  3280. }
  3281. $cgd = Db::name("purchease_diff")->where(['id' => $info['cgd_diffid']])->find();
  3282. if ($cgd == false) {
  3283. return error_show(1004, "采购工差单数据未找到");
  3284. }
  3285. $is_act = isset($this->post['is_act']) && $this->post['is_act'] !== "" ? intval($this->post['is_act']) : "";
  3286. if ($is_act === '') {
  3287. return error_show(1004, "参数is_act不能为空");
  3288. }
  3289. $customer_remark = isset($this->post['customer_remark']) && $this->post['customer_remark'] !== "" ? trim($this->post['customer_remark']) : "";
  3290. if ($customer_remark === '') {
  3291. return error_show(1004, "参数customer_remark不能为空");
  3292. }
  3293. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "2";
  3294. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  3295. $item = $info['status'];
  3296. $info['is_act'] = $is_act;
  3297. $info['customer_remark'] = $customer_remark;
  3298. $info['status'] = $status;
  3299. $info['remark'] = $remark;
  3300. $info['updatetime'] = date("Y-m-d H:i:s");
  3301. Db::startTrans();
  3302. try {
  3303. $up = Db::name("sale_diff")->save($info);
  3304. if ($up) {
  3305. $stx = ["order_code" => $info["orderCode"], "status" => $item, "action_remark" => '', "action_type" => "edit"];
  3306. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, "XSGCD", $info['status'], $info);
  3307. $order = ["order_type" => "XSGCD", "order_code" => $info["orderCode"], "order_id" => $info['id'], "order_status" => $info['status'], "before_status" => $item,'holder_id'=>$sale['apply_id']];
  3308. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
  3309. $upda = [
  3310. "status" => $status,
  3311. "remark" => $remark,
  3312. "updatetime" => date("Y-m-d H:i:s"),
  3313. ];
  3314. $old_purchease_diff = Db::name("purchease_diff")
  3315. ->field('id,cgdNo,status')
  3316. ->where(["id" => $info['cgd_diffid']])
  3317. ->find();
  3318. $cgdup = Db::name("purchease_diff")->where(["id" => $info['cgd_diffid']])->save($upda);
  3319. if ($cgdup) {
  3320. if ($status == 2) {
  3321. if ($customer_remark == 1) {
  3322. $sale['diff_weight'] = $info['diff_weight'];
  3323. $sale['diff_fee'] = $info['diff_price'];
  3324. $sale['updatetime'] = date("Y-m-d H:i:s");
  3325. $sal = Db::name("sale")->save($sale);
  3326. if ($sal == false) {
  3327. Db::rollback();
  3328. return error_show(1003, "订单更新工差失败");
  3329. }
  3330. }
  3331. $cgdup = Db::name("purchease_order")->where(["cgdNo" => $cgd['cgdNo']])->save
  3332. (["diff_weight" => $cgd['diff_weight'], "diff_fee" => $cgd['diff_price'], "updatetime" => date("Y-m-d H:i:s")]);
  3333. if ($cgdup == false) {
  3334. Db::rollback();
  3335. return error_show(1003, "采购订单更新工差失败");
  3336. }
  3337. }
  3338. $a = ["order_code" => $old_purchease_diff["cgdNo"], "status" => $old_purchease_diff['status'], "action_remark" => '', "action_type" => "status"];
  3339. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $a, "CGGCD", $upda['status'], $info);
  3340. $b = ["order_type" => "CGGCD", "order_code" => $old_purchease_diff["cgdNo"], "order_id" => $old_purchease_diff['id'], "order_status" => $upda['status'], "before_status" => $old_purchease_diff['status'], 'holder_id' => $cgd['apply_id']];
  3341. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $b);
  3342. Db::commit();
  3343. return app_show(0, "更新成功");
  3344. }
  3345. }
  3346. Db::rollback();
  3347. return error_show(1003, "更新失败");
  3348. } catch (\Exception $e) {
  3349. Db::rollback();
  3350. return error_show(1003, $e->getMessage());
  3351. }
  3352. }
  3353. /**
  3354. * @return \think\response\Json|void
  3355. * @throws \think\db\exception\DataNotFoundException
  3356. * @throws \think\db\exception\DbException
  3357. * @throws \think\db\exception\ModelNotFoundException
  3358. */
  3359. public function diffstatus()
  3360. {
  3361. // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  3362. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  3363. if ($id === "") {
  3364. return error_show(1004, "参数id不能为空");
  3365. }
  3366. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  3367. if ($info == false) {
  3368. return error_show(1004, "工差单数据未找到");
  3369. }
  3370. $sale = Db::name("sale")->where(["orderCode" => $info["orderCode"]])->find();
  3371. if ($sale == false) {
  3372. return error_show(1004, "订单数据未找到");
  3373. }
  3374. $cgd = Db::name("purchease_diff")->where(['id' => $info['cgd_diffid']])->find();
  3375. if ($cgd == false) {
  3376. return error_show(1004, "采购工差单数据未找到");
  3377. }
  3378. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "3";
  3379. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  3380. $ite = $info['status'];
  3381. Db::startTrans();
  3382. try {
  3383. $upda = [
  3384. "status" => $status,
  3385. "remark" => $remark,
  3386. "updatetime" => date("Y-m-d H:i:s"),
  3387. ];
  3388. $up = Db::name("sale_diff")->where($info)->save($upda);
  3389. if ($up) {
  3390. $stx = ["order_code" => $info["orderCode"], "status" => $ite, "action_remark" => '', "action_type" => "status"];
  3391. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, "XSGCD", $status, $info);
  3392. $order = ["order_type" => "XSGCD", "order_code" => $info["orderCode"], "order_id" => $info['id'],"order_status" => $status, "before_status" => $ite,'holder_id'=>$sale['apply_id']];
  3393. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
  3394. $cgdup = Db::name("purchease_diff")->where(["id" => $info['cgd_diffid']])->save($upda);
  3395. if ($cgdup) {
  3396. if ($status == 2 && $info['customer_remark'] == 1) {
  3397. $sale['diff_weight'] = $info['diff_weight'];
  3398. $sale['diff_fee'] = $info['diff_price'];
  3399. $sale['updatetime'] = date("Y-m-d H:i:s");
  3400. $sal = Db::name("sale")->save($sale);
  3401. if ($sal == false) {
  3402. Db::rollback();
  3403. return error_show(1003, "订单更新工差失败");
  3404. }
  3405. }
  3406. Db::commit();
  3407. return app_show(0, "更新成功");
  3408. }
  3409. }
  3410. Db::rollback();
  3411. return error_show(1003, "更新失败");
  3412. } catch (\Exception $e) {
  3413. Db::rollback();
  3414. return error_show(1003, $e->getMessage());
  3415. }
  3416. }
  3417. /**
  3418. * @return \think\response\Json|void
  3419. * @throws \think\db\exception\DataNotFoundException
  3420. * @throws \think\db\exception\DbException
  3421. * @throws \think\db\exception\ModelNotFoundException
  3422. */
  3423. public function diffinfo()
  3424. {
  3425. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  3426. if ($id === "") {
  3427. return error_show(1004, "参数id不能为空");
  3428. }
  3429. $info = Db::name('sale_diff')->where(["id" => $id])->find();
  3430. if (empty($info)) {
  3431. return error_show(1004, "工差订单数据未找到");
  3432. }
  3433. $einfo = Db::name('sale')->where(['orderCode' => $info['orderCode'], 'is_del' => 0])->find();
  3434. if ($einfo == false) {
  3435. return error_show(1002, "未找到销售订单数据");
  3436. }
  3437. if (in_array($einfo['order_type'], [3, 4])) {
  3438. $goon = Db::name("good_zixun")->where(["spuCode" => $einfo['good_code'], "is_del" => 0])->find();
  3439. } else {
  3440. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  3441. ->where(['a.skuCode' => $einfo['skuCode']])->find();
  3442. }
  3443. if ($goon == false) {
  3444. return error_show(1002, "未找到商品数据");
  3445. }
  3446. $info['skuCode'] = isset($goon['skuCode']) ? $goon['skuCode'] : "";
  3447. $info['spuCode'] = isset($goon['spuCode']) ? $goon['spuCode'] : "";
  3448. $info['order_type'] = isset($einfo['order_type']) ? $einfo['order_type'] : "";
  3449. $info['can'] = isset($info['cat_id']) && $info['cat_id'] !== 0 ? made($info['cat_id']) : [];
  3450. return app_show(0, "获取成功", $info);
  3451. }
  3452. //发货申请单列表
  3453. public function saleout()
  3454. {
  3455. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  3456. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  3457. $where = [["a.is_del", "=", 0]];
  3458. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  3459. if ($orderCode !== "") {
  3460. $where[] = ['a.orderCode', "like", "%$orderCode%"];
  3461. }
  3462. $order_type = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? trim($this->post['order_type']) : "";
  3463. if ($order_type !== "") {
  3464. $where[] = ['a.order_type', "=", $order_type];
  3465. }
  3466. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  3467. if ($outCode !== "") {
  3468. $where[] = ['a.outCode', "like", "%$outCode%"];
  3469. }
  3470. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name']) : "";
  3471. if ($apply_name !== "") {
  3472. $where[] = ['a.apply_name', "like", "%$apply_name%"];
  3473. }
  3474. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  3475. if ($good_code !== "") {
  3476. $where[] = ['b.good_code', "like", "%$good_code%"];
  3477. }
  3478. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  3479. if ($good_name !== "") {
  3480. $where[] = ['b.good_name', "like", "%$good_name%"];
  3481. }
  3482. $supplier_name = isset($this->post['supplier_name']) && $this->post['supplier_name'] !== "" ? trim($this->post['supplier_name']) : "";
  3483. if ($supplier_name !== "") {
  3484. $where[] = ['b.supName', "like", "%$supplier_name%"];
  3485. }
  3486. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  3487. if ($status !== "") {
  3488. $where[] = ['a.status', "=", $status];
  3489. }
  3490. $send_status = isset($this->post['send_status']) && $this->post['send_status'] !== "" ? trim($this->post['send_status']) : "";
  3491. if ($send_status !== "") {
  3492. $where[] = ['a.send_status', "=", $send_status];
  3493. }
  3494. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  3495. if ($start != "") {
  3496. $where[] = ["a.addtime", '>=', $start . " 00:00:00"];
  3497. }
  3498. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  3499. if ($end != "") {
  3500. $where[] = ["a.addtime", '<=', $end . " 23:59:59"];
  3501. }
  3502. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  3503. if ($companyNo != "") {
  3504. $where[] = ['b.supplierNo', "like", "%$companyNo%"];
  3505. }
  3506. $customer_code = isset($this->post['customerCode']) && $this->post['customerCode'] !== "" ? trim($this->post['customerCode']) : "";
  3507. if ($customer_code != "") {
  3508. $where[] = ['b.customer_code', "like", "%$customer_code%"];
  3509. }
  3510. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] !== "" ? trim($this->post['relaComNo']) : "";
  3511. if ($relaComNo != '') $where[] = ['b.supplierNo', '=', $relaComNo];
  3512. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  3513. if ($supplierNo != '') {
  3514. //sale b 表里存的supplierNo值是GS开头的,即业务公司编码
  3515. //所以此处应该根据供应商编码筛选商品spuCode,然后筛选发货单
  3516. $spuCode = Db::name('good_basic')
  3517. ->where(['is_del' => 0, 'supplierNo' => $supplierNo])
  3518. ->column('spuCode');
  3519. $where[] = ['b.good_code', 'in', $spuCode];
  3520. }
  3521. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo'] !== "" ? $this->post['cgdNo'] : "";
  3522. if ($cgdNo != "") {
  3523. $where[] = ["os.cgdNo", 'like', '%' . $cgdNo . '%'];
  3524. }
  3525. $condition = '';
  3526. $level= isset($this->post['level']) && $this->post['level'] !== '' ? $this->post['level'] : '0';
  3527. //只有level2的账号过滤数据权限
  3528. if ($level=='0'&& $this->level == 2) {
  3529. // //如果是供应商负责人,根据供应商筛选
  3530. // $person_supplier = Db::connect('mysql_sys')
  3531. // ->name('supplier')
  3532. // ->where(['is_del' => 0, 'personid' =>$this->uid])
  3533. // ->column('code');
  3534. //
  3535. // if(!empty($person_supplier)) $condition = "b.supNo in ('" . implode('\',\'', $person_supplier) . "')";
  3536. // else{
  3537. //不是供应商负责人,根据数据权限筛选申请人
  3538. $role = $this->checkDataShare();
  3539. if (!empty($role[DataGroupModel::$type_全部])) $condition = " a.apply_id in (" . implode(',', $role[DataGroupModel::$type_全部]) . ")";
  3540. // }
  3541. // $hand = resign_hand_user($this->uid, 0);
  3542. // $uidarr = implode(",", $hand);
  3543. // //库管只能看到库存品订单,供应商负责人只能看到非库存品订单
  3544. // if (!in_array($this->roleid, [1, 33])) {
  3545. // //库管看到所有的库存品发货申请单
  3546. // if (in_array($this->roleid, config('app.wsm_cgder_role'))) $condition .= " b.is_stock=1";
  3547. // else {
  3548. // $role = $this->checkDataShare();
  3549. // if (!empty($role[DataGroupModel::$type_全部])) {
  3550. // $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  3551. // if ($condition != '') $condition .= " or ";
  3552. // $condition .= " a.apply_id in (" . implode(',', $arr) . ")";
  3553. // }
  3554. // }
  3555. //// $personid = Db::name('supplier')->field('id')->where(['is_del' => 0, 'personid' => $hand])->findOrEmpty();
  3556. // if (!empty($hand)) {
  3557. // if ($condition != '') $condition .= " or ";
  3558. //// $condition .= "(b.is_stock=0 and sip.personid in ($uidarr))";
  3559. //
  3560. // $person_supplier = Db::connect('mysql_sys')
  3561. // ->name('supplier')
  3562. // ->where(['is_del'=>0,'personid'=>$uidarr])
  3563. // ->column('code');
  3564. //
  3565. // $condition .= "(b.is_stock=0 and wpo.supplierNo in ('" . implode('\',\'', $person_supplier) . "'))";
  3566. // }
  3567. // }
  3568. }
  3569. // if(!empty($role['platform']) ){
  3570. // $where[]=["b.platform_id","in",$role['platform']];
  3571. // }
  3572. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  3573. if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
  3574. //发货时间筛选
  3575. $start_sendtime = isset($this->post['start_sendtime']) && $this->post['start_sendtime'] !== "" ? $this->post['start_sendtime'] : "";
  3576. $end_sendtime = isset($this->post['end_sendtime']) && $this->post['end_sendtime'] !== "" ? $this->post['end_sendtime'] : "";
  3577. if ($start_sendtime != "" && $end_sendtime != "") {
  3578. $where[] = ["a.sendtime", 'between', [$start_sendtime . " 00:00:00", $end_sendtime . " 23:59:59"]];
  3579. $where[] = ["a.status", '>=', 2];//搜索发货时间时,要指定状态为已发货及之后的状态值(0待发货,1待库管发货,2已发货待收货,3已收货,4已全部退货',)
  3580. }
  3581. $order_source = isset($this->post['order_source']) && $this->post['order_source'] !== "" ? intval($this->post['order_source']) : "";
  3582. if ($order_source !== "") $where[] = ["b.order_source", '=', $order_source];
  3583. $use_type = $this->post['use_type']??'';
  3584. if($use_type!=='') $where[]=['p.use_type','=',$use_type];
  3585. $count = Db::name('order_out')
  3586. ->alias('a')
  3587. ->join("sale b", "b.orderCode=a.orderCode", "left")
  3588. // ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  3589. ->join("warehouse_info n", "n.wsm_code=a.wsm_code", "left")
  3590. ->leftJoin("order_send os", "os.outCode=a.outCode")
  3591. ->leftJoin("platform p", "p.id=b.platform_id")
  3592. // ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
  3593. // ->leftJoin('supplier sip', 'sip.code=wpo.supplierNo')
  3594. ->where($where)
  3595. ->where($condition)
  3596. ->count('a.id');
  3597. $total = ceil($count / $size);
  3598. $page = $page >= $total ? $total : $page;
  3599. $list = Db::name('order_out')
  3600. ->alias('a')
  3601. ->join("sale b", "b.orderCode=a.orderCode", "left")
  3602. // ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  3603. ->join("warehouse_info n", "n.wsm_code=a.wsm_code AND n.is_del=0", "left")
  3604. ->leftJoin("order_send os", "os.outCode=a.outCode")
  3605. ->leftJoin("platform p", "p.id=b.platform_id")
  3606. // ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
  3607. // ->leftJoin('supplier sip', 'sip.code=wpo.supplierNo')
  3608. ->field("a.*,b.order_type,b.order_source,b.good_name,b.good_code,b.skuCode,b.customer_code,b.supplierNo companyNo,b.supplierName companyName,b.origin_price,b.sale_price,b.total_price,os.cgdNo,b.supNo supplierNo,n.supplierNo wsm_supplierNo,p.use_type")
  3609. ->where($where)
  3610. ->where($condition)
  3611. ->order("addtime desc")
  3612. ->page($page, $size)
  3613. ->select()
  3614. ->toArray();
  3615. $all_createrid = array_column($list, 'apply_id');
  3616. $item = get_company_name_by_uid($all_createrid);
  3617. $user = \app\admin\common\User::getIns();
  3618. $names = $user->handle("getCodeAndName", ["code" => array_merge( array_column($list, "supplierNo"), array_column($list, "wsm_supplierNo"))]);
  3619. // $userCommon = \app\admin\common\User::getIns();
  3620. // $names = $userCommon->handle('getCodeAndName',['code'=>array_column($list,'customer_code')]);
  3621. $has_account = checkHasAccountBySupplierNos(array_unique(array_column($list,'wsm_supplierNo')));
  3622. $data = [];
  3623. foreach ($list as $value) {
  3624. // $value['companyName'] = $names['data'][$value['customer_code']] ?? '';
  3625. if ($value['order_type'] == 1 && $value['wsm_code'] == '') {
  3626. // $wsmcode = Db::name("good")->alias("a")
  3627. // ->leftJoin("supplier b","a.supplierNo=b.code")
  3628. // ->where(["a.spuCode"=>$value['good_code']])->field("'' wsm_name,b.name,b.code")->find();
  3629. $value['wsm_supplierNo'] = $value['supplierNo'];
  3630. $value['wsm_supplier'] = $names['data'][$value['supplierNo']] ?? "";
  3631. } else {
  3632. // $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  3633. // ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  3634. $value['wsm_supplier'] = $names['data'][$value['wsm_supplierNo']] ?? "";
  3635. }
  3636. $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
  3637. if ($addr) {
  3638. $addinfo = $addr['addr_code'] != '' ? json_decode($addr['addr_code'], true) ?? $addr['addr_code'] : '';
  3639. if (is_string($addinfo) && $addinfo != '') {
  3640. $addinfo = ["provice_code" => '', "city_code" => '', "area_code" => ''];
  3641. list($addinfo['provice_code'], $addinfo['city_code'], $addinfo['area_code']) = explode(",", $addr['addr_code']);
  3642. }
  3643. $addr['addr_cn'] = GetAddr(json_encode($addinfo));
  3644. }
  3645. if (in_array($value['order_type'], [3, 4])) {
  3646. $goon = Db::name("good_zixun")->field('id,cat_id')->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
  3647. } else {
  3648. $goon = Db::name('good_platform')->field('a.id,b.cat_id')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')->where(['a.skuCode' => $value['skuCode']])->find();
  3649. }
  3650. $value['wsm_has_account'] = (int)isset($has_account[$value['wsm_supplierNo']]);
  3651. $value['addr'] = isset($addr['addr']) ? $addr['addr_cn'] . $addr['addr'] : "";
  3652. $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  3653. $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  3654. $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  3655. $value['company_name'] = $item[$value['apply_id']] ?? '';
  3656. $value['sendtime'] = $value['status'] < 2 ? '' : $value['sendtime'];
  3657. //是否具有编辑权限
  3658. // $value['is_allow_update'] = 0;
  3659. // if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  3660. $data[] = $value;
  3661. }
  3662. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  3663. }
  3664. public function outinfo()
  3665. {
  3666. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  3667. if ($outCode == "") {
  3668. return error_show(1002, "参数outcode不能为空");
  3669. }
  3670. $codeinfo = Db::name("order_out")->where(['outCode' => $outCode, "is_del" => 0])->find();
  3671. if (empty($codeinfo)) {
  3672. return error_show(1002, "未找到出库数据");
  3673. }
  3674. $item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  3675. if ($item['order_type'] == 3 ||$item['order_type'] == 4 ) {
  3676. $goodinfo = Db::name("good_zixun")->where(["spuCode" => $item['good_code'], "is_del" => 0])->find();
  3677. if ($goodinfo == false) {
  3678. return error_show(1004, "未找到商品数据");
  3679. }
  3680. } else {
  3681. $goodinfo = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  3682. ->where(['a.skuCode' => $item['skuCode']])->find();
  3683. if ($goodinfo == false) {
  3684. return error_show(1002, "未找到商品数据");
  3685. }
  3686. }
  3687. $int = isset($goodinfo['cat_id']) && $goodinfo['cat_id'] != 0 ? made($goodinfo['cat_id']) : [];
  3688. $addr = Db::name("order_addr")->where(["id" => $codeinfo['addrid']])->find();
  3689. if($addr){
  3690. $addinfo =$addr['addr_code']!=''?json_decode($addr['addr_code'],true)??$addr['addr_code']: '' ;
  3691. if(is_string($addinfo)&&$addinfo!=''){
  3692. $addinfo=["provice_code"=>'',"city_code"=>'',"area_code"=>''];
  3693. list($addinfo['provice_code'],$addinfo['city_code'],$addinfo['area_code']) = explode(",",$addr['addr_code']);
  3694. }
  3695. $addr['addr_cn'] =GetAddr(json_encode($addinfo));
  3696. }
  3697. $codeinfo['good_name'] = isset($item['good_name']) ? $item['good_name'] : "";
  3698. $codeinfo['good_num'] = isset($item['good_num']) ? $item['good_num'] : "";
  3699. $codeinfo['good_code'] = isset($item['good_code']) ? $item['good_code'] : "";
  3700. $codeinfo['origin_price'] = isset($item['origin_price']) ? $item['origin_price'] : "";
  3701. $codeinfo['sale_price'] = isset($item['sale_price']) ? $item['sale_price'] : "";
  3702. $codeinfo['total_price'] = isset($item['total_price']) ? $item['total_price'] : "";
  3703. $codeinfo['skuCode'] = isset($item['skuCode']) ? $item['skuCode'] : "";
  3704. $codeinfo['addr'] = $addr['addr_cn']??'';
  3705. $codeinfo['addr'] .= isset($addr['addr']) ? $addr['addr'] : "";
  3706. $codeinfo['addr_code'] = isset($addr['addr_code']) ? $addr['addr_code'] : "";
  3707. $codeinfo['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  3708. $codeinfo['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  3709. $codeinfo['sendtime'] = $codeinfo['status'] < 2 ? '' : $codeinfo['sendtime'];
  3710. $codeinfo['can'] = $int;
  3711. $codeinfo['order_source'] = $item['order_source'];
  3712. $orderReturn = Db::name("order_return")->where(["outCode" => $outCode, "is_del" => 0])->order("id desc")->find();
  3713. $codeinfo['order_return'] = $orderReturn;
  3714. $codeinfo['platform_order'] = $item['platform_order'];
  3715. //获取销售订单对应的供应商是否有启用账号
  3716. $codeinfo['has_account'] = 0;
  3717. $supplierNo = Db::name('order_num')
  3718. ->alias('a')
  3719. ->leftJoin('purchease_order b', 'b.cgdNo=a.cgdNo')
  3720. ->where('a.orderCode', $codeinfo['orderCode'])
  3721. ->value('b.supplierNo');
  3722. if ($supplierNo) {
  3723. $has_account = checkHasAccountBySupplierNos([$supplierNo]);
  3724. $codeinfo['has_account'] = (int)isset($has_account[$supplierNo]);
  3725. }
  3726. $saleinfo=Db::name("sale_info")->where([["orderCode","=",$codeinfo['orderCode']],["num",">",0]])->select()
  3727. ->toArray();
  3728. if(!empty($saleinfo)){
  3729. $stockidArr=array_column($saleinfo,"stockid");
  3730. $wsm=Db::name("good_stock")->alias("a")
  3731. ->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")
  3732. ->where("a.id","in",$stockidArr)
  3733. ->column("a.wsm_code,name","a.id");
  3734. foreach ($saleinfo as &$item){
  3735. $item['wsm_code'] = $wsm[$item['stockid']]['wsm_code'];
  3736. $item['wsm_name'] = $wsm[$item['stockid']]['name'];
  3737. }
  3738. }
  3739. $codeinfo["saleinfo"] = $saleinfo;
  3740. return app_show(0, "获取成功", $codeinfo);
  3741. }
  3742. public function outadd()
  3743. {
  3744. // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  3745. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  3746. if ($orderCode == "") {
  3747. return error_show(1002, "参数orderCoder不能为空");
  3748. }
  3749. $retrun =Db::name("sale_return")->where([["orderCode","=",$orderCode],["is_del","=",0],["status","in",[1,2,3,
  3750. 7,9,10,8,11,12]]])->count();
  3751. if($retrun>0){
  3752. return error_show(1005,"存在未完成退货订单数据");
  3753. }
  3754. $der = Db::name('sale')->where(['orderCode' => $orderCode, "is_del" => 0])->find();
  3755. if ($der == "") {
  3756. return error_show(1002, "未找到出库订单单号");
  3757. }
  3758. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  3759. if ($send_num == "") {
  3760. return error_show(1002, "发货数量不能为空");
  3761. }
  3762. $wsed = Db::name("order_out")->where(["orderCode" => $orderCode])->where([["status", "<", 2], ["is_del", "=", 0]])->sum
  3763. ('send_num');
  3764. if ($send_num > $der['wsend_num'] - $wsed) {
  3765. return error_show(1002, "超出可发货数量");
  3766. }
  3767. $contactor = isset($this->post['contactor']) && $this->post['contactor'] != "" ? trim($this->post['contactor']) : "";
  3768. if ($contactor == "") {
  3769. return error_show(1002, "参数contactor不能为空");
  3770. }
  3771. $mobile = isset($this->post['mobile']) && $this->post['mobile'] != "" ? trim($this->post['mobile']) : "";
  3772. if ($mobile == "") {
  3773. return error_show(1002, "参数mobile不能为空");
  3774. }
  3775. $addr = isset($this->post['addr']) && $this->post['addr'] != "" ? trim($this->post['addr']) : "";
  3776. if ($addr == "") {
  3777. return error_show(1002, "参数addr不能为空");
  3778. }
  3779. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code'] != "" ? trim($this->post['addr_code']) : "";
  3780. // if ($addr_code == "") {
  3781. // return error_show(1002, "参数addr_code不能为空");
  3782. // }
  3783. // $apply_id = GetUserInfo($token);
  3784. // if (empty($apply_id) || $apply_id['code'] != 0) {
  3785. // return error_show(1002, "申请人数据不存在");
  3786. // }
  3787. $rm = $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  3788. $ri = $this->uname;//isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  3789. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  3790. Db::startTrans();
  3791. try {
  3792. $addrlst = [
  3793. "orderCode" => $orderCode,
  3794. "addr" => $addr,
  3795. "addr_code" => $addr_code!=''?json_encode($addr_code):'',
  3796. "contactor" => $contactor,
  3797. "mobile" => $mobile,
  3798. "customer_code" => $der['customer_code'],
  3799. "post_fee" => $der['post_fee'],
  3800. "arrive_time" => $sendtime,
  3801. "receipt_quantity" => $send_num,
  3802. "is_del" => 0,
  3803. "addtime" => date("Y-m-d H:i:s"),
  3804. "updatetime" => date("Y-m-d H:i:s")
  3805. ];
  3806. $addrid = Db::name("order_addr")->insert($addrlst, true);
  3807. if ($addrid > 0) {
  3808. $outCode = makeNo("DF");
  3809. $order=[];
  3810. if($der['order_type']!=1){
  3811. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  3812. ->lock(true)->find();
  3813. if ($order == false) {
  3814. Db::rollback();
  3815. return error_show(1004, "未找到可以发货得采购单数据");
  3816. }
  3817. $cgd = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
  3818. if ($cgd == false) {
  3819. Db::rollback();
  3820. return error_show(1002, "未找到对应的采购单数据");
  3821. }
  3822. $order['wsend_num'] -= $send_num;
  3823. $order['send_num'] += $send_num;
  3824. $or = Db::name("order_num")->save($order);
  3825. if ($or == false) {
  3826. Db::rollback();
  3827. return error_show(1002, "发货地址添加创建失败");
  3828. }
  3829. $tep = [
  3830. "cgdNo" => $order['cgdNo'],
  3831. "outCode" => $outCode,
  3832. "send_num" => $send_num,
  3833. "status" => 1,
  3834. "addtime" => date("Y-m-d H:i:s"),
  3835. "updatetime" => date("Y-m-d H:i:s")
  3836. ];
  3837. $sen = Db::name("order_send")->save($tep);
  3838. if ($sen == false) {
  3839. Db::rollback();
  3840. return error_show(1002, "发货地址添加创建失败");
  3841. }
  3842. }else{
  3843. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  3844. ->lock(true)->find();
  3845. if ($order!= false) {
  3846. $cgd = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
  3847. if ($cgd == false) {
  3848. Db::rollback();
  3849. return error_show(1002, "未找到对应的采购单数据");
  3850. }
  3851. $order['wsend_num'] -= $send_num;
  3852. $order['send_num'] += $send_num;
  3853. $or = Db::name("order_num")->save($order);
  3854. if ($or == false) {
  3855. Db::rollback();
  3856. return error_show(1002, "发货地址添加创建失败");
  3857. }
  3858. $tep = [
  3859. "cgdNo" => $order['cgdNo'],
  3860. "outCode" => $outCode,
  3861. "send_num" => $send_num,
  3862. "status" => 1,
  3863. "addtime" => date("Y-m-d H:i:s"),
  3864. "updatetime" => date("Y-m-d H:i:s")
  3865. ];
  3866. $sen = Db::name("order_send")->save($tep);
  3867. if ($sen == false) {
  3868. Db::rollback();
  3869. return error_show(1002, "发货地址添加创建失败");
  3870. }
  3871. }else{
  3872. $order['cgdNo']='';
  3873. $cgd=[];
  3874. }
  3875. }
  3876. $data = [
  3877. "wsm_code" => isset($cgd['wsm_code']) ? $cgd['wsm_code'] : "",
  3878. "orderCode" => $orderCode,
  3879. "outCode" => $outCode,
  3880. "order_type" => $der['order_type'],
  3881. "apply_id" => $rm,
  3882. "apply_name" => $ri,
  3883. "addrid" => $addrid,
  3884. "post_name" => "",
  3885. "post_code" => "",
  3886. "post_fee" => "",
  3887. "sendtime" => $sendtime,
  3888. "send_num" => $send_num,
  3889. "check_num" => 0,
  3890. "error_num" => 0,
  3891. "send_status" => 1,
  3892. "status" => 1,
  3893. "addtime" => date("Y-m-d H:i:s"),
  3894. "updatetime" => date("Y-m-d H:i:s")
  3895. ];
  3896. if ($der['is_stock'] == 0) {
  3897. //维护商品所在仓库的库存 --- start
  3898. $temp = Db::name('good_stock')
  3899. ->field('id,usable_stock,wait_out_stock')
  3900. ->where(['spuCode' => $der['good_code'], 'wsm_code' => $cgd['wsm_code']])
  3901. ->find();
  3902. if (($temp == false || ($temp['usable_stock'] - $send_num) < 0) && $der['send_type'] == 1) {
  3903. Db::rollback();
  3904. return error_show(1004, '库存不足');
  3905. } else {
  3906. if (($temp == false || ($temp['usable_stock'] - $send_num) < 0) && $der['send_type'] == 2) {
  3907. $data['status'] = 0;
  3908. } else {
  3909. //这个地方不需要更新,因为后面尝试拆单的时候会维护库存数
  3910. // $up = Db::name('good_stock')
  3911. // ->where('id', $temp['id'])
  3912. // ->update([
  3913. // 'usable_stock' => $temp['usable_stock'] - $send_num,
  3914. // 'wait_out_stock' => $temp['wait_out_stock'] + $send_num,
  3915. // 'updatetime' => date('Y-m-d H:i:s'),
  3916. // ]);
  3917. // if ($up == false) {
  3918. // Db::rollback();
  3919. // return error_show(1004, '库存更新失败');
  3920. // }
  3921. // ::todo
  3922. // $good_data[] = ['good_log_code' => $outCode, "stock_id" => $temp['id'], "type" => 1, 'stock' => $send_num, "stock_name" => "wait_out_stock"];
  3923. // $good_data[] = ['good_log_code' => $outCode, "stock_id" => $temp['id'], "type" => 2, 'stock' => $send_num, "stock_name" => "usable_stock"];
  3924. // GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname], $good_data, "CKD");
  3925. }
  3926. }
  3927. }
  3928. $datainfo = Db::name('order_out')->insert($data, true);
  3929. if ($datainfo > 0) {
  3930. //修改状态,添加待办
  3931. ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
  3932. "order_code" => $data['outCode'],//出库单号
  3933. "status" => $data['status'],//这里的status是之前的值
  3934. "action_remark" => '',//备注
  3935. "action_type" => "create"//新建create,编辑edit,更改状态status
  3936. ], "CKD", $data['status'], $data);
  3937. //是否库存品,待办数据推送到的人有区别,
  3938. $process = [];
  3939. if ($data['status'] == 1) {
  3940. if ($data['send_status'] == 1) OrderOutChild::makeChild($outCode);//尝试拆单
  3941. if ($der['is_stock'] == 1) {
  3942. //库存品,推给库管和库管-张凯旋
  3943. $roleid = config('app.wsm_cgder_role');
  3944. $uids = Db::name('user_role')
  3945. ->where('is_del', 0)
  3946. ->whereIn('roleid', $roleid)
  3947. ->column('uid');
  3948. $process = ["order_type" => 'CKD', "order_code" => $data['outCode'], "order_id" => $datainfo, "order_status" => $data['status'], "before_status" => 0, 'holder_id' => $data['apply_id'], 'handle_user_list' => implode(',', $uids)];
  3949. } else{
  3950. //推给供应商负责人
  3951. // $supplier = Db::name('supplier')
  3952. // ->field('person,personid')
  3953. // ->where('code', $cgd['supplierNo'])
  3954. // ->findOrEmpty();
  3955. $userCommon= \app\admin\common\User::getIns();
  3956. $supplier_temp =$userCommon->handle("sInfo",["code"=>$cgd['supplierNo']]);
  3957. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"采购单供应商不存在");
  3958. $holder_id=$supplier_temp['data']['personid']??0;
  3959. $holder_name=$supplier_temp['data']['personid']??0;
  3960. $process = ["order_type" => 'CKD', "order_code" => $data['outCode'], "order_id" =>
  3961. $datainfo, "order_status" => $data['status'], "before_status" => 0, 'holder_id' => $data['apply_id'], 'wait_id' => $holder_id, 'wait_name' => $holder_name,];
  3962. }
  3963. }
  3964. if (empty($process)) $process = ["order_type" => 'CKD', "order_code" => $data['outCode'], "order_id" => $datainfo, "order_status" => $data['status'], "before_status" => 0, 'holder_id' => $data['apply_id']];
  3965. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], $process);
  3966. //维护台账记录
  3967. Db::name('standing_book')
  3968. ->where('orderCode', $orderCode)
  3969. ->update([
  3970. 'order_type' => $der['order_type'],
  3971. 'order_source' => $der['order_source'],
  3972. 'cgdNo' => $order['cgdNo'],
  3973. 'customer_code' => $der['customer_code'],
  3974. 'updatetime' => date('Y-m-d H:i:s'),
  3975. ]);
  3976. Db::execute("UPDATE `wsm_standing_book` SET `outCode`=CONCAT(IFNULL(`outCode`,''),',{$outCode}') WHERE `cgdNo`='{$order['cgdNo']}'");
  3977. Db::commit();
  3978. return app_show(0, "出库单新建成功");
  3979. }
  3980. }
  3981. Db::rollback();
  3982. return error_show(1004, "出库单新建失败");
  3983. } catch (Exception $e) {
  3984. Db::rollback();
  3985. return error_show(1005, $e->getMessage());
  3986. }
  3987. }
  3988. //库管发货
  3989. public function outSend()
  3990. {
  3991. $outCode = isset($this->post['outCode']) && $this->post['outCode'] != "" ? trim($this->post['outCode']) : "";
  3992. if ($outCode == "") {
  3993. return error_show(1004, "参数outCode不能为空");
  3994. }
  3995. $outinfo = Db::name("order_out")->where(["outCode" => $outCode, "is_del" => 0])->find();
  3996. if ($outinfo == false) {
  3997. return error_show(1004, "发货数据未找到");
  3998. }
  3999. if($outinfo['status']!=1){
  4000. return error_show(1004, "发货状态有误");
  4001. }
  4002. $einfo = Db::name('sale')->where(['orderCode' => $outinfo['orderCode'], 'is_del' => 0])->find();
  4003. if (empty($einfo)) {
  4004. return error_show(1002, "未找到销售订单数据");
  4005. }
  4006. //判断供应商是否开通账号,若开通的话,则只能由供应商账号操作
  4007. if ($this->level != 3) {
  4008. $temp = checkHasAccountBySupplierNos([$einfo['supNo']]);
  4009. if (isset($temp[$einfo['supNo']])) return json_show(1004, '非供应商账号不能操作');
  4010. }
  4011. $is_reurn = Db::name("sale_return")->where(['orderCode' => $outinfo['orderCode'], 'is_del' => 0])->where("status", "in", [1,2,3,7,9,10,8,11,12])->find();
  4012. if ($is_reurn != false) {
  4013. return error_show(1002, "销售单存在退货未处理完成");
  4014. }
  4015. $post_name = isset($this->post['post_name']) && $this->post['post_name'] != "" ? trim($this->post['post_name']) : "";
  4016. if ($post_name == "") {
  4017. return error_show(1004, "参数post_name不能为空");
  4018. }
  4019. $post_code = isset($this->post['post_code']) && $this->post['post_code'] != "" ? trim($this->post['post_code']) : "";
  4020. if ($post_code == "") {
  4021. return error_show(1004, "参数post_code不能为空");
  4022. }
  4023. $remark = isset($this->post['remark']) && $this->post['remark'] != "" ? trim($this->post['remark']) : "";
  4024. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] != "" ? floatval($this->post['post_fee']) : "";
  4025. $outinfo['post_name'] = $post_name;
  4026. $outinfo['post_code'] = $post_code;
  4027. $outinfo['post_fee'] = $post_fee;
  4028. $outinfo['sendtime'] = date("Y-m-d H:i:s");
  4029. $old_outinfo_status = $outinfo['status'];
  4030. $outinfo['status'] = 2;
  4031. $outinfo['updatetime'] = date("Y-m-d H:i:s");
  4032. $outinfo['remark'] = $remark;
  4033. if ($einfo['wsend_num'] < $outinfo['send_num']) {
  4034. return error_show(1004, "订单未发货数量不足");
  4035. }
  4036. Db::startTrans();
  4037. try {
  4038. $up = Db::name("order_out")->where(["outCode"=>$outCode,"status"=>1,"is_del"=>0])->update($outinfo);
  4039. // $user_info = GetUserInfo($this->post['token']);
  4040. $uid = $this->uid;//isset($user_info['data']['id']) ? $user_info['data']['id'] : 0;
  4041. $uname = $this->uname;//isset($user_info['data']['nickname']) ? $user_info['data']['nickname'] : '';
  4042. if ($einfo['is_stock'] == 1) {
  4043. //由于存在一个单子对应多个仓库的情况,因此库存品的判断暂时无法进行,待分仓功能完成后再考虑
  4044. //如果是库存品,只能由库管操作
  4045. // $contactor = Db::name('warehouse_info')
  4046. // ->where(['wsm_code' => $outinfo['wsm_code'], 'is_del' => 0])
  4047. // ->value('contactor');
  4048. // $own_roleid = Db::name('user_role')->where(['is_del'=>0,'uid'=>$uid,'status'=>1])->value('roleid',0);
  4049. // if ($uid != $contactor) throw new \think\Exception('库存品只能由库管人员操作');
  4050. } elseif ($einfo['is_stock'] == 0) {
  4051. //非库存品和采返商品只能由供应商负责人操作
  4052. if ($einfo['order_type'] == 3 || $einfo['order_type'] ==4 ) {
  4053. $supplierNo = Db::name('good_zixun')
  4054. // ->leftJoin("supplier b", "a.supplierNo=b.code")
  4055. ->where(['spuCode' => $einfo['good_code'], 'is_del' => 0])
  4056. ->value('supplierNo');
  4057. } else {
  4058. $supplierNo = Db::name('good')
  4059. // ->alias("a")
  4060. // ->leftJoin("supplier b", "a.supplierNo=b.code")
  4061. ->where(['spuCode' => $einfo['good_code'], 'is_del' => 0])
  4062. ->value('supplierNo');
  4063. }
  4064. // $userCommon = \app\admin\common\User::getIns();
  4065. // $temp = $userCommon->handle('sInfo', ['code' => $supplierNo]);
  4066. $temp = get_personid_by_supplierNo([$supplierNo]);
  4067. if (($this->level == 2) && ($uid != $temp[$supplierNo])) throw new \think\Exception('非库存品和采返商品只能由供应商负责人操作');
  4068. }
  4069. if ($up) {
  4070. //修改状态,添加待办
  4071. ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], [
  4072. "order_code" => $outinfo['outCode'],//出库单号
  4073. "status" => $old_outinfo_status,//这里的status是之前的值
  4074. "action_remark" => '',//备注
  4075. "action_type" => "edit"//新建create,编辑edit,更改状态status
  4076. ], "CKD", $outinfo['status'], $outinfo);
  4077. ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], [
  4078. "order_type" => 'CKD',
  4079. "order_code" => $outinfo['outCode'],//出库单号
  4080. "order_id" => $outinfo['id'],
  4081. "order_status" => $outinfo['status'],
  4082. "before_status" => $old_outinfo_status,
  4083. 'wait_id'=>$outinfo['apply_id'],
  4084. 'wait_name'=>$outinfo['apply_name'],
  4085. 'holder_id'=>$outinfo['apply_id'],
  4086. ]);
  4087. if($einfo['wsend_num']<$outinfo['send_num']){
  4088. Db::rollback();
  4089. return error_show(1002, "订单待付货数量不足");
  4090. }
  4091. $orderstatus = $einfo['status'];
  4092. $einfo['send_num'] += $outinfo['send_num'];
  4093. $einfo['wsend_num'] -= $outinfo['send_num'];
  4094. $einfo['status'] = $einfo['wsend_num'] == 0 ? 2 : ($einfo['send_num'] == 0 ? 0 : 1);
  4095. $einfo['send_status'] = $einfo['wsend_num'] == 0 ? 3 : ($einfo['send_num'] == 0 ? 1 : 2);
  4096. $einfo['updatetime'] = date("Y-m-d H:i:s");
  4097. $saleup = Db::name("sale")->save($einfo);
  4098. if ($saleup == false) {
  4099. Db::rollback();
  4100. return error_show(1002, "销售单状态更新失败");
  4101. }
  4102. // }
  4103. //修改状态,添加待办
  4104. ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], [
  4105. "order_code" => $einfo['orderCode'],//出库单号
  4106. "status" => $orderstatus,//这里的status是之前的值
  4107. "action_remark" => '',//备注
  4108. "action_type" => "edit"//新建create,编辑edit,更改状态status
  4109. ], "XSQRD", $einfo['status'], $einfo);
  4110. ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], [
  4111. "order_type" => 'XSQRD',
  4112. "order_code" => $einfo['orderCode'],//出库单号
  4113. "order_id" => $einfo['id'],
  4114. "order_status" => $einfo['status'],
  4115. "before_status" => $orderstatus,
  4116. 'holder_id' => $einfo['apply_id']
  4117. ]);
  4118. if($einfo["order_type"]!=1 ){
  4119. $stokc = Db::name("good_stock")->where(['spuCode' => $einfo['good_code'], "wsm_code" => $outinfo['wsm_code'], "is_del" => 0])->find();
  4120. if ($stokc == false) {
  4121. Db::rollback();
  4122. return error_show(1002, "未找到库存数据");
  4123. } else {
  4124. if ($outinfo['send_num'] > $stokc['wait_out_stock']) {
  4125. Db::rollback();
  4126. return error_show(1002, "超出库存数量");
  4127. }
  4128. $stokc['wait_out_stock'] -= $outinfo['send_num'];
  4129. $stokc['total_stock'] = $stokc['wait_out_stock'] + $stokc['usable_stock'];
  4130. // $stokc['intra_stock']+=$outinfo['send_num'];
  4131. $stokc['updatetime'] = date("Y-m-d H:i:s");
  4132. }
  4133. $stoc = Db::name("good_stock")->save($stokc);
  4134. if ($stoc == false) {
  4135. Db::rollback();
  4136. return error_show(1002, "库存更新失败");
  4137. }
  4138. // $outsend =Db::name("order_send")->where(["outCode"=> $outCode])->findOrEmpty();
  4139. // if(empty($outsend)){
  4140. // Db::rollback();
  4141. // return error_show(1002, "未找到关联采购单");
  4142. // }
  4143. // $cgdinfo= Db::name("purchease_order")->where(["cgdNo"=>$outsend['cgdNo'],"is_del"=>0])
  4144. // ->findOrEmpty();
  4145. // $bn_code =makeNo("BN");
  4146. // $bnin=GoodStockInfo::AddBn($stokc["id"],$bn_code,$outinfo['send_num'],$cgdinfo['good_price']??0);
  4147. // if($bnin==false){
  4148. // Db::rollback();
  4149. // return error_show(1004,"库存bn数据新增失败");
  4150. // }
  4151. // $bnup =GoodStockInfo::OrderBn($outinfo['orderCode'],$stokc["id"],$outinfo['send_num'],0);
  4152. // if($bnup==false){
  4153. // Db::rollback();
  4154. // return error_show(1004,"库存bn库存数更新失败");
  4155. // }
  4156. // $outsend['bnCode']=$bn_code;
  4157. // $outsend['updatetime']=date("Y-m-d H:i:s");
  4158. // $ps=Db::name("order_send")->save($outsend);
  4159. // if($ps==false){
  4160. // Db::rollback();
  4161. // return error_show(1004,"库存bn库存数更新失败");
  4162. // }
  4163. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stokc['id'], "type" => 2, 'stock' => $outinfo['send_num'], "stock_name" => "wait_out_stock"];
  4164. GoodLog::LogAdd(['id' => $uid, 'nickname' => $uname], $good_data, "CKD");
  4165. }else{
  4166. // $saleinfo =Db::name("sale_info")->where(["orderCode"=>$outinfo['orderCode']])->select()->toArray();
  4167. // if (!empty($saleinfo)){
  4168. // $bnup =SaleInfo::SendStock($outinfo['orderCode'],$outinfo['send_num']);
  4169. // if($bnup==false){
  4170. // Db::rollback();
  4171. // return error_show(1004,"库存bn库存数更新失败");
  4172. // }
  4173. // }else{
  4174. $stokc = Db::name("good_stock")->where(['spuCode' => $einfo['good_code'], "wsm_code" => $outinfo['wsm_code'], "is_del" => 0])->find();
  4175. if ($stokc == false) {
  4176. Db::rollback();
  4177. return error_show(1002, "未找到库存数据");
  4178. } else {
  4179. if ($outinfo['send_num'] > $stokc['wait_out_stock']) {
  4180. Db::rollback();
  4181. return error_show(1002, "超出库存数量");
  4182. }
  4183. $stokc['wait_out_stock'] -= $outinfo['send_num'];
  4184. $stokc['total_stock'] = $stokc['wait_out_stock'] + $stokc['usable_stock'];
  4185. // $stokc['intra_stock']+=$outinfo['send_num'];
  4186. $stokc['updatetime'] = date("Y-m-d H:i:s");
  4187. }
  4188. $stoc = Db::name("good_stock")->save($stokc);
  4189. if ($stoc == false) {
  4190. Db::rollback();
  4191. return error_show(1002, "库存更新失败");
  4192. }
  4193. // }
  4194. }
  4195. // Cache::store("redis")->handler()->lPush("SENDOUT", $outCode);
  4196. Db::commit();
  4197. } else {
  4198. Db::rollback();
  4199. return error_show(1004, "发货失败");
  4200. }
  4201. //如果是有赞订单的话,将发货信息推到有赞
  4202. //有赞信息有可能推送失败(比如超过72小时,不允许多次修改等),所以不应该和这里的事务放到一起
  4203. if ($einfo['order_source'] == 5) {
  4204. $res = curl_request(config('app.yz_domain') . 'api/yz_out_send', ['orderCode' => $einfo['orderCode'], 'out_stype' => $post_name, 'post_code' => $post_code, 'uid' => $uid, 'uname' => $uname, 'order_out' => $outCode]);
  4205. $res = json_decode($res, true);
  4206. if ($res['code'] != 0) return app_show(0, '发货成功,' . $res['message']);
  4207. }
  4208. return app_show(0, "发货成功");
  4209. } catch (\Exception $e) {
  4210. Db::rollback();
  4211. return error_show(1004, $e->getMessage());
  4212. }
  4213. }
  4214. public function RelaCgd($outinfo, array &$standing_book_da = [])
  4215. {
  4216. $cgd = Db::name("order_bk")->where([["spuCode", "=", $outinfo['spuCode']], ["is_del", "=", 0], ["balance_num", ">=", $outinfo['good_num']], ['companyNo', "=", $outinfo['companyNo']]])->lock(true)->find();
  4217. if ($cgd == false) {
  4218. return false;
  4219. }
  4220. $good = Db::name("good")->where(["spuCode" => $outinfo['spuCode'], "is_del" => 0])->find();
  4221. if ($good == false) {
  4222. return false;
  4223. }
  4224. $cgdinfo = Db::name("purchease_order")->where(['cgdNo' => $cgd['cgdNo'], "is_del" => 0])->find();
  4225. if ($cgdinfo == false) {
  4226. return false;
  4227. }
  4228. $QrdCgd = [
  4229. "cgdNo" => makeNo("CG"),
  4230. "bkcode" => $cgdinfo['bkcode'],
  4231. 'wsm_code' => $cgdinfo['wsm_code'],
  4232. "cgder_id" => $cgdinfo['cgder_id'],
  4233. "cgder" => $cgdinfo['cgder'],
  4234. "spuCode" => $cgdinfo['spuCode'],
  4235. "good_name" => $cgdinfo['good_name'],
  4236. "good_num" => $outinfo['good_num'],
  4237. "good_price" => $cgdinfo['good_price'],
  4238. "total_fee" => round($cgdinfo['good_price'] * $outinfo['good_num'], 2),
  4239. "pakge_fee" => $cgdinfo['pakge_fee'],
  4240. "cert_fee" => $cgdinfo['cert_fee'],
  4241. "open_fee" => $cgdinfo['open_fee'],
  4242. "delivery_fee" => $cgdinfo['delivery_fee'],
  4243. "mark_fee" => $cgdinfo['mark_fee'],
  4244. "teach_fee" => $cgdinfo['teach_fee'],
  4245. "nake_fee" => $cgdinfo['nake_fee'],
  4246. "demo_fee" => $cgdinfo['demo_fee'],
  4247. "weight" => $cgdinfo['weight'],
  4248. "diff_weight" => $cgdinfo['diff_weight'],
  4249. "diff_fee" => $cgdinfo['diff_fee'],
  4250. "gold_price" => $cgdinfo['gold_price'],
  4251. "supplierNo" => $cgdinfo['supplierNo'],
  4252. "supplier_name" => $cgdinfo['supplier_name'],
  4253. "companyNo" => $cgdinfo['companyNo'],
  4254. "send_status" => 3,
  4255. "send_num" => $outinfo['good_num'],
  4256. "wsend_num" => 0,
  4257. "remark" => $cgdinfo['remark'],
  4258. "status" => 3,
  4259. "lasttime" => $cgdinfo['lasttime'],
  4260. "is_del" => 0,
  4261. "order_type" => $outinfo['order_type'],
  4262. "order_source" => $outinfo['order_source'],
  4263. "good_type" => $cgdinfo['good_type'],
  4264. "addtime" => date("Y-m-d H:i:s"),
  4265. "updatetime" => date("Y-m-d H:i:s"),
  4266. 'good_createrid' => $good['createrid'],
  4267. 'good_creater' => $good['creater'],//商品创建人
  4268. ];
  4269. $insetrCgd = Db::name("purchease_order")->insert($QrdCgd);
  4270. if ($insetrCgd == false) {
  4271. return false;
  4272. } else {
  4273. $standing_book_da = array_merge($standing_book_da, [
  4274. 'orderCode' => $outinfo['orderCode'],
  4275. 'cgdNo' => $cgdinfo['cgdNo'],
  4276. 'spuCode' => $outinfo['spuCode'],
  4277. 'order_type' => $QrdCgd['order_type'],
  4278. 'order_source' => $QrdCgd['order_source'],
  4279. 'supplierNo' => $cgdinfo['supplierNo'],
  4280. 'companyNo' => $cgdinfo['companyNo'],
  4281. 'bk_code' => $cgdinfo['bkcode'],
  4282. 'purchease_id' => Db::name('purchease')->where('bk_code', $cgdinfo['bkcode'])->value('id'),
  4283. ]);
  4284. }
  4285. if ($good['is_gold_price'] == 1 && $good['is_stock'] == 1) {
  4286. $gold = Db::name("gold_price1")
  4287. ->field('id,price')
  4288. ->where(["type" => $good['noble_metal'], "is_del" => 0, "status" => 1])
  4289. ->order("addtime desc")
  4290. ->find();
  4291. //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
  4292. $sale_price = $good['demo_fee'] / $outinfo['good_num'] + $good['open_fee'] / $outinfo['good_num'] + $good['noble_weight'] * $gold["price"] + $outinfo['cost_fee'] * $good['noble_weight'] + $cgdinfo['pakge_fee'] + $cgdinfo['mark_fee'] + $cgdinfo['cert_fee'] + $cgdinfo['nake_fee'] + $cgdinfo['delivery_fee'];
  4293. $ct['cgd_gold_price'] = $gold["price"];
  4294. $updat = [
  4295. "sale_price" => $sale_price,
  4296. "total_price" => round($sale_price * $outinfo['good_num'], 2),
  4297. "origin_price" => $cgdinfo['good_price'],
  4298. "gold_price" => $gold["price"],
  4299. ];
  4300. $upsale = Db::name("sale")->where(["orderCode" => $outinfo['orderCode']])->update($updat);
  4301. if ($upsale == false) {
  4302. return false;
  4303. }
  4304. }
  4305. $merge_num = Db::name("purchease_order")->where(["bkcode" => $cgdinfo['bkcode'], "order_type" => 1, "is_del" => 0])
  4306. ->where("order_source", "<>", 0)
  4307. ->field("sum(send_num)-sum(th_num) as num")->find();
  4308. $cgd['balance_num'] = $cgd['total_num'] - $merge_num['num'];
  4309. $cgd['merge_num'] = $merge_num['num'];
  4310. $cgd['updatetime'] = date("Y-m-d H:i:s");
  4311. $up = Db::name("order_bk")->save($cgd);
  4312. if ($up == false) {
  4313. return false;
  4314. }
  4315. $data = [
  4316. "orderCode" => $outinfo['orderCode'],
  4317. "cgdNo" => $QrdCgd['cgdNo'],
  4318. "spuCode" => $outinfo['spuCode'],
  4319. "companyNo" => $outinfo['companyNo'],
  4320. "good_num" => $outinfo['good_num'],
  4321. "wsend_num" => $outinfo['good_num'],
  4322. "send_num" => 0,
  4323. "wait_num" => $outinfo['good_num'],
  4324. "status" => 1,
  4325. "source" => 1,
  4326. ];
  4327. $order = Db::name("order_num")->save($data);
  4328. if ($order == false) {
  4329. return false;
  4330. }
  4331. return true;
  4332. }
  4333. public function addother()
  4334. {
  4335. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
  4336. if ($orderCode == "") {
  4337. return error_show(1004, "参数orderCode不能为空");
  4338. }
  4339. $order = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->find();
  4340. if ($order == false) {
  4341. return error_show(1004, "未找到订单数据");
  4342. }
  4343. $paytime = isset($this->post['paytime']) && $this->post['paytime'] != "" ? $this->post['paytime'] : "";
  4344. $workNo = isset($this->post['workNo']) && $this->post['workNo'] != "" ? trim($this->post['workNo']) : "";
  4345. $platform_order = isset($this->post['platform_order']) && $this->post['platform_order'] != "" ? trim($this->post['platform_order']) : "";
  4346. $paytime == "" ? "" : $order['paytime'] = $paytime;
  4347. $order['workNo'] = $workNo;
  4348. $order['platform_order'] = $platform_order;
  4349. $order['updatetime'] = date("Y-m-d H:i:s");
  4350. $sa = Db::name("sale")->save($order);
  4351. if ($sa) {
  4352. return app_show(0, "更新成功");
  4353. } else {
  4354. return error_show(1004, "更新失败");
  4355. }
  4356. }
  4357. public function getPrice()
  4358. {
  4359. $skuCode = isset($this->post['skuCode']) && $this->post['skuCode'] != "" ? trim($this->post['skuCode']) : "";
  4360. if ($skuCode === "") {
  4361. return error_show(1003, "参数skuCode不能为空");
  4362. }
  4363. $is_activity = isset($this->post['is_activity']) && $this->post['is_activity'] !== "" ? intval($this->post['is_activity'])
  4364. : "";
  4365. if ($is_activity === "") {
  4366. return error_show(1003, "参数is_activity不能为空");
  4367. }
  4368. $sale_num = isset($this->post['sale_num']) && $this->post['sale_num'] !== "" ? intval($this->post['sale_num']) : "";
  4369. if ($sale_num === "") {
  4370. return error_show(1003, "参数sale_num不能为空");
  4371. }
  4372. $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  4373. ->where(['a.skuCode' => $skuCode])->find();
  4374. if ($ct == false) {
  4375. return error_show(1002, "未找到商品数据");
  4376. }
  4377. $stock = 0;
  4378. if ($ct['is_stock'] == 1) {
  4379. // $good_stock = Db::name("good_stock")->alias("a")->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")->where
  4380. // (["spuCode" => $ct['spuCode'], "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5])->field("a.id,a.usable_stock,a.wait_out_stock")->find();
  4381. // $good_stock = Db::name("good_stock")->where(["spuCode" => $ct['spuCode'], "is_del" => 0])->find();
  4382. $stock = Db::name("good")->where(["spuCode"=>$ct['spuCode']])->value("usable_stock",0);
  4383. }
  4384. if ($is_activity == 1) {
  4385. $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b", "a.activity_code=b.activity_code")
  4386. ->where(["a.skuCode" => $skuCode, "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])->find();
  4387. if ($act == false) {
  4388. return error_show(1003, "未找到相关活动价");
  4389. }
  4390. if ($act['moq_num'] > $sale_num) {
  4391. return error_show(1003, "商品不满足活动价起订量{$act['moq_num']}");
  4392. }
  4393. if ($act['activity_stock'] < $sale_num) {
  4394. return error_show(1003, "商品活动库存剩余{$act['activity_stock']}");
  4395. }
  4396. return app_show(0, "获取成功", ['sale_price' => $act['activity_price'], "stock" => $act['activity_stock']]);
  4397. } else {
  4398. //good_nake 成本阶梯 good_ladder销售阶梯
  4399. $origin = Db::name("good_nake")->where([["spuCode", "=", $ct['spuCode']], ["is_del", "=", 0]])->order("min_num asc")->find();
  4400. if (!$origin) {
  4401. return error_show(1003, "没有找到成本数据");
  4402. }
  4403. $good = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->order("min_num asc")->find();
  4404. if (!$good) {
  4405. return error_show(1003, "未找到相关阶梯价格");
  4406. }
  4407. if (!isset($origin['min_num'])) $origin['min_num'] = 0;
  4408. //如果是库存品的话,只取销售的库存
  4409. if ($ct['is_stock'] == 1) $lastnum = $good['min_num'];
  4410. else $lastnum = max($origin['min_num'] ?? 0, $good['min_num']);
  4411. if ($sale_num < $lastnum) {
  4412. return error_show(1003, "商品不满足起订量{$lastnum}");
  4413. }
  4414. $good_temp = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->where('min_num', '<=', $sale_num)->order("min_num desc")->find();
  4415. if (!$good_temp) {
  4416. return error_show(1003, "未找到相关阶梯价格");
  4417. }
  4418. $cat_top_list = made($ct['cat_id']);
  4419. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  4420. if ($ct['is_gold_price'] == 1 && $cat_top_id == 6) {
  4421. $gold = Db::name("gold_price1")
  4422. ->field('id,price')
  4423. ->where(["type" => $ct['noble_metal'], "is_del" => 0, "status" => 1])
  4424. ->order("addtime desc")
  4425. ->find();
  4426. if($ct['is_fixed']==0) $origin['nake_fee']=0;
  4427. $saleprice = $ct['demo_fee'] / $sale_num + $ct['open_fee'] / $sale_num + $ct['noble_weight'] * $gold["price"] + $good_temp['cost_fee'] * $ct['noble_weight'] + $origin['package_fee'] + $origin['mark_fee'] + $origin['cert_fee'] + $origin['nake_fee'] + $origin['delivery_fee'];
  4428. return app_show(0, "获取成功", ['sale_price' => $saleprice, "stock" => $stock]);
  4429. }
  4430. return app_show(0, "获取成功", ['sale_price' => $good_temp['sale_price'], "stock" => $stock]);
  4431. }
  4432. }
  4433. public function saleuse()
  4434. {
  4435. $orderCode = isset($this->post['orderCode']) && !empty($this->post['orderCode']) ? $this->post['orderCode'] : "";
  4436. if ($orderCode == "") {
  4437. return error_show(1003, "参数orderCode不能为空");
  4438. }
  4439. $order = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->select()->toArray();
  4440. if (empty($order)) {
  4441. return error_show(1003, "订单数据未找到");
  4442. }
  4443. $useid = isset($this->post['useid']) && $this->post['useid'] != "" ? intval($this->post['useid']) : "";
  4444. if ($useid == "") {
  4445. return error_show(1003, "参数useid不能为空");
  4446. }
  4447. $use = Db::name("order_use")->where(["id" => $useid, "is_del" => 0])->find();
  4448. if ($use == false) {
  4449. return error_show(1003, "用途数据未找到");
  4450. }
  4451. $asve = ['use_order' => $useid, "updatetime" => date("Y-m-d H:i:s")];
  4452. $up = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->update($asve);
  4453. if ($up > 0) {
  4454. return app_show(0, "更新成功");
  4455. } else {
  4456. return error_show(1003, "更新失败");
  4457. }
  4458. }
  4459. public function goodzxinfo()
  4460. {
  4461. $orderCode = isset($this->post['spuCode']) && $this->post['spuCode'] != '' ? trim($this->post['spuCode']) : "";
  4462. if ($orderCode == "") {
  4463. return error_show(1003, "参数spuCode不能为空");
  4464. }
  4465. $order = Db::name("good_zixun")->where(["spuCode" => $orderCode, "is_del" => 0])->find();
  4466. if (empty($order)) {
  4467. return error_show(1003, "订单数据未找到");
  4468. }
  4469. $unit = Db::name("unit")->where(["id" => $order['good_unit']])->find();
  4470. if ($order['brand_id'] != 0) {
  4471. $brand = Db::name("brand")->where(["id" => $order['brand_id']])->find();
  4472. $order["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  4473. } else {
  4474. $order["brand_name"] = "";
  4475. $order["brand_id"] = "";
  4476. }
  4477. $order['specinfo'] = json_decode($order['specinfo'], true);
  4478. $order['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  4479. $order['cat_info'] = made($order['cat_id'], []);
  4480. $order['noble_name'] = isset($order['noble_metal']) && $order['noble_metal'] != 0 ? $this->noble[$order['noble_metal']] : "";
  4481. if ($order['is_gold_price'] == 1) {
  4482. $price = Db::name("gold_price1")->where(["type" => $order['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  4483. }
  4484. $depart = get_company_name_by_uid($order['order_createrid']);
  4485. $userCommon = \app\admin\common\User::getIns();
  4486. $supplier = $userCommon->handle('sInfo',['code'=>$order['supplierNo']]);
  4487. // $supplier = Db::name("supplier")->where(["code" => $order['supplierNo']])->find();
  4488. $order['supplier_name'] = isset($supplier['data']['name']) ? $supplier['data']['name'] : "";
  4489. $order['cgder'] = isset($supplier['data']['person']) ? $supplier['data']['person'] : "";
  4490. $order['cgderid'] = isset($supplier['data']['personid']) ? $supplier['data']['personid'] : "";
  4491. $order['order_creater_depart'] = $depart;
  4492. $is_online= Db::name('good_platform')->where(['spuCode'=>$order['spuCode']])->findOrEmpty();
  4493. $order['is_online'] = empty($is_online)?0:1;
  4494. $value['is_basic']= Db::name('good_basic')->where(['spuCode'=>$order['spuCode']])->value("status",null);
  4495. $palt = Db::name("platform")->where(["id" => $order['platform_id']])->find();
  4496. $order['platform_name'] = isset($palt['platform_name']) ? $palt['platform_name'] : "";
  4497. $names = $userCommon->handle('getCodeAndName',['code'=>$order['companyNo']]);
  4498. // $company = Db::name("business")->where(["companyNo" => $order['companyNo']])->find();
  4499. $order['company'] = $names['data'][$order['companyNo']]??'';//isset($company['company']) ? $company['company'] : "";
  4500. $order["gold_price"] = isset($price['price']) ? $price['price'] : 0;
  4501. $order["noble_weight"] = isset($order['weight']) ? $order['weight'] : 0;
  4502. return app_show(0, "获取成功", $order);
  4503. }
  4504. //获取采反商品详情,当数据不在good_zixun中,模仿goodzxinfo
  4505. public function getGoodZxInfoByNotZixun()
  4506. {
  4507. $param = $this->request->only(['spuCode'], 'post', 'trim');
  4508. $val = Validate::rule(['spuCode' => 'require']);
  4509. if (!$val->check($param)) return error_show(1004, $val->getError());
  4510. $order = Db::name('consult_bids')
  4511. ->field(true)
  4512. ->where(['spuCode' => $param['spuCode'], 'is_del' => 0])
  4513. ->find();
  4514. if (empty($order)) return error_show(1003, "数据未找到");
  4515. // $orderCode= isset($this->post['spuCode'])&&$this->post['spuCode']!=''?trim($this->post['spuCode']):"";
  4516. // if($orderCode==""){
  4517. // return error_show(1003,"参数spuCode不能为空");
  4518. // }
  4519. // $order= Db::name("good_zixun")->where(["spuCode"=>$orderCode,"is_del"=>0])->find();
  4520. // if(empty($order)){
  4521. // return error_show(1003,"订单数据未找到");
  4522. // }
  4523. $unit = Db::name("unit")->where(["id" => $order['unit_id']])->find();
  4524. if ($order['brand_id'] != 0) {
  4525. $brand = Db::name("brand")->where(["id" => $order['brand_id']])->find();
  4526. $order["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  4527. } else {
  4528. $order["brand_name"] = "";
  4529. $order["brand_id"] = "";
  4530. }
  4531. $order['specinfo'] = json_decode($order['specinfo'], true);
  4532. $order['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  4533. $order['cat_info'] = made($order['cat_id'], []);
  4534. $order['noble_name'] = isset($order['metal_id']) && $order['metal_id'] != 0 ? $this->noble[$order['metal_id']] : "";
  4535. if ($order['is_gold_price'] == 1) {
  4536. $price = Db::name("gold_price1")->where(["type" => $order['metal_id'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  4537. }
  4538. $userCommon = \app\admin\common\User::getIns();
  4539. $supplier_temp = $userCommon->handle('getCodeAndName', ['code' => $order['supplierNo']]);
  4540. $order['supplier_name'] = $supplier_temp['data'][$order['supplierNo']]??"";
  4541. $order["gold_price"] = isset($price['price']) ? $price['price'] : 0;
  4542. $order["noble_weight"] = isset($order['weight']) ? $order['weight'] : 0;
  4543. $taxInfo=TaxCategory::where(['id'=>$order['tax_id']])->findOrEmpty();
  4544. $order['tax_name'] = $taxInfo['cat_name']??'';
  4545. $order['tax_short_name'] =$taxInfo['short_name']??'';
  4546. $order['tax_code'] =$taxInfo['merge_code']??'';
  4547. $good_info = Db::name('good_basic')
  4548. ->field('id,createrid,creater')
  4549. ->where('is_del',0)
  4550. ->where('spuCode',$order['spuCode'])
  4551. ->findOrEmpty();
  4552. //补充商品创建人字段
  4553. // 2022-9-7号确认 creater创建人即采购单的采购员 咨询cgder 只是供应商负责人
  4554. $order['good_createrid']=$good_info['createrid']??$order['createrid'];
  4555. $order['good_creater']=$good_info['creater']??$order['creater'];
  4556. return app_show(0, "获取成功", $order);
  4557. }
  4558. //发货申请单导出
  4559. public function exportSaleOut()
  4560. {
  4561. $outCodes = $this->request->post('outCodes', [], 'trim');
  4562. if (empty($outCodes)) return error_show(1004, '要导出的发货申请单编号不能为空');
  4563. $i = 1;
  4564. $send_type = [1 => '直接发货', 2 => '延时发货'];
  4565. $status = [0 => '待发货', 1 => '待库管发货', 2 => '已发货待收货', 3 => '已收货', 4 => '已全部退货'];
  4566. $list = Db::name("order_out")
  4567. ->alias('a')
  4568. ->field('"" as 序号,a.addtime as 创建时间,po.cgdNo as 采购单编号,po.status as 采购单状态,po.cgder as 采购员,b.orderCode as 确认单号,b.addtime as 确认单时间,
  4569. b.good_code as 产品编号,b.skuCode as 商品上线编码,"" 平台商品编码,b.good_name as 产品名称,"" as 规格,"" as 单位,b.supName as 供应商名称,b.supNo as 供应商编号,
  4570. a.post_fee as 物流费,b.send_type as 发货方式,b.remark as 确认单备注,po.good_num as 采购数量,a.send_num 发货数量,
  4571. oa.contactor as 收货人,oa.mobile as 联系方式,oa.addr as 收货地址,oa.addr_code,oa.arrive_time as 到货时间,a.outCode as 发货申请单号,po.order_type,
  4572. b.platform_order 平台订单号,a.post_name 发货申请单物流公司,a.post_code 发货申请单物流单号,a.post_fee 发货申请单物流费用,a.remark 发货申请单备注,a.apply_name 申请人,b.cat_id 商品分类')
  4573. ->whereIn('a.outCode', $outCodes)
  4574. ->order("a.addtime desc")
  4575. ->withAttr('序号', function () use (&$i) {
  4576. return $i++;
  4577. })->withAttr('采购单状态', function ($val) use ($status) {
  4578. return isset($status[$val]) ? $status[$val] : '';
  4579. })->withAttr('发货方式', function ($val) use ($send_type) {
  4580. return isset($send_type[$val]) ? $send_type[$val] : '';
  4581. })->where("a.is_del", "=", 0)
  4582. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  4583. ->leftJoin("order_addr oa", "oa.id=a.addrid AND oa.is_del=0")
  4584. ->leftJoin('order_send os', 'os.outCode=a.outCode ')
  4585. ->leftJoin("purchease_order po", "po.cgdNo=os.cgdNo AND po.is_del=0")
  4586. ->select()
  4587. ->toArray();
  4588. $userCommon = \app\admin\common\User::getIns();
  4589. $skuArr =array_unique(array_column($list,"商品上线编码"));
  4590. $platCode= (new GoodPlatform())->where(["skuCode"=>$skuArr])->column("plat_code","skuCode");
  4591. foreach ($list as &$value) {
  4592. $value['平台商品编码']= $platCode[$value['商品上线编码']]??"";
  4593. if ($value['order_type'] == 3 || $value['order_type'] == 4) {
  4594. $good = Db::name("good_zixun")
  4595. ->where(["spuCode" => $value['产品编号'], "is_del" => 0])
  4596. ->field('id,specinfo,good_unit,supplierNo')
  4597. ->find();
  4598. $specinfo = isset($good['specinfo']) ? json_decode($good['specinfo'], true) : [];
  4599. $speclist = [];
  4600. foreach ($specinfo as $val) {
  4601. $speclist[] = $val['spec_name'] . ':' . $val['spec_value_name'];
  4602. }
  4603. } else {
  4604. $good = Db::name('good_basic')
  4605. ->where(['spuCode' => $value['产品编号']])
  4606. ->field('good_unit,supplierNo')
  4607. ->find();
  4608. $spec = Db::name("good_spec")
  4609. ->field('id,spec_id,spec_value_id')
  4610. ->where(["spuCode" => $value['产品编号'], "is_del" => 0])
  4611. ->select()
  4612. ->toArray();
  4613. $speclist = [];
  4614. if (!empty($spec)) {
  4615. foreach ($spec as $val) {
  4616. $speclist[] = Db::name("specs")->where(["id" => $val['spec_id']])->value('spec_name', '') . ':' . Db::name("spec_value")->where(["id" => $val['spec_value_id']])->value('spec_value', '');
  4617. }
  4618. }
  4619. }
  4620. $supplier_temp = $userCommon->handle('sInfo', ['code' =>$value['供应商编号']]);
  4621. $supplier=$supplier_temp['data']??[];
  4622. $value['供应商编号'] = $good['supplierNo']??"";
  4623. // $supplier= Db::name("supplier")->where(["code"=>$value['供应商编号']])->field("name,person")->find();
  4624. $value['供应商名称'] = $supplier['name']??"";
  4625. $value['采购员'] = $supplier['person']??"";
  4626. $good_unit = isset($good['good_unit']) ? $good['good_unit'] : 0;
  4627. $value['规格'] = empty($speclist) ? '' : implode(',', $speclist);;
  4628. $value['单位'] = $good_unit ? Db::name('unit')->where(['id' => $good_unit, 'is_del' => 0])->value('unit', '') : '';
  4629. $value['商品分类'] = implode('/', array_column(made($value['商品分类']), 'name'));
  4630. $value['发货申请单物流单号'] = ' ' . $value['发货申请单物流单号'];//添加空格防止将数字转为科学计数法(比如,韵达的快递单号就是纯数字)
  4631. $addinfo =$value['addr_code']!=''?json_decode($value['addr_code'],true)??$value['addr_code']: '' ;
  4632. if(is_string($addinfo)&&$addinfo!=''){
  4633. $addinfo=["provice_code"=>'',"city_code"=>'',"area_code"=>''];
  4634. list($addinfo['provice_code'],$addinfo['city_code'],$addinfo['area_code']) = explode(",",$value['addr_code']);
  4635. }
  4636. $addr_cn =GetAddr(json_encode($addinfo));
  4637. $value['收货地址'] = $addr_cn.$value['收货地址'];
  4638. unset($value['order_type']);
  4639. unset($value['addr_code']);
  4640. }
  4641. if (empty($list)) $list[] = '没有可供导出的数据';
  4642. $headerArr = array_keys($list[0]);
  4643. excelSave('发货申请单导出' . date('YmdHis'), $headerArr, $list);
  4644. }
  4645. //发货申请单 签收(目前只改动状态,后面要实时查询物流信息,以判断是否签收)
  4646. public function saleoutReceipt()
  4647. {
  4648. $outCode = $this->request->post('outCode', '', 'trim');
  4649. if (empty($outCode)) return error_show(1004, '发货申请单编号不能为为空');
  4650. Db::startTrans();
  4651. try {
  4652. $rs = Db::name('order_out')
  4653. ->field('id,orderCode,apply_id')
  4654. ->where(['outCode' => $outCode, 'status' => 2, "is_del" => 0])
  4655. ->find();
  4656. if (empty($rs)) throw new Exception('该出库单不存在或不允许确认收货');
  4657. //发货单收货
  4658. $res_order_out = Db::name('order_out')
  4659. ->where(['id' => $rs['id'], 'status' => 2, "is_del" => 0])
  4660. ->update(['status' => 3, 'updatetime' => date('Y-m-d H:i:s')]);
  4661. //发货工单不做更新,发货工单只给库管人员看,不关心是否收货,只保留 待发货/已发货/已取消 这几个状态就可以了
  4662. //查询该发货单所属的销售单,是否还有未收货的其他发货单
  4663. $other_res_sale = Db::name('order_out')
  4664. ->where(['orderCode' => $rs['orderCode'], 'status' => 2, "is_del" => 0])
  4665. ->where('id', '<>', $rs['id'])
  4666. ->find();
  4667. if (empty($other_res_sale)) {
  4668. //所属销售单也确认收货
  4669. Db::name('sale')
  4670. ->where(['orderCode' => $rs['orderCode'], 'status' => 0])
  4671. ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  4672. }
  4673. //修改状态,添加待办
  4674. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  4675. "order_code" => $outCode,
  4676. "status" => 2,//这里的status是之前的值
  4677. "action_remark" => '',//备注
  4678. "action_type" => "status"//新建create,编辑edit,更改状态status
  4679. ], "CKD", 3, $rs);
  4680. //将待办数据变为已办
  4681. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  4682. "order_code" => $outCode,
  4683. "order_id" => $rs['id'],
  4684. "order_status" => 3,
  4685. "order_type" => 'CKD',
  4686. "before_status" => 2,
  4687. 'holder_id' => $rs['apply_id']
  4688. ]);
  4689. if ($res_order_out) {
  4690. Db::commit();
  4691. return app_show(0, '收货完成');
  4692. } else {
  4693. Db::rollback();
  4694. error_show(1005, '收货失败');
  4695. }
  4696. } catch (\Exception $e) {
  4697. Db::rollback();
  4698. return error_show(1005, $e->getMessage());
  4699. }
  4700. }
  4701. //库管批量发货
  4702. public function outSendBatchByImport()
  4703. {
  4704. $param = $this->request->only(['list', 'token'], 'post', 'trim');
  4705. if (empty($param['list'])) return error_show(1005, 'list参数不能为空');
  4706. //只允许处理所属供应商下的采购单关联的发货单
  4707. $suppliers = Db::name('order_out')
  4708. ->alias('a')
  4709. ->leftJoin('order_num b', 'b.orderCode=a.orderCode')
  4710. ->leftJoin('purchease_order c', 'c.cgdNo=b.cgdNo')
  4711. ->where([
  4712. ['a.is_del', '=', 0],
  4713. ['c.order_type', '<>', 1],
  4714. ['a.outCode', 'in', array_column($param['list'], 'outCode')],
  4715. ])->column('c.supplierNo', 'a.outCode');
  4716. if ($this->level != 3) {
  4717. //检查这些供应商编码是否开通了账号
  4718. $temp_res = checkHasAccountBySupplierNos(array_values($suppliers));
  4719. // ->whereIn('supplierNo', array_values($suppliers))
  4720. // ->column('supplierNo');
  4721. // $temp = [];
  4722. // foreach ($suppliers as $k => $v) {
  4723. // if (in_array($v, $temp_res)) $temp[] = $k;
  4724. // }
  4725. if (!empty($temp_res)) return json_show(1003, '不允许处理已开通账号的供应商的单子', array_keys($temp_res));
  4726. }
  4727. // $user = GetUserInfo($param['token']);
  4728. $createrid = $this->uid;//$user['data']['id']??0;//$this->uid;
  4729. $creater = $this->uname;//$user['data']['nickname']??0;//$this->uname;
  4730. // $own_roleid = Db::name('user_role')->where(['is_del'=>0,'uid'=>$createrid,'status'=>1])->value('roleid',0);
  4731. //所有发货单信息
  4732. $order_out_infos = Db::name("order_out")
  4733. ->where('status', 1)
  4734. ->where('is_del', 0)
  4735. ->whereIn('outCode', array_column($param['list'], 'outCode'))
  4736. ->column('id,status,send_num,orderCode,wsm_code,apply_id,apply_name', 'outCode');
  4737. //所有库管人员信息
  4738. // $wsm_infos=Db::name('warehouse_info')
  4739. // ->where(['is_del'=>0,'wsm_code'=>array_column($order_out_infos,'wsm_code')])
  4740. // ->column('contactor','wsm_code');
  4741. //所有商品信息及供应商编码
  4742. $spuCodes=Db::name('sale')
  4743. ->where(['is_del'=>0,'orderCode'=>array_column($order_out_infos,'orderCode')])
  4744. ->column('good_code');
  4745. $supplierNo1 = Db::name('good_zixun')
  4746. ->where(['spuCode' => $spuCodes, 'is_del' => 0])
  4747. ->column('supplierNo','spuCode');
  4748. $supplierNo2 = Db::name('good')
  4749. ->where(['spuCode' => $spuCodes, 'is_del' => 0])
  4750. ->column('supplierNo','spuCode');
  4751. $supplierNos = array_unique(array_merge($supplierNo1,$supplierNo2));
  4752. $userCommon = \app\admin\common\User::getIns();
  4753. $temp = $userCommon->handle('sGetList',['more_code'=>array_values($supplierNos)]);
  4754. $supplier_personid = array_column($temp['data']['list'],'personid','code');
  4755. //处理数据
  4756. Db::startTrans();
  4757. try {
  4758. $good_data = $temp_out_codes = $yz_data = [];
  4759. foreach ($param['list'] as $value) {
  4760. if (!isset($order_out_infos[$value['outCode']])) throw new Exception($value['outCode'] . '该发货单未找到或状态不允许发货');
  4761. //每次循环都需要重新查询对应数据,为了数据及时更新
  4762. $sale_infos = Db::name("sale")
  4763. ->where('orderCode', $order_out_infos[$value['outCode']]['orderCode'])
  4764. ->where('is_del', 0)
  4765. ->column('id,send_num,wsend_num,status,good_code,order_source,order_type,apply_id,apply_name,is_stock,cgderid,orderCode', 'orderCode');
  4766. if (!isset($sale_infos[$order_out_infos[$value['outCode']]['orderCode']])) throw new Exception($value['outCode'] . '该发货单对应的销售单未找到');
  4767. //判断发货单是否重复
  4768. if (isset($temp_out_codes[$value['outCode']])) {
  4769. Db::rollback();
  4770. return app_show(1005, '下列发货申请单号重复', [$value]);
  4771. } else $temp_out_codes[$value['outCode']] = $value['outCode'];
  4772. if($this->level==2) {
  4773. //level2账号的话,库存品只能由库管操作,非库存品只能由供应商负责人操作,level3账号不限制
  4774. if ($sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['is_stock'] == 1) {
  4775. //由于存在一个单子对应多个仓库的情况,因此库存品的判断暂时无法进行,待分仓功能完成后再考虑
  4776. // if($wsm_infos[$order_out_infos[$value['outCode']]['wsm_code']]??0 != $createrid) throw new \think\Exception($value['outCode'] . '发货单只能由库管操作');
  4777. // if (!in_array($own_roleid, config('app.wsm_cgder_role'))) {
  4778. // Db::rollback();
  4779. // return app_show(1003, $value['outCode'] . '发货单只能由库管操作');
  4780. // }
  4781. } else {
  4782. // if ($sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['order_type'] == 3 || $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['order_type'] == 4) {
  4783. // $supplierNo = Db::name('good_zixun')
  4784. //// ->leftJoin("supplier b", "a.supplierNo=b.code")
  4785. // ->where(['spuCode' => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code'], 'is_del' => 0])
  4786. // ->value('supplierNo');
  4787. // } else {
  4788. // $supplierNo = Db::name('good')
  4789. //// ->alias("a")
  4790. //// ->leftJoin("supplier b", "a.supplierNo=b.code")
  4791. // ->where(['spuCode' =>$sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code'], 'is_del' => 0])
  4792. // ->value('supplierNo');
  4793. // }
  4794. if ($createrid != $supplier_personid[$supplierNos[$sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code']]]) throw new \think\Exception($value['outCode'] . '发货单只能由供应商负责人操作');
  4795. // Db::rollback();
  4796. // return app_show(1003, $value['outCode'] . '发货单只能由供应商负责人操作');
  4797. }
  4798. }
  4799. //【发货单】
  4800. //查询已有发货单信息及状态
  4801. //更新发货单
  4802. $up = Db::name("order_out")
  4803. ->where(['id' => $order_out_infos[$value['outCode']]['id'], 'outCode' => $value['outCode'], 'status' => 1, "is_del" => 0])
  4804. ->update([
  4805. 'post_name' => isset($value['post_name']) ? $value['post_name'] : '',
  4806. 'post_code' => $value['post_code'],
  4807. 'post_fee' => $value['post_fee'],
  4808. 'sendtime' => date('Y-m-d H:i:s'),
  4809. 'status' => 2,
  4810. 'updatetime' => date('Y-m-d H:i:s'),
  4811. 'remark' => isset($value['remark']) ? $value['remark'] : '',
  4812. ]);
  4813. if ($up) {
  4814. //修改状态,添加待办
  4815. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  4816. "order_code" => $value['outCode'],//出库单号
  4817. "status" => $order_out_infos[$value['outCode']]['status'],//这里的status是之前的值
  4818. "action_remark" => '',//备注
  4819. "action_type" => "edit"//新建create,编辑edit,更改状态status
  4820. ], "CKD", 2, $order_out_infos[$value['outCode']]);
  4821. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  4822. "order_type" => 'CKD',
  4823. "order_code" => $value['outCode'],//出库单号
  4824. "order_id" => $order_out_infos[$value['outCode']]['id'],
  4825. "order_status" => 2,
  4826. "before_status" => $order_out_infos[$value['outCode']]['status'],
  4827. 'wait_id' => $order_out_infos[$value['outCode']]['apply_id'],
  4828. 'wait_name' => $order_out_infos[$value['outCode']]['apply_name'],
  4829. 'holder_id' => $order_out_infos[$value['outCode']]['apply_id'],
  4830. ]);
  4831. //【销售单】
  4832. $einfo = [];
  4833. $einfo['send_num'] = $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['send_num'] + $order_out_infos[$value['outCode']]['send_num'];
  4834. $einfo['wsend_num'] = $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['wsend_num'] - $order_out_infos[$value['outCode']]['send_num'];
  4835. $einfo['status'] = $einfo['wsend_num'] == 0 ? 2 : ($einfo['send_num'] == 0 ? 0 : 1);
  4836. $einfo['send_status'] = $einfo['wsend_num'] == 0 ? 3 : ($einfo['send_num'] == 0 ? 1 : 2);
  4837. $einfo['updatetime'] = date("Y-m-d H:i:s");
  4838. $saleup = Db::name("sale")
  4839. ->where('id', $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['id'])
  4840. ->update($einfo);
  4841. if ($saleup == false) throw new Exception($value['outCode'] . '销售单状态更新失败');
  4842. //修改状态,添加待办
  4843. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  4844. "order_code" => $order_out_infos[$value['outCode']]['orderCode'],//销售单号
  4845. "status" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['status'],//这里的status是之前的值
  4846. "action_remark" => '',//备注
  4847. "action_type" => "edit"//新建create,编辑edit,更改状态status
  4848. ], "XSQRD", $einfo['status'], $einfo);
  4849. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  4850. "order_type" => 'XSQRD',
  4851. "order_code" => $order_out_infos[$value['outCode']]['orderCode'],//出库单号
  4852. "order_id" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['id'],
  4853. "order_status" => $einfo['status'],
  4854. "before_status" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['status'],
  4855. 'holder_id' => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['apply_id']
  4856. ]);
  4857. if($sale_infos[$order_out_infos[$value['outCode']]['orderCode']]["order_type"]!=1){
  4858. //【库存】
  4859. $stock = Db::name("good_stock")
  4860. ->field('id,wait_out_stock,usable_stock,total_stock,updatetime')
  4861. ->where([
  4862. "is_del" => 0,
  4863. 'spuCode' => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code'],
  4864. "wsm_code" => $order_out_infos[$value['outCode']]['wsm_code'],
  4865. ])->find();
  4866. if ($stock == false) throw new Exception($value['outCode'] . '未找到库存数据');
  4867. else {
  4868. if ($order_out_infos[$value['outCode']]['send_num'] > $stock['wait_out_stock']) throw new Exception($value['outCode'] . '超出库存数量');
  4869. $stock['wait_out_stock'] -= $order_out_infos[$value['outCode']]['send_num'];
  4870. $stock['total_stock'] = $stock['wait_out_stock'] + $stock['usable_stock'];
  4871. $stock['updatetime'] = date("Y-m-d H:i:s");
  4872. $stock_rs = Db::name("good_stock")
  4873. ->where('id', $stock['id'])
  4874. ->update($stock);
  4875. if ($stock_rs == false) throw new Exception($value['outCode'] . '库存更新失败');
  4876. // $outsend =Db::name("order_send")->where(["outCode"=> $value['outCode']])->findOrEmpty();
  4877. // if(empty($outsend)){
  4878. // Db::rollback();
  4879. // return error_show(1002, "未找到关联采购单");
  4880. // }
  4881. // $cgdinfo= Db::name("purchease_order")->where(["cgdNo"=>$outsend['cgdNo'],"is_del"=>0])
  4882. // ->findOrEmpty();
  4883. // $bn_code =makeNo("BN");
  4884. // $bnin=GoodStockInfo::AddBn($stock["id"],$bn_code,$order_out_infos[$value['outCode']]['send_num'],$cgdinfo['good_price']??0);
  4885. // if($bnin==false){
  4886. // Db::rollback();
  4887. // return error_show(1004,"库存bn数据新增失败");
  4888. // }
  4889. // $bnup =GoodStockInfo::OrderBn($order_out_infos[$value['outCode']]['orderCode'],$stock["id"],$order_out_infos[$value['outCode']]['send_num'],0);
  4890. // if($bnup==false){
  4891. // Db::rollback();
  4892. // return error_show(1004,"库存bn库存数更新失败");
  4893. // }
  4894. // $outsend['bnCode']=$bn_code;
  4895. // $outsend['updatetime']=date("Y-m-d H:i:s");
  4896. // $ps=Db::name("order_send")->save($outsend);
  4897. // if($ps==false){
  4898. // Db::rollback();
  4899. // return error_show(1004,"库存bn库存数更新失败");
  4900. // }
  4901. }
  4902. $good_data[] = [
  4903. 'good_log_code' => $value['outCode'],
  4904. 'stock_id' => $stock['id'],
  4905. 'type' => 2,
  4906. 'stock' => $order_out_infos[$value['outCode']]['send_num'],
  4907. 'stock_name' => 'wait_out_stock'
  4908. ];
  4909. }else{
  4910. // $bnup =SaleInfo::SendStock($order_out_infos[$value['outCode']]['orderCode'],$order_out_infos[$value['outCode']]['send_num']);
  4911. // if($bnup==false){
  4912. // Db::rollback();
  4913. // return error_show(1004,"库存bn库存数更新失败");
  4914. // }
  4915. // $saleinfo =Db::name("sale_info")->where(["orderCode"=>$order_out_infos[$value['outCode']]['orderCode']])->select()->toArray();
  4916. // if (!empty($saleinfo)){
  4917. // $bnup =SaleInfo::SendStock($order_out_infos[$value['outCode']]['orderCode'],$order_out_infos[$value['outCode']]['send_num']);
  4918. // if($bnup==false){
  4919. // Db::rollback();
  4920. // return error_show(1004,"库存bn库存数更新失败");
  4921. // }
  4922. // }else{
  4923. $stokc = Db::name("good_stock")->where(['spuCode' =>$sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code'], "wsm_code" => $order_out_infos[$value['outCode']]['wsm_code'], "is_del" => 0])->find();
  4924. if ($stokc == false) {
  4925. Db::rollback();
  4926. return error_show(1002, "未找到库存数据");
  4927. } else {
  4928. if ($order_out_infos[$value['outCode']]['send_num'] > $stokc['wait_out_stock']) {
  4929. Db::rollback();
  4930. return error_show(1002, "超出库存数量");
  4931. }
  4932. $stokc['wait_out_stock'] -= $order_out_infos[$value['outCode']]['send_num'];
  4933. $stokc['total_stock'] = $stokc['wait_out_stock'] + $stokc['usable_stock'];
  4934. // $stokc['intra_stock']+=$outinfo['send_num'];
  4935. $stokc['updatetime'] = date("Y-m-d H:i:s");
  4936. }
  4937. $stoc = Db::name("good_stock")->save($stokc);
  4938. if ($stoc == false) {
  4939. Db::rollback();
  4940. return error_show(1002, "库存更新失败");
  4941. }
  4942. // }
  4943. }
  4944. } else throw new Exception($value['outCode'] . '发货失败');
  4945. // Cache::store("redis")->handler()->lPush("SENDOUT",$value['outCode']);
  4946. //如果是有赞订单的话,将发货信息推到有赞
  4947. if($sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['order_source']==5){
  4948. $yz_data[]=[
  4949. 'orderCode'=>$sale_infos[$order_out_infos[$value['outCode']]['orderCode']],
  4950. 'out_stype'=>isset($value['post_name']) ? $value['post_name'] : '',
  4951. 'post_code'=>$value['post_code'],
  4952. 'uid'=>$createrid,
  4953. 'uname'=>$creater,
  4954. 'order_out'=>$value['outCode'],
  4955. ];
  4956. }
  4957. }
  4958. if (!empty($good_data)) GoodLog::LogAdd(['id' => $createrid, 'nickname' => $creater], $good_data, "CKD");
  4959. Db::commit();
  4960. //如果是有赞订单的话,将发货信息推到有赞
  4961. //有赞信息有可能推送失败(比如超过72小时,不允许多次修改等),所以不应该和这里的事务放到一起
  4962. if ($yz_data) {
  4963. foreach ($yz_data as $yz) {
  4964. // $res = curl_request(config('app.yz_domain') . 'api/yz_out_send', ['orderCode' => $einfo['orderCode'], 'out_stype' => $post_name, 'post_code' => $post_code, 'uid' => $uid, 'uname' => $uname, 'order_out' => $outCode]);
  4965. curl_request(config('app.yz_domain') . 'api/yz_out_send', $yz);
  4966. }
  4967. // $res = json_decode($res, true);
  4968. // if ($res['code'] != 0) return app_show(0, '发货成功,' . $res['message']);
  4969. }
  4970. return app_show(0, '发货成功');
  4971. } catch (Exception $exception) {
  4972. Db::rollback();
  4973. return error_show(1004, $exception->getMessage());
  4974. }
  4975. }
  4976. //获取物流信息
  4977. public function getLogisticsInformation()
  4978. {
  4979. $post_code = $this->request->post('post_code', '', 'trim');
  4980. if (empty($post_code)) return error_show(1004, '快递单号不能为空');
  4981. $postCode = explode(",", $post_code);
  4982. $rs = Db::name('express_data')
  4983. ->where('post_code', $postCode[0])
  4984. ->where('status', ">=", 0)
  4985. ->withAttr('post_data', function ($val) {
  4986. return json_decode($val, true);
  4987. })->findOrEmpty();
  4988. settype($rs, 'object');//格式统一转为对象
  4989. return app_show(0, '请求成功', $rs);
  4990. }
  4991. //订单取消
  4992. //未发货状态添加撤销功能 要求1.库存品 未发货 直接撤销 2.除了库存品以外的商品类型,采购单未入库的 可撤销。
  4993. public function orderCancel()
  4994. {
  4995. $orderCode = $this->request->post('orderCode', '', 'trim');
  4996. $val = Validate::rule(['orderCode' => 'require|array|max:100']);
  4997. if ($val->check(['orderCode' => $orderCode]) == false) return json_show(1004, $val->getError());
  4998. $list = Db::name('sale')
  4999. ->alias('a')
  5000. ->field('a.id sale_id,a.good_code,a.platform_order,a.good_name,a.wsend_num,a.good_num,a.total_price,a.order_type,
  5001. a.status sale_status,a.orderCode,a.cat_id,a.good_createrid,c.id cgd_id,c.status cgd_status,c.cgdNo,c.cgder_id,
  5002. a.addtime,c.wsm_code,a.order_source,a.other_orderNo')
  5003. ->leftJoin('order_num b', 'b.orderCode=a.orderCode')
  5004. ->leftJoin('purchease_order c', 'c.cgdNo=b.cgdNo')
  5005. ->where(['a.is_del' => 0, 'a.orderCode' => $orderCode])
  5006. ->select()
  5007. ->toArray();
  5008. Db::startTrans();
  5009. try {
  5010. $date = date('Y-m-d H:i:s');
  5011. $th=[];
  5012. $cgdId=[];
  5013. foreach ($list as $sale) {
  5014. if ($sale['sale_status'] == 3) throw new \think\Exception($sale['orderCode'] . '已取消,无法重复操作');
  5015. if ($sale['order_type'] == 1) {
  5016. if ($sale['sale_status'] != 0) throw new \think\Exception($sale['orderCode'] . '已发货,无法取消');
  5017. $good = Db::name("good")->where(["spuCode" => $sale['good_code']])->findOrEmpty();
  5018. if (empty($good)) throw new Exception('未找到商品信息');
  5019. $stock = Db::name("good")->where($good)
  5020. ->inc("usable_stock",$sale['wsend_num'])
  5021. ->update();
  5022. if ($stock == false) throw new Exception('商品库存更新失败');
  5023. if(strtotime($sale['addtime'])< strtotime('2023-04-17 00:00:00')){
  5024. $saleinfo = Db::name('sale_info')
  5025. ->where([['orderCode', '=',$sale['orderCode']], ['num', '>', 0]])
  5026. ->select()
  5027. ->toArray();
  5028. if (empty($saleinfo)) {
  5029. $ordernum = Db::name('order_num')->where(['orderCode' =>$sale['orderCode']])->findOrEmpty();
  5030. if (empty($ordernum)) throw new Exception('未找到关联采购单');
  5031. $cgd = Db::name('purchease_order')->where(['cgdNo' => $ordernum['cgdNo'], 'is_del' => 0])->findOrEmpty();
  5032. if (empty($cgd)) throw new Exception('未找到采购单数据');
  5033. $bn = makeNo('BN');
  5034. $stock = Db::name('good_stock')
  5035. ->where(['spuCode' => $sale['good_code'], 'wsm_code' => $cgd['wsm_code'], 'is_del' => 0, 'status' => 1])
  5036. ->findOrEmpty();
  5037. if ($stock == false) throw new Exception('商品库存数据未找到');
  5038. $stock['usable_stock'] += $sale['wsend_num'];
  5039. $stock['wait_out_stock'] -= $sale['wsend_num'];
  5040. $stock['updatetime'] = $date;
  5041. $st_up = Db::name('good_stock')->save($stock);
  5042. if ($st_up == false) throw new Exception('可售商品入库失败');
  5043. $yp = GoodStockInfo::AddBn($stock['id'], $bn, $sale['wsend_num'], $cgd['good_price']);
  5044. if ($yp == false) throw new Exception('商品批次退货入库失败');
  5045. }
  5046. else {
  5047. $tempnum = $sale['wsend_num'];
  5048. foreach ($saleinfo as $va) {
  5049. if ($tempnum == 0) break;
  5050. $stock = Db::name('good_stock')->where(['spuCode' => $sale['good_code'], 'id' => $va['stockid']])
  5051. ->findOrEmpty();
  5052. if ($stock == false) throw new Exception('商品库存数据未找到');
  5053. if ($va['num'] >= $tempnum) {
  5054. $tnm = $tempnum;
  5055. $va['num'] -= $tempnum;
  5056. $va['th_num'] += $tempnum;
  5057. $tempnum = 0;
  5058. } else {
  5059. $tnm = $va['num'];
  5060. $tempnum -= $va['num'];
  5061. $va['th_num'] += $va['num'];
  5062. $va['num'] = 0;
  5063. }
  5064. $stock['usable_stock'] += $tnm;
  5065. $stock['wait_out_stock'] -= $tnm;
  5066. $stock['updatetime'] = $date;
  5067. $st_up = Db::name('good_stock')->save($stock);
  5068. if ($st_up == false) throw new Exception('可售商品入库失败');
  5069. $ps = GoodStockInfo::AddBn($va['stockid'], $va['bnCode'], $tnm);
  5070. if ($ps == false) throw new Exception('商品批次退货入库失败');
  5071. $ret = GoodStockInfo::ReturnBn($sale['orderCode'], $va['id'], $tnm);
  5072. if ($ret == false) throw new Exception('商品批次退货入库失败');
  5073. $va['updatetime'] = $date;
  5074. $sal = Db::name('sale_info')->save($va);
  5075. if ($sal == false) throw new Exception('商品批次退货入库失败');
  5076. }
  5077. }
  5078. }
  5079. SaleCgdPrice::RePrice($sale['sale_id'],$sale['wsend_num']);
  5080. }
  5081. else{
  5082. if ($sale['order_source'] != 9){
  5083. $good = Db::name('good_stock')->where(['spuCode' => $sale['good_code'],'wsm_code'=>$sale['wsm_code']])
  5084. ->findOrEmpty();
  5085. if (empty($good)) throw new Exception('未找到商品信息');
  5086. if($sale['cgd_status']==1){
  5087. $stock = Db::name('good_stock')->where($good)
  5088. ->inc('wait_in_stock',$sale['wsend_num'])
  5089. ->update();
  5090. if ($stock == false) throw new Exception('商品库存更新失败');
  5091. }
  5092. if($sale['cgd_status']==3){
  5093. $wait_out= Db::name('order_out_child')
  5094. ->where(['is_del' => 0, 'orderCode' => $sale['orderCode'],'status'=>1])
  5095. ->sum('num');
  5096. $usable = $sale['wsend_num'] - intval($wait_out);
  5097. if($usable>0){
  5098. $stock = Db::name('good_stock')->where($good)
  5099. ->inc('usable_stock',$usable)
  5100. ->update();
  5101. if ($stock == false) throw new Exception('商品库存更新失败');
  5102. }
  5103. }
  5104. }
  5105. }
  5106. if($sale['order_type'] == 4){
  5107. $fill =Db::name("filing")->where(["filingCode"=>$sale["platform_order"]])->findOrEmpty();
  5108. if(empty($fill)) throw new Exception($sale['orderCode'] . '未找到对应得报备单');
  5109. $fullData=[
  5110. 'transfer_num'=>$fill['transfer_num']-$sale['wsend_num'],
  5111. 'wait_num'=>$fill['wait_num']+$sale['wsend_num'],
  5112. 'status'=>$fill['wait_num']+$sale['wsend_num']==0?4:
  5113. ($fill['transfer_num']-$sale['wsend_num']==0?2:3)];
  5114. $fillup=Db::name('filing')
  5115. ->where($fill)
  5116. ->data($fullData)
  5117. ->update();
  5118. $stn = ['order_code' => $fill['filingCode'], 'status' =>$fullData['status'], 'action_remark' => '', 'action_type' => 'status'];
  5119. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stn, 'BBD', $fill['status'],$fullData);
  5120. if($fillup==false)throw new Exception($sale['platform_order'] . '报备单更新失败');
  5121. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  5122. 'order_type' => 'BBD',
  5123. 'order_code' => $fill['filingCode'],//出库单号
  5124. 'order_id' => $fill['id'],
  5125. 'order_status' =>$fullData['status'],
  5126. 'before_status' => $fill['status'],
  5127. 'wait_id'=>0,
  5128. 'wait_name'=>0,
  5129. ]);
  5130. }
  5131. if($sale['order_source'] == 11){
  5132. $fill =(new BbcFill())->where(['fillCode'=>$sale['other_orderNo']])->findOrEmpty();
  5133. if($fill->isEmpty()) throw new Exception($sale['orderCode'] . '未找到对应得业务报备单');
  5134. if($fill->transfer_num <$sale['wsend_num'])throw new Exception($sale['orderCode'] . '对应得业务报备单已转单数量不足');
  5135. $fill->transfer_num -=$sale['wsend_num'];
  5136. $fill->status=$fill->transfer_num >0?2:1;
  5137. $upd=$fill->save();
  5138. if($upd==false)throw new \Exception('业务报备单更新失败');
  5139. }
  5140. $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$sale['orderCode'], "isCgd"=>1]);
  5141. if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
  5142. Db::rollback();
  5143. return json_show(10005, $fininfo['message']??'结算校验失败',$fininfo['data']??[]);
  5144. }
  5145. $thtemp=[
  5146. "orderCode"=>$sale["orderCode"],
  5147. "th_type"=>4,//取消订单
  5148. "th_num"=>$sale["good_num"],
  5149. "th_fee"=>$sale["total_price"],
  5150. "thCode"=>$sale["orderCode"],
  5151. "cat_id"=>$sale["cat_id"],
  5152. "good_name"=>$sale["good_name"],
  5153. "spuCode"=>$sale["good_code"],
  5154. "apply_id"=>$this->uid,
  5155. "apply_name"=>$this->uname,
  5156. "addtime"=>$date
  5157. ];
  5158. $th[]=$thtemp;
  5159. //修改状态,添加待办
  5160. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  5161. "order_code" => $sale['orderCode'],//销售单号
  5162. "status" => $sale['sale_status'],//这里的status是之前的值
  5163. "action_remark" => '',//备注
  5164. "action_type" => "status"//新建create,编辑edit,更改状态status
  5165. ], "XSQRD", 3, ['orderCode' => $orderCode]);
  5166. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  5167. "order_type" => 'XSQRD',
  5168. "order_code" => $sale['orderCode'],
  5169. "order_id" => $sale['sale_id'],
  5170. "order_status" => 3,
  5171. "before_status" => $sale['sale_status'],
  5172. 'holder_id' => $sale['good_createrid'],
  5173. ]);
  5174. if ($sale['cgdNo']) {
  5175. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  5176. "order_code" => $sale['cgdNo'],//销售单号
  5177. "status" => $sale['cgd_status'],//这里的status是之前的值
  5178. "action_remark" => '',//备注
  5179. "action_type" => "status"//新建create,编辑edit,更改状态status
  5180. ], "CGD", 4, ['orderCode' => $sale['cgdNo']]);
  5181. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  5182. "order_type" => 'CGD',
  5183. "order_code" => $sale['cgdNo'],
  5184. "order_id" => $sale['cgd_id'],
  5185. "order_status" => 4,
  5186. "before_status" => $sale['cgd_status'],
  5187. 'holder_id' => $sale['cgder_id'],
  5188. ]);
  5189. $cgdId[]=$sale['cgd_id'];
  5190. }
  5191. }
  5192. $orderup= Db::name('sale')
  5193. ->where(['is_del' => 0, 'id' => array_column($list, 'sale_id')])
  5194. ->update([
  5195. 'status' => 3,
  5196. 'th_num' => Db::raw("good_num"),
  5197. 'th_fee' =>Db::raw("total_price"),
  5198. 'send_num' =>Db::raw("good_num"),
  5199. 'wsend_num' =>0,
  5200. 'send_status' =>3,
  5201. 'updatetime' => $date
  5202. ]);
  5203. if($orderup==false) throw new \Exception("订单状态更新失败");
  5204. $thin= Db::name("th_data")->insertAll($th);
  5205. if($thin==false) throw new \Exception('订单取消失败');
  5206. if(!empty($cgdId)){
  5207. $cgdup=Db::name('purchease_order')
  5208. ->where(['is_del' => 0, 'id' => $cgdId])
  5209. ->update([
  5210. 'status' => 4,
  5211. 'th_num' => Db::raw('wsend_num+send_num'),
  5212. 'th_fee' =>Db::raw('total_fee'),
  5213. 'send_num' =>Db::raw('wsend_num+send_num'),
  5214. 'wsend_num' =>0,
  5215. 'send_status' =>3,
  5216. 'updatetime' => $date]);
  5217. if($cgdup==false) throw new \Exception('采购单取消失败');
  5218. }
  5219. $out_list = Db::name('order_out')
  5220. ->where(['is_del' => 0, 'orderCode' => $orderCode])
  5221. ->select()
  5222. ->toArray();
  5223. if (!empty($out_list)) {
  5224. $sen= Db::name('order_out')
  5225. ->where(['is_del' => 0, 'orderCode' => $orderCode])
  5226. ->update(['status' => 5, 'updatetime' => $date]);
  5227. if($sen==false) throw new \Exception('发货单取消失败');
  5228. foreach ($out_list as $out) {
  5229. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  5230. "order_code" => $out['outCode'],//销售单号
  5231. "status" => $out['status'],//这里的status是之前的值
  5232. "action_remark" => '',//备注
  5233. "action_type" => "status"//新建create,编辑edit,更改状态status
  5234. ], "CKD", 5, $out);
  5235. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  5236. "order_type" => 'CKD',
  5237. "order_code" => $out['outCode'],
  5238. "order_id" => $out['id'],
  5239. "order_status" => 5,
  5240. "before_status" => $out['status'],
  5241. 'holder_id' => $out['apply_id'],
  5242. ]);
  5243. }
  5244. }
  5245. $ooc_list = Db::name('order_out_child')
  5246. ->where(['is_del' => 0, 'orderCode' => $orderCode])
  5247. ->select()
  5248. ->toArray();
  5249. if (!empty($ooc_list)) {
  5250. $child= Db::name('order_out_child')
  5251. ->where(['is_del' => 0, 'orderCode' => $orderCode])
  5252. ->update(['status' => 5, 'updatetime' => $date]);
  5253. if ($child == false) throw new Exception('发货工单更新失败');
  5254. foreach ($ooc_list as $ooc) {
  5255. $stockinfo = Db::name("good_stock")->where(["spuCode" => $ooc['spuCode'], "wsm_code" => $ooc['wsm_code']])->findOrEmpty();
  5256. if (empty($stockinfo)) throw new Exception('未找到库存信息');
  5257. $stockup = [
  5258. "usable_stock" =>$ooc['order_type']==1? $stockinfo['usable_stock'] + $ooc['num']:$stockinfo['usable_stock'],
  5259. "wait_out_stock" => $stockinfo['wait_out_stock'] - $ooc['num'],
  5260. "updatetime" => $date
  5261. ];
  5262. $ysup = Db::name("good_stock")->where($stockinfo)->update($stockup);
  5263. if ($ysup == false) throw new Exception('库存信息更新失败');
  5264. if($ooc['order_type']==1)GoodStockInfo::ChildReturnBn($ooc['outChildCode'], $stockinfo['id'], $ooc['num']);//处理bn数据
  5265. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  5266. "order_code" => $ooc['outChildCode'],//销售单号
  5267. "status" => $ooc['status'],//这里的status是之前的值
  5268. "action_remark" => '',//备注
  5269. "action_type" => "status"//新建create,编辑edit,更改状态status
  5270. ], "FHGD", 5, $ooc);
  5271. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  5272. "order_type" => 'FHGD',
  5273. "order_code" => $ooc['outChildCode'],
  5274. "order_id" => $ooc['id'],
  5275. "order_status" => 5,
  5276. "before_status" => $ooc['status'],
  5277. 'holder_id' => $ooc['apply_id'],
  5278. ]);
  5279. }
  5280. }
  5281. Db::commit();
  5282. return json_show(0, '操作成功');
  5283. } catch (\think\Exception $exception) {
  5284. Db::rollback();
  5285. return json_show(1004, $exception->getMessage());
  5286. }catch (Exception $exception){
  5287. Db::rollback();
  5288. return json_show(1004, $exception->getMessage());
  5289. }
  5290. }
  5291. }