Sale.php 206 KB

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