Reorder.php 24 KB

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