Sale.php 143 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970
  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. }else{
  1497. $goon['exclusive']=makeExcluse($goon['is_exclusive']);
  1498. $unit =Db::name("unit")->where(["id"=>$goon['good_unit']])->find();
  1499. $goon['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1500. $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
  1501. $speclist=[];
  1502. if(!empty($spec)){
  1503. foreach ($spec as $value){
  1504. $temp=[];
  1505. $temp['id']=$value['id'];
  1506. $temp['spuCode']=$value['spuCode'];
  1507. $temp['spec_id']=$value['spec_id'];
  1508. $temp['spec_value_id']=$value['spec_value_id'];
  1509. $temp['is_del']=$value['is_del'];
  1510. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  1511. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1512. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  1513. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1514. $speclist[]=$temp;
  1515. }
  1516. }
  1517. $goon["speclist"]=empty($speclist)?[]:$speclist;
  1518. $proof =Db::name("good_proof")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  1519. $goon['proof'] = isset($proof)&&$proof!=false? $proof:[];
  1520. $goon['origin_place_cn']="";
  1521. $goon['delivery_place_cn']="";
  1522. if($goon['delivery_place']!==""){
  1523. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1524. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['delivery_place']);
  1525. $goon['delivery_place_cn']=GetAddr(json_encode($place));
  1526. }
  1527. if($goon['origin_place']!==""){
  1528. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1529. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['origin_place']);
  1530. $goon['origin_place_cn']=GetAddr(json_encode($place));
  1531. }
  1532. if($goon['brand_id']!=0){
  1533. $brand=Db::name("brand")->where(["id"=>$goon['brand_id']])->find();
  1534. $goon["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1535. }else{
  1536. $goon["brand_name"]="";
  1537. $goon["brand_id"]="";
  1538. }
  1539. $supplier = Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
  1540. $goon['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1541. $goon['noble_name']=isset($goon['noble_metal'])&&$goon['noble_metal']!=0?$this->noble[$goon['noble_metal']] :"";
  1542. $company = Db::name("business")->where(["companyNo"=>$goon['companyNo']])->find();
  1543. $goon['company'] = isset($company['company'])?$company['company']:"";
  1544. }
  1545. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  1546. $in = Db::name('customer_info')->where(['companyNo' => $einfo['customer_code']])->field('companyName')->find();
  1547. // ->field('addr,contactor,mobile,receipt_quantity,arrive_time')
  1548. $einfo['supplierName'] = '';
  1549. if ($einfo['supplierNo'] != "") {
  1550. $supplier = Db::name("business")->where(["companyNo" => $einfo['supplierNo']])->find();
  1551. $einfo['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
  1552. }
  1553. $fo = Db::name('order_addr')->where(['orderCode' => $einfo['orderCode'], 'is_del' => 0])->select();
  1554. $bum = Db::name('order_out')->where(['orderCode' => $einfo['orderCode']])->select();
  1555. $ins = [];
  1556. if (!empty($bum)) {
  1557. foreach ($bum as $stn) {
  1558. $so = Db::name('order_addr')->where(['id' => $stn['addrid']])->find();
  1559. $addr = GetAddr($so['addr_code']);
  1560. $stn['addr_info'] = $addr;
  1561. $stn['add_code'] = json_decode($so['addr_code'], true);
  1562. $stn['addr'] = $so['addr'];
  1563. $stn['contact'] = $so['contactor'];
  1564. $stn['mobile'] = $so['mobile'];
  1565. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
  1566. ->where(["a.wsm_code" => $stn['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  1567. $stn['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  1568. $stn['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  1569. $stn['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  1570. $ins[] = $stn;
  1571. }
  1572. }
  1573. $addrs = [];
  1574. if (!empty($fo)) {
  1575. foreach ($fo as $value) {
  1576. $value['addr_info'] = "";
  1577. $value['send_num'] = 0;
  1578. if ($value['addr_code'] != "") {
  1579. $addr = GetAddr($value['addr_code']);
  1580. $value['addr_info'] = $addr;
  1581. $value['addr_code'] = json_decode($value['addr_code'], true);
  1582. $send = Db::name("order_out")->where(['addrid' => $value['id'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
  1583. $value['send_num'] = $send ?? 0;
  1584. }
  1585. $value['wsend_num'] = $value['receipt_quantity'] - $value['send_num'];
  1586. $addrs[] = $value;
  1587. }
  1588. }
  1589. $einfo['useage']="";
  1590. if($einfo['use_order']!=0){
  1591. $use =Db::name("order_use")->where(["id"=>$einfo['use_order']])->find();
  1592. $einfo['useage'] = isset($use['order_use']) ?$use['order_use']:"";
  1593. }
  1594. // //->field('num,sale_price,wsm_code,stock_id')
  1595. // $st = Db::name('sale_info')->where(['orderCode' => $einfo['orderCode']])->select();
  1596. // $data = [];
  1597. // if (!empty($fo)) {
  1598. // foreach ($st as $value) {
  1599. // $value['wsm_name'] = "";
  1600. // $value['wsm_supplier'] = "";
  1601. // $value['wsm_supplierNo'] = "";
  1602. // $value['usable_stock'] = 0;
  1603. // $value['send_num'] = 0;
  1604. // if ($value['wsm_code'] != "") {
  1605. // $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
  1606. // ->where(["a.wsm_code" => $value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  1607. // $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  1608. // $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  1609. // $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  1610. // $dn = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $einfo['good_code']])->find();
  1611. // $value['usable_stock'] = isset($dn['usable_stock']) ? $dn['usable_stock'] : "0";
  1612. // $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
  1613. // $value['send_num'] = $send ?? 0;
  1614. // }
  1615. // $value['wsend_num'] = $value['num'] - $value['send_num'];
  1616. // $data[] = $value;
  1617. // }
  1618. // }
  1619. // $einfo['info'] = $data;
  1620. $einfo['companyName'] = isset($in['companyName']) ? $in['companyName'] : "";
  1621. $einfo['addrs'] = $addrs;
  1622. // $einfo['orderout'] = $ins;
  1623. $einfo['can'] = $int;
  1624. $einfo['goodinfo'] = $goon;
  1625. // $einfo['salediff'] = $info;
  1626. // $einfo['orderreturn'] = $dm;
  1627. // $einfo['orderback'] = $dk;
  1628. // $einfo['salereturn'] = $sa;
  1629. if (empty($einfo)) {
  1630. return error_show(1002, "未找到销售订单数据");
  1631. } else {
  1632. return app_show(0, "获取成功", $einfo);
  1633. }
  1634. }
  1635. public function del()
  1636. {
  1637. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1638. if ($id === "") {
  1639. return error_show(1002, "参数id不能为空");
  1640. }
  1641. $ed = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1642. if (empty($ed)) {
  1643. return error_show(1002, "未找到销售订单数据");
  1644. }
  1645. $str = Db::name('sale')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1646. if ($str) {
  1647. $stc = ["order_code"=>$id,"status"=>$ed['status'],"action_remark"=>'',"action_type"=>"delete"];
  1648. ActionLog::logAdd($this->post['token'],$stc,"XSQRD",$ed['status'],['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1649. $order=["order_type"=>'XSQRD',"order_code"=>$ed['orderCode'],"order_id"=>$id,"order_status"=>$ed['status']];
  1650. ProcessOrder::workdel($order);
  1651. return error_show(0, "删除成功");
  1652. } else {
  1653. return error_show(1002, "删除失败");
  1654. }
  1655. }
  1656. public function status()
  1657. {
  1658. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1659. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1660. if ($id == "") {
  1661. return error_show(1002, "参数id不能为空");
  1662. }
  1663. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1664. if ($status == "") {
  1665. return error_show(1002, "订单状态不能为空");
  1666. }
  1667. $dio = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1668. if (empty($dio)) {
  1669. return error_show(1002, "销售单信息未找到");
  1670. }
  1671. if ($status == 1 && $dio['order_type'] == 2) {
  1672. $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
  1673. if ($zxinfo == false) {
  1674. return error_show(1004, "未找到咨询单数据");
  1675. }
  1676. $gold['price'] = 0;
  1677. if ($zxinfo['zx_type'] == 2) {
  1678. if ($zxinfo['metals'] == "") {
  1679. return error_show(1004, "未找到咨询单贵金属类型数据");
  1680. }
  1681. $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
  1682. $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
  1683. if (empty($gold)) {
  1684. return error_show(1004, "未找到咨询单贵金属类型数据");
  1685. }
  1686. $dio['gold_price'] = $gold['price'];
  1687. }
  1688. $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
  1689. if (empty($wsm)) {
  1690. return error_show(1002, "供应商仓库未找到");
  1691. }
  1692. }
  1693. $apply_id = GetUserInfo($token);
  1694. if (empty($apply_id) || $apply_id['code'] != 0) {
  1695. return error_show(1002, "申请人数据不存在");
  1696. }
  1697. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1698. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1699. Db::startTrans();
  1700. try {
  1701. $vmp =$dio['status'];
  1702. $dio['status'] = $status;
  1703. $dio['updatetime'] = date("Y-m-d H:i:s");
  1704. $st = Db::name('sale')->save($dio);
  1705. if ($st) {
  1706. $stn = ["order_code"=>$dio['orderCode'],"status"=>$vmp,"action_remark"=>'',"action_type"=>"status"];
  1707. ActionLog::logAdd($this->post['token'],$stn, $dio['order_type'] == 2?"ZXQRD":"XSQRD",$dio['status'],$dio);
  1708. $order=["order_type"=>$dio['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dio['orderCode'],"order_id"=>$id,"order_status"=>$dio['status']];
  1709. ProcessOrder::AddProcess($this->post['token'],$order);
  1710. if ($status == 3 && $dio['order_type'] == 1) {
  1711. $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
  1712. foreach ($dn as $value) {
  1713. $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
  1714. if ($dm == "") {
  1715. Db::rollback();
  1716. return error_show(1003, "未找到商品数据");
  1717. }
  1718. if ($value['num'] > $dm['usable_stock']) {
  1719. Db::rollback();
  1720. return error_show(1002, "超出库存数量");
  1721. }
  1722. $dm['usable_stock'] -= $value['num'];
  1723. $dm['wait_out_stock'] += $value['num'];
  1724. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code']])->sum("send_num");
  1725. $value['send_num'] = $send ?? 0;
  1726. $value['wsend_num'] = $value['num'] - $value['send_num'];
  1727. $Db = Db::name('good_stock')->update($dm);
  1728. $Db['updatetime'] = date('Y-m-d H:i:s');
  1729. if ($Db == false) {
  1730. Db::rollback();
  1731. return error_show(1002, "状态更新失败");
  1732. }
  1733. }
  1734. }
  1735. if ($status == 1 && $dio['order_type'] == 2) {
  1736. $cgd = makeNo("CG");
  1737. $clll = [
  1738. "cgdNo" => $cgd,
  1739. "bkcode" => $dio['orderCode'],
  1740. "wsm_code" => $wsm['wsm_code'],
  1741. "cgder_id" => "0",
  1742. "cgder" => $zxinfo['saler'],
  1743. "good_code" => "GD-" . $zxinfo['cpNo'],
  1744. "good_name" => $zxinfo['cpName'],
  1745. "good_type_code" => $zxinfo['cpNo'],
  1746. "good_num" => $dio['good_num'],
  1747. "good_price" => $zxinfo['total_fee'],
  1748. "total_fee" => round($zxinfo['total_fee'] * $dio['good_num'], 2),
  1749. "pakge_fee" => $zxinfo['package_fee'],
  1750. "cert_fee" => $zxinfo['cert_fee'],
  1751. "open_fee" => $zxinfo['open_fee'],
  1752. "delivery_fee" => $zxinfo['delivery_fee'],
  1753. "mark_fee" => $zxinfo['mark_fee'],
  1754. "teach_fee" => $zxinfo['cost_fee'],
  1755. "demo_fee" => $zxinfo['demo_fee'],
  1756. "nake_fee" => $zxinfo['bare_fee'],
  1757. "weight" => isset($zxinfo['weight']) ? $zxinfo['weight'] : 0,
  1758. "supplierNo" => $zxinfo['gysNo'],
  1759. "supplier_name" => $zxinfo['gysname'],
  1760. "gold_price" => $gold['price'],
  1761. "send_num" => 0,
  1762. "wsend_num" => $dio['good_num'],
  1763. "remark" => '',
  1764. "lasttime" => date("Y-m-d H:i:s"),
  1765. "is_del" => 0,
  1766. "status" => $dio['send_type'] == 1 ? 3 : 0,
  1767. "order_type" => 2,
  1768. "addtime" => date("Y-m-d H:i:s"),
  1769. "updatetime" => date("Y-m-d H:i:s")
  1770. ];
  1771. $cgin = Db::name("purchease_order")->insert($clll);
  1772. // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
  1773. if ($cgin == false) {
  1774. $stb = ["order_code"=>$cgd,"status"=> $clll['status'],"action_remark"=>'',"action_type"=>"create"];
  1775. ActionLog::logAdd($this->post['token'],$stb,"xsd", $clll['status'],$stb);
  1776. Db::rollback();
  1777. return error_show(1002, "咨询采购单创建商品失败");
  1778. }
  1779. if ($dio['send_type'] == 1) {
  1780. $addr = Db::name('order_addr')->where(["orderCode" => $dio['orderCode'], 'is_del' => 0])->select();
  1781. foreach ($addr as $value) {
  1782. $outCode = makeNo("CK");
  1783. $data = [
  1784. "wsm_code" => $wsm['wsm_code'],
  1785. "orderCode" => $dio['orderCode'],
  1786. "outCode" => $outCode,
  1787. "order_type" => $dio['order_type'],
  1788. "apply_id" => $rm,
  1789. "apply_name" => $ri,
  1790. "addrid" => $value['id'],
  1791. "post_name" => '',
  1792. "post_code" => '',
  1793. "post_fee" => '',
  1794. "sendtime" => date("Y-m-d H:i:s"),
  1795. "send_num" => $value['receipt_quantity'],
  1796. "check_num" => 0,
  1797. "error_num" => 0,
  1798. "status" => 0,
  1799. "addtime" => date("Y-m-d H:i:s"),
  1800. "updatetime" => date("Y-m-d H:i:s")
  1801. ];
  1802. $datainfo = Db::name('order_out')->insert($data);
  1803. if (!$datainfo) {
  1804. $sti = ["order_code"=>$dio['orderCode'],"status"=> 0,"action_remark"=>'',"action_type"=>"create"];
  1805. ActionLog::logAdd($this->post['token'],$sti,"xsd",0,$sti);
  1806. Db::rollback();
  1807. return error_show(1003, "创建失败");
  1808. }
  1809. }
  1810. $wsm_in_code = makeNo("IC");
  1811. $orin = [
  1812. "wsm_in_code" => $wsm_in_code,
  1813. "cgdNo" => $cgd,
  1814. "wsm_code" => $wsm['wsm_code'],
  1815. "wsm_reaper" => "",
  1816. "send_num" => $dio['good_num'],
  1817. "post_company" => '',
  1818. "post_code" => '',
  1819. "post_fee" => '',
  1820. "sendtime" => date("Y-m-d H:i:s"),
  1821. "apply_id" => $rm,
  1822. "apply_name" => $ri,
  1823. "wait_num" => 0,
  1824. "status" => 4,
  1825. "addtime" => date("Y-m-d H:i:s"),
  1826. "updatetime" => date("Y-m-d H:i:s")
  1827. ];
  1828. $win = Db::name("purchease_in")->insert($orin);
  1829. if (!$win){
  1830. $stv = ["order_code"=>$wsm_in_code,"status"=>4,"action_remark"=>'',"action_type"=>"create"];
  1831. ActionLog::logAdd($this->post['token'],$stv,"xsd",4,$stv);
  1832. Db::rollback();
  1833. return error_show(1003, "创建失败");
  1834. }
  1835. $good = Db::name("good_stock")->where(["wsm_code" => $wsm['wsm_code'], "good_type_code" => $zxinfo['cpNo'], "is_del" => 0])->find();
  1836. if (empty($good)) {
  1837. $good = [
  1838. "good_type_code" => $zxinfo['cpNo'],
  1839. "wsm_code" => $wsm['wsm_code'],
  1840. "usable_stock" => 0,
  1841. "wait_out_stock" => 0,
  1842. "total_stock" => 0,
  1843. "addtime" => date("Y-m-d H:i:s"),
  1844. "updatetime" => date("Y-m-d H:i:s"),
  1845. ];
  1846. }
  1847. $good['wait_out_stock'] += $dio['good_num'];
  1848. $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
  1849. $good['updatetime'] = date("Y-m-d H:i:s");
  1850. $upd = Db::name("good_stock")->save($good);
  1851. if (!$upd) {
  1852. $ste = ["order_code"=> $zxinfo['cpNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  1853. ActionLog::logAdd($this->post['token'],$ste,"xsd",0,$ste);
  1854. Db::rollback();
  1855. return error_show(1003, "创建失败");
  1856. }
  1857. }
  1858. }
  1859. }
  1860. Db::commit();
  1861. return error_show(0, "订单状态更新成功");
  1862. } catch (Exception $e) {
  1863. Db::rollback();
  1864. return error_show(1005, $e->getMessage());
  1865. }
  1866. }
  1867. public function fee()
  1868. {
  1869. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  1870. if ($id == "") {
  1871. return error_show(1002, "参数id不能为空");
  1872. }
  1873. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  1874. if (empty($etid)) {
  1875. return error_show(1002, "未找到数据");
  1876. }
  1877. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  1878. if ($vr == "") {
  1879. return error_show(1002, "参数order_addr不能为空");
  1880. }
  1881. Db::startTrans();
  1882. try {
  1883. $data = [
  1884. "id" => $id,
  1885. "status" => 2,
  1886. "is_del" => 0,
  1887. "updatetime" => date("Y-m-d H:i:s")
  1888. ];
  1889. $datainfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($data);
  1890. if ($datainfo) {
  1891. $stx = ["order_code"=> $etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',
  1892. "action_type"=>"edit"];
  1893. ActionLog::logAdd($this->post['token'],$stx,$etid['order_type'] == 2?"ZXQRD":"XSQRD",2,$data);
  1894. $order=["order_type"=>$etid['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$data['status']];
  1895. ProcessOrder::AddProcess($this->post['token'],$order);
  1896. foreach ($vr as $value) {
  1897. $tm = [];
  1898. $tm['id'] = $value['id'];
  1899. $tm['orderCode'] = $etid['orderCode'];
  1900. $tm['post_fee'] = $value['post_fee'];
  1901. $tm['updatetime'] = date("Y-m-d H:i:s");
  1902. $dn = Db::name('order_addr')->save($tm);
  1903. if ($dn == false) {
  1904. Db::rollback();
  1905. return error_show(1002, "更新失败");
  1906. }
  1907. }
  1908. Db::commit();
  1909. return error_show(0, "更新成功");
  1910. }
  1911. Db::rollback();
  1912. return error_show(1003, "更新失败");
  1913. } catch (Exception $e) {
  1914. Db::rollback();
  1915. return error_show(1005, $e->getMessage());
  1916. }
  1917. }
  1918. public function out()
  1919. {
  1920. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1921. $outCode = makeNo("CK");
  1922. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  1923. if ($orderCode == "") {
  1924. return error_show(1002, "参数orderCoder不能为空");
  1925. }
  1926. $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
  1927. if ($der == "") {
  1928. return error_show(1002, "未找到出库订单单号");
  1929. }
  1930. // $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  1931. // if ($wsm_code == "") {
  1932. // return error_show(1002, "参数wsm_code不能为空");
  1933. // }
  1934. // $wsm = Db::name('sale_info')->where(['wsm_code' => $wsm_code, 'orderCode' => $der['orderCode']])->find();
  1935. // if ($wsm == "") {
  1936. // return error_show(1002, "未找到仓库编码");
  1937. // }
  1938. $post_name = isset($this->post['post_name']) && $this->post['post_name'] !== "" ? trim($this->post['post_name']) : "";
  1939. if ($post_name == "") {
  1940. return error_show(1002, "物流公司不能为空");
  1941. }
  1942. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
  1943. if ($post_code == "") {
  1944. return error_show(1002, "物流单号不能为空");
  1945. }
  1946. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
  1947. if ($post_fee == "") {
  1948. return error_show(1002, "物流费不能为空");
  1949. }
  1950. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  1951. if ($send_num == "") {
  1952. return error_show(1002, "发货数量不能为空");
  1953. }
  1954. if ($send_num > $der['wsend_num']) {
  1955. return error_show(1002, "超出可发货数量");
  1956. }
  1957. $apply_id = GetUserInfo($token);
  1958. if (empty($apply_id) || $apply_id['code'] != 0) {
  1959. return error_show(1002, "申请人数据不存在");
  1960. }
  1961. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1962. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1963. $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
  1964. $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
  1965. if (empty($dr)) {
  1966. return error_show(1003, "收货人信息未找到");
  1967. }
  1968. if ($dr['orderCode'] !== $orderCode) {
  1969. return error_show(1002, "订单code不存在");
  1970. }
  1971. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  1972. // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
  1973. // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
  1974. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "1";
  1975. //$order_type = isset($this->post['order_type']) && $this->post['order_type'] !=="" ? $this->post['order_type'] :"1";
  1976. //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
  1977. Db::startTrans();
  1978. try {
  1979. $data = [
  1980. "wsm_code" => "",
  1981. "orderCode" => $orderCode,
  1982. "outCode" => $outCode,
  1983. "order_type" => $der['order_type'],
  1984. "apply_id" => $rm,
  1985. "apply_name" => $ri,
  1986. "addrid" => $dr['id'],
  1987. "post_name" => $post_name,
  1988. "post_code" => $post_code,
  1989. "post_fee" => $post_fee,
  1990. "sendtime" => $sendtime,
  1991. "send_num" => $send_num,
  1992. "check_num" => 0,
  1993. "error_num" => 0,
  1994. "status" => $status,
  1995. "addtime" => date("Y-m-d H:i:s"),
  1996. "updatetime" => date("Y-m-d H:i:s")
  1997. ];
  1998. $datainfo = Db::name('order_out')->insert($data,true);
  1999. if ($datainfo>0) {
  2000. $stx = ["order_code"=>$outCode,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
  2001. ActionLog::logAdd($this->post['token'],$stx,$der['order_type']==1?"CKD":'ZXCKD',$status,$data);
  2002. $order=["order_type"=>$der['order_type']==1?"CKD":'ZXCKD',"order_code"=>$outCode,"order_id"=>$datainfo,"order_status"=>$data['status']];
  2003. ProcessOrder::AddProcess($this->post['token'],$order);
  2004. if ($status == 1) {
  2005. $var = Db::name('sale_info')->where(['orderCode' => $orderCode, 'wsm_code' => $wsm_code])->find();
  2006. if ($var == "") {
  2007. return error_show(1002, "未找到数据");
  2008. }
  2009. // $send = Db::name("order_out")->where(["wsm_code" => $wsm_code, 'orderCode' => $orderCode])->sum
  2010. //("send_num");
  2011. $item =$der['status'];
  2012. $der['send_num'] += $send_num;
  2013. $der['wsend_num'] -= $send_num;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  2014. $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
  2015. $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
  2016. $der['updatetime'] = date("Y-m-d H:i:s");
  2017. $si = Db::name('sale')->save($der);
  2018. if ($si == false) {
  2019. Db::rollback();
  2020. return error_show(1003, "更新失败");
  2021. }
  2022. $stx = ["order_code"=>$orderCode,"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2023. ActionLog::logAdd($this->post['token'],$stx,$der['order_type'] == 2?"ZXQRD":"XSQRD",$der['status'],$der);
  2024. $order=["order_type"=>$der['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$orderCode,"order_id"=>$der['id'],"order_status"=>$data['status']];
  2025. ProcessOrder::AddProcess($this->post['token'],$order);
  2026. $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'], 'good_type_code' => $der['good_code']])->find();
  2027. if ($str == false) {
  2028. Db::rollback();
  2029. return error_show(1002, "商品数据未找到");
  2030. }
  2031. if ($send_num > $str['wait_out_stock']) {
  2032. Db::rollback();
  2033. return error_show(1002, "超出库存数量");
  2034. }
  2035. $str['wait_out_stock'] -= $send_num;
  2036. $str['intra_stock'] += $send_num;
  2037. $str['updatetime'] = date("Y-m-d H:i:s");
  2038. $stre = Db::name('good_stock')->save($str);
  2039. if ($stre == false) {
  2040. Db::rollback();
  2041. return error_show(1002, "状态更新失败");
  2042. }
  2043. $good_data[]= ["stock_id"=>$str['id'],"type"=>2,'stock'=>$send_num,"stock_name"=>"wait_out_stock"];
  2044. $good_data[]= ["stock_id"=>$str['id'],"type"=>1,'stock'=>$send_num,"stock_name"=>"intra_stock"];
  2045. GoodLog::LogAdd($this->post['token'],$good_data,$der['order_type'] == 2?"ZXQRD":"XSQRD");
  2046. }
  2047. Db::commit();
  2048. return error_show(0, "创建成功");
  2049. } else {
  2050. Db::rollback();
  2051. return error_show(1003, "创建失败");
  2052. }
  2053. } catch (Exception $e) {
  2054. Db::rollback();
  2055. return error_show(1005, $e->getMessage());
  2056. }
  2057. }
  2058. public function customer()
  2059. {
  2060. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  2061. if (empty($outCode)) {
  2062. return error_show(1002, "销售订单编号不能为空");
  2063. }
  2064. $codeinfo = Db::name('order_out')->where(['outCode' => $outCode])->find();
  2065. if ($codeinfo == "") {
  2066. return error_show(1003, "未找到订单数据");
  2067. }
  2068. // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  2069. // if($orderCode==""){
  2070. // return error_show(1002,"参数orderCoder不能为空");
  2071. // }
  2072. $dr = Db::name('sale')->where(['orderCode' => $codeinfo['orderCode']])->find();
  2073. if ($dr == "") {
  2074. return error_show(1002, "未找到销售订单");
  2075. }
  2076. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "";
  2077. if ($status == "") {
  2078. return error_show(10002, "状态不能为空");
  2079. }
  2080. Db::startTrans();
  2081. try {
  2082. $time = $codeinfo['status'];
  2083. $codeinfo['status'] = $status;
  2084. $codeinfo['updatetime'] = date("Y-m-d H:i:s");
  2085. $cust = Db::name('order_out')->save($codeinfo);
  2086. if ($cust) {
  2087. $stx = ["order_code"=>$outCode,"status"=>$time,"action_remark"=>'',"action_type"=>"status"];
  2088. ActionLog::logAdd($this->post['token'],$stx,$codeinfo['order_type'] == 2?"ZXCKD":"CKD",$codeinfo['status'],$codeinfo);
  2089. $order=["order_type"=>$codeinfo['order_type'] == 2?"ZXCKD":"CKD","order_code"=>$outCode,
  2090. "order_id"=>$codeinfo['id'],"order_status"=>$codeinfo['status']];
  2091. ProcessOrder::AddProcess($this->post['token'],$order);
  2092. if ($status == 1) {
  2093. $stokc =Db::name("good_stock")->where(['spuCode'=>$codeinfo['spuCode'],"wsm_code"=>$codeinfo['wsm_code'],
  2094. "is_del"=>0])->find();
  2095. if($stokc==false){
  2096. Db::rollback();
  2097. return error_show(1002, "未找库存到数据");
  2098. }else{
  2099. if ($codeinfo['send_num'] > $stokc['usable_stock']) {
  2100. Db::rollback();
  2101. return error_show(1002, "超出库存数量");
  2102. }
  2103. $stokc['wait_out_stock']+=$codeinfo['send_num'];
  2104. $stokc['usable_stock']-=$codeinfo['send_num'];
  2105. $stokc['updatetime']=date("Y-m-d H:i:s");
  2106. }
  2107. $stoc= Db::name("good_stock")->save($stokc);
  2108. if($stoc==false){
  2109. Db::rollback();
  2110. return error_show(1002, "库存更新失败");
  2111. }
  2112. // $send = Db::name("order_out")->where(["wsm_code" => $wsm_code, 'orderCode' => $orderCode])->sum
  2113. //("send_num");
  2114. $item =$dr['status'];
  2115. $dr['send_num'] +=$codeinfo['send_num'];
  2116. $dr['wsend_num'] -= $codeinfo['send_num'];//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  2117. $dr['send_status'] = $dr['send_num'] == 0 ? 1 : $dr['wsend_num'] == 0 ? 3 : 2;
  2118. $dr['status'] = $dr['send_num'] == 0 ? 3 : $dr['wsend_num'] == 0 ? 5 : 4;
  2119. $dr['updatetime'] = date("Y-m-d H:i:s");
  2120. $si = Db::name('sale')->save($dr);
  2121. if ($si == false) {
  2122. Db::rollback();
  2123. return error_show(1003, "更新失败");
  2124. }
  2125. $stx = ["order_code"=>$dr['orderCode'],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2126. ActionLog::logAdd($this->post['token'],$stx,$dr['order_type'] == 2?"ZXQRD":"XSQRD",$dr['status'],
  2127. $dr);
  2128. $order=["order_type"=>$dr['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dr['orderCode'],"order_id"=>$dr['id'],"order_status"=>$dr['status']];
  2129. ProcessOrder::AddProcess($this->post['token'],$order);
  2130. $good_data[]= ["stock_id"=>$stoc['id'],"type"=>1,'stock'=>$codeinfo['send_num'],"stock_name"=>"wait_out_stock"];
  2131. $good_data[]= ["stock_id"=>$stoc['id'],"type"=>2,'stock'=>$codeinfo['send_num'],"stock_name"=>"usable_stock"];
  2132. GoodLog::LogAdd($this->post['token'],$good_data,'CKD');
  2133. }
  2134. if ($status == 3) {
  2135. $var = Db::name('good_stock')->where(['wsm_code' => $codeinfo['wsm_code'], 'good_type_code' => $dr['good_code']])->find();
  2136. if ($var == false) {
  2137. Db::rollback();
  2138. return error_show(1002, "未找到商品数据");
  2139. }
  2140. if ($codeinfo['send_num'] > $var['intra_stock']) {
  2141. Db::rollback();
  2142. return error_show(1003, "超出在途库存数量");
  2143. }
  2144. $var['intra_stock'] -= $codeinfo['send_num'];
  2145. $var['updatetime'] = date("Y-m-d H:i:s");
  2146. $stre = Db::name('good_stock')->save($var);
  2147. $good_data[]= ["stock_id"=>$var['id'],"type"=>2,'stock'=>$codeinfo['send_num'],"stock_name"=>"intra_stock"];
  2148. GoodLog::LogAdd($this->post['token'],$good_data,$codeinfo['order_type'] == 2?"ZXCKD":"CKD");
  2149. if ($stre == false) {
  2150. Db::rollback();
  2151. return error_show(1002, "状态更新失败");
  2152. }
  2153. }
  2154. Db::commit();
  2155. return error_show(0, "出库订单更新成功");
  2156. } else {
  2157. Db::rollback();
  2158. return error_show(1003, "出库订单更新失败");
  2159. }
  2160. } catch (Exception $e) {
  2161. Db::rollback();
  2162. return error_show(1005, $e->getMessage());
  2163. }
  2164. }
  2165. public function difflist()
  2166. {
  2167. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2168. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2169. $where = [];
  2170. $cgdNo = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
  2171. if ($cgdNo != "") {
  2172. $where[] = ['a.orderCode', "like", "%$cgdNo%"];
  2173. }
  2174. $diffNo = isset($this->post['diffCode']) && $this->post['diffCode'] != "" ? trim($this->post['diffCode']) : "";
  2175. if ($diffNo != "") {
  2176. $where[] = ['a.diffCode', "like", "%$diffNo%"];
  2177. }
  2178. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  2179. if ($status !== "") {
  2180. $where[] = ['a.status', "=", $status];
  2181. }
  2182. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  2183. if ($start != "") {
  2184. $where[] = ["a.addtime", '>=', $start];
  2185. }
  2186. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  2187. if ($end != "") {
  2188. $where[] = ["a.addtime", '<=', $end];
  2189. }
  2190. // $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  2191. // if($apply_name!==""){
  2192. // $where[]=['a.apply_name',"like","%$apply_name%"];
  2193. // }
  2194. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  2195. if ($supplierNo != "") {
  2196. $supplier = Db::name("supplier")->where([['code', "like", "%$supplierNo%"]])->column('code');
  2197. // if(empty($supplier)){
  2198. // return error_show(1004,"未找到供应商信息");
  2199. // }
  2200. $wsmcode = Db::name("sale")->where([
  2201. "is_del" => 0, "supplierNo" => $supplier])->column("orderCode");
  2202. $where[] = ['a.orderCode', "in", $wsmcode];
  2203. }
  2204. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  2205. if($companyNo!=""){
  2206. $where[]=['c.customer_code',"like","%$companyNo%"];
  2207. }
  2208. $count = Db::name('sale_diff')->alias('a')
  2209. ->join("sale c", "c.orderCode=a.orderCode", "left")
  2210. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  2211. ->join("good b", "b.good_code=a.good_code", "left")
  2212. ->where($where)->count();
  2213. $total = ceil($count / $size);
  2214. $page = $page >= $total ? $total : $page;
  2215. //var_dump( Db::name('sale_diff')->getLastSql());
  2216. $list = Db::name('sale_diff')->alias('a')
  2217. ->join("sale c", "c.orderCode=a.orderCode", "left")
  2218. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  2219. ->join("good b", "b.good_code=a.good_kode", "left")
  2220. ->where($where)->page($page, $size)->field("a.*,b.cat_id,c.customer_code,v.companyName")
  2221. ->order("a.addtime desc")->select();
  2222. $data = [];
  2223. foreach ($list as $value) {
  2224. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2225. $wsm = Db::name("sale")->alias("a")->Join("supplier b", "a.supplierNo=b.code", "left")->where
  2226. (['a.orderCode' => $value['orderCode'], "a.is_del" => 0])->field("b.code,b.name")->find();
  2227. $value['supplierNo'] = isset($wsm['code']) ? $wsm['code'] : "";
  2228. $value['supplierName'] = isset($wsm['name']) ? $wsm['name'] : "";
  2229. $data[] = $value;
  2230. }
  2231. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  2232. }
  2233. /**
  2234. * @return \think\response\Json|void
  2235. * @throws \think\db\exception\DataNotFoundException
  2236. * @throws \think\db\exception\DbException
  2237. * @throws \think\db\exception\ModelNotFoundException
  2238. */
  2239. public function diffcheck()
  2240. {
  2241. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2242. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2243. if ($id === "") {
  2244. return error_show(1004, "参数id不能为空");
  2245. }
  2246. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  2247. if (empty($info)) {
  2248. return error_show(1004, "订单数据未找到");
  2249. }
  2250. $is_act = isset($this->post['is_act']) && $this->post['is_act'] !== "" ? intval($this->post['is_act']) : "";
  2251. if ($is_act === '') {
  2252. return error_show(1004, "参数is_act不能为空");
  2253. }
  2254. $customer_remark = isset($this->post['customer_remark']) && $this->post['customer_remark'] !== "" ? trim($this->post['customer_remark']) : "";
  2255. if ($customer_remark === '') {
  2256. return error_show(1004, "参数customer_remark不能为空");
  2257. }
  2258. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "2";
  2259. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  2260. $item = $info['status'];
  2261. $info['is_act'] = $is_act;
  2262. $info['customer_remark'] = $customer_remark;
  2263. $info['status'] = $status;
  2264. $info['remark'] = $remark;
  2265. $info['updatetime'] = date("Y-m-d H:i:s");
  2266. $up = Db::name("sale_diff")->save($info);
  2267. if ($up) {
  2268. $stx = ["order_code"=>$info["orderCode"],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2269. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  2270. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
  2271. ProcessOrder::AddProcess($this->post['token'],$order);
  2272. return app_show(0, "更新成功");
  2273. } else {
  2274. return error_show(1003, "更新失败");
  2275. }
  2276. }
  2277. /**
  2278. * @return \think\response\Json|void
  2279. * @throws \think\db\exception\DataNotFoundException
  2280. * @throws \think\db\exception\DbException
  2281. * @throws \think\db\exception\ModelNotFoundException
  2282. */
  2283. public function diffstatus()
  2284. {
  2285. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2286. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2287. if ($id === "") {
  2288. return error_show(1004, "参数id不能为空");
  2289. }
  2290. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  2291. if (empty($info)) {
  2292. return error_show(1004, "订单数据未找到");
  2293. }
  2294. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "3";
  2295. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  2296. $ite=$info['status'];
  2297. $info['status'] = $status;
  2298. $info['remark'] = $remark;
  2299. $info['updatetime'] = date("Y-m-d H:i:s");
  2300. $up = Db::name("sale_diff")->save($info);
  2301. if ($up) {
  2302. $stx = ["order_code"=>$info["orderCode"],"status"=>$ite,"action_remark"=>'',"action_type"=>"status"];
  2303. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  2304. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
  2305. ProcessOrder::AddProcess($this->post['token'],$order);
  2306. return app_show(0, "更新成功");
  2307. } else {
  2308. return error_show(1003, "更新失败");
  2309. }
  2310. }
  2311. /**
  2312. * @return \think\response\Json|void
  2313. * @throws \think\db\exception\DataNotFoundException
  2314. * @throws \think\db\exception\DbException
  2315. * @throws \think\db\exception\ModelNotFoundException
  2316. */
  2317. public function diffinfo()
  2318. {
  2319. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2320. if ($id === "") {
  2321. return error_show(1004, "参数id不能为空");
  2322. }
  2323. $info = Db::name('sale_diff')->alias('a')->join("good b", "b.good_code=a.good_kode", "left")->where
  2324. (["a.id" => $id])->field("a.*,b.cat_id")->find();
  2325. if (empty($info)) {
  2326. return error_show(1004, "订单数据未找到");
  2327. }
  2328. $info['can'] = isset($info['cat_id']) && $info['cat_id'] !== 0 ? made($info['cat_id']) : [];
  2329. return app_show(0, "获取成功", $info);
  2330. }
  2331. public function saleout(){
  2332. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  2333. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  2334. $where= [];
  2335. $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode'])
  2336. :"";
  2337. if($orderCode !==""){
  2338. $where[]=['a.orderCode',"like","%$orderCode%"];
  2339. }
  2340. $order_type=isset($this->post['order_type']) && $this->post['order_type'] !=="" ? trim($this->post['order_type'])
  2341. :"";
  2342. if($order_type !==""){
  2343. $where[]=['a.order_type',"=",$order_type];
  2344. }
  2345. $outCode=isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode'])
  2346. :"";
  2347. if($outCode !==""){
  2348. $where[]=['a.outCode',"like","%$outCode%"];
  2349. }
  2350. $apply_name=isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name'])
  2351. :"";
  2352. if($apply_name !==""){
  2353. $where[]=['a.apply_name',"like","%$apply_name%"];
  2354. }
  2355. $good_code=isset($this->post['good_code']) && $this->post['good_code'] !=="" ? trim($this->post['good_code'])
  2356. :"";
  2357. if($good_code !==""){
  2358. $where[]=['b.good_code',"like","%$good_code%"];
  2359. }
  2360. $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name'])
  2361. :"";
  2362. if($good_name !==""){
  2363. $where[]=['b.good_name',"like","%$good_name%"];
  2364. }
  2365. $status=isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']):"";
  2366. if($status !==""){
  2367. $where[]=['a.status',"=",$status];
  2368. }
  2369. $start = isset($this->post['start']) && $this->post['start'] !=="" ? $this->post['start'] :"";
  2370. if($start !=""){
  2371. $where[]= ["a.addtime",'>=',$start];
  2372. }
  2373. $end = isset($this->post['end']) && $this->post['end'] !=="" ? $this->post['end'] :"";
  2374. if($end !=""){
  2375. $where[]= ["a.addtime",'<=',$end];
  2376. }
  2377. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  2378. if($companyNo!=""){
  2379. $where[]=['b.customer_code',"like","%$companyNo%"];
  2380. }
  2381. $count = Db::name('order_out')->alias('a')
  2382. ->join("sale b", "b.orderCode=a.orderCode", "left")
  2383. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  2384. //->join("good n","n.good_code=b.good_code","left")
  2385. ->where($where)->count();
  2386. $total = ceil($count / $size);
  2387. $page = $page >= $total ? $total : $page;
  2388. $list = Db::name('order_out')->alias('a')->join("sale b", "b.orderCode=a.orderCode", "left")
  2389. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  2390. //->join("good n","n.good_code=b.good_code","left")
  2391. ->field("a.*,b.good_name,b.good_code,b.supplierNo,b.customer_code,v.companyName,b.origin_price,b.sale_price,b.total_price")
  2392. ->where($where)->order("addtime desc")->page($page, $size)->select();
  2393. $data=[];
  2394. foreach ($list as $value) {
  2395. $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  2396. ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  2397. $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
  2398. $good = Db::name("good_type")->alias("b")->join("good a", "a.good_code = b.good_code", "left")
  2399. ->where(["type_code" => $value['good_code']])->field('cat_id')->find();
  2400. $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  2401. $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  2402. $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  2403. $value['addr'] = isset($addr['addr']) ? $addr['addr'] : "";
  2404. $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  2405. $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  2406. $value['can'] = isset($good['cat_id']) && $good['cat_id'] != 0 ? made($good['cat_id']) : [];
  2407. $data[] = $value;
  2408. }
  2409. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  2410. }
  2411. public function outinfo()
  2412. {
  2413. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  2414. if ($outCode == "") {
  2415. return error_show(1002, "参数outcode不能为空");
  2416. }
  2417. $codeinfo = Db::name("order_out")->where(['outCode' => $outCode])->find();
  2418. if (empty($codeinfo)) {
  2419. return error_show(1002, "未找到出库数据");
  2420. }
  2421. $item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  2422. if($item['order_type']==3|| $item['order_type']==4){
  2423. // $good=Db::name("good_zixun")->where(["spuCode"=>$good_code])->find();
  2424. // if($good==false){
  2425. // return error_show(1004,"未找到商品数据");
  2426. // }
  2427. $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$item['good_code'],"is_del"=>0])->find();
  2428. if($goodinfo==false){
  2429. return error_show(1004,"未找到商品数据");
  2430. }
  2431. }else{
  2432. $goodinfo = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2433. ->where(['a.skuCode' =>$item['skuCode']])->find();
  2434. if ($goodinfo == false) {
  2435. return error_show(1002, "未找到商品数据");
  2436. }
  2437. }
  2438. $int = isset($goodinfo['cat_id']) && $goodinfo['cat_id'] != 0 ? made($goodinfo['cat_id']) : [];
  2439. // $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  2440. // ->where(["k.wsm_code" => $codeinfo['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  2441. $addr = Db::name("order_addr")->where(["id" => $codeinfo['addrid']])->find();
  2442. //$item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  2443. $codeinfo['good_name'] = isset($item['good_name']) ? $item['good_name'] : "";
  2444. $codeinfo['good_num'] = isset($item['good_num']) ? $item['good_num'] : "";
  2445. $codeinfo['good_code'] = isset($item['good_code']) ? $item['good_code'] : "";
  2446. $codeinfo['origin_price'] = isset($item['origin_price']) ? $item['origin_price'] : "";
  2447. $codeinfo['sale_price'] = isset($item['sale_price']) ? $item['sale_price'] : "";
  2448. $codeinfo['total_price'] = isset($item['total_price']) ? $item['total_price'] : "";
  2449. // $codeinfo['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  2450. // $codeinfo['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  2451. // $codeinfo['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  2452. $codeinfo['addr'] = GetAddr($addr['addr_code']);
  2453. $codeinfo['addr'] .= isset($addr['addr']) ? $addr['addr'] : "";
  2454. $codeinfo['addr_code'] = isset($addr['addr_code']) ? $addr['addr_code'] : "";
  2455. $codeinfo['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  2456. $codeinfo['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  2457. $codeinfo['can'] = $int;
  2458. return app_show(0, "获取成功", $codeinfo);
  2459. }
  2460. public function outadd(){
  2461. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2462. $outCode = makeNo("CK");
  2463. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  2464. if ($orderCode == "") {
  2465. return error_show(1002, "参数orderCoder不能为空");
  2466. }
  2467. $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
  2468. if ($der == "") {
  2469. return error_show(1002, "未找到出库订单单号");
  2470. }
  2471. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  2472. if ($send_num == "") {
  2473. return error_show(1002, "发货数量不能为空");
  2474. }
  2475. if ($send_num > $der['wsend_num']) {
  2476. return error_show(1002, "超出可发货数量");
  2477. }
  2478. $contactor = isset($this->post['contactor'])&&$this->post['contactor']!="" ? trim($this->post['contactor']):"";
  2479. if($contactor==""){
  2480. return error_show(1002, "参数contactor不能为空");
  2481. }
  2482. $mobile = isset($this->post['mobile'])&&$this->post['mobile']!="" ? trim($this->post['mobile']):"";
  2483. if($mobile==""){
  2484. return error_show(1002, "参数mobile不能为空");
  2485. }
  2486. $addr = isset($this->post['addr'])&&$this->post['addr']!="" ? trim($this->post['addr']):"";
  2487. if($addr==""){
  2488. return error_show(1002, "参数addr不能为空");
  2489. }
  2490. $addr_code = isset($this->post['addr_code'])&&$this->post['addr_code']!="" ? trim($this->post['addr_code']):"";
  2491. if($addr_code==""){
  2492. return error_show(1002, "参数addr_code不能为空");
  2493. }
  2494. $apply_id = GetUserInfo($token);
  2495. if (empty($apply_id) || $apply_id['code'] != 0) {
  2496. return error_show(1002, "申请人数据不存在");
  2497. }
  2498. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2499. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  2500. // $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
  2501. // $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
  2502. // if (empty($dr)) {
  2503. // return error_show(1003, "收货人信息未找到");
  2504. // }
  2505. // if ($dr['orderCode'] !== $orderCode) {
  2506. // return error_show(1002, "订单code不存在");
  2507. // }
  2508. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  2509. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  2510. ->select()->toArray();
  2511. if(empty($order)){
  2512. return error_show(1004,"未找到可以发货得采购单数据");
  2513. }
  2514. Db::startTrans();
  2515. try {
  2516. $addrlst =[
  2517. "orderCode"=>$orderCode,
  2518. "addr"=>$addr,
  2519. "addr_code"=>json_encode($addr_code),
  2520. "contactor"=>$contactor,
  2521. "mobile"=>$mobile,
  2522. "customer_code"=>$der['customer_code'],
  2523. "post_fee"=>$der['post_fee'],
  2524. "arrive_time"=>$sendtime,
  2525. "receipt_quantity"=>$send_num,
  2526. "is_del"=>0,
  2527. "addtime"=>date("Y-m-d H:i:s"),
  2528. "updatetime"=>date("Y-m-d H:i:s")
  2529. ];
  2530. $addrid = Db::name("order_addr")->insert($addrlst,true);
  2531. if($addrid>0){
  2532. $data = [
  2533. "wsm_code" => "",
  2534. "orderCode" => $orderCode,
  2535. "outCode" => $outCode,
  2536. "order_type" => $der['order_type'],
  2537. "apply_id" => $rm,
  2538. "apply_name" => $ri,
  2539. "addrid" => $addrid,
  2540. "post_name" => "",
  2541. "post_code" =>"",
  2542. "post_fee" => "",
  2543. "sendtime" => $sendtime,
  2544. "send_num" => $send_num,
  2545. "check_num" => 0,
  2546. "error_num" => 0,
  2547. "status" => 1,
  2548. "addtime" => date("Y-m-d H:i:s"),
  2549. "updatetime" => date("Y-m-d H:i:s")
  2550. ];
  2551. $datainfo = Db::name('order_out')->insert($data,true);
  2552. if($datainfo>0){
  2553. $num = $send_num;
  2554. foreach ($order as $val){
  2555. $tep=[];
  2556. $ornum=0;
  2557. if($val['wsend_num']>=$num){
  2558. $val['wsend_num']-=$num;
  2559. $val['send_num']+=$num;
  2560. $ornum =$num;
  2561. $num=0;
  2562. }else{
  2563. $num-=$val['wsend_num'];
  2564. $val['send_num']+=$val['wsend_num'];
  2565. $ornum =$val['wsend_num'];
  2566. $val['wsend_num']=0;
  2567. }
  2568. $or =Db::name("order_num")->save($val);
  2569. if($or==false){
  2570. Db::rollback();
  2571. return error_show(1002,"发货地址添加创建失败");
  2572. }
  2573. $tep=[
  2574. "cgdNo"=>$val['cgdNo'],
  2575. "outCode"=>$outCode,
  2576. "send_num"=>$ornum,
  2577. "status"=>1,
  2578. "addtime"=>date("Y-m-d H:i:s"),
  2579. "updatetime"=>date("Y-m-d H:i:s")
  2580. ];
  2581. $sen=Db::name("order_send")->save($tep);
  2582. if($sen==false){
  2583. Db::rollback();
  2584. return error_show(1002,"发货地址添加创建失败");
  2585. }
  2586. if($num==0){
  2587. break;
  2588. }
  2589. }
  2590. Db::commit();
  2591. return app_show(0,"出库单新建成功",["outCode"=>$outCode]);
  2592. }
  2593. }
  2594. Db::rollback();
  2595. return error_show(1004,"出库单新建失败");
  2596. } catch (Exception $e) {
  2597. Db::rollback();
  2598. return error_show(1005, $e->getMessage());
  2599. }
  2600. }
  2601. public function outSend(){
  2602. $outCode=isset($this->post['outCode'])&& $this->post['outCode']!=""? trim($this->post['outCode']):"";
  2603. if($outCode==""){
  2604. return error_show(1004,"参数outCode不能为空");
  2605. }
  2606. $outinfo = Db::name("order_out")->where(["outCode"=>$outCode])->find();
  2607. if($outinfo==false){
  2608. return error_show(1004,"发货数据未找到");
  2609. }
  2610. $post_name = isset($this->post['post_name']) &&$this->post['post_name']!="" ? trim($this->post['post_name']):"";
  2611. if($post_name==""){
  2612. return error_show(1004,"参数post_name不能为空");
  2613. }
  2614. $post_code = isset($this->post['post_code']) &&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
  2615. if($post_code==""){
  2616. return error_show(1004,"参数post_code不能为空");
  2617. }
  2618. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee']!="" ? floatval($this->post['post_fee']):"";
  2619. $outinfo['post_name'] = $post_name;
  2620. $outinfo['post_code'] = $post_code;
  2621. $outinfo['post_fee'] = $post_fee;
  2622. $outinfo['sendtime'] = date("Y-m-d H:i:s");
  2623. $outinfo['status'] = 2;
  2624. $outinfo['updatetime'] = date("Y-m-d H:i:s");
  2625. try{
  2626. $up =Db::name("order_out")->save($outinfo);
  2627. if($up){
  2628. $stokc =Db::name("good_stock")->where(['spuCode'=>$outinfo['spuCode'],"wsm_code"=>$outinfo['wsm_code'],
  2629. "is_del"=>0])->find();
  2630. if($stokc==false){
  2631. Db::rollback();
  2632. return error_show(1002, "未找库存到数据");
  2633. }else{
  2634. if ($outinfo['send_num'] > $stokc['wait_out_stock']) {
  2635. Db::rollback();
  2636. return error_show(1002, "超出库存数量");
  2637. }
  2638. $stokc['wait_out_stock']-=$outinfo['send_num'];
  2639. $stokc['intra_stock']+=$outinfo['send_num'];
  2640. $stokc['updatetime']=date("Y-m-d H:i:s");
  2641. }
  2642. $stoc= Db::name("good_stock")->save($stokc);
  2643. if($stoc==false){
  2644. Db::rollback();
  2645. return error_show(1002, "库存更新失败");
  2646. }
  2647. Db::commit();
  2648. return app_show(0,"发货成功");
  2649. }else{
  2650. Db::rollback();
  2651. return error_show(1004,"发货失败");
  2652. }
  2653. }catch (\Exception $e){
  2654. Db::rollback();
  2655. return error_show(1004,$e->getMessage());
  2656. }
  2657. }
  2658. public function RelaCgd($outinfo){
  2659. $der = Db::name('sale')->where(['orderCode' => $outinfo['orderCode']])->find();
  2660. if ($der == "") {
  2661. return false;
  2662. }
  2663. if($der['is_stock']==1){
  2664. $cgd = Db::name("order_bk")->where([["spuCode","=",$der['spuCode']],["is_del","=",0],["balance_num",">",0]])
  2665. ->select()->toArray();
  2666. if(empty($cgd)){
  2667. return false;
  2668. }
  2669. $send =$outinfo['send_num'];
  2670. $outsend=[];
  2671. foreach ($cgd as $value){
  2672. $temp=[];
  2673. if($value['balance_num']>=$send){
  2674. $value['balance_num']-=$send;
  2675. $value['merge_num']+=$send;
  2676. $send=0;
  2677. $temp['send_num'] =$send;
  2678. }else{
  2679. $value['balance_num'] =0;
  2680. $value['merge_num']+=$value['balance_num'];
  2681. $send -= $value['balance_num'];
  2682. $temp['send_num'] =$value['balance_num'];
  2683. }
  2684. $value['status'] = $value['balance_num']==0 ?2:$value['merge_num']==0?0:1 ;
  2685. $value['updatetime'] = date("Y-m-d H:i:s");
  2686. $bk = Db::name("order_bk")->save($value);
  2687. if($bk==false){
  2688. return false;
  2689. }
  2690. $temp['cgdNo'] = $value['cgdNo'];
  2691. $temp['outCode'] = $outinfo['outCode'];
  2692. $temp['status'] = 1;
  2693. $temp['addtime']=date("Y-m-d H:i:s");
  2694. $temp['updatetime']=date("Y-m-d H:i:s");
  2695. $outsend[]=$temp;
  2696. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"cgdNo"=>$value['cgdNo'],"spuCode"=>$der['spuCode'],"status"=>1])->find();
  2697. if($order==false){
  2698. $order=[
  2699. "orderCode"=>$der['orderCode'],
  2700. "cgdNo"=>$value['cgdNo'],
  2701. "spuCode"=>$der['spuCode'],
  2702. "good_num"=>$der['good_num'],
  2703. "wsend_num"=>$der['good_num']-$temp['send_num'],
  2704. "send_num"=>$temp['send_num'],
  2705. "status"=>1,
  2706. "source"=>1
  2707. ];
  2708. }else{
  2709. $order['wsend_num']-=$temp['send_num'];
  2710. $order['send_num']+=$temp['send_num'];
  2711. }
  2712. if($order['wsend_num']<0){
  2713. return false;
  2714. }
  2715. $up =Db::name("order_num")->save($order);
  2716. if($up==false){
  2717. return false;
  2718. }
  2719. if($send==0){
  2720. break;
  2721. }
  2722. }
  2723. if(empty($temp)){
  2724. return false;
  2725. }
  2726. $insert = Db::name("order_send")->insertAll($outsend);
  2727. if($insert){
  2728. return true;
  2729. }else{
  2730. return false;
  2731. }
  2732. }else{
  2733. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"spuCode"=>$der['spuCode'],
  2734. "status"=>1])->find();
  2735. if($order==false){
  2736. return false;
  2737. }else{
  2738. if($outinfo['send_num']> $order['wsend_num']){
  2739. return false;
  2740. }
  2741. $order['wsend_num']-=$outinfo['send_num'];
  2742. $order['send_num']+=$outinfo['send_num'];
  2743. if($order['wsend_num']<0){
  2744. return false;
  2745. }
  2746. $up =Db::name("order_num")->save($order);
  2747. if($up==false){
  2748. return false;
  2749. }
  2750. $temp=[];
  2751. $temp['cgdNo'] = $order['cgdNo'];
  2752. $temp['outCode'] = $outinfo['outCode'];
  2753. $temp['send_num'] =$outinfo['send_num'];
  2754. $temp['status'] = 1;
  2755. $temp['addtime']=date("Y-m-d H:i:s");
  2756. $temp['updatetime']=date("Y-m-d H:i:s");
  2757. $insert = Db::name("order_send")->insert($temp);
  2758. if($insert){
  2759. return true;
  2760. }else{
  2761. return false;
  2762. }
  2763. }
  2764. }
  2765. }
  2766. public function addother(){
  2767. $orderCode =isset($this->post['orderCode']) && $this->post['orderCode']!=""?trim($this->post['orderCode']):"";
  2768. if($orderCode==""){
  2769. return error_show(1004,"参数orderCode不能为空");
  2770. }
  2771. $order =Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->find();
  2772. if($order==false){
  2773. return error_show(1004,"未找到订单数据");
  2774. }
  2775. $paytime =isset($this->post['paytime'])&&$this->post['paytime']!=""? $this->post['paytime']:"";
  2776. $workNo =isset($this->post['workNo'])&&$this->post['workNo']!=""? trim($this->post['workNo']):"";
  2777. $platform_order =isset($this->post['platform_order'])&&$this->post['platform_order']!=""? trim($this->post['platform_order']):"";
  2778. $paytime==""?"":$order['paytime']=$paytime;
  2779. $order['workNo']=$workNo;
  2780. $order['platform_order']=$platform_order;
  2781. $order['updatetime']=date("Y-m-d H:i:s");
  2782. $sa=Db::name("sale")->save($order);
  2783. if($sa){
  2784. return app_show(0,"更新成功");
  2785. }else{
  2786. return error_show(1004,"更新失败");
  2787. }
  2788. }
  2789. public function getPrice(){
  2790. $skuCode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
  2791. if($skuCode===""){
  2792. return error_show(1003,"参数skuCode不能为空");
  2793. }
  2794. $is_activity=isset($this->post['is_activity'])&&$this->post['is_activity']!==""?intval($this->post['is_activity'])
  2795. :"";
  2796. if($is_activity===""){
  2797. return error_show(1003,"参数is_activity不能为空");
  2798. }
  2799. $sale_num=isset($this->post['sale_num'])&&$this->post['sale_num']!==""?intval($this->post['sale_num']):"";
  2800. if($sale_num===""){
  2801. return error_show(1003,"参数sale_num不能为空");
  2802. }
  2803. $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2804. ->where(['a.skuCode' =>$skuCode])->find();
  2805. if ($ct == false) {
  2806. return error_show(1002, "未找到商品数据");
  2807. }
  2808. $origin = Db::name("good_nake")->where([["spuCode","=",$ct['spuCode']],["min_num","<=", $sale_num],["is_del","=",
  2809. 0]])->order("min_num desc")->find();
  2810. if($origin==false){
  2811. $origin = Db::name("good_nake")->where([["spuCode","=",$ct['spuCode']],["is_del","=",
  2812. 0]])->order("min_num asc")->find();
  2813. return error_show(1003,"不满足成本最低阶梯数量{$origin['min_num']}");
  2814. }
  2815. $stock=0;
  2816. if($ct['is_stock']==1){
  2817. $good_stock =Db::name("good_stock")->where(["spuCode"=>$ct['spuCode'],"is_del"=>0])->find();
  2818. $stock= isset($good_stock['usable_stock'])?$good_stock['usable_stock']:"0";
  2819. }
  2820. if($is_activity==1){
  2821. $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b","a.activity_code=b.activity_code")
  2822. ->where(["a.skuCode"=>$skuCode,"a.is_del"=>0,"a.status"=>1,"b.status"=>6,"b.is_del"=>0])->find();
  2823. if($act==false){
  2824. return error_show(1003,"未找到相关活动价");
  2825. }
  2826. if($act['moq_num']>$sale_num){
  2827. return error_show(1003,"商品不满足活动价起订量{$act['moq_num']}");
  2828. }
  2829. if($act['activity_stock']<$sale_num){
  2830. return error_show(1003,"商品活动库存剩余{$act['activity_stock']}");
  2831. }
  2832. return app_show(0,"获取成功",['sale_price'=>$act['activity_price'],"stock"=>$act['activity_stock']]);
  2833. }else{
  2834. $good = Db::name("good_ladder")->where(["skuCode"=>$skuCode,"is_del"=>0,"status"=>1])->order("min_num desc")
  2835. ->select()->toArray();
  2836. if(empty($good)){
  2837. return error_show(1003,"未找到相关阶梯价格");
  2838. }
  2839. $lastnum=0;
  2840. $lastprice=0;
  2841. foreach ($good as $value){
  2842. if($value['min_num']>$sale_num){
  2843. $lastnum=$value['min_num'];
  2844. $lastprice=0;
  2845. continue;
  2846. }else{
  2847. $lastnum=0;
  2848. $lastprice=$value['sale_price'];
  2849. break;
  2850. }
  2851. }
  2852. if($lastnum==0){
  2853. return app_show(0,"获取成功",['sale_price'=>$lastprice,"stock"=>$stock]);
  2854. }else{
  2855. return error_show(1003,"商品不满足起订量{$lastnum}");
  2856. }
  2857. }
  2858. }
  2859. public function saleuse(){
  2860. $orderCode= isset($this->post['orderCode'])&&!empty($this->post['orderCode'])?$this->post['orderCode']:"";
  2861. if($orderCode==""){
  2862. return error_show(1003,"参数orderCode不能为空");
  2863. }
  2864. $order= Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->select()->toArray();
  2865. if(empty($order)){
  2866. return error_show(1003,"订单数据未找到");
  2867. }
  2868. $useid= isset($this->post['useid'])&&$this->post['useid']!=""?intval($this->post['useid']):"";
  2869. if($useid==""){
  2870. return error_show(1003,"参数useid不能为空");
  2871. }
  2872. $use =Db::name("order_use")->where(["id"=>$useid,"is_del"=>0])->find();
  2873. if($use==false){
  2874. return error_show(1003,"用途数据未找到");
  2875. }
  2876. $order['use_order'] = $useid;
  2877. $order['updatetime'] = date("Y-m-d H:i:s");
  2878. $up=Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->update($order);
  2879. if($up>0){
  2880. return app_show(0,"更新成功");
  2881. }else{
  2882. return error_show(1003,"更新失败");
  2883. }
  2884. }
  2885. }