Sale.php 205 KB

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