Sale.php 228 KB

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