1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ConsultTemp;
- use app\admin\model\DataGroup as DataGroupModel;
- use app\admin\model\GoodLog;
- use app\admin\model\GoodPlatform;
- use app\admin\model\GoodStockInfo;
- use app\admin\model\GoodTax;
- use app\admin\model\OrderOutChild;
- use app\admin\model\OrderTax;
- use app\admin\model\ProcessOrder;
- use app\admin\model\SaleCgdPrice;
- use app\bbc\model\BbcFill;
- use app\model\TaxCategory;
- use Exception;
- use think\App;
- use think\facade\Db;
- use app\admin\model\ActionLog;
- use think\facade\Validate;
- //销售单
- class Sale extends Base
- {
- public $noble = [];
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->noble = \think\facade\Config::get("noble");
- }
- public function create()
- {
- $orderCode = makeNo("QR");
- $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
- if ($customer_code == "") {
- return error_show(1002, "客户customer_code不能为空");
- }
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
- $userCommon = \app\admin\common\User::getIns();
- $tmp = $userCommon->handle('getCodeAndName',['code'=>[$customer_code,$supplierNo]]);
- if(!isset($tmp['code']) || $tmp['code']!=0) return json_show($tmp['code'],$tmp['message'],$tmp['data']);
- if(!isset($tmp['data'][$customer_code])) return json_show(1004, "未找到客户数据");
- if(!isset($tmp['data'][$supplierNo])) return json_show(1004, '未找到平台供应商数据');
- $goodtype = isset($this->post['goodtype']) && $this->post['goodtype'] !== "" ? intval($this->post['goodtype']) : "1";
- $order_type = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type']) : "1";
- $sendtype = isset($this->post['sendtype']) && $this->post['sendtype'] !== "" ? intval($this->post['sendtype']) : "";
- if ($sendtype === '') {
- return error_show(1004, "参数sendtype不能为空");
- }
- $platform_id = isset($this->post['platform_id']) && $this->post['platform_id'] !== "" ? intval($this->post['platform_id']) : "";
- if ($platform_id == '') {
- return error_show(1004, "参数platform_id不能为空");
- }
- $platforminfo = Db::name("platform")->where(["id"=> $platform_id,"is_del"=>0])->findOrEmpty();
- if (empty($platforminfo)) return error_show(1004, "平台信息未找到");
- if ($platforminfo['status'] != 1) return error_show(1004, "平台信息已禁用");
- if($platforminfo['is_select_pay_rate']==1 && channel_is_company($platform_id,$supplierNo))return error_show(1004, "平台渠道包含当前业务公司 {$tmp['data'][$supplierNo]}");
- $platform_order = isset($this->post['platform_order']) && $this->post['platform_order'] !== "" ? trim($this->post['platform_order']) : "";
- $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
- if ($good_code == '') {
- return error_show(1004, "参数good_code不能为空");
- }
- $good_num = isset($this->post['good_num']) && $this->post['good_num'] !== "" ? intval($this->post['good_num']) : "";
- if ($good_num === '') {
- return error_show(1004, "参数good_num不能为空");
- }
- $arrtime = isset($this->post['arrtime']) && $this->post['arrtime'] != "" ? $this->post['arrtime'] : "";
- if ($arrtime == "") {
- return error_show(1004, "参数arrtime不能为空");
- }
-
- $manager = isset($this->post['manager']) && $this->post['manager'] != '' ? $this->post['manager'] :$this->uname;
- $managerid = isset($this->post['managerid']) && $this->post['managerid'] != '' ? $this->post['managerid'] :$this->uid;
- $paytime = isset($this->post['paytime']) && $this->post['paytime'] != "" ? $this->post['paytime'] : "";
- $workNo = isset($this->post['workNo']) && $this->post['workNo'] != "" ? trim($this->post['workNo']) : "";
- $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $good_code])->field("b.*,a.skuCode,a.platform_code,a.plat_code,a.is_fixed")
- ->findOrEmpty();
- if (empty($ct)) {
- return error_show(1002, "未找到商品数据");
- }
- $holder_id=0;
- $holder_name='';
- $supplier_name=$ct['supplierName'];
- if($ct['is_combind']==0){
- $supplier_temp =$userCommon->handle('sInfo',['code'=>$ct['supplierNo']]);
- if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,'采购单供应商不存在');
- $holder_id=$supplier_temp['data']['personid']??0;
- $holder_name=$supplier_temp['data']['person']??'';
- $supplier_name=$supplier_temp['data']['name']??'';
- }
- $goodinfo = $ct;
- $is_stock = $ct['is_stock'];
- $spuCode = $ct['spuCode'];
- $skuCode = $ct['skuCode'];
- $is_activity = isset($this->post['is_activity']) && $this->post['is_activity'] !== "" ? $this->post['is_activity'] : "";
- $actcode = isset($this->post['act_code']) && $this->post['act_code'] !== "" ? trim($this->post['act_code']) : "";
- if ($order_type == 1) {
- if ($is_activity === "") {
- return error_show(1002, "参数is_activity不能为空");
- }
- if ($is_activity == 1 && $actcode == "") {
- return error_show(1002, "参数act_code不能为空");
- }
- }
- $origin = Db::name('good_nake')->where([['spuCode', '=', $spuCode], ['min_num', '<=', $good_num], ['is_del', '=', 0]])->order('min_num desc')->find();
- $origin_price = $origin['nake_total']??0;
- $cgd_origin_price = $origin['supplier_origin_price']??0;
- if ($goodinfo['is_stock'] == 1) {
- $stock_num = Db::name("good")->where(["spuCode"=> $spuCode])->value("usable_stock",0);
- if($stock_num < $good_num){
- return error_show(1003, "商品可用库存数量不足");
- }
- $origin_price = 0;
- }else{
-
- if ($origin == false) {
- return error_show(1003, '未找到相关阶梯成本价格');
- }
- }
- $sale_price = isset($this->post['good_price']) && $this->post['good_price'] !== "" ? floatval($this->post['good_price']) : '';
- $ct['cgd_gold_price'] = 0;
- if ($goodtype == 1) {
- if ($is_activity == 1) {
- $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b", "a.activity_code=b.activity_code")
- ->where(["a.skuCode" => $skuCode, "a.activity_code" => $actcode, "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])
- ->find();
- if ($act == false) {
- return error_show(1003, "未找到相关活动价");
- }
- if ($act['moq_num'] > $good_num) {
- return error_show(1003, "商品不满足活动价起订量{$act['moq_num']}");
- }
- if ($act['activity_stock'] < $good_num) {
- return error_show(1003, "商品活动库存剩余{$act['activity_stock']}");
- }
- $sale_price = $sale_price !== "" ? $sale_price : $act['activity_price'];
- $origin_price = $act['cost_price'];
- } else {
- $good = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->where([["min_num", "<=", $good_num]])->order("min_num desc")->find();
- if ($good == false) {
- return error_show(1003, "未找到相关阶梯价格");
- }
- $sale_price = $sale_price !== "" ? $sale_price : $good['sale_price'];
- if ($ct['is_gold_price'] == 1 && $is_stock != 1) {
- $gold = Db::name("gold_price1")
- ->field('id,price')
- ->where(["type" => $ct['noble_metal'], "is_del" => 0, "status" => 1])
- ->order("addtime desc")
- ->find();
- if($ct['is_fixed']==0) $origin['nake_fee']=0;
- //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
- $sale_price = $sale_price !== "" ? $sale_price : ($ct['demo_fee'] / $good_num + $ct['open_fee'] / $good_num
- + $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']);
- $ct['cgd_gold_price'] = $gold["price"];
- }
- }
- } else {
- $sale_price = 0;
- }
-
- $cgd = [
- "supplierNo" => $ct['supplierNo'],
- "supplierName" => $supplier_name,
- "companyNo" => $supplierNo,
- "companyName" => $tmp['data'][$supplierNo]??"",
- "orderCode" => $orderCode,
- "spuCode" => $ct['spuCode'],
- "skuCode" => $ct['skuCode'],
- "good_name" => $ct['good_name'],
- "sale_price" => $origin_price,
- "total_fee" => $origin_price * $good_num,
- "pakge_fee" => isset($origin['package_fee']) ? $origin['package_fee'] : 0,
- "cert_fee" => isset($origin['cert_fee']) ? $origin['cert_fee'] : 0,
- "open_fee" => $ct['open_fee'],
- "cost_fee" => isset($origin['cost_fee']) ? $origin['cost_fee'] : 0,
- "mark_fee" => isset($origin['mark_fee']) ? $origin['mark_fee'] : 0,
- "nake_fee" => isset($origin['nake_fee']) ? $origin['nake_fee'] : 0,
- "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
- "demo_fee" => $ct['demo_fee'],
- "good_num" => $good_num,
- "good_type" => $goodtype,
- "weight" => $ct['noble_weight'],
- "gold_price" => isset($ct['cgd_gold_price']) ? $ct['cgd_gold_price'] : 0,
- "order_type" => $is_stock == 1 ? 1 : 2,
- "order_source" => 1,//1直接下单
- "createrid" =>$holder_id,
- "creater" =>$holder_name,
- 'send_way' => 2,
- "open_type"=>$ct['open_type'],
- 'good_createrid' => $goodinfo['createrid'],
- 'good_creater' => $goodinfo['creater'],//商品创建人
- 'supplier_origin_price'=>$cgd_origin_price,//供应商采购成本
- 'cgd_supplier_code'=>$goodinfo['cgd_supplier_code'],//采购供应商编号
- 'cgd_supplier_name'=>$goodinfo['cgd_supplier_name'],//采购供应商编号
- 'cgd_apply_id'=>$goodinfo['cgd_apply_id'],//竞单人
- 'cgd_apply_name'=>$goodinfo['cgd_apply_name'],//竞单人
- ];
- $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !== "" ? $this->post['addrlist'] : "";
- $send_num = 0;
- if ($sendtype == 1) {
- if ($addrlist == "" || empty($addrlist) || !is_array($addrlist)) {
- return error_show(1004, "参数addrlist不能为空");
- }
- $send_num = array_sum(array_column($addrlist, "receipt_quantity"));
- }
- if ($send_num > $good_num) {
- return error_show(1004, "发货数量超出订单总数量");
- }
- $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
- $proof_id = isset($this->post['proof_id']) && $this->post['proof_id'] !== "" ? intval($this->post['proof_id']) : 0;
- $rm = $this->uid;
- $ri = $this->uname;
- Db::startTrans();
- try {
- $goodStock = Db::name("good")->where(["spuCode"=> $spuCode])->lock(true)->field("spuCode,usable_stock")
- ->findOrEmpty();
- if(empty($goodStock)) throw new Exception("未找到商品数据");
- $data = [
- "orderCode" => $orderCode,
- "good_code" => $spuCode,
- "skuCode" => $skuCode,
- "customer_code" => $customer_code,
- "customerName" =>$tmp['data'][$customer_code]??"",
- "good_name" => isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '' ? $goodinfo['good_name'] : '',
- "good_num" => $good_num,
- "cat_id" => $goodinfo['cat_id'],
- "apply_id" => $rm,
- "apply_name" => $ri,
- "origin_price" => $origin_price,
- "sale_price" => $sale_price,
- "post_fee" => 0,
- "status" => 0,
- "send_num" => 0,
- "wsend_num" => $good_num,
- "send_status" => 1,
- "good_type" => $goodtype,
- "send_type" => $sendtype,
- "supplierNo" => $supplierNo,
- "supplierName" => $tmp['data'][$supplierNo]??"",
- "supName" => $supplier_name,
- "supNo" => $ct['supplierNo'],
- "is_del" => 0,
- "zxNo" => "",
- "platform_order" => $platform_order,
- "platform_id" => $platform_id,
- "remark" => $remark,
- "is_stock" => $is_stock,
- "is_activity" => $is_activity === "" ? 0 : $is_activity,
- "activity_code" => $actcode,
- "order_type" => $is_stock == 1 ? 1 : 2,
- "order_source" => 1,//1直接下单
- 'good_weight' => $ct['noble_weight'],
- 'gold_price' => isset($ct['cgd_gold_price']) ? $ct['cgd_gold_price'] : 0,
- 'cost_price' => isset($good['cost_fee']) ? $good['cost_fee'] : 0,
- 'diff_weight' => 0,
- 'diff_fee' => 0,
- "workNo" => $workNo,
- "use_order"=>$this->post['useid']??0,
- 'open_type'=>$ct['open_type'],
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- 'total_price' => round($sale_price * $good_num, 2),
- 'proof_id' => $proof_id,
- 'cgderid' => $holder_id,
- 'cgder' => $holder_name,//采购员(供应商负责人)
- 'good_createrid' => $goodinfo['createrid'],
- 'good_creater' => $goodinfo['creater'],//商品创建人
- 'manager' => $manager,
- 'managerid' => $managerid,//商品创建人
- ];
- $paytime == "" ? "" : $data['paytime'] = $paytime;
- $datainfo = Db::name('sale')->insert($data, true);
- if ($datainfo > 0) {
- $taxInfo = OrderTax::SpuCat($spuCode);
- if (!empty($taxInfo)) {
- (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
- $temp=[];
- $temp['code']=$orderCode;
- $temp['spuCode']=$item['spuCode'];
- $temp['tax_code']=$item['cat_code'];
- $temp['tax_name']=$item['cat_name'];
- $temp['tax_short_name']=$item['short_name'];
- $temp['inv_tax']=$item['tax'];
- $temp['inv_good_name']=$item['inv_good_name'];
- return $temp;
- },$taxInfo));
- }
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $orderCode,//销售单code
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "XSQRD", 0, $this->post);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'XSQRD',
- "order_code" => $orderCode,//销售单code
- "order_id" => $datainfo,
- "order_status" => 0,
- "before_status" => 0,
- 'holder_id' => $data['apply_id']
- ]);
- if ($is_activity == 1) {
- $actup = [
- "activity_stock" => $act['activity_stock'] - $good_num,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $actupp = Db::name("activity_info")->where(["skuCode" => $skuCode, "activity_code" => $actcode,
- "is_del" => 0, "status" => 1])->save($actup);
- if ($actupp == false) {
- throw new Exception("活动库存修改失败");
- }
- }
- $outstatus = 0;
- $standing_book_da = ['sale_id' => $datainfo, 'customer_code' => $customer_code, 'skuCode' => $skuCode, 'updatetime' => date('Y-m-d H:i:s')];
- if ($is_stock == 0) {
- $bol = $this->createCgd($cgd, $standing_book_da);
- if ($bol == false) {
- throw new Exception("订单创建失败");
- }
- } else {
- $outstatus = 1;
- $stockUp =[
- "usable_stock"=>$goodStock['usable_stock']-$good_num,
- "updatetime"=>date("Y-m-d H:i:s"),
- ];
- $goodStockUp = Db::name("good")->where($goodStock)->update($stockUp);
- if($goodStockUp==false) throw new Exception("商品可用库存更新失败");
- SaleCgdPrice::GetPrice($datainfo);
- }
- if ($sendtype == 1) {
- $i=1;
- foreach ($addrlist as $value) {
- $temp = [];
- $addrs = [];
- if ($value['addr_code'] !== '' && is_array($value['addr_code']) && !empty($value['addr_code'])) {
- $addrs['provice_code'] = $value['addr_code'][0];
- $addrs['city_code'] = $value['addr_code'][1];
- $addrs['area_code'] = $value['addr_code'][2];
- $addr = json_encode($addrs);
- } else {
- $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
- }
- if($value['receipt_quantity']<=0) throw new Exception('地址发货数量不能小于1');
- $temp['orderCode'] = $orderCode;
- $temp['contactor'] = $value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code'] = $addr;
- $temp['customer_code'] = $customer_code;
- $temp['receipt_quantity'] = $value['receipt_quantity'];
- $temp['post_fee'] = 0;
- $temp['is_del'] = 0;
- $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $temp['arrive_time'] = $arrtime;
- $vmp = Db::name('order_addr')->insert($temp, true);
- if ($vmp > 0) {
- $num = $value['receipt_quantity'];
- $outCode = makeNo("DF");
- //改变编码规则,将原来的outCode后两位换成序列号
- //str_pad字符串填充
- $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
- $i++;
- if($is_stock!=1) {
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
- ->lock(true)->find();
- if ($order == false) {
- throw new Exception("未找到可以发货得采购单数据");
- }
- $tep = [
- "cgdNo" => $order['cgdNo'],
- "outCode" => $outCode,
- "send_num" => $num,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $sen = Db::name("order_send")->save($tep);
- if ($sen == false) {
- throw new Exception("发货地址添加创建失败");
- }
- $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
- if ($cgdinfo == false) {
- throw new Exception("未匹配到采购数据");
- }
- }
- $out = [
- "orderCode" => $orderCode,
- "outCode" => $outCode,
- "apply_id" => $rm,
- "apply_name" => $ri,
- "addrid" => $vmp,
- "post_name" => "",
- "post_code" => "",
- "post_fee" => 0,
- "sendtime" => date("Y-m-d H:i:s"),
- "send_num" => $num,
- "check_num" => 0,
- "error_num" => 0,
- "wsm_code" => $is_stock == 1 ?'':$cgdinfo['wsm_code'],
- "order_type" => $is_stock == 1 ? 1 : 2,
- "send_status" => $outstatus,
- "status" => $outstatus,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $ou = Db::name("order_out")->insertGetId($out);
- if ($ou == false) {
- throw new Exception("发货地址添加创建失败");
- // return error_show(1002, "发货地址添加创建失败");
- } else {
- if($is_stock==1) OrderOutChild::makeChild($outCode);//库存品拆单
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
- "order_code" => $outCode,//出库单号
- "status" => $out['status'],//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "CKD", $out['status'], $out);
- if($out['status']==1 ){
- //节点1待库管发货
- if($data['is_stock']==0){
- //非库存品,推给供应商负责人
- // $supp = Db::name('supplier')
- // ->field('person,personid')
- // ->where('code',$ct['supplierNo'])
- // ->findOrEmpty();
- ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], [
- "order_type" => 'CKD',
- "order_code" => $outCode,//出库单号
- "order_id" => $ou,
- "order_status" => $out['status'],
- "before_status" => $out['status'],
- 'wait_id'=>$holder_id,
- 'wait_name'=>$holder_name,
- ]);
- }else{
- //库存品,推给31库管和41库管-张凯旋
- $uids = Db::name('user_role')
- ->where(['is_del' => 0, 'roleid' => config('app.wsm_cgder_role'), 'status' => 1])
- ->column('uid');
- ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], [
- "order_type" => 'CKD',
- "order_code" => $outCode,//出库单号
- "order_id" => $ou,
- "order_status" => $out['status'],
- "before_status" => $out['status'],
- 'handle_user_list' => implode(',', $uids),
- ]);
- }
- }else{
- ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], [
- "order_type" => 'CKD',
- "order_code" => $outCode,//出库单号
- "order_id" => $ou,
- "order_status" => $out['status'],
- "before_status" => $out['status'],
- 'holder_id'=>$out['apply_id'],
- ]);
- }
- // $standing_book_da['outCode'] = $outCode;
- if (isset($standing_book_da['outCode'])) $standing_book_da['outCode'][] = $outCode;
- else $standing_book_da['outCode'] = [$outCode];
- }
- }
- else {
- throw new Exception("发货地址添加创建失败");
- // return error_show(1002, "发货地址添加创建失败");
- }
- }
- }
- //处理台账
- if (isset($standing_book_da['outCode'])) $standing_book_da['outCode'] = implode(',', $standing_book_da['outCode']);//发货单号拼接
- 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')]));
- Db::commit();
- return app_show(0, "订单创建成功", ["order_code" => $orderCode]);
- }else{
- throw new Exception("订单创建失败");
- }
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- //采购单
- public function createCgd($data, array &$standing_book_da = [])
- {
- $cgdCode = makeNo("CG");
- $wsm = Db::name("warehouse_info")->where(["supplierNo" => $data["supplierNo"], "companyNo" => $data['companyNo'], "wsm_type" => 2, "is_del" => 0])->find();
- if ($wsm == false) {
- $wsm_code = makeNo("WSM");
- $inwsm = [
- "wsm_code" => $wsm_code,
- "name" => $data['supplierName'],
- "wsm_type" => 2,
- "supplierNo" => $data['supplierNo'],
- "supplierName" => $data['supplierName'],
- "addr" => "",
- "addrs_code" => "",
- "contactor" => $data['createrid'] ,
- "contactor_name" => $data['creater'] ,
- "mobile" => "",
- "position" => "",
- "companyNo" => $data['companyNo'],
- "companyName" => $data['companyName'],
- "status" => 1,
- "is_del" => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- 'createrid' => $this->uid,
- 'creater' => $this->uname,
- 'updaterid' => $this->uid,
- 'updater' => $this->uname,
- ];
- $in = Db::name("warehouse_info")->insert($inwsm);
- if ($in == false) {
- throw new Exception("虚拟供应商仓库创建失败");
- }
- } else {
- $wsm_code = $wsm['wsm_code'];
- }
- //判断该供应商是否开通了供应商账号
- $from_tag=checkHasAccountBySupplierNos([$data['supplierNo']]);
- $cg = [
- "cgdNo" => $cgdCode,
- "bkcode" => "",
- "wsm_code" => $wsm_code,
- "cgder" => $data['creater'],
- "cgder_id" => $data['createrid'],
- "spuCode" => $data['spuCode'],
- "skuCode" => $data['skuCode'],
- "good_name" => $data['good_name'],
- "good_num" => $data['good_num'],
- "good_price" => $data['sale_price'],
- "total_fee" => round($data['sale_price'] * $data['good_num'], 2),
- "origin_total" => round($data['sale_price'] * $data['good_num'], 2),
- "pakge_fee" => $data['pakge_fee'],
- "cert_fee" => $data['cert_fee'],
- "open_fee" => $data['open_fee'],
- "teach_fee" => $data['cost_fee'],
- "mark_fee" => $data['mark_fee'],
- "demo_fee" => $data['demo_fee'],
- "nake_fee" => $data['nake_fee'],
- "weight" => $data['weight'],
- "delivery_fee" => $data['delivery_fee'],
- "gold_price" => $data['gold_price'],
- "diff_weight" => "0",
- "diff_fee" => "0",
- "supplierNo" => $data['supplierNo'],
- "supplier_name" => $data['supplierName'],
- "companyNo" => $data['companyNo'],
- "companyName" => $data['companyName'],
- "send_status" => 1,
- "send_num" => 0,
- "wsend_num" => $data['good_num'],
- "remark" => "",
- "status" => 0,//0初始化
- "lasttime" => date("Y-m-d H:i:s"),
- "is_del" => 0,
- 'open_type'=>$data['open_type'],
- "order_type" => $data['order_type'],
- "order_source" => $data['order_source'],
- "good_type" => $data['good_type'],
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- 'good_createrid' => $data['good_createrid'],
- 'good_creater' => $data['good_creater'],//商品创建人
- 'from_tag' => isset($from_tag[$data['supplierNo']]) ? 2 : 1,//来源标签:1采销(默认),2供应商端
- 'supplier_origin_price'=>$data['supplier_origin_price'],//供应商采购成本
- 'cgd_supplier_code'=>$data['cgd_supplier_code'],//采购供应商编号
- 'cgd_supplier_name'=>$data['cgd_supplier_name'],//采购供应商编号
- 'cgd_apply_id'=>$data['cgd_apply_id'],//竞单人
- 'cgd_apply_name'=>$data['cgd_apply_name'],//竞单人
- ];
- $up = Db::name("purchease_order")->insert($cg, true);
- if ($up) {
- $taxInfo = OrderTax::SpuCat($data['spuCode'],1,1);
- if (!empty($taxInfo)) {
- (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($cgdCode){
- $temp=[];
- $temp['code']=$cgdCode;
- $temp['spuCode']=$item['spuCode'];
- $temp['tax_code']=$item['cat_code'];
- $temp['tax_name']=$item['cat_name'];
- $temp['tax_short_name']=$item['short_name'];
- $temp['inv_tax']=$item['tax'];
- $temp['inv_good_name']=$item['inv_good_name'];
- return $temp;
- },$taxInfo));
- }
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $cg['cgdNo'],//销售单code
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "CGD", $cg['status'], $cg);
- //当节点是0待与供应商确认,推给供应商负责人
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'CGD',
- "order_code" => $cg['cgdNo'],//销售单code
- "order_id" => $up,
- "order_status" => $cg['status'],
- "before_status" => 0,
- 'holder_id' => $data['createrid'],
- 'wait_id'=>$data['createrid'],
- 'wait_name'=>$data['creater'],
- ]);
- $standing_book_da = array_merge($standing_book_da, [
- 'orderCode' => $data['orderCode'],
- 'cgdNo' => $cgdCode,
- 'spuCode' => $data['spuCode'],
- 'skuCode' => $data['skuCode'],
- 'order_type' => $data['order_type'],
- 'order_source' => $data['order_source'],
- 'supplierNo' => $data['supplierNo'],
- "companyNo" => $data['companyNo'],
- ]);
- $rela = [
- "orderCode" => $data['orderCode'],
- "cgdNo" => $cgdCode,
- "spuCode" => $data['spuCode'],
- "good_num" => $data['good_num'],
- "wsend_num" => $data['good_num'],
- "send_num" => 0,
- "wait_num" => 0,
- "status" => 1,
- "source" => 2
- ];
- $re = Db::name("order_num")->save($rela);
- if ($re == false) {
- throw new Exception("采购单销售单关联失败");
- } else {
- $stokc = Db::name("good_stock")->where(['spuCode' => $data['spuCode'], "wsm_code" => $wsm_code, "is_del" => 0])->find();
- if ($stokc == false) {
- $stokc = [
- "spuCode" => $data['spuCode'],
- "wsm_code" => $wsm_code,
- "wait_in_stock" => $data['good_num'],
- "wait_out_stock" => 0,
- "usable_stock" => 0,
- "intra_stock" => 0,
- "total_stock" => 0,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- } else {
- $stokc['wait_in_stock'] += $data['good_num'];
- $stokc['updatetime'] = date("Y-m-d H:i:s");
- }
- $stoc = Db::name("good_stock")->save($stokc);
- if ($stoc == false) {
- throw new Exception("商品待入库存更新失败");
- }
- $good_data[] = ['good_log_code' => $cgdCode, "stock_id" => isset($stoc['id']) ? $stoc['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1,
- 'stock' => $data['good_num'], "stock_name" => "wait_in_stock"];
- GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname], $good_data, "CGD");
- return true;
- }
- } else {
- throw new Exception("采购单生成失败");
- }
- }
- public function addAddr()
- {
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
- $etid = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->find();
- if (empty($etid)) {
- return error_show(1002, "未找到数据");
- }
- $retrun = Db::name("sale_return")->where([["orderCode", "=", $orderCode], ["is_del", "=", 0], ["status", "in", [1, 2, 3,
- 7, 9,8, 10, 11, 12]]])->count('id');
- if ($retrun > 0) {
- return error_show(1005, "存在未完成退货订单数据");
- }
- $arrtime = isset($this->post['arrtime']) && $this->post['arrtime'] != "" ? $this->post['arrtime'] : "";
- $rm = $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri = $this->uname;//isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !== "" ? $this->post['addrlist'] : "";
- if ($addrlist == "" || empty($addrlist) || !is_array($addrlist)) {
- return error_show(1004, "参数addrlist不能为空");
- }
- Db::startTrans();
- try {
- $i = 1;
- $total_num = array_sum(array_column($addrlist, "receipt_quantity"));
- $goodStock_num = Db::name('good_stock')->alias("a")
- ->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")
- ->where(['a.is_del' => 0, 'a.spuCode' =>$etid['good_code'],"b.wsm_type"=>[2,5]])->sum('usable_stock');
- if ($goodStock_num < $total_num && $etid['is_stock'] == 1) throw new Exception("库存品库存数不足发货");
- foreach ($addrlist as $value) {
- $temp = [];
- $addrs = [];
- if ($value['addr_code'] !== '' && is_array($value['addr_code']) && !empty($value['addr_code'])) {
- $addrs['provice_code'] = $value['addr_code'][0];
- $addrs['city_code'] = $value['addr_code'][1];
- $addrs['area_code'] = $value['addr_code'][2];
- $addr = json_encode($addrs);
- } else {
- $addr = isset($value['addr_code']) && $value['addr_code'] !== '' ? $value['addr_code'] : '';
- }
- if($value['receipt_quantity']<=0) throw new Exception('地址发货数量不能小于1');
- $temp['orderCode'] = $orderCode;
- $temp['contactor'] = $value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code'] = $addr;
- $temp['customer_code'] = $etid['customer_code'];
- $temp['receipt_quantity'] = $value['receipt_quantity'];
- $temp['post_fee'] = 0;
- $temp['is_del'] = 0;
- $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- if ($arrtime != "") {
- $temp['arrive_time'] = $arrtime;
- }
- $vmp = Db::name('order_addr')->insert($temp, true);
- if ($vmp > 0) {
- $num = $value['receipt_quantity'];
- $outCode = makeNo("DF");
- //改变编码规则,将原来的outCode后两位换成序列号
- //str_pad字符串填充
- $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
- $i++;
- //维护商品所在仓库的库存 --- start
- if ($etid['is_stock'] != 1) {
- //查找关联采购单
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->findOrEmpty();
- if (empty($order)) {
- throw new Exception("未找到可以发货得采购单数据");
- }
- $tep = [
- "cgdNo" => $order['cgdNo'],
- "outCode" => $outCode,
- "send_num" => $num,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $sen = Db::name("order_send")->save($tep);
- if ($sen == false) {
- throw new Exception("发货地址添加创建失败");
- }
- $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
- if ($cgdinfo == false) {
- throw new Exception("采购单数据不存在");
- }
- if ($goodStock_num == 0) {
- $status = 0;
- } else {
- if (($goodStock_num - $num) < 0) throw new Exception("非库存品可用库存不足");
- $goodStock_num -= $num;
- $status = 1;
- }
- } else {
- if ($goodStock_num == 0 || ($goodStock_num - $num) < 0) throw new Exception("库存品可用库存不足");
- $goodStock_num -= $num;
- $status = 1;
- }
- $out = [
- "orderCode" => $orderCode,
- "outCode" => $outCode,
- "apply_id" => $rm,
- "apply_name" => $ri,
- "addrid" => $vmp,
- "post_name" => "",
- "post_code" => "",
- "post_fee" => 0,
- "sendtime" => date("Y-m-d H:i:s"),
- "send_num" => $num,
- "check_num" => 0,
- "error_num" => 0,
- "wsm_code" => $cgdinfo['wsm_code'] ?? '',
- "order_type" => $etid['order_type'],
- "send_status" => $status,
- "status" => $status,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $ou = Db::name("order_out")->insertGetId($out);
- if ($ou == false) throw new Exception("发货单创建失败");
- else {
- if ($out['send_status'] == 1) OrderOutChild::makeChild($outCode);
- //修改状态,添加待办
- // ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
- // "order_code" => $outCode,//出库单号
- // "status" => 0,//这里的status是之前的值
- // "action_remark" => '',//备注
- // "action_type" => "create"//新建create,编辑edit,更改状态status
- // ], "CKD", 0, $out);
- //区分是否是库存品订单
- $process = [];
- // if($status == 1){
- // //库存品,推给库管和库管-张凯旋
- // if($etid['is_stock']==1){
- // $roleid = config('app.wsm_cgder_role');
- // $uids = Db::name('user_role')
- // ->where('is_del', 0)
- // ->whereIn('roleid', $roleid)
- // ->column('uid');
- // $process=[
- // "order_type" => 'CKD',
- // "order_code" => $outCode,//出库单号
- // "order_id" => $ou,
- // "order_status" => $status,
- // "before_status" => 0,
- //// 'holder_id'=>$out['apply_id'],
- // 'handle_user_list' => implode(',', $uids)
- // ];
- // }else{
- // //推给供应商负责人
- //// $supplier = Db::name('supplier')
- //// ->field('person,personid')
- //// ->where('code',$cgdinfo['supplierNo'])
- //// ->findOrEmpty();
- //
- // $supplier_temp =$userCommon->handle("sInfo",["code"=>$cgdinfo['supplierNo']]);
- // if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"采购单供应商不存在");
- // $holder_id=$supplier_temp['data']['personid']??0;
- // $holder_name=$supplier_temp['data']['person']??'';
- // $supplier_name=$supplier_temp['data']['name']??'';
- // $process = [
- // "order_type" => 'CKD',
- // "order_code" => $outCode,//出库单号
- // "order_id" => $ou,
- // "order_status" => $status,
- // "before_status" => 0,
- // 'wait_id'=>$holder_id,
- // 'wait_name'=>$holder_name,
- // 'holder_id'=>$holder_id,
- // ];
- // }
- // }
- // if(empty($process)) $process=[
- // "order_type" => 'CKD',
- // "order_code" => $outCode,//出库单号
- // "order_id" => $ou,
- // "order_status" => $status,
- // "before_status" => 0,
- // 'holder_id'=>$out['apply_id'],
- // ];
- //
- // ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri],$process);
- //处理台账-既然是根据orderCode更新的数据,那么肯定是有数据的,只需要更新就行了
- Db::execute("UPDATE `wsm_standing_book` SET `outCode`=CONCAT(IFNULL(`outCode`,''),',{$outCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `orderCode`='{$orderCode}'");
- }
- //维护商品所在仓库的库存 --- end
- } else {
- Db::rollback();
- return error_show(1002, "发货地址添加创建失败");
- }
- }
- // $usable = $GoodModel->where($goodStock)->update(["usable_stock"=>$goodStock_num,"updatetime"=>date("Y-m-d H:i:s")]);
- // if($usable==false) throw new Exception("商品可用库存数更新失败");
- Db::commit();
- return app_show(0, "发货地址添加完成");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1002, $e->getMessage());
- }
- }
- public function consultOrder()
- {
- $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] != "" ? trim($this->post['bidNo']) : "";
- if ($bidNo == "") {
- return error_show(1003, "参数bidNo不能为空");
- }
- $zxinfo = Db::name("consult_bids")->where(["bidNo" => $bidNo, "is_del" => 0])->find();
- if ($zxinfo == false) {
- return error_show(1003, "未找到咨询单商品信息");
- }
- if ($zxinfo['tax_status'] !=1) {
- return error_show(1003, "咨询单商品财务未审核通过");
- }
- $bargaininfo =Db::name("bargain_order")->where(["bidsNo" => $bidNo,"is_del"=>0,"status"=>0])->findOrEmpty();
- $zx = Db::name("consult_info")->where(["infoNo" => $zxinfo['infoNo'], "is_del" => 0])->find();
- if ($zx == false) {
- return error_show(1003, "未找到咨询单信息");
- }
- $manager = isset($this->post['manager']) && $this->post['manager'] != '' ? $this->post['manager'] :$this->uname;
- $managerid = isset($this->post['managerid']) && $this->post['managerid'] != '' ? $this->post['managerid'] :$this->uid;
- $zxorder = Db::name("consult_order")->where(["zxNo" => $zx["zxNo"], "is_del" => 0])->find();
- if ($zxorder == false) {
- return error_show(1003, "未找到咨询单信息");
- }
- $good_num = isset($this->post['good_num']) && $this->post['good_num'] != "" ? intval($this->post['good_num']) : "";
- if ($good_num === "") {
- return error_show(1003, "参数 good_num 不能为空");
- }
- $sale_price = isset($this->post['sale_price']) && $this->post['sale_price'] != "" ? floatval($this->post['sale_price']) : "";
- if ($sale_price === "") {
- return error_show(1003, "参数 sale_price 销售单价 不能为空");
- }
- if ($sale_price < $zxinfo['sale_price']) {
- return error_show(1003, "修改的销售单价不能低于原来的销售单价");
- }
- $goodtype = isset($this->post['goodtype']) && $this->post['goodtype'] !== '' ? intval($this->post['goodtype']) : '1';
- $sendtype = isset($this->post['sendtype']) && $this->post['sendtype'] != "" ? intval($this->post['sendtype']) : "";
- if ($sendtype == "") {
- return error_show(1003, "参数sendtype不能为空");
- }
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] != "" ? trim($this->post['companyNo']) : "";
- if ($companyNo == "") {
- return error_show(1003, "参数 companyNo 不能为空");
- }
- $userCommon = \app\admin\common\User::getIns();
- // }
- $remark = isset($this->post['remark']) && $this->post['remark'] != "" ? trim($this->post['remark']) : "";
- $tmp = $userCommon->handle('sInfo',['code'=>$zxinfo['supplierNo']]);
- if(!isset($tmp['code']) || $tmp['code']!=0) return json_show($tmp['code'],$tmp['message'],$tmp['data']);
- $companyinfo = $userCommon->handle('getCodeAndName',['code'=>[$companyNo,$zxorder['khNo']]]);
- if(!isset($companyinfo['code']) || $companyinfo['code']!=0) return json_show($companyinfo['code'],$companyinfo['message'],$companyinfo['data']);
- $supplier_temp_info = $tmp['data'];
- $platforminfo = Db::name("platform")->where(["id"=> $zxorder['platform_code'],"is_del"=>0])->findOrEmpty();
- if (empty($platforminfo)) return error_show(1004, "平台信息未找到");
- if ($platforminfo['status'] != 1) return error_show(1004, "平台信息已禁用");
- if($platforminfo['is_select_pay_rate']==1 && channel_is_company($zxorder['platform_code'],$companyNo))return error_show(1004, "平台渠道含有 {$companyinfo['data'][$companyNo]}");
- $orderCode = makeNo("QR");
- $spuCode = $zxinfo['spuCode'];
- $skuCode = "";
- $is_stock = 0;
- $cgd = [
- "supplierNo" => $zxinfo['supplierNo'],
- "supplierName" => $supplier_temp_info['name'],
- "companyNo" => $companyNo,
- "companyName" => $companyinfo['data'][$companyNo]??"",
- "spuCode" => $spuCode,
- "skuCode" => $skuCode,
- "orderCode" => $orderCode,
- "good_name" => $zxinfo['good_name'],
- "sale_price" => $zxinfo['total_fee'],
- "total_fee" => round($zxinfo['total_fee'] * $good_num, 2),
- "pakge_fee" => $zxinfo['pakge_fee'],
- "cert_fee" => $zxinfo['cert_fee'],
- "open_fee" => $zxinfo['open_fee'],
- "cost_fee" => $zxinfo['cost_fee'],
- "mark_fee" => $zxinfo['mark_fee'],
- "demo_fee" => $zxinfo['demo_fee'],
- "nake_fee" => $zxinfo['nake_fee'],
- "delivery_fee" => $zxinfo['delivery_fee'],
- "good_num" => $good_num,
- "createrid" =>$supplier_temp_info['personid'],
- "creater" =>$supplier_temp_info['person'],
- "good_type" => 1,
- "open_type"=>$zxinfo["open_type"],
- "weight" => $zxinfo['good_weight'],
- "gold_price" => $zxinfo['gold_price'],
- "is_diff" => $zxinfo['is_diff'],
- "order_type" => 3,
- "order_source" => 2,//咨询
- 'send_way' => $zxinfo['send_way'],
- 'good_createrid' => $zxinfo['createrid'],
- 'good_creater' => $zxinfo['creater'],//商品创建人id
- 'supplier_origin_price'=>$zxinfo['supplier_origin_price'],//供应商采购成本
- 'cgd_supplier_code'=>$zxinfo['cgd_supplier_code'],//采购供应商编号
- 'cgd_supplier_name'=>$zxinfo['cgd_supplier_name'],//采购供应商编号
- 'cgd_apply_id'=>$zxinfo['cgd_apply_id'],//竞单人
- 'cgd_apply_name'=>$zxinfo['cgd_apply_name'],//竞单人
- ];
- $rm = $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri = $this->uname;//isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- $va = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
- $send_num = 0;
- if ($sendtype == 1) {
- if ($va == "") {
- return error_show(1002, "参数order_addr不能为空");
- }
- $send_num = array_sum(array_column($va, "receipt_quantity"));
- }
- if ($good_num < $send_num) {
- return error_show(1002, "发货数量不能超过购买数量");
- }
- $arrtime = isset($this->post['arrtime']) && $this->post['arrtime'] != "" ? $this->post['arrtime'] : "";
- if ($arrtime == "") {
- return error_show(1002, "参数arrtime不能为空");
- }
- //新加字段
- $platform_order = isset($this->post['platform_order']) && $this->post['platform_order'] != "" ? $this->post['platform_order'] : "";
- $workNo = isset($this->post['workNo']) && $this->post['workNo'] != "" ? $this->post['workNo'] : "";
- $proof_type = isset($this->post['proof_type']) && $this->post['proof_type'] != "" ? intval($this->post['proof_type']) : 0;
- $proof_url = isset($this->post['proof_url']) && $this->post['proof_url'] != "" ? trim($this->post['proof_url']) : '';
- if($proof_url=="")return error_show(1002, '参数 proof_url 不能为空');
- if($proof_type==0)return error_show(1002, '参数 proof_type 不能为空');
- Db::startTrans();
- try {
- $zx = Db::name("consult_info")->where(["infoNo" => $zxinfo['infoNo'], "is_del" => 0])->lock(true)->find();
- if ($zx == false) {
- Db::rollback();
- return error_show(1003, "未找到咨询单信息");
- }
- if ($companyNo != $zxorder['companyNo']) {
- $zxord = Db::name("consult_order")->where($zxorder)->update(["companyNo" => $companyNo, "updatetime" => date("Y-m-d H:i:s")]);
- if ($zxord == false) {
- Db::rollback();
- return error_show(1003, "咨询单更新业务公司失败");
- }
- }
- if(!empty($bargaininfo)){
- $bargaininfo['status']=4;
- $bargaininfo['updatetime']=date("Y-m-d H:i:s");
- $branip =Db::name("bargain_order")->save($bargaininfo);
- if($branip==false) throw new Exception("未完成的议价单取消失败");
- }
- $bidsup =[
- "status"=>6,
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $updateinfp =Db::name("consult_bids")->where(["bidNo" => $bidNo, "is_del" => 0])->update($bidsup);
- if($updateinfp==false) throw new Exception("反馈单转单失败");
- $data = [
- "orderCode" => $orderCode,
- "good_code" => $spuCode,
- "skuCode" => $skuCode,
- "customer_code" => $zxorder['khNo'],
- "customerName" => $companyinfo['data'][$zxorder['khNo']]??"",
- "good_name" => isset($zxinfo['good_name']) && $zxinfo['good_name'] !== '' ? $zxinfo['good_name'] : '',
- "good_num" => $good_num,
- "cat_id" => $zxinfo['cat_id'],
- "apply_id" => $rm,
- "apply_name" => $ri,
- "origin_price" => $zxinfo['total_fee'],
- "sale_price" => $sale_price,//销售单价支持修改
- "post_fee" => 0,
- "status" => 0,
- "send_num" => 0,
- "wsend_num" => $good_num,
- "send_status" => 1,
- "good_type" =>$goodtype,
- "send_type" => $sendtype,
- "supplierNo" => $companyNo,
- "supplierName" =>$companyinfo['data'][$companyNo]??"",
- "is_del" => 0,
- "supNo" => $zxinfo['supplierNo'],
- "supName" =>$supplier_temp_info['name'],
- "zxNo" => $bidNo,
- "platform_order" => $platform_order,
- "platform_id" => $zxorder['platform_code'],
- "remark" => $remark,
- "arrive_time" => $arrtime,
- "is_stock" => 0,
- "is_activity" => 0,
- "activity_code" => '',
- "proof_id" => 0,
- "order_type" => 3,
- "order_source" => 2,//2咨询
- 'good_weight' => $zxinfo['good_weight'],
- 'gold_price' => $zxinfo['gold_price'],
- 'cost_price' => $zxinfo['sale_cost_fee'],
- 'diff_weight' => 0,
- 'open_type'=>$zxinfo['open_type'],
- 'diff_fee' => 0,
- 'use_order'=>$this->post['useid']??0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- 'total_price' => round($sale_price * $good_num, 2),
- 'workNo' => $workNo,
- 'cgderid' => $supplier_temp_info['personid'],
- 'cgder' => $supplier_temp_info['person'],//采购员(采购单对应的供应商负责人)
- 'good_createrid' => $zxinfo['createrid'],
- 'good_creater' => $zxinfo['creater'],//商品创建人id
- "manager"=>$manager,
- "managerid"=>$managerid,
- ];
- $datainfo = Db::name('sale')->insert($data, true);
- if ($datainfo > 0) {
- $standing_book_data = [
- 'sale_id' => $datainfo,
- 'infoNo' => $zxinfo['infoNo'],
- 'updatetime' => date('Y-m-d H:i:s')
- ];
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $orderCode,//销售单code
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "XSQRD", $data['status'], $data);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'XSQRD',
- "order_code" => $orderCode,//销售单code
- "order_id" => $datainfo,
- "order_status" => $data['status'],
- "before_status" => 0,
- 'holder_id' => $data['apply_id'],
- ]);
- $old_zx_status = $zx['status'];
- $sa = Db::name("consult_info")->where($zx)->save(["status" => 5, "updatetime" => date("Y-m-d H:i:s")]);
- if ($sa == false) {
- Db::rollback();
- return error_show(1002, "咨询单修改失败");
- } else {
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $zx['infoNo'],//咨询单详情编号
- "status" => $old_zx_status,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "ZXD", 5, $zx);
- }
- $limt = [
- "spuCode" => $zxinfo['spuCode'],
- "good_name" => $zxinfo['good_name'],
- "brand_id" => $zxinfo['brand_id'],
- "good_unit" => $zxinfo['unit_id'],
- "cat_id" => $zxinfo['cat_id'],
- "good_type" => 0,
- "moq" => 1,
- "customized" => $zxinfo['work_day'],
- "tax" => $zxinfo['tax'],
- "supplierNo" => $zxinfo["supplierNo"],
- "supplierName" =>$supplier_temp_info['name'],
- "is_auth" => 0,
- "craft_desc" => $zxinfo['good_name'],
- "good_remark" => "",
- "platform_id" => $zxorder['platform_id'],
- "good_img" => $zxinfo['good_img'],
- "good_thumb_img" => "",
- "good_info_img" => "",
- "specinfo" => $zxinfo['specinfo'],
- "work_day" => $zxinfo['work_day'],
- "noble_metal" => $zxinfo['metal_id'],
- "is_gold_price" => $zxinfo['is_gold_price'],
- "config" => $zxinfo['config'],
- "other_config" => $zxinfo['other_config'],
- "weight" => $zxinfo['weight'],
- "good_weight" => $zxinfo['good_weight'],
- "is_diff" => $zxinfo['is_diff'],
- "supply_area" => $zxinfo['supply_area'],
- "pay_way" => $zxinfo['pay_way'],
- "send_way" => $zxinfo['send_way'],
- "companyNo" => $companyNo,
- "companyName" =>$companyinfo['data'][$companyNo]??"",
- 'sale_price' => $sale_price,
- "status" => 1,
- "is_combind" => $zxinfo['is_combind'],
- "open_type"=>$zxinfo['open_type'],
- "is_del" => 0,
- 'order_type' => 3,
- 'order_source' => 2,
- "createrid" => $zxinfo['createrid'],
- "creater" => $zxinfo['creater'],
- "order_createrid" => $this->uid,
- "order_creater" => $this->uname,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- 'proof_type' => $proof_type,//凭证类型
- 'proof_url' => $proof_url,//凭证文件
- ];
- $good = Db::name("good_zixun")->insert($limt);
- if (!$good) {
- Db::rollback();
- return error_show(1006, "咨询商品录入失败");
- }
-
- if($zxinfo['is_combind']==1){
- $marage=[
- "parent_code"=>$zxinfo['spuCode'],
- "parent_name"=>$zxinfo['good_name'],
- 'order_type' => 3,
- 'order_source' => 2,
- 'good_type' => 0,
- 'moq' => 1,
- 'good_thumb_img' => '',
- 'good_info_img' => '',
- "is_auth" => 0,
- 'good_remark' => '',
- 'createrid' => $zxinfo['createrid'],
- 'creater' => $zxinfo['creater'],
- 'order_createrid' => $this->uid,
- 'order_creater' => $this->uname,
- 'proof_type' => $proof_type,//凭证类型
- 'proof_url' => $proof_url,//凭证文件
- 'platform_id' => $zxorder['platform_id'],
- ];
- (new ConsultTemp())->CreateGood($zxinfo['bidNo'],$marage);
- }
- if($zxinfo['open_type']==1|| $zxinfo['tax_id']>0){
- $data = [
- 'spuCode'=>$zxinfo['spuCode'],
- 'companyNo'=>$companyNo,
- 'tax_id'=>$zxinfo['tax_id'],
- 'inv_good_name'=>$zxinfo['inv_good_name'],
- 'open_type'=>$zxinfo['open_type'],
- 'tax'=>$zxinfo['tax'],
- "out_tax_id"=>$zxinfo['out_tax_id'],
- 'out_tax'=> str_replace("%","",$zxinfo['out_tax']),
- 'cgd_tax_id'=>$zxinfo['cgd_tax_id'],
- 'cgd_tax'=>str_replace('%','',$zxinfo['cgd_tax']),
- "status"=>2,
- 'createrid' => $zxinfo['createrid'],
- 'creater' => $zxinfo['creater'],
- ];
- GoodTax::create($data);
- }
- $taxInfo = OrderTax::SpuCat($spuCode);
- if (!empty($taxInfo)) {
- (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
- $temp=[];
- $temp['code']=$orderCode;
- $temp['spuCode']=$item['spuCode'];
- $temp['tax_code']=$item['cat_code'];
- $temp['tax_name']=$item['cat_name'];
- $temp['tax_short_name']=$item['short_name'];
- $temp['inv_tax']=$item['tax'];
- $temp['inv_good_name']=$item['inv_good_name'];
- return $temp;
- },$taxInfo));
- }
- $bol = $this->createCgd($cgd, $standing_book_data);
- if ($bol == false) {
- Db::rollback();
- return error_show(1002, '咨询订单创建失败');
- }
- if (!empty($va)) {
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
- ->find();
- if ($order == false) {
- Db::rollback();
- return error_show(1006, "采购单关联数据未找到");
- }
- $i = 1;
- foreach ($va as $value) {
- $temp = [];
- $addrs = [];
- if ($value['addr_code'] !== '' && is_array($value['addr_code']) && !empty($value['addr_code'])) {
- $addrs['provice_code'] = $value['addr_code'][0];
- $addrs['city_code'] = $value['addr_code'][1];
- $addrs['area_code'] = $value['addr_code'][2];
- $addr = json_encode($addrs);
- } else {
- $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
- }
-
- if($value['receipt_quantity']<=0) throw new Exception("地址发货数量不能小于1");
- $temp['orderCode'] = $orderCode;
- $temp['contactor'] = $value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code'] = $addr;
- $temp['customer_code'] = $zxorder['khNo'];
- $temp['receipt_quantity'] = $value['receipt_quantity'];
- $temp['post_fee'] = 0;
- $temp['is_del'] = 0;
- $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $temp['arrive_time'] = $arrtime;
- $vmp = Db::name('order_addr')->insert($temp, true);
- if ($vmp > 0) {
- $outCode = makeNo("DF");
- //改变编码规则,将原来的outCode后两位换成序列号
- //str_pad字符串填充
- $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
- $i++;
- $out = [
- "orderCode" => $orderCode,
- "outCode" => $outCode,
- "apply_id" => $rm,
- "apply_name" => $ri,
- "addrid" => $vmp,
- "post_name" => "",
- "post_code" => "",
- "post_fee" => 0,
- "sendtime" => date("Y-m-d H:i:s"),
- "send_num" => $value['receipt_quantity'],
- "check_num" => 0,
- "error_num" => 0,
- "wsm_code" => "",
- "order_type" => 3,
- "status" => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $ou = Db::name("order_out")->insertGetId($out);
- if ($ou == false) {
- Db::rollback();
- return error_show(1002, "发货地址添加创建失败");
- } else {
- // OrderOutChild::makeChild($outCode); //非库存品下单无法立即分单
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
- "order_code" => $outCode,//出库单号
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "CKD", 0, $out);
- ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], [
- "order_type" => 'CKD',
- "order_code" => $outCode,//出库单号
- "order_id" => $ou,
- "order_status" => 0,
- "before_status" => 0,
- 'holder_id'=>$out['apply_id'],
- 'wait_id'=>$supplier_temp_info['personid'],
- 'wait_name'=>$supplier_temp_info['person'],
- ]);
- //将发货编号添加到台账中
- $standing_book_data['outCode'][] = $outCode;
- }
- $tep = [
- "cgdNo" => $order['cgdNo'],
- "outCode" => $outCode,
- "send_num" => $value['receipt_quantity'],
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $sen = Db::name("order_send")->save($tep);
- if ($sen == false) {
- Db::rollback();
- return error_show(1002, "发货地址添加创建失败");
- }
- } else {
- Db::rollback();
- return error_show(1002, "发货地址添加创建失败");
- }
- }
- }
- //处理台账
- if (isset($standing_book_data['outCode'])) {
- 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']}'");
- unset($standing_book_data['outCode']);
- }
- Db::name('standing_book')->where('infoNo', $standing_book_data['infoNo'])->update($standing_book_data);
- Db::commit();
- return error_show(0, "咨询订单创建成功", ["order_code" => $orderCode]);
- }
- Db::rollback();
- return error_show(1002, "咨询订单创建失败");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1003, $e->getMessage());
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function projectCreate()
- {
- $planNo = isset($this->post['planNo']) && $this->post['planNo'] != "" ? trim($this->post['planNo']) : "";
- if ($planNo == "") {
- return error_show(1004, "参数planNo不能为空");
- }
- $plan = Db::name("project_plan")->where(["planNo" => $planNo, "is_del" => 0])->find();
- if ($plan == false) {
- return error_show(1004, "未找到方案信息");
- }
- $feedbackid = Db::name("project_plan_rela")->where(["planNo" => $planNo, "is_del" => 0])->column("feedback_id,sale_price,sale_num");
- if ($feedbackid == false) {
- return error_show(1004, "未找到方案反馈信息");
- }
- $project = Db::name("project")->where(["projectNo" => $plan['projectNo'], "is_del" => 0])->find();
- if ($project == false) {
- return error_show(1004, "未找到方案信息");
- }
- $arrtime = isset($this->post['arrtime']) && $this->post['arrtime'] != "" ? $this->post['arrtime'] : "";
- if ($arrtime == "") {
- return error_show(1002, "参数arrtime不能为空");
- }
- $planinfo = isset($this->post['planinfo']) && !empty($this->post['planinfo']) ? $this->post['planinfo'] : "";
- if ($planinfo == "") {
- return error_show(1002, "参数planinfo不能为空");
- }
- $userCommon = \app\admin\common\User::getIns();
- $names = $userCommon->handle('getCodeAndName', ['code' =>[$project['companyNo'],$project['khNo']]]);
- if($names['code']!=0 || empty($names['data']) ) return error_show($names['code'],$names['message']);
- $platforminfo = Db::name("platform")->where(["id"=> $project['platform_id'],"is_del"=>0])->findOrEmpty();
- if (empty($platforminfo)) return error_show(1004, "平台信息未找到");
- if ($platforminfo['status'] != 1) return error_show(1004, "平台信息已禁用");
- if($platforminfo['is_select_pay_rate']==1 && channel_is_company($project['platform_id'],$project['companyNo']))return error_show(1004, "平台渠道含有 {$names['data'][$project['companyNo']]}");
- $rm = $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri = $this->uname;//isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- $manager = isset($this->post['manager']) && $this->post['manager'] != '' ? $this->post['manager'] :$this->uname;
- $managerid = isset($this->post['managerid']) && $this->post['managerid'] != '' ? $this->post['managerid'] :$this->uid;
- Db::startTrans();
- try {
- $plan = Db::name("project_plan")->where(["planNo" => $planNo, "is_del" => 0])->lock(true)->find();
- if ($plan == false) {
- throw new Exception("未找到方案信息");
- // return error_show(1004, "未找到方案信息");
- }
- $feedid = array_column($feedbackid, "feedback_id");
- $feedbacks = Db::name("project_feedback")
- ->where(["id" => $feedid, "projectNo" => $plan['projectNo'], "is_del" => 0])
- ->column("*","id");
- foreach ($planinfo as $key => $value) {
- $good = [];
- $feedback = $feedbacks[$value['feedback_id']]??[];
- if (empty($feedback)) {
- throw new Exception("反馈数据未找到");
- // return error_show(1002, "反馈数据未找到");
- }
- $key = array_search($feedback['id'], $feedid);
- $price = $feedbackid[$key];
- $good['spuCode'] = $feedback['spuCode'];
- $good['skuCode'] = $feedback['skuCode'];
- $good['good_num'] = $price['sale_num'];
- $good['sendtype'] = $value['sendtype'];
- $good['sale_price'] = $price['sale_price'];
- $good['origin_price'] = $feedback['origin_price'];
- $good['companyNo'] = $project['companyNo'];
- $good['companyName'] =$names['data'][$project['companyNo']]??'';
- $good['customerNo'] = $project['khNo'];
- $good['customerName'] =$names['data'][$project['khNo']]??'';
- $good['pgNo'] = $feedback['pgNo'];
- $good['platform_id'] = $project['platform_id'];
- $good['arrtime'] = $arrtime;
- $good['rm'] = $rm;
- $good['ri'] = $ri;
- $good['use_order']=$this->post['useid']??0;
- $good['manager'] = $manager;
- $good['managerid'] = $managerid;
- $good['send_num'] = 0;
- $standing_book_data = ['projectNo' => $plan['projectNo'], 'updatetime' => date('Y-m-d H:i:s')];
- if ($value['sendtype'] == 1) {
- if (!isset($value['addrlist']) || empty($value['addrlist'])) {
- throw new Exception("订单地址不能为空");
- // return error_show(1002, "订单地址不能为空");
- }
- $good['addrlist'] = $value['addrlist'];
- $good['send_num'] = array_sum(array_column($value['addrlist'], "receipt_quantity"));
- }
- if ($feedback['data_source'] == 1) {
- $feed = $this->project_good($good, $standing_book_data);
- if ($feed !== true) {
- throw new Exception("订单生成失败");
- // return error_show(1002, $msg);
- }
- } else {
- $feed = $this->project_zx($good, $standing_book_data);
- if ($feed == false) {
- throw new Exception("咨询订单生成失败");
- // return error_show(1002, "咨询订单生成失败");
- }
- }
- $old_fk_status = $feedback['status'];
- $fed = Db::name("project_feedback")->where($feedback)->save(['status' => 2, "updatetime" => date("Y-m-d H:i:s")]);
- if ($fed == false) {
- throw new Exception("项目反馈更新失败");
- // return error_show(1002, "项目订单生成失败");
- }
- //处理台账(一个项目会生成多个销售订单,第一个更新,其余的新增)
- //项目创建时已有供应商和企业,不能修改
- if (isset($standing_book_data['companyNo'])) unset($standing_book_data['companyNo']);
- if (isset($standing_book_data['customer_code'])) unset($standing_book_data['customer_code']);
- if (isset($standing_book_data['outCode'])) $standing_book_data['outCode'] = implode(',', $standing_book_data['outCode']);
- //普通商品
- if ($feedback['data_source'] == 1) {
- if ($key == 0) Db::name('standing_book')->where('projectNo', $plan['projectNo'])->update($standing_book_data);
- else {
- $temp = Db::name('standing_book')->where('projectNo', $plan['projectNo'])->find();
- if (!empty($temp)) {
- unset($temp['id']);
- $temp = array_merge($temp, $standing_book_data);
- $temp['standBookNo'] = makeNo('IO');
- Db::name('standing_book')->insert($temp);
- }
- }
- } else {
- //项目类竞价单
- Db::name('standing_book')->where(['projectNo' => $plan['projectNo'], 'infoNo' => $standing_book_data['infoNo']])->update($standing_book_data);
- }
- }
- $old_plan_status = $plan['status'];
- // $plan['status']=2;
- // $plan['updatetime']=date("Y-m-d H:i:s");
- $in = Db::name("project_plan")->where($plan)->save(['status' => 2, "updatetime" => date("Y-m-d H:i:s")]);
- if ($in == false) {
- throw new Exception("项目方案状态更新失败");
- // return error_show(1002, "项目订单生成失败");
- } else {
- //修改状态,添加待办,只记录动作
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $planNo,//编码
- "status" => $old_plan_status,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "edit"//新建create,编辑edit,更改状态status
- ], "PRP", 2, $plan);
- }
- $old_project_status = $project["status"];
- // $project["status"]=6;
- // $project['updatetime']=date("Y-m-d H:i:s");
- $pr = Db::name("project")->where($project)->save(["updatetime" => date("Y-m-d H:i:s"), "status" => 6]);
- if ($pr == false) {
- throw new Exception("项目状态更新失败");
- // return error_show(1002, "项目订单生成失败");
- } else {
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $project['projectNo'],//项目编码
- "status" => $old_project_status,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "PRO", 6, $project);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'PRO',
- "order_code" => $project['projectNo'],
- "order_id" => $project['id'],
- "order_status" => 6,
- "before_status" => $old_project_status,
- 'holder_id'=>$project['createrid']
- ]);
- }
- //修改状态,添加待办,只记录动作
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $project['projectNo'],//编码,这里是project的编码
- "status" => 1,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "PRT", 2, $this->post);
- $process = ["order_code" => $project['projectNo'], "order_id" => $project['id'], "order_status" => 2, "order_type" => "PRT", "before_status" => 1];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $process);
- Db::commit();
- return app_show(0, "咨询订单生成成功");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1002, $e->getMessage());
- }
- }
- /**
- * @param $data
- * @return false
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- *
- */
- public function project_zx($data, array &$standing_book_data = [])
- {
- $goodinfo = Db::name("consult_bids")->where(["spuCode" => $data['spuCode'], "is_del" => 0])->find();
- if ($goodinfo == false) {
- throw new Exception("咨询商品未找到");
- }
- if ($goodinfo['status'] !=7) {
- throw new Exception('咨询单商品财务未审核');
- }
- $bargaininfo =Db::name("bargain_order")->where(["bidsNo" => $goodinfo["bidNo"],"is_del"=>0,"status"=>0])
- ->findOrEmpty();
- if(!empty($bargaininfo)){
- $bargaininfo['status']=4;
- $bargaininfo['updatetime']=date("Y-m-d H:i:s");
- $branip =Db::name("bargain_order")->save($bargaininfo);
- if($branip==false) throw new Exception("未完成的议价单取消失败");
- }
- $orderCode = makeNo("QR");
- $userCommon= \app\admin\common\User::getIns();
- $supplier_temp =$userCommon->handle("sInfo",["code"=>$goodinfo['supplierNo']]);
- if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception("采购单供应商不存在");
- $holder_id=$supplier_temp['data']['personid']??0;
- $holder_name=$supplier_temp['data']['person']??'';
- $supplierName=$supplier_temp['data']['name']??'';
- $cgd = [
- "supplierNo" => $goodinfo['supplierNo'],
- "supplierName" => $supplierName,
- "companyNo" => $data['companyNo'],
- "companyName" => $data['companyName'],
- "spuCode" => $data['spuCode'],
- "skuCode" => "",
- "orderCode" => $orderCode,
- "good_name" => $goodinfo['good_name'],
- "sale_price" => $goodinfo['total_fee'],
- "total_fee" => round($goodinfo['total_fee'] * $data['good_num'], 2),
- "pakge_fee" => $goodinfo['pakge_fee'],
- "cert_fee" => $goodinfo['cert_fee'],
- "open_fee" => $goodinfo['open_fee'],
- "cost_fee" => $goodinfo['cost_fee'],
- "mark_fee" => $goodinfo['mark_fee'],
- "demo_fee" => $goodinfo['demo_fee'],
- "nake_fee" => $goodinfo['nake_fee'],
- "good_num" => $data['good_num'],
- "delivery_fee" => $goodinfo['delivery_fee'],
- "createrid" =>$holder_id,
- "creater" =>$holder_name,
- "weight" => $goodinfo['good_weight'],
- "gold_price" => $goodinfo['gold_price'],
- 'open_type'=>$goodinfo['open_type'],
- "good_type" => 1,
- "order_type" => 3,//3咨询商品
- "order_source" => 3,//项目
- "send_way" => $goodinfo['send_way'],
- 'good_createrid' => $goodinfo['createrid'],
- 'good_creater' => $goodinfo['creater'],//商品创建人
- 'supplier_origin_price'=>$goodinfo['supplier_origin_price'],//供应商采购成本
- 'cgd_supplier_code'=>$goodinfo['cgd_supplier_code'],//采购供应商编号
- 'cgd_supplier_name'=>$goodinfo['cgd_supplier_name'],//采购供应商编号
- 'cgd_apply_id'=>$goodinfo['cgd_apply_id'],//竞单人
- 'cgd_apply_name'=>$goodinfo['cgd_apply_name'],//竞单人
- ];
- $datas = [
- "orderCode" => $orderCode,
- "good_code" => $data['spuCode'],
- "skuCode" => "",
- "customer_code" => $data['customerNo'],
- "customerName" => $data['customerName'],
- "good_name" => isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '' ? $goodinfo['good_name'] : '',
- "good_num" => $data['good_num'],
- "cat_id" => $goodinfo['cat_id'],
- "apply_id" => $data['rm'],
- "apply_name" => $data['ri'],
- "origin_price" => $goodinfo['total_fee'],
- "sale_price" => $data['sale_price'],
- "post_fee" => 0,
- "status" => 0,
- "send_num" => 0,
- "wsend_num" => $data['good_num'],
- "send_status" => 1,
- "good_type" => 1,
- "send_type" => $data['sendtype'],
- "supplierNo" => $data['companyNo'],
- "supplierName" => $data['companyName'],
- "supNo" =>$goodinfo['supplierNo'],
- "supName" => $supplierName,
- "is_del" => 0,
- "zxNo" => $data["pgNo"],
- "platform_order" => "",
- "platform_id" => $data['platform_id'],
- 'open_type'=>$goodinfo['open_type'],
- "remark" => "",
- "is_stock" => 0,
- "is_activity" => 0,
- "activity_code" => '',
- "proof_id" => 0,
- "order_type" => 3,//咨询商品
- "order_source" => 3,//项目
- 'use_order'=>$data['useid']??0,
- 'good_weight' => $goodinfo['good_weight'],
- 'gold_price' => $goodinfo['gold_price'],
- 'cost_price' => $goodinfo['sale_cost_fee'],
- 'diff_weight' => 0,
- 'diff_fee' => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- 'total_price' => round($data['sale_price'] * $data['good_num'], 2),
- 'cgderid' => $holder_id,
- 'cgder' => $holder_name,//采购员(供应商负责人)
- 'good_createrid' => $goodinfo['createrid'],
- 'good_creater' => $goodinfo['creater'],//商品创建人
- "manager"=>$data['manager'],
- "managerid"=>$data['managerid'],
- ];
- $datainfo = Db::name('sale')->insert($datas, true);
- if ($datainfo > 0) {
- $standing_book_data['sale_id'] = $datainfo;
- $standing_book_data['customer_code'] = $datas['customer_code'];
- $standing_book_data['infoNo'] = $goodinfo['infoNo'];
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $orderCode,//项目编码
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "XSQRD", 0, $datas);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'XSQRD',
- "order_code" => $orderCode,
- "order_id" => $datainfo,
- "order_status" => 0,
- "before_status" => 0,
- 'holder_id' => $datas['apply_id']
- ]);
- $bidstatus = $goodinfo['status'];
- $goodinfo['status'] = 6;
- $goodinfo['updatetime'] = date("Y-m-d H:i:s");
- $sa = Db::name("consult_bids")->save($goodinfo);
- if ($sa == false) {
- throw new Exception("咨询反馈单更新失败");
- }
- $goodinfo['status'] = 5;
- $goodinfo['updatetime'] = date("Y-m-d H:i:s");
- $saa = Db::name("consult_info")->where(["infoNo"=>$goodinfo['infoNo']])->update(["status"=>5,
- "updatetime"=>date("Y-m-d H:i:s")]);
- if ($saa == false) {
- throw new Exception("咨询单更新失败");
- }
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $goodinfo['bidNo'],//项目编码
- "status" => $bidstatus,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "FKD", 6, $datas);
- $zxorder = Db::name("consult_order")->where(["zxNo" => $goodinfo["zxNo"], "is_del" => 0])->find();
- if ($zxorder == false) {
- throw new Exception("咨询单为找到");
- }
- $limt = [
- "spuCode" => $goodinfo['spuCode'],
- "good_name" => $goodinfo['good_name'],
- "brand_id" => $goodinfo['brand_id'],
- "good_unit" => $goodinfo['unit_id'],
- "cat_id" => $goodinfo['cat_id'],
- "good_type" => 0,
- "moq" => 1,
- "customized" => $goodinfo['work_day'],
- "tax" => $goodinfo['tax'],
- "supplierNo" => $goodinfo["supplierNo"],
- "supplierName" => $supplierName,
- "is_auth" => 0,
- "craft_desc" => $goodinfo['good_name'],
- "good_remark" => "",
- "good_img" => $goodinfo['good_img'],
- "good_thumb_img" => "",
- "good_info_img" => "",
- "platform_id" => $zxorder['platform_id'],
- "specinfo" => $goodinfo['specinfo'],
- "work_day" => $goodinfo['work_day'],
- "noble_metal" => $goodinfo['metal_id'],
- "is_gold_price" => $goodinfo['is_gold_price'],
- "good_weight" => $goodinfo['good_weight'],
- "companyNo" => $data['companyNo'],
- "companyName" => $data['companyName'],
- "config" => $goodinfo['config'],
- "other_config" => $goodinfo['other_config'],
- "weight" => $goodinfo['weight'],
- "is_diff" => $goodinfo['is_diff'],
- "supply_area" => $goodinfo['supply_area'],
- "pay_way" => $goodinfo['pay_way'],
- "send_way" => $goodinfo['send_way'],
- 'sale_price' => $data['sale_price'],
- 'open_type'=>$goodinfo['open_type'],
- "status" => 1,
- "is_del" => 0,
- "order_type" => 3,
- 'order_source' => 3,
- 'order_createrid' => $data['rm'],
- 'order_creater' => $data['ri'],
- "createrid" => $goodinfo['createrid'],
- "creater" => $goodinfo['creater'],
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $good = Db::name("good_zixun")->insert($limt);
- if (!$good) {
- throw new Exception("咨询商品录入失败");
- }
- if($goodinfo['is_combind']==1){
- $marage=[
- 'parent_code'=>$goodinfo['spuCode'],
- 'parent_name'=>$goodinfo['good_name'],
- 'order_type' => 3,
- 'order_source' =>3,
- 'good_type' => 0,
- 'moq' => 1,
- 'good_thumb_img' => '',
- 'good_info_img' => '',
- 'is_auth' => 0,
- 'good_remark' => '',
- 'createrid' => $goodinfo['createrid'],
- 'creater' => $goodinfo['creater'],
- 'order_createrid' => $data['rm'],
- 'order_creater' => $data['ri'],
- 'platform_id' => $zxorder['platform_id'],
- ];
- (new ConsultTemp())->CreateGood($goodinfo['bidNo'],$marage);
- }
- if($goodinfo['open_type']==1|| $goodinfo['tax_id']>0){
- $data = [
- 'spuCode'=>$goodinfo['spuCode'],
- 'companyNo'=>$data['companyNo'],
- 'tax_id'=>$goodinfo['tax_id'],
- 'open_type'=>$goodinfo['open_type'],
- 'inv_good_name'=>$goodinfo['inv_good_name'],
- 'tax'=>$goodinfo['tax'],
- 'out_tax_id'=>$goodinfo['out_tax_id'],
- 'out_tax'=>str_replace('%','',$goodinfo['out_tax']),
- 'cgd_tax_id'=>$goodinfo['cgd_tax_id'],
- 'cgd_tax'=>str_replace('%','',$goodinfo['cgd_tax']),
- 'status'=>2,
- 'createrid' => $goodinfo['createrid'],
- 'creater' => $goodinfo['creater'],
- ];
- GoodTax::create($data);
- }
- $taxInfo = OrderTax::SpuCat( $data['spuCode']);
- if (!empty($taxInfo)) {
- (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
- $temp=[];
- $temp['code']=$orderCode;
- $temp['spuCode']=$item['spuCode'];
- $temp['tax_code']=$item['cat_code'];
- $temp['tax_name']=$item['cat_name'];
- $temp['tax_short_name']=$item['short_name'];
- $temp['inv_tax']=$item['tax'];
- $temp['inv_good_name']=$item['inv_good_name'];
- return $temp;
- },$taxInfo));
- }
- $bol = $this->createCgd($cgd, $standing_book_data);
- if ($bol == false) {
- throw new Exception('采购单生成失败');
- }
- if ($data['sendtype'] == 1 && !empty($data['addrlist'])) {
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])
- ->find();
- if ($order == false) {
- throw new Exception("关联采购单信息未找到");
- }
- $i = 1;
- foreach ($data['addrlist'] as $value) {
- $temp = [];
- $addrs = [];
- if ($value['addr_code'] !== '' && is_array($value['addr_code']) && !empty($value['addr_code'])) {
- $addrs['provice_code'] = $value['addr_code'][0];
- $addrs['city_code'] = $value['addr_code'][1];
- $addrs['area_code'] = $value['addr_code'][2];
- $addr = json_encode($addrs);
- } else {
- $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
- }
- if($value['receipt_quantity']<=0) throw new Exception('地址发货数量不能小于1');
- $temp['orderCode'] = $orderCode;
- $temp['contactor'] = $value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code'] = $addr;
- $temp['customer_code'] = $data['companyNo'];
- $temp['receipt_quantity'] = $value['receipt_quantity'];
- $temp['post_fee'] = 0;
- $temp['is_del'] = 0;
- $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $temp['arrive_time'] = $data['arrtime'];
- $vmp = Db::name('order_addr')->insert($temp, true);
- if ($vmp > 0) {
- $outCode = makeNo("DF");
- //改变编码规则,将原来的outCode后两位换成序列号
- //str_pad字符串填充
- $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
- $i++;
- $out = [
- "orderCode" => $orderCode,
- "outCode" => $outCode,
- "apply_id" => $data['rm'],
- "apply_name" => $data['ri'],
- "addrid" => $vmp,
- "post_name" => "",
- "post_code" => "",
- "post_fee" => 0,
- "sendtime" => date("Y-m-d H:i:s"),
- "send_num" => $value['receipt_quantity'],
- "check_num" => 0,
- "error_num" => 0,
- "wsm_code" => "",
- "order_type" => 3,//3咨询商品
- "status" => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $ou = Db::name("order_out")->insertGetId($out);
- if ($ou == false) {
- throw new Exception("发货单生成失败");
- }
- // OrderOutChild::makeChild($outCode);
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $outCode,//项目编码
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "CKD", 0, $out);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'CKD',
- "order_code" => $outCode,
- "order_id" => $ou,
- "order_status" => 0,
- "before_status" => 0,
- 'holder_id'=>$data['rm'],
- 'wait_id'=>$holder_id,
- 'wait_name'=>$holder_name,
- ]);
- $tep = [
- "cgdNo" => $order['cgdNo'],
- "outCode" => $outCode,
- "send_num" => $value['receipt_quantity'],
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $sen = Db::name("order_send")->save($tep);
- if ($sen == false) {
- throw new Exception("发货单关联采购单生成失败");
- }
- $standing_book_data['outCode'][] = $outCode;
- } else {
- throw new Exception("地址录入失败");
- }
- }
- }
- }
- return true;
- }
- /**
- * @param $data
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function project_good($data, array &$standing_book_data = [])
- {
- $good = Db::name('good')
- ->alias("a")
- ->leftJoin("good_platform b", "a.spuCode=b.spuCode")
- ->where(["b.skuCode" => $data['skuCode'], "a.is_del" => 0, "b.is_del" => 0])
- ->field("a.*,b.skuCode,b.platform_code,b.is_fixed")->find();
- if ($good == false) {
- // return 4; //商品信息未找到
- throw new Exception("商品信息未找到");
- }
- $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();
- if ($goodlass == false) {
- // /return 4;//商品信息未找到
- throw new Exception("商品售价信息未找到");
- }
- $sale_price = $goodlass['sale_price'];
- $origin = Db::name('good_nake')->where([['spuCode', '=', $data['spuCode']], ['min_num', '<=', $data['good_num']],
- ['is_del', '=', 0]])->order('min_num desc')->find();
- if ($origin == false && $good['is_stock'] ==0) {
- throw new Exception('商品成本售价信息未找到');
- }
- $origin_price = $good['is_stock'] == 0?($origin['nake_total']??0):0;
- $cgd_origin_price = $origin['supplier_origin_price']??0;
-
- if ($good['is_gold_price'] == 1 && $good['is_stock'] == 0) {
- $gold = Db::name("gold_price1")
- ->field('id,price')
- ->where(["type" => $good['noble_metal'], "is_del" => 0, "status" => 1])
- ->order("addtime desc")
- ->find();
- if($good['is_fixed']==0) $origin['nake_fee']=0;
- //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
- $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'];
- $good['cgd_gold_price'] = $gold["price"];
- }
- $orderCode = makeNo("QR");
- $supplier_temp_info =[];
- if($good['supplierNo']!=''){
- $userCommon= \app\admin\common\User::getIns();
- $supplier_temp =$userCommon->handle('sInfo',['code'=>$good['supplierNo']]);
- if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('供应商不存在');
- $supplier_temp_info = $supplier_temp['data'];
- }
- $datas = [
- "orderCode" => $orderCode,
- "good_code" => $data['spuCode'],
- "skuCode" => $data['skuCode'],
- "customer_code" => $data['customerNo'],
- "customerName" => $data['customerName'],
- "good_name" => isset($good['good_name']) && $good['good_name'] !== '' ? $good['good_name'] : '',
- "good_num" => $data['good_num'],
- "cat_id" => $good['cat_id'],
- "apply_id" => $data['rm'],
- "apply_name" => $data['ri'],
- "origin_price" => $origin_price,
- "sale_price" => $sale_price,
- "post_fee" => 0,
- "status" => 0,
- "send_num" => 0,
- "wsend_num" => $data['good_num'],
- "send_status" => 1,
- "good_type" => 1,
- "send_type" => $data['sendtype'],
- "supplierNo" => $data['companyNo'],
- "supplierName" => $data['companyName'],
- "supName" => $good['supplierName'],
- "supNo" => $good['supplierNo'],
- 'use_order'=>$data['useid']??0,
- "is_del" => 0,
- "zxNo" => $data["pgNo"],
- "platform_order" => "",
- "platform_id" => $data['platform_id'],
- "remark" => "",
- "is_stock" => $good['is_stock'],
- 'open_type'=>$good['open_type'],
- "is_activity" => 0,
- "activity_code" => '',
- "proof_id" => 0,
- "order_type" => $good['is_stock'] == 1 ? 1 : 2,//1备库,2非库存品
- 'order_source' => 3,//3项目
- 'good_weight' => $good['noble_weight'],
- 'gold_price' => isset($good['cgd_gold_price']) ? $good['cgd_gold_price'] : 0,
- 'cost_price' => $goodlass['cost_fee'],
- 'diff_weight' => 0,
- 'diff_fee' => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- 'total_price' => round($sale_price * $data['good_num'], 2),
- 'cgderid' => $supplier_temp_info['personid']??"0",
- 'cgder' => $supplier_temp_info['person']??"",//采购员(供应商负责人)
- 'good_createrid' => $good['createrid'],
- 'good_creater' => $good['creater'],//商品创建人
- "manager"=>$data['manager'],
- "managerid"=>$data['managerid'],
- ];
- $datainfo = Db::name('sale')->insert($datas, true);
- if ($datainfo > 0) {
- $standing_book_data['sale_id'] = $datainfo;
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $orderCode,//项目编码
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "XSQRD", 0, $datas);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'XSQRD',
- "order_code" => $orderCode,
- "order_id" => $datainfo,
- "order_status" => 0,
- "before_status" => 0,
- 'holder_id' => $datas['apply_id']
- ]);
- $cgd = [
- "supplierNo" => $good['supplierNo'],
- "supplierName" =>$good['supplierName'],
- "companyNo" => $data['companyNo'],
- "companyName" => $data['companyName'],
- "orderCode" => $orderCode,
- "spuCode" => $good['spuCode'],
- "skuCode" => $good['skuCode'],
- "good_name" => $good['good_name'],
- "sale_price" => $origin_price,
- "total_fee" => $origin_price * $data['good_num'],
- "pakge_fee" => isset($origin['package_fee']) ? $origin['package_fee'] : 0,
- "cert_fee" => isset($origin['cert_fee']) ? $origin['cert_fee'] : 0,
- "open_fee" => $good['open_fee'],
- "cost_fee" => isset($origin['cost_fee']) ? $origin['cost_fee'] : 0,
- "mark_fee" => isset($origin['mark_fee']) ? $origin['mark_fee'] : 0,
- "demo_fee" => $good['demo_fee'],
- "nake_fee" => isset($origin['nake_fee']) ? $origin['nake_fee'] : 0,
- "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
- "good_num" => $data['good_num'],
- "good_type" => 1,
- "weight" => $good['noble_weight'],
- "gold_price" => isset($good['cgd_gold_price']) ? $good['cgd_gold_price'] : 0,
- "createrid" => $supplier_temp_info['personid']??0,
- "creater" => $supplier_temp_info['person']??"",
- "order_type" => $good['is_stock'] == 1 ? 1 : 2,
- 'open_type'=>$good['open_type'],
- 'order_source' => 3,//3项目
- 'send_way' => 2,
- 'good_createrid' => $good['createrid'],
- 'good_creater' => $good['creater'],//商品创建人
- 'supplier_origin_price'=>$cgd_origin_price,//供应商采购成本
- 'cgd_supplier_code'=>$good['cgd_supplier_code'],//采购供应商编号
- 'cgd_supplier_name'=>$good['cgd_supplier_name'],//采购供应商编号
- 'cgd_apply_id'=>$good['cgd_apply_id'],//竞单人
- 'cgd_apply_name'=>$good['cgd_apply_name'],//竞单人
- ];
- $taxInfo = OrderTax::SpuCat( $data['spuCode']);
- if (!empty($taxInfo)) {
- (new \app\admin\model\OrderTax)->saveAll(array_map(function ($item)use($orderCode){
- $temp=[];
- $temp['code']=$orderCode;
- $temp['spuCode']=$item['spuCode'];
- $temp['tax_code']=$item['cat_code'];
- $temp['tax_name']=$item['cat_name'];
- $temp['tax_short_name']=$item['short_name'];
- $temp['inv_tax']=$item['tax'];
- $temp['inv_good_name']=$item['inv_good_name'];
- return $temp;
- },$taxInfo));
- }
- if ($good['is_stock'] == 0) {
- $bol = $this->createCgd($cgd, $standing_book_data);
- if ($bol == false) {
- // return 3;//关联采购失败
- throw new Exception("采购单生成失败");
- }
- } else {
- if($good['usable_stock'] < $data['good_num']){
- throw new Exception("可用库存数不足");
- }
- $stockUp =[
- "usable_stock"=>$good['usable_stock']-$data['good_num'],
- "updatetime"=>date("Y-m-d H:i:s"),
- ];
- $goodStockUp = Db::name("good")->where(['spuCode'=>$good['spuCode'],"usable_stock"=>$good['usable_stock']])->update
- ($stockUp);
- if($goodStockUp==false) throw new Exception("商品可用库存更新失败");
- SaleCgdPrice::GetPrice($datainfo);
- }
- if ($data['sendtype'] == 1 && !empty($data['addrlist'])) {
- $i = 1;
- foreach ($data['addrlist'] as $value) {
- $temp = [];
- $addrs = [];
- if ($value['addr_code'] !== '' && is_array($value['addr_code']) && !empty($value['addr_code'])) {
- $addrs['provice_code'] = $value['addr_code'][0];
- $addrs['city_code'] = $value['addr_code'][1];
- $addrs['area_code'] = $value['addr_code'][2];
- $addr = json_encode($addrs);
- } else {
- $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
- }
- if($value['receipt_quantity']<=0) throw new Exception('地址发货数量不能小于1');
- $temp['orderCode'] = $orderCode;
- $temp['contactor'] = $value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code'] = $addr;
- $temp['customer_code'] = $data['companyNo'];
- $temp['receipt_quantity'] = $value['receipt_quantity'];
- $temp['post_fee'] = 0;
- $temp['is_del'] = 0;
- $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $temp['arrive_time'] = $data['arrtime'];
- $vmp = Db::name('order_addr')->insert($temp, true);
- if ($vmp > 0) {
- $standing_book_data['customer_code'] = $temp['customer_code'];
- $num = $value['receipt_quantity'];
- $outCode = makeNo("DF");
- $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
- $i++;
- if ($good['is_stock'] != 1) {
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])
- ->find();
- if ($order == false) {
- throw new Exception("关联采购单信息未找到");
- }
- $tep = [
- "cgdNo" => $order['cgdNo'],
- "outCode" => $outCode,
- "send_num" => $num,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $sen = Db::name("order_send")->save($tep);
- if ($sen == false) {
- throw new Exception("发货单关联采购单信息失败");
- }
- $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
- if ($cgdinfo == false) {
- throw new Exception("采购单信息未找到");
- }
- }
- $out = [
- "orderCode" => $orderCode,
- "outCode" => $outCode,
- "apply_id" => $data['rm'],
- "apply_name" => $data['ri'],
- "addrid" => $vmp,
- "post_name" => "",
- "post_code" => "",
- "post_fee" => 0,
- "sendtime" => date("Y-m-d H:i:s"),
- "send_num" => $num,
- "check_num" => 0,
- "error_num" => 0,
- "wsm_code" => $good['is_stock'] == 1 ?'':$cgdinfo['wsm_code'],
- "order_type" => 1,
- "status" => $good['is_stock'] == 1 ? 1 : 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $ou = Db::name("order_out")->insertGetId($out);
- if ($ou == false) {
- throw new Exception("发货单生成失败");
- } else {
- if($good['is_stock'] == 1)OrderOutChild::makeChild($outCode);//非库存品无法立即分单
- $standing_book_data['outCode'][] = $outCode;
- //修改状态,添加待办
- if($good['is_stock'] == 1){
- $roleid = config('app.wsm_cgder_role');
- $uids = Db::name('user_role')
- ->where('is_del', 0)
- ->whereIn('roleid', $roleid)
- ->column('uid');
- $handle_user_list=implode(',', $uids);
- }
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $outCode,//出库单号
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "CKD", 0, $out);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'CKD',
- "order_code" => $outCode,//出库单号
- "order_id" => $ou,
- "order_status" => $good['is_stock'] == 1 ? 1 : 0,
- "before_status" => 0,
- 'holder_id'=>$out['apply_id'],
- 'handle_user_list' =>$handle_user_list??""
- ]);
- }
- } else {
- throw new Exception("地址录入失败");
- }
- }
- }
- // }
- }
- return true;
- }
- public function list()
- {
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
- $where[] = ['s.is_del', "=", 0];
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
- if ($orderCode !== "") {
- $where[] = ['s.orderCode', "like", "%$orderCode%"];
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name']) : "";
- if ($apply_name !== "") {
- $where[] = ['s.apply_name', "like", "%$apply_name%"];
- }
- $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
- if ($good_name !== "") {
- $where[] = ['s.good_name', "like", "%$good_name%"];
- }
- $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
- if ($good_code !== "") {
- $where[] = ['s.good_code', "like", "%$good_code%"];
- }
-
- $platform_order = isset($this->post['platform_order']) && $this->post['platform_order'] !== '' ? trim
- ($this->post['platform_order']) : '';
- if ($platform_order !== '') {
- $where[] = ['s.platform_order', 'like', "%$platform_order%"];
- }
- $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
- if ($customer_code !== "") {
- $where[] = ['s.customer_code', "like", "%$customer_code%"];
- }
-
- $customer_name = isset($this->post['customer_name']) && $this->post['customer_name'] !== '' ? trim($this->post['customer_name']) : '';
- if ($customer_name !== '') {
- $where[] = ['s.customerName', 'like', "%$customer_name%"];
- }
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
- if ($supplierNo !== "") {
- $where[] = ['s.supplierNo', "=", $supplierNo];
- }
- $relaComNo = trim($this->post['relaComNo']??'');
- if ($relaComNo !== "") {
- $where[] = ['s.supplierNo', "=", $relaComNo];
- }
- $ordertype = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type']) : "";
- if ($ordertype !== "") {
- $where[] = ['s.order_type', "=", $ordertype];
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
- if ($status !== "") {
- $where[] = ['s.status', "=", $status];
- }
- $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
- if ($start != "") {
- $where[] = ["s.addtime", '>=', $start];
- }
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
- if ($end != "") {
- $end .= " 23:59:59";
- $where[] = ["s.addtime", '<=', $end];
- }
- $use_type = $this->post['use_type']??'';
- if($use_type!=='') $where[]=['e.use_type','=',$use_type];
- $platform_id = $this->post['platform_id']??'';
- if($platform_id!=='') $where[]=['s.platform_id','=',$platform_id];
- $role = $this->checkDataShare();
- $hand = resign_hand_user($this->uid,0);
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
- $where[] = ['s.apply_id', 'in',$arr];
- }
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["s.apply_id", 'in', get_company_item_user_by_name($company_name)];
- $order_source = isset($this->post['order_source']) && $this->post['order_source'] !== "" ? trim($this->post['order_source']) : "";
- if ($order_source !== "") $where[] = ["s.order_source", '=', $order_source];
- $count = Db::name('sale')
- ->alias('s')
- ->leftJoin('order_num b','b.orderCode=s.orderCode')
- // ->leftJoin('order_use c','c.id=s.use_order')
- ->leftJoin('purchease_order d','d.cgdNo=b.cgdNo')
- ->leftJoin('platform e','e.id=s.platform_id')
- ->where($where)
- ->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('sale')
- ->alias('s')
- ->field('s.*,b.cgdNo,s.use_order useage,d.status cgd_status,e.use_type,e.platform_name')
- ->leftJoin('order_num b','b.orderCode=s.orderCode')
- // ->leftJoin('order_use c','c.id=s.use_order')
- ->leftJoin('purchease_order d','d.cgdNo=b.cgdNo')
- ->leftJoin('platform e','e.id=s.platform_id')
- ->order("s.addtime desc")
- ->page($page, $size)
- ->where($where)
- ->select()
- ->toArray();
- $all_createrid = array_unique(array_column($list, 'apply_id'));
- $item = get_company_name_by_uid($all_createrid);
- $useAddr = \app\admin\model\OrderUse::where(["is_del"=>1])->column("order_use","id");
- $data = [];
- foreach ($list as $value) {
- $value['useage'] = $useAddr[$value['useage']]??"";
- if ($value['order_type'] == 3 ||$value['order_type']==4) {
- $var = Db::name("good_zixun")->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
- $value["speclist"] = isset($var['specinfo']) && $var['specinfo'] != "" ? json_decode($var['specinfo'], true) : "";
- } else {
- $var = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $value['skuCode']])->find();
- $spec = Db::name("good_spec")->where(["spuCode" => $var['spuCode'], "is_del" => 0])->select()->toArray();
- $speclist = [];
- if (!empty($spec)) {
- foreach ($spec as $val) {
- $temp = [];
- $temp['id'] = $val['id'];
- $temp['spuCode'] = $val['spuCode'];
- $temp['spec_id'] = $val['spec_id'];
- $temp['spec_value_id'] = $val['spec_value_id'];
- $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
- $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
- $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
- $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
- $speclist[] = $temp;
- }
- }
- $value["speclist"] = empty($speclist) ? [] : $speclist;
- }
- $value['can'] = isset($var['cat_id']) && $var['cat_id'] != 0 ? made($var['cat_id']) : [];
- $value['good_num'] -= $value['th_num'];
- $value['send_num'] -= $value['th_num'];
- $value['total_price'] = round($value['total_price'] - $value['th_fee'], 2);
- $value['company_name'] = $item[$value['apply_id']]??'';
- //是否具有编辑权限
- $value['is_allow_update'] = 0;
- if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
- $data[] = $value;
- }
- return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
- }
- public function edit()
- {
- // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
- if ($id == "") {
- return error_show(1002, "参数id不能为空");
- }
- $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
- if (empty($etid)) {
- return error_show(1002, "未找到数据");
- }
- // $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
- // if($orderCode==""){
- // return error_show(1002,"销售单code不能为空");
- // }
- $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
- if ($good_code == "") {
- return error_show(1002, "商品code不能为空");
- }
- $ct = Db::name('good')->alias('a')->join('good_type b', 'b.good_code=a.good_code', 'left')
- ->where(['b.type_code' => $good_code])->find();
- if ($ct == "") {
- return error_show(1002, "未找到商品数据");
- }
- $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
- if ($customer_code == "") {
- return error_show(1002, "客户code不能为空");
- }
- // $customer = Db::name("customer_info")->where(["companyNo" => $customer_code])->find();
- // if ($customer == false) {
- // return error_show(1004, "未找到客户数据");
- // }
- $supplierNo = $this->post['supplierNo'] && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
- if ($supplierNo == "") {
- return error_show(1002, "参数supplierNo不能为空");
- }
- // $supplier = Db::name("supplier")->where(["code" => $supplierNo])->find();
- // if ($supplier == false) {
- // return error_show(1004, "未找到平台供应商数据");
- // }
- // $apply_id = GetUserInfo($token);
- // if (empty($apply_id) || $apply_id['code'] != 0) {
- // return error_show(1002, "申请人数据不存在");
- // }
- $rm = $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri = $this->uname;//isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- // $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim
- //($this->post['good_name']) : "";
- // $good_num = isset($this->post['good_num']) && $this->post['good_num'] !== "" ? intval
- //($this->post['good_num']) : "";
- // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !== "" ? intval
- // ($this->post['origin_price']) : "";
- // $sale_price = isset($this->post['sale_price']) && $this->post['sale_price'] !== "" ? trim($this->post['sale_price']) : "";
- // $total_price = isset($this->post['total_price']) && $this->post['total_price'] !== "" ? trim($this->post['total_price']) : "";
- // $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? trim($this->post['post_fee']) : "";
- // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
- $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
- if ($vr == "") {
- return error_show(1002, "参数order_addr不能为空");
- }
- $vi = isset($this->post['good_stock']) && $this->post['good_stock'] !== "" ? $this->post['good_stock'] : "";
- if ($vi == "") {
- return error_show(1002, "参数good_stock不能为空");
- }
- $good_num = intval(array_sum(array_column($vi, "num")));
- Db::startTrans();
- try {
- $datn = [
- "id" => $id,
- "good_code" => $good_code,
- "customer_code" => $customer_code,
- "good_num" => $good_num,
- "supplierNo" => $supplierNo,
- "apply_id" => $rm,
- "apply_name" => $ri,
- "is_del" => 0,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $datninfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($datn);
- if ($datninfo > 0) {
- $stn = ["order_code" => $etid['orderCode'], "status" => $etid['status'], "action_remark" => '', "action_type" => "edit"];
- ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], $stn, "XSQRD", $etid['status'], $datn);
- // $order=["order_type"=>'XSQRD',"order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$etid['status'],"before_status"=> 0];
- // ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$order);
- //更新台账
- Db::name('standing_book')
- ->where('orderCode', $etid['orderCode'])
- ->update([
- 'customer_code' => $customer_code,
- 'supplierNo' => $supplierNo,
- 'updatetime' => date("Y-m-d H:i:s")
- ]);
- foreach ($vi as $ion) {
- $iten = [];
- isset($ion['id']) && $ion['id'] !== "" ? $iten['id'] = $ion['id'] : '';
- $iten['orderCode'] = $etid['orderCode'];
- $iten['wsm_code'] = $ion['wsm_code'];
- $iten['stock_id'] = 0;
- $iten['num'] = $ion['num'];
- $iten['status'] = 1;
- $iten['sale_price'] = $ct['original_price'];
- isset($ion['id']) && $ion['id'] !== "" ? '' : $iten['addtime'] = date("Y-m-d H:i:s");
- $iten['updatetime'] = date("Y-m-d H:i:s");
- $vp = Db::name('sale_info')->save($iten);
- if ($vp == false) {
- Db::rollback();
- return error_show(1002, "更新失败");
- }
- }
- foreach ($vr as $value) {
- $temp = [];
- isset($value['id']) && $value['id'] !== "" ? $temp['id'] = $value['id'] : '';
- $temp['orderCode'] = $etid['orderCode'];
- $temp['contactor'] = $value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code'] = $value['addr_code'];
- $temp['customer_code'] = $customer_code;
- $temp['receipt_quantity'] = $value['receipt_quantity'];
- $temp['post_fee'] = 0;
- $temp['is_del'] = $value['is_del'];
- isset($value['id']) && $value['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $temp['arrive_time'] = date("Y-m-d H:i:s");
- $dat = Db::name('order_addr')->save($temp);
- if ($dat == false) {
- Db::rollback();
- return error_show(1002, "更新失败");
- }
- }
- Db::commit();
- return error_show(0, "更新成功");
- }
- Db::rollback();
- return error_show(1002, "更新失败");
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- public function info()
- {
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- if ($id == "") {
- return error_show(1002, "参数id不能为空");
- }
- $einfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
- if (empty($einfo)) {
- return error_show(1002, "未找到销售订单数据");
- }
- if ($einfo['order_type'] == 3 || $einfo['order_type']==4) {
- $goon = Db::name("good_zixun")->where(["spuCode" => $einfo['good_code'], "is_del" => 0])->find();
- } else {
- $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')->where(['a.skuCode' => $einfo['skuCode']])->find();
- }
- if ($goon == false) {
- return error_show(1003, "未找到商品数据");
- } else {
- $taxInfo=OrderTax::where(['code'=>$einfo['orderCode']])->findOrEmpty();
- $einfo['tax_name'] = $taxInfo['tax_name']??'';
- $einfo['tax_short_name'] =$taxInfo['tax_short_name']??'';
- $einfo['tax_code'] =$taxInfo['tax_code']??'';
- $einfo['tax']=$taxInfo['inv_tax']??'';
- $einfo['inv_good_name']=$taxInfo['inv_good_name']??'';
- $goon['exclusive'] = isset($goon['is_exclusive']) ? makeExcluse($goon['is_exclusive']) : "";
- $unit = Db::name("unit")->where(["id" => $goon['good_unit']])->find();
- $goon['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
- $spec = Db::name("good_spec")->where(["spuCode" => $goon['spuCode'], "is_del" => 0])->select()->toArray();
- $speclist = [];
- if (!empty($spec)) {
- foreach ($spec as $value) {
- $temp = [];
- $temp['id'] = $value['id'];
- $temp['spuCode'] = $value['spuCode'];
- $temp['spec_id'] = $value['spec_id'];
- $temp['spec_value_id'] = $value['spec_value_id'];
- $temp['is_del'] = $value['is_del'];
- $sp = Db::name("specs")->where(["id" => $value['spec_id']])->find();
- $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
- $spv = Db::name("spec_value")->where(["id" => $value['spec_value_id']])->find();
- $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
- $speclist[] = $temp;
- }
- }
- $goon["speclist"] = empty($speclist) ? [] : $speclist;
- $proof = Db::name("good_proof")->where(["spuCode" => $goon['spuCode'], "is_del" => 0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
- $goon['proof'] = isset($proof) && $proof != false ? $proof : [];
- $goon['origin_place_cn'] = "";
- $goon['delivery_place_cn'] = "";
- if (isset($goon['delivery_place']) && $goon['delivery_place'] !== "") {
- $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
- list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $goon['delivery_place']);
- $goon['delivery_place_cn'] = GetAddr(json_encode($place));
- }
- if (isset($goon['delivery_place']) && $goon['origin_place'] !== "") {
- $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
- list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $goon['origin_place']);
- $goon['origin_place_cn'] = GetAddr(json_encode($place));
- }
- if ($goon['brand_id'] != 0) {
- $brand = Db::name("brand")->where(["id" => $goon['brand_id']])->find();
- $goon["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
- } else {
- $goon["brand_name"] = "";
- $goon["brand_id"] = "";
- }
- $userCommon = \app\admin\common\User::getIns();
- $names = $userCommon->handle('getCodeAndName',['code'=>[
- $goon['supplierNo'],
- $goon['companyNo'],
- $einfo['customer_code'],
- $einfo['supplierNo']
- ]]);
- $goon['supplierName'] = $names['data'][$goon['supplierNo']]??'';//isset($supplier['name']) ? $supplier['name'] : "";
- $goon['noble_name'] = isset($goon['noble_metal']) && $goon['noble_metal'] != 0 ? $this->noble[$goon['noble_metal']] : "";
- $goon['company'] = $names['data'][$goon['companyNo']]??'';//isset($company['company']) ? $company['company'] : "";
- }
- $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
- // $in = Db::name('customer_info')->where(['companyNo' => $einfo['customer_code']])->field('companyName')->find();
- $einfo['supplierName'] = '';
- if ($einfo['supplierNo'] != "") {
- $einfo['supplierName'] = $names['data'][$einfo['supplierNo']]??'';//isset($supplier['company']) ? $supplier['company'] : "";
- }
- $addr_sum = Db::name('order_addr')->where(['orderCode' => $einfo['orderCode'],"is_del"=>0])->sum('receipt_quantity');
- $einfo['addr_sum']=$addr_sum;
- $addrs = [];
- $einfo['useage'] = "";
- if ($einfo['use_order'] != 0) {
- $use = Db::name("order_use")->where(["id" => $einfo['use_order']])->find();
- $einfo['useage'] = isset($use['order_use']) ? $use['order_use'] : "";
- } else {
- $einfo['use_order'] = '';
- }
- $einfo['platform_name'] = '';
- if ($einfo['platform_id'] != 0) {
- $plat = Db::name("platform")->where(['id' => $einfo['platform_id']])->find();
- $einfo['platform_name'] = isset($plat['platform_name']) ? $plat['platform_name'] : "";
- }
- $einfo['companyName'] = $names['data'][$einfo['customer_code']]??'';//isset($in['companyName']) ? $in['companyName'] : "";
- $einfo['addrs'] = $addrs;
- $einfo['can'] = $int;
- $einfo['goodinfo'] = $goon;
- $einfo['good_num'] -= $einfo['th_num'];
- $einfo['send_num'] -= $einfo['th_num'];
- $einfo['total_price'] = round($einfo['total_price'] - $einfo['th_fee'], 2);
- //处理凭证
- if ($einfo['order_type'] == 1 || $einfo['order_type'] == 2) {
- $proof = Db::name('good_proof')
- ->field('id,proof_type,proof_url')
- ->where(['id' => $einfo['proof_id'], 'is_del' => 0])
- ->find();
- $einfo['proof_type'] = isset($proof['proof_type']) ? $proof['proof_type'] : '';
- $einfo['proof_url'] = isset($proof['proof_url']) ? $proof['proof_url'] : '';
- } elseif ($einfo['order_type'] == 3 ||$einfo['order_type']==4) {
- $einfo['proof_type'] = isset($goon['proof_type']) ? $goon['proof_type'] : '';
- $einfo['proof_url'] = isset($goon['proof_url']) ? $goon['proof_url'] : '';
- } else {
- $einfo['proof_type'] = '';
- $einfo['proof_url'] = '';
- }
- if (empty($einfo)) {
- return error_show(1002, "未找到销售订单数据");
- } else {
- return app_show(0, "获取成功", $einfo);
- }
- }
- public function del()
- {
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- if ($id === "") {
- return error_show(1002, "参数id不能为空");
- }
- $ed = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
- if (empty($ed)) {
- return error_show(1002, "未找到销售订单数据");
- }
- $str = Db::name('sale')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
- if ($str) {
- $stc = ["order_code" => $id, "status" => $ed['status'], "action_remark" => '', "action_type" => "delete"];
- 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")]);
- $order = ["order_type" => 'XSQRD', "order_code" => $ed['orderCode'], "order_id" => $id, "order_status" => $ed['status'],'holder_id' => $ed['apply_id']
- ];
- ProcessOrder::workdel($order);
- return error_show(0, "删除成功");
- } else {
- return error_show(1002, "删除失败");
- }
- }
- //废弃接口
- public function status()
- {
- // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- if ($id == "") {
- return error_show(1002, "参数id不能为空");
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
- if ($status == "") {
- return error_show(1002, "订单状态不能为空");
- }
- $dio = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
- if (empty($dio)) {
- return error_show(1002, "销售单信息未找到");
- }
- if ($status == 1 && $dio['order_type'] == 2) {
- $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
- if ($zxinfo == false) {
- return error_show(1004, "未找到咨询单数据");
- }
- $gold['price'] = 0;
- if ($zxinfo['zx_type'] == 2) {
- if ($zxinfo['metals'] == "") {
- return error_show(1004, "未找到咨询单贵金属类型数据");
- }
- $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
- $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
- if (empty($gold)) {
- return error_show(1004, "未找到咨询单贵金属类型数据");
- }
- $dio['gold_price'] = $gold['price'];
- }
- $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
- if (empty($wsm)) {
- return error_show(1002, "供应商仓库未找到");
- }
- }
- // $apply_id = GetUserInfo($token);
- // if (empty($apply_id) || $apply_id['code'] != 0) {
- // return error_show(1002, "申请人数据不存在");
- // }
- $rm = $this->uid;
- $ri = $this->uname;
- Db::startTrans();
- try {
- $vmp = $dio['status'];
- $dio['status'] = $status;
- $dio['updatetime'] = date("Y-m-d H:i:s");
- $st = Db::name('sale')->save($dio);
- if ($st) {
- $stn = ["order_code" => $dio['orderCode'], "status" => $vmp, "action_remark" => '', "action_type" => "status"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stn, $dio['order_type'] == 2 ? "ZXQRD" : "XSQRD", $dio['status'], $dio);
- $order = ["order_type" => "XSQRD", "order_code" => $dio['orderCode'], "order_id" => $id, "order_status" => $dio['status'], "before_status" => 1,'holder_id' => $dio['apply_id']];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
- if ($status == 3 && $dio['order_type'] == 1) {
- $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
- foreach ($dn as $value) {
- $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
- if ($dm == "") {
- Db::rollback();
- return error_show(1003, "未找到商品数据");
- }
- if ($value['num'] > $dm['usable_stock']) {
- Db::rollback();
- return error_show(1002, "超出库存数量");
- }
- $dm['usable_stock'] -= $value['num'];
- $dm['wait_out_stock'] += $value['num'];
- $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], "is_del" => 0])->sum("send_num");
- $value['send_num'] = $send ?? 0;
- $value['wsend_num'] = $value['num'] - $value['send_num'];
- $Db = Db::name('good_stock')->update($dm);
- $Db['updatetime'] = date('Y-m-d H:i:s');
- if ($Db == false) {
- Db::rollback();
- return error_show(1002, "状态更新失败");
- }
- }
- }
- if ($status == 1 && $dio['order_type'] == 2) {
- $cgd = makeNo("CG");
- $clll = [
- "cgdNo" => $cgd,
- "bkcode" => $dio['orderCode'],
- "wsm_code" => $wsm['wsm_code'],
- "cgder_id" => Db::name('depart_user')->where('nickname', $zxinfo['saler'])->value('uid') ?? 0,//重名以及多个账号的话…………
- "cgder" => $zxinfo['saler'],
- "good_code" => "GD-" . $zxinfo['cpNo'],
- "good_name" => $zxinfo['cpName'],
- "good_type_code" => $zxinfo['cpNo'],
- "good_num" => $dio['good_num'],
- "good_price" => $zxinfo['total_fee'],
- "total_fee" => round($zxinfo['total_fee'] * $dio['good_num'], 2),
- "pakge_fee" => $zxinfo['package_fee'],
- "cert_fee" => $zxinfo['cert_fee'],
- "open_fee" => $zxinfo['open_fee'],
- "delivery_fee" => $zxinfo['delivery_fee'],
- "mark_fee" => $zxinfo['mark_fee'],
- "teach_fee" => $zxinfo['cost_fee'],
- "demo_fee" => $zxinfo['demo_fee'],
- "nake_fee" => $zxinfo['bare_fee'],
- "weight" => isset($zxinfo['weight']) ? $zxinfo['weight'] : 0,
- "supplierNo" => $zxinfo['gysNo'],
- "supplier_name" => $zxinfo['gysname'],
- "gold_price" => $gold['price'],
- "send_num" => 0,
- "wsend_num" => $dio['good_num'],
- "remark" => '',
- "lasttime" => date("Y-m-d H:i:s"),
- "is_del" => 0,
- "status" => $dio['send_type'] == 1 ? 3 : 0,
- "order_type" => 2,
- "order_source" => 3,//3项目,废弃接口???
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $cgin = Db::name("purchease_order")->insert($clll);
- // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
- if ($cgin == false) {
- $stb = ["order_code" => $cgd, "status" => $clll['status'], "action_remark" => '', "action_type" => "create"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stb, "xsd", $clll['status'], $stb);
- Db::rollback();
- return error_show(1002, "咨询采购单创建商品失败");
- }
- if ($dio['send_type'] == 1) {
- $addr = Db::name('order_addr')->where(["orderCode" => $dio['orderCode'], 'is_del' => 0])->select();
- $i = 1;
- foreach ($addr as $value) {
- $outCode = makeNo("DF");
- //改变编码规则,将原来的outCode后两位换成序列号
- //str_pad字符串填充
- $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
- $i++;
- $data = [
- "wsm_code" => $wsm['wsm_code'],
- "orderCode" => $dio['orderCode'],
- "outCode" => $outCode,
- "order_type" => $dio['order_type'],
- "apply_id" => $rm,
- "apply_name" => $ri,
- "addrid" => $value['id'],
- "post_name" => '',
- "post_code" => '',
- "post_fee" => '',
- "sendtime" => date("Y-m-d H:i:s"),
- "send_num" => $value['receipt_quantity'],
- "check_num" => 0,
- "error_num" => 0,
- "status" => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $datainfo = Db::name('order_out')->insertGetId($data);
- if (!$datainfo) {
- $sti = ["order_code" => $dio['orderCode'], "status" => 0, "action_remark" => '', "action_type" => "create"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $sti, "xsd", 0, $sti);
- Db::rollback();
- return error_show(1003, "创建失败");
- } else {
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
- "order_code" => $outCode,//出库单号
- "status" => 0,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "CKD", 0, $data);
- ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], [
- "order_type" => 'CKD',
- "order_code" => $outCode,//出库单号
- "order_id" => $datainfo,
- "order_status" => 0,
- "before_status" => 0,
- 'holder_id'=>$data['apply_id'],
- ]);
- }
- }
- $wsm_in_code = makeNo("CF");
- $orin = [
- "wsm_in_code" => $wsm_in_code,
- "cgdNo" => $cgd,
- "wsm_code" => $wsm['wsm_code'],
- "wsm_reaper" => "",
- "send_num" => $dio['good_num'],
- "post_company" => '',
- "post_code" => '',
- "post_fee" => '',
- "sendtime" => date("Y-m-d H:i:s"),
- "apply_id" => $rm,
- "apply_name" => $ri,
- "wait_num" => 0,
- "status" => 4,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $win = Db::name("purchease_in")->insert($orin);
- if (!$win) {
- $stv = ["order_code" => $wsm_in_code, "status" => 4, "action_remark" => '', "action_type" => "create"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stv, "xsd", 4, $stv);
- Db::rollback();
- return error_show(1003, "创建失败");
- }
- //维护台账
- 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}'");
- $good = Db::name("good_stock")->where(["wsm_code" => $wsm['wsm_code'], "good_type_code" => $zxinfo['cpNo'], "is_del" => 0])->find();
- if (empty($good)) {
- $good = [
- "good_type_code" => $zxinfo['cpNo'],
- "wsm_code" => $wsm['wsm_code'],
- "usable_stock" => 0,
- "wait_out_stock" => 0,
- "total_stock" => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- ];
- }
- $good['wait_out_stock'] += $dio['good_num'];
- $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
- $good['updatetime'] = date("Y-m-d H:i:s");
- $upd = Db::name("good_stock")->save($good);
- if (!$upd) {
- $ste = ["order_code" => $zxinfo['cpNo'], "status" => 0, "action_remark" => '', "action_type" => "create"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $ste, "xsd", 0, $ste);
- Db::rollback();
- return error_show(1003, "创建失败");
- }
- }
- }
- }
- Db::commit();
- return error_show(0, "订单状态更新成功");
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- public function fee()
- {
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
- if ($id == "") {
- return error_show(1002, "参数id不能为空");
- }
- $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
- if (empty($etid)) {
- return error_show(1002, "未找到数据");
- }
- $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
- if ($vr == "") {
- return error_show(1002, "参数order_addr不能为空");
- }
- Db::startTrans();
- try {
- $data = [
- "id" => $id,
- "status" => 2,
- "is_del" => 0,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $datainfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($data);
- if ($datainfo) {
- $stx = ["order_code" => $etid['orderCode'], "status" => $etid['status'], "action_remark" => '', "action_type" => "edit"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, "XSQRD", 2, $data);
- $order = ["order_type" => "XSQRD", "order_code" => $etid['orderCode'], "order_id" => $id, "order_status" => $data['status'], "before_status" => 0,'holder_id'=>$etid['apply_id']];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
- foreach ($vr as $value) {
- $tm = [];
- $tm['id'] = $value['id'];
- $tm['orderCode'] = $etid['orderCode'];
- $tm['post_fee'] = $value['post_fee'];
- $tm['updatetime'] = date("Y-m-d H:i:s");
- $dn = Db::name('order_addr')->save($tm);
- if ($dn == false) {
- Db::rollback();
- return error_show(1002, "更新失败");
- }
- }
- Db::commit();
- return error_show(0, "更新成功");
- }
- Db::rollback();
- return error_show(1003, "更新失败");
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- // 废弃
- public function out()
- {
- // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
- $outCode = makeNo("DF");
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
- if ($orderCode == "") {
- return error_show(1002, "参数orderCoder不能为空");
- }
- $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
- if ($der == "") {
- return error_show(1002, "未找到出库订单单号");
- }
- // $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
- // if ($wsm_code == "") {
- // return error_show(1002, "参数wsm_code不能为空");
- // }
- // $wsm = Db::name('sale_info')->where(['wsm_code' => $wsm_code, 'orderCode' => $der['orderCode']])->find();
- // if ($wsm == "") {
- // return error_show(1002, "未找到仓库编码");
- // }
- $post_name = isset($this->post['post_name']) && $this->post['post_name'] !== "" ? trim($this->post['post_name']) : "";
- if ($post_name == "") {
- return error_show(1002, "物流公司不能为空");
- }
- $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
- if ($post_code == "") {
- return error_show(1002, "物流单号不能为空");
- }
- $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
- if ($post_fee == "") {
- return error_show(1002, "物流费不能为空");
- }
- $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
- if ($send_num == "") {
- return error_show(1002, "发货数量不能为空");
- }
- if ($send_num > $der['wsend_num']) {
- return error_show(1002, "超出可发货数量");
- }
- // $apply_id = GetUserInfo($token);
- // if (empty($apply_id) || $apply_id['code'] != 0) {
- // return error_show(1002, "申请人数据不存在");
- // }
- $rm = $this->uid;
- $ri = $this->uname;
- $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
- $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
- if (empty($dr)) {
- return error_show(1003, "收货人信息未找到");
- }
- if ($dr['orderCode'] !== $orderCode) {
- return error_show(1002, "订单code不存在");
- }
- $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
- // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
- // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "1";
- //$order_type = isset($this->post['order_type']) && $this->post['order_type'] !=="" ? $this->post['order_type'] :"1";
- //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
- Db::startTrans();
- try {
- $data = [
- "wsm_code" => "",
- "orderCode" => $orderCode,
- "outCode" => $outCode,
- "order_type" => $der['order_type'],
- "apply_id" => $rm,
- "apply_name" => $ri,
- "addrid" => $dr['id'],
- "post_name" => $post_name,
- "post_code" => $post_code,
- "post_fee" => $post_fee,
- "sendtime" => $sendtime,
- "send_num" => $send_num,
- "check_num" => 0,
- "error_num" => 0,
- "status" => $status,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $datainfo = Db::name('order_out')->insert($data, true);
- if ($datainfo > 0) {
- $stx = ["order_code" => $outCode, "status" => $status, "action_remark" => '', "action_type" => "create"];
- ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], $stx, $der['order_type'] == 1 ? "CKD" : 'ZXCKD', $status, $data);
- //是否库存品,待办数据推送到的人有区别,
- //库存品——>推到库管,非库存品——>推送供应商负责人
- $order=[];
- if($data['status'] == 1){
- if($der['is_stock'] == 1){
- //库存品,推给库管和库管-张凯旋
- $roleid = config('app.wsm_cgder_role');
- $uids = Db::name('user_role')
- ->where('is_del', 0)
- ->whereIn('roleid', $roleid)
- ->column('uid');
- $order = ["order_type" => "CKD", "order_code" => $outCode, "order_id" => $datainfo, "order_status" => $data['status'], "before_status" => 0, 'handle_user_list' => implode(',', $uids)];
- }else{
- //推给供应商负责人 ###todo::接口废弃
- $supplier = Db::name('supplier')
- ->alias('a')
- ->field('a.id,a.person,a.personid')
- ->leftJoin('purchease_order b', 'b.is_del=0 AND b.supplierNo=a.code')
- ->leftJoin('order_num c', 'c.cgdNo=b.cgdNo')
- ->where('c.orderCode', $orderCode)
- ->findOrEmpty();
- $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'] ?? ''];
- }
- }
- 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']];
- ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], $order);
- if ($status == 1) {
- $item = $der['status'];
- $der['send_num'] += $send_num;
- $der['wsend_num'] -= $send_num;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
- $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
- $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
- $der['updatetime'] = date("Y-m-d H:i:s");
- $si = Db::name('sale')->save($der);
- if ($si == false) {
- Db::rollback();
- return error_show(1003, "更新失败");
- }
- $stx = ["order_code" => $orderCode, "status" => $item, "action_remark" => '', "action_type" => "edit"];
- ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], $stx, "XSQRD", $der['status'], $der);
- $order = ["order_type" => "XSQRD", "order_code" => $orderCode, "order_id" => $der['id'], "order_status" => $data['status'], "before_status" => 0,'holder_id'=>$der['apply_id']];
- ProcessOrder::AddProcess(['id'=>$rm,'nickname'=>$ri], $order);
- }
- Db::commit();
- return error_show(0, "创建成功");
- } else {
- Db::rollback();
- return error_show(1003, "创建失败");
- }
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- // 废弃
- public function customer()
- {
- $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
- if (empty($outCode)) {
- return error_show(1002, "销售订单编号不能为空");
- }
- $codeinfo = Db::name('order_out')->where(['outCode' => $outCode])->find();
- if ($codeinfo == "") {
- return error_show(1003, "未找到订单数据");
- }
- // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
- // if($orderCode==""){
- // return error_show(1002,"参数orderCoder不能为空");
- // }
- $dr = Db::name('sale')->where(['orderCode' => $codeinfo['orderCode']])->find();
- if ($dr == "") {
- return error_show(1002, "未找到销售订单");
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "";
- if ($status == "") {
- return error_show(10002, "状态不能为空");
- }
- Db::startTrans();
- try {
- $time = $codeinfo['status'];
- $codeinfo['status'] = $status;
- $codeinfo['updatetime'] = date("Y-m-d H:i:s");
- $cust = Db::name('order_out')->save($codeinfo);
- if ($cust) {
- $stx = ["order_code" => $outCode, "status" => $time, "action_remark" => '', "action_type" => "status"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, "CKD", $codeinfo['status'], $codeinfo);
- $order = [];
- if ($status == 1) {
- //推给供应商负责人#todo::接口废弃
- if ($dr['is_stock'] == 0) {
- $supplier = Db::name('supplier')
- ->alias('a')
- ->field('a.id,a.person,a.personid')
- ->leftJoin('purchease_order b', 'b.is_del=0 AND b.supplierNo=a.code')
- ->leftJoin('order_num c', 'c.cgdNo=b.cgdNo')
- ->where('c.orderCode', $codeinfo['orderCode'])
- ->findOrEmpty();
- $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'] ?? ''];
- } else{
- $roleid = config('app.wsm_cgder_role');
- $uids = Db::name('user_role')
- ->where('is_del', 0)
- ->whereIn('roleid', $roleid)
- ->column('uid');
- $order = ["order_type" => "CKD", "order_code" => $outCode, "order_id" => $codeinfo['id'], "order_status" => $codeinfo['status'], "before_status" => 0, 'handle_user_list' => implode(',', $uids)];
- }
- }
- 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']];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
- if ($status == 1) {
- $stokc = Db::name("good_stock")->where(['spuCode' => $codeinfo['spuCode'], "wsm_code" => $codeinfo['wsm_code'],
- "is_del" => 0])->find();
- if ($stokc == false) {
- Db::rollback();
- return error_show(1002, "未找库存到数据");
- } else {
- if ($codeinfo['send_num'] > $stokc['usable_stock']) {
- Db::rollback();
- return error_show(1002, "超出库存数量");
- }
- $stokc['wait_out_stock'] += $codeinfo['send_num'];
- $stokc['usable_stock'] -= $codeinfo['send_num'];
- $stokc['updatetime'] = date("Y-m-d H:i:s");
- }
- $stoc = Db::name("good_stock")->save($stokc);
- if ($stoc == false) {
- Db::rollback();
- return error_show(1002, "库存更新失败");
- }
- $item = $dr['status'];
- $dr['send_num'] += $codeinfo['send_num'];
- $dr['wsend_num'] -= $codeinfo['send_num'];//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
- $dr['send_status'] = $dr['send_num'] == 0 ? 1 : $dr['wsend_num'] == 0 ? 3 : 2;
- $dr['status'] = $dr['send_num'] == 0 ? 3 : $dr['wsend_num'] == 0 ? 5 : 4;
- $dr['updatetime'] = date("Y-m-d H:i:s");
- $si = Db::name('sale')->save($dr);
- if ($si == false) {
- Db::rollback();
- return error_show(1003, "更新失败");
- }
- $stx = ["order_code" => $dr['orderCode'], "status" => $item, "action_remark" => '', "action_type" => "edit"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, $dr['order_type'] == 2 ? "ZXQRD" : "XSQRD", $dr['status'],$dr);
- $order = ["order_type" => "XSQRD", "order_code" => $dr['orderCode'], "order_id" => $dr['id'], "order_status" => $dr['status'], "before_status" => 0, 'holder_id' => $dr['apply_id']];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
- //商品变动日志表,good_log_code字段存储销售订单编号
- $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stoc['id'], "type" => 1, 'stock' => $codeinfo['send_num'], "stock_name" => "wait_out_stock"];
- $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stoc['id'], "type" => 2, 'stock' => $codeinfo['send_num'], "stock_name" => "usable_stock"];
- GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname], $good_data, 'CKD');
- }
- if ($status == 3) {
- $var = Db::name('good_stock')->where(['wsm_code' => $codeinfo['wsm_code'], 'good_type_code' => $dr['good_code']])->find();
- if ($var == false) {
- Db::rollback();
- return error_show(1002, "未找到商品数据");
- }
- if ($codeinfo['send_num'] > $var['intra_stock']) {
- Db::rollback();
- return error_show(1003, "超出在途库存数量");
- }
- $var['intra_stock'] -= $codeinfo['send_num'];
- $var['updatetime'] = date("Y-m-d H:i:s");
- $stre = Db::name('good_stock')->save($var);
- //商品变动日志表,good_log_code字段存储销售订单编号
- $good_data[] = ['good_log_code' => $outCode, "stock_id" => $var['id'], "type" => 2, 'stock' => $codeinfo['send_num'], "stock_name" => "intra_stock"];
- GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname], $good_data, $codeinfo['order_type'] == 2 ? "ZXCKD" : "CKD");
- if ($stre == false) {
- Db::rollback();
- return error_show(1002, "状态更新失败");
- }
- }
- Db::commit();
- return error_show(0, "出库订单更新成功");
- } else {
- Db::rollback();
- return error_show(1003, "出库订单更新失败");
- }
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- public function difflist()
- {
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
- $where = [];
- $cgdNo = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
- if ($cgdNo != "") {
- $where[] = ['a.orderCode', "like", "%$cgdNo%"];
- }
- $diffNo = isset($this->post['diffCode']) && $this->post['diffCode'] != "" ? trim($this->post['diffCode']) : "";
- if ($diffNo != "") {
- $where[] = ['a.diffCode', "like", "%$diffNo%"];
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
- if ($status !== "") {
- $where[] = ['a.status', "=", $status];
- }
- $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
- if ($start != "") {
- $where[] = ["a.addtime", '>=', $start];
- }
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
- if ($end != "") {
- $where[] = ["a.addtime", '<=', $end];
- }
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
- if ($companyNo != "") {
- $where[] = ['a.companyNo', "like", "%$companyNo%"];
- }
- $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
- if ($customer_code != "") {
- $where[] = ['a.customerNo', "like", "%$customer_code%"];
- }
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
- if ($supplierNo != "") {
- $where[] = ['a.supplierNo', "like", "%$supplierNo%"];
- }
- $relaComNo = trim($this->post['relaComNo'] ?? '');
- if ($relaComNo !== "") {
- $where[] = ['a.companyNo', "=", $relaComNo];
- }
- $order_source = isset($this->post['order_source']) && $this->post['order_source'] != "" ? trim($this->post['order_source']) : "";
- if ($order_source !== "") {
- $where[] = ['c.order_source', "=", $order_source];
- }
- $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] != "" ? trim($this->post['is_stock']) : "";
- if ($is_stock !== "") {
- $where[] = ['c.is_stock', "=", $is_stock];
- }
- // $role=$this->checkRole();
- // if(!empty($role['write'])){
- // $where[]=["apply_id","in",$role['write']];
- // }
- // $role = $this->checkDataShare();
- // if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['c.apply_id', 'in', $role[DataGroupModel::$type_全部]];
- $role = $this->checkDataShare();
- $hand = resign_hand_user($this->uid, 0);
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- $where[] = ['c.apply_id', 'in', $arr];
- }
- // if(!empty($role['platform']) ){
- // $where[]=["c.platform_id","in",$role['platform']];
- // }
- $count = Db::name('sale_diff')
- ->alias('a')
- ->join("sale c", "c.orderCode=a.orderCode", "left")
- // ->join("customer_info v", "v.companyNo=c.customer_code", "left")
- ->where($where)
- ->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? intval($total) : $page;
- $list = Db::name('sale_diff')
- ->alias('a')
- ->field("a.*,c.skuCode,c.order_type,c.apply_id,c.order_source,c.is_stock")
- ->join("sale c", "c.orderCode=a.orderCode", "left")
- // ->join("customer_info v", "v.companyNo=c.customer_code", "left")
- ->where($where)
- ->page($page, $size)
- ->order("a.addtime desc")
- ->select()
- ->toArray();
- $data = [];
- // $userCommon = \app\admin\common\User::getIns();
- // $names = $userCommon->handle('getCodeAndName',['code'=>array_merge(array_column($list,'supplierNo'),array_column($list,'customer_code'))]);
- foreach ($list as $value) {
- if (in_array($value['order_type'], [3, 4])) {
- $goon = Db::name("good_zixun")->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
- } else {
- $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $value['skuCode']])->find();
- }
- $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
- // $wsm = Db::name("business")->where(['companyNo' => $value['supplierNo']])->find();
- // $value['supplierNo'] = $value['supplierNo'];//isset($wsm['companyNo']) ? $wsm['companyNo'] : "";
- // $value['supplierName'] = $names['data'][$value['supplierNo']] ?? '';//isset($wsm['company']) ? $wsm['company'] : "";
- // $value['customer_name'] = $names['data'][$value['customer_code']] ?? '';//isset($wsm['company']) ? $wsm['company'] : "";
- //是否具有编辑权限
- $value['is_allow_update'] = 0;
- if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
- $data[] = $value;
- }
- return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- //工差单审核
- public function diffcheck()
- {
- // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- if ($id === "") {
- return error_show(1004, "参数id不能为空");
- }
- $info = Db::name("sale_diff")->where(["id" => $id])->find();
- if (empty($info)) {
- return error_show(1004, "订单数据未找到");
- }
- $sale = Db::name("sale")->where(["orderCode" => $info["orderCode"]])->find();
- if ($sale == false) {
- return error_show(1004, "订单数据未找到");
- }
- $cgd = Db::name("purchease_diff")->where(['id' => $info['cgd_diffid']])->find();
- if ($cgd == false) {
- return error_show(1004, "采购工差单数据未找到");
- }
- $is_act = isset($this->post['is_act']) && $this->post['is_act'] !== "" ? intval($this->post['is_act']) : "";
- if ($is_act === '') {
- return error_show(1004, "参数is_act不能为空");
- }
- $customer_remark = isset($this->post['customer_remark']) && $this->post['customer_remark'] !== "" ? trim($this->post['customer_remark']) : "";
- if ($customer_remark === '') {
- return error_show(1004, "参数customer_remark不能为空");
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "2";
- $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
- $item = $info['status'];
- $info['is_act'] = $is_act;
- $info['customer_remark'] = $customer_remark;
- $info['status'] = $status;
- $info['remark'] = $remark;
- $info['updatetime'] = date("Y-m-d H:i:s");
- Db::startTrans();
- try {
- $up = Db::name("sale_diff")->save($info);
- if ($up) {
- $stx = ["order_code" => $info["orderCode"], "status" => $item, "action_remark" => '', "action_type" => "edit"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, "XSGCD", $info['status'], $info);
- $order = ["order_type" => "XSGCD", "order_code" => $info["orderCode"], "order_id" => $info['id'], "order_status" => $info['status'], "before_status" => $item,'holder_id'=>$sale['apply_id']];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
- $upda = [
- "status" => $status,
- "remark" => $remark,
- "updatetime" => date("Y-m-d H:i:s"),
- ];
- $old_purchease_diff = Db::name("purchease_diff")
- ->field('id,cgdNo,status')
- ->where(["id" => $info['cgd_diffid']])
- ->find();
- $cgdup = Db::name("purchease_diff")->where(["id" => $info['cgd_diffid']])->save($upda);
- if ($cgdup) {
- if ($status == 2) {
- if ($customer_remark == 1) {
- $sale['diff_weight'] = $info['diff_weight'];
- $sale['diff_fee'] = $info['diff_price'];
- $sale['updatetime'] = date("Y-m-d H:i:s");
- $sal = Db::name("sale")->save($sale);
- if ($sal == false) {
- Db::rollback();
- return error_show(1003, "订单更新工差失败");
- }
- }
- $cgdup = Db::name("purchease_order")->where(["cgdNo" => $cgd['cgdNo']])->save
- (["diff_weight" => $cgd['diff_weight'], "diff_fee" => $cgd['diff_price'], "updatetime" => date("Y-m-d H:i:s")]);
- if ($cgdup == false) {
- Db::rollback();
- return error_show(1003, "采购订单更新工差失败");
- }
- }
- $a = ["order_code" => $old_purchease_diff["cgdNo"], "status" => $old_purchease_diff['status'], "action_remark" => '', "action_type" => "status"];
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $a, "CGGCD", $upda['status'], $info);
- $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']];
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $b);
- Db::commit();
- return app_show(0, "更新成功");
- }
- }
- Db::rollback();
- return error_show(1003, "更新失败");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1003, $e->getMessage());
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function diffstatus()
- {
- // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- if ($id === "") {
- return error_show(1004, "参数id不能为空");
- }
- $info = Db::name("sale_diff")->where(["id" => $id])->find();
- if ($info == false) {
- return error_show(1004, "工差单数据未找到");
- }
- $sale = Db::name("sale")->where(["orderCode" => $info["orderCode"]])->find();
- if ($sale == false) {
- return error_show(1004, "订单数据未找到");
- }
- $cgd = Db::name("purchease_diff")->where(['id' => $info['cgd_diffid']])->find();
- if ($cgd == false) {
- return error_show(1004, "采购工差单数据未找到");
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "3";
- $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
- $ite = $info['status'];
- Db::startTrans();
- try {
- $upda = [
- "status" => $status,
- "remark" => $remark,
- "updatetime" => date("Y-m-d H:i:s"),
- ];
- $up = Db::name("sale_diff")->where($info)->save($upda);
- if ($up) {
- $stx = ["order_code" => $info["orderCode"], "status" => $ite, "action_remark" => '', "action_type" => "status"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stx, "XSGCD", $status, $info);
- $order = ["order_type" => "XSGCD", "order_code" => $info["orderCode"], "order_id" => $info['id'],"order_status" => $status, "before_status" => $ite,'holder_id'=>$sale['apply_id']];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], $order);
- $cgdup = Db::name("purchease_diff")->where(["id" => $info['cgd_diffid']])->save($upda);
- if ($cgdup) {
- if ($status == 2 && $info['customer_remark'] == 1) {
- $sale['diff_weight'] = $info['diff_weight'];
- $sale['diff_fee'] = $info['diff_price'];
- $sale['updatetime'] = date("Y-m-d H:i:s");
- $sal = Db::name("sale")->save($sale);
- if ($sal == false) {
- Db::rollback();
- return error_show(1003, "订单更新工差失败");
- }
- }
- Db::commit();
- return app_show(0, "更新成功");
- }
- }
- Db::rollback();
- return error_show(1003, "更新失败");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1003, $e->getMessage());
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function diffinfo()
- {
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- if ($id === "") {
- return error_show(1004, "参数id不能为空");
- }
- $info = Db::name('sale_diff')->where(["id" => $id])->find();
- if (empty($info)) {
- return error_show(1004, "工差订单数据未找到");
- }
- $einfo = Db::name('sale')->where(['orderCode' => $info['orderCode'], 'is_del' => 0])->find();
- if ($einfo == false) {
- return error_show(1002, "未找到销售订单数据");
- }
- if (in_array($einfo['order_type'], [3, 4])) {
- $goon = Db::name("good_zixun")->where(["spuCode" => $einfo['good_code'], "is_del" => 0])->find();
- } else {
- $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $einfo['skuCode']])->find();
- }
- if ($goon == false) {
- return error_show(1002, "未找到商品数据");
- }
- $info['skuCode'] = isset($goon['skuCode']) ? $goon['skuCode'] : "";
- $info['spuCode'] = isset($goon['spuCode']) ? $goon['spuCode'] : "";
- $info['order_type'] = isset($einfo['order_type']) ? $einfo['order_type'] : "";
- $info['can'] = isset($info['cat_id']) && $info['cat_id'] !== 0 ? made($info['cat_id']) : [];
- return app_show(0, "获取成功", $info);
- }
- //发货申请单列表
- public function saleout()
- {
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
- $where = [["a.is_del", "=", 0]];
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
- if ($orderCode !== "") {
- $where[] = ['a.orderCode', "like", "%$orderCode%"];
- }
- $order_type = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? trim($this->post['order_type']) : "";
- if ($order_type !== "") {
- $where[] = ['a.order_type', "=", $order_type];
- }
- $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
- if ($outCode !== "") {
- $where[] = ['a.outCode', "like", "%$outCode%"];
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name']) : "";
- if ($apply_name !== "") {
- $where[] = ['a.apply_name', "like", "%$apply_name%"];
- }
- $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
- if ($good_code !== "") {
- $where[] = ['b.good_code', "like", "%$good_code%"];
- }
- $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
- if ($good_name !== "") {
- $where[] = ['b.good_name', "like", "%$good_name%"];
- }
- $supplier_name = isset($this->post['supplier_name']) && $this->post['supplier_name'] !== "" ? trim($this->post['supplier_name']) : "";
- if ($supplier_name !== "") {
- $where[] = ['b.supName', "like", "%$supplier_name%"];
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
- if ($status !== "") {
- $where[] = ['a.status', "=", $status];
- }
- $send_status = isset($this->post['send_status']) && $this->post['send_status'] !== "" ? trim($this->post['send_status']) : "";
- if ($send_status !== "") {
- $where[] = ['a.send_status', "=", $send_status];
- }
- $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
- if ($start != "") {
- $where[] = ["a.addtime", '>=', $start . " 00:00:00"];
- }
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
- if ($end != "") {
- $where[] = ["a.addtime", '<=', $end . " 23:59:59"];
- }
- $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
- if ($companyNo != "") {
- $where[] = ['b.supplierNo', "like", "%$companyNo%"];
- }
- $customer_code = isset($this->post['customerCode']) && $this->post['customerCode'] !== "" ? trim($this->post['customerCode']) : "";
- if ($customer_code != "") {
- $where[] = ['b.customer_code', "like", "%$customer_code%"];
- }
- $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo'] !== "" ? trim($this->post['relaComNo']) : "";
- if ($relaComNo != '') $where[] = ['b.supplierNo', '=', $relaComNo];
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
- if ($supplierNo != '') {
- //sale b 表里存的supplierNo值是GS开头的,即业务公司编码
- //所以此处应该根据供应商编码筛选商品spuCode,然后筛选发货单
- $spuCode = Db::name('good_basic')
- ->where(['is_del' => 0, 'supplierNo' => $supplierNo])
- ->column('spuCode');
- $where[] = ['b.good_code', 'in', $spuCode];
- }
- $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo'] !== "" ? $this->post['cgdNo'] : "";
- if ($cgdNo != "") {
- $where[] = ["os.cgdNo", 'like', '%' . $cgdNo . '%'];
- }
- $condition = '';
- $level= isset($this->post['level']) && $this->post['level'] !== '' ? $this->post['level'] : '0';
- //只有level2的账号过滤数据权限
- if ($level=='0'&& $this->level == 2) {
- // //如果是供应商负责人,根据供应商筛选
- // $person_supplier = Db::connect('mysql_sys')
- // ->name('supplier')
- // ->where(['is_del' => 0, 'personid' =>$this->uid])
- // ->column('code');
- //
- // if(!empty($person_supplier)) $condition = "b.supNo in ('" . implode('\',\'', $person_supplier) . "')";
- // else{
- //不是供应商负责人,根据数据权限筛选申请人
- $role = $this->checkDataShare();
- if (!empty($role[DataGroupModel::$type_全部])) $condition = " a.apply_id in (" . implode(',', $role[DataGroupModel::$type_全部]) . ")";
- // }
- // $hand = resign_hand_user($this->uid, 0);
- // $uidarr = implode(",", $hand);
- // //库管只能看到库存品订单,供应商负责人只能看到非库存品订单
- // if (!in_array($this->roleid, [1, 33])) {
- // //库管看到所有的库存品发货申请单
- // if (in_array($this->roleid, config('app.wsm_cgder_role'))) $condition .= " b.is_stock=1";
- // else {
- // $role = $this->checkDataShare();
- // if (!empty($role[DataGroupModel::$type_全部])) {
- // $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- // if ($condition != '') $condition .= " or ";
- // $condition .= " a.apply_id in (" . implode(',', $arr) . ")";
- // }
- // }
- //// $personid = Db::name('supplier')->field('id')->where(['is_del' => 0, 'personid' => $hand])->findOrEmpty();
- // if (!empty($hand)) {
- // if ($condition != '') $condition .= " or ";
- //// $condition .= "(b.is_stock=0 and sip.personid in ($uidarr))";
- //
- // $person_supplier = Db::connect('mysql_sys')
- // ->name('supplier')
- // ->where(['is_del'=>0,'personid'=>$uidarr])
- // ->column('code');
- //
- // $condition .= "(b.is_stock=0 and wpo.supplierNo in ('" . implode('\',\'', $person_supplier) . "'))";
- // }
- // }
- }
- // if(!empty($role['platform']) ){
- // $where[]=["b.platform_id","in",$role['platform']];
- // }
- $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($company_name !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($company_name)];
- //发货时间筛选
- $start_sendtime = isset($this->post['start_sendtime']) && $this->post['start_sendtime'] !== "" ? $this->post['start_sendtime'] : "";
- $end_sendtime = isset($this->post['end_sendtime']) && $this->post['end_sendtime'] !== "" ? $this->post['end_sendtime'] : "";
- if ($start_sendtime != "" && $end_sendtime != "") {
- $where[] = ["a.sendtime", 'between', [$start_sendtime . " 00:00:00", $end_sendtime . " 23:59:59"]];
- $where[] = ["a.status", '>=', 2];//搜索发货时间时,要指定状态为已发货及之后的状态值(0待发货,1待库管发货,2已发货待收货,3已收货,4已全部退货',)
- }
- $order_source = isset($this->post['order_source']) && $this->post['order_source'] !== "" ? intval($this->post['order_source']) : "";
- if ($order_source !== "") $where[] = ["b.order_source", '=', $order_source];
- $use_type = $this->post['use_type']??'';
- if($use_type!=='') $where[]=['p.use_type','=',$use_type];
- $count = Db::name('order_out')
- ->alias('a')
- ->join("sale b", "b.orderCode=a.orderCode", "left")
- // ->join("customer_info v", "v.companyNo=b.customer_code", "left")
- ->join("warehouse_info n", "n.wsm_code=a.wsm_code", "left")
- ->leftJoin("order_send os", "os.outCode=a.outCode")
- ->leftJoin("platform p", "p.id=b.platform_id")
- // ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
- // ->leftJoin('supplier sip', 'sip.code=wpo.supplierNo')
- ->where($where)
- ->where($condition)
- ->count('a.id');
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('order_out')
- ->alias('a')
- ->join("sale b", "b.orderCode=a.orderCode", "left")
- // ->join("customer_info v", "v.companyNo=b.customer_code", "left")
- ->join("warehouse_info n", "n.wsm_code=a.wsm_code AND n.is_del=0", "left")
- ->leftJoin("order_send os", "os.outCode=a.outCode")
- ->leftJoin("platform p", "p.id=b.platform_id")
- // ->leftJoin("purchease_order wpo", "wpo.cgdNo=os.cgdNo")
- // ->leftJoin('supplier sip', 'sip.code=wpo.supplierNo')
- ->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")
- ->where($where)
- ->where($condition)
- ->order("addtime desc")
- ->page($page, $size)
- ->select()
- ->toArray();
- $all_createrid = array_column($list, 'apply_id');
- $item = get_company_name_by_uid($all_createrid);
- $user = \app\admin\common\User::getIns();
- $names = $user->handle("getCodeAndName", ["code" => array_merge( array_column($list, "supplierNo"), array_column($list, "wsm_supplierNo"))]);
- // $userCommon = \app\admin\common\User::getIns();
- // $names = $userCommon->handle('getCodeAndName',['code'=>array_column($list,'customer_code')]);
- $has_account = checkHasAccountBySupplierNos(array_unique(array_column($list,'wsm_supplierNo')));
- $data = [];
- foreach ($list as $value) {
- // $value['companyName'] = $names['data'][$value['customer_code']] ?? '';
- if ($value['order_type'] == 1 && $value['wsm_code'] == '') {
- // $wsmcode = Db::name("good")->alias("a")
- // ->leftJoin("supplier b","a.supplierNo=b.code")
- // ->where(["a.spuCode"=>$value['good_code']])->field("'' wsm_name,b.name,b.code")->find();
- $value['wsm_supplierNo'] = $value['supplierNo'];
- $value['wsm_supplier'] = $names['data'][$value['supplierNo']] ?? "";
- } else {
- // $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
- // ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
- $value['wsm_supplier'] = $names['data'][$value['wsm_supplierNo']] ?? "";
- }
- $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
- if ($addr) {
- $addinfo = $addr['addr_code'] != '' ? json_decode($addr['addr_code'], true) ?? $addr['addr_code'] : '';
- if (is_string($addinfo) && $addinfo != '') {
- $addinfo = ["provice_code" => '', "city_code" => '', "area_code" => ''];
- list($addinfo['provice_code'], $addinfo['city_code'], $addinfo['area_code']) = explode(",", $addr['addr_code']);
- }
- $addr['addr_cn'] = GetAddr(json_encode($addinfo));
- }
- if (in_array($value['order_type'], [3, 4])) {
- $goon = Db::name("good_zixun")->field('id,cat_id')->where(["spuCode" => $value['good_code'], "is_del" => 0])->find();
- } else {
- $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();
- }
- $value['wsm_has_account'] = (int)isset($has_account[$value['wsm_supplierNo']]);
- $value['addr'] = isset($addr['addr']) ? $addr['addr_cn'] . $addr['addr'] : "";
- $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
- $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
- $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
- $value['company_name'] = $item[$value['apply_id']] ?? '';
- $value['sendtime'] = $value['status'] < 2 ? '' : $value['sendtime'];
- //是否具有编辑权限
- // $value['is_allow_update'] = 0;
- // if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
- $data[] = $value;
- }
- return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
- }
- public function outinfo()
- {
- $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
- if ($outCode == "") {
- return error_show(1002, "参数outcode不能为空");
- }
- $codeinfo = Db::name("order_out")->where(['outCode' => $outCode, "is_del" => 0])->find();
- if (empty($codeinfo)) {
- return error_show(1002, "未找到出库数据");
- }
- $item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
- if ($item['order_type'] == 3 ||$item['order_type'] == 4 ) {
- $goodinfo = Db::name("good_zixun")->where(["spuCode" => $item['good_code'], "is_del" => 0])->find();
- if ($goodinfo == false) {
- return error_show(1004, "未找到商品数据");
- }
- } else {
- $goodinfo = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $item['skuCode']])->find();
- if ($goodinfo == false) {
- return error_show(1002, "未找到商品数据");
- }
- }
- $int = isset($goodinfo['cat_id']) && $goodinfo['cat_id'] != 0 ? made($goodinfo['cat_id']) : [];
- $addr = Db::name("order_addr")->where(["id" => $codeinfo['addrid']])->find();
- if($addr){
- $addinfo =$addr['addr_code']!=''?json_decode($addr['addr_code'],true)??$addr['addr_code']: '' ;
- if(is_string($addinfo)&&$addinfo!=''){
- $addinfo=["provice_code"=>'',"city_code"=>'',"area_code"=>''];
- list($addinfo['provice_code'],$addinfo['city_code'],$addinfo['area_code']) = explode(",",$addr['addr_code']);
- }
- $addr['addr_cn'] =GetAddr(json_encode($addinfo));
- }
- $codeinfo['good_name'] = isset($item['good_name']) ? $item['good_name'] : "";
- $codeinfo['good_num'] = isset($item['good_num']) ? $item['good_num'] : "";
- $codeinfo['good_code'] = isset($item['good_code']) ? $item['good_code'] : "";
- $codeinfo['origin_price'] = isset($item['origin_price']) ? $item['origin_price'] : "";
- $codeinfo['sale_price'] = isset($item['sale_price']) ? $item['sale_price'] : "";
- $codeinfo['total_price'] = isset($item['total_price']) ? $item['total_price'] : "";
- $codeinfo['skuCode'] = isset($item['skuCode']) ? $item['skuCode'] : "";
- $codeinfo['addr'] = $addr['addr_cn']??'';
- $codeinfo['addr'] .= isset($addr['addr']) ? $addr['addr'] : "";
- $codeinfo['addr_code'] = isset($addr['addr_code']) ? $addr['addr_code'] : "";
- $codeinfo['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
- $codeinfo['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
- $codeinfo['sendtime'] = $codeinfo['status'] < 2 ? '' : $codeinfo['sendtime'];
- $codeinfo['can'] = $int;
- $codeinfo['order_source'] = $item['order_source'];
- $orderReturn = Db::name("order_return")->where(["outCode" => $outCode, "is_del" => 0])->order("id desc")->find();
- $codeinfo['order_return'] = $orderReturn;
- $codeinfo['platform_order'] = $item['platform_order'];
- //获取销售订单对应的供应商是否有启用账号
- $codeinfo['has_account'] = 0;
- $supplierNo = Db::name('order_num')
- ->alias('a')
- ->leftJoin('purchease_order b', 'b.cgdNo=a.cgdNo')
- ->where('a.orderCode', $codeinfo['orderCode'])
- ->value('b.supplierNo');
- if ($supplierNo) {
- $has_account = checkHasAccountBySupplierNos([$supplierNo]);
- $codeinfo['has_account'] = (int)isset($has_account[$supplierNo]);
- }
- $saleinfo=Db::name("sale_info")->where([["orderCode","=",$codeinfo['orderCode']],["num",">",0]])->select()
- ->toArray();
- if(!empty($saleinfo)){
- $stockidArr=array_column($saleinfo,"stockid");
- $wsm=Db::name("good_stock")->alias("a")
- ->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")
- ->where("a.id","in",$stockidArr)
- ->column("a.wsm_code,name","a.id");
- foreach ($saleinfo as &$item){
- $item['wsm_code'] = $wsm[$item['stockid']]['wsm_code'];
- $item['wsm_name'] = $wsm[$item['stockid']]['name'];
- }
- }
- $codeinfo["saleinfo"] = $saleinfo;
- return app_show(0, "获取成功", $codeinfo);
- }
- public function outadd()
- {
- // $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
- if ($orderCode == "") {
- return error_show(1002, "参数orderCoder不能为空");
- }
- $retrun =Db::name("sale_return")->where([["orderCode","=",$orderCode],["is_del","=",0],["status","in",[1,2,3,
- 7,9,10,8,11,12]]])->count();
- if($retrun>0){
- return error_show(1005,"存在未完成退货订单数据");
- }
- $der = Db::name('sale')->where(['orderCode' => $orderCode, "is_del" => 0])->find();
- if ($der == "") {
- return error_show(1002, "未找到出库订单单号");
- }
- $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
- if ($send_num == "") {
- return error_show(1002, "发货数量不能为空");
- }
- $wsed = Db::name("order_out")->where(["orderCode" => $orderCode])->where([["status", "<", 2], ["is_del", "=", 0]])->sum
- ('send_num');
- if ($send_num > $der['wsend_num'] - $wsed) {
- return error_show(1002, "超出可发货数量");
- }
- $contactor = isset($this->post['contactor']) && $this->post['contactor'] != "" ? trim($this->post['contactor']) : "";
- if ($contactor == "") {
- return error_show(1002, "参数contactor不能为空");
- }
- $mobile = isset($this->post['mobile']) && $this->post['mobile'] != "" ? trim($this->post['mobile']) : "";
- if ($mobile == "") {
- return error_show(1002, "参数mobile不能为空");
- }
- $addr = isset($this->post['addr']) && $this->post['addr'] != "" ? trim($this->post['addr']) : "";
- if ($addr == "") {
- return error_show(1002, "参数addr不能为空");
- }
- $addr_code = isset($this->post['addr_code']) && $this->post['addr_code'] != "" ? trim($this->post['addr_code']) : "";
- // if ($addr_code == "") {
- // return error_show(1002, "参数addr_code不能为空");
- // }
- // $apply_id = GetUserInfo($token);
- // if (empty($apply_id) || $apply_id['code'] != 0) {
- // return error_show(1002, "申请人数据不存在");
- // }
- $rm = $this->uid;//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri = $this->uname;//isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
- Db::startTrans();
- try {
- $addrlst = [
- "orderCode" => $orderCode,
- "addr" => $addr,
- "addr_code" => $addr_code!=''?json_encode($addr_code):'',
- "contactor" => $contactor,
- "mobile" => $mobile,
- "customer_code" => $der['customer_code'],
- "post_fee" => $der['post_fee'],
- "arrive_time" => $sendtime,
- "receipt_quantity" => $send_num,
- "is_del" => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $addrid = Db::name("order_addr")->insert($addrlst, true);
- if ($addrid > 0) {
- $outCode = makeNo("DF");
- $order=[];
- if($der['order_type']!=1){
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
- ->lock(true)->find();
- if ($order == false) {
- Db::rollback();
- return error_show(1004, "未找到可以发货得采购单数据");
- }
- $cgd = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
- if ($cgd == false) {
- Db::rollback();
- return error_show(1002, "未找到对应的采购单数据");
- }
- $order['wsend_num'] -= $send_num;
- $order['send_num'] += $send_num;
- $or = Db::name("order_num")->save($order);
- if ($or == false) {
- Db::rollback();
- return error_show(1002, "发货地址添加创建失败");
- }
- $tep = [
- "cgdNo" => $order['cgdNo'],
- "outCode" => $outCode,
- "send_num" => $send_num,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $sen = Db::name("order_send")->save($tep);
- if ($sen == false) {
- Db::rollback();
- return error_show(1002, "发货地址添加创建失败");
- }
- }else{
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
- ->lock(true)->find();
- if ($order!= false) {
- $cgd = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
- if ($cgd == false) {
- Db::rollback();
- return error_show(1002, "未找到对应的采购单数据");
- }
- $order['wsend_num'] -= $send_num;
- $order['send_num'] += $send_num;
- $or = Db::name("order_num")->save($order);
- if ($or == false) {
- Db::rollback();
- return error_show(1002, "发货地址添加创建失败");
- }
- $tep = [
- "cgdNo" => $order['cgdNo'],
- "outCode" => $outCode,
- "send_num" => $send_num,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $sen = Db::name("order_send")->save($tep);
- if ($sen == false) {
- Db::rollback();
- return error_show(1002, "发货地址添加创建失败");
- }
- }else{
- $order['cgdNo']='';
- $cgd=[];
- }
- }
- $data = [
- "wsm_code" => isset($cgd['wsm_code']) ? $cgd['wsm_code'] : "",
- "orderCode" => $orderCode,
- "outCode" => $outCode,
- "order_type" => $der['order_type'],
- "apply_id" => $rm,
- "apply_name" => $ri,
- "addrid" => $addrid,
- "post_name" => "",
- "post_code" => "",
- "post_fee" => "",
- "sendtime" => $sendtime,
- "send_num" => $send_num,
- "check_num" => 0,
- "error_num" => 0,
- "send_status" => 1,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- if ($der['is_stock'] == 0) {
- //维护商品所在仓库的库存 --- start
- $temp = Db::name('good_stock')
- ->field('id,usable_stock,wait_out_stock')
- ->where(['spuCode' => $der['good_code'], 'wsm_code' => $cgd['wsm_code']])
- ->find();
- if (($temp == false || ($temp['usable_stock'] - $send_num) < 0) && $der['send_type'] == 1) {
- Db::rollback();
- return error_show(1004, '库存不足');
- } else {
- if (($temp == false || ($temp['usable_stock'] - $send_num) < 0) && $der['send_type'] == 2) {
- $data['status'] = 0;
- } else {
- //这个地方不需要更新,因为后面尝试拆单的时候会维护库存数
- // $up = Db::name('good_stock')
- // ->where('id', $temp['id'])
- // ->update([
- // 'usable_stock' => $temp['usable_stock'] - $send_num,
- // 'wait_out_stock' => $temp['wait_out_stock'] + $send_num,
- // 'updatetime' => date('Y-m-d H:i:s'),
- // ]);
- // if ($up == false) {
- // Db::rollback();
- // return error_show(1004, '库存更新失败');
- // }
- // ::todo
- // $good_data[] = ['good_log_code' => $outCode, "stock_id" => $temp['id'], "type" => 1, 'stock' => $send_num, "stock_name" => "wait_out_stock"];
- // $good_data[] = ['good_log_code' => $outCode, "stock_id" => $temp['id'], "type" => 2, 'stock' => $send_num, "stock_name" => "usable_stock"];
- // GoodLog::LogAdd(['id'=>$this->uid,'nickname'=>$this->uname], $good_data, "CKD");
- }
- }
- }
- $datainfo = Db::name('order_out')->insert($data, true);
- if ($datainfo > 0) {
- //修改状态,添加待办
- ActionLog::logAdd(['id'=>$rm,'nickname'=>$ri], [
- "order_code" => $data['outCode'],//出库单号
- "status" => $data['status'],//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "create"//新建create,编辑edit,更改状态status
- ], "CKD", $data['status'], $data);
- //是否库存品,待办数据推送到的人有区别,
- $process = [];
- if ($data['status'] == 1) {
- if ($data['send_status'] == 1) OrderOutChild::makeChild($outCode);//尝试拆单
- if ($der['is_stock'] == 1) {
- //库存品,推给库管和库管-张凯旋
- $roleid = config('app.wsm_cgder_role');
- $uids = Db::name('user_role')
- ->where('is_del', 0)
- ->whereIn('roleid', $roleid)
- ->column('uid');
- $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)];
- } else{
- //推给供应商负责人
- // $supplier = Db::name('supplier')
- // ->field('person,personid')
- // ->where('code', $cgd['supplierNo'])
- // ->findOrEmpty();
- $userCommon= \app\admin\common\User::getIns();
- $supplier_temp =$userCommon->handle("sInfo",["code"=>$cgd['supplierNo']]);
- if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1002,"采购单供应商不存在");
- $holder_id=$supplier_temp['data']['personid']??0;
- $holder_name=$supplier_temp['data']['personid']??0;
- $process = ["order_type" => 'CKD', "order_code" => $data['outCode'], "order_id" =>
- $datainfo, "order_status" => $data['status'], "before_status" => 0, 'holder_id' => $data['apply_id'], 'wait_id' => $holder_id, 'wait_name' => $holder_name,];
- }
- }
- 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']];
- ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], $process);
- //维护台账记录
- Db::name('standing_book')
- ->where('orderCode', $orderCode)
- ->update([
- 'order_type' => $der['order_type'],
- 'order_source' => $der['order_source'],
- 'cgdNo' => $order['cgdNo'],
- 'customer_code' => $der['customer_code'],
- 'updatetime' => date('Y-m-d H:i:s'),
- ]);
- Db::execute("UPDATE `wsm_standing_book` SET `outCode`=CONCAT(IFNULL(`outCode`,''),',{$outCode}') WHERE `cgdNo`='{$order['cgdNo']}'");
- Db::commit();
- return app_show(0, "出库单新建成功");
- }
- }
- Db::rollback();
- return error_show(1004, "出库单新建失败");
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- //库管发货
- public function outSend()
- {
- $outCode = isset($this->post['outCode']) && $this->post['outCode'] != "" ? trim($this->post['outCode']) : "";
- if ($outCode == "") {
- return error_show(1004, "参数outCode不能为空");
- }
- $outinfo = Db::name("order_out")->where(["outCode" => $outCode, "is_del" => 0])->find();
- if ($outinfo == false) {
- return error_show(1004, "发货数据未找到");
- }
- if($outinfo['status']!=1){
- return error_show(1004, "发货状态有误");
- }
- $einfo = Db::name('sale')->where(['orderCode' => $outinfo['orderCode'], 'is_del' => 0])->find();
- if (empty($einfo)) {
- return error_show(1002, "未找到销售订单数据");
- }
- //判断供应商是否开通账号,若开通的话,则只能由供应商账号操作
- if ($this->level != 3) {
- $temp = checkHasAccountBySupplierNos([$einfo['supNo']]);
- if (isset($temp[$einfo['supNo']])) return json_show(1004, '非供应商账号不能操作');
- }
- $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();
- if ($is_reurn != false) {
- return error_show(1002, "销售单存在退货未处理完成");
- }
- $post_name = isset($this->post['post_name']) && $this->post['post_name'] != "" ? trim($this->post['post_name']) : "";
- if ($post_name == "") {
- return error_show(1004, "参数post_name不能为空");
- }
- $post_code = isset($this->post['post_code']) && $this->post['post_code'] != "" ? trim($this->post['post_code']) : "";
- if ($post_code == "") {
- return error_show(1004, "参数post_code不能为空");
- }
- $remark = isset($this->post['remark']) && $this->post['remark'] != "" ? trim($this->post['remark']) : "";
- $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] != "" ? floatval($this->post['post_fee']) : "";
- $outinfo['post_name'] = $post_name;
- $outinfo['post_code'] = $post_code;
- $outinfo['post_fee'] = $post_fee;
- $outinfo['sendtime'] = date("Y-m-d H:i:s");
- $old_outinfo_status = $outinfo['status'];
- $outinfo['status'] = 2;
- $outinfo['updatetime'] = date("Y-m-d H:i:s");
- $outinfo['remark'] = $remark;
- if ($einfo['wsend_num'] < $outinfo['send_num']) {
- return error_show(1004, "订单未发货数量不足");
- }
- Db::startTrans();
- try {
- $up = Db::name("order_out")->where(["outCode"=>$outCode,"status"=>1,"is_del"=>0])->update($outinfo);
- // $user_info = GetUserInfo($this->post['token']);
- $uid = $this->uid;//isset($user_info['data']['id']) ? $user_info['data']['id'] : 0;
- $uname = $this->uname;//isset($user_info['data']['nickname']) ? $user_info['data']['nickname'] : '';
- if ($einfo['is_stock'] == 1) {
- //由于存在一个单子对应多个仓库的情况,因此库存品的判断暂时无法进行,待分仓功能完成后再考虑
- //如果是库存品,只能由库管操作
- // $contactor = Db::name('warehouse_info')
- // ->where(['wsm_code' => $outinfo['wsm_code'], 'is_del' => 0])
- // ->value('contactor');
- // $own_roleid = Db::name('user_role')->where(['is_del'=>0,'uid'=>$uid,'status'=>1])->value('roleid',0);
- // if ($uid != $contactor) throw new \think\Exception('库存品只能由库管人员操作');
- } elseif ($einfo['is_stock'] == 0) {
- //非库存品和采返商品只能由供应商负责人操作
- if ($einfo['order_type'] == 3 || $einfo['order_type'] ==4 ) {
- $supplierNo = Db::name('good_zixun')
- // ->leftJoin("supplier b", "a.supplierNo=b.code")
- ->where(['spuCode' => $einfo['good_code'], 'is_del' => 0])
- ->value('supplierNo');
- } else {
- $supplierNo = Db::name('good')
- // ->alias("a")
- // ->leftJoin("supplier b", "a.supplierNo=b.code")
- ->where(['spuCode' => $einfo['good_code'], 'is_del' => 0])
- ->value('supplierNo');
- }
- // $userCommon = \app\admin\common\User::getIns();
- // $temp = $userCommon->handle('sInfo', ['code' => $supplierNo]);
- $temp = get_personid_by_supplierNo([$supplierNo]);
- if (($this->level == 2) && ($uid != $temp[$supplierNo])) throw new \think\Exception('非库存品和采返商品只能由供应商负责人操作');
- }
- if ($up) {
- //修改状态,添加待办
- ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], [
- "order_code" => $outinfo['outCode'],//出库单号
- "status" => $old_outinfo_status,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "edit"//新建create,编辑edit,更改状态status
- ], "CKD", $outinfo['status'], $outinfo);
- ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], [
- "order_type" => 'CKD',
- "order_code" => $outinfo['outCode'],//出库单号
- "order_id" => $outinfo['id'],
- "order_status" => $outinfo['status'],
- "before_status" => $old_outinfo_status,
- 'wait_id'=>$outinfo['apply_id'],
- 'wait_name'=>$outinfo['apply_name'],
- 'holder_id'=>$outinfo['apply_id'],
- ]);
- if($einfo['wsend_num']<$outinfo['send_num']){
- Db::rollback();
- return error_show(1002, "订单待付货数量不足");
- }
- $orderstatus = $einfo['status'];
- $einfo['send_num'] += $outinfo['send_num'];
- $einfo['wsend_num'] -= $outinfo['send_num'];
- $einfo['status'] = $einfo['wsend_num'] == 0 ? 2 : ($einfo['send_num'] == 0 ? 0 : 1);
- $einfo['send_status'] = $einfo['wsend_num'] == 0 ? 3 : ($einfo['send_num'] == 0 ? 1 : 2);
- $einfo['updatetime'] = date("Y-m-d H:i:s");
- $saleup = Db::name("sale")->save($einfo);
- if ($saleup == false) {
- Db::rollback();
- return error_show(1002, "销售单状态更新失败");
- }
- // }
- //修改状态,添加待办
- ActionLog::logAdd(['id' => $uid, 'nickname' => $uname], [
- "order_code" => $einfo['orderCode'],//出库单号
- "status" => $orderstatus,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "edit"//新建create,编辑edit,更改状态status
- ], "XSQRD", $einfo['status'], $einfo);
- ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $uname], [
- "order_type" => 'XSQRD',
- "order_code" => $einfo['orderCode'],//出库单号
- "order_id" => $einfo['id'],
- "order_status" => $einfo['status'],
- "before_status" => $orderstatus,
- 'holder_id' => $einfo['apply_id']
- ]);
- if($einfo["order_type"]!=1 ){
- $stokc = Db::name("good_stock")->where(['spuCode' => $einfo['good_code'], "wsm_code" => $outinfo['wsm_code'], "is_del" => 0])->find();
- if ($stokc == false) {
- Db::rollback();
- return error_show(1002, "未找到库存数据");
- } else {
- if ($outinfo['send_num'] > $stokc['wait_out_stock']) {
- Db::rollback();
- return error_show(1002, "超出库存数量");
- }
- $stokc['wait_out_stock'] -= $outinfo['send_num'];
- $stokc['total_stock'] = $stokc['wait_out_stock'] + $stokc['usable_stock'];
- // $stokc['intra_stock']+=$outinfo['send_num'];
- $stokc['updatetime'] = date("Y-m-d H:i:s");
- }
- $stoc = Db::name("good_stock")->save($stokc);
- if ($stoc == false) {
- Db::rollback();
- return error_show(1002, "库存更新失败");
- }
- // $outsend =Db::name("order_send")->where(["outCode"=> $outCode])->findOrEmpty();
- // if(empty($outsend)){
- // Db::rollback();
- // return error_show(1002, "未找到关联采购单");
- // }
- // $cgdinfo= Db::name("purchease_order")->where(["cgdNo"=>$outsend['cgdNo'],"is_del"=>0])
- // ->findOrEmpty();
- // $bn_code =makeNo("BN");
- // $bnin=GoodStockInfo::AddBn($stokc["id"],$bn_code,$outinfo['send_num'],$cgdinfo['good_price']??0);
- // if($bnin==false){
- // Db::rollback();
- // return error_show(1004,"库存bn数据新增失败");
- // }
- // $bnup =GoodStockInfo::OrderBn($outinfo['orderCode'],$stokc["id"],$outinfo['send_num'],0);
- // if($bnup==false){
- // Db::rollback();
- // return error_show(1004,"库存bn库存数更新失败");
- // }
- // $outsend['bnCode']=$bn_code;
- // $outsend['updatetime']=date("Y-m-d H:i:s");
- // $ps=Db::name("order_send")->save($outsend);
- // if($ps==false){
- // Db::rollback();
- // return error_show(1004,"库存bn库存数更新失败");
- // }
- $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stokc['id'], "type" => 2, 'stock' => $outinfo['send_num'], "stock_name" => "wait_out_stock"];
- GoodLog::LogAdd(['id' => $uid, 'nickname' => $uname], $good_data, "CKD");
- }else{
- // $saleinfo =Db::name("sale_info")->where(["orderCode"=>$outinfo['orderCode']])->select()->toArray();
- // if (!empty($saleinfo)){
- // $bnup =SaleInfo::SendStock($outinfo['orderCode'],$outinfo['send_num']);
- // if($bnup==false){
- // Db::rollback();
- // return error_show(1004,"库存bn库存数更新失败");
- // }
- // }else{
- $stokc = Db::name("good_stock")->where(['spuCode' => $einfo['good_code'], "wsm_code" => $outinfo['wsm_code'], "is_del" => 0])->find();
- if ($stokc == false) {
- Db::rollback();
- return error_show(1002, "未找到库存数据");
- } else {
- if ($outinfo['send_num'] > $stokc['wait_out_stock']) {
- Db::rollback();
- return error_show(1002, "超出库存数量");
- }
- $stokc['wait_out_stock'] -= $outinfo['send_num'];
- $stokc['total_stock'] = $stokc['wait_out_stock'] + $stokc['usable_stock'];
- // $stokc['intra_stock']+=$outinfo['send_num'];
- $stokc['updatetime'] = date("Y-m-d H:i:s");
- }
- $stoc = Db::name("good_stock")->save($stokc);
- if ($stoc == false) {
- Db::rollback();
- return error_show(1002, "库存更新失败");
- }
- // }
- }
- // Cache::store("redis")->handler()->lPush("SENDOUT", $outCode);
- Db::commit();
- } else {
- Db::rollback();
- return error_show(1004, "发货失败");
- }
- //如果是有赞订单的话,将发货信息推到有赞
- //有赞信息有可能推送失败(比如超过72小时,不允许多次修改等),所以不应该和这里的事务放到一起
- if ($einfo['order_source'] == 5) {
- $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]);
- $res = json_decode($res, true);
- if ($res['code'] != 0) return app_show(0, '发货成功,' . $res['message']);
- }
- return app_show(0, "发货成功");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1004, $e->getMessage());
- }
- }
- public function RelaCgd($outinfo, array &$standing_book_da = [])
- {
- $cgd = Db::name("order_bk")->where([["spuCode", "=", $outinfo['spuCode']], ["is_del", "=", 0], ["balance_num", ">=", $outinfo['good_num']], ['companyNo', "=", $outinfo['companyNo']]])->lock(true)->find();
- if ($cgd == false) {
- return false;
- }
- $good = Db::name("good")->where(["spuCode" => $outinfo['spuCode'], "is_del" => 0])->find();
- if ($good == false) {
- return false;
- }
- $cgdinfo = Db::name("purchease_order")->where(['cgdNo' => $cgd['cgdNo'], "is_del" => 0])->find();
- if ($cgdinfo == false) {
- return false;
- }
- $QrdCgd = [
- "cgdNo" => makeNo("CG"),
- "bkcode" => $cgdinfo['bkcode'],
- 'wsm_code' => $cgdinfo['wsm_code'],
- "cgder_id" => $cgdinfo['cgder_id'],
- "cgder" => $cgdinfo['cgder'],
- "spuCode" => $cgdinfo['spuCode'],
- "good_name" => $cgdinfo['good_name'],
- "good_num" => $outinfo['good_num'],
- "good_price" => $cgdinfo['good_price'],
- "total_fee" => round($cgdinfo['good_price'] * $outinfo['good_num'], 2),
- "pakge_fee" => $cgdinfo['pakge_fee'],
- "cert_fee" => $cgdinfo['cert_fee'],
- "open_fee" => $cgdinfo['open_fee'],
- "delivery_fee" => $cgdinfo['delivery_fee'],
- "mark_fee" => $cgdinfo['mark_fee'],
- "teach_fee" => $cgdinfo['teach_fee'],
- "nake_fee" => $cgdinfo['nake_fee'],
- "demo_fee" => $cgdinfo['demo_fee'],
- "weight" => $cgdinfo['weight'],
- "diff_weight" => $cgdinfo['diff_weight'],
- "diff_fee" => $cgdinfo['diff_fee'],
- "gold_price" => $cgdinfo['gold_price'],
- "supplierNo" => $cgdinfo['supplierNo'],
- "supplier_name" => $cgdinfo['supplier_name'],
- "companyNo" => $cgdinfo['companyNo'],
- "send_status" => 3,
- "send_num" => $outinfo['good_num'],
- "wsend_num" => 0,
- "remark" => $cgdinfo['remark'],
- "status" => 3,
- "lasttime" => $cgdinfo['lasttime'],
- "is_del" => 0,
- "order_type" => $outinfo['order_type'],
- "order_source" => $outinfo['order_source'],
- "good_type" => $cgdinfo['good_type'],
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- 'good_createrid' => $good['createrid'],
- 'good_creater' => $good['creater'],//商品创建人
- ];
- $insetrCgd = Db::name("purchease_order")->insert($QrdCgd);
- if ($insetrCgd == false) {
- return false;
- } else {
- $standing_book_da = array_merge($standing_book_da, [
- 'orderCode' => $outinfo['orderCode'],
- 'cgdNo' => $cgdinfo['cgdNo'],
- 'spuCode' => $outinfo['spuCode'],
- 'order_type' => $QrdCgd['order_type'],
- 'order_source' => $QrdCgd['order_source'],
- 'supplierNo' => $cgdinfo['supplierNo'],
- 'companyNo' => $cgdinfo['companyNo'],
- 'bk_code' => $cgdinfo['bkcode'],
- 'purchease_id' => Db::name('purchease')->where('bk_code', $cgdinfo['bkcode'])->value('id'),
- ]);
- }
- if ($good['is_gold_price'] == 1 && $good['is_stock'] == 1) {
- $gold = Db::name("gold_price1")
- ->field('id,price')
- ->where(["type" => $good['noble_metal'], "is_del" => 0, "status" => 1])
- ->order("addtime desc")
- ->find();
- //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
- $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'];
- $ct['cgd_gold_price'] = $gold["price"];
- $updat = [
- "sale_price" => $sale_price,
- "total_price" => round($sale_price * $outinfo['good_num'], 2),
- "origin_price" => $cgdinfo['good_price'],
- "gold_price" => $gold["price"],
- ];
- $upsale = Db::name("sale")->where(["orderCode" => $outinfo['orderCode']])->update($updat);
- if ($upsale == false) {
- return false;
- }
- }
- $merge_num = Db::name("purchease_order")->where(["bkcode" => $cgdinfo['bkcode'], "order_type" => 1, "is_del" => 0])
- ->where("order_source", "<>", 0)
- ->field("sum(send_num)-sum(th_num) as num")->find();
- $cgd['balance_num'] = $cgd['total_num'] - $merge_num['num'];
- $cgd['merge_num'] = $merge_num['num'];
- $cgd['updatetime'] = date("Y-m-d H:i:s");
- $up = Db::name("order_bk")->save($cgd);
- if ($up == false) {
- return false;
- }
- $data = [
- "orderCode" => $outinfo['orderCode'],
- "cgdNo" => $QrdCgd['cgdNo'],
- "spuCode" => $outinfo['spuCode'],
- "companyNo" => $outinfo['companyNo'],
- "good_num" => $outinfo['good_num'],
- "wsend_num" => $outinfo['good_num'],
- "send_num" => 0,
- "wait_num" => $outinfo['good_num'],
- "status" => 1,
- "source" => 1,
- ];
- $order = Db::name("order_num")->save($data);
- if ($order == false) {
- return false;
- }
- return true;
- }
- public function addother()
- {
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
- if ($orderCode == "") {
- return error_show(1004, "参数orderCode不能为空");
- }
- $order = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->find();
- if ($order == false) {
- return error_show(1004, "未找到订单数据");
- }
- $paytime = isset($this->post['paytime']) && $this->post['paytime'] != "" ? $this->post['paytime'] : "";
- $workNo = isset($this->post['workNo']) && $this->post['workNo'] != "" ? trim($this->post['workNo']) : "";
- $platform_order = isset($this->post['platform_order']) && $this->post['platform_order'] != "" ? trim($this->post['platform_order']) : "";
- $paytime == "" ? "" : $order['paytime'] = $paytime;
- $order['workNo'] = $workNo;
- $order['platform_order'] = $platform_order;
- $order['updatetime'] = date("Y-m-d H:i:s");
- $sa = Db::name("sale")->save($order);
- if ($sa) {
- return app_show(0, "更新成功");
- } else {
- return error_show(1004, "更新失败");
- }
- }
- public function getPrice()
- {
- $skuCode = isset($this->post['skuCode']) && $this->post['skuCode'] != "" ? trim($this->post['skuCode']) : "";
- if ($skuCode === "") {
- return error_show(1003, "参数skuCode不能为空");
- }
- $is_activity = isset($this->post['is_activity']) && $this->post['is_activity'] !== "" ? intval($this->post['is_activity'])
- : "";
- if ($is_activity === "") {
- return error_show(1003, "参数is_activity不能为空");
- }
- $sale_num = isset($this->post['sale_num']) && $this->post['sale_num'] !== "" ? intval($this->post['sale_num']) : "";
- if ($sale_num === "") {
- return error_show(1003, "参数sale_num不能为空");
- }
- $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $skuCode])->find();
- if ($ct == false) {
- return error_show(1002, "未找到商品数据");
- }
- $stock = 0;
- if ($ct['is_stock'] == 1) {
- // $good_stock = Db::name("good_stock")->alias("a")->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")->where
- // (["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();
- // $good_stock = Db::name("good_stock")->where(["spuCode" => $ct['spuCode'], "is_del" => 0])->find();
- $stock = Db::name("good")->where(["spuCode"=>$ct['spuCode']])->value("usable_stock",0);
- }
- if ($is_activity == 1) {
- $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b", "a.activity_code=b.activity_code")
- ->where(["a.skuCode" => $skuCode, "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])->find();
- if ($act == false) {
- return error_show(1003, "未找到相关活动价");
- }
- if ($act['moq_num'] > $sale_num) {
- return error_show(1003, "商品不满足活动价起订量{$act['moq_num']}");
- }
- if ($act['activity_stock'] < $sale_num) {
- return error_show(1003, "商品活动库存剩余{$act['activity_stock']}");
- }
- return app_show(0, "获取成功", ['sale_price' => $act['activity_price'], "stock" => $act['activity_stock']]);
- } else {
- //good_nake 成本阶梯 good_ladder销售阶梯
- $origin = Db::name("good_nake")->where([["spuCode", "=", $ct['spuCode']], ["is_del", "=", 0]])->order("min_num asc")->find();
- if (!$origin) {
- return error_show(1003, "没有找到成本数据");
- }
- $good = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->order("min_num asc")->find();
- if (!$good) {
- return error_show(1003, "未找到相关阶梯价格");
- }
- if (!isset($origin['min_num'])) $origin['min_num'] = 0;
- //如果是库存品的话,只取销售的库存
- if ($ct['is_stock'] == 1) $lastnum = $good['min_num'];
- else $lastnum = max($origin['min_num'] ?? 0, $good['min_num']);
- if ($sale_num < $lastnum) {
- return error_show(1003, "商品不满足起订量{$lastnum}");
- }
- $good_temp = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->where('min_num', '<=', $sale_num)->order("min_num desc")->find();
- if (!$good_temp) {
- return error_show(1003, "未找到相关阶梯价格");
- }
- $cat_top_list = made($ct['cat_id']);
- $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
- if ($ct['is_gold_price'] == 1 && $cat_top_id == 6) {
- $gold = Db::name("gold_price1")
- ->field('id,price')
- ->where(["type" => $ct['noble_metal'], "is_del" => 0, "status" => 1])
- ->order("addtime desc")
- ->find();
- if($ct['is_fixed']==0) $origin['nake_fee']=0;
- $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'];
- return app_show(0, "获取成功", ['sale_price' => $saleprice, "stock" => $stock]);
- }
- return app_show(0, "获取成功", ['sale_price' => $good_temp['sale_price'], "stock" => $stock]);
- }
- }
- public function saleuse()
- {
- $orderCode = isset($this->post['orderCode']) && !empty($this->post['orderCode']) ? $this->post['orderCode'] : "";
- if ($orderCode == "") {
- return error_show(1003, "参数orderCode不能为空");
- }
- $order = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->select()->toArray();
- if (empty($order)) {
- return error_show(1003, "订单数据未找到");
- }
- $useid = isset($this->post['useid']) && $this->post['useid'] != "" ? intval($this->post['useid']) : "";
- if ($useid == "") {
- return error_show(1003, "参数useid不能为空");
- }
- $use = Db::name("order_use")->where(["id" => $useid, "is_del" => 0])->find();
- if ($use == false) {
- return error_show(1003, "用途数据未找到");
- }
- $asve = ['use_order' => $useid, "updatetime" => date("Y-m-d H:i:s")];
- $up = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->update($asve);
- if ($up > 0) {
- return app_show(0, "更新成功");
- } else {
- return error_show(1003, "更新失败");
- }
- }
- public function goodzxinfo()
- {
- $orderCode = isset($this->post['spuCode']) && $this->post['spuCode'] != '' ? trim($this->post['spuCode']) : "";
- if ($orderCode == "") {
- return error_show(1003, "参数spuCode不能为空");
- }
- $order = Db::name("good_zixun")->where(["spuCode" => $orderCode, "is_del" => 0])->find();
- if (empty($order)) {
- return error_show(1003, "订单数据未找到");
- }
- $unit = Db::name("unit")->where(["id" => $order['good_unit']])->find();
- if ($order['brand_id'] != 0) {
- $brand = Db::name("brand")->where(["id" => $order['brand_id']])->find();
- $order["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
- } else {
- $order["brand_name"] = "";
- $order["brand_id"] = "";
- }
- $order['specinfo'] = json_decode($order['specinfo'], true);
- $order['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
- $order['cat_info'] = made($order['cat_id'], []);
- $order['noble_name'] = isset($order['noble_metal']) && $order['noble_metal'] != 0 ? $this->noble[$order['noble_metal']] : "";
- if ($order['is_gold_price'] == 1) {
- $price = Db::name("gold_price1")->where(["type" => $order['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
- }
- $order['tax_info']=GoodTax::with(['Tax','OutTax',"CgdTax"])->where(['spuCode'=>$orderCode])->findOrEmpty();
- $depart = get_company_name_by_uid($order['order_createrid']);
- $userCommon = \app\admin\common\User::getIns();
- $supplier = $userCommon->handle('sInfo',['code'=>$order['supplierNo']]);
- $order['supplier_name'] = isset($supplier['data']['name']) ? $supplier['data']['name'] : "";
- $order['cgder'] = isset($supplier['data']['person']) ? $supplier['data']['person'] : "";
- $order['cgderid'] = isset($supplier['data']['personid']) ? $supplier['data']['personid'] : "";
- $order['order_creater_depart'] = $depart;
- $is_online= Db::name('good_platform')->where(['spuCode'=>$order['spuCode']])->findOrEmpty();
- $order['is_online'] = empty($is_online)?0:1;
- $value['is_basic']= Db::name('good_basic')->where(['spuCode'=>$order['spuCode']])->value("status",null);
- $palt = Db::name("platform")->where(["id" => $order['platform_id']])->find();
- $order['platform_name'] = isset($palt['platform_name']) ? $palt['platform_name'] : "";
- $names = $userCommon->handle('getCodeAndName',['code'=>$order['companyNo']]);
- $order['company'] = $names['data'][$order['companyNo']]??'';
- $order["gold_price"] = isset($price['price']) ? $price['price'] : 0;
- $order["noble_weight"] = isset($order['weight']) ? $order['weight'] : 0;
- return app_show(0, "获取成功", $order);
- }
- //获取采反商品详情,当数据不在good_zixun中,模仿goodzxinfo
- public function getGoodZxInfoByNotZixun()
- {
- $param = $this->request->only(['spuCode'], 'post', 'trim');
- $val = Validate::rule(['spuCode' => 'require']);
- if (!$val->check($param)) return error_show(1004, $val->getError());
- $order = Db::name('consult_bids')
- ->field(true)
- ->where(['spuCode' => $param['spuCode'], 'is_del' => 0])
- ->find();
- if (empty($order)) return error_show(1003, "数据未找到");
- $unit = Db::name("unit")->where(["id" => $order['unit_id']])->find();
- if ($order['brand_id'] != 0) {
- $brand = Db::name("brand")->where(["id" => $order['brand_id']])->find();
- $order["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
- } else {
- $order["brand_name"] = "";
- $order["brand_id"] = "";
- }
- $order['specinfo'] = json_decode($order['specinfo'], true);
- $order['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
- $order['cat_info'] = made($order['cat_id'], []);
- $order['noble_name'] = isset($order['metal_id']) && $order['metal_id'] != 0 ? $this->noble[$order['metal_id']] : "";
- if ($order['is_gold_price'] == 1) {
- $price = Db::name("gold_price1")->where(["type" => $order['metal_id'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
- }
- $userCommon = \app\admin\common\User::getIns();
- $supplier_temp = $userCommon->handle('getCodeAndName', ['code' => $order['supplierNo']]);
- $order['supplier_name'] = $supplier_temp['data'][$order['supplierNo']]??"";
- $order["gold_price"] = isset($price['price']) ? $price['price'] : 0;
- $order["noble_weight"] = isset($order['weight']) ? $order['weight'] : 0;
- $tax = TaxCategory::where(['id'=>[$order['tax_id'],$order['out_tax_id'],$order['cgd_tax_id']]])->column('short_name,cat_name,cat_code,merge_code','id');
- $order['in_info'] = $tax[$order['tax_id']]??[];
- $order['out_info'] = $tax[$order['out_tax_id']]??[];
- $order['cgd_info'] = $tax[$order['cgd_tax_id']]??[];
- $order['child'] =[];
- if($order['is_combind']==1){
- $order['child'] =ConsultTemp::where(['bidNo'=>$order['bidNo']])->select()->each(function(&$item){
- $tax = TaxCategory::where(['id'=>[$item['tax_id'],$item['out_tax_id'],$item['cgd_tax_id']]])->column('short_name,cat_name,cat_code,merge_code','id');
- $item['in_info'] = $tax[$item['tax_id']]??[];
- $item['out_info'] = $tax[$item['out_tax_id']]??[];
- $item['cgd_info'] = $tax[$item['cgd_tax_id']]??[];
- });
- }
- $good_info = Db::name('good_basic')
- ->field('id,createrid,creater')
- ->where('is_del',0)
- ->where('spuCode',$order['spuCode'])
- ->findOrEmpty();
- //补充商品创建人字段
- // 2022-9-7号确认 creater创建人即采购单的采购员 咨询cgder 只是供应商负责人
- $order['good_createrid']=$good_info['createrid']??$order['createrid'];
- $order['good_creater']=$good_info['creater']??$order['creater'];
- return app_show(0, "获取成功", $order);
- }
- //发货申请单导出
- public function exportSaleOut()
- {
- $outCodes = $this->request->post('outCodes', [], 'trim');
- if (empty($outCodes)) return error_show(1004, '要导出的发货申请单编号不能为空');
- $i = 1;
- $send_type = [1 => '直接发货', 2 => '延时发货'];
- $status = [0 => '待发货', 1 => '待库管发货', 2 => '已发货待收货', 3 => '已收货', 4 => '已全部退货'];
- $list = Db::name("order_out")
- ->alias('a')
- ->field('"" as 序号,a.addtime as 创建时间,po.cgdNo as 采购单编号,po.status as 采购单状态,po.cgder as 采购员,b.orderCode as 确认单号,b.addtime as 确认单时间,
- b.good_code as 产品编号,b.skuCode as 商品上线编码,"" 平台商品编码,b.good_name as 产品名称,"" as 规格,"" as 单位,b.supName as 供应商名称,b.supNo as 供应商编号,
- a.post_fee as 物流费,b.send_type as 发货方式,b.remark as 确认单备注,po.good_num as 采购数量,a.send_num 发货数量,
- oa.contactor as 收货人,oa.mobile as 联系方式,oa.addr as 收货地址,oa.addr_code,oa.arrive_time as 到货时间,a.outCode as 发货申请单号,po.order_type,
- b.platform_order 平台订单号,a.post_name 发货申请单物流公司,a.post_code 发货申请单物流单号,a.post_fee 发货申请单物流费用,a.remark 发货申请单备注,a.apply_name 申请人,b.cat_id 商品分类')
- ->whereIn('a.outCode', $outCodes)
- ->order("a.addtime desc")
- ->withAttr('序号', function () use (&$i) {
- return $i++;
- })->withAttr('采购单状态', function ($val) use ($status) {
- return isset($status[$val]) ? $status[$val] : '';
- })->withAttr('发货方式', function ($val) use ($send_type) {
- return isset($send_type[$val]) ? $send_type[$val] : '';
- })->where("a.is_del", "=", 0)
- ->leftJoin("sale b", "b.orderCode=a.orderCode")
- ->leftJoin("order_addr oa", "oa.id=a.addrid AND oa.is_del=0")
- ->leftJoin('order_send os', 'os.outCode=a.outCode ')
- ->leftJoin("purchease_order po", "po.cgdNo=os.cgdNo AND po.is_del=0")
- ->select()
- ->toArray();
- $userCommon = \app\admin\common\User::getIns();
- $skuArr =array_unique(array_column($list,"商品上线编码"));
- $platCode= (new GoodPlatform())->where(["skuCode"=>$skuArr])->column("plat_code","skuCode");
- foreach ($list as &$value) {
- $value['平台商品编码']= $platCode[$value['商品上线编码']]??"";
- if ($value['order_type'] == 3 || $value['order_type'] == 4) {
- $good = Db::name("good_zixun")
- ->where(["spuCode" => $value['产品编号'], "is_del" => 0])
- ->field('id,specinfo,good_unit,supplierNo')
- ->find();
- $specinfo = isset($good['specinfo']) ? json_decode($good['specinfo'], true) : [];
- $speclist = [];
- foreach ($specinfo as $val) {
- $speclist[] = $val['spec_name'] . ':' . $val['spec_value_name'];
- }
- } else {
- $good = Db::name('good_basic')
- ->where(['spuCode' => $value['产品编号']])
- ->field('good_unit,supplierNo')
- ->find();
- $spec = Db::name("good_spec")
- ->field('id,spec_id,spec_value_id')
- ->where(["spuCode" => $value['产品编号'], "is_del" => 0])
- ->select()
- ->toArray();
- $speclist = [];
- if (!empty($spec)) {
- foreach ($spec as $val) {
- $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', '');
- }
- }
- }
- $supplier_temp = $userCommon->handle('sInfo', ['code' =>$value['供应商编号']]);
- $supplier=$supplier_temp['data']??[];
- $value['供应商编号'] = $good['supplierNo']??"";
- // $supplier= Db::name("supplier")->where(["code"=>$value['供应商编号']])->field("name,person")->find();
- $value['供应商名称'] = $supplier['name']??"";
- $value['采购员'] = $supplier['person']??"";
- $good_unit = isset($good['good_unit']) ? $good['good_unit'] : 0;
- $value['规格'] = empty($speclist) ? '' : implode(',', $speclist);;
- $value['单位'] = $good_unit ? Db::name('unit')->where(['id' => $good_unit, 'is_del' => 0])->value('unit', '') : '';
- $value['商品分类'] = implode('/', array_column(made($value['商品分类']), 'name'));
- $value['发货申请单物流单号'] = ' ' . $value['发货申请单物流单号'];//添加空格防止将数字转为科学计数法(比如,韵达的快递单号就是纯数字)
- $addinfo =$value['addr_code']!=''?json_decode($value['addr_code'],true)??$value['addr_code']: '' ;
- if(is_string($addinfo)&&$addinfo!=''){
- $addinfo=["provice_code"=>'',"city_code"=>'',"area_code"=>''];
- list($addinfo['provice_code'],$addinfo['city_code'],$addinfo['area_code']) = explode(",",$value['addr_code']);
- }
- $addr_cn =GetAddr(json_encode($addinfo));
- $value['收货地址'] = $addr_cn.$value['收货地址'];
- unset($value['order_type']);
- unset($value['addr_code']);
- }
- if (empty($list)) $list[] = '没有可供导出的数据';
- $headerArr = array_keys($list[0]);
- excelSave('发货申请单导出' . date('YmdHis'), $headerArr, $list);
- }
- //发货申请单 签收(目前只改动状态,后面要实时查询物流信息,以判断是否签收)
- public function saleoutReceipt()
- {
- $outCode = $this->request->post('outCode', '', 'trim');
- if (empty($outCode)) return error_show(1004, '发货申请单编号不能为为空');
- Db::startTrans();
- try {
- $rs = Db::name('order_out')
- ->field('id,orderCode,apply_id')
- ->where(['outCode' => $outCode, 'status' => 2, "is_del" => 0])
- ->find();
- if (empty($rs)) throw new Exception('该出库单不存在或不允许确认收货');
- //发货单收货
- $res_order_out = Db::name('order_out')
- ->where(['id' => $rs['id'], 'status' => 2, "is_del" => 0])
- ->update(['status' => 3, 'updatetime' => date('Y-m-d H:i:s')]);
- //发货工单不做更新,发货工单只给库管人员看,不关心是否收货,只保留 待发货/已发货/已取消 这几个状态就可以了
- //查询该发货单所属的销售单,是否还有未收货的其他发货单
- $other_res_sale = Db::name('order_out')
- ->where(['orderCode' => $rs['orderCode'], 'status' => 2, "is_del" => 0])
- ->where('id', '<>', $rs['id'])
- ->find();
- if (empty($other_res_sale)) {
- //所属销售单也确认收货
- Db::name('sale')
- ->where(['orderCode' => $rs['orderCode'], 'status' => 0])
- ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
- }
- //修改状态,添加待办
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $outCode,
- "status" => 2,//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "CKD", 3, $rs);
- //将待办数据变为已办
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $outCode,
- "order_id" => $rs['id'],
- "order_status" => 3,
- "order_type" => 'CKD',
- "before_status" => 2,
- 'holder_id' => $rs['apply_id']
- ]);
- if ($res_order_out) {
- Db::commit();
- return app_show(0, '收货完成');
- } else {
- Db::rollback();
- error_show(1005, '收货失败');
- }
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- //库管批量发货
- public function outSendBatchByImport()
- {
- $param = $this->request->only(['list', 'token'], 'post', 'trim');
- if (empty($param['list'])) return error_show(1005, 'list参数不能为空');
- //只允许处理所属供应商下的采购单关联的发货单
- $suppliers = Db::name('order_out')
- ->alias('a')
- ->leftJoin('order_num b', 'b.orderCode=a.orderCode')
- ->leftJoin('purchease_order c', 'c.cgdNo=b.cgdNo')
- ->where([
- ['a.is_del', '=', 0],
- ['c.order_type', '<>', 1],
- ['a.outCode', 'in', array_column($param['list'], 'outCode')],
- ])->column('c.supplierNo', 'a.outCode');
- if ($this->level != 3) {
- //检查这些供应商编码是否开通了账号
- $temp_res = checkHasAccountBySupplierNos(array_values($suppliers));
- // ->whereIn('supplierNo', array_values($suppliers))
- // ->column('supplierNo');
- // $temp = [];
- // foreach ($suppliers as $k => $v) {
- // if (in_array($v, $temp_res)) $temp[] = $k;
- // }
- if (!empty($temp_res)) return json_show(1003, '不允许处理已开通账号的供应商的单子', array_keys($temp_res));
- }
- // $user = GetUserInfo($param['token']);
- $createrid = $this->uid;//$user['data']['id']??0;//$this->uid;
- $creater = $this->uname;//$user['data']['nickname']??0;//$this->uname;
- // $own_roleid = Db::name('user_role')->where(['is_del'=>0,'uid'=>$createrid,'status'=>1])->value('roleid',0);
- //所有发货单信息
- $order_out_infos = Db::name("order_out")
- ->where('status', 1)
- ->where('is_del', 0)
- ->whereIn('outCode', array_column($param['list'], 'outCode'))
- ->column('id,status,send_num,orderCode,wsm_code,apply_id,apply_name', 'outCode');
- //所有库管人员信息
- // $wsm_infos=Db::name('warehouse_info')
- // ->where(['is_del'=>0,'wsm_code'=>array_column($order_out_infos,'wsm_code')])
- // ->column('contactor','wsm_code');
- //所有商品信息及供应商编码
- $spuCodes=Db::name('sale')
- ->where(['is_del'=>0,'orderCode'=>array_column($order_out_infos,'orderCode')])
- ->column('good_code');
- $supplierNo1 = Db::name('good_zixun')
- ->where(['spuCode' => $spuCodes, 'is_del' => 0])
- ->column('supplierNo','spuCode');
- $supplierNo2 = Db::name('good')
- ->where(['spuCode' => $spuCodes, 'is_del' => 0])
- ->column('supplierNo','spuCode');
- $supplierNos = array_unique(array_merge($supplierNo1,$supplierNo2));
- $userCommon = \app\admin\common\User::getIns();
- $temp = $userCommon->handle('sGetList',['more_code'=>array_values($supplierNos)]);
- $supplier_personid = array_column($temp['data']['list'],'personid','code');
- //处理数据
- Db::startTrans();
- try {
- $good_data = $temp_out_codes = $yz_data = [];
- foreach ($param['list'] as $value) {
- if (!isset($order_out_infos[$value['outCode']])) throw new Exception($value['outCode'] . '该发货单未找到或状态不允许发货');
- //每次循环都需要重新查询对应数据,为了数据及时更新
- $sale_infos = Db::name("sale")
- ->where('orderCode', $order_out_infos[$value['outCode']]['orderCode'])
- ->where('is_del', 0)
- ->column('id,send_num,wsend_num,status,good_code,order_source,order_type,apply_id,apply_name,is_stock,cgderid,orderCode', 'orderCode');
- if (!isset($sale_infos[$order_out_infos[$value['outCode']]['orderCode']])) throw new Exception($value['outCode'] . '该发货单对应的销售单未找到');
- //判断发货单是否重复
- if (isset($temp_out_codes[$value['outCode']])) {
- Db::rollback();
- return app_show(1005, '下列发货申请单号重复', [$value]);
- } else $temp_out_codes[$value['outCode']] = $value['outCode'];
- if($this->level==2) {
- //level2账号的话,库存品只能由库管操作,非库存品只能由供应商负责人操作,level3账号不限制
- if ($sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['is_stock'] == 1) {
- //由于存在一个单子对应多个仓库的情况,因此库存品的判断暂时无法进行,待分仓功能完成后再考虑
- // if($wsm_infos[$order_out_infos[$value['outCode']]['wsm_code']]??0 != $createrid) throw new \think\Exception($value['outCode'] . '发货单只能由库管操作');
- // if (!in_array($own_roleid, config('app.wsm_cgder_role'))) {
- // Db::rollback();
- // return app_show(1003, $value['outCode'] . '发货单只能由库管操作');
- // }
- } else {
- // if ($sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['order_type'] == 3 || $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['order_type'] == 4) {
- // $supplierNo = Db::name('good_zixun')
- //// ->leftJoin("supplier b", "a.supplierNo=b.code")
- // ->where(['spuCode' => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code'], 'is_del' => 0])
- // ->value('supplierNo');
- // } else {
- // $supplierNo = Db::name('good')
- //// ->alias("a")
- //// ->leftJoin("supplier b", "a.supplierNo=b.code")
- // ->where(['spuCode' =>$sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code'], 'is_del' => 0])
- // ->value('supplierNo');
- // }
- if ($createrid != $supplier_personid[$supplierNos[$sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code']]]) throw new \think\Exception($value['outCode'] . '发货单只能由供应商负责人操作');
- // Db::rollback();
- // return app_show(1003, $value['outCode'] . '发货单只能由供应商负责人操作');
- }
- }
- //【发货单】
- //查询已有发货单信息及状态
- //更新发货单
- $up = Db::name("order_out")
- ->where(['id' => $order_out_infos[$value['outCode']]['id'], 'outCode' => $value['outCode'], 'status' => 1, "is_del" => 0])
- ->update([
- 'post_name' => isset($value['post_name']) ? $value['post_name'] : '',
- 'post_code' => $value['post_code'],
- 'post_fee' => $value['post_fee'],
- 'sendtime' => date('Y-m-d H:i:s'),
- 'status' => 2,
- 'updatetime' => date('Y-m-d H:i:s'),
- 'remark' => isset($value['remark']) ? $value['remark'] : '',
- ]);
- if ($up) {
- //修改状态,添加待办
- ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
- "order_code" => $value['outCode'],//出库单号
- "status" => $order_out_infos[$value['outCode']]['status'],//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "edit"//新建create,编辑edit,更改状态status
- ], "CKD", 2, $order_out_infos[$value['outCode']]);
- ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
- "order_type" => 'CKD',
- "order_code" => $value['outCode'],//出库单号
- "order_id" => $order_out_infos[$value['outCode']]['id'],
- "order_status" => 2,
- "before_status" => $order_out_infos[$value['outCode']]['status'],
- 'wait_id' => $order_out_infos[$value['outCode']]['apply_id'],
- 'wait_name' => $order_out_infos[$value['outCode']]['apply_name'],
- 'holder_id' => $order_out_infos[$value['outCode']]['apply_id'],
- ]);
- //【销售单】
- $einfo = [];
- $einfo['send_num'] = $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['send_num'] + $order_out_infos[$value['outCode']]['send_num'];
- $einfo['wsend_num'] = $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['wsend_num'] - $order_out_infos[$value['outCode']]['send_num'];
- $einfo['status'] = $einfo['wsend_num'] == 0 ? 2 : ($einfo['send_num'] == 0 ? 0 : 1);
- $einfo['send_status'] = $einfo['wsend_num'] == 0 ? 3 : ($einfo['send_num'] == 0 ? 1 : 2);
- $einfo['updatetime'] = date("Y-m-d H:i:s");
- $saleup = Db::name("sale")
- ->where('id', $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['id'])
- ->update($einfo);
- if ($saleup == false) throw new Exception($value['outCode'] . '销售单状态更新失败');
- //修改状态,添加待办
- ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
- "order_code" => $order_out_infos[$value['outCode']]['orderCode'],//销售单号
- "status" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['status'],//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "edit"//新建create,编辑edit,更改状态status
- ], "XSQRD", $einfo['status'], $einfo);
- ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
- "order_type" => 'XSQRD',
- "order_code" => $order_out_infos[$value['outCode']]['orderCode'],//出库单号
- "order_id" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['id'],
- "order_status" => $einfo['status'],
- "before_status" => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['status'],
- 'holder_id' => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['apply_id']
- ]);
- if($sale_infos[$order_out_infos[$value['outCode']]['orderCode']]["order_type"]!=1){
- //【库存】
- $stock = Db::name("good_stock")
- ->field('id,wait_out_stock,usable_stock,total_stock,updatetime')
- ->where([
- "is_del" => 0,
- 'spuCode' => $sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['good_code'],
- "wsm_code" => $order_out_infos[$value['outCode']]['wsm_code'],
- ])->find();
- if ($stock == false) throw new Exception($value['outCode'] . '未找到库存数据');
- else {
- if ($order_out_infos[$value['outCode']]['send_num'] > $stock['wait_out_stock']) throw new Exception($value['outCode'] . '超出库存数量');
- $stock['wait_out_stock'] -= $order_out_infos[$value['outCode']]['send_num'];
- $stock['total_stock'] = $stock['wait_out_stock'] + $stock['usable_stock'];
- $stock['updatetime'] = date("Y-m-d H:i:s");
- $stock_rs = Db::name("good_stock")
- ->where('id', $stock['id'])
- ->update($stock);
- if ($stock_rs == false) throw new Exception($value['outCode'] . '库存更新失败');
- // $outsend =Db::name("order_send")->where(["outCode"=> $value['outCode']])->findOrEmpty();
- // if(empty($outsend)){
- // Db::rollback();
- // return error_show(1002, "未找到关联采购单");
- // }
- // $cgdinfo= Db::name("purchease_order")->where(["cgdNo"=>$outsend['cgdNo'],"is_del"=>0])
- // ->findOrEmpty();
- // $bn_code =makeNo("BN");
- // $bnin=GoodStockInfo::AddBn($stock["id"],$bn_code,$order_out_infos[$value['outCode']]['send_num'],$cgdinfo['good_price']??0);
- // if($bnin==false){
- // Db::rollback();
- // return error_show(1004,"库存bn数据新增失败");
- // }
- // $bnup =GoodStockInfo::OrderBn($order_out_infos[$value['outCode']]['orderCode'],$stock["id"],$order_out_infos[$value['outCode']]['send_num'],0);
- // if($bnup==false){
- // Db::rollback();
- // return error_show(1004,"库存bn库存数更新失败");
- // }
- // $outsend['bnCode']=$bn_code;
- // $outsend['updatetime']=date("Y-m-d H:i:s");
- // $ps=Db::name("order_send")->save($outsend);
- // if($ps==false){
- // Db::rollback();
- // return error_show(1004,"库存bn库存数更新失败");
- // }
- }
- $good_data[] = [
- 'good_log_code' => $value['outCode'],
- 'stock_id' => $stock['id'],
- 'type' => 2,
- 'stock' => $order_out_infos[$value['outCode']]['send_num'],
- 'stock_name' => 'wait_out_stock'
- ];
- }else{
- // $bnup =SaleInfo::SendStock($order_out_infos[$value['outCode']]['orderCode'],$order_out_infos[$value['outCode']]['send_num']);
- // if($bnup==false){
- // Db::rollback();
- // return error_show(1004,"库存bn库存数更新失败");
- // }
- // $saleinfo =Db::name("sale_info")->where(["orderCode"=>$order_out_infos[$value['outCode']]['orderCode']])->select()->toArray();
- // if (!empty($saleinfo)){
- // $bnup =SaleInfo::SendStock($order_out_infos[$value['outCode']]['orderCode'],$order_out_infos[$value['outCode']]['send_num']);
- // if($bnup==false){
- // Db::rollback();
- // return error_show(1004,"库存bn库存数更新失败");
- // }
- // }else{
- $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();
- if ($stokc == false) {
- Db::rollback();
- return error_show(1002, "未找到库存数据");
- } else {
- if ($order_out_infos[$value['outCode']]['send_num'] > $stokc['wait_out_stock']) {
- Db::rollback();
- return error_show(1002, "超出库存数量");
- }
- $stokc['wait_out_stock'] -= $order_out_infos[$value['outCode']]['send_num'];
- $stokc['total_stock'] = $stokc['wait_out_stock'] + $stokc['usable_stock'];
- // $stokc['intra_stock']+=$outinfo['send_num'];
- $stokc['updatetime'] = date("Y-m-d H:i:s");
- }
- $stoc = Db::name("good_stock")->save($stokc);
- if ($stoc == false) {
- Db::rollback();
- return error_show(1002, "库存更新失败");
- }
- // }
- }
- } else throw new Exception($value['outCode'] . '发货失败');
- // Cache::store("redis")->handler()->lPush("SENDOUT",$value['outCode']);
- //如果是有赞订单的话,将发货信息推到有赞
- if($sale_infos[$order_out_infos[$value['outCode']]['orderCode']]['order_source']==5){
- $yz_data[]=[
- 'orderCode'=>$sale_infos[$order_out_infos[$value['outCode']]['orderCode']],
- 'out_stype'=>isset($value['post_name']) ? $value['post_name'] : '',
- 'post_code'=>$value['post_code'],
- 'uid'=>$createrid,
- 'uname'=>$creater,
- 'order_out'=>$value['outCode'],
- ];
- }
- }
- if (!empty($good_data)) GoodLog::LogAdd(['id' => $createrid, 'nickname' => $creater], $good_data, "CKD");
- Db::commit();
- //如果是有赞订单的话,将发货信息推到有赞
- //有赞信息有可能推送失败(比如超过72小时,不允许多次修改等),所以不应该和这里的事务放到一起
- if ($yz_data) {
- foreach ($yz_data as $yz) {
- // $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]);
- curl_request(config('app.yz_domain') . 'api/yz_out_send', $yz);
- }
- // $res = json_decode($res, true);
- // if ($res['code'] != 0) return app_show(0, '发货成功,' . $res['message']);
- }
- return app_show(0, '发货成功');
- } catch (Exception $exception) {
- Db::rollback();
- return error_show(1004, $exception->getMessage());
- }
- }
- //获取物流信息
- public function getLogisticsInformation()
- {
- $post_code = $this->request->post('post_code', '', 'trim');
- if (empty($post_code)) return error_show(1004, '快递单号不能为空');
- $postCode = explode(",", $post_code);
- $rs = Db::name('express_data')
- ->where('post_code', $postCode[0])
- ->where('status', ">=", 0)
- ->withAttr('post_data', function ($val) {
- return json_decode($val, true);
- })->findOrEmpty();
- settype($rs, 'object');//格式统一转为对象
- return app_show(0, '请求成功', $rs);
- }
- //订单取消
- //未发货状态添加撤销功能 要求1.库存品 未发货 直接撤销 2.除了库存品以外的商品类型,采购单未入库的 可撤销。
- public function orderCancel()
- {
- $orderCode = $this->request->post('orderCode', '', 'trim');
- $val = Validate::rule(['orderCode' => 'require|array|max:100']);
- if ($val->check(['orderCode' => $orderCode]) == false) return json_show(1004, $val->getError());
- $list = Db::name('sale')
- ->alias('a')
- ->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,
- 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,
- a.addtime,c.wsm_code,a.order_source,a.other_orderNo')
- ->leftJoin('order_num b', 'b.orderCode=a.orderCode')
- ->leftJoin('purchease_order c', 'c.cgdNo=b.cgdNo')
- ->where(['a.is_del' => 0, 'a.orderCode' => $orderCode])
- ->select()
- ->toArray();
- Db::startTrans();
- try {
- $date = date('Y-m-d H:i:s');
- $th=[];
- $cgdId=[];
- foreach ($list as $sale) {
- if ($sale['sale_status'] == 3) throw new \think\Exception($sale['orderCode'] . '已取消,无法重复操作');
- if ($sale['order_type'] == 1) {
- if ($sale['sale_status'] != 0) throw new \think\Exception($sale['orderCode'] . '已发货,无法取消');
- $good = Db::name("good")->where(["spuCode" => $sale['good_code']])->findOrEmpty();
- if (empty($good)) throw new Exception('未找到商品信息');
- $stock = Db::name("good")->where($good)
- ->inc("usable_stock",$sale['wsend_num'])
- ->update();
- if ($stock == false) throw new Exception('商品库存更新失败');
- if(strtotime($sale['addtime'])< strtotime('2023-04-17 00:00:00')){
- $saleinfo = Db::name('sale_info')
- ->where([['orderCode', '=',$sale['orderCode']], ['num', '>', 0]])
- ->select()
- ->toArray();
- if (empty($saleinfo)) {
- $ordernum = Db::name('order_num')->where(['orderCode' =>$sale['orderCode']])->findOrEmpty();
- if (empty($ordernum)) throw new Exception('未找到关联采购单');
- $cgd = Db::name('purchease_order')->where(['cgdNo' => $ordernum['cgdNo'], 'is_del' => 0])->findOrEmpty();
- if (empty($cgd)) throw new Exception('未找到采购单数据');
- $bn = makeNo('BN');
- $stock = Db::name('good_stock')
- ->where(['spuCode' => $sale['good_code'], 'wsm_code' => $cgd['wsm_code'], 'is_del' => 0, 'status' => 1])
- ->findOrEmpty();
- if ($stock == false) throw new Exception('商品库存数据未找到');
- $stock['usable_stock'] += $sale['wsend_num'];
- $stock['wait_out_stock'] -= $sale['wsend_num'];
- $stock['updatetime'] = $date;
- $st_up = Db::name('good_stock')->save($stock);
- if ($st_up == false) throw new Exception('可售商品入库失败');
- $yp = GoodStockInfo::AddBn($stock['id'], $bn, $sale['wsend_num'], $cgd['good_price']);
- if ($yp == false) throw new Exception('商品批次退货入库失败');
- }
- else {
- $tempnum = $sale['wsend_num'];
- foreach ($saleinfo as $va) {
- if ($tempnum == 0) break;
- $stock = Db::name('good_stock')->where(['spuCode' => $sale['good_code'], 'id' => $va['stockid']])
- ->findOrEmpty();
- if ($stock == false) throw new Exception('商品库存数据未找到');
- if ($va['num'] >= $tempnum) {
- $tnm = $tempnum;
- $va['num'] -= $tempnum;
- $va['th_num'] += $tempnum;
- $tempnum = 0;
- } else {
- $tnm = $va['num'];
- $tempnum -= $va['num'];
- $va['th_num'] += $va['num'];
- $va['num'] = 0;
- }
- $stock['usable_stock'] += $tnm;
- $stock['wait_out_stock'] -= $tnm;
- $stock['updatetime'] = $date;
- $st_up = Db::name('good_stock')->save($stock);
- if ($st_up == false) throw new Exception('可售商品入库失败');
- $ps = GoodStockInfo::AddBn($va['stockid'], $va['bnCode'], $tnm);
- if ($ps == false) throw new Exception('商品批次退货入库失败');
- $ret = GoodStockInfo::ReturnBn($sale['orderCode'], $va['id'], $tnm);
- if ($ret == false) throw new Exception('商品批次退货入库失败');
- $va['updatetime'] = $date;
- $sal = Db::name('sale_info')->save($va);
- if ($sal == false) throw new Exception('商品批次退货入库失败');
- }
- }
- }
- SaleCgdPrice::RePrice($sale['sale_id'],$sale['wsend_num']);
- }
- else{
- if ($sale['order_source'] != 9){
- $good = Db::name('good_stock')->where(['spuCode' => $sale['good_code'],'wsm_code'=>$sale['wsm_code']])
- ->findOrEmpty();
- if (empty($good)) throw new Exception('未找到商品信息');
- if($sale['cgd_status']==1){
- $stock = Db::name('good_stock')->where($good)
- ->inc('wait_in_stock',$sale['wsend_num'])
- ->update();
- if ($stock == false) throw new Exception('商品库存更新失败');
- }
-
- if($sale['cgd_status']==3){
- $wait_out= Db::name('order_out_child')
- ->where(['is_del' => 0, 'orderCode' => $sale['orderCode'],'status'=>1])
- ->sum('num');
- $usable = $sale['wsend_num'] - intval($wait_out);
- if($usable>0){
- $stock = Db::name('good_stock')->where($good)
- ->inc('usable_stock',$usable)
- ->update();
- if ($stock == false) throw new Exception('商品库存更新失败');
- }
- }
- }
- }
-
- if($sale['order_type'] == 4){
- $fill =Db::name("filing")->where(["filingCode"=>$sale["platform_order"]])->findOrEmpty();
- if(empty($fill)) throw new Exception($sale['orderCode'] . '未找到对应得报备单');
- $fullData=[
- 'transfer_num'=>$fill['transfer_num']-$sale['wsend_num'],
- 'wait_num'=>$fill['wait_num']+$sale['wsend_num'],
- 'status'=>$fill['wait_num']+$sale['wsend_num']==0?4:
- ($fill['transfer_num']-$sale['wsend_num']==0?2:3)];
-
- $fillup=Db::name('filing')
- ->where($fill)
- ->data($fullData)
- ->update();
- $stn = ['order_code' => $fill['filingCode'], 'status' =>$fullData['status'], 'action_remark' => '', 'action_type' => 'status'];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], $stn, 'BBD', $fill['status'],$fullData);
- if($fillup==false)throw new Exception($sale['platform_order'] . '报备单更新失败');
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- 'order_type' => 'BBD',
- 'order_code' => $fill['filingCode'],//出库单号
- 'order_id' => $fill['id'],
- 'order_status' =>$fullData['status'],
- 'before_status' => $fill['status'],
- 'wait_id'=>0,
- 'wait_name'=>0,
- ]);
- }
- if($sale['order_source'] == 11){
- $fill =(new BbcFill())->where(['fillCode'=>$sale['other_orderNo']])->findOrEmpty();
- if($fill->isEmpty()) throw new Exception($sale['orderCode'] . '未找到对应得业务报备单');
- if($fill->transfer_num <$sale['wsend_num'])throw new Exception($sale['orderCode'] . '对应得业务报备单已转单数量不足');
- $fill->transfer_num -=$sale['wsend_num'];
- $fill->status=$fill->transfer_num >0?2:1;
- $upd=$fill->save();
- if($upd==false)throw new \Exception('业务报备单更新失败');
- }
- $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$sale['orderCode'], "isCgd"=>1]);
- if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
- Db::rollback();
- return json_show(10005, $fininfo['message']??'结算校验失败',$fininfo['data']??[]);
- }
- $thtemp=[
- "orderCode"=>$sale["orderCode"],
- "th_type"=>4,//取消订单
- "th_num"=>$sale["good_num"],
- "th_fee"=>$sale["total_price"],
- "thCode"=>$sale["orderCode"],
- "cat_id"=>$sale["cat_id"],
- "good_name"=>$sale["good_name"],
- "spuCode"=>$sale["good_code"],
- "apply_id"=>$this->uid,
- "apply_name"=>$this->uname,
- "addtime"=>$date
- ];
- $th[]=$thtemp;
- //修改状态,添加待办
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $sale['orderCode'],//销售单号
- "status" => $sale['sale_status'],//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "XSQRD", 3, ['orderCode' => $orderCode]);
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_type" => 'XSQRD',
- "order_code" => $sale['orderCode'],
- "order_id" => $sale['sale_id'],
- "order_status" => 3,
- "before_status" => $sale['sale_status'],
- 'holder_id' => $sale['good_createrid'],
- ]);
- if ($sale['cgdNo']) {
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $sale['cgdNo'],//销售单号
- "status" => $sale['cgd_status'],//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "CGD", 4, ['orderCode' => $sale['cgdNo']]);
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_type" => 'CGD',
- "order_code" => $sale['cgdNo'],
- "order_id" => $sale['cgd_id'],
- "order_status" => 4,
- "before_status" => $sale['cgd_status'],
- 'holder_id' => $sale['cgder_id'],
- ]);
- $cgdId[]=$sale['cgd_id'];
- }
- }
- $orderup= Db::name('sale')
- ->where(['is_del' => 0, 'id' => array_column($list, 'sale_id')])
- ->update([
- 'status' => 3,
- 'th_num' => Db::raw("good_num"),
- 'th_fee' =>Db::raw("total_price"),
- 'send_num' =>Db::raw("good_num"),
- 'wsend_num' =>0,
- 'send_status' =>3,
- 'updatetime' => $date
- ]);
- if($orderup==false) throw new \Exception("订单状态更新失败");
-
- $thin= Db::name("th_data")->insertAll($th);
- if($thin==false) throw new \Exception('订单取消失败');
- if(!empty($cgdId)){
- $cgdup=Db::name('purchease_order')
- ->where(['is_del' => 0, 'id' => $cgdId])
- ->update([
- 'status' => 4,
- 'th_num' => Db::raw('wsend_num+send_num'),
- 'th_fee' =>Db::raw('total_fee'),
- 'send_num' =>Db::raw('wsend_num+send_num'),
- 'wsend_num' =>0,
- 'send_status' =>3,
- 'updatetime' => $date]);
- if($cgdup==false) throw new \Exception('采购单取消失败');
- }
-
- $out_list = Db::name('order_out')
- ->where(['is_del' => 0, 'orderCode' => $orderCode])
- ->select()
- ->toArray();
- if (!empty($out_list)) {
- $sen= Db::name('order_out')
- ->where(['is_del' => 0, 'orderCode' => $orderCode])
- ->update(['status' => 5, 'updatetime' => $date]);
- if($sen==false) throw new \Exception('发货单取消失败');
- foreach ($out_list as $out) {
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $out['outCode'],//销售单号
- "status" => $out['status'],//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "CKD", 5, $out);
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_type" => 'CKD',
- "order_code" => $out['outCode'],
- "order_id" => $out['id'],
- "order_status" => 5,
- "before_status" => $out['status'],
- 'holder_id' => $out['apply_id'],
- ]);
- }
- }
- $ooc_list = Db::name('order_out_child')
- ->where(['is_del' => 0, 'orderCode' => $orderCode])
- ->select()
- ->toArray();
- if (!empty($ooc_list)) {
- $child= Db::name('order_out_child')
- ->where(['is_del' => 0, 'orderCode' => $orderCode])
- ->update(['status' => 5, 'updatetime' => $date]);
- if ($child == false) throw new Exception('发货工单更新失败');
- foreach ($ooc_list as $ooc) {
- $stockinfo = Db::name("good_stock")->where(["spuCode" => $ooc['spuCode'], "wsm_code" => $ooc['wsm_code']])->findOrEmpty();
- if (empty($stockinfo)) throw new Exception('未找到库存信息');
- $stockup = [
- "usable_stock" =>$ooc['order_type']==1? $stockinfo['usable_stock'] + $ooc['num']:$stockinfo['usable_stock'],
- "wait_out_stock" => $stockinfo['wait_out_stock'] - $ooc['num'],
- "updatetime" => $date
- ];
- $ysup = Db::name("good_stock")->where($stockinfo)->update($stockup);
- if ($ysup == false) throw new Exception('库存信息更新失败');
- if($ooc['order_type']==1)GoodStockInfo::ChildReturnBn($ooc['outChildCode'], $stockinfo['id'], $ooc['num']);//处理bn数据
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $ooc['outChildCode'],//销售单号
- "status" => $ooc['status'],//这里的status是之前的值
- "action_remark" => '',//备注
- "action_type" => "status"//新建create,编辑edit,更改状态status
- ], "FHGD", 5, $ooc);
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_type" => 'FHGD',
- "order_code" => $ooc['outChildCode'],
- "order_id" => $ooc['id'],
- "order_status" => 5,
- "before_status" => $ooc['status'],
- 'holder_id' => $ooc['apply_id'],
- ]);
- }
- }
-
- Db::commit();
- return json_show(0, '操作成功');
- } catch (\think\Exception $exception) {
- Db::rollback();
- return json_show(1004, $exception->getMessage());
- }catch (Exception $exception){
- Db::rollback();
- return json_show(1004, $exception->getMessage());
- }
- }
- }
|