Sale.php 203 KB

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