Sale.php 204 KB

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