Sale.php 272 KB

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