Reorder.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ProcessOrder;
  4. use think\facade\Db;
  5. use think\App;
  6. use app\admin\model\ActionLog;
  7. class Reorder extends \app\BaseController
  8. {
  9. public $post=[];
  10. public function __construct(App $app)
  11. {
  12. parent::__construct($app);
  13. $this->post =$this->request->post();
  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. $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
  25. if($errorCode==''){
  26. return error_show(1004,"参数errorCode 不能为空");
  27. }
  28. $error =Db::name('result_info')->where(["result_code"=>$errorCode,"is_del"=>0])->find();
  29. if(empty($error)){
  30. return error_show(1005,"未找到退货原因数据");
  31. }
  32. $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
  33. $thnum =isset($this->post['thnum']) &&$this->post['thnum']!=''?intval($this->post['thnum']) :"";
  34. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  35. if($token==''){
  36. return error_show(105,"参数token不能为空");
  37. }
  38. $user =GetUserInfo($token);
  39. if(empty($user)||$user['code']!=0){
  40. return error_show(1002,"申请人数据不存在");
  41. }
  42. $rm= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  43. $ri= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  44. $returnadr =isset($this->post['returnAddr'])&&$this->post['returnAddr']!="" ? $this->post['returnAddr']:"";
  45. if($returnadr!=''){
  46. $thnum=array_sum(array_column($returnadr,"return_num"));
  47. }
  48. $returnCode=makeNo("RXS");
  49. Db::startTrans();
  50. try{
  51. $in = [
  52. "returnCode"=>$returnCode,
  53. "orderCode"=>$ordeCode,
  54. "good_code"=>$order['good_code'],
  55. "good_name"=>$order['good_name'],
  56. "apply_id"=>$rm,
  57. "apply_name"=>$ri,
  58. "error_code"=>$errorCode,
  59. "num"=>$thnum,
  60. "remark"=>$remark,
  61. "order_type"=>$order['order_type'],
  62. "status"=>0,
  63. "is_del"=>0,
  64. "addtime"=>date("Y-m-d H:i:s"),
  65. "updatetime"=>date("Y-m-d H:i:s")
  66. ];
  67. $create = Db::name("sale_return")->insert($in,true);
  68. if($create>0){
  69. $stn = ["order_code"=>$returnCode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  70. ActionLog::logAdd($this->post['token'],$stn,"QRTHD",0,$stn);
  71. $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>0,"order_type"=>'QRTHD'];
  72. ProcessOrder::AddProcess($this->post['token'],$process);
  73. if($returnadr!=""){
  74. $inf=[];
  75. foreach ($returnadr as $val){
  76. $temp=[];
  77. $addrinfo =Db::name("order_addr")->where(['id'=>$val['id'],"orderCode"=>$ordeCode])->find();
  78. if($addrinfo==false){
  79. Db::rollback();
  80. return error_show(1005,"地址信息未找到");
  81. }
  82. $send =Db::name('order_out')->where([["addrid","=",$val['id']],["status",">=",2]])->sum('send_num');
  83. if($send!=0 && $addrinfo['receipt_quantity']<$send+$val['return_num']){
  84. Db::rollback();
  85. return error_show(1005,"地址已发货");
  86. }
  87. $temp['returnCode']=$returnCode;
  88. $temp['orderCode']=$ordeCode;
  89. $temp['addrid']=$val['id'];
  90. $temp['send_num']=$addrinfo['receipt_quantity'];
  91. $temp['return_num']=$val['return_num'];
  92. $temp['is_del']=0;
  93. $temp['addtime']=date("Y-m-d H:i:s");
  94. $temp['updatetime']=date("Y-m-d H:i:s");
  95. $inf[]=$temp;
  96. }
  97. $inadd=Db::name("sale_returnaddr")->insertAll($inf);
  98. if($inadd==0){
  99. Db::rollback();
  100. return error_show(1005,"退货单新建失败");
  101. }
  102. }
  103. Db::commit();
  104. return app_show(0,"退货单新建成功",["returnCode"=>$returnCode]);
  105. }
  106. Db::rollback();
  107. return error_show(1005,"退货单新建失败");
  108. }catch (\Exception $e){
  109. Db::rollback();
  110. return error_show(1005,$e->getMessage());
  111. }
  112. }
  113. public function list(){
  114. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  115. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  116. $where =[['is_del',"=",0]];
  117. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  118. if($bkcode!=""){
  119. $where[]=['returnCode',"like", "%{$bkcode}%"];
  120. }
  121. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  122. if($status!==""){
  123. $where[]=['status',"=", $status];
  124. }
  125. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode'])
  126. :"";
  127. if($orderCode!=""){
  128. $where[]=['orderCode',"like", "%{$orderCode}%"];
  129. }
  130. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name'])
  131. :"";
  132. if($apply_name!=""){
  133. $where[]=['apply_name',"like", "%{$apply_name}%"];
  134. }
  135. $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
  136. if($start!==""){
  137. $where[]=['addtime',">=", $start];
  138. }
  139. $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
  140. if($end!==""){
  141. $where[]=['addtime',"<=", $end];
  142. }
  143. $count=Db::name("sale_return")->where($where)->count();
  144. $total = ceil($count/$size);
  145. $page = $total>=$page ? $page :$total;
  146. $list = Db::name("sale_return")->where($where)->order("addtime desc")->page($page,$size)->select();
  147. // echo Db::name("sale_return")->getLastSql();
  148. $data=[];
  149. foreach ($list as $value){
  150. $value['error_msg']='';
  151. if($value['error_code']!=''){
  152. $error = Db::name("result_info")->where(["result_code"=>$value['error_code']])->find();
  153. $value['error_msg']= isset($error['result'])?$error['result']:"";
  154. }
  155. $order =Db::name("sale")->where(["orderCode"=>$value['orderCode'],"is_del"=>0])->find();
  156. $value['sale_price'] = isset($order['sale_price']) ?$order['sale_price']:0;
  157. $value['return_total'] =$value['sale_price']*$value['num'] ;
  158. $value['total_num'] =$order['good_num'] ;
  159. $data[]=$value ;
  160. }
  161. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  162. }
  163. public function info(){
  164. $code = isset($this->post['returnCode']) && $this->post['returnCode'] !=="" ? trim($this->post['returnCode'])
  165. :"";
  166. if($code==""){
  167. return error_show(1004,"参数returnCode不能为空");
  168. }
  169. $info = Db::name("sale_return")->where(["returnCode"=>$code,"is_del"=>0])->find();
  170. if(empty($info)){
  171. return error_show(1004,"未找到退货数据");
  172. }
  173. $orderinfo = Db::name("sale")->where(["orderCode"=>$info["orderCode"]])->find();
  174. if($orderinfo['order_type']==3|| $orderinfo['order_type']==4){
  175. $goon = Db::name("good_zixun")->where(["spuCode"=>$orderinfo['good_code'],"is_del"=>0])->find();
  176. }else {
  177. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  178. ->where(['a.skuCode' => $orderinfo['skuCode']])->find();
  179. }
  180. if ($goon==false) {
  181. return error_show(1003, "未找到商品数据");
  182. }
  183. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  184. $info['is_stock']=isset($goon['is_stock'])?$goon['is_stock']:'0';
  185. $info['good_code'] = isset($orderinfo['good_code'])?$orderinfo['good_code']:'';
  186. $info['good_name'] = isset($orderinfo['good_name'])?$orderinfo['good_name']:'';
  187. $info['good_num'] = isset($orderinfo['good_num'])?$orderinfo['good_num']:'';
  188. $info['sale_price'] = isset($orderinfo['sale_price'])?$orderinfo['sale_price']:'0';
  189. $info['origin_price'] = isset($orderinfo['origin_price'])?$orderinfo['origin_price']:'0';
  190. $info['return_total'] = $info['sale_price']*$info['num'] ;
  191. $info['send_num'] = isset($orderinfo['send_num'])?$orderinfo['send_num']:'0';
  192. $info['wsend_num'] = isset($orderinfo['wsend_num'])?$orderinfo['wsend_num']:'0';
  193. $info['send_status'] = isset($orderinfo['send_status'])?$orderinfo['send_status']:'';
  194. $info['total_price'] = isset($orderinfo['total_price'])?$orderinfo['total_price']:'0';
  195. $info['post_fee'] = isset($orderinfo['post_fee'])?$orderinfo['post_fee']:'0';
  196. $info['customer_code'] = isset($orderinfo['customer_code'])?$orderinfo['customer_code']:'';
  197. $info['customer_name']='';
  198. if(isset($orderinfo['customer_code'])&&$orderinfo['customer_code']!=''){
  199. $customerinfo = Db::name("customer_info")->where(['companyNo'=>$orderinfo['customer_code']])->find();
  200. $info['customer_name'] = isset($customerinfo['companyName']) ? $customerinfo['companyName']:"";
  201. }
  202. $info['cgd_wsend']="";
  203. $info['cgd_send']="";
  204. $info['cgd_total']="";
  205. if($orderinfo['order_type']==2){
  206. $cgd = Db::name("purchease_order")->where(["bkcode"=>$info["orderCode"],"order_type"=>2])->find();
  207. $info['cgd_wsend'] = isset($cgd['wsend_num']) ? $cgd['wsend_num']:0;
  208. $info['cgd_send'] = isset($cgd['send_num']) ? $cgd['send_num']:0;
  209. $info['cgd_total'] = isset($cgd['good_num']) ? $cgd['good_num']:0;
  210. }
  211. $info['error_msg']='';
  212. if($info['error_code']!=''){
  213. $error = Db::name("result_info")->where(["result_code"=>$info['error_code']])->find();
  214. $info['error_msg']= isset($error['result'])?$error['result']:"";
  215. }
  216. $wsm_return = Db::name("sale_returninfo")->where(["returnCode"=>$info["returnCode"],"is_del"=>0])->select()->toArray();
  217. $wsm=[];
  218. if(!empty($wsm_return)){
  219. foreach ($wsm_return as $value){
  220. $value['wsm_name']="";
  221. $value['wsm_supplier']="";
  222. $value['wsm_supplierNo']="";
  223. if($value['wsm_code']!=""){
  224. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  225. ->where(["a.wsm_code"=>$value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  226. $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  227. $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  228. $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  229. }
  230. $orderwsm = Db::name("sale_info")->where(["orderCode"=>$info["orderCode"],"wsm_code"=>$value["wsm_code"]])->find();
  231. $value["wsm_total"] = isset($orderwsm["num"]) ? $orderwsm["num"]:0;
  232. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], 'orderCode' => $info['orderCode']])->sum("send_num");
  233. $value['wsm_send'] = $send ?? 0;
  234. $value['wsm_wsend'] = $value['wsm_total'] - $value['wsm_send'];
  235. $wsm[]=$value;
  236. }
  237. }
  238. $info['wsminfo']=$wsm;
  239. $addr =Db::name("sale_returnaddr")->where(["returnCode"=>$info["returnCode"],"is_del"=>0])->select()->toArray();
  240. $addrinfo=[];
  241. if(!empty($addr)){
  242. foreach ( $addr as $value){
  243. $addrlist = Db::name("order_addr")->where(["id"=>$value["addrid"]])->find();
  244. $value['addr']=isset($addrlist['addr'])?$addrlist['addr']:"";
  245. $value['addr_code']=isset($addrlist['addr_code'])?$addrlist['addr_code']:"";
  246. $value['contactor']=isset($addrlist['contactor'])?$addrlist['contactor']:"";
  247. $value['mobile']=isset($addrlist['mobile'])?$addrlist['mobile']:"";
  248. $value['post_fee']=isset($addrlist['post_fee'])?$addrlist['post_fee']:"";
  249. $value['addive_time']=isset($addrlist['addive_time'])?$addrlist['addive_time']:"";
  250. $value['customer_code']=isset($addrlist['customer_code']) ?$addrlist['customer_code']:"" ;
  251. $value['receipt_quantity']=isset($addrlist['receipt_quantity']) ?$addrlist['receipt_quantity']:"" ;
  252. $send = Db::name("order_out")->where(['addrid' => $addrlist['id'], 'orderCode' => $addrlist['orderCode']])->sum("send_num");
  253. $value['addr_send'] = $send ?? 0;
  254. $value['addr_wsend'] = $value['receipt_quantity'] - $value['addr_send'];
  255. $customer = Db::name("customer_info")->where(['companyNo'=>$addrlist['customer_code']])->find();
  256. $value['customer_name'] = isset($customer['companyName']) ? $customer['companyName']:"";
  257. $addrinfo[]=$value;
  258. }
  259. }
  260. $info['addrinfo']=$addrinfo;
  261. $info['can']=$int;
  262. return app_show(0,"获取成功",$info);
  263. }
  264. /**
  265. * @return \think\response\Json|void
  266. * @throws \think\db\exception\DataNotFoundException
  267. * @throws \think\db\exception\DbException
  268. * @throws \think\db\exception\ModelNotFoundException
  269. */
  270. public function delete(){
  271. $code = isset($this->post['returnCode']) && $this->post['returnCode'] !=="" ? trim($this->post['returnCode'])
  272. :"";
  273. if($code==""){
  274. return error_show(1004,"参数returnCode不能为空");
  275. }
  276. $info = Db::name("sale_return")->where(["returnCode"=>$code,"is_del"=>0])->find();
  277. if(empty($info)){
  278. return error_show(1004,"未找到退货数据");
  279. }
  280. $info["is_del"]=1;
  281. $info["updatetime"]=date("Y-m-d H:i:s");
  282. $del = Db::name("sale_return")->save($info);
  283. if($del){
  284. $ste = ["order_code"=>$code,"status"=>0,"action_remark"=>'',"action_type"=>"delete"];
  285. ActionLog::logAdd($this->post['token'],$ste,$info['order_type'] == 2?"ZXTHD":"QRTHD",0,$ste);
  286. $process=["order_code"=>$code,"order_id"=>$info['id'],"order_status"=>0,"order_type"=>$info['order_type'] == 2?"ZXTHD":"QRTHD"];
  287. ProcessOrder::workdel($process);
  288. return app_show(0,"删除成功");
  289. }else{
  290. return error_show(1004,"删除失败");
  291. }
  292. }
  293. /**审核
  294. * @return \think\response\Json|void
  295. * @throws \think\db\exception\DataNotFoundException
  296. * @throws \think\db\exception\DbException
  297. * @throws \think\db\exception\ModelNotFoundException
  298. */
  299. public function exam(){
  300. $code = isset($this->post['returnCode']) && $this->post['returnCode'] !=="" ? trim($this->post['returnCode'])
  301. :"";
  302. if($code==""){
  303. return error_show(1004,"参数returnCode不能为空");
  304. }
  305. $info = Db::name("sale_return")->where(["returnCode"=>$code,"is_del"=>0])->find();
  306. if(empty($info)){
  307. return error_show(1004,"未找到退货数据");
  308. }
  309. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  310. :"";
  311. if($status===""){
  312. return error_show(1004,"参数status不能为空");
  313. }
  314. $remark = isset($this->post['remark']) && $this->post['remark'] !="" ? trim($this->post['remark']) :"";
  315. $var = $info['status'];
  316. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  317. $apply_id =GetUserInfo($token);
  318. if(empty($apply_id)||$apply_id['code']!=0){
  319. return error_show(1002,"申请人数据不存在");
  320. }
  321. $rid= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  322. $rname= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  323. $orderinfo = Db::name("sale")->where(["orderCode"=>$info["orderCode"]])->find();
  324. if($orderinfo==false){
  325. return error_show(1004,"未找到订单数据");
  326. }
  327. if($status==4){
  328. $cgd=Db::name("order_num")->where(['orderCode'=>$info["orderCode"]])->order("send_num asc")->column('cgdNo');
  329. if(empty($cgd)){
  330. return error_show(1004,"未找到商品库存数据");
  331. }
  332. $wsm =Db::name("purchease_order")->where(["cgdNo"=>$cgd])->column("wsm_code");
  333. if(empty($wsm)){
  334. return error_show(1004,"未找到商品仓库库存数据");
  335. }
  336. $good_stock = Db::name("good_stock")->where(["spuCode"=>$orderinfo['good_code'],"wsm_code"=>$wsm,"is_del"=>0])
  337. ->select()->toArray();
  338. if(empty($good_stock)){
  339. return error_show(1004,"未找到商品库存数据");
  340. }
  341. }
  342. if($status==3){
  343. $is_th =isset($this->post['is_th'])&&$this->post['is_th']!=="" ? intval($this->post['is_th']):"";
  344. if($is_th===""){
  345. return error_show(1004,"参数is_th不能为空");
  346. }
  347. $return_wsm =isset($this->post['return_wsm'])&&$this->post['return_wsm']!=="" ? intval($this->post['return_wsm']):"";
  348. if($return_wsm===""){
  349. return error_show(1004,"参数return_wsm 不能为空");
  350. }
  351. }
  352. Db::startTrans();
  353. try{
  354. $temp= $info['status'];
  355. $info['status'] =$status;
  356. $remark!=""? $info['remark'] =$remark:"";
  357. $info["updatetime"]=date("Y-m-d H:i:s");
  358. $up = Db::name("sale_return")->save($info);
  359. if($up){
  360. $process=["order_code"=>$code,"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>$info['order_type'] == 2?"ZXTHD":"QRTHD"];
  361. ProcessOrder::AddProcess($this->post['token'],$process);
  362. $ste = ["order_code"=>$code,"status"=>$temp,"action_remark"=>'',"action_type"=>"status"];
  363. ActionLog::logAdd($this->post['token'],$ste,$info['order_type'] == 2?"ZXTHD":"QRTHD",$status,$info);
  364. if($status==4){
  365. $orderinfo['wsend_num']-=$info['num'];
  366. $orderinfo['th_num']+=$info['num'];
  367. $orderinfo['send_status'] = $orderinfo['send_num'] == 0 ? 1 : $orderinfo['wsend_num'] == 0 ? 3 : 2;
  368. $orderinfo['status'] = $orderinfo['send_num'] == 0 ? 3 : $orderinfo['wsend_num'] == 0 ? 5 : 4;
  369. $orderinfo['updatetime']=date("Y-m-d H:i:s");
  370. $return = Db::name("sale")->save($orderinfo);
  371. if($return==false){
  372. Db::rollback();
  373. return error_show(1004,"更新失败");
  374. }
  375. foreach ($good_stock as $value){
  376. if($value['wait_out_stock']>=$info['num']){
  377. $value['usable_stock']+=$info['num'];
  378. $value['wait_out_stock']-=$info['num'];
  379. $value['updatetime']=date("Y-m-d H:i:s");
  380. $info["num"]=0;
  381. }else{
  382. $value['usable_stock']+=$value['wait_out_stock'];
  383. $value['wait_out_stock']=0;
  384. $value['updatetime']=date("Y-m-d H:i:s");
  385. $info["num"]-=$value['wait_out_stock'];
  386. }
  387. $stock = Db::name("good_stock")->save($value);
  388. if($stock==false){
  389. Db::rollback();
  390. return error_show(1004,"更新失败");
  391. }
  392. if($info['num']==0){
  393. break;
  394. }
  395. }
  396. }
  397. Db::commit();
  398. return app_show(0,"更新成功");
  399. }
  400. Db::rollback();
  401. return error_show(1004,"更新失败");
  402. }catch (\Exception $e){
  403. Db::rollback();
  404. return error_show(1004,"更新失败");
  405. }
  406. }
  407. public function zxcreate(){
  408. $ordeCode = isset($this->post['orderCode']) &&$this->post['orderCode']!=''?trim($this->post['orderCode']) :"";
  409. if($ordeCode==''){
  410. return error_show(1004,"参数orderCode 不能为空");
  411. }
  412. $order= Db::name("sale")->where(["orderCode"=>$ordeCode,"is_del"=>0])->find();
  413. if(empty($order)){
  414. return error_show(1005,"未找到订单数据");
  415. }
  416. $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
  417. if($errorCode==''){
  418. return error_show(1004,"参数errorCode 不能为空");
  419. }
  420. $error =Db::name('result_info')->where(["result_code"=>$errorCode,"is_del"=>0])->find();
  421. if(empty($error)){
  422. return error_show(1005,"未找到退货原因数据");
  423. }
  424. $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
  425. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  426. if($token==''){
  427. return error_show(105,"参数token不能为空");
  428. }
  429. $user =GetUserInfo($token);
  430. if(empty($user)||$user['code']!=0){
  431. return error_show(1002,"申请人数据不存在");
  432. }
  433. $rm= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  434. $ri= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  435. $num = isset($this->post['num'])&&$this->post['num']!='' ? intval($this->post['num']):"";
  436. if($num==''){
  437. return error_show(1005,"参数num不能为空");
  438. }
  439. if($order['wsend_num']<$num){
  440. return error_show(1002,"仓库未发货数量不足退货");
  441. }
  442. $returnCode=makeNo("RXS");
  443. Db::startTrans();
  444. try{
  445. $in = [
  446. "returnCode"=>$returnCode,
  447. "orderCode"=>$ordeCode,
  448. "good_code"=>$order['good_code'],
  449. "good_name"=>$order['good_name'],
  450. "apply_id"=>$rm,
  451. "apply_name"=>$ri,
  452. "error_code"=>$errorCode,
  453. "num"=>$num,
  454. "remark"=>$remark,
  455. "order_type"=>2,
  456. "status"=>0,
  457. "is_del"=>0,
  458. "addtime"=>date("Y-m-d H:i:s"),
  459. "updatetime"=>date("Y-m-d H:i:s")
  460. ];
  461. $create = Db::name("sale_return")->insert($in,true);
  462. if($create>0) {
  463. $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>0,"order_type"=>'ZXTHD'];
  464. ProcessOrder::AddProcess($this->post['token'],$process);
  465. $ste = ["order_code"=>$returnCode,"status"=>0,"action_remark"=>'',
  466. "action_type"=>"create"];
  467. ActionLog::logAdd($this->post['token'],$ste,"ZXTHD",3,$in);
  468. if ($order['send_type'] == 1) {
  469. $wsend = Db::name("order_out")->where(['orderCode' => $ordeCode, "status" => 1, "order_type"
  470. =>2])->select();
  471. // ->save(["status" => 0, "updatetime" => date("Y-m-d H:i:s")]);
  472. if(!empty($wsend)){
  473. foreach ($wsend as $value){
  474. $tt = $value['status'];
  475. $value['status']=0;
  476. $value['updatetime']=date("Y-m-d H:i:s");
  477. $up =Db::name("order_out")->save($value);
  478. if($up){
  479. $process=["order_code"=> $value['outCode'],"order_id"=>$value['id'],"order_status"=>0,"order_type"=>'CKD'];
  480. ProcessOrder::AddProcess($this->post['token'],$process);
  481. $ste = ["order_code"=>$value['outCode'],"status"=>$tt,"action_remark"=>'',"action_type"=>"status"];
  482. ActionLog::logAdd($this->post['token'],$ste,"CKD",0,$value);
  483. }else{
  484. Db::rollback();
  485. return error_show(1005,"退货单新建失败");
  486. }
  487. }
  488. }
  489. }
  490. Db::commit();
  491. return error_show(0,"退货单新建成功");
  492. }
  493. Db::rollback();
  494. return error_show(1005,"退货单新建失败");
  495. }catch (\Exception $e){
  496. Db::rollback();
  497. return error_show(1005,$e->getMessage());
  498. }
  499. }
  500. }