Sale.php 296 KB

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