Reorder.php 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\GoodLog;
  4. use app\admin\model\GoodStockInfo;use app\admin\model\ProcessOrder;
  5. use think\facade\Db;
  6. use think\App;
  7. use app\admin\model\ActionLog;
  8. //销售单退货
  9. class Reorder extends Base
  10. {
  11. public function __construct(App $app)
  12. {
  13. parent::__construct($app);
  14. }
  15. public function create(){
  16. $ordeCode = isset($this->post['orderCode']) &&$this->post['orderCode']!=''?trim($this->post['orderCode']) :"";
  17. if($ordeCode==''){
  18. return error_show(1004,"参数orderCode 不能为空");
  19. }
  20. $order= Db::name("sale")->where(["orderCode"=>$ordeCode,"is_del"=>0])->find();
  21. if(empty($order)){
  22. return error_show(1005,"未找到订单数据");
  23. }
  24. $retrun =Db::name("sale_return")->where([["orderCode","=",$ordeCode],["is_del","=",0],["status","<",4]])
  25. ->count();
  26. if($retrun>0){
  27. return error_show(1005,"存在未完成退货订单数据");
  28. }
  29. if($order['order_type']==3){
  30. $goon = Db::name("good_zixun")->where(["spuCode"=>$order['good_code'],"is_del"=>0])->find();
  31. }else {
  32. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  33. ->where(['a.skuCode' => $order['skuCode']])->field("b.creater,b.createrid,b.supplierNo")->find();
  34. }
  35. if($goon==false){
  36. return error_show(1005,"未找到商品数据");
  37. }
  38. $supplier =Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
  39. if($supplier==false){
  40. return error_show(1005,"未找到商品供应商数据");
  41. }
  42. $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
  43. if($errorCode==''){
  44. return error_show(1004,"参数errorCode 不能为空");
  45. }
  46. $error =Db::name('result_info')->where(["result_code"=>$errorCode,"is_del"=>0])->find();
  47. if(empty($error)){
  48. return error_show(1005,"未找到退货原因数据");
  49. }
  50. $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
  51. $thnum =isset($this->post['thnum']) &&$this->post['thnum']!=''?intval($this->post['thnum']) :"";
  52. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  53. if($token==''){
  54. return error_show(105,"参数token不能为空");
  55. }
  56. $user =GetUserInfo($token);
  57. if(empty($user)||$user['code']!=0){
  58. return error_show(1002,"申请人数据不存在");
  59. }
  60. $is_addr=0;
  61. $rm= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  62. $ri= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  63. $returnadr =isset($this->post['returnAddr'])&& !empty($this->post['returnAddr']) ? $this->post['returnAddr']:"";
  64. if($returnadr!=''){
  65. $thnum=array_sum(array_column($returnadr,"return_num"));
  66. $is_addr=1;
  67. }
  68. $returnCode=makeNo("RN");
  69. Db::startTrans();
  70. try{
  71. $in = [
  72. "returnCode"=>$returnCode,
  73. "orderCode"=>$ordeCode,
  74. "good_code"=>$order['good_code'],
  75. "good_name"=>$order['good_name'],
  76. "apply_id"=>$rm,
  77. "apply_name"=>$ri,
  78. "cgderid"=>$goon['createrid'],
  79. "cgder"=>$goon['creater'],
  80. "person"=>$supplier['person']??'',
  81. "person_id"=>$supplier['personid']??0,
  82. "error_code"=>$errorCode,
  83. "num"=>$thnum,
  84. "total_fee"=>round($order['sale_price']*$thnum,2),
  85. "good_price"=>$order['sale_price'],
  86. "platform_id"=>$order['platform_id'],
  87. "remark"=>$remark,
  88. "order_type"=>$order['order_type'],
  89. "is_addr"=>$is_addr,
  90. "status"=>$order['is_stock']==1?4:1,
  91. "is_del"=>0,
  92. "addtime"=>date("Y-m-d H:i:s"),
  93. "updatetime"=>date("Y-m-d H:i:s")
  94. ];
  95. $create = Db::name("sale_return")->insert($in,true);
  96. if($create>0){
  97. $stn = ["order_code"=>$returnCode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  98. ActionLog::logAdd($this->post['token'],$stn,"XSTHD",$in['status'],$in);
  99. $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>$in['status'],"order_type"=>'XSTHD',"before_status"=>0,'holder_id'=>$in['apply_id']];
  100. ProcessOrder::AddProcess($this->post['token'],$process);
  101. //维护台账信息
  102. Db::execute("UPDATE `wsm_standing_book` SET `returnGoodCode`=CONCAT(IFNULL(`returnGoodCode`,''),',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `orderCode`='{$ordeCode}'");
  103. if($returnadr!=""){
  104. $inf=[];
  105. foreach ($returnadr as $val){
  106. if ($val['return_num'] == 0) continue;//当退货数量为0时,跳过
  107. $temp=[];
  108. $addrinfo =Db::name("order_addr")->where(['id'=>$val['id'],"orderCode"=>$ordeCode])->find();
  109. if($addrinfo==false){
  110. Db::rollback();
  111. return error_show(1005,"地址信息未找到");
  112. }
  113. $send =Db::name('order_out')->where([["addrid","=",$val['id']]])->find();
  114. if($send['status']>=2){
  115. Db::rollback();
  116. return error_show(1005,"地址已发货");
  117. }
  118. if($order['is_stock']==1){
  119. if ($addrinfo['receipt_quantity'] < $val['return_num']) {
  120. Db::rollback();
  121. return error_show(1004, "地址发货数量不足");
  122. }
  123. $addrinfo['receipt_quantity'] -= $val['return_num'];
  124. $addrinfo['is_del'] = $addrinfo['receipt_quantity'] <= 0 ? 1 : 0;
  125. $addrinfo['updatetime'] = date("Y-m-d H:i:s");
  126. $addrup = Db::name("order_addr")->save($addrinfo);
  127. if ($addrup == false) {
  128. Db::rollback();
  129. return error_show(1004, "地址发货数量更新失败");
  130. }
  131. $out = Db::name("order_out")->where(["addrid"=>$val['id']])->find();
  132. if ($out == false) {
  133. Db::rollback();
  134. return error_show(1004, "地址发货单数据未找到");
  135. }
  136. // if ($send!=false) {
  137. if ($out['status'] >= 2) {
  138. Db::rollback();
  139. return error_show(1004, "地址发货单已发货");
  140. }
  141. if ($out['send_num'] < $val['return_num']) {
  142. Db::rollback();
  143. return error_show(1004, "地址发货单发货数量不足");
  144. }
  145. $out['send_num'] -= $val['return_num'];
  146. $out['is_del'] = $out['send_num']==0?1:0;
  147. $out['updatetime'] = date("Y-m-d H:i:s");
  148. $outup = Db::name("order_out")->save($out);
  149. if ($outup == false) {
  150. Db::rollback();
  151. return error_show(1004, "地址发货单更新失败");
  152. }
  153. // $ordersend = Db::name("order_send")->where(["outCode" => $out['outCode']])->find();
  154. // if ($ordersend['send_num'] < $val['return_num']) {
  155. // Db::rollback();
  156. // return error_show(1004, "发货单发货数量不足");
  157. // }
  158. // $ordersend['send_num'] -= $val['return_num'];
  159. // $ordersend['status'] = $ordersend['send_num'] <= 0 ? 0 : 1;
  160. // $ordersend['updatetime'] = date("Y-m-d H:i:s");
  161. // $sendip = Db::name("order_send")->save($ordersend);
  162. // if ($sendip == false) {
  163. // Db::rollback();
  164. // return error_show(1004, "发货单更新失败");
  165. // }
  166. // }
  167. }
  168. $temp['returnCode']=$returnCode;
  169. $temp['orderCode']=$ordeCode;
  170. $temp['outCode']=isset($send['outCode'])?$send['outCode']:"";
  171. $temp['addrid']=$val['id'];
  172. $temp['send_num']=$addrinfo['receipt_quantity'];
  173. $temp['return_num']=$val['return_num'];
  174. $temp['is_del']=0;
  175. $temp['addtime']=date("Y-m-d H:i:s");
  176. $temp['updatetime']=date("Y-m-d H:i:s");
  177. $inf[]=$temp;
  178. }
  179. $inadd=Db::name("sale_returnaddr")->insertAll($inf);
  180. if($inadd==0){
  181. Db::rollback();
  182. return error_show(1005,"退货单新建失败");
  183. }
  184. }
  185. if($order['is_stock']==1){
  186. if ($order['wsend_num'] < $thnum) {
  187. Db::rollback();
  188. return error_show(1004, "销售单未发货数量不足退货");
  189. }
  190. $lor=$order['status'] ;
  191. $order['wsend_num'] -= $thnum;
  192. $order['send_num'] += $thnum;
  193. $order['status'] = $order['wsend_num']==0?2:($order['send_num']==0?0:1);
  194. $order['send_status'] =$order['wsend_num']==0?3:($order['send_num']==0?1:2);
  195. $order['th_num'] += $thnum;
  196. if($order['th_num']==$order['send_num']&& $order['wsend_num']==0){
  197. $order['status']=3;
  198. }
  199. $order['th_fee'] += round($thnum * $order['sale_price'], 2);
  200. $order['updatetime'] = date("Y-m-d H:i:s");
  201. $uap = Db::name("sale")->save($order);
  202. if ($uap == false) {
  203. Db::rollback();
  204. return error_show(1005, '销售单订单更新失败');
  205. }
  206. ActionLog::logAdd($this->post['token'], [
  207. "order_code" => $order["orderCode"],//出库单号
  208. "status" => $lor,//这里的status是之前的值
  209. "action_remark" => '',//备注
  210. "action_type" => "status"//新建create,编辑edit,更改状态status
  211. ], "XSQRD", $order['status'], $order);
  212. ProcessOrder::AddProcess($this->post['token'], [
  213. "order_type" => 'XSQRD',
  214. "order_code" =>$order["orderCode"],//出库单号
  215. "order_id" => $order["id"],
  216. "order_status" =>$order['status'],"before_status"=>$lor
  217. ]);
  218. // $ordernum = Db::name("order_num")->where(['orderCode' => $ordeCode])->find();
  219. // if ($ordernum == false) {
  220. // Db::rollback();
  221. // return error_show(1005, '未找到关联采购单');
  222. // }
  223. // $ordernum['send_num'] -= $thnum;
  224. // $orderup = Db::name("order_num")->save($ordernum);
  225. // if ($orderup == false) {
  226. // Db::rollback();
  227. // return error_show(1005, '关联数据更新失败');
  228. // }
  229. // $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
  230. // if ($cgd == false) {
  231. // Db::rollback();
  232. // return error_show(1005, '未找到采购单数据');
  233. // }
  234. // $cgd['th_fee'] += round($cgd['good_price'] * $thnum, 2);
  235. // $cgd['th_num'] += $thnum;
  236. // $cgd['updatetime'] = date("Y-m-d H:i:s");
  237. // $cgdup = Db::name("purchease_order")->save($cgd);
  238. // if ($cgdup == false) {
  239. // Db::rollback();
  240. // return error_show(1005, '采购单数据更新失败');
  241. // }
  242. // if ($cgd['bkcode'] != "") {
  243. // $bk = Db::name("purchease_order")->where(["bkcode" => $cgd['bkcode'], "order_type" => 1, "order_source" =>0, "is_del" => 0])
  244. // ->find();
  245. // if ($bk == false) {
  246. // Db::rollback();
  247. // return error_show(1005, '未找到备库单数据');
  248. // }
  249. // $orderbk = Db::name("order_bk")->where(['cgdNo' => $bk['cgdNo'], "is_del" => 0])->find();
  250. // if ($orderbk == false) {
  251. // Db::rollback();
  252. // return error_show(1005, '备库单未完全入库');
  253. // }
  254. // $merge_num = Db::name("purchease_order")->where(["bkcode" => $bk['bkcode'], "order_type" =>
  255. // 1, "is_del" => 0])->where("order_source","<>",0)->field("sum(send_num)-sum(th_num) as num")
  256. // ->find();
  257. //
  258. // $orderbk['balance_num'] = $orderbk['total_num'] - $merge_num['num'];
  259. // $orderbk['merge_num'] = $merge_num['num'];
  260. // $orderbk['updatetime'] = date("Y-m-d H:i:s");
  261. // $orderbkup = Db::name("order_bk")->save($orderbk);
  262. // if ($orderbkup == false) {
  263. // Db::rollback();
  264. // return error_show(1005, '备库单库存数据释放失败');
  265. // }
  266. // }
  267. $saleinfo=Db::name("sale_info")->where([["orderCode","=",$ordeCode],["num",">",0]])->select()
  268. ->toArray();
  269. if(empty($saleinfo)) {
  270. Db::rollback();
  271. return error_show(1005, '商品批次数据未找到');
  272. }
  273. $tempnum =$thnum;
  274. foreach ( $saleinfo as $va){
  275. if($tempnum ==0) break;
  276. $stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'id' => $va['stockid']])
  277. ->find();
  278. if($stock==false) {
  279. Db::rollback();
  280. return error_show(1005, '商品库存数据未找到');
  281. }
  282. if($va['num']>=$tempnum) {
  283. $tnm = $tempnum;
  284. $va['num']-= $tempnum;
  285. $tempnum=0;
  286. }else{
  287. $tnm = $va['num'];
  288. $tempnum -=$va['num'];
  289. $va['num'] =0;
  290. }
  291. $stock['usable_stock']+=$tnm;
  292. $stock['wait_out_stock'] -=$tnm;
  293. $stock['updatetime'] = date("Y-m-d H:i:s");
  294. $st_up = Db::name("good_stock")->save($stock);
  295. if ($st_up == false) {
  296. return error_show(1005, '可售商品入库失败');
  297. }
  298. $ps = GoodStockInfo::AddBn($va['stockid'],$va['bnCode'],$tnm);
  299. if ($ps == false) {
  300. return error_show(1005, '商品批次退货入库失败');
  301. }
  302. $ret = GoodStockInfo::ReturnBn($returnCode,$va['id'],$tnm);
  303. if ($ret == false) {
  304. return error_show(1005, '商品批次退货入库失败');
  305. }
  306. $va['updatetime']=date("Y-m-d H:i:s");
  307. $sal= Db::name("sale_info")->save($va);
  308. if ($sal == false) {
  309. return error_show(1005, '商品批次退货入库失败');
  310. }
  311. $good_data[]= ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 1, 'stock' => $thnum, "stock_name" => "usable_stock"];
  312. $good_data[]= ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 2, 'stock' => $thnum, "stock_name" => "wait_out_stock"];
  313. GoodLog::LogAdd($this->post['token'], $good_data, 'XSTHD');
  314. }
  315. $data=[
  316. "orderCode"=>$ordeCode,
  317. "th_type"=>1,
  318. "th_num"=>$thnum,
  319. "th_fee"=>round($order['sale_price']*$thnum,2),
  320. "thCode"=>$returnCode,
  321. "spuCode"=>$order['good_code'],
  322. "good_name"=>$order['good_name'],
  323. "cat_id"=>$order['cat_id'],
  324. "apply_id"=>$rm,
  325. "apply_name"=>$ri,
  326. "addtime"=>date("Y-m-d H:i:s"),
  327. "status"=>1,
  328. "is_del"=>0
  329. ];
  330. $inse=Db::name("th_data")->insert($data);
  331. if($inse==false){
  332. Db::rollback();
  333. return error_show(1004,"退货单更新失败");
  334. }
  335. }
  336. Db::commit();
  337. return app_show(0,"退货单新建成功",["returnCode"=>$returnCode]);
  338. }
  339. Db::rollback();
  340. return error_show(1005,"退货单新建失败");
  341. }catch (\Exception $e){
  342. Db::rollback();
  343. return error_show(1005,$e->getMessage());
  344. }
  345. }
  346. public function list(){
  347. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  348. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  349. $where =[['sr.is_del',"=",0]];
  350. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  351. if($bkcode!=""){
  352. $where[]=['sr.returnCode',"like", "%{$bkcode}%"];
  353. }
  354. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  355. if($status!==""){
  356. $where[]=['sr.status',"=", $status];
  357. }
  358. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode'])
  359. :"";
  360. if($orderCode!=""){
  361. $where[]=['sr.orderCode',"like", "%{$orderCode}%"];
  362. }
  363. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name'])
  364. :"";
  365. if($apply_name!=""){
  366. $where[]=['sr.apply_name',"like", "%{$apply_name}%"];
  367. }
  368. $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
  369. if($start!==""){
  370. $where[]=['sr.addtime',">=", $start.' 00:00:00'];
  371. }
  372. $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
  373. if($end!==""){
  374. $where[]=['sr.addtime',"<=", $end.' 23:59:59'];
  375. }
  376. $role=$this->checkRole();
  377. $condition='';
  378. if(!empty($role['write']) && $this->uid!=""){
  379. // $where[]=["sr.apply_id","in",$role['write']];
  380. $condition .="sr.cgderid = {$this->uid} or sr.apply_id in (".implode(',',$role['write']).") or sr.person_id={$this->uid}";
  381. }
  382. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  383. if ($company_name !== "") $where[] = ["sr.apply_id", 'in', get_company_item_user_by_name($company_name)];
  384. $count=Db::name("sale_return")->alias('sr')->where($where)->where($condition)->count();
  385. $total = ceil($count/$size);
  386. $page = $total>=$page ? $page :$total;
  387. $list = Db::name("sale_return")
  388. ->alias('sr')
  389. ->field('sr.*,u.itemid')
  390. ->leftJoin("depart_user u", "u.uid=sr.apply_id AND u.is_del=0")
  391. ->where($where)
  392. ->where($condition)
  393. ->order("addtime desc")
  394. ->page($page,$size)
  395. ->cursor();
  396. // echo Db::name("sale_return")->getLastSql();
  397. $data=[];
  398. foreach ($list as $value){
  399. $value['error_msg']='';
  400. if($value['error_code']!=''){
  401. $error = Db::name("result_info")->where(["result_code"=>$value['error_code']])->find();
  402. $value['error_msg']= isset($error['result'])?$error['result']:"";
  403. }
  404. $order =Db::name("sale")->where(["orderCode"=>$value['orderCode'],"is_del"=>0])->find();
  405. $value['sale_price'] = isset($order['sale_price']) ?$order['sale_price']:0;
  406. $value['return_total'] =$value['sale_price']*$value['num'] ;
  407. $value['total_num'] =$order['good_num'] ;
  408. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  409. $data[]=$value ;
  410. }
  411. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  412. }
  413. public function info(){
  414. $code = isset($this->post['returnCode']) && $this->post['returnCode'] !=="" ? trim($this->post['returnCode'])
  415. :"";
  416. if($code==""){
  417. return error_show(1004,"参数returnCode不能为空");
  418. }
  419. $info = Db::name("sale_return")->where(["returnCode"=>$code,"is_del"=>0])->find();
  420. if(empty($info)){
  421. return error_show(1004,"未找到退货数据");
  422. }
  423. $orderinfo = Db::name("sale")->where(["orderCode"=>$info["orderCode"]])->find();
  424. if($orderinfo['order_type']==3){
  425. $goon = Db::name("good_zixun")->where(["spuCode"=>$orderinfo['good_code'],"is_del"=>0])->find();
  426. }else {
  427. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  428. ->where(['a.skuCode' => $orderinfo['skuCode']])->find();
  429. }
  430. if ($goon==false) {
  431. return error_show(1003, "未找到商品数据");
  432. }
  433. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  434. $info['is_stock']=isset($goon['is_stock'])?$goon['is_stock']:'0';
  435. $info['good_code'] = isset($orderinfo['good_code'])?$orderinfo['good_code']:'';
  436. $info['send_type'] = isset($orderinfo['send_type'])?$orderinfo['send_type']:'';
  437. $info['skuCode'] = isset($orderinfo['skuCode'])?$orderinfo['skuCode']:'';
  438. $info['good_name'] = isset($orderinfo['good_name'])?$orderinfo['good_name']:'';
  439. $info['good_num'] = isset($orderinfo['good_num'])?$orderinfo['good_num']:'';
  440. $info['sale_price'] = isset($orderinfo['sale_price'])?$orderinfo['sale_price']:'0';
  441. $info['origin_price'] = isset($orderinfo['origin_price'])?$orderinfo['origin_price']:'0';
  442. $info['return_total'] = $info['sale_price']*$info['num'] ;
  443. $info['send_num'] = isset($orderinfo['send_num'])?$orderinfo['send_num']:'0';
  444. $info['wsend_num'] = isset($orderinfo['wsend_num'])?$orderinfo['wsend_num']:'0';
  445. $info['send_status'] = isset($orderinfo['send_status'])?$orderinfo['send_status']:'';
  446. $info['total_price'] = isset($orderinfo['total_price'])?$orderinfo['total_price']:'0';
  447. $info['post_fee'] = isset($orderinfo['post_fee'])?$orderinfo['post_fee']:'0';
  448. $info['customer_code'] = isset($orderinfo['customer_code'])?$orderinfo['customer_code']:'';
  449. $info['customer_name']='';
  450. if(isset($orderinfo['customer_code'])&&$orderinfo['customer_code']!=''){
  451. $customerinfo = Db::name("customer_info")->where(['companyNo'=>$orderinfo['customer_code']])->find();
  452. $info['customer_name'] = isset($customerinfo['companyName']) ? $customerinfo['companyName']:"";
  453. }
  454. $info['supplierNo'] = isset($orderinfo['supplierNo'])?$orderinfo['supplierNo']:'';
  455. $info['supplier_name']='';
  456. if(isset($orderinfo['supplierNo'])&&$orderinfo['supplierNo']!=''){
  457. $customerinfo = Db::name("business")->where(['companyNo'=>$orderinfo['supplierNo']])->find();
  458. $info['supplier_name'] = isset($customerinfo['company']) ? $customerinfo['company']:"";
  459. }
  460. $info['platform_name']='';
  461. $info['platform_id']=$orderinfo['platform_id'];
  462. if($orderinfo['platform_id']!=0){
  463. $plat=Db::name("platform")->where(['id'=>$orderinfo['platform_id']])->find();
  464. $info['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  465. }
  466. $info['cgd_wsend']="";
  467. $info['cgd_send']="";
  468. $info['cgd_total']="";
  469. if($orderinfo['order_type']==2){
  470. $cgd = Db::name("purchease_order")->where(["bkcode"=>$info["orderCode"],"order_type"=>2])->find();
  471. $info['cgd_wsend'] = isset($cgd['wsend_num']) ? $cgd['wsend_num']:0;
  472. $info['cgd_send'] = isset($cgd['send_num']) ? $cgd['send_num']:0;
  473. $info['cgd_total'] = isset($cgd['good_num']) ? $cgd['good_num']:0;
  474. }
  475. $info['error_msg']='';
  476. if($info['error_code']!=''){
  477. $error = Db::name("result_info")->where(["result_code"=>$info['error_code']])->find();
  478. $info['error_msg']= isset($error['result'])?$error['result']:"";
  479. }
  480. if($info['return_wsm']!=""){
  481. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  482. ->where(["a.wsm_code"=>$info['return_wsm']])->field("a.name as wsm_name,b.name,b.code")->find();
  483. }
  484. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  485. // $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  486. // $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  487. $wsm_return = Db::name("sale_returninfo")->where(["returnCode"=>$info["returnCode"],"is_del"=>0])->select()->toArray();
  488. $wsm=[];
  489. if(!empty($wsm_return)){
  490. foreach ($wsm_return as $value){
  491. $value['wsm_name']="";
  492. $value['wsm_supplier']="";
  493. $value['wsm_supplierNo']="";
  494. if($value['wsm_code']!=""){
  495. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  496. ->where(["a.wsm_code"=>$value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  497. $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  498. $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  499. $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  500. }
  501. $orderwsm = Db::name("sale_info")->where(["orderCode"=>$info["orderCode"],"wsm_code"=>$value["wsm_code"]])->find();
  502. $value["wsm_total"] = isset($orderwsm["num"]) ? $orderwsm["num"]:0;
  503. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], 'orderCode' => $info['orderCode']])->sum("send_num");
  504. $value['wsm_send'] = $send ?? 0;
  505. $value['wsm_wsend'] = $value['wsm_total'] - $value['wsm_send'];
  506. $wsm[]=$value;
  507. }
  508. }
  509. $info['wsminfo']=$wsm;
  510. $addr =Db::name("sale_returnaddr")->where(["returnCode"=>$info["returnCode"],"is_del"=>0])->select()->toArray();
  511. $addrinfo=[];
  512. if(!empty($addr)){
  513. foreach ( $addr as $value){
  514. $addrlist = Db::name("order_addr")->where(["id"=>$value["addrid"]])->find();
  515. $value['addr']=isset($addrlist['addr'])?$addrlist['addr']:"";
  516. $value['addr_code']=isset($addrlist['addr_code'])?$addrlist['addr_code']:"";
  517. $value['contactor']=isset($addrlist['contactor'])?$addrlist['contactor']:"";
  518. $value['mobile']=isset($addrlist['mobile'])?$addrlist['mobile']:"";
  519. $value['post_fee']=isset($addrlist['post_fee'])?$addrlist['post_fee']:"";
  520. $value['addive_time']=isset($addrlist['addive_time'])?$addrlist['addive_time']:"";
  521. $value['customer_code']=isset($addrlist['customer_code']) ?$addrlist['customer_code']:"" ;
  522. $value['receipt_quantity']=isset($addrlist['receipt_quantity']) ?$addrlist['receipt_quantity']:"" ;
  523. $send = Db::name("order_out")->where(['addrid' => $addrlist['id'], 'orderCode' => $addrlist['orderCode'],"is_del"=>0])->where("status",">=",2)->sum("send_num");
  524. $value['addr_send'] = $send ?? 0;
  525. $value['addr_wsend'] = $value['receipt_quantity'] - $value['addr_send'];
  526. $customer = Db::name("customer_info")->where(['companyNo'=>$addrlist['customer_code']])->find();
  527. $value['customer_name'] = isset($customer['companyName']) ? $customer['companyName']:"";
  528. $addrinfo[]=$value;
  529. }
  530. }
  531. $info['addrinfo']=$addrinfo;
  532. $info['can']=$int;
  533. return app_show(0,"获取成功",$info);
  534. }
  535. /**
  536. * @return \think\response\Json|void
  537. * @throws \think\db\exception\DataNotFoundException
  538. * @throws \think\db\exception\DbException
  539. * @throws \think\db\exception\ModelNotFoundException
  540. */
  541. public function delete(){
  542. $code = isset($this->post['returnCode']) && $this->post['returnCode'] !=="" ? trim($this->post['returnCode'])
  543. :"";
  544. if($code==""){
  545. return error_show(1004,"参数returnCode不能为空");
  546. }
  547. $info = Db::name("sale_return")->where(["returnCode"=>$code,"is_del"=>0])->find();
  548. if(empty($info)){
  549. return error_show(1004,"未找到退货数据");
  550. }
  551. $info["is_del"]=1;
  552. $info["updatetime"]=date("Y-m-d H:i:s");
  553. $del = Db::name("sale_return")->save($info);
  554. if($del){
  555. $ste = ["order_code"=>$code,"status"=>0,"action_remark"=>'',"action_type"=>"delete"];
  556. ActionLog::logAdd($this->post['token'],$ste,"XSTHD",0,$ste);
  557. $process=["order_code"=>$code,"order_id"=>$info['id'],"order_status"=>0,"order_type"=>"XSTHD"];
  558. ProcessOrder::workdel($process);
  559. return app_show(0,"删除成功");
  560. }else{
  561. return error_show(1004,"删除失败");
  562. }
  563. }
  564. /**审核
  565. * @return \think\response\Json|void
  566. * @throws \think\db\exception\DataNotFoundException
  567. * @throws \think\db\exception\DbException
  568. * @throws \think\db\exception\ModelNotFoundException
  569. */
  570. public function exam(){
  571. $code = isset($this->post['returnCode']) && $this->post['returnCode'] !=="" ? trim($this->post['returnCode']):"";
  572. if($code==""){
  573. return error_show(1004,"参数returnCode不能为空");
  574. }
  575. $info = Db::name("sale_return")->where(["returnCode"=>$code,"is_del"=>0])->find();
  576. if(empty($info)){
  577. return error_show(1004,"未找到退货数据");
  578. }
  579. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  580. if($status===""){
  581. return error_show(1004,"参数status不能为空");
  582. }
  583. $remark = isset($this->post['remark']) && $this->post['remark'] !="" ? trim($this->post['remark']) :"";
  584. $var = $info['status'];
  585. $orderinfo = Db::name("sale")->where(["orderCode"=>$info["orderCode"]])->find();
  586. if($orderinfo==false){
  587. return error_show(1004,"未找到订单数据");
  588. }
  589. if($status==4){
  590. if($info['is_addr']==1){
  591. $addr=Db::name("sale_returnaddr")->where(['returnCode'=>$info['returnCode'],"is_del"=>0])->select()
  592. ->toArray();
  593. if(empty($addr)){
  594. return error_show(1004,"未找到发货单地址数据");
  595. }
  596. }
  597. }
  598. if($status==3){
  599. $is_th =isset($this->post['is_th'])&&$this->post['is_th']!=="" ? intval($this->post['is_th']):"";
  600. if($is_th===""){
  601. return error_show(1004,"参数is_th不能为空");
  602. }
  603. $return_wsm =isset($this->post['return_wsm'])&&$this->post['return_wsm']!=="" ? trim($this->post['return_wsm']):"";
  604. if($is_th==0){
  605. if($return_wsm===""){
  606. return error_show(1004,"参数return_wsm 不能为空");
  607. }
  608. $wsmcode = Db::name("warehouse_info")->where(['wsm_code'=>$return_wsm])->find();
  609. if($wsmcode==false){
  610. return error_show(1004,"为找到仓库数据");
  611. }
  612. }
  613. $info['return_wsm'] =$return_wsm ;
  614. $info['is_th'] =$is_th ;
  615. }
  616. Db::startTrans();
  617. try{
  618. $temp= $info['status'];
  619. $info['status'] =$status;
  620. $remark!=""? $info['remark'] =$remark:"";
  621. $info["updatetime"]=date("Y-m-d H:i:s");
  622. $up = Db::name("sale_return")->save($info);
  623. if($up) {
  624. $process = ["order_code" => $code, "order_id" => $info['id'], "order_status" => $status, "order_type"=>"XSTHD",'before_status'=>$temp,'holder_id'=>$info['apply_id']];
  625. ProcessOrder::AddProcess($this->post['token'], $process);
  626. $ste = ["order_code" => $code, "status" => $temp, "action_remark" => '', "action_type" => "status"];
  627. ActionLog::logAdd($this->post['token'], $ste, "XSTHD", $status, $info);
  628. if ($status == 4) {
  629. if ($info['is_addr'] == 1) {
  630. if (isset($addr) && !empty($addr)) {
  631. foreach ($addr as $value) {
  632. $addrinfo = Db::name("order_addr")->where(['id' => $value['addrid'], "is_del" => 0])->find();
  633. if ($addrinfo == false) {
  634. Db::rollback();
  635. return error_show(1004, "地址数据未找到");
  636. }
  637. if ($addrinfo['receipt_quantity'] < $value['return_num']) {
  638. Db::rollback();
  639. return error_show(1004, "地址发货数量不足");
  640. }
  641. $addrinfo['receipt_quantity'] -= $value['return_num'];
  642. $addrinfo['is_del'] = $addrinfo['receipt_quantity'] <= 0 ? 1 : 0;
  643. $addrinfo['updatetime'] = date("Y-m-d H:i:s");
  644. $addrup = Db::name("order_addr")->save($addrinfo);
  645. if ($addrup == false) {
  646. Db::rollback();
  647. return error_show(1004, "地址发货数量更新失败");
  648. }
  649. if ($value['outCode'] != "") {
  650. $out = Db::name("order_out")->where(["outCode" => $value['outCode']])->find();
  651. if ($out == false) {
  652. Db::rollback();
  653. return error_show(1004, "地址发货单数据未找到");
  654. }
  655. if ($out['status'] >= 2) {
  656. Db::rollback();
  657. return error_show(1004, "地址发货单已发货");
  658. }
  659. if ($out['send_num'] < $value['return_num']) {
  660. Db::rollback();
  661. return error_show(1004, "地址发货单发货数量不足");
  662. }
  663. $out['send_num'] -= $value['return_num'];
  664. $out['is_del'] = $out['send_num'] <= 0 ? 1 : 0;
  665. $out['updatetime'] = date("Y-m-d H:i:s");
  666. $outup = Db::name("order_out")->save($out);
  667. if ($outup == false) {
  668. Db::rollback();
  669. return error_show(1004, "地址发货单更新失败");
  670. }
  671. // $ordersend = Db::name("order_send")->where(["outCode" => $value['outCode']])->find();
  672. // if ($ordersend['send_num'] < $value['return_num']) {
  673. // Db::rollback();
  674. // return error_show(1004, "发货单发货数量不足");
  675. // }
  676. // $ordersend['send_num'] -= $value['return_num'];
  677. // $ordersend['status'] = $ordersend['send_num'] <= 0 ? 0 : 1;
  678. // $ordersend['updatetime'] = date("Y-m-d H:i:s");
  679. // $sendip = Db::name("order_send")->save($ordersend);
  680. // if ($sendip == false) {
  681. // Db::rollback();
  682. // return error_show(1004, "发货单更新失败");
  683. // }
  684. }
  685. }
  686. }
  687. }
  688. if ($orderinfo['wsend_num'] < $info['num']) {
  689. Db::rollback();
  690. return error_show(1004, "销售单未发货数量不足退货");
  691. }
  692. $lor=$orderinfo['status'];
  693. $orderinfo['wsend_num'] -= $info['num'];
  694. $orderinfo['send_num'] += $info['num'];
  695. $orderinfo['status'] = $orderinfo['wsend_num']==0?2:($orderinfo['send_num']==0?0:1);
  696. $orderinfo['send_status'] =$orderinfo['wsend_num']==0?3:($orderinfo['send_num']==0?1:2);
  697. if ($orderinfo['is_stock'] == 1) {
  698. $orderinfo['th_num'] += $info['num'];
  699. if($orderinfo['th_num']==$orderinfo['send_num']&& $orderinfo['wsend_num']==0){
  700. $orderinfo['status']=3;
  701. }
  702. $orderinfo['th_fee'] += round($info['num'] * $orderinfo['sale_price'], 2);
  703. $orderinfo['updatetime'] = date("Y-m-d H:i:s");
  704. $uap = Db::name("sale")->save($orderinfo);
  705. if ($uap == false) {
  706. Db::rollback();
  707. return error_show(1005, '销售单订单更新失败');
  708. }
  709. // $ordernum = Db::name("order_num")->where(['orderCode' => $info['orderCode']])->find();
  710. // if ($ordernum == false) {
  711. // Db::rollback();
  712. // return error_show(1005, '未找到关联采购单');
  713. // }
  714. // $ordernum['send_num'] -= $info['num'];
  715. // $orderup = Db::name("order_num")->save($ordernum);
  716. // if ($orderup == false) {
  717. // Db::rollback();
  718. // return error_show(1005, '关联数据更新失败');
  719. // }
  720. // $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
  721. // if ($cgd == false) {
  722. // Db::rollback();
  723. // return error_show(1005, '未找到采购单数据');
  724. // }
  725. // $cgd['th_fee'] += round($cgd['good_price'] * $info['num'], 2);
  726. // $cgd['th_num'] += $info['num'];
  727. // if($cgd['th_num']==$cgd['send_num']&& $cgd['wsend_num']==0){
  728. // $cgd['status']=4;
  729. // }
  730. // $cgd['updatetime'] = date("Y-m-d H:i:s");
  731. // $cgdup = Db::name("purchease_order")->save($cgd);
  732. // if ($cgdup == false) {
  733. // Db::rollback();
  734. // return error_show(1005, '采购单数据更新失败');
  735. // }
  736. // if ($cgd['bkcode'] != "") {
  737. // $bk = Db::name("purchease_order")->where(["bkcode" => $cgd['bkcode'], "order_type" => 1,"order_source"=>0, "is_del" => 0])
  738. // ->find();
  739. // if ($bk == false) {
  740. // Db::rollback();
  741. // return error_show(1005, '未找到备库单数据');
  742. // }
  743. // $orderbk = Db::name("order_bk")->where(['cgdNo' => $bk['cgdNo'], "is_del" => 0])->find();
  744. // if ($orderbk == false) {
  745. // Db::rollback();
  746. // return error_show(1005, '备库单未完全入库');
  747. // }
  748. // $merge_num = Db::name("purchease_order")->where(["bkcode" => $bk['bkcode'], "order_type"
  749. // => 1, "is_del" => 0])->where("order_source","<>",0)
  750. // ->field("sum(send_num)-sum(th_num) as num")->find();
  751. //
  752. // $orderbk['balance_num'] = $orderbk['total_num'] - $merge_num['num'];
  753. // $orderbk['merge_num'] = $merge_num['num'];
  754. // $orderbk['updatetime'] = date("Y-m-d H:i:s");
  755. // $orderbkup = Db::name("order_bk")->save($orderbk);
  756. // if ($orderbkup == false) {
  757. // Db::rollback();
  758. // return error_show(1005, '备库单库存数据释放失败');
  759. // }
  760. // }
  761. } else {
  762. if ($info['is_th'] == 1) {
  763. $orderinfo['th_num'] += $info['num'];
  764. if($orderinfo['th_num']==$orderinfo['send_num']&& $orderinfo['wsend_num']==0){
  765. $orderinfo['status']=3;
  766. }
  767. $orderinfo['th_fee'] += round($info['num'] * $orderinfo['sale_price'], 2);
  768. $orderinfo['updatetime'] = date("Y-m-d H:i:s");
  769. $uap = Db::name("sale")->save($orderinfo);
  770. if ($uap == false) {
  771. Db::rollback();
  772. return error_show(1005, '销售单订单更新失败');
  773. }
  774. $ordernum = Db::name("order_num")->where(['orderCode' => $orderinfo['orderCode']])->find();
  775. if ($ordernum == false) {
  776. Db::rollback();
  777. return error_show(1005, '未找到关联采购单');
  778. }
  779. $ordernum['send_num'] -= $info['num'];
  780. $orderup = Db::name("order_num")->save($ordernum);
  781. if ($orderup == false) {
  782. Db::rollback();
  783. return error_show(1005, '关联数据更新失败');
  784. }
  785. $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
  786. if ($cgd == false) {
  787. Db::rollback();
  788. return error_show(1005, '未找到采购单数据');
  789. }
  790. if( $info['is_all']==1 && $cgd['send_status']!=1){
  791. Db::rollback();
  792. return error_show(1005, '采购单已入库无法全部退货');
  793. }
  794. $lor=$cgd['status'];
  795. if($cgd['wsend_num']<$info['num']){
  796. $cgd['send_num'] += $cgd['wsend_num']==0?0 :($info['num']-$cgd['wsend_num']);
  797. $cgd['wsend_num']=0;
  798. }else{
  799. $cgd['wsend_num'] -= $info['num'];
  800. $cgd['send_num'] += $info['num'];
  801. }
  802. $cgd['status'] = $cgd['wsend_num']==0?2:($cgd['send_num']==0?0:1);
  803. $cgd['send_status'] =$cgd['wsend_num']==0?3:($cgd['send_num']==0?1:2);
  804. $cgd['th_num'] += $info['num'];
  805. if($cgd['th_num']==$cgd['send_num']&& $cgd['wsend_num']==0){
  806. $cgd['status']=4;
  807. }
  808. $cgd['th_fee'] += round($info['num'] * $cgd['good_price'], 2);
  809. $cgd['updatetime'] = date("Y-m-d H:i:s");
  810. $cgdup = Db::name("purchease_order")->save($cgd);
  811. if ($cgdup == false) {
  812. Db::rollback();
  813. return error_show(1005, '采购单数据更新失败');
  814. }
  815. $stock = Db::name("good_stock")->where(["spuCode" => $info['good_code'], 'wsm_code' =>$cgd['wsm_code']])->find();
  816. if ($stock==false) {
  817. Db::rollback();
  818. return error_show(1005, '商品仓库未找到');
  819. }
  820. if($stock['wait_in_stock']<$info['num']){
  821. $stock['wait_in_stock']=0;
  822. if( $stock['usable_stock']>$info['num']-$stock['wait_in_stock']){
  823. $stock['usable_stock'] -= $info['num']-$stock['wait_in_stock'];
  824. }else{
  825. $stock['usable_stock'] = 0;
  826. $stock['wait_out_stock']-= $info['num']-$stock['wait_in_stock']- $stock['usable_stock'] ;
  827. }
  828. $stock['total_stock']= $stock['usable_stock']+ $stock['wait_out_stock'];
  829. }else{
  830. $stock['wait_in_stock']-=$info['num'];
  831. }
  832. $stock['updatetime'] = date("Y-m-d H:i:s");
  833. $st_up = Db::name("good_stock")->save($stock);
  834. if ($st_up == false) {
  835. Db::rollback();
  836. return error_show(1005, '可售商品入库失败');
  837. }
  838. } else {
  839. $orderinfo['th_num'] += $info['num'];
  840. if($orderinfo['th_num']==$orderinfo['send_num']&& $orderinfo['wsend_num']==0){
  841. $orderinfo['status']=3;
  842. }
  843. $orderinfo['th_fee'] += round($info['num'] * $orderinfo['sale_price'], 2);
  844. $orderinfo['updatetime'] = date("Y-m-d H:i:s");
  845. $uap = Db::name("sale")->save($orderinfo);
  846. if ($uap == false) {
  847. Db::rollback();
  848. return error_show(1005, '销售单订单更新失败');
  849. }
  850. $ordernum = Db::name("order_num")->where(['orderCode' => $orderinfo['orderCode']])->find();
  851. if ($ordernum == false) {
  852. Db::rollback();
  853. return error_show(1005, '未找到关联采购单');
  854. }
  855. $ordernum['send_num'] -= $info['num'];
  856. $ordernum['wsend_num'] = $info['num'];
  857. $orderup = Db::name("order_num")->save($ordernum);
  858. if ($orderup == false) {
  859. Db::rollback();
  860. return error_show(1005, '关联数据更新失败');
  861. }
  862. $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
  863. if ($cgd == false) {
  864. Db::rollback();
  865. return error_show(1005, '未找到采购单数据');
  866. }
  867. $stock = Db::name("good_stock")->where(["spuCode" => $info['good_code'], 'wsm_code' =>$cgd['wsm_code']])->find();
  868. if ($stock==false) {
  869. Db::rollback();
  870. return error_show(1005, '商品仓库未找到');
  871. }
  872. if($stock['usable_stock']+$stock['wait_out_stock']<$info['num']){
  873. Db::rollback();
  874. return error_show(1005, '商品可用库存不足退回数量');
  875. }else{
  876. if($stock['usable_stock']>$info['num']){
  877. $stock['usable_stock'] -= $info['num'];
  878. }else{
  879. $stock['usable_stock'] = 0;
  880. $stock['wait_out_stock']-= $info['num']- $stock['usable_stock'] ;
  881. }
  882. $stock['total_stock']= $stock['usable_stock']+ $stock['wait_out_stock'];
  883. }
  884. $stock['updatetime'] = date("Y-m-d H:i:s");
  885. $st_up = Db::name("good_stock")->save($stock);
  886. if ($st_up == false) {
  887. Db::rollback();
  888. return error_show(1005, '可售商品入库失败');
  889. }
  890. }
  891. }
  892. ActionLog::logAdd($this->post['token'], [
  893. "order_code" => $orderinfo["orderCode"],//出库单号
  894. "status" => $lor,//这里的status是之前的值
  895. "action_remark" => '',//备注
  896. "action_type" => "status"//新建create,编辑edit,更改状态status
  897. ], "XSQRD", $orderinfo['status'], $orderinfo);
  898. ProcessOrder::AddProcess($this->post['token'], [
  899. "order_type" => 'XSQRD',
  900. "order_code" =>$orderinfo["orderCode"],//出库单号
  901. "order_id" => $orderinfo["id"],
  902. "order_status" =>$orderinfo['status'],"before_status"=>$lor
  903. ]);
  904. if($orderinfo['is_stock'] == 1 || $info['is_th'] == 0){
  905. $wsmcode = $orderinfo['is_stock'] == 1 ? $cgd['wsm_code'] : $info['return_wsm'];
  906. if ($wsmcode == "") {
  907. Db::rollback();
  908. return error_show(1005, '未找到退货仓库');
  909. }
  910. //::todo 非库存品订单退货 采购单退货 虚拟仓如何减库存
  911. $stock = Db::name("good_stock")->where(["spuCode" => $info['good_code'], 'wsm_code' => $wsmcode])->find();
  912. if (empty($stock)) {
  913. $stock = [
  914. "spuCode" => $info['good_code'],
  915. "wsm_code" => $wsmcode,
  916. "usable_stock" => 0,
  917. "wait_out_stock" => 0,
  918. "wait_in_stock" => 0,
  919. "total_stock" => 0,
  920. "addtime" => date("Y-m-d H:i:s"),
  921. "updatetime" => date("Y-m-d H:i:s"),
  922. ];
  923. }
  924. $stock['usable_stock'] += $info['num'];
  925. $stock['updatetime'] = date("Y-m-d H:i:s");
  926. $st_up = Db::name("good_stock")->save($stock);
  927. if ($st_up == false) {
  928. Db::rollback();
  929. return error_show(1005, '可售商品入库失败');
  930. }
  931. $stockid = isset($stock['id']) ? $stock['id'] : Db::name("good_stock")->getLastInsID();
  932. $sabebn =Db::name("sale_info")->where(["orderCode"=>$orderinfo["orderCode"]])->select()->toArray();
  933. if(!empty($sabebn)){
  934. $total_num =$info['num'];
  935. foreach ($sabebn as $ve){
  936. $tempnum=0;
  937. if ($total_num==0) break;
  938. if($total_num>=$ve['num']){
  939. $tempnum = $ve['num'];
  940. $total_num-=$ve['num'];
  941. $ve['num']=0;
  942. }else{
  943. $tempnum = $total_num;
  944. $total_num=0;
  945. $ve['num']-=$total_num;
  946. }
  947. $bnin=GoodStockInfo::AddBn($stockid,$ve['bnCode'],$tempnum,$ve['origin_price']);
  948. if($bnin==false){
  949. Db::rollback();
  950. return error_show(1005, '可售商品Bn库存数入库失败');
  951. }
  952. $up=Db::name("sale_info")->save($ve);
  953. if($up==false){
  954. Db::rollback();
  955. return error_show(1005, '可售商品Bn库存数入库失败');
  956. }
  957. $bnin=GoodStockInfo::ReturnBn($info['returnCode'],$ve['id'],$tempnum);
  958. if($bnin==false){
  959. Db::rollback();
  960. return error_show(1005, '可售商品Bn库存数入库失败');
  961. }
  962. }
  963. }
  964. $good_data = ['good_log_code' => $info['returnCode'], "stock_id" => $stockid, "type" => 1, 'stock'=> $info['num'], "stock_name" => "usable_stock"];
  965. GoodLog::LogAdd($this->post['token'], $good_data, 'XSTHD');
  966. }
  967. $data=[
  968. "orderCode"=>$info['orderCode'],
  969. "th_type"=>1,
  970. "th_num"=>$info['num'],
  971. "th_fee"=>round($info['num']*$orderinfo['sale_price'],2),
  972. "thCode"=>$info['returnCode'],
  973. "spuCode"=>$orderinfo['good_code'],
  974. "good_name"=>$orderinfo['good_name'],
  975. "cat_id"=>$orderinfo['cat_id'],
  976. "apply_id"=>$info['apply_id'],
  977. "apply_name"=>$info['apply_name'],
  978. "addtime"=>date("Y-m-d H:i:s"),
  979. "status"=>1,
  980. "is_del"=>0
  981. ];
  982. $inse=Db::name("th_data")->insert($data);
  983. if($inse==false){
  984. Db::rollback();
  985. return error_show(1004,"退货单更新失败");
  986. }
  987. }
  988. }
  989. Db::commit();
  990. return app_show(0,"更新成功");
  991. }catch (\Exception $e){
  992. Db::rollback();
  993. return error_show(1004,$e->getMessage()."|".$e->getLine());
  994. }
  995. }
  996. public function zxcreate(){
  997. $ordeCode = isset($this->post['orderCode']) &&$this->post['orderCode']!=''?trim($this->post['orderCode']) :"";
  998. if($ordeCode==''){
  999. return error_show(1004,"参数orderCode 不能为空");
  1000. }
  1001. $order= Db::name("sale")->where(["orderCode"=>$ordeCode,"is_del"=>0])->find();
  1002. if(empty($order)){
  1003. return error_show(1005,"未找到订单数据");
  1004. }
  1005. $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
  1006. if($errorCode==''){
  1007. return error_show(1004,"参数errorCode 不能为空");
  1008. }
  1009. $error =Db::name('result_info')->where(["result_code"=>$errorCode,"is_del"=>0])->find();
  1010. if(empty($error)){
  1011. return error_show(1005,"未找到退货原因数据");
  1012. }
  1013. $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
  1014. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  1015. if($token==''){
  1016. return error_show(105,"参数token不能为空");
  1017. }
  1018. $user =GetUserInfo($token);
  1019. if(empty($user)||$user['code']!=0){
  1020. return error_show(1002,"申请人数据不存在");
  1021. }
  1022. $rm= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1023. $ri= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1024. $num = isset($this->post['num'])&&$this->post['num']!='' ? intval($this->post['num']):"";
  1025. if($num==''){
  1026. return error_show(1005,"参数num不能为空");
  1027. }
  1028. if($order['wsend_num']<$num){
  1029. return error_show(1002,"仓库未发货数量不足退货");
  1030. }
  1031. $returnCode=makeNo("RS");
  1032. Db::startTrans();
  1033. try{
  1034. $in = [
  1035. "returnCode"=>$returnCode,
  1036. "orderCode"=>$ordeCode,
  1037. "good_code"=>$order['good_code'],
  1038. "good_name"=>$order['good_name'],
  1039. "apply_id"=>$rm,
  1040. "apply_name"=>$ri,
  1041. "error_code"=>$errorCode,
  1042. "num"=>$num,
  1043. "remark"=>$remark,
  1044. "order_type"=>2,
  1045. "status"=>0,
  1046. "is_del"=>0,
  1047. "addtime"=>date("Y-m-d H:i:s"),
  1048. "updatetime"=>date("Y-m-d H:i:s")
  1049. ];
  1050. $create = Db::name("sale_return")->insert($in,true);
  1051. if($create>0) {
  1052. $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>0,"order_type"=>'XSTHD',"before_status"=>0,'holder_id'=>$in['apply_id']];
  1053. ProcessOrder::AddProcess($this->post['token'],$process);
  1054. $ste = ["order_code"=>$returnCode,"status"=>0,"action_remark"=>'',
  1055. "action_type"=>"create"];
  1056. ActionLog::logAdd($this->post['token'],$ste,"XSTHD",3,$in);
  1057. //维护台账记录
  1058. // Db::name('standing_book')
  1059. // ->where('ordeCode', $ordeCode)
  1060. // ->update([
  1061. // 'returnGoodCode' => $returnCode,
  1062. // 'updatetime' => date("Y-m-d H:i:s")
  1063. // ]);
  1064. Db::execute("UPDATE `wsm_standing_book` SET `returnGoodCode`=CONCAT(IFNULL(`returnGoodCode`,''),',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `orderCode`='{$ordeCode}'");
  1065. if ($order['send_type'] == 1) {
  1066. $wsend = Db::name("order_out")->where(['orderCode' => $ordeCode, "status" => 1, "order_type"=>2])->select();
  1067. // ->save(["status" => 0, "updatetime" => date("Y-m-d H:i:s")]);
  1068. if(!empty($wsend)){
  1069. foreach ($wsend as $value){
  1070. $tt = $value['status'];
  1071. $value['status']=0;
  1072. $value['updatetime']=date("Y-m-d H:i:s");
  1073. $up =Db::name("order_out")->save($value);
  1074. if($up){
  1075. $process=["order_code"=> $value['outCode'],"order_id"=>$value['id'],"order_status"=>0,"order_type"=>'CKD',"before_status"=>$tt,'holder_id' => $value['apply_id']];
  1076. ProcessOrder::AddProcess($this->post['token'],$process);
  1077. $ste = ["order_code"=>$value['outCode'],"status"=>$tt,"action_remark"=>'',"action_type"=>"status"];
  1078. ActionLog::logAdd($this->post['token'],$ste,"CKD",0,$value);
  1079. }else{
  1080. Db::rollback();
  1081. return error_show(1005,"退货单新建失败");
  1082. }
  1083. }
  1084. }
  1085. }
  1086. Db::commit();
  1087. return error_show(0,"退货单新建成功");
  1088. }
  1089. Db::rollback();
  1090. return error_show(1005,"退货单新建失败");
  1091. }catch (\Exception $e){
  1092. Db::rollback();
  1093. return error_show(1005,$e->getMessage());
  1094. }
  1095. }
  1096. public function allReturn(){
  1097. $orderCode =isset($this->post['orderCode'])&&$this->post['orderCode']!=''? trim($this->post['orderCode']):"";
  1098. if($orderCode==''){
  1099. return error_show(1004,"参数orderCode 不能为空");
  1100. }
  1101. $order= Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->find();
  1102. if(empty($order)){
  1103. return error_show(1005,"未找到订单数据");
  1104. }
  1105. if($order['wsend_num']!=$order['good_num']){
  1106. return error_show(1005,"订单未发货数量与总数不等,无法全退");
  1107. }
  1108. $retrun =Db::name("sale_return")->where([["orderCode","=",$orderCode],["is_del","=",0],["status","<",4]])
  1109. ->count();
  1110. if($retrun>0){
  1111. return error_show(1005,"存在退货订单数据");
  1112. }
  1113. if($order['order_type']==3){
  1114. $goon = Db::name("good_zixun")->where(["spuCode"=>$order['good_code'],"is_del"=>0])->find();
  1115. }else {
  1116. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  1117. ->where(['a.skuCode' => $order['skuCode']])->field("b.creater,b.createrid,b.supplierNo")->find();
  1118. }
  1119. if($goon==false){
  1120. return error_show(1005,"未找到商品数据");
  1121. }
  1122. $supplier =Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
  1123. if($supplier==false){
  1124. return error_show(1005,"未找到商品供应商数据");
  1125. }
  1126. $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
  1127. if($errorCode==''){
  1128. return error_show(1004,"参数errorCode 不能为空");
  1129. }
  1130. $error =Db::name('result_info')->where(["result_code"=>$errorCode,"is_del"=>0])->find();
  1131. if(empty($error)){
  1132. return error_show(1005,"未找到退货原因数据");
  1133. }
  1134. $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
  1135. $addr =Db::name("order_addr")->where([["orderCode","=",$orderCode],["is_del","=",0]])->select()->toArray();
  1136. if($order['is_stock']==0){
  1137. $ordernum = Db::name("order_num")->where(['orderCode' => $orderCode])->find();
  1138. if ($ordernum == false) {
  1139. return error_show(1005, '未找到关联采购单');
  1140. }
  1141. $cgd = Db::name("purchease_order")->where(["cgdNo" => $ordernum['cgdNo'], "is_del" => 0])->find();
  1142. if ($cgd == false) {
  1143. return error_show(1005, '未找到采购单数据');
  1144. }
  1145. }
  1146. if($order['is_stock']==0&&$cgd['send_status']!=1){
  1147. return error_show(1005, '采购单已发起入库');
  1148. }
  1149. $returnCode=makeNo("RN");
  1150. Db::startTrans();
  1151. try{
  1152. $in = [
  1153. "returnCode"=>$returnCode,
  1154. "orderCode"=>$orderCode,
  1155. "good_code"=>$order['good_code'],
  1156. "good_name"=>$order['good_name'],
  1157. "apply_id"=>$this->uid,
  1158. "apply_name"=>$this->uname,
  1159. "cgderid"=>$goon['createrid'],
  1160. "cgder"=>$goon['creater'],
  1161. "person"=>$supplier['person']??'',
  1162. "person_id"=>$supplier['personid']??0,
  1163. "error_code"=>$errorCode,
  1164. "num"=>$order['wsend_num'],
  1165. "total_fee"=>round($order['sale_price']*$order['wsend_num'],2),
  1166. "good_price"=>$order['sale_price'],
  1167. "platform_id"=>$order['platform_id'],
  1168. "remark"=>$remark,
  1169. "order_type"=>$order['order_type'],
  1170. "is_addr"=>count($addr)>0 ?1:0,
  1171. "status"=>$order['is_stock']==1?4:1,
  1172. "is_del"=>0,
  1173. "is_all"=>1,
  1174. "addtime"=>date("Y-m-d H:i:s"),
  1175. "updatetime"=>date("Y-m-d H:i:s")
  1176. ];
  1177. $create = Db::name("sale_return")->insert($in,true);
  1178. if($create>0){
  1179. $stn = ["order_code"=>$returnCode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  1180. ActionLog::logAdd(["id"=>$this->uid,"nickname"=>$this->uname],$stn,"XSTHD",$in['status'],$in);
  1181. $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>$in['status'],"order_type"=>'XSTHD',"before_status"=>0,'holder_id'=>$in['apply_id']];
  1182. ProcessOrder::AddProcess(["id"=>$this->uid,"nickname"=>$this->uname],$process);
  1183. //维护台账信息
  1184. Db::execute("UPDATE `wsm_standing_book` SET `returnGoodCode`=CONCAT(IFNULL(`returnGoodCode`,''),',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `orderCode`='{$orderCode}'");
  1185. if(count($addr)!=0){
  1186. $inf=[];
  1187. foreach ($addr as $val){
  1188. if ($val['receipt_quantity'] == 0) continue;//当退货数量为0时,跳过
  1189. $temp=[];
  1190. $send =Db::name('order_out')->where([["addrid","=",$val['id']]])->find();
  1191. if ($send == false) {
  1192. Db::rollback();
  1193. return error_show(1004, "地址发货单未找到");
  1194. }
  1195. if($send['status']>=2){
  1196. Db::rollback();
  1197. return error_show(1005,"地址已发货");
  1198. }
  1199. if($order['is_stock']==1){
  1200. $val['is_del'] = 1;
  1201. $val['updatetime'] = date("Y-m-d H:i:s");
  1202. $addrup = Db::name("order_addr")->save($val);
  1203. if ($addrup == false) {
  1204. Db::rollback();
  1205. return error_show(1004, "地址更新失败");
  1206. }
  1207. $send['is_del'] = 1;
  1208. $send['updatetime'] = date("Y-m-d H:i:s");
  1209. $outup = Db::name("order_out")->save($send);
  1210. if ($outup == false) {
  1211. Db::rollback();
  1212. return error_show(1004, "地址发货单更新失败");
  1213. }
  1214. // $ordersend = Db::name("order_send")->where(["outCode" => $send['outCode']])->find();
  1215. // if($ordersend==false){
  1216. // Db::rollback();
  1217. // return error_show(1004, "发货单关联数据未找到");
  1218. // }
  1219. // $ordersend['status'] = 0;
  1220. // $ordersend['updatetime'] = date("Y-m-d H:i:s");
  1221. // $sendip = Db::name("order_send")->save($ordersend);
  1222. // if ($sendip == false) {
  1223. // Db::rollback();
  1224. // return error_show(1004, "发货单更新失败");
  1225. // }
  1226. }
  1227. $temp['returnCode']=$returnCode;
  1228. $temp['orderCode']=$orderCode;
  1229. $temp['outCode']=isset($send['outCode'])?$send['outCode']:"";
  1230. $temp['addrid']=$val['id'];
  1231. $temp['send_num']=$val['receipt_quantity'];
  1232. $temp['return_num']=$val['receipt_quantity'];
  1233. $temp['is_del']=0;
  1234. $temp['addtime']=date("Y-m-d H:i:s");
  1235. $temp['updatetime']=date("Y-m-d H:i:s");
  1236. $inf[]=$temp;
  1237. }
  1238. $inadd=Db::name("sale_returnaddr")->insertAll($inf);
  1239. if($inadd==0){
  1240. Db::rollback();
  1241. return error_show(1005,"退货单新建失败");
  1242. }
  1243. }
  1244. if($order['is_stock']==1){
  1245. $lor=$order['status'];
  1246. $thnum = $order['wsend_num'];
  1247. $order['send_num'] += $thnum;
  1248. $order['th_num'] += $thnum;
  1249. $order['wsend_num'] =0;
  1250. $order['status'] = 3;
  1251. $order['send_status']=3;
  1252. $order['th_fee'] += round($thnum * $order['sale_price'], 2);
  1253. $order['updatetime'] = date("Y-m-d H:i:s");
  1254. $uap = Db::name("sale")->save($order);
  1255. if ($uap == false) {
  1256. Db::rollback();
  1257. return error_show(1005, '销售单订单更新失败');
  1258. }
  1259. ActionLog::logAdd(["id"=>$this->uid,"nickname"=>$this->uname], [
  1260. "order_code" => $order["orderCode"],//出库单号
  1261. "status" => $lor,//这里的status是之前的值
  1262. "action_remark" => '',//备注
  1263. "action_type" => "status"//新建create,编辑edit,更改状态status
  1264. ], "XSQRD", $order['status'], $order);
  1265. ProcessOrder::AddProcess(["id"=>$this->uid,"nickname"=>$this->uname], [
  1266. "order_type" => 'XSQRD',
  1267. "order_code" =>$order["orderCode"],//出库单号
  1268. "order_id" => $order["id"],
  1269. "order_status" =>$order['status'],
  1270. "before_status"=>$lor,
  1271. 'holder_id=' => $order['apply_id']
  1272. ]);
  1273. $saleinfo=Db::name("sale_info")->where([["orderCode","=",$orderCode],["num",">",0]])->select()
  1274. ->toArray();
  1275. if(empty($saleinfo)) {
  1276. Db::rollback();
  1277. return error_show(1005, '商品批次数据未找到');
  1278. }
  1279. $tempnum =$thnum;
  1280. foreach ( $saleinfo as $va){
  1281. if($tempnum ==0) break;
  1282. $stock = Db::name("good_stock")->where(["spuCode" => $order['good_code'], 'id' => $va['stockid']])
  1283. ->find();
  1284. if($stock==false) {
  1285. Db::rollback();
  1286. return error_show(1005, '商品库存数据未找到');
  1287. }
  1288. if($va['num']>=$tempnum) {
  1289. $tnm = $tempnum;
  1290. $va['num']-= $tempnum;
  1291. $tempnum=0;
  1292. }else{
  1293. $tnm = $va['num'];
  1294. $tempnum -=$va['num'];
  1295. $va['num'] =0;
  1296. }
  1297. $stock['usable_stock']+=$tnm;
  1298. $stock['wait_out_stock'] -=$tnm;
  1299. $stock['updatetime'] = date("Y-m-d H:i:s");
  1300. $st_up = Db::name("good_stock")->save($stock);
  1301. if ($st_up == false) {
  1302. return error_show(1005, '可售商品入库失败');
  1303. }
  1304. $ps = GoodStockInfo::AddBn($va['stockid'],$va['bnCode'],$tnm);
  1305. if ($ps == false) {
  1306. return error_show(1005, '商品批次退货入库失败');
  1307. }
  1308. $ret = GoodStockInfo::ReturnBn($returnCode,$va['id'],$tnm);
  1309. if ($ret == false) {
  1310. return error_show(1005, '商品批次退货入库失败');
  1311. }
  1312. $va['updatetime']=date("Y-m-d H:i:s");
  1313. $sal= Db::name("sale_info")->save($va);
  1314. if ($sal == false) {
  1315. return error_show(1005, '商品批次退货入库失败');
  1316. }
  1317. $good_data[]= ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 1, 'stock' => $thnum, "stock_name" => "usable_stock"];
  1318. $good_data[]= ['good_log_code' => $returnCode, "stock_id" => $va['stockid'], "type" => 2, 'stock' => $thnum, "stock_name" => "wait_out_stock"];
  1319. GoodLog::LogAdd($this->post['token'], $good_data, 'XSTHD');
  1320. }
  1321. $data=[
  1322. "orderCode"=>$orderCode,
  1323. "th_type"=>1,
  1324. "th_num"=>$thnum,
  1325. "th_fee"=>round($order['sale_price']*$thnum,2),
  1326. "thCode"=>$returnCode,
  1327. "spuCode"=>$order['good_code'],
  1328. "good_name"=>$order['good_name'],
  1329. "cat_id"=>$order['cat_id'],
  1330. "apply_id"=>$this->uid,
  1331. "apply_name"=>$this->uname,
  1332. "addtime"=>date("Y-m-d H:i:s"),
  1333. "status"=>1,
  1334. "is_del"=>0
  1335. ];
  1336. $inse=Db::name("th_data")->insert($data);
  1337. if($inse==false){
  1338. Db::rollback();
  1339. return error_show(1004,"退货单更新失败");
  1340. }
  1341. }
  1342. Db::commit();
  1343. return app_show(0,"退货单新建成功",["returnCode"=>$returnCode]);
  1344. }
  1345. Db::rollback();
  1346. return error_show(1005,"退货单新建失败");
  1347. }catch (\Exception $e){
  1348. Db::rollback();
  1349. return error_show(1005, $e->getMessage());
  1350. }
  1351. }
  1352. }