Reorder.php 28 KB

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