Sale.php 207 KB

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