Reorder.php 24 KB

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