Reorder.php 28 KB

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