Sale.php 295 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663
  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_code'] =$taxInfo['tax_code']??'';
  2476. $einfo['tax']=$taxInfo['inv_tax']??'';
  2477. $einfo['inv_good_name']=$taxInfo['inv_good_name']??'';
  2478. $goon['exclusive'] = isset($goon['is_exclusive']) ? makeExcluse($goon['is_exclusive']) : "";
  2479. $unit = Db::name("unit")->where(["id" => $goon['good_unit']])->find();
  2480. $goon['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2481. $spec = Db::name("good_spec")->where(["spuCode" => $goon['spuCode'], "is_del" => 0])->select()->toArray();
  2482. $speclist = [];
  2483. if (!empty($spec)) {
  2484. foreach ($spec as $value) {
  2485. $temp = [];
  2486. $temp['id'] = $value['id'];
  2487. $temp['spuCode'] = $value['spuCode'];
  2488. $temp['spec_id'] = $value['spec_id'];
  2489. $temp['spec_value_id'] = $value['spec_value_id'];
  2490. $temp['is_del'] = $value['is_del'];
  2491. $sp = Db::name("specs")->where(["id" => $value['spec_id']])->find();
  2492. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  2493. $spv = Db::name("spec_value")->where(["id" => $value['spec_value_id']])->find();
  2494. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  2495. $speclist[] = $temp;
  2496. }
  2497. }
  2498. $goon["speclist"] = empty($speclist) ? [] : $speclist;
  2499. $proof = Db::name("good_proof")->where(["spuCode" => $goon['spuCode'], "is_del" => 0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  2500. $goon['proof'] = isset($proof) && $proof != false ? $proof : [];
  2501. $goon['origin_place_cn'] = "";
  2502. $goon['delivery_place_cn'] = "";
  2503. if (isset($goon['delivery_place']) && $goon['delivery_place'] !== "") {
  2504. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2505. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $goon['delivery_place']);
  2506. $goon['delivery_place_cn'] = GetAddr(json_encode($place));
  2507. }
  2508. if (isset($goon['delivery_place']) && $goon['origin_place'] !== "") {
  2509. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2510. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $goon['origin_place']);
  2511. $goon['origin_place_cn'] = GetAddr(json_encode($place));
  2512. }
  2513. if ($goon['brand_id'] != 0) {
  2514. $brand = Db::name("brand")->where(["id" => $goon['brand_id']])->find();
  2515. $goon["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2516. } else {
  2517. $goon["brand_name"] = "";
  2518. $goon["brand_id"] = "";
  2519. }
  2520. $userCommon = \app\admin\common\User::getIns();
  2521. $names = $userCommon->handle('getCodeAndName',['code'=>[
  2522. $goon['supplierNo'],
  2523. $goon['companyNo'],
  2524. $einfo['customer_code'],
  2525. $einfo['supplierNo']
  2526. ]]);
  2527. $goon['supplierName'] = $names['data'][$goon['supplierNo']]??'';//isset($supplier['name']) ? $supplier['name'] : "";
  2528. $goon['noble_name'] = isset($goon['noble_metal']) && $goon['noble_metal'] != 0 ? $this->noble[$goon['noble_metal']] : "";
  2529. $goon['company'] = $names['data'][$goon['companyNo']]??'';//isset($company['company']) ? $company['company'] : "";
  2530. }
  2531. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  2532. // $in = Db::name('customer_info')->where(['companyNo' => $einfo['customer_code']])->field('companyName')->find();
  2533. $einfo['supplierName'] = '';
  2534. if ($einfo['supplierNo'] != "") {
  2535. $einfo['supplierName'] = $names['data'][$einfo['supplierNo']]??'';//isset($supplier['company']) ? $supplier['company'] : "";
  2536. }
  2537. $addr_sum = Db::name('order_addr')->where(['orderCode' => $einfo['orderCode'],"is_del"=>0])->sum('receipt_quantity');
  2538. $einfo['addr_sum']=$addr_sum;
  2539. $addrs = [];
  2540. $einfo['useage'] = "";
  2541. if ($einfo['use_order'] != 0) {
  2542. $use = Db::name("order_use")->where(["id" => $einfo['use_order']])->find();
  2543. $einfo['useage'] = isset($use['order_use']) ? $use['order_use'] : "";
  2544. } else {
  2545. $einfo['use_order'] = '';
  2546. }
  2547. $einfo['platform_name'] = '';
  2548. if ($einfo['platform_id'] != 0) {
  2549. $plat = Db::name("platform")->where(['id' => $einfo['platform_id']])->find();
  2550. $einfo['platform_name'] = isset($plat['platform_name']) ? $plat['platform_name'] : "";
  2551. }
  2552. $einfo['companyName'] = $names['data'][$einfo['customer_code']]??'';//isset($in['companyName']) ? $in['companyName'] : "";
  2553. $einfo['addrs'] = $addrs;
  2554. $einfo['can'] = $int;
  2555. $einfo['goodinfo'] = $goon;
  2556. $einfo['good_num'] -= $einfo['th_num'];
  2557. $einfo['send_num'] -= $einfo['th_num'];
  2558. $einfo['total_price'] = round($einfo['total_price'] - $einfo['th_fee'], 2);
  2559. //处理凭证
  2560. if ($einfo['order_type'] == 1 || $einfo['order_type'] == 2) {
  2561. $proof = Db::name('good_proof')
  2562. ->field('id,proof_type,proof_url')
  2563. ->where(['id' => $einfo['proof_id'], 'is_del' => 0])
  2564. ->find();
  2565. $einfo['proof_type'] = isset($proof['proof_type']) ? $proof['proof_type'] : '';
  2566. $einfo['proof_url'] = isset($proof['proof_url']) ? $proof['proof_url'] : '';
  2567. } elseif ($einfo['order_type'] == 3 ||$einfo['order_type']==4) {
  2568. $einfo['proof_type'] = isset($goon['proof_type']) ? $goon['proof_type'] : '';
  2569. $einfo['proof_url'] = isset($goon['proof_url']) ? $goon['proof_url'] : '';
  2570. } else {
  2571. $einfo['proof_type'] = '';
  2572. $einfo['proof_url'] = '';
  2573. }
  2574. if (empty($einfo)) {
  2575. return error_show(1002, "未找到销售订单数据");
  2576. } else {
  2577. return app_show(0, "获取成功", $einfo);
  2578. }
  2579. }
  2580. public function del()
  2581. {
  2582. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2583. if ($id === "") {
  2584. return error_show(1002, "参数id不能为空");
  2585. }
  2586. $ed = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  2587. if (empty($ed)) {
  2588. return error_show(1002, "未找到销售订单数据");
  2589. }
  2590. $str = Db::name('sale')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  2591. if ($str) {
  2592. $stc = ["order_code" => $id, "status" => $ed['status'], "action_remark" => '', "action_type" => "delete"];
  2593. 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")]);
  2594. $order = ["order_type" => 'XSQRD', "order_code" => $ed['orderCode'], "order_id" => $id, "order_status" => $ed['status'],'holder_id' => $ed['apply_id']
  2595. ];
  2596. ProcessOrder::workdel($order);
  2597. return error_show(0, "删除成功");
  2598. } else {
  2599. return error_show(1002, "删除失败");
  2600. }
  2601. }
  2602. //废弃接口
  2603. public function status()
  2604. {
  2605. // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2606. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2607. if ($id == "") {
  2608. return error_show(1002, "参数id不能为空");
  2609. }
  2610. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  2611. if ($status == "") {
  2612. return error_show(1002, "订单状态不能为空");
  2613. }
  2614. $dio = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  2615. if (empty($dio)) {
  2616. return error_show(1002, "销售单信息未找到");
  2617. }
  2618. if ($status == 1 && $dio['order_type'] == 2) {
  2619. $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
  2620. if ($zxinfo == false) {
  2621. return error_show(1004, "未找到咨询单数据");
  2622. }
  2623. $gold['price'] = 0;
  2624. if ($zxinfo['zx_type'] == 2) {
  2625. if ($zxinfo['metals'] == "") {
  2626. return error_show(1004, "未找到咨询单贵金属类型数据");
  2627. }
  2628. $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
  2629. $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
  2630. if (empty($gold)) {
  2631. return error_show(1004, "未找到咨询单贵金属类型数据");
  2632. }
  2633. $dio['gold_price'] = $gold['price'];
  2634. }
  2635. $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
  2636. if (empty($wsm)) {
  2637. return error_show(1002, "供应商仓库未找到");
  2638. }
  2639. }
  2640. // $apply_id = GetUserInfo($token);
  2641. // if (empty($apply_id) || $apply_id['code'] != 0) {
  2642. // return error_show(1002, "申请人数据不存在");
  2643. // }
  2644. $rm = $this->uid;
  2645. $ri = $this->uname;
  2646. Db::startTrans();
  2647. try {
  2648. $vmp = $dio['status'];
  2649. $dio['status'] = $status;
  2650. $dio['updatetime'] = date("Y-m-d H:i:s");
  2651. $st = Db::name('sale')->save($dio);
  2652. if ($st) {
  2653. $stn = ["order_code" => $dio['orderCode'], "status" => $vmp, "action_remark" => '', "action_type" => "status"];
  2654. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stn, $dio['order_type'] == 2 ? "ZXQRD" : "XSQRD", $dio['status'], $dio);
  2655. $order = ["order_type" => "XSQRD", "order_code" => $dio['orderCode'], "order_id" => $id, "order_status" => $dio['status'], "before_status" => 1,'holder_id' => $dio['apply_id']];
  2656. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
  2657. if ($status == 3 && $dio['order_type'] == 1) {
  2658. $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
  2659. foreach ($dn as $value) {
  2660. $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
  2661. if ($dm == "") {
  2662. Db::rollback();
  2663. return error_show(1003, "未找到商品数据");
  2664. }
  2665. if ($value['num'] > $dm['usable_stock']) {
  2666. Db::rollback();
  2667. return error_show(1002, "超出库存数量");
  2668. }
  2669. $dm['usable_stock'] -= $value['num'];
  2670. $dm['wait_out_stock'] += $value['num'];
  2671. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], "is_del" => 0])->sum("send_num");
  2672. $value['send_num'] = $send ?? 0;
  2673. $value['wsend_num'] = $value['num'] - $value['send_num'];
  2674. $Db = Db::name('good_stock')->update($dm);
  2675. $Db['updatetime'] = date('Y-m-d H:i:s');
  2676. if ($Db == false) {
  2677. Db::rollback();
  2678. return error_show(1002, "状态更新失败");
  2679. }
  2680. }
  2681. }
  2682. if ($status == 1 && $dio['order_type'] == 2) {
  2683. $cgd = makeNo("CG");
  2684. $clll = [
  2685. "cgdNo" => $cgd,
  2686. "bkcode" => $dio['orderCode'],
  2687. "wsm_code" => $wsm['wsm_code'],
  2688. "cgder_id" => Db::name('depart_user')->where('nickname', $zxinfo['saler'])->value('uid') ?? 0,//重名以及多个账号的话…………
  2689. "cgder" => $zxinfo['saler'],
  2690. "good_code" => "GD-" . $zxinfo['cpNo'],
  2691. "good_name" => $zxinfo['cpName'],
  2692. "good_type_code" => $zxinfo['cpNo'],
  2693. "good_num" => $dio['good_num'],
  2694. "good_price" => $zxinfo['total_fee'],
  2695. "total_fee" => round($zxinfo['total_fee'] * $dio['good_num'], 2),
  2696. "pakge_fee" => $zxinfo['package_fee'],
  2697. "cert_fee" => $zxinfo['cert_fee'],
  2698. "open_fee" => $zxinfo['open_fee'],
  2699. "delivery_fee" => $zxinfo['delivery_fee'],
  2700. "mark_fee" => $zxinfo['mark_fee'],
  2701. "teach_fee" => $zxinfo['cost_fee'],
  2702. "demo_fee" => $zxinfo['demo_fee'],
  2703. "nake_fee" => $zxinfo['bare_fee'],
  2704. "weight" => isset($zxinfo['weight']) ? $zxinfo['weight'] : 0,
  2705. "supplierNo" => $zxinfo['gysNo'],
  2706. "supplier_name" => $zxinfo['gysname'],
  2707. "gold_price" => $gold['price'],
  2708. "send_num" => 0,
  2709. "wsend_num" => $dio['good_num'],
  2710. "remark" => '',
  2711. "lasttime" => date("Y-m-d H:i:s"),
  2712. "is_del" => 0,
  2713. "status" => $dio['send_type'] == 1 ? 3 : 0,
  2714. "order_type" => 2,
  2715. "order_source" => 3,//3项目,废弃接口???
  2716. "addtime" => date("Y-m-d H:i:s"),
  2717. "updatetime" => date("Y-m-d H:i:s")
  2718. ];
  2719. $cgin = Db::name("purchease_order")->insert($clll);
  2720. // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
  2721. if ($cgin == false) {
  2722. $stb = ["order_code" => $cgd, "status" => $clll['status'], "action_remark" => '', "action_type" => "create"];
  2723. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stb, "xsd", $clll['status'], $stb);
  2724. Db::rollback();
  2725. return error_show(1002, "咨询采购单创建商品失败");
  2726. }
  2727. if ($dio['send_type'] == 1) {
  2728. $addr = Db::name('order_addr')->where(["orderCode" => $dio['orderCode'], 'is_del' => 0])->select();
  2729. $i = 1;
  2730. foreach ($addr as $value) {
  2731. $outCode = makeNo("DF");
  2732. //改变编码规则,将原来的outCode后两位换成序列号
  2733. //str_pad字符串填充
  2734. $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  2735. $i++;
  2736. $data = [
  2737. "wsm_code" => $wsm['wsm_code'],
  2738. "orderCode" => $dio['orderCode'],
  2739. "outCode" => $outCode,
  2740. "order_type" => $dio['order_type'],
  2741. "apply_id" => $rm,
  2742. "apply_name" => $ri,
  2743. "addrid" => $value['id'],
  2744. "post_name" => '',
  2745. "post_code" => '',
  2746. "post_fee" => '',
  2747. "sendtime" => date("Y-m-d H:i:s"),
  2748. "send_num" => $value['receipt_quantity'],
  2749. "check_num" => 0,
  2750. "error_num" => 0,
  2751. "status" => 0,
  2752. "addtime" => date("Y-m-d H:i:s"),
  2753. "updatetime" => date("Y-m-d H:i:s")
  2754. ];
  2755. $datainfo = Db::name('order_out')->insertGetId($data);
  2756. if (!$datainfo) {
  2757. $sti = ["order_code" => $dio['orderCode'], "status" => 0, "action_remark" => '', "action_type" => "create"];
  2758. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $sti, "xsd", 0, $sti);
  2759. Db::rollback();
  2760. return error_show(1003, "创建失败");
  2761. } else {
  2762. //修改状态,添加待办
  2763. ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
  2764. "order_code" => $outCode,//出库单号
  2765. "status" => 0,//这里的status是之前的值
  2766. "action_remark" => '',//备注
  2767. "action_type" => "create"//新建create,编辑edit,更改状态status
  2768. ], "CKD", 0, $data);
  2769. ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], [
  2770. "order_type" => 'CKD',
  2771. "order_code" => $outCode,//出库单号
  2772. "order_id" => $datainfo,
  2773. "order_status" => 0,
  2774. "before_status" => 0,
  2775. 'holder_id'=>$data['apply_id'],
  2776. ]);
  2777. }
  2778. }
  2779. $wsm_in_code = makeNo("CF");
  2780. $orin = [
  2781. "wsm_in_code" => $wsm_in_code,
  2782. "cgdNo" => $cgd,
  2783. "wsm_code" => $wsm['wsm_code'],
  2784. "wsm_reaper" => "",
  2785. "send_num" => $dio['good_num'],
  2786. "post_company" => '',
  2787. "post_code" => '',
  2788. "post_fee" => '',
  2789. "sendtime" => date("Y-m-d H:i:s"),
  2790. "apply_id" => $rm,
  2791. "apply_name" => $ri,
  2792. "wait_num" => 0,
  2793. "status" => 4,
  2794. "addtime" => date("Y-m-d H:i:s"),
  2795. "updatetime" => date("Y-m-d H:i:s")
  2796. ];
  2797. $win = Db::name("purchease_in")->insert($orin);
  2798. if (!$win) {
  2799. $stv = ["order_code" => $wsm_in_code, "status" => 4, "action_remark" => '', "action_type" => "create"];
  2800. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stv, "xsd", 4, $stv);
  2801. Db::rollback();
  2802. return error_show(1003, "创建失败");
  2803. }
  2804. //维护台账
  2805. 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}'");
  2806. $good = Db::name("good_stock")->where(["wsm_code" => $wsm['wsm_code'], "good_type_code" => $zxinfo['cpNo'], "is_del" => 0])->find();
  2807. if (empty($good)) {
  2808. $good = [
  2809. "good_type_code" => $zxinfo['cpNo'],
  2810. "wsm_code" => $wsm['wsm_code'],
  2811. "usable_stock" => 0,
  2812. "wait_out_stock" => 0,
  2813. "total_stock" => 0,
  2814. "addtime" => date("Y-m-d H:i:s"),
  2815. "updatetime" => date("Y-m-d H:i:s"),
  2816. ];
  2817. }
  2818. $good['wait_out_stock'] += $dio['good_num'];
  2819. $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
  2820. $good['updatetime'] = date("Y-m-d H:i:s");
  2821. $upd = Db::name("good_stock")->save($good);
  2822. if (!$upd) {
  2823. $ste = ["order_code" => $zxinfo['cpNo'], "status" => 0, "action_remark" => '', "action_type" => "create"];
  2824. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $ste, "xsd", 0, $ste);
  2825. Db::rollback();
  2826. return error_show(1003, "创建失败");
  2827. }
  2828. }
  2829. }
  2830. }
  2831. Db::commit();
  2832. return error_show(0, "订单状态更新成功");
  2833. } catch (Exception $e) {
  2834. Db::rollback();
  2835. return error_show(1005, $e->getMessage());
  2836. }
  2837. }
  2838. public function fee()
  2839. {
  2840. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  2841. if ($id == "") {
  2842. return error_show(1002, "参数id不能为空");
  2843. }
  2844. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  2845. if (empty($etid)) {
  2846. return error_show(1002, "未找到数据");
  2847. }
  2848. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  2849. if ($vr == "") {
  2850. return error_show(1002, "参数order_addr不能为空");
  2851. }
  2852. Db::startTrans();
  2853. try {
  2854. $data = [
  2855. "id" => $id,
  2856. "status" => 2,
  2857. "is_del" => 0,
  2858. "updatetime" => date("Y-m-d H:i:s")
  2859. ];
  2860. $datainfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($data);
  2861. if ($datainfo) {
  2862. $stx = ["order_code" => $etid['orderCode'], "status" => $etid['status'], "action_remark" => '', "action_type" => "edit"];
  2863. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, "XSQRD", 2, $data);
  2864. $order = ["order_type" => "XSQRD", "order_code" => $etid['orderCode'], "order_id" => $id, "order_status" => $data['status'], "before_status" => 0,'holder_id'=>$etid['apply_id']];
  2865. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
  2866. foreach ($vr as $value) {
  2867. $tm = [];
  2868. $tm['id'] = $value['id'];
  2869. $tm['orderCode'] = $etid['orderCode'];
  2870. $tm['post_fee'] = $value['post_fee'];
  2871. $tm['updatetime'] = date("Y-m-d H:i:s");
  2872. $dn = Db::name('order_addr')->save($tm);
  2873. if ($dn == false) {
  2874. Db::rollback();
  2875. return error_show(1002, "更新失败");
  2876. }
  2877. }
  2878. Db::commit();
  2879. return error_show(0, "更新成功");
  2880. }
  2881. Db::rollback();
  2882. return error_show(1003, "更新失败");
  2883. } catch (Exception $e) {
  2884. Db::rollback();
  2885. return error_show(1005, $e->getMessage());
  2886. }
  2887. }
  2888. // 废弃
  2889. public function out()
  2890. {
  2891. // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2892. $outCode = makeNo("DF");
  2893. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  2894. if ($orderCode == "") {
  2895. return error_show(1002, "参数orderCoder不能为空");
  2896. }
  2897. $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
  2898. if ($der == "") {
  2899. return error_show(1002, "未找到出库订单单号");
  2900. }
  2901. // $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  2902. // if ($wsm_code == "") {
  2903. // return error_show(1002, "参数wsm_code不能为空");
  2904. // }
  2905. // $wsm = Db::name('sale_info')->where(['wsm_code' => $wsm_code, 'orderCode' => $der['orderCode']])->find();
  2906. // if ($wsm == "") {
  2907. // return error_show(1002, "未找到仓库编码");
  2908. // }
  2909. $post_name = isset($this->post['post_name']) && $this->post['post_name'] !== "" ? trim($this->post['post_name']) : "";
  2910. if ($post_name == "") {
  2911. return error_show(1002, "物流公司不能为空");
  2912. }
  2913. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
  2914. if ($post_code == "") {
  2915. return error_show(1002, "物流单号不能为空");
  2916. }
  2917. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
  2918. if ($post_fee == "") {
  2919. return error_show(1002, "物流费不能为空");
  2920. }
  2921. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  2922. if ($send_num == "") {
  2923. return error_show(1002, "发货数量不能为空");
  2924. }
  2925. if ($send_num > $der['wsend_num']) {
  2926. return error_show(1002, "超出可发货数量");
  2927. }
  2928. // $apply_id = GetUserInfo($token);
  2929. // if (empty($apply_id) || $apply_id['code'] != 0) {
  2930. // return error_show(1002, "申请人数据不存在");
  2931. // }
  2932. $rm = $this->uid;
  2933. $ri = $this->uname;
  2934. $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
  2935. $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
  2936. if (empty($dr)) {
  2937. return error_show(1003, "收货人信息未找到");
  2938. }
  2939. if ($dr['orderCode'] !== $orderCode) {
  2940. return error_show(1002, "订单code不存在");
  2941. }
  2942. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  2943. // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
  2944. // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
  2945. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "1";
  2946. //$order_type = isset($this->post['order_type']) && $this->post['order_type'] !=="" ? $this->post['order_type'] :"1";
  2947. //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
  2948. Db::startTrans();
  2949. try {
  2950. $data = [
  2951. "wsm_code" => "",
  2952. "orderCode" => $orderCode,
  2953. "outCode" => $outCode,
  2954. "order_type" => $der['order_type'],
  2955. "apply_id" => $rm,
  2956. "apply_name" => $ri,
  2957. "addrid" => $dr['id'],
  2958. "post_name" => $post_name,
  2959. "post_code" => $post_code,
  2960. "post_fee" => $post_fee,
  2961. "sendtime" => $sendtime,
  2962. "send_num" => $send_num,
  2963. "check_num" => 0,
  2964. "error_num" => 0,
  2965. "status" => $status,
  2966. "addtime" => date("Y-m-d H:i:s"),
  2967. "updatetime" => date("Y-m-d H:i:s")
  2968. ];
  2969. $datainfo = Db::name('order_out')->insert($data, true);
  2970. if ($datainfo > 0) {
  2971. $stx = ["order_code" => $outCode, "status" => $status, "action_remark" => '', "action_type" => "create"];
  2972. ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], $stx, $der['order_type'] == 1 ? "CKD" : 'ZXCKD', $status, $data);
  2973. //是否库存品,待办数据推送到的人有区别,
  2974. //库存品——>推到库管,非库存品——>推送供应商负责人
  2975. $order=[];
  2976. if($data['status'] == 1){
  2977. if($der['is_stock'] == 1){
  2978. //库存品,推给库管和库管-张凯旋
  2979. $roleid = config('app.wsm_cgder_role');
  2980. $uids = Db::name('user_role')
  2981. ->where('is_del', 0)
  2982. ->whereIn('roleid', $roleid)
  2983. ->column('uid');
  2984. $order = ["order_type" => "CKD", "order_code" => $outCode, "order_id" => $datainfo, "order_status" => $data['status'], "before_status" => 0, 'handle_user_list' => implode(',', $uids)];
  2985. }else{
  2986. //推给供应商负责人 ###todo::接口废弃
  2987. $supplier = Db::name('supplier')
  2988. ->alias('a')
  2989. ->field('a.id,a.person,a.personid')
  2990. ->leftJoin('purchease_order b', 'b.is_del=0 AND b.supplierNo=a.code')
  2991. ->leftJoin('order_num c', 'c.cgdNo=b.cgdNo')
  2992. ->where('c.orderCode', $orderCode)
  2993. ->findOrEmpty();
  2994. $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'] ?? ''];
  2995. }
  2996. }
  2997. 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']];
  2998. ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], $order);
  2999. if ($status == 1) {
  3000. $item = $der['status'];
  3001. $der['send_num'] += $send_num;
  3002. $der['wsend_num'] -= $send_num;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  3003. $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
  3004. $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
  3005. $der['updatetime'] = date("Y-m-d H:i:s");
  3006. $si = Db::name('sale')->save($der);
  3007. if ($si == false) {
  3008. Db::rollback();
  3009. return error_show(1003, "更新失败");
  3010. }
  3011. $stx = ["order_code" => $orderCode, "status" => $item, "action_remark" => '', "action_type" => "edit"];
  3012. ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], $stx, "XSQRD", $der['status'], $der);
  3013. $order = ["order_type" => "XSQRD", "order_code" => $orderCode, "order_id" => $der['id'], "order_status" => $data['status'], "before_status" => 0,'holder_id'=>$der['apply_id']];
  3014. ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], $order);
  3015. }
  3016. Db::commit();
  3017. return error_show(0, "创建成功");
  3018. } else {
  3019. Db::rollback();
  3020. return error_show(1003, "创建失败");
  3021. }
  3022. } catch (Exception $e) {
  3023. Db::rollback();
  3024. return error_show(1005, $e->getMessage());
  3025. }
  3026. }
  3027. // 废弃
  3028. public function customer()
  3029. {
  3030. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  3031. if (empty($outCode)) {
  3032. return error_show(1002, "销售订单编号不能为空");
  3033. }
  3034. $codeinfo = Db::name('order_out')->where(['outCode' => $outCode])->find();
  3035. if ($codeinfo == "") {
  3036. return error_show(1003, "未找到订单数据");
  3037. }
  3038. // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  3039. // if($orderCode==""){
  3040. // return error_show(1002,"参数orderCoder不能为空");
  3041. // }
  3042. $dr = Db::name('sale')->where(['orderCode' => $codeinfo['orderCode']])->find();
  3043. if ($dr == "") {
  3044. return error_show(1002, "未找到销售订单");
  3045. }
  3046. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "";
  3047. if ($status == "") {
  3048. return error_show(10002, "状态不能为空");
  3049. }
  3050. Db::startTrans();
  3051. try {
  3052. $time = $codeinfo['status'];
  3053. $codeinfo['status'] = $status;
  3054. $codeinfo['updatetime'] = date("Y-m-d H:i:s");
  3055. $cust = Db::name('order_out')->save($codeinfo);
  3056. if ($cust) {
  3057. $stx = ["order_code" => $outCode, "status" => $time, "action_remark" => '', "action_type" => "status"];
  3058. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, "CKD", $codeinfo['status'], $codeinfo);
  3059. $order = [];
  3060. if ($status == 1) {
  3061. //推给供应商负责人#todo::接口废弃
  3062. if ($dr['is_stock'] == 0) {
  3063. $supplier = Db::name('supplier')
  3064. ->alias('a')
  3065. ->field('a.id,a.person,a.personid')
  3066. ->leftJoin('purchease_order b', 'b.is_del=0 AND b.supplierNo=a.code')
  3067. ->leftJoin('order_num c', 'c.cgdNo=b.cgdNo')
  3068. ->where('c.orderCode', $codeinfo['orderCode'])
  3069. ->findOrEmpty();
  3070. $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'] ?? ''];
  3071. } else{
  3072. $roleid = config('app.wsm_cgder_role');
  3073. $uids = Db::name('user_role')
  3074. ->where('is_del', 0)
  3075. ->whereIn('roleid', $roleid)
  3076. ->column('uid');
  3077. $order = ["order_type" => "CKD", "order_code" => $outCode, "order_id" => $codeinfo['id'], "order_status" => $codeinfo['status'], "before_status" => 0, 'handle_user_list' => implode(',', $uids)];
  3078. }
  3079. }
  3080. 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']];
  3081. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
  3082. if ($status == 1) {
  3083. $stokc = Db::name("good_stock")->where(['spuCode' => $codeinfo['spuCode'], "wsm_code" => $codeinfo['wsm_code'],
  3084. "is_del" => 0])->find();
  3085. if ($stokc == false) {
  3086. Db::rollback();
  3087. return error_show(1002, "未找库存到数据");
  3088. } else {
  3089. if ($codeinfo['send_num'] > $stokc['usable_stock']) {
  3090. Db::rollback();
  3091. return error_show(1002, "超出库存数量");
  3092. }
  3093. $stokc['wait_out_stock'] += $codeinfo['send_num'];
  3094. $stokc['usable_stock'] -= $codeinfo['send_num'];
  3095. $stokc['updatetime'] = date("Y-m-d H:i:s");
  3096. }
  3097. $stoc = Db::name("good_stock")->save($stokc);
  3098. if ($stoc == false) {
  3099. Db::rollback();
  3100. return error_show(1002, "库存更新失败");
  3101. }
  3102. $item = $dr['status'];
  3103. $dr['send_num'] += $codeinfo['send_num'];
  3104. $dr['wsend_num'] -= $codeinfo['send_num'];//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  3105. $dr['send_status'] = $dr['send_num'] == 0 ? 1 : $dr['wsend_num'] == 0 ? 3 : 2;
  3106. $dr['status'] = $dr['send_num'] == 0 ? 3 : $dr['wsend_num'] == 0 ? 5 : 4;
  3107. $dr['updatetime'] = date("Y-m-d H:i:s");
  3108. $si = Db::name('sale')->save($dr);
  3109. if ($si == false) {
  3110. Db::rollback();
  3111. return error_show(1003, "更新失败");
  3112. }
  3113. $stx = ["order_code" => $dr['orderCode'], "status" => $item, "action_remark" => '', "action_type" => "edit"];
  3114. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, $dr['order_type'] == 2 ? "ZXQRD" : "XSQRD", $dr['status'],$dr);
  3115. $order = ["order_type" => "XSQRD", "order_code" => $dr['orderCode'], "order_id" => $dr['id'], "order_status" => $dr['status'], "before_status" => 0, 'holder_id' => $dr['apply_id']];
  3116. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
  3117. //商品变动日志表,good_log_code字段存储销售订单编号
  3118. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stoc['id'], "type" => 1, 'stock' => $codeinfo['send_num'], "stock_name" => "wait_out_stock"];
  3119. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stoc['id'], "type" => 2, 'stock' => $codeinfo['send_num'], "stock_name" => "usable_stock"];
  3120. GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname], $good_data, 'CKD');
  3121. }
  3122. if ($status == 3) {
  3123. $var = Db::name('good_stock')->where(['wsm_code' => $codeinfo['wsm_code'], 'good_type_code' => $dr['good_code']])->find();
  3124. if ($var == false) {
  3125. Db::rollback();
  3126. return error_show(1002, "未找到商品数据");
  3127. }
  3128. if ($codeinfo['send_num'] > $var['intra_stock']) {
  3129. Db::rollback();
  3130. return error_show(1003, "超出在途库存数量");
  3131. }
  3132. $var['intra_stock'] -= $codeinfo['send_num'];
  3133. $var['updatetime'] = date("Y-m-d H:i:s");
  3134. $stre = Db::name('good_stock')->save($var);
  3135. //商品变动日志表,good_log_code字段存储销售订单编号
  3136. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $var['id'], "type" => 2, 'stock' => $codeinfo['send_num'], "stock_name" => "intra_stock"];
  3137. GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname], $good_data, $codeinfo['order_type'] == 2 ? "ZXCKD" : "CKD");
  3138. if ($stre == false) {
  3139. Db::rollback();
  3140. return error_show(1002, "状态更新失败");
  3141. }
  3142. }
  3143. Db::commit();
  3144. return error_show(0, "出库订单更新成功");
  3145. } else {
  3146. Db::rollback();
  3147. return error_show(1003, "出库订单更新失败");
  3148. }
  3149. } catch (Exception $e) {
  3150. Db::rollback();
  3151. return error_show(1005, $e->getMessage());
  3152. }
  3153. }
  3154. public function difflist()
  3155. {
  3156. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  3157. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  3158. $where = [];
  3159. $cgdNo = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
  3160. if ($cgdNo != "") {
  3161. $where[] = ['a.orderCode', "like", "%$cgdNo%"];
  3162. }
  3163. $diffNo = isset($this->post['diffCode']) && $this->post['diffCode'] != "" ? trim($this->post['diffCode']) : "";
  3164. if ($diffNo != "") {
  3165. $where[] = ['a.diffCode', "like", "%$diffNo%"];
  3166. }
  3167. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  3168. if ($status !== "") {
  3169. $where[] = ['a.status', "=", $status];
  3170. }
  3171. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  3172. if ($start != "") {
  3173. $where[] = ["a.addtime", '>=', $start];
  3174. }
  3175. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  3176. if ($end != "") {
  3177. $where[] = ["a.addtime", '<=', $end];
  3178. }
  3179. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  3180. if ($companyNo != "") {
  3181. $where[] = ['a.companyNo', "like", "%$companyNo%"];
  3182. }
  3183. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  3184. if ($customer_code != "") {
  3185. $where[] = ['a.customerNo', "like", "%$customer_code%"];
  3186. }
  3187. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  3188. if ($supplierNo != "") {
  3189. $where[] = ['a.supplierNo', "like", "%$supplierNo%"];
  3190. }
  3191. $relaComNo = trim($this->post['relaComNo'] ?? '');
  3192. if ($relaComNo !== "") {
  3193. $where[] = ['a.companyNo', "=", $relaComNo];
  3194. }
  3195. $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? trim($this->post['order_source']) : "";
  3196. if ($order_source !== "") {
  3197. $where[] = ['c.order_source', "=", $order_source];
  3198. }
  3199. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] != "" ? trim($this->post['is_stock']) : "";
  3200. if ($is_stock !== "") {
  3201. $where[] = ['c.is_stock', "=", $is_stock];
  3202. }
  3203. // $role=$this->checkRole();
  3204. // if(!empty($role['write'])){
  3205. // $where[]=["apply_id","in",$role['write']];
  3206. // }
  3207. // $role = $this->checkDataShare();
  3208. // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['c.apply_id', 'in', $role[DataGroupModel::$type_全部]];
  3209. $role = $this->checkDataShare();
  3210. $hand = resign_hand_user($this->uid, 0);
  3211. if (!empty($role[DataGroupModel::$type_全部])) {
  3212. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  3213. $where[] = ['c.apply_id', 'in', $arr];
  3214. }
  3215. // if(!empty($role['platform']) ){
  3216. // $where[]=["c.platform_id","in",$role['platform']];
  3217. // }
  3218. $count = Db::name('sale_diff')
  3219. ->alias('a')
  3220. ->join("sale c", "c.orderCode=a.orderCode", "left")
  3221. // ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  3222. ->where($where)
  3223. ->count();
  3224. $total = ceil($count / $size);
  3225. $page = $page >= $total ? intval($total) : $page;
  3226. $list = Db::name('sale_diff')
  3227. ->alias('a')
  3228. ->field("a.*,c.skuCode,c.order_type,c.apply_id,c.order_source,c.is_stock")
  3229. ->join("sale c", "c.orderCode=a.orderCode", "left")
  3230. // ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  3231. ->where($where)
  3232. ->page($page, $size)
  3233. ->order("a.addtime desc")
  3234. ->select()
  3235. ->toArray();
  3236. $data = [];
  3237. // $userCommon = \app\admin\common\User::getIns();
  3238. // $names = $userCommon->handle('getCodeAndName',['code'=>array_merge(array_column($list,'supplierNo'),array_column($list,'customer_code'))]);
  3239. foreach ($list as $value) {
  3240. if (in_array($value['order_type'], [3, 4])) {
  3241. $goon = Db::name("good_zixun")->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
  3242. } else {
  3243. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  3244. ->where(['a.skuCode' => $value['skuCode']])->find();
  3245. }
  3246. $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  3247. // $wsm = Db::name("business")->where(['companyNo' => $value['supplierNo']])->find();
  3248. // $value['supplierNo'] = $value['supplierNo'];//isset($wsm['companyNo']) ? $wsm['companyNo'] : "";
  3249. // $value['supplierName'] = $names['data'][$value['supplierNo']] ?? '';//isset($wsm['company']) ? $wsm['company'] : "";
  3250. // $value['customer_name'] = $names['data'][$value['customer_code']] ?? '';//isset($wsm['company']) ? $wsm['company'] : "";
  3251. //是否具有编辑权限
  3252. $value['is_allow_update'] = 0;
  3253. if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  3254. $data[] = $value;
  3255. }
  3256. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  3257. }
  3258. /**
  3259. * @return \think\response\Json|void
  3260. * @throws \think\db\exception\DataNotFoundException
  3261. * @throws \think\db\exception\DbException
  3262. * @throws \think\db\exception\ModelNotFoundException
  3263. */
  3264. //工差单审核
  3265. public function diffcheck()
  3266. {
  3267. // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  3268. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  3269. if ($id === "") {
  3270. return error_show(1004, "参数id不能为空");
  3271. }
  3272. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  3273. if (empty($info)) {
  3274. return error_show(1004, "订单数据未找到");
  3275. }
  3276. $sale = Db::name("sale")->where(["orderCode" => $info["orderCode"]])->find();
  3277. if ($sale == false) {
  3278. return error_show(1004, "订单数据未找到");
  3279. }
  3280. $cgd = Db::name("purchease_diff")->where(['id' => $info['cgd_diffid']])->find();
  3281. if ($cgd == false) {
  3282. return error_show(1004, "采购工差单数据未找到");
  3283. }
  3284. $is_act = isset($this->post['is_act']) && $this->post['is_act'] !== "" ? intval($this->post['is_act']) : "";
  3285. if ($is_act === '') {
  3286. return error_show(1004, "参数is_act不能为空");
  3287. }
  3288. $customer_remark = isset($this->post['customer_remark']) && $this->post['customer_remark'] !== "" ? trim($this->post['customer_remark']) : "";
  3289. if ($customer_remark === '') {
  3290. return error_show(1004, "参数customer_remark不能为空");
  3291. }
  3292. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "2";
  3293. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  3294. $item = $info['status'];
  3295. $info['is_act'] = $is_act;
  3296. $info['customer_remark'] = $customer_remark;
  3297. $info['status'] = $status;
  3298. $info['remark'] = $remark;
  3299. $info['updatetime'] = date("Y-m-d H:i:s");
  3300. Db::startTrans();
  3301. try {
  3302. $up = Db::name("sale_diff")->save($info);
  3303. if ($up) {
  3304. $stx = ["order_code" => $info["orderCode"], "status" => $item, "action_remark" => '', "action_type" => "edit"];
  3305. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, "XSGCD", $info['status'], $info);
  3306. $order = ["order_type" => "XSGCD", "order_code" => $info["orderCode"], "order_id" => $info['id'], "order_status" => $info['status'], "before_status" => $item,'holder_id'=>$sale['apply_id']];
  3307. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
  3308. $upda = [
  3309. "status" => $status,
  3310. "remark" => $remark,
  3311. "updatetime" => date("Y-m-d H:i:s"),
  3312. ];
  3313. $old_purchease_diff = Db::name("purchease_diff")
  3314. ->field('id,cgdNo,status')
  3315. ->where(["id" => $info['cgd_diffid']])
  3316. ->find();
  3317. $cgdup = Db::name("purchease_diff")->where(["id" => $info['cgd_diffid']])->save($upda);
  3318. if ($cgdup) {
  3319. if ($status == 2) {
  3320. if ($customer_remark == 1) {
  3321. $sale['diff_weight'] = $info['diff_weight'];
  3322. $sale['diff_fee'] = $info['diff_price'];
  3323. $sale['updatetime'] = date("Y-m-d H:i:s");
  3324. $sal = Db::name("sale")->save($sale);
  3325. if ($sal == false) {
  3326. Db::rollback();
  3327. return error_show(1003, "订单更新工差失败");
  3328. }
  3329. }
  3330. $cgdup = Db::name("purchease_order")->where(["cgdNo" => $cgd['cgdNo']])->save
  3331. (["diff_weight" => $cgd['diff_weight'], "diff_fee" => $cgd['diff_price'], "updatetime" => date("Y-m-d H:i:s")]);
  3332. if ($cgdup == false) {
  3333. Db::rollback();
  3334. return error_show(1003, "采购订单更新工差失败");
  3335. }
  3336. }
  3337. $a = ["order_code" => $old_purchease_diff["cgdNo"], "status" => $old_purchease_diff['status'], "action_remark" => '', "action_type" => "status"];
  3338. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $a, "CGGCD", $upda['status'], $info);
  3339. $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']];
  3340. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $b);
  3341. Db::commit();
  3342. return app_show(0, "更新成功");
  3343. }
  3344. }
  3345. Db::rollback();
  3346. return error_show(1003, "更新失败");
  3347. } catch (\Exception $e) {
  3348. Db::rollback();
  3349. return error_show(1003, $e->getMessage());
  3350. }
  3351. }
  3352. /**
  3353. * @return \think\response\Json|void
  3354. * @throws \think\db\exception\DataNotFoundException
  3355. * @throws \think\db\exception\DbException
  3356. * @throws \think\db\exception\ModelNotFoundException
  3357. */
  3358. public function diffstatus()
  3359. {
  3360. // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  3361. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  3362. if ($id === "") {
  3363. return error_show(1004, "参数id不能为空");
  3364. }
  3365. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  3366. if ($info == false) {
  3367. return error_show(1004, "工差单数据未找到");
  3368. }
  3369. $sale = Db::name("sale")->where(["orderCode" => $info["orderCode"]])->find();
  3370. if ($sale == false) {
  3371. return error_show(1004, "订单数据未找到");
  3372. }
  3373. $cgd = Db::name("purchease_diff")->where(['id' => $info['cgd_diffid']])->find();
  3374. if ($cgd == false) {
  3375. return error_show(1004, "采购工差单数据未找到");
  3376. }
  3377. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "3";
  3378. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  3379. $ite = $info['status'];
  3380. Db::startTrans();
  3381. try {
  3382. $upda = [
  3383. "status" => $status,
  3384. "remark" => $remark,
  3385. "updatetime" => date("Y-m-d H:i:s"),
  3386. ];
  3387. $up = Db::name("sale_diff")->where($info)->save($upda);
  3388. if ($up) {
  3389. $stx = ["order_code" => $info["orderCode"], "status" => $ite, "action_remark" => '', "action_type" => "status"];
  3390. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, "XSGCD", $status, $info);
  3391. $order = ["order_type" => "XSGCD", "order_code" => $info["orderCode"], "order_id" => $info['id'],"order_status" => $status, "before_status" => $ite,'holder_id'=>$sale['apply_id']];
  3392. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
  3393. $cgdup = Db::name("purchease_diff")->where(["id" => $info['cgd_diffid']])->save($upda);
  3394. if ($cgdup) {
  3395. if ($status == 2 && $info['customer_remark'] == 1) {
  3396. $sale['diff_weight'] = $info['diff_weight'];
  3397. $sale['diff_fee'] = $info['diff_price'];
  3398. $sale['updatetime'] = date("Y-m-d H:i:s");
  3399. $sal = Db::name("sale")->save($sale);
  3400. if ($sal == false) {
  3401. Db::rollback();
  3402. return error_show(1003, "订单更新工差失败");
  3403. }
  3404. }
  3405. Db::commit();
  3406. return app_show(0, "更新成功");
  3407. }
  3408. }
  3409. Db::rollback();
  3410. return error_show(1003, "更新失败");
  3411. } catch (\Exception $e) {
  3412. Db::rollback();
  3413. return error_show(1003, $e->getMessage());
  3414. }
  3415. }
  3416. /**
  3417. * @return \think\response\Json|void
  3418. * @throws \think\db\exception\DataNotFoundException
  3419. * @throws \think\db\exception\DbException
  3420. * @throws \think\db\exception\ModelNotFoundException
  3421. */
  3422. public function diffinfo()
  3423. {
  3424. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  3425. if ($id === "") {
  3426. return error_show(1004, "参数id不能为空");
  3427. }
  3428. $info = Db::name('sale_diff')->where(["id" => $id])->find();
  3429. if (empty($info)) {
  3430. return error_show(1004, "工差订单数据未找到");
  3431. }
  3432. $einfo = Db::name('sale')->where(['orderCode' => $info['orderCode'], 'is_del' => 0])->find();
  3433. if ($einfo == false) {
  3434. return error_show(1002, "未找到销售订单数据");
  3435. }
  3436. if (in_array($einfo['order_type'], [3, 4])) {
  3437. $goon = Db::name("good_zixun")->where(["spuCode" => $einfo['good_code'], "is_del" => 0])->find();
  3438. } else {
  3439. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  3440. ->where(['a.skuCode' => $einfo['skuCode']])->find();
  3441. }
  3442. if ($goon == false) {
  3443. return error_show(1002, "未找到商品数据");
  3444. }
  3445. $info['skuCode'] = isset($goon['skuCode']) ? $goon['skuCode'] : "";
  3446. $info['spuCode'] = isset($goon['spuCode']) ? $goon['spuCode'] : "";
  3447. $info['order_type'] = isset($einfo['order_type']) ? $einfo['order_type'] : "";
  3448. $info['can'] = isset($info['cat_id']) && $info['cat_id'] !== 0 ? made($info['cat_id']) : [];
  3449. return app_show(0, "获取成功", $info);
  3450. }
  3451. //发货申请单列表
  3452. public function saleout()
  3453. {
  3454. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  3455. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  3456. $where = [["a.is_del", "=", 0]];
  3457. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  3458. if ($orderCode !== "") {
  3459. $where[] = ['a.orderCode', "like", "%$orderCode%"];
  3460. }
  3461. $order_type = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? trim($this->post['order_type']) : "";
  3462. if ($order_type !== "") {
  3463. $where[] = ['a.order_type', "=", $order_type];
  3464. }
  3465. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  3466. if ($outCode !== "") {
  3467. $where[] = ['a.outCode', "like", "%$outCode%"];
  3468. }
  3469. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name']) : "";
  3470. if ($apply_name !== "") {
  3471. $where[] = ['a.apply_name', "like", "%$apply_name%"];
  3472. }
  3473. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  3474. if ($good_code !== "") {
  3475. $where[] = ['b.good_code', "like", "%$good_code%"];
  3476. }
  3477. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  3478. if ($good_name !== "") {
  3479. $where[] = ['b.good_name', "like", "%$good_name%"];
  3480. }
  3481. $supplier_name = isset($this->post['supplier_name']) && $this->post['supplier_name'] !== "" ? trim($this->post['supplier_name']) : "";
  3482. if ($supplier_name !== "") {
  3483. $where[] = ['b.supName', "like", "%$supplier_name%"];
  3484. }
  3485. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  3486. if ($status !== "") {
  3487. $where[] = ['a.status', "=", $status];
  3488. }
  3489. $send_status = isset($this->post['send_status']) && $this->post['send_status'] !== "" ? trim($this->post['send_status']) : "";
  3490. if ($send_status !== "") {
  3491. $where[] = ['a.send_status', "=", $send_status];
  3492. }
  3493. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  3494. if ($start != "") {
  3495. $where[] = ["a.addtime", '>=', $start . " 00:00:00"];
  3496. }
  3497. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  3498. if ($end != "") {
  3499. $where[] = ["a.addtime", '<=', $end . " 23:59:59"];
  3500. }
  3501. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  3502. if ($companyNo != "") {
  3503. $where[] = ['b.supplierNo', "like", "%$companyNo%"];
  3504. }
  3505. $customer_code = isset($this->post['customerCode']) && $this->post['customerCode'] !== "" ? trim($this->post['customerCode']) : "";
  3506. if ($customer_code != "") {
  3507. $where[] = ['b.customer_code', "like", "%$customer_code%"];
  3508. }
  3509. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] !== "" ? trim($this->post['relaComNo']) : "";
  3510. if ($relaComNo != '') $where[] = ['b.supplierNo', '=', $relaComNo];
  3511. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  3512. if ($supplierNo != '') {
  3513. //sale b 表里存的supplierNo值是GS开头的,即业务公司编码
  3514. //所以此处应该根据供应商编码筛选商品spuCode,然后筛选发货单
  3515. $spuCode = Db::name('good_basic')
  3516. ->where(['is_del' => 0, 'supplierNo' => $supplierNo])
  3517. ->column('spuCode');
  3518. $where[] = ['b.good_code', 'in', $spuCode];
  3519. }
  3520. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo'] !== "" ? $this->post['cgdNo'] : "";
  3521. if ($cgdNo != "") {
  3522. $where[] = ["os.cgdNo", 'like', '%' . $cgdNo . '%'];
  3523. }
  3524. $condition = '';
  3525. $level= isset($this->post['level']) && $this->post['level'] !== '' ? $this->post['level'] : '0';
  3526. //只有level2的账号过滤数据权限
  3527. if ($level=='0'&& $this->level == 2) {
  3528. // //如果是供应商负责人,根据供应商筛选
  3529. // $person_supplier = Db::connect('mysql_sys')
  3530. // ->name('supplier')
  3531. // ->where(['is_del' => 0, 'personid' =>$this->uid])
  3532. // ->column('code');
  3533. //
  3534. // if(!empty($person_supplier)) $condition = "b.supNo in ('" . implode('\',\'', $person_supplier) . "')";
  3535. // else{
  3536. //不是供应商负责人,根据数据权限筛选申请人
  3537. $role = $this->checkDataShare();
  3538. if (!empty($role[DataGroupModel::$type_全部])) $condition = " a.apply_id in (" . implode(',', $role[DataGroupModel::$type_全部]) . ")";
  3539. // }
  3540. // $hand = resign_hand_user($this->uid, 0);
  3541. // $uidarr = implode(",", $hand);
  3542. // //库管只能看到库存品订单,供应商负责人只能看到非库存品订单
  3543. // if (!in_array($this->roleid, [1, 33])) {
  3544. // //库管看到所有的库存品发货申请单
  3545. // if (in_array($this->roleid, config('app.wsm_cgder_role'))) $condition .= " b.is_stock=1";
  3546. // else {
  3547. // $role = $this->checkDataShare();
  3548. // if (!empty($role[DataGroupModel::$type_全部])) {
  3549. // $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  3550. // if ($condition != '') $condition .= " or ";
  3551. // $condition .= " a.apply_id in (" . implode(',', $arr) . ")";
  3552. // }
  3553. // }
  3554. //// $personid = Db::name('supplier')->field('id')->where(['is_del' => 0, 'personid' => $hand])->findOrEmpty();
  3555. // if (!empty($hand)) {
  3556. // if ($condition != '') $condition .= " or ";
  3557. //// $condition .= "(b.is_stock=0 and sip.personid in ($uidarr))";
  3558. //
  3559. // $person_supplier = Db::connect('mysql_sys')
  3560. // ->name('supplier')
  3561. // ->where(['is_del'=>0,'personid'=>$uidarr])
  3562. // ->column('code');
  3563. //
  3564. // $condition .= "(b.is_stock=0 and wpo.supplierNo in ('" . implode('\',\'', $person_supplier) . "'))";
  3565. // }
  3566. // }
  3567. }
  3568. // if(!empty($role['platform']) ){
  3569. // $where[]=["b.platform_id","in",$role['platform']];
  3570. // }
  3571. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  3572. if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
  3573. //发货时间筛选
  3574. $start_sendtime = isset($this->post['start_sendtime']) && $this->post['start_sendtime'] !== "" ? $this->post['start_sendtime'] : "";
  3575. $end_sendtime = isset($this->post['end_sendtime']) && $this->post['end_sendtime'] !== "" ? $this->post['end_sendtime'] : "";
  3576. if ($start_sendtime != "" && $end_sendtime != "") {
  3577. $where[] = ["a.sendtime", 'between', [$start_sendtime . " 00:00:00", $end_sendtime . " 23:59:59"]];
  3578. $where[] = ["a.status", '>=', 2];//搜索发货时间时,要指定状态为已发货及之后的状态值(0待发货,1待库管发货,2已发货待收货,3已收货,4已全部退货',)
  3579. }
  3580. $order_source = isset($this->post['order_source']) && $this->post['order_source'] !== "" ? intval($this->post['order_source']) : "";
  3581. if ($order_source !== "") $where[] = ["b.order_source", '=', $order_source];
  3582. $use_type = $this->post['use_type']??'';
  3583. if($use_type!=='') $where[]=['p.use_type','=',$use_type];
  3584. $count = Db::name('order_out')
  3585. ->alias('a')
  3586. ->join("sale b", "b.orderCode=a.orderCode", "left")
  3587. // ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  3588. ->join("warehouse_info n", "n.wsm_code=a.wsm_code", "left")
  3589. ->leftJoin("order_send os", "os.outCode=a.outCode")
  3590. ->leftJoin("platform p", "p.id=b.platform_id")
  3591. // ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
  3592. // ->leftJoin('supplier sip', 'sip.code=wpo.supplierNo')
  3593. ->where($where)
  3594. ->where($condition)
  3595. ->count('a.id');
  3596. $total = ceil($count / $size);
  3597. $page = $page >= $total ? $total : $page;
  3598. $list = Db::name('order_out')
  3599. ->alias('a')
  3600. ->join("sale b", "b.orderCode=a.orderCode", "left")
  3601. // ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  3602. ->join("warehouse_info n", "n.wsm_code=a.wsm_code AND n.is_del=0", "left")
  3603. ->leftJoin("order_send os", "os.outCode=a.outCode")
  3604. ->leftJoin("platform p", "p.id=b.platform_id")
  3605. // ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
  3606. // ->leftJoin('supplier sip', 'sip.code=wpo.supplierNo')
  3607. ->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")
  3608. ->where($where)
  3609. ->where($condition)
  3610. ->order("addtime desc")
  3611. ->page($page, $size)
  3612. ->select()
  3613. ->toArray();
  3614. $all_createrid = array_column($list, 'apply_id');
  3615. $item = get_company_name_by_uid($all_createrid);
  3616. $user = \app\admin\common\User::getIns();
  3617. $names = $user->handle("getCodeAndName", ["code" => array_merge( array_column($list, "supplierNo"), array_column($list, "wsm_supplierNo"))]);
  3618. // $userCommon = \app\admin\common\User::getIns();
  3619. // $names = $userCommon->handle('getCodeAndName',['code'=>array_column($list,'customer_code')]);
  3620. $has_account = checkHasAccountBySupplierNos(array_unique(array_column($list,'wsm_supplierNo')));
  3621. $data = [];
  3622. foreach ($list as $value) {
  3623. // $value['companyName'] = $names['data'][$value['customer_code']] ?? '';
  3624. if ($value['order_type'] == 1 && $value['wsm_code'] == '') {
  3625. // $wsmcode = Db::name("good")->alias("a")
  3626. // ->leftJoin("supplier b","a.supplierNo=b.code")
  3627. // ->where(["a.spuCode"=>$value['good_code']])->field("'' wsm_name,b.name,b.code")->find();
  3628. $value['wsm_supplierNo'] = $value['supplierNo'];
  3629. $value['wsm_supplier'] = $names['data'][$value['supplierNo']] ?? "";
  3630. } else {
  3631. // $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  3632. // ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  3633. $value['wsm_supplier'] = $names['data'][$value['wsm_supplierNo']] ?? "";
  3634. }
  3635. $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
  3636. if ($addr) {
  3637. $addinfo = $addr['addr_code'] != '' ? json_decode($addr['addr_code'], true) ?? $addr['addr_code'] : '';
  3638. if (is_string($addinfo) && $addinfo != '') {
  3639. $addinfo = ["provice_code" => '', "city_code" => '', "area_code" => ''];
  3640. list($addinfo['provice_code'], $addinfo['city_code'], $addinfo['area_code']) = explode(",", $addr['addr_code']);
  3641. }
  3642. $addr['addr_cn'] = GetAddr(json_encode($addinfo));
  3643. }
  3644. if (in_array($value['order_type'], [3, 4])) {
  3645. $goon = Db::name("good_zixun")->field('id,cat_id')->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
  3646. } else {
  3647. $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();
  3648. }
  3649. $value['wsm_has_account'] = (int)isset($has_account[$value['wsm_supplierNo']]);
  3650. $value['addr'] = isset($addr['addr']) ? $addr['addr_cn'] . $addr['addr'] : "";
  3651. $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  3652. $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  3653. $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  3654. $value['company_name'] = $item[$value['apply_id']] ?? '';
  3655. $value['sendtime'] = $value['status'] < 2 ? '' : $value['sendtime'];
  3656. //是否具有编辑权限
  3657. // $value['is_allow_update'] = 0;
  3658. // if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  3659. $data[] = $value;
  3660. }
  3661. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  3662. }
  3663. public function outinfo()
  3664. {
  3665. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  3666. if ($outCode == "") {
  3667. return error_show(1002, "参数outcode不能为空");
  3668. }
  3669. $codeinfo = Db::name("order_out")->where(['outCode' => $outCode, "is_del" => 0])->find();
  3670. if (empty($codeinfo)) {
  3671. return error_show(1002, "未找到出库数据");
  3672. }
  3673. $item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  3674. if ($item['order_type'] == 3 ||$item['order_type'] == 4 ) {
  3675. $goodinfo = Db::name("good_zixun")->where(["spuCode" => $item['good_code'], "is_del" => 0])->find();
  3676. if ($goodinfo == false) {
  3677. return error_show(1004, "未找到商品数据");
  3678. }
  3679. } else {
  3680. $goodinfo = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  3681. ->where(['a.skuCode' => $item['skuCode']])->find();
  3682. if ($goodinfo == false) {
  3683. return error_show(1002, "未找到商品数据");
  3684. }
  3685. }
  3686. $int = isset($goodinfo['cat_id']) && $goodinfo['cat_id'] != 0 ? made($goodinfo['cat_id']) : [];
  3687. $addr = Db::name("order_addr")->where(["id" => $codeinfo['addrid']])->find();
  3688. if($addr){
  3689. $addinfo =$addr['addr_code']!=''?json_decode($addr['addr_code'],true)??$addr['addr_code']: '' ;
  3690. if(is_string($addinfo)&&$addinfo!=''){
  3691. $addinfo=["provice_code"=>'',"city_code"=>'',"area_code"=>''];
  3692. list($addinfo['provice_code'],$addinfo['city_code'],$addinfo['area_code']) = explode(",",$addr['addr_code']);
  3693. }
  3694. $addr['addr_cn'] =GetAddr(json_encode($addinfo));
  3695. }
  3696. $codeinfo['good_name'] = isset($item['good_name']) ? $item['good_name'] : "";
  3697. $codeinfo['good_num'] = isset($item['good_num']) ? $item['good_num'] : "";
  3698. $codeinfo['good_code'] = isset($item['good_code']) ? $item['good_code'] : "";
  3699. $codeinfo['origin_price'] = isset($item['origin_price']) ? $item['origin_price'] : "";
  3700. $codeinfo['sale_price'] = isset($item['sale_price']) ? $item['sale_price'] : "";
  3701. $codeinfo['total_price'] = isset($item['total_price']) ? $item['total_price'] : "";
  3702. $codeinfo['skuCode'] = isset($item['skuCode']) ? $item['skuCode'] : "";
  3703. $codeinfo['addr'] = $addr['addr_cn']??'';
  3704. $codeinfo['addr'] .= isset($addr['addr']) ? $addr['addr'] : "";
  3705. $codeinfo['addr_code'] = isset($addr['addr_code']) ? $addr['addr_code'] : "";
  3706. $codeinfo['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  3707. $codeinfo['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  3708. $codeinfo['sendtime'] = $codeinfo['status'] < 2 ? '' : $codeinfo['sendtime'];
  3709. $codeinfo['can'] = $int;
  3710. $codeinfo['order_source'] = $item['order_source'];
  3711. $orderReturn = Db::name("order_return")->where(["outCode" => $outCode, "is_del" => 0])->order("id desc")->find();
  3712. $codeinfo['order_return'] = $orderReturn;
  3713. $codeinfo['platform_order'] = $item['platform_order'];
  3714. //获取销售订单对应的供应商是否有启用账号
  3715. $codeinfo['has_account'] = 0;
  3716. $supplierNo = Db::name('order_num')
  3717. ->alias('a')
  3718. ->leftJoin('purchease_order b', 'b.cgdNo=a.cgdNo')
  3719. ->where('a.orderCode', $codeinfo['orderCode'])
  3720. ->value('b.supplierNo');
  3721. if ($supplierNo) {
  3722. $has_account = checkHasAccountBySupplierNos([$supplierNo]);
  3723. $codeinfo['has_account'] = (int)isset($has_account[$supplierNo]);
  3724. }
  3725. $saleinfo=Db::name("sale_info")->where([["orderCode","=",$codeinfo['orderCode']],["num",">",0]])->select()
  3726. ->toArray();
  3727. if(!empty($saleinfo)){
  3728. $stockidArr=array_column($saleinfo,"stockid");
  3729. $wsm=Db::name("good_stock")->alias("a")
  3730. ->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")
  3731. ->where("a.id","in",$stockidArr)
  3732. ->column("a.wsm_code,name","a.id");
  3733. foreach ($saleinfo as &$item){
  3734. $item['wsm_code'] = $wsm[$item['stockid']]['wsm_code'];
  3735. $item['wsm_name'] = $wsm[$item['stockid']]['name'];
  3736. }
  3737. }
  3738. $codeinfo["saleinfo"] = $saleinfo;
  3739. return app_show(0, "获取成功", $codeinfo);
  3740. }
  3741. public function outadd()
  3742. {
  3743. // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  3744. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  3745. if ($orderCode == "") {
  3746. return error_show(1002, "参数orderCoder不能为空");
  3747. }
  3748. $retrun =Db::name("sale_return")->where([["orderCode","=",$orderCode],["is_del","=",0],["status","in",[1,2,3,
  3749. 7,9,10,8,11,12]]])->count();
  3750. if($retrun>0){
  3751. return error_show(1005,"存在未完成退货订单数据");
  3752. }
  3753. $der = Db::name('sale')->where(['orderCode' => $orderCode, "is_del" => 0])->find();
  3754. if ($der == "") {
  3755. return error_show(1002, "未找到出库订单单号");
  3756. }
  3757. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  3758. if ($send_num == "") {
  3759. return error_show(1002, "发货数量不能为空");
  3760. }
  3761. $wsed = Db::name("order_out")->where(["orderCode" => $orderCode])->where([["status", "<", 2], ["is_del", "=", 0]])->sum
  3762. ('send_num');
  3763. if ($send_num > $der['wsend_num'] - $wsed) {
  3764. return error_show(1002, "超出可发货数量");
  3765. }
  3766. $contactor = isset($this->post['contactor']) && $this->post['contactor'] != "" ? trim($this->post['contactor']) : "";
  3767. if ($contactor == "") {
  3768. return error_show(1002, "参数contactor不能为空");
  3769. }
  3770. $mobile = isset($this->post['mobile']) && $this->post['mobile'] != "" ? trim($this->post['mobile']) : "";
  3771. if ($mobile == "") {
  3772. return error_show(1002, "参数mobile不能为空");
  3773. }
  3774. $addr = isset($this->post['addr']) && $this->post['addr'] != "" ? trim($this->post['addr']) : "";
  3775. if ($addr == "") {
  3776. return error_show(1002, "参数addr不能为空");
  3777. }
  3778. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code'] != "" ? trim($this->post['addr_code']) : "";
  3779. // if ($addr_code == "") {
  3780. // return error_show(1002, "参数addr_code不能为空");
  3781. // }
  3782. // $apply_id = GetUserInfo($token);
  3783. // if (empty($apply_id) || $apply_id['code'] != 0) {
  3784. // return error_show(1002, "申请人数据不存在");
  3785. // }
  3786. $rm = $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  3787. $ri = $this->uname;//isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  3788. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  3789. Db::startTrans();
  3790. try {
  3791. $addrlst = [
  3792. "orderCode" => $orderCode,
  3793. "addr" => $addr,
  3794. "addr_code" => $addr_code!=''?json_encode($addr_code):'',
  3795. "contactor" => $contactor,
  3796. "mobile" => $mobile,
  3797. "customer_code" => $der['customer_code'],
  3798. "post_fee" => $der['post_fee'],
  3799. "arrive_time" => $sendtime,
  3800. "receipt_quantity" => $send_num,
  3801. "is_del" => 0,
  3802. "addtime" => date("Y-m-d H:i:s"),
  3803. "updatetime" => date("Y-m-d H:i:s")
  3804. ];
  3805. $addrid = Db::name("order_addr")->insert($addrlst, true);
  3806. if ($addrid > 0) {
  3807. $outCode = makeNo("DF");
  3808. $order=[];
  3809. if($der['order_type']!=1){
  3810. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  3811. ->lock(true)->find();
  3812. if ($order == false) {
  3813. Db::rollback();
  3814. return error_show(1004, "未找到可以发货得采购单数据");
  3815. }
  3816. $cgd = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
  3817. if ($cgd == false) {
  3818. Db::rollback();
  3819. return error_show(1002, "未找到对应的采购单数据");
  3820. }
  3821. $order['wsend_num'] -= $send_num;
  3822. $order['send_num'] += $send_num;
  3823. $or = Db::name("order_num")->save($order);
  3824. if ($or == false) {
  3825. Db::rollback();
  3826. return error_show(1002, "发货地址添加创建失败");
  3827. }
  3828. $tep = [
  3829. "cgdNo" => $order['cgdNo'],
  3830. "outCode" => $outCode,
  3831. "send_num" => $send_num,
  3832. "status" => 1,
  3833. "addtime" => date("Y-m-d H:i:s"),
  3834. "updatetime" => date("Y-m-d H:i:s")
  3835. ];
  3836. $sen = Db::name("order_send")->save($tep);
  3837. if ($sen == false) {
  3838. Db::rollback();
  3839. return error_show(1002, "发货地址添加创建失败");
  3840. }
  3841. }else{
  3842. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  3843. ->lock(true)->find();
  3844. if ($order!= false) {
  3845. $cgd = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
  3846. if ($cgd == false) {
  3847. Db::rollback();
  3848. return error_show(1002, "未找到对应的采购单数据");
  3849. }
  3850. $order['wsend_num'] -= $send_num;
  3851. $order['send_num'] += $send_num;
  3852. $or = Db::name("order_num")->save($order);
  3853. if ($or == false) {
  3854. Db::rollback();
  3855. return error_show(1002, "发货地址添加创建失败");
  3856. }
  3857. $tep = [
  3858. "cgdNo" => $order['cgdNo'],
  3859. "outCode" => $outCode,
  3860. "send_num" => $send_num,
  3861. "status" => 1,
  3862. "addtime" => date("Y-m-d H:i:s"),
  3863. "updatetime" => date("Y-m-d H:i:s")
  3864. ];
  3865. $sen = Db::name("order_send")->save($tep);
  3866. if ($sen == false) {
  3867. Db::rollback();
  3868. return error_show(1002, "发货地址添加创建失败");
  3869. }
  3870. }else{
  3871. $order['cgdNo']='';
  3872. $cgd=[];
  3873. }
  3874. }
  3875. $data = [
  3876. "wsm_code" => isset($cgd['wsm_code']) ? $cgd['wsm_code'] : "",
  3877. "orderCode" => $orderCode,
  3878. "outCode" => $outCode,
  3879. "order_type" => $der['order_type'],
  3880. "apply_id" => $rm,
  3881. "apply_name" => $ri,
  3882. "addrid" => $addrid,
  3883. "post_name" => "",
  3884. "post_code" => "",
  3885. "post_fee" => "",
  3886. "sendtime" => $sendtime,
  3887. "send_num" => $send_num,
  3888. "check_num" => 0,
  3889. "error_num" => 0,
  3890. "send_status" => 1,
  3891. "status" => 1,
  3892. "addtime" => date("Y-m-d H:i:s"),
  3893. "updatetime" => date("Y-m-d H:i:s")
  3894. ];
  3895. if ($der['is_stock'] == 0) {
  3896. //维护商品所在仓库的库存 --- start
  3897. $temp = Db::name('good_stock')
  3898. ->field('id,usable_stock,wait_out_stock')
  3899. ->where(['spuCode' => $der['good_code'], 'wsm_code' => $cgd['wsm_code']])
  3900. ->find();
  3901. if (($temp == false || ($temp['usable_stock'] - $send_num) < 0) && $der['send_type'] == 1) {
  3902. Db::rollback();
  3903. return error_show(1004, '库存不足');
  3904. } else {
  3905. if (($temp == false || ($temp['usable_stock'] - $send_num) < 0) && $der['send_type'] == 2) {
  3906. $data['status'] = 0;
  3907. } else {
  3908. //这个地方不需要更新,因为后面尝试拆单的时候会维护库存数
  3909. // $up = Db::name('good_stock')
  3910. // ->where('id', $temp['id'])
  3911. // ->update([
  3912. // 'usable_stock' => $temp['usable_stock'] - $send_num,
  3913. // 'wait_out_stock' => $temp['wait_out_stock'] + $send_num,
  3914. // 'updatetime' => date('Y-m-d H:i:s'),
  3915. // ]);
  3916. // if ($up == false) {
  3917. // Db::rollback();
  3918. // return error_show(1004, '库存更新失败');
  3919. // }
  3920. // ::todo
  3921. // $good_data[] = ['good_log_code' => $outCode, "stock_id" => $temp['id'], "type" => 1, 'stock' => $send_num, "stock_name" => "wait_out_stock"];
  3922. // $good_data[] = ['good_log_code' => $outCode, "stock_id" => $temp['id'], "type" => 2, 'stock' => $send_num, "stock_name" => "usable_stock"];
  3923. // GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname], $good_data, "CKD");
  3924. }
  3925. }
  3926. }
  3927. $datainfo = Db::name('order_out')->insert($data, true);
  3928. if ($datainfo > 0) {
  3929. //修改状态,添加待办
  3930. ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
  3931. "order_code" => $data['outCode'],//出库单号
  3932. "status" => $data['status'],//这里的status是之前的值
  3933. "action_remark" => '',//备注
  3934. "action_type" => "create"//新建create,编辑edit,更改状态status
  3935. ], "CKD", $data['status'], $data);
  3936. //是否库存品,待办数据推送到的人有区别,
  3937. $process = [];
  3938. if ($data['status'] == 1) {
  3939. if ($data['send_status'] == 1) OrderOutChild::makeChild($outCode);//尝试拆单
  3940. if ($der['is_stock'] == 1) {
  3941. //库存品,推给库管和库管-张凯旋
  3942. $roleid = config('app.wsm_cgder_role');
  3943. $uids = Db::name('user_role')
  3944. ->where('is_del', 0)
  3945. ->whereIn('roleid', $roleid)
  3946. ->column('uid');
  3947. $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)];
  3948. } else{
  3949. //推给供应商负责人
  3950. // $supplier = Db::name('supplier')
  3951. // ->field('person,personid')
  3952. // ->where('code', $cgd['supplierNo'])
  3953. // ->findOrEmpty();
  3954. $userCommon= \app\admin\common\User::getIns();
  3955. $supplier_temp =$userCommon->handle("sInfo",["code"=>$cgd['supplierNo']]);
  3956. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"采购单供应商不存在");
  3957. $holder_id=$supplier_temp['data']['personid']??0;
  3958. $holder_name=$supplier_temp['data']['personid']??0;
  3959. $process = ["order_type" => 'CKD', "order_code" => $data['outCode'], "order_id" =>
  3960. $datainfo, "order_status" => $data['status'], "before_status" => 0, 'holder_id' => $data['apply_id'], 'wait_id' => $holder_id, 'wait_name' => $holder_name,];
  3961. }
  3962. }
  3963. 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']];
  3964. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], $process);
  3965. //维护台账记录
  3966. Db::name('standing_book')
  3967. ->where('orderCode', $orderCode)
  3968. ->update([
  3969. 'order_type' => $der['order_type'],
  3970. 'order_source' => $der['order_source'],
  3971. 'cgdNo' => $order['cgdNo'],
  3972. 'customer_code' => $der['customer_code'],
  3973. 'updatetime' => date('Y-m-d H:i:s'),
  3974. ]);
  3975. Db::execute("UPDATE `wsm_standing_book` SET `outCode`=CONCAT(IFNULL(`outCode`,''),',{$outCode}') WHERE `cgdNo`='{$order['cgdNo']}'");
  3976. Db::commit();
  3977. return app_show(0, "出库单新建成功");
  3978. }
  3979. }
  3980. Db::rollback();
  3981. return error_show(1004, "出库单新建失败");
  3982. } catch (Exception $e) {
  3983. Db::rollback();
  3984. return error_show(1005, $e->getMessage());
  3985. }
  3986. }
  3987. //库管发货
  3988. public function outSend()
  3989. {
  3990. $outCode = isset($this->post['outCode']) && $this->post['outCode'] != "" ? trim($this->post['outCode']) : "";
  3991. if ($outCode == "") {
  3992. return error_show(1004, "参数outCode不能为空");
  3993. }
  3994. $outinfo = Db::name("order_out")->where(["outCode" => $outCode, "is_del" => 0])->find();
  3995. if ($outinfo == false) {
  3996. return error_show(1004, "发货数据未找到");
  3997. }
  3998. if($outinfo['status']!=1){
  3999. return error_show(1004, "发货状态有误");
  4000. }
  4001. $einfo = Db::name('sale')->where(['orderCode' => $outinfo['orderCode'], 'is_del' => 0])->find();
  4002. if (empty($einfo)) {
  4003. return error_show(1002, "未找到销售订单数据");
  4004. }
  4005. //判断供应商是否开通账号,若开通的话,则只能由供应商账号操作
  4006. if ($this->level != 3) {
  4007. $temp = checkHasAccountBySupplierNos([$einfo['supNo']]);
  4008. if (isset($temp[$einfo['supNo']])) return json_show(1004, '非供应商账号不能操作');
  4009. }
  4010. $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();
  4011. if ($is_reurn != false) {
  4012. return error_show(1002, "销售单存在退货未处理完成");
  4013. }
  4014. $post_name = isset($this->post['post_name']) && $this->post['post_name'] != "" ? trim($this->post['post_name']) : "";
  4015. if ($post_name == "") {
  4016. return error_show(1004, "参数post_name不能为空");
  4017. }
  4018. $post_code = isset($this->post['post_code']) && $this->post['post_code'] != "" ? trim($this->post['post_code']) : "";
  4019. if ($post_code == "") {
  4020. return error_show(1004, "参数post_code不能为空");
  4021. }
  4022. $remark = isset($this->post['remark']) && $this->post['remark'] != "" ? trim($this->post['remark']) : "";
  4023. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] != "" ? floatval($this->post['post_fee']) : "";
  4024. $outinfo['post_name'] = $post_name;
  4025. $outinfo['post_code'] = $post_code;
  4026. $outinfo['post_fee'] = $post_fee;
  4027. $outinfo['sendtime'] = date("Y-m-d H:i:s");
  4028. $old_outinfo_status = $outinfo['status'];
  4029. $outinfo['status'] = 2;
  4030. $outinfo['updatetime'] = date("Y-m-d H:i:s");
  4031. $outinfo['remark'] = $remark;
  4032. if ($einfo['wsend_num'] < $outinfo['send_num']) {
  4033. return error_show(1004, "订单未发货数量不足");
  4034. }
  4035. Db::startTrans();
  4036. try {
  4037. $up = Db::name("order_out")->where(["outCode"=>$outCode,"status"=>1,"is_del"=>0])->update($outinfo);
  4038. // $user_info = GetUserInfo($this->post['token']);
  4039. $uid = $this->uid;//isset($user_info['data']['id']) ? $user_info['data']['id'] : 0;
  4040. $uname = $this->uname;//isset($user_info['data']['nickname']) ? $user_info['data']['nickname'] : '';
  4041. if ($einfo['is_stock'] == 1) {
  4042. //由于存在一个单子对应多个仓库的情况,因此库存品的判断暂时无法进行,待分仓功能完成后再考虑
  4043. //如果是库存品,只能由库管操作
  4044. // $contactor = Db::name('warehouse_info')
  4045. // ->where(['wsm_code' => $outinfo['wsm_code'], 'is_del' => 0])
  4046. // ->value('contactor');
  4047. // $own_roleid = Db::name('user_role')->where(['is_del'=>0,'uid'=>$uid,'status'=>1])->value('roleid',0);
  4048. // if ($uid != $contactor) throw new \think\Exception('库存品只能由库管人员操作');
  4049. } elseif ($einfo['is_stock'] == 0) {
  4050. //非库存品和采返商品只能由供应商负责人操作
  4051. if ($einfo['order_type'] == 3 || $einfo['order_type'] ==4 ) {
  4052. $supplierNo = Db::name('good_zixun')
  4053. // ->leftJoin("supplier b", "a.supplierNo=b.code")
  4054. ->where(['spuCode' => $einfo['good_code'], 'is_del' => 0])
  4055. ->value('supplierNo');
  4056. } else {
  4057. $supplierNo = Db::name('good')
  4058. // ->alias("a")
  4059. // ->leftJoin("supplier b", "a.supplierNo=b.code")
  4060. ->where(['spuCode' => $einfo['good_code'], 'is_del' => 0])
  4061. ->value('supplierNo');
  4062. }
  4063. // $userCommon = \app\admin\common\User::getIns();
  4064. // $temp = $userCommon->handle('sInfo', ['code' => $supplierNo]);
  4065. $temp = get_personid_by_supplierNo([$supplierNo]);
  4066. if (($this->level == 2) && ($uid != $temp[$supplierNo])) throw new \think\Exception('非库存品和采返商品只能由供应商负责人操作');
  4067. }
  4068. if ($up) {
  4069. //修改状态,添加待办
  4070. ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], [
  4071. "order_code" => $outinfo['outCode'],//出库单号
  4072. "status" => $old_outinfo_status,//这里的status是之前的值
  4073. "action_remark" => '',//备注
  4074. "action_type" => "edit"//新建create,编辑edit,更改状态status
  4075. ], "CKD", $outinfo['status'], $outinfo);
  4076. ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], [
  4077. "order_type" => 'CKD',
  4078. "order_code" => $outinfo['outCode'],//出库单号
  4079. "order_id" => $outinfo['id'],
  4080. "order_status" => $outinfo['status'],
  4081. "before_status" => $old_outinfo_status,
  4082. 'wait_id'=>$outinfo['apply_id'],
  4083. 'wait_name'=>$outinfo['apply_name'],
  4084. 'holder_id'=>$outinfo['apply_id'],
  4085. ]);
  4086. if($einfo['wsend_num']<$outinfo['send_num']){
  4087. Db::rollback();
  4088. return error_show(1002, "订单待付货数量不足");
  4089. }
  4090. $orderstatus = $einfo['status'];
  4091. $einfo['send_num'] += $outinfo['send_num'];
  4092. $einfo['wsend_num'] -= $outinfo['send_num'];
  4093. $einfo['status'] = $einfo['wsend_num'] == 0 ? 2 : ($einfo['send_num'] == 0 ? 0 : 1);
  4094. $einfo['send_status'] = $einfo['wsend_num'] == 0 ? 3 : ($einfo['send_num'] == 0 ? 1 : 2);
  4095. $einfo['updatetime'] = date("Y-m-d H:i:s");
  4096. $saleup = Db::name("sale")->save($einfo);
  4097. if ($saleup == false) {
  4098. Db::rollback();
  4099. return error_show(1002, "销售单状态更新失败");
  4100. }
  4101. // }
  4102. //修改状态,添加待办
  4103. ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], [
  4104. "order_code" => $einfo['orderCode'],//出库单号
  4105. "status" => $orderstatus,//这里的status是之前的值
  4106. "action_remark" => '',//备注
  4107. "action_type" => "edit"//新建create,编辑edit,更改状态status
  4108. ], "XSQRD", $einfo['status'], $einfo);
  4109. ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], [
  4110. "order_type" => 'XSQRD',
  4111. "order_code" => $einfo['orderCode'],//出库单号
  4112. "order_id" => $einfo['id'],
  4113. "order_status" => $einfo['status'],
  4114. "before_status" => $orderstatus,
  4115. 'holder_id' => $einfo['apply_id']
  4116. ]);
  4117. if($einfo["order_type"]!=1 ){
  4118. $stokc = Db::name("good_stock")->where(['spuCode' => $einfo['good_code'], "wsm_code" => $outinfo['wsm_code'], "is_del" => 0])->find();
  4119. if ($stokc == false) {
  4120. Db::rollback();
  4121. return error_show(1002, "未找到库存数据");
  4122. } else {
  4123. if ($outinfo['send_num'] > $stokc['wait_out_stock']) {
  4124. Db::rollback();
  4125. return error_show(1002, "超出库存数量");
  4126. }
  4127. $stokc['wait_out_stock'] -= $outinfo['send_num'];
  4128. $stokc['total_stock'] = $stokc['wait_out_stock'] + $stokc['usable_stock'];
  4129. // $stokc['intra_stock']+=$outinfo['send_num'];
  4130. $stokc['updatetime'] = date("Y-m-d H:i:s");
  4131. }
  4132. $stoc = Db::name("good_stock")->save($stokc);
  4133. if ($stoc == false) {
  4134. Db::rollback();
  4135. return error_show(1002, "库存更新失败");
  4136. }
  4137. // $outsend =Db::name("order_send")->where(["outCode"=> $outCode])->findOrEmpty();
  4138. // if(empty($outsend)){
  4139. // Db::rollback();
  4140. // return error_show(1002, "未找到关联采购单");
  4141. // }
  4142. // $cgdinfo= Db::name("purchease_order")->where(["cgdNo"=>$outsend['cgdNo'],"is_del"=>0])
  4143. // ->findOrEmpty();
  4144. // $bn_code =makeNo("BN");
  4145. // $bnin=GoodStockInfo::AddBn($stokc["id"],$bn_code,$outinfo['send_num'],$cgdinfo['good_price']??0);
  4146. // if($bnin==false){
  4147. // Db::rollback();
  4148. // return error_show(1004,"库存bn数据新增失败");
  4149. // }
  4150. // $bnup =GoodStockInfo::OrderBn($outinfo['orderCode'],$stokc["id"],$outinfo['send_num'],0);
  4151. // if($bnup==false){
  4152. // Db::rollback();
  4153. // return error_show(1004,"库存bn库存数更新失败");
  4154. // }
  4155. // $outsend['bnCode']=$bn_code;
  4156. // $outsend['updatetime']=date("Y-m-d H:i:s");
  4157. // $ps=Db::name("order_send")->save($outsend);
  4158. // if($ps==false){
  4159. // Db::rollback();
  4160. // return error_show(1004,"库存bn库存数更新失败");
  4161. // }
  4162. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stokc['id'], "type" => 2, 'stock' => $outinfo['send_num'], "stock_name" => "wait_out_stock"];
  4163. GoodLog::LogAdd(['id' => $uid, 'nickname' => $uname], $good_data, "CKD");
  4164. }else{
  4165. // $saleinfo =Db::name("sale_info")->where(["orderCode"=>$outinfo['orderCode']])->select()->toArray();
  4166. // if (!empty($saleinfo)){
  4167. // $bnup =SaleInfo::SendStock($outinfo['orderCode'],$outinfo['send_num']);
  4168. // if($bnup==false){
  4169. // Db::rollback();
  4170. // return error_show(1004,"库存bn库存数更新失败");
  4171. // }
  4172. // }else{
  4173. $stokc = Db::name("good_stock")->where(['spuCode' => $einfo['good_code'], "wsm_code" => $outinfo['wsm_code'], "is_del" => 0])->find();
  4174. if ($stokc == false) {
  4175. Db::rollback();
  4176. return error_show(1002, "未找到库存数据");
  4177. } else {
  4178. if ($outinfo['send_num'] > $stokc['wait_out_stock']) {
  4179. Db::rollback();
  4180. return error_show(1002, "超出库存数量");
  4181. }
  4182. $stokc['wait_out_stock'] -= $outinfo['send_num'];
  4183. $stokc['total_stock'] = $stokc['wait_out_stock'] + $stokc['usable_stock'];
  4184. // $stokc['intra_stock']+=$outinfo['send_num'];
  4185. $stokc['updatetime'] = date("Y-m-d H:i:s");
  4186. }
  4187. $stoc = Db::name("good_stock")->save($stokc);
  4188. if ($stoc == false) {
  4189. Db::rollback();
  4190. return error_show(1002, "库存更新失败");
  4191. }
  4192. // }
  4193. }
  4194. // Cache::store("redis")->handler()->lPush("SENDOUT", $outCode);
  4195. Db::commit();
  4196. } else {
  4197. Db::rollback();
  4198. return error_show(1004, "发货失败");
  4199. }
  4200. //如果是有赞订单的话,将发货信息推到有赞
  4201. //有赞信息有可能推送失败(比如超过72小时,不允许多次修改等),所以不应该和这里的事务放到一起
  4202. if ($einfo['order_source'] == 5) {
  4203. $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]);
  4204. $res = json_decode($res, true);
  4205. if ($res['code'] != 0) return app_show(0, '发货成功,' . $res['message']);
  4206. }
  4207. return app_show(0, "发货成功");
  4208. } catch (\Exception $e) {
  4209. Db::rollback();
  4210. return error_show(1004, $e->getMessage());
  4211. }
  4212. }
  4213. public function RelaCgd($outinfo, array &$standing_book_da = [])
  4214. {
  4215. $cgd = Db::name("order_bk")->where([["spuCode", "=", $outinfo['spuCode']], ["is_del", "=", 0], ["balance_num", ">=", $outinfo['good_num']], ['companyNo', "=", $outinfo['companyNo']]])->lock(true)->find();
  4216. if ($cgd == false) {
  4217. return false;
  4218. }
  4219. $good = Db::name("good")->where(["spuCode" => $outinfo['spuCode'], "is_del" => 0])->find();
  4220. if ($good == false) {
  4221. return false;
  4222. }
  4223. $cgdinfo = Db::name("purchease_order")->where(['cgdNo' => $cgd['cgdNo'], "is_del" => 0])->find();
  4224. if ($cgdinfo == false) {
  4225. return false;
  4226. }
  4227. $QrdCgd = [
  4228. "cgdNo" => makeNo("CG"),
  4229. "bkcode" => $cgdinfo['bkcode'],
  4230. 'wsm_code' => $cgdinfo['wsm_code'],
  4231. "cgder_id" => $cgdinfo['cgder_id'],
  4232. "cgder" => $cgdinfo['cgder'],
  4233. "spuCode" => $cgdinfo['spuCode'],
  4234. "good_name" => $cgdinfo['good_name'],
  4235. "good_num" => $outinfo['good_num'],
  4236. "good_price" => $cgdinfo['good_price'],
  4237. "total_fee" => round($cgdinfo['good_price'] * $outinfo['good_num'], 2),
  4238. "pakge_fee" => $cgdinfo['pakge_fee'],
  4239. "cert_fee" => $cgdinfo['cert_fee'],
  4240. "open_fee" => $cgdinfo['open_fee'],
  4241. "delivery_fee" => $cgdinfo['delivery_fee'],
  4242. "mark_fee" => $cgdinfo['mark_fee'],
  4243. "teach_fee" => $cgdinfo['teach_fee'],
  4244. "nake_fee" => $cgdinfo['nake_fee'],
  4245. "demo_fee" => $cgdinfo['demo_fee'],
  4246. "weight" => $cgdinfo['weight'],
  4247. "diff_weight" => $cgdinfo['diff_weight'],
  4248. "diff_fee" => $cgdinfo['diff_fee'],
  4249. "gold_price" => $cgdinfo['gold_price'],
  4250. "supplierNo" => $cgdinfo['supplierNo'],
  4251. "supplier_name" => $cgdinfo['supplier_name'],
  4252. "companyNo" => $cgdinfo['companyNo'],
  4253. "send_status" => 3,
  4254. "send_num" => $outinfo['good_num'],
  4255. "wsend_num" => 0,
  4256. "remark" => $cgdinfo['remark'],
  4257. "status" => 3,
  4258. "lasttime" => $cgdinfo['lasttime'],
  4259. "is_del" => 0,
  4260. "order_type" => $outinfo['order_type'],
  4261. "order_source" => $outinfo['order_source'],
  4262. "good_type" => $cgdinfo['good_type'],
  4263. "addtime" => date("Y-m-d H:i:s"),
  4264. "updatetime" => date("Y-m-d H:i:s"),
  4265. 'good_createrid' => $good['createrid'],
  4266. 'good_creater' => $good['creater'],//商品创建人
  4267. ];
  4268. $insetrCgd = Db::name("purchease_order")->insert($QrdCgd);
  4269. if ($insetrCgd == false) {
  4270. return false;
  4271. } else {
  4272. $standing_book_da = array_merge($standing_book_da, [
  4273. 'orderCode' => $outinfo['orderCode'],
  4274. 'cgdNo' => $cgdinfo['cgdNo'],
  4275. 'spuCode' => $outinfo['spuCode'],
  4276. 'order_type' => $QrdCgd['order_type'],
  4277. 'order_source' => $QrdCgd['order_source'],
  4278. 'supplierNo' => $cgdinfo['supplierNo'],
  4279. 'companyNo' => $cgdinfo['companyNo'],
  4280. 'bk_code' => $cgdinfo['bkcode'],
  4281. 'purchease_id' => Db::name('purchease')->where('bk_code', $cgdinfo['bkcode'])->value('id'),
  4282. ]);
  4283. }
  4284. if ($good['is_gold_price'] == 1 && $good['is_stock'] == 1) {
  4285. $gold = Db::name("gold_price1")
  4286. ->field('id,price')
  4287. ->where(["type" => $good['noble_metal'], "is_del" => 0, "status" => 1])
  4288. ->order("addtime desc")
  4289. ->find();
  4290. //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
  4291. $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'];
  4292. $ct['cgd_gold_price'] = $gold["price"];
  4293. $updat = [
  4294. "sale_price" => $sale_price,
  4295. "total_price" => round($sale_price * $outinfo['good_num'], 2),
  4296. "origin_price" => $cgdinfo['good_price'],
  4297. "gold_price" => $gold["price"],
  4298. ];
  4299. $upsale = Db::name("sale")->where(["orderCode" => $outinfo['orderCode']])->update($updat);
  4300. if ($upsale == false) {
  4301. return false;
  4302. }
  4303. }
  4304. $merge_num = Db::name("purchease_order")->where(["bkcode" => $cgdinfo['bkcode'], "order_type" => 1, "is_del" => 0])
  4305. ->where("order_source", "<>", 0)
  4306. ->field("sum(send_num)-sum(th_num) as num")->find();
  4307. $cgd['balance_num'] = $cgd['total_num'] - $merge_num['num'];
  4308. $cgd['merge_num'] = $merge_num['num'];
  4309. $cgd['updatetime'] = date("Y-m-d H:i:s");
  4310. $up = Db::name("order_bk")->save($cgd);
  4311. if ($up == false) {
  4312. return false;
  4313. }
  4314. $data = [
  4315. "orderCode" => $outinfo['orderCode'],
  4316. "cgdNo" => $QrdCgd['cgdNo'],
  4317. "spuCode" => $outinfo['spuCode'],
  4318. "companyNo" => $outinfo['companyNo'],
  4319. "good_num" => $outinfo['good_num'],
  4320. "wsend_num" => $outinfo['good_num'],
  4321. "send_num" => 0,
  4322. "wait_num" => $outinfo['good_num'],
  4323. "status" => 1,
  4324. "source" => 1,
  4325. ];
  4326. $order = Db::name("order_num")->save($data);
  4327. if ($order == false) {
  4328. return false;
  4329. }
  4330. return true;
  4331. }
  4332. public function addother()
  4333. {
  4334. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
  4335. if ($orderCode == "") {
  4336. return error_show(1004, "参数orderCode不能为空");
  4337. }
  4338. $order = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->find();
  4339. if ($order == false) {
  4340. return error_show(1004, "未找到订单数据");
  4341. }
  4342. $paytime = isset($this->post['paytime']) && $this->post['paytime'] != "" ? $this->post['paytime'] : "";
  4343. $workNo = isset($this->post['workNo']) && $this->post['workNo'] != "" ? trim($this->post['workNo']) : "";
  4344. $platform_order = isset($this->post['platform_order']) && $this->post['platform_order'] != "" ? trim($this->post['platform_order']) : "";
  4345. $paytime == "" ? "" : $order['paytime'] = $paytime;
  4346. $order['workNo'] = $workNo;
  4347. $order['platform_order'] = $platform_order;
  4348. $order['updatetime'] = date("Y-m-d H:i:s");
  4349. $sa = Db::name("sale")->save($order);
  4350. if ($sa) {
  4351. return app_show(0, "更新成功");
  4352. } else {
  4353. return error_show(1004, "更新失败");
  4354. }
  4355. }
  4356. public function getPrice()
  4357. {
  4358. $skuCode = isset($this->post['skuCode']) && $this->post['skuCode'] != "" ? trim($this->post['skuCode']) : "";
  4359. if ($skuCode === "") {
  4360. return error_show(1003, "参数skuCode不能为空");
  4361. }
  4362. $is_activity = isset($this->post['is_activity']) && $this->post['is_activity'] !== "" ? intval($this->post['is_activity'])
  4363. : "";
  4364. if ($is_activity === "") {
  4365. return error_show(1003, "参数is_activity不能为空");
  4366. }
  4367. $sale_num = isset($this->post['sale_num']) && $this->post['sale_num'] !== "" ? intval($this->post['sale_num']) : "";
  4368. if ($sale_num === "") {
  4369. return error_show(1003, "参数sale_num不能为空");
  4370. }
  4371. $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  4372. ->where(['a.skuCode' => $skuCode])->find();
  4373. if ($ct == false) {
  4374. return error_show(1002, "未找到商品数据");
  4375. }
  4376. $stock = 0;
  4377. if ($ct['is_stock'] == 1) {
  4378. // $good_stock = Db::name("good_stock")->alias("a")->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")->where
  4379. // (["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();
  4380. // $good_stock = Db::name("good_stock")->where(["spuCode" => $ct['spuCode'], "is_del" => 0])->find();
  4381. $stock = Db::name("good")->where(["spuCode"=>$ct['spuCode']])->value("usable_stock",0);
  4382. }
  4383. if ($is_activity == 1) {
  4384. $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b", "a.activity_code=b.activity_code")
  4385. ->where(["a.skuCode" => $skuCode, "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])->find();
  4386. if ($act == false) {
  4387. return error_show(1003, "未找到相关活动价");
  4388. }
  4389. if ($act['moq_num'] > $sale_num) {
  4390. return error_show(1003, "商品不满足活动价起订量{$act['moq_num']}");
  4391. }
  4392. if ($act['activity_stock'] < $sale_num) {
  4393. return error_show(1003, "商品活动库存剩余{$act['activity_stock']}");
  4394. }
  4395. return app_show(0, "获取成功", ['sale_price' => $act['activity_price'], "stock" => $act['activity_stock']]);
  4396. } else {
  4397. //good_nake 成本阶梯 good_ladder销售阶梯
  4398. $origin = Db::name("good_nake")->where([["spuCode", "=", $ct['spuCode']], ["is_del", "=", 0]])->order("min_num asc")->find();
  4399. if (!$origin) {
  4400. return error_show(1003, "没有找到成本数据");
  4401. }
  4402. $good = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->order("min_num asc")->find();
  4403. if (!$good) {
  4404. return error_show(1003, "未找到相关阶梯价格");
  4405. }
  4406. if (!isset($origin['min_num'])) $origin['min_num'] = 0;
  4407. //如果是库存品的话,只取销售的库存
  4408. if ($ct['is_stock'] == 1) $lastnum = $good['min_num'];
  4409. else $lastnum = max($origin['min_num'] ?? 0, $good['min_num']);
  4410. if ($sale_num < $lastnum) {
  4411. return error_show(1003, "商品不满足起订量{$lastnum}");
  4412. }
  4413. $good_temp = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->where('min_num', '<=', $sale_num)->order("min_num desc")->find();
  4414. if (!$good_temp) {
  4415. return error_show(1003, "未找到相关阶梯价格");
  4416. }
  4417. $cat_top_list = made($ct['cat_id']);
  4418. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  4419. if ($ct['is_gold_price'] == 1 && $cat_top_id == 6) {
  4420. $gold = Db::name("gold_price1")
  4421. ->field('id,price')
  4422. ->where(["type" => $ct['noble_metal'], "is_del" => 0, "status" => 1])
  4423. ->order("addtime desc")
  4424. ->find();
  4425. if($ct['is_fixed']==0) $origin['nake_fee']=0;
  4426. $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'];
  4427. return app_show(0, "获取成功", ['sale_price' => $saleprice, "stock" => $stock]);
  4428. }
  4429. return app_show(0, "获取成功", ['sale_price' => $good_temp['sale_price'], "stock" => $stock]);
  4430. }
  4431. }
  4432. public function saleuse()
  4433. {
  4434. $orderCode = isset($this->post['orderCode']) && !empty($this->post['orderCode']) ? $this->post['orderCode'] : "";
  4435. if ($orderCode == "") {
  4436. return error_show(1003, "参数orderCode不能为空");
  4437. }
  4438. $order = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->select()->toArray();
  4439. if (empty($order)) {
  4440. return error_show(1003, "订单数据未找到");
  4441. }
  4442. $useid = isset($this->post['useid']) && $this->post['useid'] != "" ? intval($this->post['useid']) : "";
  4443. if ($useid == "") {
  4444. return error_show(1003, "参数useid不能为空");
  4445. }
  4446. $use = Db::name("order_use")->where(["id" => $useid, "is_del" => 0])->find();
  4447. if ($use == false) {
  4448. return error_show(1003, "用途数据未找到");
  4449. }
  4450. $asve = ['use_order' => $useid, "updatetime" => date("Y-m-d H:i:s")];
  4451. $up = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->update($asve);
  4452. if ($up > 0) {
  4453. return app_show(0, "更新成功");
  4454. } else {
  4455. return error_show(1003, "更新失败");
  4456. }
  4457. }
  4458. public function goodzxinfo()
  4459. {
  4460. $orderCode = isset($this->post['spuCode']) && $this->post['spuCode'] != '' ? trim($this->post['spuCode']) : "";
  4461. if ($orderCode == "") {
  4462. return error_show(1003, "参数spuCode不能为空");
  4463. }
  4464. $order = Db::name("good_zixun")->where(["spuCode" => $orderCode, "is_del" => 0])->find();
  4465. if (empty($order)) {
  4466. return error_show(1003, "订单数据未找到");
  4467. }
  4468. $unit = Db::name("unit")->where(["id" => $order['good_unit']])->find();
  4469. if ($order['brand_id'] != 0) {
  4470. $brand = Db::name("brand")->where(["id" => $order['brand_id']])->find();
  4471. $order["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  4472. } else {
  4473. $order["brand_name"] = "";
  4474. $order["brand_id"] = "";
  4475. }
  4476. $order['specinfo'] = json_decode($order['specinfo'], true);
  4477. $order['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  4478. $order['cat_info'] = made($order['cat_id'], []);
  4479. $order['noble_name'] = isset($order['noble_metal']) && $order['noble_metal'] != 0 ? $this->noble[$order['noble_metal']] : "";
  4480. if ($order['is_gold_price'] == 1) {
  4481. $price = Db::name("gold_price1")->where(["type" => $order['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  4482. }
  4483. $depart = get_company_name_by_uid($order['order_createrid']);
  4484. $userCommon = \app\admin\common\User::getIns();
  4485. $supplier = $userCommon->handle('sInfo',['code'=>$order['supplierNo']]);
  4486. // $supplier = Db::name("supplier")->where(["code" => $order['supplierNo']])->find();
  4487. $order['supplier_name'] = isset($supplier['data']['name']) ? $supplier['data']['name'] : "";
  4488. $order['cgder'] = isset($supplier['data']['person']) ? $supplier['data']['person'] : "";
  4489. $order['cgderid'] = isset($supplier['data']['personid']) ? $supplier['data']['personid'] : "";
  4490. $order['order_creater_depart'] = $depart;
  4491. $is_online= Db::name('good_platform')->where(['spuCode'=>$order['spuCode']])->findOrEmpty();
  4492. $order['is_online'] = empty($is_online)?0:1;
  4493. $value['is_basic']= Db::name('good_basic')->where(['spuCode'=>$order['spuCode']])->value("status",null);
  4494. $palt = Db::name("platform")->where(["id" => $order['platform_id']])->find();
  4495. $order['platform_name'] = isset($palt['platform_name']) ? $palt['platform_name'] : "";
  4496. $names = $userCommon->handle('getCodeAndName',['code'=>$order['companyNo']]);
  4497. // $company = Db::name("business")->where(["companyNo" => $order['companyNo']])->find();
  4498. $order['company'] = $names['data'][$order['companyNo']]??'';//isset($company['company']) ? $company['company'] : "";
  4499. $order["gold_price"] = isset($price['price']) ? $price['price'] : 0;
  4500. $order["noble_weight"] = isset($order['weight']) ? $order['weight'] : 0;
  4501. return app_show(0, "获取成功", $order);
  4502. }
  4503. //获取采反商品详情,当数据不在good_zixun中,模仿goodzxinfo
  4504. public function getGoodZxInfoByNotZixun()
  4505. {
  4506. $param = $this->request->only(['spuCode'], 'post', 'trim');
  4507. $val = Validate::rule(['spuCode' => 'require']);
  4508. if (!$val->check($param)) return error_show(1004, $val->getError());
  4509. $order = Db::name('consult_bids')
  4510. ->field(true)
  4511. ->where(['spuCode' => $param['spuCode'], 'is_del' => 0])
  4512. ->find();
  4513. if (empty($order)) return error_show(1003, "数据未找到");
  4514. // $orderCode= isset($this->post['spuCode'])&&$this->post['spuCode']!=''?trim($this->post['spuCode']):"";
  4515. // if($orderCode==""){
  4516. // return error_show(1003,"参数spuCode不能为空");
  4517. // }
  4518. // $order= Db::name("good_zixun")->where(["spuCode"=>$orderCode,"is_del"=>0])->find();
  4519. // if(empty($order)){
  4520. // return error_show(1003,"订单数据未找到");
  4521. // }
  4522. $unit = Db::name("unit")->where(["id" => $order['unit_id']])->find();
  4523. if ($order['brand_id'] != 0) {
  4524. $brand = Db::name("brand")->where(["id" => $order['brand_id']])->find();
  4525. $order["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  4526. } else {
  4527. $order["brand_name"] = "";
  4528. $order["brand_id"] = "";
  4529. }
  4530. $order['specinfo'] = json_decode($order['specinfo'], true);
  4531. $order['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  4532. $order['cat_info'] = made($order['cat_id'], []);
  4533. $order['noble_name'] = isset($order['metal_id']) && $order['metal_id'] != 0 ? $this->noble[$order['metal_id']] : "";
  4534. if ($order['is_gold_price'] == 1) {
  4535. $price = Db::name("gold_price1")->where(["type" => $order['metal_id'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  4536. }
  4537. $userCommon = \app\admin\common\User::getIns();
  4538. $supplier_temp = $userCommon->handle('getCodeAndName', ['code' => $order['supplierNo']]);
  4539. $order['supplier_name'] = $supplier_temp['data'][$order['supplierNo']]??"";
  4540. $order["gold_price"] = isset($price['price']) ? $price['price'] : 0;
  4541. $order["noble_weight"] = isset($order['weight']) ? $order['weight'] : 0;
  4542. $taxInfo=TaxCategory::where(['id'=>$order['tax_id']])->findOrEmpty();
  4543. $order['tax_name'] = $taxInfo['cat_name']??'';
  4544. $order['tax_short_name'] =$taxInfo['short_name']??'';
  4545. $order['tax_code'] =$taxInfo['merge_code']??'';
  4546. $good_info = Db::name('good_basic')
  4547. ->field('id,createrid,creater')
  4548. ->where('is_del',0)
  4549. ->where('spuCode',$order['spuCode'])
  4550. ->findOrEmpty();
  4551. //补充商品创建人字段
  4552. // 2022-9-7号确认 creater创建人即采购单的采购员 咨询cgder 只是供应商负责人
  4553. $order['good_createrid']=$good_info['createrid']??$order['createrid'];
  4554. $order['good_creater']=$good_info['creater']??$order['creater'];
  4555. return app_show(0, "获取成功", $order);
  4556. }
  4557. //发货申请单导出
  4558. public function exportSaleOut()
  4559. {
  4560. $outCodes = $this->request->post('outCodes', [], 'trim');
  4561. if (empty($outCodes)) return error_show(1004, '要导出的发货申请单编号不能为空');
  4562. $i = 1;
  4563. $send_type = [1 => '直接发货', 2 => '延时发货'];
  4564. $status = [0 => '待发货', 1 => '待库管发货', 2 => '已发货待收货', 3 => '已收货', 4 => '已全部退货'];
  4565. $list = Db::name("order_out")
  4566. ->alias('a')
  4567. ->field('"" as 序号,a.addtime as 创建时间,po.cgdNo as 采购单编号,po.status as 采购单状态,po.cgder as 采购员,b.orderCode as 确认单号,b.addtime as 确认单时间,
  4568. b.good_code as 产品编号,b.skuCode as 商品上线编码,"" 平台商品编码,b.good_name as 产品名称,"" as 规格,"" as 单位,b.supName as 供应商名称,b.supNo as 供应商编号,
  4569. a.post_fee as 物流费,b.send_type as 发货方式,b.remark as 确认单备注,po.good_num as 采购数量,a.send_num 发货数量,
  4570. oa.contactor as 收货人,oa.mobile as 联系方式,oa.addr as 收货地址,oa.addr_code,oa.arrive_time as 到货时间,a.outCode as 发货申请单号,po.order_type,
  4571. b.platform_order 平台订单号,a.post_name 发货申请单物流公司,a.post_code 发货申请单物流单号,a.post_fee 发货申请单物流费用,a.remark 发货申请单备注,a.apply_name 申请人,b.cat_id 商品分类')
  4572. ->whereIn('a.outCode', $outCodes)
  4573. ->order("a.addtime desc")
  4574. ->withAttr('序号', function () use (&$i) {
  4575. return $i++;
  4576. })->withAttr('采购单状态', function ($val) use ($status) {
  4577. return isset($status[$val]) ? $status[$val] : '';
  4578. })->withAttr('发货方式', function ($val) use ($send_type) {
  4579. return isset($send_type[$val]) ? $send_type[$val] : '';
  4580. })->where("a.is_del", "=", 0)
  4581. ->leftJoin("sale b", "b.orderCode=a.orderCode")
  4582. ->leftJoin("order_addr oa", "oa.id=a.addrid AND oa.is_del=0")
  4583. ->leftJoin('order_send os', 'os.outCode=a.outCode ')
  4584. ->leftJoin("purchease_order po", "po.cgdNo=os.cgdNo AND po.is_del=0")
  4585. ->select()
  4586. ->toArray();
  4587. $userCommon = \app\admin\common\User::getIns();
  4588. $skuArr =array_unique(array_column($list,"商品上线编码"));
  4589. $platCode= (new GoodPlatform())->where(["skuCode"=>$skuArr])->column("plat_code","skuCode");
  4590. foreach ($list as &$value) {
  4591. $value['平台商品编码']= $platCode[$value['商品上线编码']]??"";
  4592. if ($value['order_type'] == 3 || $value['order_type'] == 4) {
  4593. $good = Db::name("good_zixun")
  4594. ->where(["spuCode" => $value['产品编号'], "is_del" => 0])
  4595. ->field('id,specinfo,good_unit,supplierNo')
  4596. ->find();
  4597. $specinfo = isset($good['specinfo']) ? json_decode($good['specinfo'], true) : [];
  4598. $speclist = [];
  4599. foreach ($specinfo as $val) {
  4600. $speclist[] = $val['spec_name'] . ':' . $val['spec_value_name'];
  4601. }
  4602. } else {
  4603. $good = Db::name('good_basic')
  4604. ->where(['spuCode' => $value['产品编号']])
  4605. ->field('good_unit,supplierNo')
  4606. ->find();
  4607. $spec = Db::name("good_spec")
  4608. ->field('id,spec_id,spec_value_id')
  4609. ->where(["spuCode" => $value['产品编号'], "is_del" => 0])
  4610. ->select()
  4611. ->toArray();
  4612. $speclist = [];
  4613. if (!empty($spec)) {
  4614. foreach ($spec as $val) {
  4615. $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', '');
  4616. }
  4617. }
  4618. }
  4619. $supplier_temp = $userCommon->handle('sInfo', ['code' =>$value['供应商编号']]);
  4620. $supplier=$supplier_temp['data']??[];
  4621. $value['供应商编号'] = $good['supplierNo']??"";
  4622. // $supplier= Db::name("supplier")->where(["code"=>$value['供应商编号']])->field("name,person")->find();
  4623. $value['供应商名称'] = $supplier['name']??"";
  4624. $value['采购员'] = $supplier['person']??"";
  4625. $good_unit = isset($good['good_unit']) ? $good['good_unit'] : 0;
  4626. $value['规格'] = empty($speclist) ? '' : implode(',', $speclist);;
  4627. $value['单位'] = $good_unit ? Db::name('unit')->where(['id' => $good_unit, 'is_del' => 0])->value('unit', '') : '';
  4628. $value['商品分类'] = implode('/', array_column(made($value['商品分类']), 'name'));
  4629. $value['发货申请单物流单号'] = ' ' . $value['发货申请单物流单号'];//添加空格防止将数字转为科学计数法(比如,韵达的快递单号就是纯数字)
  4630. $addinfo =$value['addr_code']!=''?json_decode($value['addr_code'],true)??$value['addr_code']: '' ;
  4631. if(is_string($addinfo)&&$addinfo!=''){
  4632. $addinfo=["provice_code"=>'',"city_code"=>'',"area_code"=>''];
  4633. list($addinfo['provice_code'],$addinfo['city_code'],$addinfo['area_code']) = explode(",",$value['addr_code']);
  4634. }
  4635. $addr_cn =GetAddr(json_encode($addinfo));
  4636. $value['收货地址'] = $addr_cn.$value['收货地址'];
  4637. unset($value['order_type']);
  4638. unset($value['addr_code']);
  4639. }
  4640. if (empty($list)) $list[] = '没有可供导出的数据';
  4641. $headerArr = array_keys($list[0]);
  4642. excelSave('发货申请单导出' . date('YmdHis'), $headerArr, $list);
  4643. }
  4644. //发货申请单 签收(目前只改动状态,后面要实时查询物流信息,以判断是否签收)
  4645. public function saleoutReceipt()
  4646. {
  4647. $outCode = $this->request->post('outCode', '', 'trim');
  4648. if (empty($outCode)) return error_show(1004, '发货申请单编号不能为为空');
  4649. Db::startTrans();
  4650. try {
  4651. $rs = Db::name('order_out')
  4652. ->field('id,orderCode,apply_id')
  4653. ->where(['outCode' => $outCode, 'status' => 2, "is_del" => 0])
  4654. ->find();
  4655. if (empty($rs)) throw new Exception('该出库单不存在或不允许确认收货');
  4656. //发货单收货
  4657. $res_order_out = Db::name('order_out')
  4658. ->where(['id' => $rs['id'], 'status' => 2, "is_del" => 0])
  4659. ->update(['status' => 3, 'updatetime' => date('Y-m-d H:i:s')]);
  4660. //发货工单不做更新,发货工单只给库管人员看,不关心是否收货,只保留 待发货/已发货/已取消 这几个状态就可以了
  4661. //查询该发货单所属的销售单,是否还有未收货的其他发货单
  4662. $other_res_sale = Db::name('order_out')
  4663. ->where(['orderCode' => $rs['orderCode'], 'status' => 2, "is_del" => 0])
  4664. ->where('id', '<>', $rs['id'])
  4665. ->find();
  4666. if (empty($other_res_sale)) {
  4667. //所属销售单也确认收货
  4668. Db::name('sale')
  4669. ->where(['orderCode' => $rs['orderCode'], 'status' => 0])
  4670. ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  4671. }
  4672. //修改状态,添加待办
  4673. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  4674. "order_code" => $outCode,
  4675. "status" => 2,//这里的status是之前的值
  4676. "action_remark" => '',//备注
  4677. "action_type" => "status"//新建create,编辑edit,更改状态status
  4678. ], "CKD", 3, $rs);
  4679. //将待办数据变为已办
  4680. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  4681. "order_code" => $outCode,
  4682. "order_id" => $rs['id'],
  4683. "order_status" => 3,
  4684. "order_type" => 'CKD',
  4685. "before_status" => 2,
  4686. 'holder_id' => $rs['apply_id']
  4687. ]);
  4688. if ($res_order_out) {
  4689. Db::commit();
  4690. return app_show(0, '收货完成');
  4691. } else {
  4692. Db::rollback();
  4693. error_show(1005, '收货失败');
  4694. }
  4695. } catch (\Exception $e) {
  4696. Db::rollback();
  4697. return error_show(1005, $e->getMessage());
  4698. }
  4699. }
  4700. //库管批量发货
  4701. public function outSendBatchByImport()
  4702. {
  4703. $param = $this->request->only(['list', 'token'], 'post', 'trim');
  4704. if (empty($param['list'])) return error_show(1005, 'list参数不能为空');
  4705. //只允许处理所属供应商下的采购单关联的发货单
  4706. $suppliers = Db::name('order_out')
  4707. ->alias('a')
  4708. ->leftJoin('order_num b', 'b.orderCode=a.orderCode')
  4709. ->leftJoin('purchease_order c', 'c.cgdNo=b.cgdNo')
  4710. ->where([
  4711. ['a.is_del', '=', 0],
  4712. ['c.order_type', '<>', 1],
  4713. ['a.outCode', 'in', array_column($param['list'], 'outCode')],
  4714. ])->column('c.supplierNo', 'a.outCode');
  4715. if ($this->level != 3) {
  4716. //检查这些供应商编码是否开通了账号
  4717. $temp_res = checkHasAccountBySupplierNos(array_values($suppliers));
  4718. // ->whereIn('supplierNo', array_values($suppliers))
  4719. // ->column('supplierNo');
  4720. // $temp = [];
  4721. // foreach ($suppliers as $k => $v) {
  4722. // if (in_array($v, $temp_res)) $temp[] = $k;
  4723. // }
  4724. if (!empty($temp_res)) return json_show(1003, '不允许处理已开通账号的供应商的单子', array_keys($temp_res));
  4725. }
  4726. // $user = GetUserInfo($param['token']);
  4727. $createrid = $this->uid;//$user['data']['id']??0;//$this->uid;
  4728. $creater = $this->uname;//$user['data']['nickname']??0;//$this->uname;
  4729. // $own_roleid = Db::name('user_role')->where(['is_del'=>0,'uid'=>$createrid,'status'=>1])->value('roleid',0);
  4730. //所有发货单信息
  4731. $order_out_infos = Db::name("order_out")
  4732. ->where('status', 1)
  4733. ->where('is_del', 0)
  4734. ->whereIn('outCode', array_column($param['list'], 'outCode'))
  4735. ->column('id,status,send_num,orderCode,wsm_code,apply_id,apply_name', 'outCode');
  4736. //所有库管人员信息
  4737. // $wsm_infos=Db::name('warehouse_info')
  4738. // ->where(['is_del'=>0,'wsm_code'=>array_column($order_out_infos,'wsm_code')])
  4739. // ->column('contactor','wsm_code');
  4740. //所有商品信息及供应商编码
  4741. $spuCodes=Db::name('sale')
  4742. ->where(['is_del'=>0,'orderCode'=>array_column($order_out_infos,'orderCode')])
  4743. ->column('good_code');
  4744. $supplierNo1 = Db::name('good_zixun')
  4745. ->where(['spuCode' => $spuCodes, 'is_del' => 0])
  4746. ->column('supplierNo','spuCode');
  4747. $supplierNo2 = Db::name('good')
  4748. ->where(['spuCode' => $spuCodes, 'is_del' => 0])
  4749. ->column('supplierNo','spuCode');
  4750. $supplierNos = array_unique(array_merge($supplierNo1,$supplierNo2));
  4751. $userCommon = \app\admin\common\User::getIns();
  4752. $temp = $userCommon->handle('sGetList',['more_code'=>array_values($supplierNos)]);
  4753. $supplier_personid = array_column($temp['data']['list'],'personid','code');
  4754. //处理数据
  4755. Db::startTrans();
  4756. try {
  4757. $good_data = $temp_out_codes = $yz_data = [];
  4758. foreach ($param['list'] as $value) {
  4759. if (!isset($order_out_infos[$value['outCode']])) throw new Exception($value['outCode'] . '该发货单未找到或状态不允许发货');
  4760. //每次循环都需要重新查询对应数据,为了数据及时更新
  4761. $sale_infos = Db::name("sale")
  4762. ->where('orderCode', $order_out_infos[$value['outCode']]['orderCode'])
  4763. ->where('is_del', 0)
  4764. ->column('id,send_num,wsend_num,status,good_code,order_source,order_type,apply_id,apply_name,is_stock,cgderid,orderCode', 'orderCode');
  4765. if (!isset($sale_infos[$order_out_infos[$value['outCode']]['orderCode']])) throw new Exception($value['outCode'] . '该发货单对应的销售单未找到');
  4766. //判断发货单是否重复
  4767. if (isset($temp_out_codes[$value['outCode']])) {
  4768. Db::rollback();
  4769. return app_show(1005, '下列发货申请单号重复', [$value]);
  4770. } else $temp_out_codes[$value['outCode']] = $value['outCode'];
  4771. if($this->level==2) {
  4772. //level2账号的话,库存品只能由库管操作,非库存品只能由供应商负责人操作,level3账号不限制
  4773. if ($sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['is_stock'] == 1) {
  4774. //由于存在一个单子对应多个仓库的情况,因此库存品的判断暂时无法进行,待分仓功能完成后再考虑
  4775. // if($wsm_infos[$order_out_infos[$value['outCode']]['wsm_code']]??0 != $createrid) throw new \think\Exception($value['outCode'] . '发货单只能由库管操作');
  4776. // if (!in_array($own_roleid, config('app.wsm_cgder_role'))) {
  4777. // Db::rollback();
  4778. // return app_show(1003, $value['outCode'] . '发货单只能由库管操作');
  4779. // }
  4780. } else {
  4781. // if ($sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['order_type'] == 3 || $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['order_type'] == 4) {
  4782. // $supplierNo = Db::name('good_zixun')
  4783. //// ->leftJoin("supplier b", "a.supplierNo=b.code")
  4784. // ->where(['spuCode' => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code'], 'is_del' => 0])
  4785. // ->value('supplierNo');
  4786. // } else {
  4787. // $supplierNo = Db::name('good')
  4788. //// ->alias("a")
  4789. //// ->leftJoin("supplier b", "a.supplierNo=b.code")
  4790. // ->where(['spuCode' =>$sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code'], 'is_del' => 0])
  4791. // ->value('supplierNo');
  4792. // }
  4793. if ($createrid != $supplier_personid[$supplierNos[$sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code']]]) throw new \think\Exception($value['outCode'] . '发货单只能由供应商负责人操作');
  4794. // Db::rollback();
  4795. // return app_show(1003, $value['outCode'] . '发货单只能由供应商负责人操作');
  4796. }
  4797. }
  4798. //【发货单】
  4799. //查询已有发货单信息及状态
  4800. //更新发货单
  4801. $up = Db::name("order_out")
  4802. ->where(['id' => $order_out_infos[$value['outCode']]['id'], 'outCode' => $value['outCode'], 'status' => 1, "is_del" => 0])
  4803. ->update([
  4804. 'post_name' => isset($value['post_name']) ? $value['post_name'] : '',
  4805. 'post_code' => $value['post_code'],
  4806. 'post_fee' => $value['post_fee'],
  4807. 'sendtime' => date('Y-m-d H:i:s'),
  4808. 'status' => 2,
  4809. 'updatetime' => date('Y-m-d H:i:s'),
  4810. 'remark' => isset($value['remark']) ? $value['remark'] : '',
  4811. ]);
  4812. if ($up) {
  4813. //修改状态,添加待办
  4814. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  4815. "order_code" => $value['outCode'],//出库单号
  4816. "status" => $order_out_infos[$value['outCode']]['status'],//这里的status是之前的值
  4817. "action_remark" => '',//备注
  4818. "action_type" => "edit"//新建create,编辑edit,更改状态status
  4819. ], "CKD", 2, $order_out_infos[$value['outCode']]);
  4820. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  4821. "order_type" => 'CKD',
  4822. "order_code" => $value['outCode'],//出库单号
  4823. "order_id" => $order_out_infos[$value['outCode']]['id'],
  4824. "order_status" => 2,
  4825. "before_status" => $order_out_infos[$value['outCode']]['status'],
  4826. 'wait_id' => $order_out_infos[$value['outCode']]['apply_id'],
  4827. 'wait_name' => $order_out_infos[$value['outCode']]['apply_name'],
  4828. 'holder_id' => $order_out_infos[$value['outCode']]['apply_id'],
  4829. ]);
  4830. //【销售单】
  4831. $einfo = [];
  4832. $einfo['send_num'] = $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['send_num'] + $order_out_infos[$value['outCode']]['send_num'];
  4833. $einfo['wsend_num'] = $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['wsend_num'] - $order_out_infos[$value['outCode']]['send_num'];
  4834. $einfo['status'] = $einfo['wsend_num'] == 0 ? 2 : ($einfo['send_num'] == 0 ? 0 : 1);
  4835. $einfo['send_status'] = $einfo['wsend_num'] == 0 ? 3 : ($einfo['send_num'] == 0 ? 1 : 2);
  4836. $einfo['updatetime'] = date("Y-m-d H:i:s");
  4837. $saleup = Db::name("sale")
  4838. ->where('id', $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['id'])
  4839. ->update($einfo);
  4840. if ($saleup == false) throw new Exception($value['outCode'] . '销售单状态更新失败');
  4841. //修改状态,添加待办
  4842. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  4843. "order_code" => $order_out_infos[$value['outCode']]['orderCode'],//销售单号
  4844. "status" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['status'],//这里的status是之前的值
  4845. "action_remark" => '',//备注
  4846. "action_type" => "edit"//新建create,编辑edit,更改状态status
  4847. ], "XSQRD", $einfo['status'], $einfo);
  4848. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  4849. "order_type" => 'XSQRD',
  4850. "order_code" => $order_out_infos[$value['outCode']]['orderCode'],//出库单号
  4851. "order_id" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['id'],
  4852. "order_status" => $einfo['status'],
  4853. "before_status" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['status'],
  4854. 'holder_id' => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['apply_id']
  4855. ]);
  4856. if($sale_infos[$order_out_infos[$value['outCode']]['orderCode']]["order_type"]!=1){
  4857. //【库存】
  4858. $stock = Db::name("good_stock")
  4859. ->field('id,wait_out_stock,usable_stock,total_stock,updatetime')
  4860. ->where([
  4861. "is_del" => 0,
  4862. 'spuCode' => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code'],
  4863. "wsm_code" => $order_out_infos[$value['outCode']]['wsm_code'],
  4864. ])->find();
  4865. if ($stock == false) throw new Exception($value['outCode'] . '未找到库存数据');
  4866. else {
  4867. if ($order_out_infos[$value['outCode']]['send_num'] > $stock['wait_out_stock']) throw new Exception($value['outCode'] . '超出库存数量');
  4868. $stock['wait_out_stock'] -= $order_out_infos[$value['outCode']]['send_num'];
  4869. $stock['total_stock'] = $stock['wait_out_stock'] + $stock['usable_stock'];
  4870. $stock['updatetime'] = date("Y-m-d H:i:s");
  4871. $stock_rs = Db::name("good_stock")
  4872. ->where('id', $stock['id'])
  4873. ->update($stock);
  4874. if ($stock_rs == false) throw new Exception($value['outCode'] . '库存更新失败');
  4875. // $outsend =Db::name("order_send")->where(["outCode"=> $value['outCode']])->findOrEmpty();
  4876. // if(empty($outsend)){
  4877. // Db::rollback();
  4878. // return error_show(1002, "未找到关联采购单");
  4879. // }
  4880. // $cgdinfo= Db::name("purchease_order")->where(["cgdNo"=>$outsend['cgdNo'],"is_del"=>0])
  4881. // ->findOrEmpty();
  4882. // $bn_code =makeNo("BN");
  4883. // $bnin=GoodStockInfo::AddBn($stock["id"],$bn_code,$order_out_infos[$value['outCode']]['send_num'],$cgdinfo['good_price']??0);
  4884. // if($bnin==false){
  4885. // Db::rollback();
  4886. // return error_show(1004,"库存bn数据新增失败");
  4887. // }
  4888. // $bnup =GoodStockInfo::OrderBn($order_out_infos[$value['outCode']]['orderCode'],$stock["id"],$order_out_infos[$value['outCode']]['send_num'],0);
  4889. // if($bnup==false){
  4890. // Db::rollback();
  4891. // return error_show(1004,"库存bn库存数更新失败");
  4892. // }
  4893. // $outsend['bnCode']=$bn_code;
  4894. // $outsend['updatetime']=date("Y-m-d H:i:s");
  4895. // $ps=Db::name("order_send")->save($outsend);
  4896. // if($ps==false){
  4897. // Db::rollback();
  4898. // return error_show(1004,"库存bn库存数更新失败");
  4899. // }
  4900. }
  4901. $good_data[] = [
  4902. 'good_log_code' => $value['outCode'],
  4903. 'stock_id' => $stock['id'],
  4904. 'type' => 2,
  4905. 'stock' => $order_out_infos[$value['outCode']]['send_num'],
  4906. 'stock_name' => 'wait_out_stock'
  4907. ];
  4908. }else{
  4909. // $bnup =SaleInfo::SendStock($order_out_infos[$value['outCode']]['orderCode'],$order_out_infos[$value['outCode']]['send_num']);
  4910. // if($bnup==false){
  4911. // Db::rollback();
  4912. // return error_show(1004,"库存bn库存数更新失败");
  4913. // }
  4914. // $saleinfo =Db::name("sale_info")->where(["orderCode"=>$order_out_infos[$value['outCode']]['orderCode']])->select()->toArray();
  4915. // if (!empty($saleinfo)){
  4916. // $bnup =SaleInfo::SendStock($order_out_infos[$value['outCode']]['orderCode'],$order_out_infos[$value['outCode']]['send_num']);
  4917. // if($bnup==false){
  4918. // Db::rollback();
  4919. // return error_show(1004,"库存bn库存数更新失败");
  4920. // }
  4921. // }else{
  4922. $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();
  4923. if ($stokc == false) {
  4924. Db::rollback();
  4925. return error_show(1002, "未找到库存数据");
  4926. } else {
  4927. if ($order_out_infos[$value['outCode']]['send_num'] > $stokc['wait_out_stock']) {
  4928. Db::rollback();
  4929. return error_show(1002, "超出库存数量");
  4930. }
  4931. $stokc['wait_out_stock'] -= $order_out_infos[$value['outCode']]['send_num'];
  4932. $stokc['total_stock'] = $stokc['wait_out_stock'] + $stokc['usable_stock'];
  4933. // $stokc['intra_stock']+=$outinfo['send_num'];
  4934. $stokc['updatetime'] = date("Y-m-d H:i:s");
  4935. }
  4936. $stoc = Db::name("good_stock")->save($stokc);
  4937. if ($stoc == false) {
  4938. Db::rollback();
  4939. return error_show(1002, "库存更新失败");
  4940. }
  4941. // }
  4942. }
  4943. } else throw new Exception($value['outCode'] . '发货失败');
  4944. // Cache::store("redis")->handler()->lPush("SENDOUT",$value['outCode']);
  4945. //如果是有赞订单的话,将发货信息推到有赞
  4946. if($sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['order_source']==5){
  4947. $yz_data[]=[
  4948. 'orderCode'=>$sale_infos[$order_out_infos[$value['outCode']]['orderCode']],
  4949. 'out_stype'=>isset($value['post_name']) ? $value['post_name'] : '',
  4950. 'post_code'=>$value['post_code'],
  4951. 'uid'=>$createrid,
  4952. 'uname'=>$creater,
  4953. 'order_out'=>$value['outCode'],
  4954. ];
  4955. }
  4956. }
  4957. if (!empty($good_data)) GoodLog::LogAdd(['id' => $createrid, 'nickname' => $creater], $good_data, "CKD");
  4958. Db::commit();
  4959. //如果是有赞订单的话,将发货信息推到有赞
  4960. //有赞信息有可能推送失败(比如超过72小时,不允许多次修改等),所以不应该和这里的事务放到一起
  4961. if ($yz_data) {
  4962. foreach ($yz_data as $yz) {
  4963. // $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]);
  4964. curl_request(config('app.yz_domain') . 'api/yz_out_send', $yz);
  4965. }
  4966. // $res = json_decode($res, true);
  4967. // if ($res['code'] != 0) return app_show(0, '发货成功,' . $res['message']);
  4968. }
  4969. return app_show(0, '发货成功');
  4970. } catch (Exception $exception) {
  4971. Db::rollback();
  4972. return error_show(1004, $exception->getMessage());
  4973. }
  4974. }
  4975. //获取物流信息
  4976. public function getLogisticsInformation()
  4977. {
  4978. $post_code = $this->request->post('post_code', '', 'trim');
  4979. if (empty($post_code)) return error_show(1004, '快递单号不能为空');
  4980. $postCode = explode(",", $post_code);
  4981. $rs = Db::name('express_data')
  4982. ->where('post_code', $postCode[0])
  4983. ->where('status', ">=", 0)
  4984. ->withAttr('post_data', function ($val) {
  4985. return json_decode($val, true);
  4986. })->findOrEmpty();
  4987. settype($rs, 'object');//格式统一转为对象
  4988. return app_show(0, '请求成功', $rs);
  4989. }
  4990. //订单取消
  4991. //未发货状态添加撤销功能 要求1.库存品 未发货 直接撤销 2.除了库存品以外的商品类型,采购单未入库的 可撤销。
  4992. public function orderCancel()
  4993. {
  4994. $orderCode = $this->request->post('orderCode', '', 'trim');
  4995. $val = Validate::rule(['orderCode' => 'require|array|max:100']);
  4996. if ($val->check(['orderCode' => $orderCode]) == false) return json_show(1004, $val->getError());
  4997. $list = Db::name('sale')
  4998. ->alias('a')
  4999. ->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,
  5000. 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,
  5001. a.addtime,c.wsm_code,a.order_source,a.other_orderNo')
  5002. ->leftJoin('order_num b', 'b.orderCode=a.orderCode')
  5003. ->leftJoin('purchease_order c', 'c.cgdNo=b.cgdNo')
  5004. ->where(['a.is_del' => 0, 'a.orderCode' => $orderCode])
  5005. ->select()
  5006. ->toArray();
  5007. Db::startTrans();
  5008. try {
  5009. $date = date('Y-m-d H:i:s');
  5010. $th=[];
  5011. $cgdId=[];
  5012. foreach ($list as $sale) {
  5013. if ($sale['sale_status'] == 3) throw new \think\Exception($sale['orderCode'] . '已取消,无法重复操作');
  5014. if ($sale['order_type'] == 1) {
  5015. if ($sale['sale_status'] != 0) throw new \think\Exception($sale['orderCode'] . '已发货,无法取消');
  5016. $good = Db::name("good")->where(["spuCode" => $sale['good_code']])->findOrEmpty();
  5017. if (empty($good)) throw new Exception('未找到商品信息');
  5018. $stock = Db::name("good")->where($good)
  5019. ->inc("usable_stock",$sale['wsend_num'])
  5020. ->update();
  5021. if ($stock == false) throw new Exception('商品库存更新失败');
  5022. if(strtotime($sale['addtime'])< strtotime('2023-04-17 00:00:00')){
  5023. $saleinfo = Db::name('sale_info')
  5024. ->where([['orderCode', '=',$sale['orderCode']], ['num', '>', 0]])
  5025. ->select()
  5026. ->toArray();
  5027. if (empty($saleinfo)) {
  5028. $ordernum = Db::name('order_num')->where(['orderCode' =>$sale['orderCode']])->findOrEmpty();
  5029. if (empty($ordernum)) throw new Exception('未找到关联采购单');
  5030. $cgd = Db::name('purchease_order')->where(['cgdNo' => $ordernum['cgdNo'], 'is_del' => 0])->findOrEmpty();
  5031. if (empty($cgd)) throw new Exception('未找到采购单数据');
  5032. $bn = makeNo('BN');
  5033. $stock = Db::name('good_stock')
  5034. ->where(['spuCode' => $sale['good_code'], 'wsm_code' => $cgd['wsm_code'], 'is_del' => 0, 'status' => 1])
  5035. ->findOrEmpty();
  5036. if ($stock == false) throw new Exception('商品库存数据未找到');
  5037. $stock['usable_stock'] += $sale['wsend_num'];
  5038. $stock['wait_out_stock'] -= $sale['wsend_num'];
  5039. $stock['updatetime'] = $date;
  5040. $st_up = Db::name('good_stock')->save($stock);
  5041. if ($st_up == false) throw new Exception('可售商品入库失败');
  5042. $yp = GoodStockInfo::AddBn($stock['id'], $bn, $sale['wsend_num'], $cgd['good_price']);
  5043. if ($yp == false) throw new Exception('商品批次退货入库失败');
  5044. }
  5045. else {
  5046. $tempnum = $sale['wsend_num'];
  5047. foreach ($saleinfo as $va) {
  5048. if ($tempnum == 0) break;
  5049. $stock = Db::name('good_stock')->where(['spuCode' => $sale['good_code'], 'id' => $va['stockid']])
  5050. ->findOrEmpty();
  5051. if ($stock == false) throw new Exception('商品库存数据未找到');
  5052. if ($va['num'] >= $tempnum) {
  5053. $tnm = $tempnum;
  5054. $va['num'] -= $tempnum;
  5055. $va['th_num'] += $tempnum;
  5056. $tempnum = 0;
  5057. } else {
  5058. $tnm = $va['num'];
  5059. $tempnum -= $va['num'];
  5060. $va['th_num'] += $va['num'];
  5061. $va['num'] = 0;
  5062. }
  5063. $stock['usable_stock'] += $tnm;
  5064. $stock['wait_out_stock'] -= $tnm;
  5065. $stock['updatetime'] = $date;
  5066. $st_up = Db::name('good_stock')->save($stock);
  5067. if ($st_up == false) throw new Exception('可售商品入库失败');
  5068. $ps = GoodStockInfo::AddBn($va['stockid'], $va['bnCode'], $tnm);
  5069. if ($ps == false) throw new Exception('商品批次退货入库失败');
  5070. $ret = GoodStockInfo::ReturnBn($sale['orderCode'], $va['id'], $tnm);
  5071. if ($ret == false) throw new Exception('商品批次退货入库失败');
  5072. $va['updatetime'] = $date;
  5073. $sal = Db::name('sale_info')->save($va);
  5074. if ($sal == false) throw new Exception('商品批次退货入库失败');
  5075. }
  5076. }
  5077. }
  5078. SaleCgdPrice::RePrice($sale['sale_id'],$sale['wsend_num']);
  5079. }
  5080. else{
  5081. if ($sale['order_source'] != 9){
  5082. $good = Db::name('good_stock')->where(['spuCode' => $sale['good_code'],'wsm_code'=>$sale['wsm_code']])
  5083. ->findOrEmpty();
  5084. if (empty($good)) throw new Exception('未找到商品信息');
  5085. if($sale['cgd_status']==1){
  5086. $stock = Db::name('good_stock')->where($good)
  5087. ->inc('wait_in_stock',$sale['wsend_num'])
  5088. ->update();
  5089. if ($stock == false) throw new Exception('商品库存更新失败');
  5090. }
  5091. if($sale['cgd_status']==3){
  5092. $wait_out= Db::name('order_out_child')
  5093. ->where(['is_del' => 0, 'orderCode' => $sale['orderCode'],'status'=>1])
  5094. ->sum('num');
  5095. $usable = $sale['wsend_num'] - intval($wait_out);
  5096. if($usable>0){
  5097. $stock = Db::name('good_stock')->where($good)
  5098. ->inc('usable_stock',$usable)
  5099. ->update();
  5100. if ($stock == false) throw new Exception('商品库存更新失败');
  5101. }
  5102. }
  5103. }
  5104. }
  5105. if($sale['order_type'] == 4){
  5106. $fill =Db::name("filing")->where(["filingCode"=>$sale["platform_order"]])->findOrEmpty();
  5107. if(empty($fill)) throw new Exception($sale['orderCode'] . '未找到对应得报备单');
  5108. $fullData=[
  5109. 'transfer_num'=>$fill['transfer_num']-$sale['wsend_num'],
  5110. 'wait_num'=>$fill['wait_num']+$sale['wsend_num'],
  5111. 'status'=>$fill['wait_num']+$sale['wsend_num']==0?4:
  5112. ($fill['transfer_num']-$sale['wsend_num']==0?2:3)];
  5113. $fillup=Db::name('filing')
  5114. ->where($fill)
  5115. ->data($fullData)
  5116. ->update();
  5117. $stn = ['order_code' => $fill['filingCode'], 'status' =>$fullData['status'], 'action_remark' => '', 'action_type' => 'status'];
  5118. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stn, 'BBD', $fill['status'],$fullData);
  5119. if($fillup==false)throw new Exception($sale['platform_order'] . '报备单更新失败');
  5120. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  5121. 'order_type' => 'BBD',
  5122. 'order_code' => $fill['filingCode'],//出库单号
  5123. 'order_id' => $fill['id'],
  5124. 'order_status' =>$fullData['status'],
  5125. 'before_status' => $fill['status'],
  5126. 'wait_id'=>0,
  5127. 'wait_name'=>0,
  5128. ]);
  5129. }
  5130. if($sale['order_source'] == 11){
  5131. $fill =(new BbcFill())->where(['fillCode'=>$sale['other_orderNo']])->findOrEmpty();
  5132. if($fill->isEmpty()) throw new Exception($sale['orderCode'] . '未找到对应得业务报备单');
  5133. if($fill->transfer_num <$sale['wsend_num'])throw new Exception($sale['orderCode'] . '对应得业务报备单已转单数量不足');
  5134. $fill->transfer_num -=$sale['wsend_num'];
  5135. $fill->status=$fill->transfer_num >0?2:1;
  5136. $upd=$fill->save();
  5137. if($upd==false)throw new \Exception('业务报备单更新失败');
  5138. }
  5139. $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$sale['orderCode'], "isCgd"=>1]);
  5140. if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
  5141. Db::rollback();
  5142. return json_show(10005, $fininfo['message']??'结算校验失败',$fininfo['data']??[]);
  5143. }
  5144. $thtemp=[
  5145. "orderCode"=>$sale["orderCode"],
  5146. "th_type"=>4,//取消订单
  5147. "th_num"=>$sale["good_num"],
  5148. "th_fee"=>$sale["total_price"],
  5149. "thCode"=>$sale["orderCode"],
  5150. "cat_id"=>$sale["cat_id"],
  5151. "good_name"=>$sale["good_name"],
  5152. "spuCode"=>$sale["good_code"],
  5153. "apply_id"=>$this->uid,
  5154. "apply_name"=>$this->uname,
  5155. "addtime"=>$date
  5156. ];
  5157. $th[]=$thtemp;
  5158. //修改状态,添加待办
  5159. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  5160. "order_code" => $sale['orderCode'],//销售单号
  5161. "status" => $sale['sale_status'],//这里的status是之前的值
  5162. "action_remark" => '',//备注
  5163. "action_type" => "status"//新建create,编辑edit,更改状态status
  5164. ], "XSQRD", 3, ['orderCode' => $orderCode]);
  5165. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  5166. "order_type" => 'XSQRD',
  5167. "order_code" => $sale['orderCode'],
  5168. "order_id" => $sale['sale_id'],
  5169. "order_status" => 3,
  5170. "before_status" => $sale['sale_status'],
  5171. 'holder_id' => $sale['good_createrid'],
  5172. ]);
  5173. if ($sale['cgdNo']) {
  5174. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  5175. "order_code" => $sale['cgdNo'],//销售单号
  5176. "status" => $sale['cgd_status'],//这里的status是之前的值
  5177. "action_remark" => '',//备注
  5178. "action_type" => "status"//新建create,编辑edit,更改状态status
  5179. ], "CGD", 4, ['orderCode' => $sale['cgdNo']]);
  5180. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  5181. "order_type" => 'CGD',
  5182. "order_code" => $sale['cgdNo'],
  5183. "order_id" => $sale['cgd_id'],
  5184. "order_status" => 4,
  5185. "before_status" => $sale['cgd_status'],
  5186. 'holder_id' => $sale['cgder_id'],
  5187. ]);
  5188. $cgdId[]=$sale['cgd_id'];
  5189. }
  5190. }
  5191. $orderup= Db::name('sale')
  5192. ->where(['is_del' => 0, 'id' => array_column($list, 'sale_id')])
  5193. ->update([
  5194. 'status' => 3,
  5195. 'th_num' => Db::raw("good_num"),
  5196. 'th_fee' =>Db::raw("total_price"),
  5197. 'send_num' =>Db::raw("good_num"),
  5198. 'wsend_num' =>0,
  5199. 'send_status' =>3,
  5200. 'updatetime' => $date
  5201. ]);
  5202. if($orderup==false) throw new \Exception("订单状态更新失败");
  5203. $thin= Db::name("th_data")->insertAll($th);
  5204. if($thin==false) throw new \Exception('订单取消失败');
  5205. if(!empty($cgdId)){
  5206. $cgdup=Db::name('purchease_order')
  5207. ->where(['is_del' => 0, 'id' => $cgdId])
  5208. ->update([
  5209. 'status' => 4,
  5210. 'th_num' => Db::raw('wsend_num+send_num'),
  5211. 'th_fee' =>Db::raw('total_fee'),
  5212. 'send_num' =>Db::raw('wsend_num+send_num'),
  5213. 'wsend_num' =>0,
  5214. 'send_status' =>3,
  5215. 'updatetime' => $date]);
  5216. if($cgdup==false) throw new \Exception('采购单取消失败');
  5217. }
  5218. $out_list = Db::name('order_out')
  5219. ->where(['is_del' => 0, 'orderCode' => $orderCode])
  5220. ->select()
  5221. ->toArray();
  5222. if (!empty($out_list)) {
  5223. $sen= Db::name('order_out')
  5224. ->where(['is_del' => 0, 'orderCode' => $orderCode])
  5225. ->update(['status' => 5, 'updatetime' => $date]);
  5226. if($sen==false) throw new \Exception('发货单取消失败');
  5227. foreach ($out_list as $out) {
  5228. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  5229. "order_code" => $out['outCode'],//销售单号
  5230. "status" => $out['status'],//这里的status是之前的值
  5231. "action_remark" => '',//备注
  5232. "action_type" => "status"//新建create,编辑edit,更改状态status
  5233. ], "CKD", 5, $out);
  5234. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  5235. "order_type" => 'CKD',
  5236. "order_code" => $out['outCode'],
  5237. "order_id" => $out['id'],
  5238. "order_status" => 5,
  5239. "before_status" => $out['status'],
  5240. 'holder_id' => $out['apply_id'],
  5241. ]);
  5242. }
  5243. }
  5244. $ooc_list = Db::name('order_out_child')
  5245. ->where(['is_del' => 0, 'orderCode' => $orderCode])
  5246. ->select()
  5247. ->toArray();
  5248. if (!empty($ooc_list)) {
  5249. $child= Db::name('order_out_child')
  5250. ->where(['is_del' => 0, 'orderCode' => $orderCode])
  5251. ->update(['status' => 5, 'updatetime' => $date]);
  5252. if ($child == false) throw new Exception('发货工单更新失败');
  5253. foreach ($ooc_list as $ooc) {
  5254. $stockinfo = Db::name("good_stock")->where(["spuCode" => $ooc['spuCode'], "wsm_code" => $ooc['wsm_code']])->findOrEmpty();
  5255. if (empty($stockinfo)) throw new Exception('未找到库存信息');
  5256. $stockup = [
  5257. "usable_stock" =>$ooc['order_type']==1? $stockinfo['usable_stock'] + $ooc['num']:$stockinfo['usable_stock'],
  5258. "wait_out_stock" => $stockinfo['wait_out_stock'] - $ooc['num'],
  5259. "updatetime" => $date
  5260. ];
  5261. $ysup = Db::name("good_stock")->where($stockinfo)->update($stockup);
  5262. if ($ysup == false) throw new Exception('库存信息更新失败');
  5263. if($ooc['order_type']==1)GoodStockInfo::ChildReturnBn($ooc['outChildCode'], $stockinfo['id'], $ooc['num']);//处理bn数据
  5264. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  5265. "order_code" => $ooc['outChildCode'],//销售单号
  5266. "status" => $ooc['status'],//这里的status是之前的值
  5267. "action_remark" => '',//备注
  5268. "action_type" => "status"//新建create,编辑edit,更改状态status
  5269. ], "FHGD", 5, $ooc);
  5270. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  5271. "order_type" => 'FHGD',
  5272. "order_code" => $ooc['outChildCode'],
  5273. "order_id" => $ooc['id'],
  5274. "order_status" => 5,
  5275. "before_status" => $ooc['status'],
  5276. 'holder_id' => $ooc['apply_id'],
  5277. ]);
  5278. }
  5279. }
  5280. Db::commit();
  5281. return json_show(0, '操作成功');
  5282. } catch (\think\Exception $exception) {
  5283. Db::rollback();
  5284. return json_show(1004, $exception->getMessage());
  5285. }catch (Exception $exception){
  5286. Db::rollback();
  5287. return json_show(1004, $exception->getMessage());
  5288. }
  5289. }
  5290. }