Sale.php 138 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892
  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. class Sale extends Base
  10. {
  11. public function __construct(App $app)
  12. {
  13. parent::__construct($app);
  14. }
  15. public function create()
  16. {
  17. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  18. $orderCode=makeNo("CX");
  19. $customer_code= isset($this->post['customer_code'])&& $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :"";
  20. if($customer_code==""){
  21. return error_show(1002,"客户customer_code不能为空");
  22. }
  23. $customer=Db::name("customer_info")->where(["companyNo"=>$customer_code])->find();
  24. if($customer==false){
  25. return error_show(1004,"未找到客户数据");
  26. }
  27. $supplierNo= isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  28. if($supplierNo==""){
  29. return error_show(1002,"参数supplierNo不能为空");
  30. }
  31. $supplier=Db::name("business")->where(["companyNo"=>$supplierNo])->find();
  32. if($supplier==false){
  33. return error_show(1004,"未找到平台供应商数据");
  34. }
  35. $goodtype =isset($this->post['goodtype']) && $this->post['goodtype'] !=="" ?intval($this->post['goodtype']):"1";
  36. $order_type =isset($this->post['order_type']) && $this->post['order_type'] !=="" ?intval($this->post['order_type'])
  37. :"1";
  38. $sendtype =isset($this->post['sendtype']) && $this->post['sendtype'] !=="" ?intval($this->post['sendtype']):"";
  39. if($sendtype===''){
  40. return error_show(1004,"参数sendtype不能为空");
  41. }
  42. $platform_id =isset($this->post['platform_id']) && $this->post['platform_id'] !=="" ?intval($this->post['platform_id']):"";
  43. if($platform_id==''){
  44. return error_show(1004,"参数platform_id不能为空");
  45. }
  46. // $zxinfoNo= isset($this->post['zxinfoNo'])&& $this->post['zxinfoNo'] !=="" ? trim($this->post['zxinfoNo']) :"";
  47. // if($zxinfoNo=="" &&$order_type!==1){
  48. // return error_show(1002,"参数 zxinfoNo 不能为空");
  49. // }
  50. $platform_order =isset($this->post['platform_order']) && $this->post['platform_order'] !=="" ?trim($this->post['platform_order']):"";
  51. // if($platform_order==''){
  52. // return error_show(1004,"参数platform_order不能为空");
  53. // }
  54. $good_code =isset($this->post['good_code']) && $this->post['good_code'] !=="" ?trim($this->post['good_code']):"";
  55. if($good_code==''){
  56. return error_show(1004,"参数good_code不能为空");
  57. }
  58. $good_num =isset($this->post['good_num']) && $this->post['good_num'] !=="" ?intval($this->post['good_num']):"";
  59. if($good_num===''){
  60. return error_show(1004,"参数good_num不能为空");
  61. }
  62. $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  63. if($arrtime==""){
  64. return error_show(1004,"参数arrtime不能为空");
  65. }
  66. $paytime =isset($this->post['paytime'])&&$this->post['paytime']!=""? $this->post['paytime']:"";
  67. $workNo =isset($this->post['workNo'])&&$this->post['workNo']!=""? trim($this->post['workNo']):"";
  68. // $poNo =isset($this->post['poNo'])&&$this->post['poNo']!=""? trim($this->post['poNo']):"";
  69. $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  70. ->where(['a.skuCode' => $good_code])->find();
  71. if ($ct == false) {
  72. return error_show(1002, "未找到商品数据");
  73. }
  74. $goodinfo=$ct;
  75. $is_stock=$ct['is_stock'];
  76. $spuCode = $ct['spuCode'];
  77. $skuCode = $ct['skuCode'];
  78. $is_activity= isset($this->post['is_activity'])&&$this->post['is_activity']!=="" ?$this->post['is_activity']:"";
  79. $actcode= isset($this->post['act_code'])&&$this->post['act_code']!=="" ?trim($this->post['act_code']):"";
  80. if($order_type==1){
  81. if($is_activity===""){
  82. return error_show(1002, "参数is_activity不能为空");
  83. }
  84. if($is_activity==1 &&$actcode=="" ){
  85. return error_show(1002, "参数act_code不能为空");
  86. }
  87. }
  88. if($goodinfo['is_stock']==1){
  89. $stock =Db::name("good_stock")->where(["spuCode"=>$spuCode,"is_del"=>0])->find();
  90. if($stock==false||$stock['usable_stock']<$good_num){
  91. return error_show(1003,"库存数量不足");
  92. }
  93. }
  94. $origin = Db::name("good_nake")->where([["spuCode","=",$spuCode],["min_num","<=",$good_num],["is_del","=",
  95. 0]])->order("min_num desc")->find();
  96. if($origin==false){
  97. return error_show(1003,"未找到相关阶梯成本价格");
  98. }
  99. $origin_price = $origin['nake_fee'];
  100. $sale_price = isset($this->post['good_price'])&&$this->post['good_price']!="" ? floatval($this->post['good_price']):0;
  101. if($goodtype==1){
  102. $good = Db::name("good_ladder")->where(["skuCode"=>$skuCode,"is_del"=>0,"status"=>1])->where([["min_num",
  103. "<=",$good_num]])->order("min_num desc")->find();
  104. if($good==false){
  105. return error_show(1003,"未找到相关阶梯价格");
  106. }
  107. $sale_price = $good['sale_price'];
  108. if($is_activity==1){
  109. $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b","a.activity_code=b.activity_code")
  110. ->where(["a.skuCode"=>$skuCode,"a.activity_code"=>$actcode,"a.is_del"=>0,"a.status"=>1,"b.status"=>6,"b.is_del"=>0])
  111. ->find();
  112. if($act==false){
  113. return error_show(1003,"未找到相关活动价");
  114. }
  115. if($act['moq_num']>$good_num){
  116. return error_show(1003,"商品不满足活动价起订量{$act['moq_num']}");
  117. }
  118. if($act['activity_stock']<$good_num){
  119. return error_show(1003,"商品活动库存剩余{$act['activity_stock']}");
  120. }
  121. $sale_price=$act['activity_price'];
  122. }
  123. }
  124. $cgd=[
  125. "supplierNo"=>$ct['supplierNo'],
  126. "companyNo"=>$supplierNo,
  127. "orderCode"=>$orderCode,
  128. "spuCode"=>$ct['spuCode'],
  129. "skuCode"=>$ct['skuCode'],
  130. "good_name"=>$ct['good_name'],
  131. "sale_price"=>$origin_price,
  132. "total_fee"=>$origin_price*$good_num,
  133. "pakge_fee"=>$ct['packing_fee'],
  134. "cert_fee"=>$ct['cert_fee'],
  135. "open_fee"=>$ct['open_fee'],
  136. "cost_fee"=>$ct['cost_fee'],
  137. "mark_fee"=>$ct['mark_fee'],
  138. "demo_fee"=>$ct['demo_fee'],
  139. "good_num"=>$good_num,
  140. "good_type"=>$goodtype,
  141. "order_type"=>$order_type,
  142. ];
  143. $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
  144. if($sendtype==1){
  145. if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){
  146. return error_show(1004,"参数addrlist不能为空");
  147. }
  148. }
  149. $remark =isset($this->post['remark']) && $this->post['remark'] !=="" ?trim($this->post['remark']):"";
  150. $proofid= isset($this->post['proof_id'])&&$this->post['proof_id']===""?intval($this->post['proof_id']):"0";
  151. $apply_id =GetUserInfo($token);
  152. if(empty($apply_id)||$apply_id['code']!=0){
  153. return error_show(1002,"申请人数据不存在");
  154. }
  155. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  156. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  157. Db::startTrans();
  158. try {
  159. $data=[
  160. "orderCode"=>$orderCode,
  161. "good_code"=>$spuCode,
  162. "skuCode"=>$skuCode,
  163. "customer_code"=>$customer_code,
  164. "good_name"=>isset($goodinfo['good_name'])&&$goodinfo['good_name']!==''?$goodinfo['good_name']:'',
  165. "good_num"=>$good_num,
  166. "cat_id"=>$goodinfo['cat_id'],
  167. "apply_id"=>$rm,
  168. "apply_name"=>$ri,
  169. "origin_price"=>$origin_price,
  170. "sale_price"=>$sale_price,
  171. "post_fee"=>0,
  172. "status"=>0,
  173. "send_num"=>0,
  174. "wsend_num"=>$good_num,
  175. "send_status"=>1,
  176. "good_type"=>$goodtype,
  177. "send_type"=>$sendtype,
  178. "supplierNo"=>$supplierNo,
  179. "is_del"=>0,
  180. "zxNo"=>"",
  181. "platform_order"=>$platform_order,
  182. "platform_id"=>$platform_id,
  183. "remark"=>$remark,
  184. "is_stock"=>$is_stock,
  185. "is_activity"=>$is_activity===""?0:$is_activity,
  186. "proof_id"=>$proofid,
  187. "order_type"=>$order_type,
  188. // "poNo"=>$poNo,
  189. "workNo"=>$workNo,
  190. "addtime"=>date("Y-m-d H:i:s"),
  191. "updatetime"=>date("Y-m-d H:i:s"),
  192. 'total_price'=>round($sale_price*$good_num,2),
  193. ];
  194. $paytime==""?"": $data['paytime'] = $paytime;
  195. $datainfo = Db::name('sale')->insert($data,true);
  196. if($datainfo>0){
  197. if($is_activity==1){
  198. $actup =[
  199. "activity_stock"=> $act['activity_stock'] - $good_num,
  200. "updatetime"=>date("Y-m-d H:i:s")
  201. ];
  202. $actupp= Db::name("activity_info")->where(["skuCode"=>$skuCode,"activity_code"=>$actcode,
  203. "is_del"=>0,"status"=>1])->save($actup);
  204. if($actupp==false){
  205. Db::rollback();
  206. return error_show(1002,"活动库存修改失败");
  207. }
  208. }
  209. if($is_stock==0){
  210. $bol=$this->createCgd($cgd);
  211. if($bol==false){
  212. Db::rollback();
  213. return error_show(1002,"咨询订单创建失败");
  214. }
  215. }else{
  216. $dd=[
  217. "orderCode"=>$orderCode,
  218. "spuCode"=>$spuCode,
  219. "total_num"=>$good_num,
  220. "merge_num"=>0,
  221. "balance_num"=>$good_num,
  222. "status"=>1,
  223. "is_del"=>0,
  224. "addtime"=>date("Y-m-d H:i:s"),
  225. "updatetime"=>date("Y-m-d H:i:s"),
  226. ];
  227. $db=Db::name("sale_bk")->insert($dd);
  228. if($db==false){
  229. Db::rollback();
  230. return error_show(1002,"咨询订单创建失败");
  231. }
  232. }
  233. if($sendtype==1){
  234. foreach ($addrlist as $value){
  235. $temp=[];
  236. $addrs=[];
  237. if($value['addr_code']!==''&&is_array($value['addr_code'])){
  238. $addrs['provice_code'] = $value['addr_code'][0];
  239. $addrs['city_code'] = $value['addr_code'][1];
  240. $addrs['area_code'] = $value['addr_code'][2];
  241. $addr = json_encode($addrs);
  242. }else{
  243. $addr = isset($value['addr_code'])?$value['addr_code']:'';
  244. }
  245. $temp['orderCode']=$orderCode;
  246. $temp['contactor']=$value['contactor'];
  247. $temp['mobile'] = $value['mobile'];
  248. $temp['addr'] = $value['addr'];
  249. $temp['addr_code']=$addr;
  250. $temp['customer_code'] =$customer_code;
  251. $temp['receipt_quantity']=$value['receipt_quantity'];
  252. $temp['post_fee'] =0;
  253. $temp['is_del'] =0;
  254. $temp['addtime'] =date("Y-m-d H:i:s");
  255. $temp['updatetime'] =date("Y-m-d H:i:s");
  256. $temp['arrive_time']=$arrtime;
  257. $vmp = Db::name('order_addr')->insert($temp,true);
  258. if($vmp>0){
  259. // $outCode=makeNo("CK");
  260. // $out=[
  261. // "orderCode"=>$orderCode,
  262. // "outCode"=>$outCode,
  263. // "apply_id"=>$rm,
  264. // "apply_name"=>$ri,
  265. // "addrid"=>$vmp,
  266. // "post_name"=>"",
  267. // "post_code"=>"",
  268. // "post_fee"=>0,
  269. // "sendtime"=>date("Y-m-d H:i:s"),
  270. // "send_num"=>$value['receipt_quantity'],
  271. // "check_num"=>0,
  272. // "error_num"=>0,
  273. // "wsm_code"=>"",
  274. // "order_type"=>$order_type,
  275. // "status"=>0,
  276. // "addtime"=>date("Y-m-d H:i:s"),
  277. // "updatetime"=>date("Y-m-d H:i:s")
  278. // ];
  279. // $ou =Db::name("order_out")->insert($out);
  280. // if($ou==false){
  281. // Db::rollback();
  282. // return error_show(1002,"发货地址添加创建失败");
  283. // }
  284. // if($is_stock==0){
  285. // $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  286. // ->find();
  287. // if($order==false){
  288. // Db::rollback();
  289. // return error_show(1006,"采购单关联数据未找到");
  290. // }
  291. // $order['send_num']+=$value['receipt_quantity'];
  292. // $order['wsend_num']-=$value['receipt_quantity'];
  293. // if($order['wsend_num']<0){
  294. // Db::rollback();
  295. // return error_show(1002,"发货数量已超出总数");
  296. // }
  297. // $ups = Db::name("order_num")->save($order);
  298. // if($ups){
  299. // $tep=[
  300. // "cgdNo"=>$order['cgdNo'],
  301. // "outCode"=>$outCode,
  302. // "send_num"=>$value['receipt_quantity'],
  303. // "status"=>1,
  304. // "addtime"=>date("Y-m-d H:i:s"),
  305. // "updatetime"=>date("Y-m-d H:i:s")
  306. // ];
  307. // $sen=Db::name("order_send")->save($tep);
  308. // if($sen==false){
  309. // Db::rollback();
  310. // return error_show(1002,"发货地址添加创建失败");
  311. // }
  312. // }
  313. // }
  314. }else{
  315. Db::rollback();
  316. return error_show(1002,"发货地址添加创建失败");
  317. }
  318. }
  319. }
  320. Db::commit();
  321. return error_show(0,"咨询订单创建成功",["order_code"=>$orderCode]);
  322. }
  323. Db::rollback();
  324. return error_show(1002,"咨询订单创建失败");
  325. }catch(\Exception $e){
  326. Db::rollback();
  327. return error_show(1005,$e->getMessage());
  328. }
  329. }
  330. public function createCgd($data){
  331. $cgdCode = makeNo("CG");
  332. $supplier=Db::name("supplier")->where(["code"=>$data['supplierNo'],"is_del"=>0])->find();
  333. //echo Db::name("supplier")->getLastSql();
  334. if($supplier==false){
  335. return false;
  336. }
  337. $wsm= Db::name("warehouse_info")->where(["supplierNo"=>$data["supplierNo"],"companyNo"=>$data['companyNo'],"is_del"=>0])->find();
  338. if($wsm==false){
  339. $wsm_code = makeNo("WSM");
  340. $inwsm=[
  341. "wsm_code"=>$wsm_code,
  342. "name"=>$supplier['name'],
  343. "wsm_type"=>2,
  344. "supplierNo"=>$supplier['code'],
  345. "addr"=>"",
  346. "addrs_code"=>"",
  347. "contactor"=>0,
  348. "contactor_name"=>0,
  349. "mobile"=>"",
  350. "position"=>"",
  351. "companyNo"=>$data['companyNo'],
  352. "status"=>1,
  353. "is_del"=>0,
  354. "addtime"=>date("Y-m-d H:i:s"),
  355. "updatetime"=>date("Y-m-d H:i:s")
  356. ];
  357. $in = Db::name("warehouse_info")->insert($inwsm);
  358. if($in==false){
  359. return false;
  360. }
  361. }else{
  362. $wsm_code =$wsm['wsm_code'];
  363. }
  364. $cg =["cgdNo"=>$cgdCode,
  365. "bkcode"=>"",
  366. "wsm_code"=>$wsm_code,
  367. "cgder"=>$supplier['person'],
  368. "cgder_id"=>$supplier['personid'],
  369. "spuCode"=>$data['spuCode'],
  370. "skuCode"=>$data['skuCode'],
  371. "good_name"=>$data['good_name'],
  372. "good_num"=>$data['good_num'],
  373. "good_price"=>$data['sale_price'],
  374. "total_fee"=>$data['total_fee'],
  375. "pakge_fee"=>$data['pakge_fee'],
  376. "cert_fee"=>$data['cert_fee'],
  377. "open_fee"=>$data['open_fee'],
  378. "teach_fee"=>$data['cost_fee'],
  379. "mark_fee"=>$data['mark_fee'],
  380. "demo_fee"=>$data['demo_fee'],
  381. #"weight"=>$data['weight'],
  382. "diff_weight"=>"0",
  383. "diff_fee"=>"0",
  384. "gold_price"=>"0",
  385. "supplierNo"=>$data['supplierNo'],
  386. "supplier_name"=>$supplier['name'],
  387. "companyNo"=>$data['companyNo'],
  388. "send_status"=>1,
  389. "send_num"=>"0",
  390. "wsend_num"=>$data['good_num'],
  391. "remark"=>"",
  392. "status"=>0,
  393. "lasttime"=>date("Y-m-d H:i:s"),
  394. "is_del"=>0,
  395. "order_type"=>$data['order_type'],
  396. "good_type"=>$data['good_type'],
  397. "addtime"=>date("Y-m-d H:i:s"),
  398. "updatetime"=>date("Y-m-d H:i:s")
  399. ];
  400. $up =Db::name("purchease_order")->insert($cg);
  401. if($up){
  402. $rela=[
  403. "orderCode"=>$data['orderCode'],
  404. "cgdNo"=>$cgdCode,
  405. "spuCode"=>$data['spuCode'],
  406. "good_num"=>$data['good_num'],
  407. "wsend_num"=>$data['good_num'],
  408. "send_num"=>0,
  409. "wait_num"=>0,
  410. "status"=>1,
  411. "source"=>2
  412. ];
  413. $re =Db::name("order_num")->save($rela);
  414. if($re==false){
  415. return false;
  416. }else{
  417. $stokc =Db::name("good_stock")->where(['spuCode'=>$data['spuCode'],"wsm_code"=>$wsm_code,
  418. "is_del"=>0])->find();
  419. if($stokc==false){
  420. $stokc=[
  421. "spuCode"=>$data['spuCode'],
  422. "wsm_code"=>$wsm_code,
  423. "wait_in_stock"=>$data['good_num'],
  424. "wait_out_stock"=>0,
  425. "usable_stock"=>0,
  426. "intra_stock"=>0,
  427. "total_stock"=>$data['good_num'],
  428. "status"=>1,
  429. "addtime"=>date("Y-m-d H:i:s"),
  430. "updatetime"=>date("Y-m-d H:i:s")
  431. ];
  432. }else{
  433. $stokc['wait_in_stock']+=$data['good_num'];
  434. $stokc['updatetime']=date("Y-m-d H:i:s");
  435. }
  436. $stoc= Db::name("good_stock")->save($stokc);
  437. if($stoc==false){
  438. return false;
  439. }
  440. return true;
  441. }
  442. }else{
  443. return false;
  444. }
  445. }
  446. public function addAddr(){
  447. $orderCode = isset($this->post['orderCode'])&&$this->post['orderCode']!=""? trim($this->post['orderCode']):"";
  448. $etid = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->find();
  449. if (empty($etid)) {
  450. return error_show(1002, "未找到数据");
  451. }
  452. $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  453. if($arrtime==""){
  454. return error_show(1004,"参数arrtime不能为空");
  455. }
  456. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  457. ->select()->toArray();
  458. if(empty($order)){
  459. return error_show(1004,"未找到可以发货得采购单数据");
  460. }
  461. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  462. $apply_id =GetUserInfo($token);
  463. if(empty($apply_id)||$apply_id['code']!=0){
  464. return error_show(1002,"申请人数据不存在");
  465. }
  466. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  467. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  468. $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
  469. if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){
  470. return error_show(1004,"参数addrlist不能为空");
  471. }
  472. Db::startTrans();
  473. try{
  474. foreach ($addrlist as $value){
  475. $temp=[];
  476. $addrs=[];
  477. if($value['addr_code']!==''&&is_array($value['addr_code'])){
  478. $addrs['provice_code'] = $value['addr_code'][0];
  479. $addrs['city_code'] = $value['addr_code'][1];
  480. $addrs['area_code'] = $value['addr_code'][2];
  481. $addr = json_encode($addrs);
  482. }else{
  483. $addr = isset($value['addr_code'])?$value['addr_code']:'';
  484. }
  485. $temp['orderCode']=$orderCode;
  486. $temp['contactor']=$value['contactor'];
  487. $temp['mobile'] = $value['mobile'];
  488. $temp['addr'] = $value['addr'];
  489. $temp['addr_code']=$addr;
  490. $temp['customer_code'] =$etid['customer_code'];
  491. $temp['receipt_quantity']=$value['receipt_quantity'];
  492. $temp['post_fee'] =0;
  493. $temp['is_del'] =0;
  494. $temp['addtime'] =date("Y-m-d H:i:s");
  495. $temp['updatetime'] =date("Y-m-d H:i:s");
  496. $temp['arrive_time']=$arrtime;
  497. $vmp = Db::name('order_addr')->insert($temp,true);
  498. if($vmp>0){
  499. $outCode=makeNo("CK");
  500. $out=[
  501. "orderCode"=>$orderCode,
  502. "outCode"=>$outCode,
  503. "apply_id"=>$rm,
  504. "apply_name"=>$ri,
  505. "addrid"=>$vmp,
  506. "post_name"=>"",
  507. "post_code"=>"",
  508. "post_fee"=>0,
  509. "sendtime"=>date("Y-m-d H:i:s"),
  510. "send_num"=>$value['receipt_quantity'],
  511. "check_num"=>0,
  512. "error_num"=>0,
  513. "wsm_code"=>"",
  514. "order_type"=>$etid['order_type'],
  515. "status"=>0,
  516. "addtime"=>date("Y-m-d H:i:s"),
  517. "updatetime"=>date("Y-m-d H:i:s")
  518. ];
  519. $ou =Db::name("order_out")->insert($out);
  520. if($ou==false){
  521. Db::rollback();
  522. return error_show(1002,"发货地址添加创建失败");
  523. }
  524. $num = $value['receipt_quantity'];
  525. $orsend=[];
  526. foreach ($order as $val){
  527. $tep=[];$ornum=0;
  528. if($val['wsend_num']>=$num){
  529. $val['wsend_num']-=$num;
  530. $val['send_num']+=$num;
  531. $ornum =$num;
  532. $num=0;
  533. }else{
  534. $num-=$val['wsend_num'];
  535. $val['send_num']+=$val['wsend_num'];
  536. $ornum =$val['wsend_num'];
  537. $val['wsend_num']=0;
  538. }
  539. $or =Db::name("order_num")->save($val);
  540. if($or==false){
  541. Db::rollback();
  542. return error_show(1002,"发货地址添加创建失败");
  543. }
  544. $tep=[
  545. "cgdNo"=>$val['cgdNo'],
  546. "outCode"=>$outCode,
  547. "send_num"=>$ornum,
  548. "status"=>1,
  549. "addtime"=>date("Y-m-d H:i:s"),
  550. "updatetime"=>date("Y-m-d H:i:s")
  551. ];
  552. $sen=Db::name("order_send")->save($tep);
  553. if($sen==false){
  554. Db::rollback();
  555. return error_show(1002,"发货地址添加创建失败");
  556. }
  557. if($num==0){
  558. break;
  559. }
  560. }
  561. }else{
  562. Db::rollback();
  563. return error_show(1002,"发货地址添加创建失败");
  564. }
  565. }
  566. Db::commit();
  567. return app_show(0,"发货地址添加完成");
  568. }catch(\Exception $e){
  569. Db::rollback();
  570. return error_show(1002,$e->getMessage());
  571. }
  572. }
  573. public function consultOrder(){
  574. $bidNo =isset($this->post['bidNo'])&&$this->post['bidNo']!="" ? trim($this->post['bidNo']):"";
  575. if($bidNo==""){
  576. return error_show(1003,"参数bidNo不能为空");
  577. }
  578. $zxinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  579. if($zxinfo==false){
  580. return error_show(1003,"未找到咨询单商品信息");
  581. }
  582. if($zxinfo['status']!=6){
  583. return error_show(1003,"咨询单状态有误无法转单");
  584. }
  585. $zx =Db::name("consult_info")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->find();
  586. if($zx==false){
  587. return error_show(1003,"未找到咨询单信息");
  588. }
  589. if($zx['status']!=4){
  590. return error_show(1003,"咨询单状态有误无法转单");
  591. }
  592. $zxorder =Db::name("consult_order")->where(["zxNo"=>$zx["zxNo"],"is_del"=>0])->find();
  593. if($zxorder==false){
  594. return error_show(1003,"未找到咨询单信息");
  595. }
  596. $good_num =isset($this->post['good_num'])&&$this->post['good_num']!="" ? intval($this->post['good_num']):"";
  597. if($good_num===""){
  598. return error_show(1003,"参数 good_num 不能为空");
  599. }
  600. $sendtype = isset($this->post['sendtype'])&&$this->post['sendtype']!="" ? intval($this->post['sendtype']):"";
  601. if($sendtype==""){
  602. return error_show(1003,"参数sendtype不能为空");
  603. }
  604. $orderCode = makeNo("QR");
  605. $spuCode = $zxinfo['spuCode'];
  606. $skuCode = "";
  607. $is_stock=0;
  608. $cgd=[
  609. "supplierNo"=>$zxinfo['supplierNo'],
  610. "companyNo"=>$zxorder['companyNo'],
  611. "spuCode"=>$spuCode,
  612. "skuCode"=>$skuCode,
  613. "orderCode"=>$orderCode,
  614. "good_name"=>$zxinfo['good_name'],
  615. "sale_price"=>$zxinfo['sale_price'],
  616. "total_fee"=>$zxinfo['total_fee'],
  617. "pakge_fee"=>$zxinfo['pakge_fee'],
  618. "cert_fee"=>$zxinfo['cert_fee'],
  619. "open_fee"=>$zxinfo['open_fee'],
  620. "cost_fee"=>$zxinfo['cost_fee'],
  621. "mark_fee"=>$zxinfo['mark_fee'],
  622. "demo_fee"=>$zxinfo['demo_fee'],
  623. "good_num"=>$good_num,
  624. "good_type"=>1,
  625. "is_diff"=>$zxinfo['is_diff'],
  626. "order_type"=>3,
  627. ];
  628. $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
  629. if($token==""){
  630. return error_show(102, "参数token不能为空");
  631. }
  632. $apply_id = GetUserInfo($token);
  633. if (empty($apply_id) || $apply_id['code'] != 0) {
  634. return error_show(102, "申请人数据不存在");
  635. }
  636. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  637. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  638. $va = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  639. if($sendtype==1){
  640. if ($va == "") {
  641. return error_show(1002, "参数order_addr不能为空");
  642. }
  643. }
  644. $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  645. if($arrtime==""){
  646. return error_show(1002, "参数arrtime不能为空");
  647. }
  648. Db::startTrans();
  649. try{
  650. $data=[
  651. "orderCode"=>$orderCode,
  652. "good_code"=>$spuCode,
  653. "skuCode"=>$skuCode,
  654. "customer_code"=>$zxorder['khNo'],
  655. "good_name"=>isset($zxinfo['good_name'])&&$zxinfo['good_name']!==''?$zxinfo['good_name']:'',
  656. "good_num"=>$good_num,
  657. "cat_id"=>$zxinfo['cat_id'],
  658. "apply_id"=>$rm,
  659. "apply_name"=>$ri,
  660. "origin_price"=>$zxinfo['nake_fee'],
  661. "sale_price"=>$zxinfo['sale_price'],
  662. "post_fee"=>0,
  663. "status"=>0,
  664. "send_num"=>0,
  665. "wsend_num"=>$good_num,
  666. "send_status"=>1,
  667. "good_type"=>1,
  668. "send_type"=>$sendtype,
  669. "supplierNo"=>$zxorder['companyNo'],
  670. "is_del"=>0,
  671. "zxNo"=>$bidNo,
  672. "platform_order"=>"",
  673. "platform_id"=>0,
  674. "remark"=>"",
  675. "arrivetime"=>$arrtime,
  676. "is_stock"=>0,
  677. "is_activity"=>0,
  678. "proof_id"=>0,
  679. "order_type"=>3,
  680. "addtime"=>date("Y-m-d H:i:s"),
  681. "updatetime"=>date("Y-m-d H:i:s"),
  682. 'total_price'=>round($zxinfo['sale_price']*$good_num,2),
  683. ];
  684. $datainfo = Db::name('sale')->insert($data, true);
  685. if($datainfo>0){
  686. $zx['status']=5;
  687. $zx['updatetime']=date("Y-m-d H:i:s");
  688. $sa=Db::name("consult_info")->save($zx);
  689. if($sa==false){
  690. Db::rollback();
  691. return error_show(1002,"咨询单修改失败");
  692. }
  693. $bol=$this->createCgd($cgd);
  694. if($bol==false){
  695. Db::rollback();
  696. return error_show(1002,"咨询订单创建失败");
  697. }
  698. $limt=[
  699. "spuCode"=>$zxinfo['spuCode'],
  700. "good_name"=>$zxinfo['good_name'],
  701. "brand_id"=>$zxinfo['brand_id'],
  702. "good_unit"=>$zxinfo['good_name'],
  703. "cat_id"=>$zxinfo['cat_id'],
  704. "good_type"=>0,
  705. "moq"=>1,
  706. "customized"=>$zxinfo['work_day'],
  707. "tax"=>$zxinfo['tax'],
  708. "supplierNo"=>$zxinfo["supplierNo"],
  709. "is_auth"=>0,
  710. "craft_desc"=>$zxinfo['good_name'],
  711. "good_remark"=>"",
  712. "good_img"=>$zxinfo['good_img'],
  713. "good_thumb_img"=>"",
  714. "good_info_img"=>"",
  715. "status"=>1,
  716. "is_del"=>0,
  717. "createrid"=>$rm,
  718. "creater"=>$ri,
  719. "addtime"=>date("Y-m-d H:i:s"),
  720. "updatetime"=>date("Y-m-d H:i:s")
  721. ];
  722. $good = Db::name("good_zixun")->insert($limt);
  723. if(!$good){
  724. Db::rollback();
  725. return error_show(1006,"咨询商品录入失败");
  726. }
  727. if(!empty($va)){
  728. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  729. ->find();
  730. if($order==false){
  731. Db::rollback();
  732. return error_show(1006,"采购单关联数据未找到");
  733. }
  734. foreach ($va as $value){
  735. $temp=[];
  736. $addrs=[];
  737. if($value['addr_code']!==''&&is_array($value['addr_code'])){
  738. $addrs['provice_code'] = $value['addr_code'][0];
  739. $addrs['city_code'] = $value['addr_code'][1];
  740. $addrs['area_code'] = $value['addr_code'][2];
  741. $addr = json_encode($addrs);
  742. }else{
  743. $addr = isset($value['addr_code'])?$value['addr_code']:'';
  744. }
  745. $temp['orderCode']=$orderCode;
  746. $temp['contactor']=$value['contactor'];
  747. $temp['mobile'] = $value['mobile'];
  748. $temp['addr'] = $value['addr'];
  749. $temp['addr_code']=$addr;
  750. $temp['customer_code'] =$zxorder['khNo'];
  751. $temp['receipt_quantity']=$value['receipt_quantity'];
  752. $temp['post_fee'] =0;
  753. $temp['is_del'] =0;
  754. $temp['addtime'] =date("Y-m-d H:i:s");
  755. $temp['updatetime'] =date("Y-m-d H:i:s");
  756. $temp['arrive_time']=$arrtime;
  757. $vmp = Db::name('order_addr')->insert($temp,true);
  758. if($vmp>0){
  759. $outCode=makeNo("CK");
  760. $out=[
  761. "orderCode"=>$orderCode,
  762. "outCode"=>$outCode,
  763. "apply_id"=>$rm,
  764. "apply_name"=>$ri,
  765. "addrid"=>$vmp,
  766. "post_name"=>"",
  767. "post_code"=>"",
  768. "post_fee"=>0,
  769. "sendtime"=>date("Y-m-d H:i:s"),
  770. "send_num"=>$value['receipt_quantity'],
  771. "check_num"=>0,
  772. "error_num"=>0,
  773. "wsm_code"=>"",
  774. "order_type"=>3,
  775. "status"=>0,
  776. "addtime"=>date("Y-m-d H:i:s"),
  777. "updatetime"=>date("Y-m-d H:i:s")
  778. ];
  779. $ou =Db::name("order_out")->insert($out);
  780. if($ou==false){
  781. Db::rollback();
  782. return error_show(1002,"发货地址添加创建失败");
  783. }
  784. $order['send_num']+=$value['receipt_quantity'];
  785. $order['wsend_num']-=$value['receipt_quantity'];
  786. if($order['wsend_num']<0){
  787. Db::rollback();
  788. return error_show(1002,"发货数量已超出总数");
  789. }
  790. $ups = Db::name("order_num")->save($order);
  791. if($ups){
  792. $tep=[
  793. "cgdNo"=>$order['cgdNo'],
  794. "outCode"=>$outCode,
  795. "send_num"=>$value['receipt_quantity'],
  796. "status"=>1,
  797. "addtime"=>date("Y-m-d H:i:s"),
  798. "updatetime"=>date("Y-m-d H:i:s")
  799. ];
  800. $sen=Db::name("order_send")->save($tep);
  801. if($sen==false){
  802. Db::rollback();
  803. return error_show(1002,"发货地址添加创建失败");
  804. }
  805. }
  806. }else{
  807. Db::rollback();
  808. return error_show(1002,"发货地址添加创建失败");
  809. }
  810. }
  811. }
  812. Db::commit();
  813. return error_show(0,"咨询订单创建成功",["order_code"=>$orderCode]);
  814. }
  815. Db::rollback();
  816. return error_show(1002,"咨询订单创建失败");
  817. }catch(\Exception $e){
  818. Db::rollback();
  819. return error_show(1003,$e->getMessage());
  820. }
  821. }
  822. /**
  823. * @return \think\response\Json|void
  824. * @throws \think\db\exception\DataNotFoundException
  825. * @throws \think\db\exception\DbException
  826. * @throws \think\db\exception\ModelNotFoundException
  827. */
  828. public function projectCreate(){
  829. $planNo =isset($this->post['planNo'])&&$this->post['planNo']!=""?trim($this->post['planNo']):"";
  830. if($planNo==""){
  831. return error_show(1004,"参数planNo不能为空");
  832. }
  833. $plan =Db::name("project_plan")->where(["planNo"=>$planNo,"is_del"=>0])->find();
  834. if($plan==false){
  835. return error_show(1004,"未找到方案信息");
  836. }
  837. $feedbackid = Db::name("project_plan_rela")->where(["planNo"=>$planNo,"is_del"=>0])->column("feedback_id,sale_price,sale_num");
  838. if($feedbackid==false){
  839. return error_show(1004,"未找到方案反馈信息");
  840. }
  841. $project = Db::name("project")->where(["projectNo"=>$plan['projectNo'],"is_del"=>0])->find();
  842. if($project==false){
  843. return error_show(1004,"未找到方案信息");
  844. }
  845. $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  846. if($arrtime==""){
  847. return error_show(1002, "参数arrtime不能为空");
  848. }
  849. $planinfo =isset($this->post['planinfo'])&&!empty($this->post['planinfo']) ?$this->post['planinfo']:"";
  850. if($planinfo==""){
  851. return error_show(1002, "参数planinfo不能为空");
  852. }
  853. $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
  854. if($token==""){
  855. return error_show(102, "参数token不能为空");
  856. }
  857. $apply_id = GetUserInfo($token);
  858. if (empty($apply_id) || $apply_id['code'] != 0) {
  859. return error_show(102, "申请人数据不存在");
  860. }
  861. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  862. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  863. Db::startTrans();
  864. try {
  865. $feedid = array_column($feedbackid,"feedback_id");
  866. foreach ($planinfo as $value){
  867. $good=[];
  868. $feedback = Db::name("project_feedback")->where(["id"=>$value['feedback_id'],"projectNo"=>$plan['projectNo'],
  869. "is_del"=>0])->find();
  870. if($feedback==false){
  871. Db::rollback();
  872. return error_show(1002, "反馈数据未找到");
  873. }
  874. $key =array_search($feedback['id'],$feedid);
  875. $price = $feedbackid[$key];
  876. $good['spuCode'] = $feedback['spuCode'];
  877. $good['skuCode'] = $feedback['skuCode'];
  878. $good['good_num'] = $price['sale_num'];
  879. $good['sendtype'] = $value['sendtype'];
  880. $good['sale_price']=$price['sale_price'];
  881. $good['origin_price']=$feedback['origin_price'];
  882. $good['companyNo']=$project['companyNo'];
  883. $good['customerNo']=$project['khNo'];
  884. $good['pgNo']=$feedback['pgNo'];
  885. $good['arrtime']=$arrtime;
  886. $good['rm']=$rm;
  887. $good['ri']=$ri;
  888. if($value['sendtype']==1){
  889. if(!isset($value['addrlist'])||empty($value['addrlist'])){
  890. Db::rollback();
  891. return error_show(1002, "订单地址不能为空");
  892. }
  893. $good['addrlist'] = $value['addrlist'];
  894. }
  895. if($feedback['data_source']==1){
  896. $feed=$this->project_good($good);
  897. }else{
  898. $feed=$this->project_zx($good);
  899. }
  900. if($feed==false){
  901. Db::rollback();
  902. return error_show(1002, "咨询订单生成失败");
  903. }
  904. $feedback['status']=2;
  905. $feedback['updatetime']=date("Y-m-d H:i:s");
  906. $fed =Db::name("project_feedback")->save($feedback);
  907. if($fed==false){
  908. Db::rollback();
  909. return error_show(1002, "项目订单生成失败");
  910. }
  911. }
  912. $plan['status']=2;
  913. $plan['updatetime']=date("Y-m-d H:i:s");
  914. $in =Db::name("project_plan")->save($plan);
  915. if($in==false){
  916. Db::rollback();
  917. return error_show(1002, "项目订单生成失败");
  918. }
  919. $project["status"]=6;
  920. $project['updatetime']=date("Y-m-d H:i:s");
  921. $pr =Db::name("project")->save($project);
  922. if($pr==false){
  923. Db::rollback();
  924. return error_show(1002, "项目订单生成失败");
  925. }
  926. Db::commit();
  927. return app_show(0, "咨询订单生成成功");
  928. }catch (\Exception $e){
  929. Db::rollback();
  930. return error_show(1002, $e->getMessage());
  931. }
  932. }
  933. /**
  934. * @param $data
  935. * @return false
  936. * @throws \think\db\exception\DataNotFoundException
  937. * @throws \think\db\exception\DbException
  938. * @throws \think\db\exception\ModelNotFoundException
  939. *
  940. */
  941. public function project_zx($data){
  942. $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$data['spuCode'],"is_del"=>0])->find();
  943. if($goodinfo==false){
  944. return false;
  945. }
  946. $orderCode=makeNo("QR");
  947. $cgd=[
  948. "supplierNo"=>$goodinfo['supplierNo'],
  949. "companyNo"=>$data['companyNo'],
  950. "spuCode"=>$data['spuCode'],
  951. "skuCode"=>"",
  952. "orderCode"=>$orderCode,
  953. "good_name"=>$goodinfo['good_name'],
  954. "sale_price"=>$data['origin_price'],
  955. "total_fee"=>$data['origin_price']*$data['good_num'],
  956. "pakge_fee"=>$goodinfo['pakge_fee'],
  957. "cert_fee"=>$goodinfo['cert_fee'],
  958. "open_fee"=>$goodinfo['open_fee'],
  959. "cost_fee"=>$goodinfo['cost_fee'],
  960. "mark_fee"=>$goodinfo['mark_fee'],
  961. "demo_fee"=>$goodinfo['demo_fee'],
  962. "good_num"=>$data['good_num'],
  963. "good_type"=>1,
  964. "order_type"=>4,
  965. ];
  966. $datas=[
  967. "orderCode"=>$orderCode,
  968. "good_code"=>$data['spuCode'],
  969. "skuCode"=>"",
  970. "customer_code"=>$data['customerNo'],
  971. "good_name"=>isset($goodinfo['good_name'])&&$goodinfo['good_name']!==''?$goodinfo['good_name']:'',
  972. "good_num"=>$data['good_num'],
  973. "cat_id"=>$goodinfo['cat_id'],
  974. "apply_id"=>$data['rm'],
  975. "apply_name"=>$data['ri'],
  976. "origin_price"=>$goodinfo['nake_fee'],
  977. "sale_price"=>$data['sale_price'],
  978. "post_fee"=>0,
  979. "status"=>0,
  980. "send_num"=>0,
  981. "wsend_num"=>$data['good_num'],
  982. "send_status"=>1,
  983. "good_type"=>1,
  984. "send_type"=>$data['sendtype'],
  985. "supplierNo"=>$data['companyNo'],
  986. "is_del"=>0,
  987. "zxNo"=>$data["pgNo"],
  988. "platform_order"=>"",
  989. "platform_id"=>0,
  990. "remark"=>"",
  991. "is_stock"=>0,
  992. "is_activity"=>0,
  993. "proof_id"=>0,
  994. "order_type"=>4,
  995. "addtime"=>date("Y-m-d H:i:s"),
  996. "updatetime"=>date("Y-m-d H:i:s"),
  997. 'total_price'=>round($data['sale_price']*$data['good_num'],2),
  998. ];
  999. $datainfo = Db::name('sale')->insert($datas, true);
  1000. if($datainfo>0){
  1001. $bol = $this->createCgd($cgd);
  1002. if ($bol == false) {
  1003. return false;
  1004. }
  1005. $goodinfo['status']=6;
  1006. $goodinfo['updatetime']=date("Y-m-d H:i:s");
  1007. $sa=Db::name("consult_bids")->save($goodinfo);
  1008. if($sa==false){
  1009. return false;
  1010. }
  1011. if ($data['sendtype']==1&&!empty($data['addrlist'])) {
  1012. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  1013. ->find();
  1014. if ($order == false) {
  1015. return false;
  1016. }
  1017. foreach ($data['addrlist'] as $value) {
  1018. $temp = [];
  1019. $addrs = [];
  1020. if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
  1021. $addrs['provice_code'] = $value['addr_code'][0];
  1022. $addrs['city_code'] = $value['addr_code'][1];
  1023. $addrs['area_code'] = $value['addr_code'][2];
  1024. $addr = json_encode($addrs);
  1025. } else {
  1026. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  1027. }
  1028. $temp['orderCode'] = $orderCode;
  1029. $temp['contactor'] = $value['contactor'];
  1030. $temp['mobile'] = $value['mobile'];
  1031. $temp['addr'] = $value['addr'];
  1032. $temp['addr_code'] = $addr;
  1033. $temp['customer_code'] = $data['companyNo'];
  1034. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1035. $temp['post_fee'] = 0;
  1036. $temp['is_del'] = 0;
  1037. $temp['addtime'] = date("Y-m-d H:i:s");
  1038. $temp['updatetime'] = date("Y-m-d H:i:s");
  1039. $temp['arrive_time'] = $data['arrtime'];
  1040. $vmp = Db::name('order_addr')->insert($temp, true);
  1041. if ($vmp > 0) {
  1042. // $outCode = makeNo("CK");
  1043. // $out = [
  1044. // "orderCode" => $orderCode,
  1045. // "outCode" => $outCode,
  1046. // "apply_id"=>$data['rm'],
  1047. // "apply_name"=>$data['ri'],
  1048. // "addrid" => $vmp,
  1049. // "post_name" => "",
  1050. // "post_code" => "",
  1051. // "post_fee" => 0,
  1052. // "sendtime" => date("Y-m-d H:i:s"),
  1053. // "send_num" => $value['receipt_quantity'],
  1054. // "check_num" => 0,
  1055. // "error_num" => 0,
  1056. // "wsm_code" => "",
  1057. // "order_type" => 4,
  1058. // "status" => 0,
  1059. // "addtime" => date("Y-m-d H:i:s"),
  1060. // "updatetime" => date("Y-m-d H:i:s")
  1061. // ];
  1062. // $ou = Db::name("order_out")->insert($out);
  1063. // if ($ou == false) {
  1064. // return false;
  1065. // }
  1066. // $order['send_num'] += $value['receipt_quantity'];
  1067. // $order['wsend_num'] -= $value['receipt_quantity'];
  1068. // if ($order['wsend_num'] < 0) {
  1069. // return false;
  1070. // }
  1071. // $ups = Db::name("order_num")->save($order);
  1072. // if ($ups) {
  1073. // $tep = [
  1074. // "cgdNo" => $order['cgdNo'],
  1075. // "outCode" => $outCode,
  1076. // "send_num" => $value['receipt_quantity'],
  1077. // "status" => 1,
  1078. // "addtime" => date("Y-m-d H:i:s"),
  1079. // "updatetime" => date("Y-m-d H:i:s")
  1080. // ];
  1081. // $sen = Db::name("order_send")->save($tep);
  1082. // if ($sen == false) {
  1083. // return false;
  1084. // }
  1085. // }
  1086. } else {
  1087. return false;
  1088. }
  1089. }
  1090. }
  1091. }
  1092. return true;
  1093. }
  1094. /**
  1095. * @param $data
  1096. * @return bool
  1097. * @throws \think\db\exception\DataNotFoundException
  1098. * @throws \think\db\exception\DbException
  1099. * @throws \think\db\exception\ModelNotFoundException
  1100. */
  1101. public function project_good($data){
  1102. $good=Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where(["b.skuCode"=>$data['skuCode'],"a.is_del"=>0,"b.is_del"=>0])->find();
  1103. if($good==false){
  1104. return false;
  1105. }
  1106. $goodlass = Db::name("good_ladder")->where(["skuCode"=>$data['skuCode'],"is_del"=>0,"status"=>1])->where([["min_num",
  1107. "<=",$data['good_num']]])->order("min_num desc")->find();
  1108. if($goodlass==false){
  1109. return false;
  1110. }
  1111. $sale_price = $goodlass['sale_price'];
  1112. $origin = Db::name("good_nake")->where([["spuCode","=",$data['spuCode']],["min_num","<=",$data['good_num']],
  1113. ["is_del","=",0]])->order("min_num desc")->find();
  1114. if($origin==false){
  1115. return false;
  1116. }
  1117. $origin_price = $origin['nake_fee'];
  1118. $orderCode=makeNo("QR");
  1119. $datas=[
  1120. "orderCode"=>$orderCode,
  1121. "good_code"=>$data['spuCode'],
  1122. "skuCode"=>$data['skuCode'],
  1123. "customer_code"=>$data['customerNo'],
  1124. "good_name"=>isset($good['good_name'])&&$good['good_name']!==''?$good['good_name']:'',
  1125. "good_num"=>$data['good_num'],
  1126. "cat_id"=>$good['cat_id'],
  1127. "apply_id"=>$data['rm'],
  1128. "apply_name"=>$data['ri'],
  1129. "origin_price"=>$origin_price,
  1130. "sale_price"=>$sale_price,
  1131. "post_fee"=>0,
  1132. "status"=>0,
  1133. "send_num"=>0,
  1134. "wsend_num"=>$data['good_num'],
  1135. "send_status"=>1,
  1136. "good_type"=>1,
  1137. "send_type"=>$data['sendtype'],
  1138. "supplierNo"=>$data['companyNo'],
  1139. "is_del"=>0,
  1140. "zxNo"=>$data["pgNo"],
  1141. "platform_order"=>"",
  1142. "platform_id"=>0,
  1143. "remark"=>"",
  1144. "is_stock"=>$good['is_stock'],
  1145. "is_activity"=>0,
  1146. "proof_id"=>0,
  1147. "order_type"=>$good['is_stock']==1?2:4,
  1148. "addtime"=>date("Y-m-d H:i:s"),
  1149. "updatetime"=>date("Y-m-d H:i:s"),
  1150. 'total_price'=>round($sale_price*$data['good_num'],2),
  1151. ];
  1152. $datainfo = Db::name('sale')->insert($datas, true);
  1153. if($datainfo>0) {
  1154. $cgd=[
  1155. "supplierNo"=>$good['supplierNo'],
  1156. "companyNo"=>$data['companyNo'],
  1157. "orderCode"=>$orderCode,
  1158. "spuCode"=>$good['spuCode'],
  1159. "skuCode"=>$good['skuCode'],
  1160. "good_name"=>$good['good_name'],
  1161. "sale_price"=>$origin_price,
  1162. "total_fee"=>$origin_price*$data['good_num'],
  1163. "pakge_fee"=>$good['packing_fee'],
  1164. "cert_fee"=>$good['cert_fee'],
  1165. "open_fee"=>$good['open_fee'],
  1166. "cost_fee"=>$good['cost_fee'],
  1167. "mark_fee"=>$good['mark_fee'],
  1168. "demo_fee"=>$good['demo_fee'],
  1169. "good_num"=>$data['good_num'],
  1170. "good_type"=>1,
  1171. "order_type"=>2,
  1172. ];
  1173. if($good['is_stock']==0) {
  1174. $bol = $this->createCgd($cgd);
  1175. if ($bol == false) {
  1176. return false;
  1177. }
  1178. }
  1179. if ($data['sendtype']==1&&!empty($data['addrlist'])) {
  1180. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  1181. ->find();
  1182. if ($order == false) {
  1183. return false;
  1184. }
  1185. foreach ($data['addrlist'] as $value) {
  1186. $temp = [];
  1187. $addrs = [];
  1188. if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
  1189. $addrs['provice_code'] = $value['addr_code'][0];
  1190. $addrs['city_code'] = $value['addr_code'][1];
  1191. $addrs['area_code'] = $value['addr_code'][2];
  1192. $addr = json_encode($addrs);
  1193. } else {
  1194. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  1195. }
  1196. $temp['orderCode'] = $orderCode;
  1197. $temp['contactor'] = $value['contactor'];
  1198. $temp['mobile'] = $value['mobile'];
  1199. $temp['addr'] = $value['addr'];
  1200. $temp['addr_code'] = $addr;
  1201. $temp['customer_code'] =$data['companyNo'];
  1202. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1203. $temp['post_fee'] = 0;
  1204. $temp['is_del'] = 0;
  1205. $temp['addtime'] = date("Y-m-d H:i:s");
  1206. $temp['updatetime'] = date("Y-m-d H:i:s");
  1207. $temp['arrive_time'] = $data['arrtime'];
  1208. $vmp = Db::name('order_addr')->insert($temp, true);
  1209. if ($vmp > 0) {
  1210. // if($good['is_stock']!=1){
  1211. // $outCode = makeNo("CK");
  1212. // $out = [
  1213. // "orderCode" => $orderCode,
  1214. // "outCode" => $outCode,
  1215. // "apply_id"=>$data['rm'],
  1216. // "apply_name"=>$data['ri'],
  1217. // "addrid" => $vmp,
  1218. // "post_name" => "",
  1219. // "post_code" => "",
  1220. // "post_fee" => 0,
  1221. // "sendtime" => date("Y-m-d H:i:s"),
  1222. // "send_num" => $value['receipt_quantity'],
  1223. // "check_num" => 0,
  1224. // "error_num" => 0,
  1225. // "wsm_code" => "",
  1226. // "order_type" => 4,
  1227. // "status" => 0,
  1228. // "addtime" => date("Y-m-d H:i:s"),
  1229. // "updatetime" => date("Y-m-d H:i:s")
  1230. // ];
  1231. // $ou = Db::name("order_out")->insert($out);
  1232. // if ($ou == false) {
  1233. // return false;
  1234. // }
  1235. // $order['send_num'] += $value['receipt_quantity'];
  1236. // $order['wsend_num'] -= $value['receipt_quantity'];
  1237. // if ($order['wsend_num'] < 0) {
  1238. // return false;
  1239. // }
  1240. // $ups = Db::name("order_num")->save($order);
  1241. // if ($ups) {
  1242. // $tep = [
  1243. // "cgdNo" => $order['cgdNo'],
  1244. // "outCode" => $outCode,
  1245. // "send_num" => $value['receipt_quantity'],
  1246. // "status" => 1,
  1247. // "addtime" => date("Y-m-d H:i:s"),
  1248. // "updatetime" => date("Y-m-d H:i:s")
  1249. // ];
  1250. // $sen = Db::name("order_send")->insert($tep);
  1251. // if ($sen == false) {
  1252. // return false;
  1253. // }
  1254. // }
  1255. // }
  1256. } else {
  1257. return false;
  1258. }
  1259. }
  1260. }
  1261. }
  1262. return true;
  1263. }
  1264. public function list()
  1265. {
  1266. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  1267. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  1268. $where[] = ['is_del', "=", 0];
  1269. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  1270. if ($orderCode !== "") {
  1271. $where[] = ['orderCode', "like", "%$orderCode%"];
  1272. }
  1273. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name'])
  1274. : "";
  1275. if ($apply_name !== "") {
  1276. $where[] = ['apply_name', "like", "%$apply_name%"];
  1277. }
  1278. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name'])
  1279. : "";
  1280. if ($good_name !== "") {
  1281. $where[] = ['good_name', "like", "%$good_name%"];
  1282. }
  1283. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  1284. if ($good_code !== "") {
  1285. $where[] = ['good_code', "like", "%$good_code%"];
  1286. }
  1287. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  1288. if ($customer_code !== "") {
  1289. $where[] = ['customer_code', "like", "%$customer_code%"];
  1290. }
  1291. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  1292. if ($supplierNo !== "") {
  1293. $where[] = ['supplierNo', "like", "%$supplierNo%"];
  1294. }
  1295. $ordertype = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type'])
  1296. : "";
  1297. if ($ordertype !== "") {
  1298. $where[] = ['order_type', "=", $ordertype];
  1299. }
  1300. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1301. if ($status !== "") {
  1302. $where[] = ['status', "=", $status];
  1303. }
  1304. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1305. if ($start != "") {
  1306. $where[] = ["addtime", '>=', $start];
  1307. }
  1308. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1309. if ($end != "") {
  1310. $where[] = ["addtime", '<=', $end];
  1311. }
  1312. $count = Db::name('sale')->where($where)->count();
  1313. $total = ceil($count / $size);
  1314. $page = $page >= $total ? $total : $page;
  1315. $list = Db::name('sale')->where($where)->order("addtime desc")->page($page, $size)->select();
  1316. $data = [];
  1317. foreach ($list as $value) {
  1318. if($value['order_type']==3|| $value['order_type']==4){
  1319. $var = Db::name("good_zixun")->where(["spuCode"=>$value['good_code'],"is_del"=>0])->find();
  1320. }else {
  1321. $var = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  1322. ->where(['a.skuCode' => $value['skuCode']])->find();
  1323. }
  1324. $value['can'] = isset($var['cat_id']) && $var['cat_id'] != 0 ? made($var['cat_id']) : [];
  1325. $value['supplierName'] = '';
  1326. if ($value['supplierNo'] != "") {
  1327. $supplier = Db::name("business")->where(["companyNo" => $value['supplierNo']])->find();
  1328. $value['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
  1329. }
  1330. $value['customerName'] = '';
  1331. if ($value['customer_code'] != "") {
  1332. $supplier = Db::name("customer_info")->where(["companyNo" => $value['customer_code']])->find();
  1333. $value['customerName'] = isset($supplier['companyName']) ? $supplier['companyName'] : "";
  1334. }
  1335. $data[] = $value;
  1336. }
  1337. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  1338. }
  1339. public function edit()
  1340. {
  1341. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1342. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  1343. if ($id == "") {
  1344. return error_show(1002, "参数id不能为空");
  1345. }
  1346. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  1347. if (empty($etid)) {
  1348. return error_show(1002, "未找到数据");
  1349. }
  1350. // $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  1351. // if($orderCode==""){
  1352. // return error_show(1002,"销售单code不能为空");
  1353. // }
  1354. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  1355. if ($good_code == "") {
  1356. return error_show(1002, "商品code不能为空");
  1357. }
  1358. $ct = Db::name('good')->alias('a')->join('good_type b', 'b.good_code=a.good_code', 'left')
  1359. ->where(['b.type_code' => $good_code])->find();
  1360. if ($ct == "") {
  1361. return error_show(1002, "未找到商品数据");
  1362. }
  1363. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  1364. if ($customer_code == "") {
  1365. return error_show(1002, "客户code不能为空");
  1366. }
  1367. $customer = Db::name("customer_info")->where(["companyNo" => $customer_code])->find();
  1368. if ($customer == false) {
  1369. return error_show(1004, "未找到客户数据");
  1370. }
  1371. $supplierNo = $this->post['supplierNo'] && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  1372. if ($supplierNo == "") {
  1373. return error_show(1002, "参数supplierNo不能为空");
  1374. }
  1375. $supplier = Db::name("supplier")->where(["code" => $supplierNo])->find();
  1376. if ($supplier == false) {
  1377. return error_show(1004, "未找到平台供应商数据");
  1378. }
  1379. $apply_id = GetUserInfo($token);
  1380. if (empty($apply_id) || $apply_id['code'] != 0) {
  1381. return error_show(1002, "申请人数据不存在");
  1382. }
  1383. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1384. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1385. // $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim
  1386. //($this->post['good_name']) : "";
  1387. // $good_num = isset($this->post['good_num']) && $this->post['good_num'] !== "" ? intval
  1388. //($this->post['good_num']) : "";
  1389. // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !== "" ? intval
  1390. // ($this->post['origin_price']) : "";
  1391. // $sale_price = isset($this->post['sale_price']) && $this->post['sale_price'] !== "" ? trim($this->post['sale_price']) : "";
  1392. // $total_price = isset($this->post['total_price']) && $this->post['total_price'] !== "" ? trim($this->post['total_price']) : "";
  1393. // $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? trim($this->post['post_fee']) : "";
  1394. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1395. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  1396. if ($vr == "") {
  1397. return error_show(1002, "参数order_addr不能为空");
  1398. }
  1399. $vi = isset($this->post['good_stock']) && $this->post['good_stock'] !== "" ? $this->post['good_stock'] : "";
  1400. if ($vi == "") {
  1401. return error_show(1002, "参数good_stock不能为空");
  1402. }
  1403. $good_num = intval(array_sum(array_column($vi, "num")));
  1404. Db::startTrans();
  1405. try {
  1406. $datn = [
  1407. "id" => $id,
  1408. "good_code" => $good_code,
  1409. "customer_code" => $customer_code,
  1410. "good_num" => $good_num,
  1411. "supplierNo" => $supplierNo,
  1412. "apply_id" => $rm,
  1413. "apply_name" => $ri,
  1414. "is_del" => 0,
  1415. "updatetime" => date("Y-m-d H:i:s")
  1416. ];
  1417. $datninfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($datn);
  1418. if ($datninfo > 0) {
  1419. $stn = ["order_code"=>$etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',"action_type"=>"edit"];
  1420. ActionLog::logAdd($this->post['token'],$stn,"XSQRD",$etid['status'],$datn);
  1421. $order=["order_type"=>'XSQRD',"order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$etid['status']];
  1422. ProcessOrder::AddProcess($this->post['token'],$order);
  1423. foreach ($vi as $ion) {
  1424. $iten = [];
  1425. isset($ion['id']) && $ion['id'] !== "" ? $iten['id'] = $ion['id'] : '';
  1426. $iten['orderCode'] = $etid['orderCode'];
  1427. $iten['wsm_code'] = $ion['wsm_code'];
  1428. $iten['stock_id'] = 0;
  1429. $iten['num'] = $ion['num'];
  1430. $iten['status'] = 1;
  1431. $iten['sale_price'] = $ct['original_price'];
  1432. isset($ion['id']) && $ion['id'] !== "" ? '' : $iten['addtime'] = date("Y-m-d H:i:s");
  1433. $iten['updatetime'] = date("Y-m-d H:i:s");
  1434. $vp = Db::name('sale_info')->save($iten);
  1435. if ($vp == false)
  1436. {
  1437. Db::rollback();
  1438. return error_show(1002, "更新失败");
  1439. }
  1440. }
  1441. foreach ($vr as $value) {
  1442. $temp = [];
  1443. isset($value['id']) && $value['id'] !== "" ? $temp['id'] = $value['id'] : '';
  1444. $temp['orderCode'] = $etid['orderCode'];
  1445. $temp['contactor'] = $value['contactor'];
  1446. $temp['mobile'] = $value['mobile'];
  1447. $temp['addr'] = $value['addr'];
  1448. $temp['addr_code'] = $value['addr_code'];
  1449. $temp['customer_code'] = $customer_code;
  1450. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1451. $temp['post_fee'] = 0;
  1452. $temp['is_del'] = $value['is_del'];
  1453. isset($value['id']) && $value['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  1454. $temp['updatetime'] = date("Y-m-d H:i:s");
  1455. $temp['arrive_time'] = date("Y-m-d H:i:s");
  1456. $dat = Db::name('order_addr')->save($temp);
  1457. if ($dat == false) {
  1458. Db::rollback();
  1459. return error_show(1002, "更新失败");
  1460. }
  1461. }
  1462. Db::commit();
  1463. return error_show(0, "更新成功");
  1464. }
  1465. Db::rollback();
  1466. return error_show(1002, "更新失败");
  1467. } catch (Exception $e) {
  1468. Db::rollback();
  1469. return error_show(1005, $e->getMessage());
  1470. }
  1471. }
  1472. public function info()
  1473. {
  1474. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1475. if ($id == "") {
  1476. return error_show(1002, "参数id不能为空");
  1477. }
  1478. //->field('good_code,good_name,good_num,customer_code,orderCode')
  1479. $einfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1480. if (empty($einfo)) {
  1481. return error_show(1002, "未找到销售订单数据");
  1482. }
  1483. $info = Db::name('sale_diff')->where(['orderCode' => $einfo['orderCode']])->select();
  1484. //$de = Db::name('order_out')->where(['orderCode' => $einfo['orderCode']])->select();
  1485. $dm = Db::name('order_return')->where(['orderCode' => $einfo['orderCode']])->select();
  1486. $dk = Db::name('order_back')->where(['orderCode' => $einfo['orderCode']])->select();
  1487. $sa = Db::name('sale_return')->where(['orderCode' => $einfo['orderCode']])->select();
  1488. if($einfo['order_type']==3|| $einfo['order_type']==4){
  1489. $goon = Db::name("good_zixun")->where(["spuCode"=>$einfo['good_code'],"is_del"=>0])->find();
  1490. }else {
  1491. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  1492. ->where(['a.skuCode' => $einfo['skuCode']])->find();
  1493. }
  1494. if ($goon==false) {
  1495. return error_show(1003, "未找到商品数据");
  1496. }
  1497. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  1498. $in = Db::name('customer_info')->where(['companyNo' => $einfo['customer_code']])->field('companyName')->find();
  1499. // ->field('addr,contactor,mobile,receipt_quantity,arrive_time')
  1500. $einfo['supplierName'] = '';
  1501. if ($einfo['supplierNo'] != "") {
  1502. $supplier = Db::name("business")->where(["companyNo" => $einfo['supplierNo']])->find();
  1503. $einfo['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
  1504. }
  1505. $fo = Db::name('order_addr')->where(['orderCode' => $einfo['orderCode'], 'is_del' => 0])->select();
  1506. $bum = Db::name('order_out')->where(['orderCode' => $einfo['orderCode']])->select();
  1507. $ins = [];
  1508. if (!empty($bum)) {
  1509. foreach ($bum as $stn) {
  1510. $so = Db::name('order_addr')->where(['id' => $stn['addrid']])->find();
  1511. $addr = GetAddr($so['addr_code']);
  1512. $stn['addr_info'] = $addr;
  1513. $stn['add_code'] = json_decode($so['addr_code'], true);
  1514. $stn['addr'] = $so['addr'];
  1515. $stn['contact'] = $so['contactor'];
  1516. $stn['mobile'] = $so['mobile'];
  1517. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
  1518. ->where(["a.wsm_code" => $stn['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  1519. $stn['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  1520. $stn['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  1521. $stn['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  1522. $ins[] = $stn;
  1523. }
  1524. }
  1525. $addrs = [];
  1526. if (!empty($fo)) {
  1527. foreach ($fo as $value) {
  1528. $value['addr_info'] = "";
  1529. $value['send_num'] = 0;
  1530. if ($value['addr_code'] != "") {
  1531. $addr = GetAddr($value['addr_code']);
  1532. $value['addr_info'] = $addr;
  1533. $value['addr_code'] = json_decode($value['addr_code'], true);
  1534. $send = Db::name("order_out")->where(['addrid' => $value['id'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
  1535. $value['send_num'] = $send ?? 0;
  1536. }
  1537. $value['wsend_num'] = $value['receipt_quantity'] - $value['send_num'];
  1538. $addrs[] = $value;
  1539. }
  1540. }
  1541. // //->field('num,sale_price,wsm_code,stock_id')
  1542. // $st = Db::name('sale_info')->where(['orderCode' => $einfo['orderCode']])->select();
  1543. // $data = [];
  1544. // if (!empty($fo)) {
  1545. // foreach ($st as $value) {
  1546. // $value['wsm_name'] = "";
  1547. // $value['wsm_supplier'] = "";
  1548. // $value['wsm_supplierNo'] = "";
  1549. // $value['usable_stock'] = 0;
  1550. // $value['send_num'] = 0;
  1551. // if ($value['wsm_code'] != "") {
  1552. // $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
  1553. // ->where(["a.wsm_code" => $value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  1554. // $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  1555. // $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  1556. // $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  1557. // $dn = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $einfo['good_code']])->find();
  1558. // $value['usable_stock'] = isset($dn['usable_stock']) ? $dn['usable_stock'] : "0";
  1559. // $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
  1560. // $value['send_num'] = $send ?? 0;
  1561. // }
  1562. // $value['wsend_num'] = $value['num'] - $value['send_num'];
  1563. // $data[] = $value;
  1564. // }
  1565. // }
  1566. // $einfo['info'] = $data;
  1567. $einfo['companyName'] = isset($in['companyName']) ? $in['companyName'] : "";
  1568. $einfo['addrs'] = $addrs;
  1569. $einfo['orderout'] = $ins;
  1570. $einfo['can'] = $int;
  1571. $einfo['salediff'] = $info;
  1572. $einfo['orderreturn'] = $dm;
  1573. $einfo['orderback'] = $dk;
  1574. $einfo['salereturn'] = $sa;
  1575. if (empty($einfo)) {
  1576. return error_show(1002, "未找到销售订单数据");
  1577. } else {
  1578. return app_show(0, "获取成功", $einfo);
  1579. }
  1580. }
  1581. public function del()
  1582. {
  1583. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1584. if ($id === "") {
  1585. return error_show(1002, "参数id不能为空");
  1586. }
  1587. $ed = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1588. if (empty($ed)) {
  1589. return error_show(1002, "未找到销售订单数据");
  1590. }
  1591. $str = Db::name('sale')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1592. if ($str) {
  1593. $stc = ["order_code"=>$id,"status"=>$ed['status'],"action_remark"=>'',"action_type"=>"delete"];
  1594. ActionLog::logAdd($this->post['token'],$stc,"XSQRD",$ed['status'],['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1595. $order=["order_type"=>'XSQRD',"order_code"=>$ed['orderCode'],"order_id"=>$id,"order_status"=>$ed['status']];
  1596. ProcessOrder::workdel($order);
  1597. return error_show(0, "删除成功");
  1598. } else {
  1599. return error_show(1002, "删除失败");
  1600. }
  1601. }
  1602. public function status()
  1603. {
  1604. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1605. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1606. if ($id == "") {
  1607. return error_show(1002, "参数id不能为空");
  1608. }
  1609. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1610. if ($status == "") {
  1611. return error_show(1002, "订单状态不能为空");
  1612. }
  1613. $dio = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1614. if (empty($dio)) {
  1615. return error_show(1002, "销售单信息未找到");
  1616. }
  1617. if ($status == 1 && $dio['order_type'] == 2) {
  1618. $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
  1619. if ($zxinfo == false) {
  1620. return error_show(1004, "未找到咨询单数据");
  1621. }
  1622. $gold['price'] = 0;
  1623. if ($zxinfo['zx_type'] == 2) {
  1624. if ($zxinfo['metals'] == "") {
  1625. return error_show(1004, "未找到咨询单贵金属类型数据");
  1626. }
  1627. $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
  1628. $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
  1629. if (empty($gold)) {
  1630. return error_show(1004, "未找到咨询单贵金属类型数据");
  1631. }
  1632. $dio['gold_price'] = $gold['price'];
  1633. }
  1634. $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
  1635. if (empty($wsm)) {
  1636. return error_show(1002, "供应商仓库未找到");
  1637. }
  1638. }
  1639. $apply_id = GetUserInfo($token);
  1640. if (empty($apply_id) || $apply_id['code'] != 0) {
  1641. return error_show(1002, "申请人数据不存在");
  1642. }
  1643. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1644. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1645. Db::startTrans();
  1646. try {
  1647. $vmp =$dio['status'];
  1648. $dio['status'] = $status;
  1649. $dio['updatetime'] = date("Y-m-d H:i:s");
  1650. $st = Db::name('sale')->save($dio);
  1651. if ($st) {
  1652. $stn = ["order_code"=>$dio['orderCode'],"status"=>$vmp,"action_remark"=>'',"action_type"=>"status"];
  1653. ActionLog::logAdd($this->post['token'],$stn, $dio['order_type'] == 2?"ZXQRD":"XSQRD",$dio['status'],$dio);
  1654. $order=["order_type"=>$dio['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dio['orderCode'],"order_id"=>$id,"order_status"=>$dio['status']];
  1655. ProcessOrder::AddProcess($this->post['token'],$order);
  1656. if ($status == 3 && $dio['order_type'] == 1) {
  1657. $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
  1658. foreach ($dn as $value) {
  1659. $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
  1660. if ($dm == "") {
  1661. Db::rollback();
  1662. return error_show(1003, "未找到商品数据");
  1663. }
  1664. if ($value['num'] > $dm['usable_stock']) {
  1665. Db::rollback();
  1666. return error_show(1002, "超出库存数量");
  1667. }
  1668. $dm['usable_stock'] -= $value['num'];
  1669. $dm['wait_out_stock'] += $value['num'];
  1670. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code']])->sum("send_num");
  1671. $value['send_num'] = $send ?? 0;
  1672. $value['wsend_num'] = $value['num'] - $value['send_num'];
  1673. $Db = Db::name('good_stock')->update($dm);
  1674. $Db['updatetime'] = date('Y-m-d H:i:s');
  1675. if ($Db == false) {
  1676. Db::rollback();
  1677. return error_show(1002, "状态更新失败");
  1678. }
  1679. }
  1680. }
  1681. if ($status == 1 && $dio['order_type'] == 2) {
  1682. $cgd = makeNo("CG");
  1683. $clll = [
  1684. "cgdNo" => $cgd,
  1685. "bkcode" => $dio['orderCode'],
  1686. "wsm_code" => $wsm['wsm_code'],
  1687. "cgder_id" => "0",
  1688. "cgder" => $zxinfo['saler'],
  1689. "good_code" => "GD-" . $zxinfo['cpNo'],
  1690. "good_name" => $zxinfo['cpName'],
  1691. "good_type_code" => $zxinfo['cpNo'],
  1692. "good_num" => $dio['good_num'],
  1693. "good_price" => $zxinfo['total_fee'],
  1694. "total_fee" => round($zxinfo['total_fee'] * $dio['good_num'], 2),
  1695. "pakge_fee" => $zxinfo['package_fee'],
  1696. "cert_fee" => $zxinfo['cert_fee'],
  1697. "open_fee" => $zxinfo['open_fee'],
  1698. "delivery_fee" => $zxinfo['delivery_fee'],
  1699. "mark_fee" => $zxinfo['mark_fee'],
  1700. "teach_fee" => $zxinfo['cost_fee'],
  1701. "demo_fee" => $zxinfo['demo_fee'],
  1702. "nake_fee" => $zxinfo['bare_fee'],
  1703. "weight" => isset($zxinfo['weight']) ? $zxinfo['weight'] : 0,
  1704. "supplierNo" => $zxinfo['gysNo'],
  1705. "supplier_name" => $zxinfo['gysname'],
  1706. "gold_price" => $gold['price'],
  1707. "send_num" => 0,
  1708. "wsend_num" => $dio['good_num'],
  1709. "remark" => '',
  1710. "lasttime" => date("Y-m-d H:i:s"),
  1711. "is_del" => 0,
  1712. "status" => $dio['send_type'] == 1 ? 3 : 0,
  1713. "order_type" => 2,
  1714. "addtime" => date("Y-m-d H:i:s"),
  1715. "updatetime" => date("Y-m-d H:i:s")
  1716. ];
  1717. $cgin = Db::name("purchease_order")->insert($clll);
  1718. // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
  1719. if ($cgin == false) {
  1720. $stb = ["order_code"=>$cgd,"status"=> $clll['status'],"action_remark"=>'',"action_type"=>"create"];
  1721. ActionLog::logAdd($this->post['token'],$stb,"xsd", $clll['status'],$stb);
  1722. Db::rollback();
  1723. return error_show(1002, "咨询采购单创建商品失败");
  1724. }
  1725. if ($dio['send_type'] == 1) {
  1726. $addr = Db::name('order_addr')->where(["orderCode" => $dio['orderCode'], 'is_del' => 0])->select();
  1727. foreach ($addr as $value) {
  1728. $outCode = makeNo("CK");
  1729. $data = [
  1730. "wsm_code" => $wsm['wsm_code'],
  1731. "orderCode" => $dio['orderCode'],
  1732. "outCode" => $outCode,
  1733. "order_type" => $dio['order_type'],
  1734. "apply_id" => $rm,
  1735. "apply_name" => $ri,
  1736. "addrid" => $value['id'],
  1737. "post_name" => '',
  1738. "post_code" => '',
  1739. "post_fee" => '',
  1740. "sendtime" => date("Y-m-d H:i:s"),
  1741. "send_num" => $value['receipt_quantity'],
  1742. "check_num" => 0,
  1743. "error_num" => 0,
  1744. "status" => 0,
  1745. "addtime" => date("Y-m-d H:i:s"),
  1746. "updatetime" => date("Y-m-d H:i:s")
  1747. ];
  1748. $datainfo = Db::name('order_out')->insert($data);
  1749. if (!$datainfo) {
  1750. $sti = ["order_code"=>$dio['orderCode'],"status"=> 0,"action_remark"=>'',"action_type"=>"create"];
  1751. ActionLog::logAdd($this->post['token'],$sti,"xsd",0,$sti);
  1752. Db::rollback();
  1753. return error_show(1003, "创建失败");
  1754. }
  1755. }
  1756. $wsm_in_code = makeNo("IC");
  1757. $orin = [
  1758. "wsm_in_code" => $wsm_in_code,
  1759. "cgdNo" => $cgd,
  1760. "wsm_code" => $wsm['wsm_code'],
  1761. "wsm_reaper" => "",
  1762. "send_num" => $dio['good_num'],
  1763. "post_company" => '',
  1764. "post_code" => '',
  1765. "post_fee" => '',
  1766. "sendtime" => date("Y-m-d H:i:s"),
  1767. "apply_id" => $rm,
  1768. "apply_name" => $ri,
  1769. "wait_num" => 0,
  1770. "status" => 4,
  1771. "addtime" => date("Y-m-d H:i:s"),
  1772. "updatetime" => date("Y-m-d H:i:s")
  1773. ];
  1774. $win = Db::name("purchease_in")->insert($orin);
  1775. if (!$win){
  1776. $stv = ["order_code"=>$wsm_in_code,"status"=>4,"action_remark"=>'',"action_type"=>"create"];
  1777. ActionLog::logAdd($this->post['token'],$stv,"xsd",4,$stv);
  1778. Db::rollback();
  1779. return error_show(1003, "创建失败");
  1780. }
  1781. $good = Db::name("good_stock")->where(["wsm_code" => $wsm['wsm_code'], "good_type_code" => $zxinfo['cpNo'], "is_del" => 0])->find();
  1782. if (empty($good)) {
  1783. $good = [
  1784. "good_type_code" => $zxinfo['cpNo'],
  1785. "wsm_code" => $wsm['wsm_code'],
  1786. "usable_stock" => 0,
  1787. "wait_out_stock" => 0,
  1788. "total_stock" => 0,
  1789. "addtime" => date("Y-m-d H:i:s"),
  1790. "updatetime" => date("Y-m-d H:i:s"),
  1791. ];
  1792. }
  1793. $good['wait_out_stock'] += $dio['good_num'];
  1794. $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
  1795. $good['updatetime'] = date("Y-m-d H:i:s");
  1796. $upd = Db::name("good_stock")->save($good);
  1797. if (!$upd) {
  1798. $ste = ["order_code"=> $zxinfo['cpNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  1799. ActionLog::logAdd($this->post['token'],$ste,"xsd",0,$ste);
  1800. Db::rollback();
  1801. return error_show(1003, "创建失败");
  1802. }
  1803. }
  1804. }
  1805. }
  1806. Db::commit();
  1807. return error_show(0, "订单状态更新成功");
  1808. } catch (Exception $e) {
  1809. Db::rollback();
  1810. return error_show(1005, $e->getMessage());
  1811. }
  1812. }
  1813. public function fee()
  1814. {
  1815. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  1816. if ($id == "") {
  1817. return error_show(1002, "参数id不能为空");
  1818. }
  1819. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  1820. if (empty($etid)) {
  1821. return error_show(1002, "未找到数据");
  1822. }
  1823. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  1824. if ($vr == "") {
  1825. return error_show(1002, "参数order_addr不能为空");
  1826. }
  1827. Db::startTrans();
  1828. try {
  1829. $data = [
  1830. "id" => $id,
  1831. "status" => 2,
  1832. "is_del" => 0,
  1833. "updatetime" => date("Y-m-d H:i:s")
  1834. ];
  1835. $datainfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($data);
  1836. if ($datainfo) {
  1837. $stx = ["order_code"=> $etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',
  1838. "action_type"=>"edit"];
  1839. ActionLog::logAdd($this->post['token'],$stx,$etid['order_type'] == 2?"ZXQRD":"XSQRD",2,$data);
  1840. $order=["order_type"=>$etid['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$data['status']];
  1841. ProcessOrder::AddProcess($this->post['token'],$order);
  1842. foreach ($vr as $value) {
  1843. $tm = [];
  1844. $tm['id'] = $value['id'];
  1845. $tm['orderCode'] = $etid['orderCode'];
  1846. $tm['post_fee'] = $value['post_fee'];
  1847. $tm['updatetime'] = date("Y-m-d H:i:s");
  1848. $dn = Db::name('order_addr')->save($tm);
  1849. if ($dn == false) {
  1850. Db::rollback();
  1851. return error_show(1002, "更新失败");
  1852. }
  1853. }
  1854. Db::commit();
  1855. return error_show(0, "更新成功");
  1856. }
  1857. Db::rollback();
  1858. return error_show(1003, "更新失败");
  1859. } catch (Exception $e) {
  1860. Db::rollback();
  1861. return error_show(1005, $e->getMessage());
  1862. }
  1863. }
  1864. public function out()
  1865. {
  1866. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1867. $outCode = makeNo("CK");
  1868. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  1869. if ($orderCode == "") {
  1870. return error_show(1002, "参数orderCoder不能为空");
  1871. }
  1872. $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
  1873. if ($der == "") {
  1874. return error_show(1002, "未找到出库订单单号");
  1875. }
  1876. // $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  1877. // if ($wsm_code == "") {
  1878. // return error_show(1002, "参数wsm_code不能为空");
  1879. // }
  1880. // $wsm = Db::name('sale_info')->where(['wsm_code' => $wsm_code, 'orderCode' => $der['orderCode']])->find();
  1881. // if ($wsm == "") {
  1882. // return error_show(1002, "未找到仓库编码");
  1883. // }
  1884. $post_name = isset($this->post['post_name']) && $this->post['post_name'] !== "" ? trim($this->post['post_name']) : "";
  1885. if ($post_name == "") {
  1886. return error_show(1002, "物流公司不能为空");
  1887. }
  1888. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
  1889. if ($post_code == "") {
  1890. return error_show(1002, "物流单号不能为空");
  1891. }
  1892. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
  1893. if ($post_fee == "") {
  1894. return error_show(1002, "物流费不能为空");
  1895. }
  1896. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  1897. if ($send_num == "") {
  1898. return error_show(1002, "发货数量不能为空");
  1899. }
  1900. if ($send_num > $der['wsend_num']) {
  1901. return error_show(1002, "超出可发货数量");
  1902. }
  1903. $apply_id = GetUserInfo($token);
  1904. if (empty($apply_id) || $apply_id['code'] != 0) {
  1905. return error_show(1002, "申请人数据不存在");
  1906. }
  1907. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1908. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1909. $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
  1910. $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
  1911. if (empty($dr)) {
  1912. return error_show(1003, "收货人信息未找到");
  1913. }
  1914. if ($dr['orderCode'] !== $orderCode) {
  1915. return error_show(1002, "订单code不存在");
  1916. }
  1917. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  1918. // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
  1919. // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
  1920. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "1";
  1921. //$order_type = isset($this->post['order_type']) && $this->post['order_type'] !=="" ? $this->post['order_type'] :"1";
  1922. //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
  1923. Db::startTrans();
  1924. try {
  1925. $data = [
  1926. "wsm_code" => "",
  1927. "orderCode" => $orderCode,
  1928. "outCode" => $outCode,
  1929. "order_type" => $der['order_type'],
  1930. "apply_id" => $rm,
  1931. "apply_name" => $ri,
  1932. "addrid" => $dr['id'],
  1933. "post_name" => $post_name,
  1934. "post_code" => $post_code,
  1935. "post_fee" => $post_fee,
  1936. "sendtime" => $sendtime,
  1937. "send_num" => $send_num,
  1938. "check_num" => 0,
  1939. "error_num" => 0,
  1940. "status" => $status,
  1941. "addtime" => date("Y-m-d H:i:s"),
  1942. "updatetime" => date("Y-m-d H:i:s")
  1943. ];
  1944. $datainfo = Db::name('order_out')->insert($data,true);
  1945. if ($datainfo>0) {
  1946. $stx = ["order_code"=>$outCode,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
  1947. ActionLog::logAdd($this->post['token'],$stx,$der['order_type']==1?"CKD":'ZXCKD',$status,$data);
  1948. $order=["order_type"=>$der['order_type']==1?"CKD":'ZXCKD',"order_code"=>$outCode,"order_id"=>$datainfo,"order_status"=>$data['status']];
  1949. ProcessOrder::AddProcess($this->post['token'],$order);
  1950. if ($status == 1) {
  1951. $var = Db::name('sale_info')->where(['orderCode' => $orderCode, 'wsm_code' => $wsm_code])->find();
  1952. if ($var == "") {
  1953. return error_show(1002, "未找到数据");
  1954. }
  1955. // $send = Db::name("order_out")->where(["wsm_code" => $wsm_code, 'orderCode' => $orderCode])->sum
  1956. //("send_num");
  1957. $item =$der['status'];
  1958. $der['send_num'] += $send_num;
  1959. $der['wsend_num'] -= $send_num;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  1960. $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
  1961. $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
  1962. $der['updatetime'] = date("Y-m-d H:i:s");
  1963. $si = Db::name('sale')->save($der);
  1964. if ($si == false) {
  1965. Db::rollback();
  1966. return error_show(1003, "更新失败");
  1967. }
  1968. $stx = ["order_code"=>$orderCode,"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  1969. ActionLog::logAdd($this->post['token'],$stx,$der['order_type'] == 2?"ZXQRD":"XSQRD",$der['status'],$der);
  1970. $order=["order_type"=>$der['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$orderCode,"order_id"=>$der['id'],"order_status"=>$data['status']];
  1971. ProcessOrder::AddProcess($this->post['token'],$order);
  1972. $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'], 'good_type_code' => $der['good_code']])->find();
  1973. if ($str == false) {
  1974. Db::rollback();
  1975. return error_show(1002, "商品数据未找到");
  1976. }
  1977. if ($send_num > $str['wait_out_stock']) {
  1978. Db::rollback();
  1979. return error_show(1002, "超出库存数量");
  1980. }
  1981. $str['wait_out_stock'] -= $send_num;
  1982. $str['intra_stock'] += $send_num;
  1983. $str['updatetime'] = date("Y-m-d H:i:s");
  1984. $stre = Db::name('good_stock')->save($str);
  1985. if ($stre == false) {
  1986. Db::rollback();
  1987. return error_show(1002, "状态更新失败");
  1988. }
  1989. $good_data[]= ["stock_id"=>$str['id'],"type"=>2,'stock'=>$send_num,"stock_name"=>"wait_out_stock"];
  1990. $good_data[]= ["stock_id"=>$str['id'],"type"=>1,'stock'=>$send_num,"stock_name"=>"intra_stock"];
  1991. GoodLog::LogAdd($this->post['token'],$good_data,$der['order_type'] == 2?"ZXQRD":"XSQRD");
  1992. }
  1993. Db::commit();
  1994. return error_show(0, "创建成功");
  1995. } else {
  1996. Db::rollback();
  1997. return error_show(1003, "创建失败");
  1998. }
  1999. } catch (Exception $e) {
  2000. Db::rollback();
  2001. return error_show(1005, $e->getMessage());
  2002. }
  2003. }
  2004. public function customer()
  2005. {
  2006. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  2007. if (empty($outCode)) {
  2008. return error_show(1002, "销售订单编号不能为空");
  2009. }
  2010. $codeinfo = Db::name('order_out')->where(['outCode' => $outCode])->find();
  2011. if ($codeinfo == "") {
  2012. return error_show(1003, "未找到订单数据");
  2013. }
  2014. // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  2015. // if($orderCode==""){
  2016. // return error_show(1002,"参数orderCoder不能为空");
  2017. // }
  2018. $dr = Db::name('sale')->where(['orderCode' => $codeinfo['orderCode']])->find();
  2019. if ($dr == "") {
  2020. return error_show(1002, "未找到销售订单");
  2021. }
  2022. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "";
  2023. if ($status == "") {
  2024. return error_show(10002, "状态不能为空");
  2025. }
  2026. Db::startTrans();
  2027. try {
  2028. $time = $codeinfo['status'];
  2029. $codeinfo['status'] = $status;
  2030. $codeinfo['updatetime'] = date("Y-m-d H:i:s");
  2031. $cust = Db::name('order_out')->save($codeinfo);
  2032. if ($cust) {
  2033. $stx = ["order_code"=>$outCode,"status"=>$time,"action_remark"=>'',"action_type"=>"status"];
  2034. ActionLog::logAdd($this->post['token'],$stx,$codeinfo['order_type'] == 2?"ZXCKD":"CKD",$codeinfo['status'],$codeinfo);
  2035. $order=["order_type"=>$codeinfo['order_type'] == 2?"ZXCKD":"CKD","order_code"=>$outCode,
  2036. "order_id"=>$codeinfo['id'],"order_status"=>$codeinfo['status']];
  2037. ProcessOrder::AddProcess($this->post['token'],$order);
  2038. if ($status == 1) {
  2039. $stokc =Db::name("good_stock")->where(['spuCode'=>$codeinfo['spuCode'],"wsm_code"=>$codeinfo['wsm_code'],
  2040. "is_del"=>0])->find();
  2041. if($stokc==false){
  2042. Db::rollback();
  2043. return error_show(1002, "未找库存到数据");
  2044. }else{
  2045. if ($codeinfo['send_num'] > $stokc['usable_stock']) {
  2046. Db::rollback();
  2047. return error_show(1002, "超出库存数量");
  2048. }
  2049. $stokc['wait_out_stock']+=$codeinfo['send_num'];
  2050. $stokc['usable_stock']-=$codeinfo['send_num'];
  2051. $stokc['updatetime']=date("Y-m-d H:i:s");
  2052. }
  2053. $stoc= Db::name("good_stock")->save($stokc);
  2054. if($stoc==false){
  2055. Db::rollback();
  2056. return error_show(1002, "库存更新失败");
  2057. }
  2058. // $send = Db::name("order_out")->where(["wsm_code" => $wsm_code, 'orderCode' => $orderCode])->sum
  2059. //("send_num");
  2060. $item =$dr['status'];
  2061. $dr['send_num'] +=$codeinfo['send_num'];
  2062. $dr['wsend_num'] -= $codeinfo['send_num'];//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  2063. $dr['send_status'] = $dr['send_num'] == 0 ? 1 : $dr['wsend_num'] == 0 ? 3 : 2;
  2064. $dr['status'] = $dr['send_num'] == 0 ? 3 : $dr['wsend_num'] == 0 ? 5 : 4;
  2065. $dr['updatetime'] = date("Y-m-d H:i:s");
  2066. $si = Db::name('sale')->save($dr);
  2067. if ($si == false) {
  2068. Db::rollback();
  2069. return error_show(1003, "更新失败");
  2070. }
  2071. $stx = ["order_code"=>$dr['orderCode'],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2072. ActionLog::logAdd($this->post['token'],$stx,$dr['order_type'] == 2?"ZXQRD":"XSQRD",$dr['status'],
  2073. $dr);
  2074. $order=["order_type"=>$dr['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dr['orderCode'],"order_id"=>$dr['id'],"order_status"=>$dr['status']];
  2075. ProcessOrder::AddProcess($this->post['token'],$order);
  2076. $good_data[]= ["stock_id"=>$stoc['id'],"type"=>1,'stock'=>$codeinfo['send_num'],"stock_name"=>"wait_out_stock"];
  2077. $good_data[]= ["stock_id"=>$stoc['id'],"type"=>2,'stock'=>$codeinfo['send_num'],"stock_name"=>"usable_stock"];
  2078. GoodLog::LogAdd($this->post['token'],$good_data,'CKD');
  2079. }
  2080. if ($status == 3) {
  2081. $var = Db::name('good_stock')->where(['wsm_code' => $codeinfo['wsm_code'], 'good_type_code' => $dr['good_code']])->find();
  2082. if ($var == false) {
  2083. Db::rollback();
  2084. return error_show(1002, "未找到商品数据");
  2085. }
  2086. if ($codeinfo['send_num'] > $var['intra_stock']) {
  2087. Db::rollback();
  2088. return error_show(1003, "超出在途库存数量");
  2089. }
  2090. $var['intra_stock'] -= $codeinfo['send_num'];
  2091. $var['updatetime'] = date("Y-m-d H:i:s");
  2092. $stre = Db::name('good_stock')->save($var);
  2093. $good_data[]= ["stock_id"=>$var['id'],"type"=>2,'stock'=>$codeinfo['send_num'],"stock_name"=>"intra_stock"];
  2094. GoodLog::LogAdd($this->post['token'],$good_data,$codeinfo['order_type'] == 2?"ZXCKD":"CKD");
  2095. if ($stre == false) {
  2096. Db::rollback();
  2097. return error_show(1002, "状态更新失败");
  2098. }
  2099. }
  2100. Db::commit();
  2101. return error_show(0, "出库订单更新成功");
  2102. } else {
  2103. Db::rollback();
  2104. return error_show(1003, "出库订单更新失败");
  2105. }
  2106. } catch (Exception $e) {
  2107. Db::rollback();
  2108. return error_show(1005, $e->getMessage());
  2109. }
  2110. }
  2111. public function difflist()
  2112. {
  2113. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2114. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2115. $where = [];
  2116. $cgdNo = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
  2117. if ($cgdNo != "") {
  2118. $where[] = ['a.orderCode', "like", "%$cgdNo%"];
  2119. }
  2120. $diffNo = isset($this->post['diffCode']) && $this->post['diffCode'] != "" ? trim($this->post['diffCode']) : "";
  2121. if ($diffNo != "") {
  2122. $where[] = ['a.diffCode', "like", "%$diffNo%"];
  2123. }
  2124. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  2125. if ($status !== "") {
  2126. $where[] = ['a.status', "=", $status];
  2127. }
  2128. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  2129. if ($start != "") {
  2130. $where[] = ["a.addtime", '>=', $start];
  2131. }
  2132. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  2133. if ($end != "") {
  2134. $where[] = ["a.addtime", '<=', $end];
  2135. }
  2136. // $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  2137. // if($apply_name!==""){
  2138. // $where[]=['a.apply_name',"like","%$apply_name%"];
  2139. // }
  2140. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  2141. if ($supplierNo != "") {
  2142. $supplier = Db::name("supplier")->where([['code', "like", "%$supplierNo%"]])->column('code');
  2143. // if(empty($supplier)){
  2144. // return error_show(1004,"未找到供应商信息");
  2145. // }
  2146. $wsmcode = Db::name("sale")->where([
  2147. "is_del" => 0, "supplierNo" => $supplier])->column("orderCode");
  2148. $where[] = ['a.orderCode', "in", $wsmcode];
  2149. }
  2150. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  2151. if($companyNo!=""){
  2152. $where[]=['c.customer_code',"like","%$companyNo%"];
  2153. }
  2154. $count = Db::name('sale_diff')->alias('a')
  2155. ->join("sale c", "c.orderCode=a.orderCode", "left")
  2156. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  2157. ->join("good b", "b.good_code=a.good_code", "left")
  2158. ->where($where)->count();
  2159. $total = ceil($count / $size);
  2160. $page = $page >= $total ? $total : $page;
  2161. //var_dump( Db::name('sale_diff')->getLastSql());
  2162. $list = Db::name('sale_diff')->alias('a')
  2163. ->join("sale c", "c.orderCode=a.orderCode", "left")
  2164. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  2165. ->join("good b", "b.good_code=a.good_kode", "left")
  2166. ->where($where)->page($page, $size)->field("a.*,b.cat_id,c.customer_code,v.companyName")
  2167. ->order("a.addtime desc")->select();
  2168. $data = [];
  2169. foreach ($list as $value) {
  2170. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2171. $wsm = Db::name("sale")->alias("a")->Join("supplier b", "a.supplierNo=b.code", "left")->where
  2172. (['a.orderCode' => $value['orderCode'], "a.is_del" => 0])->field("b.code,b.name")->find();
  2173. $value['supplierNo'] = isset($wsm['code']) ? $wsm['code'] : "";
  2174. $value['supplierName'] = isset($wsm['name']) ? $wsm['name'] : "";
  2175. $data[] = $value;
  2176. }
  2177. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  2178. }
  2179. /**
  2180. * @return \think\response\Json|void
  2181. * @throws \think\db\exception\DataNotFoundException
  2182. * @throws \think\db\exception\DbException
  2183. * @throws \think\db\exception\ModelNotFoundException
  2184. */
  2185. public function diffcheck()
  2186. {
  2187. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2188. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2189. if ($id === "") {
  2190. return error_show(1004, "参数id不能为空");
  2191. }
  2192. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  2193. if (empty($info)) {
  2194. return error_show(1004, "订单数据未找到");
  2195. }
  2196. $is_act = isset($this->post['is_act']) && $this->post['is_act'] !== "" ? intval($this->post['is_act']) : "";
  2197. if ($is_act === '') {
  2198. return error_show(1004, "参数is_act不能为空");
  2199. }
  2200. $customer_remark = isset($this->post['customer_remark']) && $this->post['customer_remark'] !== "" ? trim($this->post['customer_remark']) : "";
  2201. if ($customer_remark === '') {
  2202. return error_show(1004, "参数customer_remark不能为空");
  2203. }
  2204. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "2";
  2205. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  2206. $item = $info['status'];
  2207. $info['is_act'] = $is_act;
  2208. $info['customer_remark'] = $customer_remark;
  2209. $info['status'] = $status;
  2210. $info['remark'] = $remark;
  2211. $info['updatetime'] = date("Y-m-d H:i:s");
  2212. $up = Db::name("sale_diff")->save($info);
  2213. if ($up) {
  2214. $stx = ["order_code"=>$info["orderCode"],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2215. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  2216. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
  2217. ProcessOrder::AddProcess($this->post['token'],$order);
  2218. return app_show(0, "更新成功");
  2219. } else {
  2220. return error_show(1003, "更新失败");
  2221. }
  2222. }
  2223. /**
  2224. * @return \think\response\Json|void
  2225. * @throws \think\db\exception\DataNotFoundException
  2226. * @throws \think\db\exception\DbException
  2227. * @throws \think\db\exception\ModelNotFoundException
  2228. */
  2229. public function diffstatus()
  2230. {
  2231. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2232. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2233. if ($id === "") {
  2234. return error_show(1004, "参数id不能为空");
  2235. }
  2236. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  2237. if (empty($info)) {
  2238. return error_show(1004, "订单数据未找到");
  2239. }
  2240. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "3";
  2241. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  2242. $ite=$info['status'];
  2243. $info['status'] = $status;
  2244. $info['remark'] = $remark;
  2245. $info['updatetime'] = date("Y-m-d H:i:s");
  2246. $up = Db::name("sale_diff")->save($info);
  2247. if ($up) {
  2248. $stx = ["order_code"=>$info["orderCode"],"status"=>$ite,"action_remark"=>'',"action_type"=>"status"];
  2249. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  2250. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
  2251. ProcessOrder::AddProcess($this->post['token'],$order);
  2252. return app_show(0, "更新成功");
  2253. } else {
  2254. return error_show(1003, "更新失败");
  2255. }
  2256. }
  2257. /**
  2258. * @return \think\response\Json|void
  2259. * @throws \think\db\exception\DataNotFoundException
  2260. * @throws \think\db\exception\DbException
  2261. * @throws \think\db\exception\ModelNotFoundException
  2262. */
  2263. public function diffinfo()
  2264. {
  2265. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2266. if ($id === "") {
  2267. return error_show(1004, "参数id不能为空");
  2268. }
  2269. $info = Db::name('sale_diff')->alias('a')->join("good b", "b.good_code=a.good_kode", "left")->where
  2270. (["a.id" => $id])->field("a.*,b.cat_id")->find();
  2271. if (empty($info)) {
  2272. return error_show(1004, "订单数据未找到");
  2273. }
  2274. $info['can'] = isset($info['cat_id']) && $info['cat_id'] !== 0 ? made($info['cat_id']) : [];
  2275. return app_show(0, "获取成功", $info);
  2276. }
  2277. public function saleout(){
  2278. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  2279. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  2280. $where= [];
  2281. $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode'])
  2282. :"";
  2283. if($orderCode !==""){
  2284. $where[]=['a.orderCode',"like","%$orderCode%"];
  2285. }
  2286. $order_type=isset($this->post['order_type']) && $this->post['order_type'] !=="" ? trim($this->post['order_type'])
  2287. :"";
  2288. if($order_type !==""){
  2289. $where[]=['a.order_type',"=",$order_type];
  2290. }
  2291. $outCode=isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode'])
  2292. :"";
  2293. if($outCode !==""){
  2294. $where[]=['a.outCode',"like","%$outCode%"];
  2295. }
  2296. $apply_name=isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name'])
  2297. :"";
  2298. if($apply_name !==""){
  2299. $where[]=['a.apply_name',"like","%$apply_name%"];
  2300. }
  2301. $good_code=isset($this->post['good_code']) && $this->post['good_code'] !=="" ? trim($this->post['good_code'])
  2302. :"";
  2303. if($good_code !==""){
  2304. $where[]=['b.good_code',"like","%$good_code%"];
  2305. }
  2306. $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name'])
  2307. :"";
  2308. if($good_name !==""){
  2309. $where[]=['b.good_name',"like","%$good_name%"];
  2310. }
  2311. $status=isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']):"";
  2312. if($status !==""){
  2313. $where[]=['a.status',"=",$status];
  2314. }
  2315. $start = isset($this->post['start']) && $this->post['start'] !=="" ? $this->post['start'] :"";
  2316. if($start !=""){
  2317. $where[]= ["a.addtime",'>=',$start];
  2318. }
  2319. $end = isset($this->post['end']) && $this->post['end'] !=="" ? $this->post['end'] :"";
  2320. if($end !=""){
  2321. $where[]= ["a.addtime",'<=',$end];
  2322. }
  2323. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  2324. if($companyNo!=""){
  2325. $where[]=['b.customer_code',"like","%$companyNo%"];
  2326. }
  2327. $count = Db::name('order_out')->alias('a')
  2328. ->join("sale b", "b.orderCode=a.orderCode", "left")
  2329. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  2330. //->join("good n","n.good_code=b.good_code","left")
  2331. ->where($where)->count();
  2332. $total = ceil($count / $size);
  2333. $page = $page >= $total ? $total : $page;
  2334. $list = Db::name('order_out')->alias('a')->join("sale b", "b.orderCode=a.orderCode", "left")
  2335. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  2336. //->join("good n","n.good_code=b.good_code","left")
  2337. ->field("a.*,b.good_name,b.good_code,b.supplierNo,b.customer_code,v.companyName,b.origin_price,b.sale_price,b.total_price")
  2338. ->where($where)->order("addtime desc")->page($page, $size)->select();
  2339. $data=[];
  2340. foreach ($list as $value) {
  2341. $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  2342. ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  2343. $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
  2344. $good = Db::name("good_type")->alias("b")->join("good a", "a.good_code = b.good_code", "left")
  2345. ->where(["type_code" => $value['good_code']])->field('cat_id')->find();
  2346. $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  2347. $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  2348. $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  2349. $value['addr'] = isset($addr['addr']) ? $addr['addr'] : "";
  2350. $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  2351. $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  2352. $value['can'] = isset($good['cat_id']) && $good['cat_id'] != 0 ? made($good['cat_id']) : [];
  2353. $data[] = $value;
  2354. }
  2355. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  2356. }
  2357. public function outinfo()
  2358. {
  2359. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  2360. if ($outCode == "") {
  2361. return error_show(1002, "参数outcode不能为空");
  2362. }
  2363. $codeinfo = Db::name("order_out")->where(['outCode' => $outCode])->find();
  2364. if (empty($codeinfo)) {
  2365. return error_show(1002, "未找到出库数据");
  2366. }
  2367. $item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  2368. if($item['order_type']==3|| $item['order_type']==4){
  2369. // $good=Db::name("good_zixun")->where(["spuCode"=>$good_code])->find();
  2370. // if($good==false){
  2371. // return error_show(1004,"未找到商品数据");
  2372. // }
  2373. $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$item['good_code'],"is_del"=>0])->find();
  2374. if($goodinfo==false){
  2375. return error_show(1004,"未找到商品数据");
  2376. }
  2377. }else{
  2378. $goodinfo = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2379. ->where(['a.skuCode' =>$item['skuCode']])->find();
  2380. if ($goodinfo == false) {
  2381. return error_show(1002, "未找到商品数据");
  2382. }
  2383. }
  2384. $int = isset($goodinfo['cat_id']) && $goodinfo['cat_id'] != 0 ? made($goodinfo['cat_id']) : [];
  2385. // $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  2386. // ->where(["k.wsm_code" => $codeinfo['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  2387. $addr = Db::name("order_addr")->where(["id" => $codeinfo['addrid']])->find();
  2388. //$item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  2389. $codeinfo['good_name'] = isset($item['good_name']) ? $item['good_name'] : "";
  2390. $codeinfo['good_num'] = isset($item['good_num']) ? $item['good_num'] : "";
  2391. $codeinfo['good_code'] = isset($item['good_code']) ? $item['good_code'] : "";
  2392. $codeinfo['origin_price'] = isset($item['origin_price']) ? $item['origin_price'] : "";
  2393. $codeinfo['sale_price'] = isset($item['sale_price']) ? $item['sale_price'] : "";
  2394. $codeinfo['total_price'] = isset($item['total_price']) ? $item['total_price'] : "";
  2395. // $codeinfo['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  2396. // $codeinfo['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  2397. // $codeinfo['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  2398. $codeinfo['addr'] = GetAddr($addr['addr_code']);
  2399. $codeinfo['addr'] .= isset($addr['addr']) ? $addr['addr'] : "";
  2400. $codeinfo['addr_code'] = isset($addr['addr_code']) ? $addr['addr_code'] : "";
  2401. $codeinfo['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  2402. $codeinfo['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  2403. $codeinfo['can'] = $int;
  2404. return app_show(0, "获取成功", $codeinfo);
  2405. }
  2406. public function outadd(){
  2407. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2408. $outCode = makeNo("CK");
  2409. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  2410. if ($orderCode == "") {
  2411. return error_show(1002, "参数orderCoder不能为空");
  2412. }
  2413. $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
  2414. if ($der == "") {
  2415. return error_show(1002, "未找到出库订单单号");
  2416. }
  2417. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  2418. if ($send_num == "") {
  2419. return error_show(1002, "发货数量不能为空");
  2420. }
  2421. if ($send_num > $der['wsend_num']) {
  2422. return error_show(1002, "超出可发货数量");
  2423. }
  2424. $contactor = isset($this->post['contactor'])&&$this->post['contactor']!="" ? trim($this->post['contactor']):"";
  2425. if($contactor==""){
  2426. return error_show(1002, "参数contactor不能为空");
  2427. }
  2428. $mobile = isset($this->post['mobile'])&&$this->post['mobile']!="" ? trim($this->post['mobile']):"";
  2429. if($mobile==""){
  2430. return error_show(1002, "参数mobile不能为空");
  2431. }
  2432. $addr = isset($this->post['addr'])&&$this->post['addr']!="" ? trim($this->post['addr']):"";
  2433. if($addr==""){
  2434. return error_show(1002, "参数addr不能为空");
  2435. }
  2436. $addr_code = isset($this->post['addr_code'])&&$this->post['addr_code']!="" ? trim($this->post['addr_code']):"";
  2437. if($addr_code==""){
  2438. return error_show(1002, "参数addr_code不能为空");
  2439. }
  2440. $apply_id = GetUserInfo($token);
  2441. if (empty($apply_id) || $apply_id['code'] != 0) {
  2442. return error_show(1002, "申请人数据不存在");
  2443. }
  2444. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2445. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  2446. // $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
  2447. // $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
  2448. // if (empty($dr)) {
  2449. // return error_show(1003, "收货人信息未找到");
  2450. // }
  2451. // if ($dr['orderCode'] !== $orderCode) {
  2452. // return error_show(1002, "订单code不存在");
  2453. // }
  2454. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  2455. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  2456. ->select()->toArray();
  2457. if(empty($order)){
  2458. return error_show(1004,"未找到可以发货得采购单数据");
  2459. }
  2460. Db::startTrans();
  2461. try {
  2462. $addrlst =[
  2463. "orderCode"=>$orderCode,
  2464. "addr"=>$addr,
  2465. "addr_code"=>json_encode($addr_code),
  2466. "contactor"=>$contactor,
  2467. "mobile"=>$mobile,
  2468. "customer_code"=>$der['customer_code'],
  2469. "post_fee"=>$der['post_fee'],
  2470. "arrive_time"=>$sendtime,
  2471. "receipt_quantity"=>$send_num,
  2472. "is_del"=>0,
  2473. "addtime"=>date("Y-m-d H:i:s"),
  2474. "updatetime"=>date("Y-m-d H:i:s")
  2475. ];
  2476. $addrid = Db::name("order_addr")->insert($addrlst,true);
  2477. if($addrid>0){
  2478. $data = [
  2479. "wsm_code" => "",
  2480. "orderCode" => $orderCode,
  2481. "outCode" => $outCode,
  2482. "order_type" => $der['order_type'],
  2483. "apply_id" => $rm,
  2484. "apply_name" => $ri,
  2485. "addrid" => $addrid,
  2486. "post_name" => "",
  2487. "post_code" =>"",
  2488. "post_fee" => "",
  2489. "sendtime" => $sendtime,
  2490. "send_num" => $send_num,
  2491. "check_num" => 0,
  2492. "error_num" => 0,
  2493. "status" => 1,
  2494. "addtime" => date("Y-m-d H:i:s"),
  2495. "updatetime" => date("Y-m-d H:i:s")
  2496. ];
  2497. $datainfo = Db::name('order_out')->insert($data,true);
  2498. if($datainfo>0){
  2499. $num = $send_num;
  2500. foreach ($order as $val){
  2501. $tep=[];
  2502. $ornum=0;
  2503. if($val['wsend_num']>=$num){
  2504. $val['wsend_num']-=$num;
  2505. $val['send_num']+=$num;
  2506. $ornum =$num;
  2507. $num=0;
  2508. }else{
  2509. $num-=$val['wsend_num'];
  2510. $val['send_num']+=$val['wsend_num'];
  2511. $ornum =$val['wsend_num'];
  2512. $val['wsend_num']=0;
  2513. }
  2514. $or =Db::name("order_num")->save($val);
  2515. if($or==false){
  2516. Db::rollback();
  2517. return error_show(1002,"发货地址添加创建失败");
  2518. }
  2519. $tep=[
  2520. "cgdNo"=>$val['cgdNo'],
  2521. "outCode"=>$outCode,
  2522. "send_num"=>$ornum,
  2523. "status"=>1,
  2524. "addtime"=>date("Y-m-d H:i:s"),
  2525. "updatetime"=>date("Y-m-d H:i:s")
  2526. ];
  2527. $sen=Db::name("order_send")->save($tep);
  2528. if($sen==false){
  2529. Db::rollback();
  2530. return error_show(1002,"发货地址添加创建失败");
  2531. }
  2532. if($num==0){
  2533. break;
  2534. }
  2535. }
  2536. Db::commit();
  2537. return app_show(0,"出库单新建成功",["outCode"=>$outCode]);
  2538. }
  2539. }
  2540. Db::rollback();
  2541. return error_show(1004,"出库单新建失败");
  2542. } catch (Exception $e) {
  2543. Db::rollback();
  2544. return error_show(1005, $e->getMessage());
  2545. }
  2546. }
  2547. public function outSend(){
  2548. $outCode=isset($this->post['outCode'])&& $this->post['outCode']!=""? trim($this->post['outCode']):"";
  2549. if($outCode==""){
  2550. return error_show(1004,"参数outCode不能为空");
  2551. }
  2552. $outinfo = Db::name("order_out")->where(["outCode"=>$outCode])->find();
  2553. if($outinfo==false){
  2554. return error_show(1004,"发货数据未找到");
  2555. }
  2556. $post_name = isset($this->post['post_name']) &&$this->post['post_name']!="" ? trim($this->post['post_name']):"";
  2557. if($post_name==""){
  2558. return error_show(1004,"参数post_name不能为空");
  2559. }
  2560. $post_code = isset($this->post['post_code']) &&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
  2561. if($post_code==""){
  2562. return error_show(1004,"参数post_code不能为空");
  2563. }
  2564. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee']!="" ? floatval($this->post['post_fee']):"";
  2565. $outinfo['post_name'] = $post_name;
  2566. $outinfo['post_code'] = $post_code;
  2567. $outinfo['post_fee'] = $post_fee;
  2568. $outinfo['sendtime'] = date("Y-m-d H:i:s");
  2569. $outinfo['status'] = 2;
  2570. $outinfo['updatetime'] = date("Y-m-d H:i:s");
  2571. try{
  2572. $up =Db::name("order_out")->save($outinfo);
  2573. if($up){
  2574. $stokc =Db::name("good_stock")->where(['spuCode'=>$outinfo['spuCode'],"wsm_code"=>$outinfo['wsm_code'],
  2575. "is_del"=>0])->find();
  2576. if($stokc==false){
  2577. Db::rollback();
  2578. return error_show(1002, "未找库存到数据");
  2579. }else{
  2580. if ($outinfo['send_num'] > $stokc['wait_out_stock']) {
  2581. Db::rollback();
  2582. return error_show(1002, "超出库存数量");
  2583. }
  2584. $stokc['wait_out_stock']-=$outinfo['send_num'];
  2585. $stokc['intra_stock']+=$outinfo['send_num'];
  2586. $stokc['updatetime']=date("Y-m-d H:i:s");
  2587. }
  2588. $stoc= Db::name("good_stock")->save($stokc);
  2589. if($stoc==false){
  2590. Db::rollback();
  2591. return error_show(1002, "库存更新失败");
  2592. }
  2593. Db::commit();
  2594. return app_show(0,"发货成功");
  2595. }else{
  2596. Db::rollback();
  2597. return error_show(1004,"发货失败");
  2598. }
  2599. }catch (\Exception $e){
  2600. Db::rollback();
  2601. return error_show(1004,$e->getMessage());
  2602. }
  2603. }
  2604. public function RelaCgd($outinfo){
  2605. $der = Db::name('sale')->where(['orderCode' => $outinfo['orderCode']])->find();
  2606. if ($der == "") {
  2607. return false;
  2608. }
  2609. if($der['is_stock']==1){
  2610. $cgd = Db::name("order_bk")->where([["spuCode","=",$der['spuCode']],["is_del","=",0],["balance_num",">",0]])
  2611. ->select()->toArray();
  2612. if(empty($cgd)){
  2613. return false;
  2614. }
  2615. $send =$outinfo['send_num'];
  2616. $outsend=[];
  2617. foreach ($cgd as $value){
  2618. $temp=[];
  2619. if($value['balance_num']>=$send){
  2620. $value['balance_num']-=$send;
  2621. $value['merge_num']+=$send;
  2622. $send=0;
  2623. $temp['send_num'] =$send;
  2624. }else{
  2625. $value['balance_num'] =0;
  2626. $value['merge_num']+=$value['balance_num'];
  2627. $send -= $value['balance_num'];
  2628. $temp['send_num'] =$value['balance_num'];
  2629. }
  2630. $value['status'] = $value['balance_num']==0 ?2:$value['merge_num']==0?0:1 ;
  2631. $value['updatetime'] = date("Y-m-d H:i:s");
  2632. $bk = Db::name("order_bk")->save($value);
  2633. if($bk==false){
  2634. return false;
  2635. }
  2636. $temp['cgdNo'] = $value['cgdNo'];
  2637. $temp['outCode'] = $outinfo['outCode'];
  2638. $temp['status'] = 1;
  2639. $temp['addtime']=date("Y-m-d H:i:s");
  2640. $temp['updatetime']=date("Y-m-d H:i:s");
  2641. $outsend[]=$temp;
  2642. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"cgdNo"=>$value['cgdNo'],"spuCode"=>$der['spuCode'],"status"=>1])->find();
  2643. if($order==false){
  2644. $order=[
  2645. "orderCode"=>$der['orderCode'],
  2646. "cgdNo"=>$value['cgdNo'],
  2647. "spuCode"=>$der['spuCode'],
  2648. "good_num"=>$der['good_num'],
  2649. "wsend_num"=>$der['good_num']-$temp['send_num'],
  2650. "send_num"=>$temp['send_num'],
  2651. "status"=>1,
  2652. "source"=>1
  2653. ];
  2654. }else{
  2655. $order['wsend_num']-=$temp['send_num'];
  2656. $order['send_num']+=$temp['send_num'];
  2657. }
  2658. if($order['wsend_num']<0){
  2659. return false;
  2660. }
  2661. $up =Db::name("order_num")->save($order);
  2662. if($up==false){
  2663. return false;
  2664. }
  2665. if($send==0){
  2666. break;
  2667. }
  2668. }
  2669. if(empty($temp)){
  2670. return false;
  2671. }
  2672. $insert = Db::name("order_send")->insertAll($outsend);
  2673. if($insert){
  2674. return true;
  2675. }else{
  2676. return false;
  2677. }
  2678. }else{
  2679. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"spuCode"=>$der['spuCode'],
  2680. "status"=>1])->find();
  2681. if($order==false){
  2682. return false;
  2683. }else{
  2684. if($outinfo['send_num']> $order['wsend_num']){
  2685. return false;
  2686. }
  2687. $order['wsend_num']-=$outinfo['send_num'];
  2688. $order['send_num']+=$outinfo['send_num'];
  2689. if($order['wsend_num']<0){
  2690. return false;
  2691. }
  2692. $up =Db::name("order_num")->save($order);
  2693. if($up==false){
  2694. return false;
  2695. }
  2696. $temp=[];
  2697. $temp['cgdNo'] = $order['cgdNo'];
  2698. $temp['outCode'] = $outinfo['outCode'];
  2699. $temp['send_num'] =$outinfo['send_num'];
  2700. $temp['status'] = 1;
  2701. $temp['addtime']=date("Y-m-d H:i:s");
  2702. $temp['updatetime']=date("Y-m-d H:i:s");
  2703. $insert = Db::name("order_send")->insert($temp);
  2704. if($insert){
  2705. return true;
  2706. }else{
  2707. return false;
  2708. }
  2709. }
  2710. }
  2711. }
  2712. public function addother(){
  2713. $orderCode =isset($this->post['orderCode']) && $this->post['orderCode']!=""?trim($this->post['orderCode']):"";
  2714. if($orderCode==""){
  2715. return error_show(1004,"参数orderCode不能为空");
  2716. }
  2717. $order =Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->find();
  2718. if($order==false){
  2719. return error_show(1004,"未找到订单数据");
  2720. }
  2721. $paytime =isset($this->post['paytime'])&&$this->post['paytime']!=""? $this->post['paytime']:"";
  2722. $workNo =isset($this->post['workNo'])&&$this->post['workNo']!=""? trim($this->post['workNo']):"";
  2723. $platform_order =isset($this->post['platform_order'])&&$this->post['platform_order']!=""? trim($this->post['platform_order']):"";
  2724. $paytime==""?"":$order['paytime']=$paytime;
  2725. $order['workNo']=$workNo;
  2726. $order['platform_order']=$platform_order;
  2727. $order['updatetime']=date("Y-m-d H:i:s");
  2728. $sa=Db::name("sale")->save($order);
  2729. if($sa){
  2730. return app_show(0,"更新成功");
  2731. }else{
  2732. return error_show(1004,"更新失败");
  2733. }
  2734. }
  2735. public function getPrice(){
  2736. $skuCode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
  2737. if($skuCode===""){
  2738. return error_show(1003,"参数skuCode不能为空");
  2739. }
  2740. $is_activity=isset($this->post['is_activity'])&&$this->post['is_activity']!==""?intval($this->post['is_activity'])
  2741. :"";
  2742. if($is_activity===""){
  2743. return error_show(1003,"参数is_activity不能为空");
  2744. }
  2745. $sale_num=isset($this->post['sale_num'])&&$this->post['sale_num']!==""?intval($this->post['sale_num']):"";
  2746. if($sale_num===""){
  2747. return error_show(1003,"参数sale_num不能为空");
  2748. }
  2749. $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2750. ->where(['a.skuCode' =>$skuCode])->find();
  2751. if ($ct == false) {
  2752. return error_show(1002, "未找到商品数据");
  2753. }
  2754. $origin = Db::name("good_nake")->where([["spuCode","=",$ct['spuCode']],["min_num","<=", $sale_num],["is_del","=",
  2755. 0]])->order("min_num desc")->find();
  2756. if($origin==false){
  2757. $origin = Db::name("good_nake")->where([["spuCode","=",$ct['spuCode']],["is_del","=",
  2758. 0]])->order("min_num asc")->find();
  2759. return error_show(1003,"不满足成本最低阶梯数量{$origin['min_num']}");
  2760. }
  2761. $stock=0;
  2762. if($ct['is_stock']==1){
  2763. $good_stock =Db::name("good_stock")->where(["spuCode"=>$ct['spuCode'],"is_del"=>0])->find();
  2764. $stock= isset($good_stock['usable_stock'])?$good_stock['usable_stock']:"0";
  2765. }
  2766. if($is_activity==1){
  2767. $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b","a.activity_code=b.activity_code")
  2768. ->where(["a.skuCode"=>$skuCode,"a.is_del"=>0,"a.status"=>1,"b.status"=>6,"b.is_del"=>0])->find();
  2769. if($act==false){
  2770. return error_show(1003,"未找到相关活动价");
  2771. }
  2772. if($act['moq_num']>$sale_num){
  2773. return error_show(1003,"商品不满足活动价起订量{$act['moq_num']}");
  2774. }
  2775. if($act['activity_stock']<$sale_num){
  2776. return error_show(1003,"商品活动库存剩余{$act['activity_stock']}");
  2777. }
  2778. return app_show(0,"获取成功",['sale_price'=>$act['activity_price'],"stock"=>$act['activity_stock']]);
  2779. }else{
  2780. $good = Db::name("good_ladder")->where(["skuCode"=>$skuCode,"is_del"=>0,"status"=>1])->order("min_num desc")
  2781. ->select()->toArray();
  2782. if(empty($good)){
  2783. return error_show(1003,"未找到相关阶梯价格");
  2784. }
  2785. $lastnum=0;
  2786. $lastprice=0;
  2787. foreach ($good as $value){
  2788. if($value['min_num']>$sale_num){
  2789. $lastnum=$value['min_num'];
  2790. $lastprice=0;
  2791. continue;
  2792. }else{
  2793. $lastnum=0;
  2794. $lastprice=$value['sale_price'];
  2795. break;
  2796. }
  2797. }
  2798. if($lastnum==0){
  2799. return app_show(0,"获取成功",['sale_price'=>$lastprice,"stock"=>$stock]);
  2800. }else{
  2801. return error_show(1003,"商品不满足起订量{$lastnum}");
  2802. }
  2803. }
  2804. }
  2805. }