Orderback.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. <?php
  2. namespace app\Admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\GoodLog;
  5. use app\admin\model\ProcessOrder;
  6. use think\App;
  7. use think\Exception;
  8. use think\facade\Db;
  9. use think\facade\Validate;
  10. //退货单
  11. class Orderback extends \app\BaseController
  12. {
  13. public $post=[];
  14. public function __construct(App $app)
  15. {
  16. parent::__construct($app);
  17. $this->post =$this->request->post();
  18. }
  19. public function list(){
  20. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  21. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  22. $where =[['is_del',"=",0]];
  23. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  24. if($thNo!=""){
  25. $where[]=['thNo',"like", "%{$thNo}%"];
  26. }
  27. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  28. if($status!==""){
  29. // $where['status'] = $status;
  30. $where[]=['status',"=", $status];
  31. }
  32. $post_code= isset($this->post['post_code']) && $this->post['post_code']!="" ? trim($this->post['post_code']):"";
  33. if($post_code!=""){
  34. $where[]=['post_code',"like", "%{$post_code}%"];
  35. }
  36. $post_compay = isset($this->post['post_compay']) && $this->post['post_compay']!="" ? trim($this->post['post_compay']):"";
  37. if($post_compay!=""){
  38. $where[]=['post_company',"=", $post_compay];
  39. }
  40. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code']!="" ? trim($this->post['customer_code']):"";
  41. if($customer_code!=""){
  42. $where[]=['customer_code',"like", "%{$customer_code}%"];
  43. }
  44. $order_code = isset($this->post['order_code']) && $this->post['order_code']!="" ? trim($this->post['order_code']):"";
  45. if($order_code!=""){
  46. $where[]=['orderCode',"like", "%{$order_code}%"];
  47. }
  48. $out_code = isset($this->post['out_code']) && $this->post['out_code']!="" ? trim($this->post['out_code']):"";
  49. if($out_code!=""){
  50. $where[]=['outCode',"like", "%{$out_code}%"];
  51. }
  52. $return_code = isset($this->post['return_code']) && $this->post['return_code']!="" ? trim($this->post['return_code']):"";
  53. if($return_code!=""){
  54. $where[]=['returnCode',"like", "%{$return_code}%"];
  55. }
  56. $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
  57. if($start!==""){
  58. $where[]=['addtime',">=", $start];
  59. }
  60. $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
  61. if($end!==""){
  62. $where[]=['addtime',"<=", $end];
  63. }
  64. $count=Db::name("order_back")->where($where)->count();
  65. $total = ceil($count/$size);
  66. $page = $page >= $total ? $total : $page;
  67. $list = Db::name("order_back")->where($where)->page($page,$size)->order("addtime desc")->select();
  68. $data=[];
  69. foreach ($list as $value){
  70. $value['wsm_name']="";
  71. $value['wsm_supplier']='';
  72. $value['wsm_supplierNo']='';
  73. if($value['return_wsm']!=""){
  74. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  75. ->where(["a.wsm_code"=>$value['return_wsm']])->field("a.name as wsm_name,b.name,b.code")->find();
  76. $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  77. $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  78. $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  79. }
  80. $value['customer_name']='';
  81. if($value['customer_code']!=''){
  82. $customer = Db::name("customer_info")->where(['companyNo'=>$value['customer_code']])->find();
  83. $value['customer_name']=isset($customer['companyName'])?$customer['companyName']:'';
  84. }
  85. $inorder= Db::name("order_backinfo")->where(['thNo'=>$value['thNo'],"is_del"=>0])->select();
  86. $value['child']=empty($inorder)? [] : $inorder;
  87. $data[]=$value;
  88. }
  89. return app_show(0,"获取成功",["list"=>$data ,"count"=>$count]);
  90. }
  91. /**
  92. * @return \think\response\Json|void
  93. * @throws \think\db\exception\DataNotFoundException
  94. * @throws \think\db\exception\DbException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. */
  97. public function info(){
  98. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  99. if($thNo==""){
  100. return error_show(1004,"参数thNo不能为空");
  101. }
  102. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  103. if(empty($info)){
  104. return error_show(1004,"未找到数据");
  105. }
  106. $orderinfo = Db::name("sale")->where(["orderCode"=>$info["orderCode"]])->find();
  107. $info['origin_price']=$orderinfo['origin_price'];
  108. $info['sale_price']=$orderinfo['sale_price'];
  109. $info['order_type']=$orderinfo['order_type'];
  110. $info['total_price']=$orderinfo['total_price'];
  111. $info['companyNo']=$orderinfo['supplierNo'];
  112. $info['company'] = Db::name('business')->where(['companyNo' => $orderinfo['supplierNo'], 'is_del' => 0])->value('company','');
  113. $info['addr_cn']=GetAddr($info['addr_code']);
  114. if($orderinfo['order_type']==3|| $orderinfo['order_type']==4){
  115. $goon = Db::name("good_zixun")->where(["spuCode"=>$orderinfo['good_code'],"is_del"=>0])->find();
  116. }else {
  117. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  118. ->where(['a.skuCode' => $orderinfo['skuCode']])->find();
  119. }
  120. if (empty($goon)) {
  121. return error_show(1003, "未找到商品数据");
  122. }
  123. $retutninfo = Db::name("order_return")->where(['returnCode'=>$info['returnCode']])->find();
  124. $info['apply_id'] = $retutninfo['apply_id'];
  125. $info['apply_name'] = $retutninfo['apply_name'];
  126. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  127. $info['wsm_name']="";
  128. $info['wsm_supplier']='';
  129. $info['wsm_supplierNo']='';
  130. if($info['return_wsm']!=""){
  131. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  132. ->where(["a.wsm_code"=>$info['return_wsm']])->field("a.name as wsm_name,b.name,b.code")->find();
  133. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  134. $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  135. $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  136. }
  137. $inorder= Db::name("order_backinfo")->alias("a")->leftJoin("result_info b","a.error_code=b.result_code")
  138. ->where(['a.thNo'=>$info['thNo'],"a.is_del"=>0])->field("a.*,b.result as error_msg")->select();
  139. $info['child']=empty($inorder)? [] : $inorder;
  140. $info['can']=$int;
  141. //补充仓库名称
  142. $warehouse = Db::name('warehouse_info')
  143. ->alias('wi')
  144. ->where(['wi.is_del' => 0, 'wi.status' => 1])
  145. ->whereIn('wi.wsm_code', [$info['can_sell_wsm'], $info['defective_wsm']])
  146. ->leftJoin('supplier s', 's.code=wi.supplierNo AND s.is_del=0')
  147. ->column('wi.name,wi.supplierNo,s.name supplier', 'wi.wsm_code');
  148. $info['can_sell_wsm_name'] = isset($warehouse[$info['can_sell_wsm']]['name']) ? $warehouse[$info['can_sell_wsm']]['name'] : '';
  149. $info['can_sell_wsm_supplierNo'] = isset($warehouse[$info['can_sell_wsm']]['supplierNo']) ? $warehouse[$info['can_sell_wsm']]['supplierNo'] : '';
  150. $info['can_sell_wsm_supplier'] = isset($warehouse[$info['can_sell_wsm']]['supplier']) ? $warehouse[$info['can_sell_wsm']]['supplier'] : '';
  151. $info['defective_wsm_name'] = isset($warehouse[$info['defective_wsm']]['name']) ? $warehouse[$info['defective_wsm']]['name'] : '';
  152. $info['defective_wsm_supplierNo'] = isset($warehouse[$info['defective_wsm']]['supplierNo']) ? $warehouse[$info['defective_wsm']]['supplierNo'] : '';
  153. $info['defective_wsm_supplier'] = isset($warehouse[$info['defective_wsm']]['supplier']) ? $warehouse[$info['defective_wsm']]['supplier'] : '';
  154. return app_show(0, "获取成功", $info);
  155. }
  156. /**
  157. * @return \think\response\Json|void
  158. * @throws \think\db\exception\DataNotFoundException
  159. * @throws \think\db\exception\DbException
  160. * @throws \think\db\exception\ModelNotFoundException
  161. */
  162. public function check(){
  163. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  164. if($thNo==""){
  165. return error_show(1004,"参数thNo不能为空");
  166. }
  167. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  168. if(empty($info)){
  169. return error_show(1004,"未找到数据");
  170. }
  171. $normal = isset($this->post['normal']) && $this->post['normal']!=="" ? intval($this->post['normal']):"";
  172. if($normal===""){
  173. return error_show(1004,"参数normal不能为空");
  174. }
  175. $errorlist = isset($this->post['errorlist']) && $this->post['errorlist']!=="" ? $this->post['errorlist']:[];
  176. if($info['status']== 2){
  177. return error_show(1002,"退货单已验货");
  178. }
  179. $receive=$normal+array_sum(array_column($errorlist,'error_num'));
  180. $remark = isset($this->post['remark']) && $this->post['remark']!=="" ? trim($this->post['remark']):"";
  181. $info['received_num'] = $receive;
  182. $info['normal_num'] = $normal;
  183. $info['remark'] = $remark;
  184. $str = $info['status'];
  185. $info['status'] =empty($errorlist)?3: 2;
  186. $info['updatetime'] = date("Y-m-d H:i:s");
  187. Db::startTrans();
  188. try{
  189. $up=Db::name("order_back")->save($info);
  190. if($up){
  191. $stn = ["order_code"=>$info['thNo'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  192. ActionLog::logAdd($this->post['token'],$stn,$info['order_type'] == 2?"ZXCKTHD":"CKTHD",2,$info);
  193. $process=["order_code"=>$info['thNo'],"order_id"=>$info['id'],"order_status"=>2,"order_type"=>$info['order_type'] == 2?"ZXCKTHD":"CKTHD"];
  194. ProcessOrder::AddProcess($this->post['token'],$process);
  195. if(empty($errorlist)){
  196. Db::commit();
  197. return app_show(0,'更新成功');
  198. }
  199. foreach($errorlist as $value){
  200. $data=[];
  201. isset($value['id'])&&$value['id']!=''?$data['id']=$value['id']:"";
  202. $data['thNo']=$thNo;
  203. $data['error_num']=$value['error_num'];
  204. $data['error_code']=$value['error_code'];
  205. $data['error_remark']=$value['error_remark'];
  206. $data['is_del']=isset($value['is_del'])?$value['is_del']:0;
  207. isset($value['id'])&&$value['id']!=''? "" : $data['addtime']=date("Y-m-d H:i:s");
  208. $data['updatetime']=date("Y-m-d H:i:s");
  209. $in = Db::name("order_backinfo")->save($data);
  210. if(!$in){
  211. Db::rollback();
  212. return error_show(1005,'更新失败');
  213. }
  214. }
  215. Db::commit();
  216. return app_show(0,'更新成功');
  217. }
  218. Db::rollback();
  219. return error_show(1005,'更新失败');
  220. }catch (\Exception $e){
  221. Db::rollback();
  222. return error_show(1004,$e->getMessage());
  223. }
  224. }
  225. public function CheckExam(){
  226. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  227. if($thNo==""){
  228. return error_show(1004,"参数thNo不能为空");
  229. }
  230. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  231. if(empty($info)){
  232. return error_show(1004,"未找到数据");
  233. }
  234. $errorlist = isset($this->post['errorlist']) && $this->post['errorlist']!=="" ? $this->post['errorlist']:[];
  235. Db::startTrans();
  236. try{
  237. $temp=$info['status'];
  238. $info['status'] =3;
  239. $info['updatetime'] = date("Y-m-d H:i:s");
  240. $up=Db::name("order_back")->save($info);
  241. if($up){
  242. $stn = ["order_code"=>$thNo,"status"=>$temp,"action_remark"=>'',"action_type"=>"edit"];
  243. ActionLog::logAdd($this->post['token'],$stn,$info['order_type'] == 2?"ZXCKTHD":"CKTHD",$info['status'],$stn);
  244. $process=["order_code"=>$info['thNo'],"order_id"=>$info['id'],"order_status"=>3,"order_type"=>$info['order_type'] == 2?"ZXCKTHD":"CKTHD"];
  245. ProcessOrder::AddProcess($this->post['token'],$process);
  246. if(empty($errorlist)){
  247. $up =Db::name("order_backinfo")->where(["thNo"=>$thNo,"is_del"=>0])->save(["status"=>1,
  248. "updatetime"=>date("Y-m-d H:i:s")]);
  249. if($up){
  250. Db::commit();
  251. return app_show(0,'更新成功');
  252. }else{
  253. Db::rollback();
  254. return error_show(1005,'异常记录数据更新失败');
  255. }
  256. }else{
  257. foreach($errorlist as $value){
  258. $temp=Db::name("order_backinfo")->where(['id'=>$value["id"],"is_del"=>0,"thNo"=>$thNo])->find();
  259. if(empty($temp)){
  260. Db::rollback();
  261. return error_show(1005,'异常记录数据未找到');
  262. }
  263. $temp['status']=$value['status'];
  264. $temp['exam_remark']=$value['remark'];
  265. $temp['updatetime']=date("Y-m-d H:i:s");
  266. $com = Db::name("order_backinfo")->save($temp);
  267. if($com==false){
  268. Db::rollback();
  269. return error_show(1005,'异常记录数据更新失败');
  270. }
  271. }
  272. Db::commit();
  273. return app_show(0,'更新成功');
  274. }
  275. }
  276. Db::rollback();
  277. return error_show(1005,'更新失败');
  278. }catch (\Exception $e){
  279. Db::rollback();
  280. return error_show(1004,$e->getMessage());
  281. }
  282. }
  283. public function Exam(){
  284. $thNo = isset($this->post['thNo']) && $this->post['thNo']!="" ? trim($this->post['thNo']):"";
  285. if($thNo==""){
  286. return error_show(1004,"参数thNo不能为空");
  287. }
  288. $info =Db::name("order_back")->where(['thNo'=>$thNo])->find();
  289. if(empty($info)){
  290. return error_show(1004,"未找到数据");
  291. }
  292. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  293. if($status===""){
  294. return error_show(1004,"参数status不能为空");
  295. }
  296. $return_wsm=isset($this->post["return_wsm"])&&$this->post["return_wsm"]!=""?trim($this->post["return_wsm"]):"";
  297. $normal_num=isset($this->post["normal_num"])&&$this->post["normal_num"]!=""?intval($this->post["normal_num"])
  298. :"";
  299. // $defective_wsm=isset($this->post["defective_wsm"])&&$this->post["defective_wsm"]!=""?trim($this->post["defective_wsm"]):"";
  300. // $defective_num=isset($this->post["defective_num"])&&$this->post["defective_num"]!==""?intval($this->post["defective_num"]):"";
  301. // $loss_num=isset($this->post["loss_num"])&&$this->post["loss_num"]!=""?intval($this->post["loss_num"]):"";
  302. if($status==4){
  303. // if($defective_num===""){
  304. // return error_show(1004,"参数defective_num不能为空");
  305. // }
  306. // if($loss_num===""){
  307. // return error_show(1004,"参数loss_num不能为空");
  308. // }
  309. if($normal_num===""){
  310. return error_show(1004,"参数normal_num不能为空");
  311. }
  312. // if($defective_wsm===""){
  313. // return error_show(1004,"参数defective_wsm不能为空");
  314. // }
  315. if($return_wsm===""){
  316. return error_show(1004,"参数return_wsm不能为空");
  317. }
  318. $info['return_wsm']=$return_wsm;
  319. $info['normal_num']=$normal_num;
  320. // $info['loss_num']=$loss_num;//order_back表里没有这三个字段,不知道是干嘛的
  321. // $info['defective_wsm']=$defective_wsm;
  322. // $info['defective_num']=$defective_num;
  323. }
  324. $remark= isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  325. Db::startTrans();
  326. try{
  327. $var = $info['status'];
  328. $info['status'] =$status;
  329. $info['remark'] =$remark;
  330. $info['updatetime'] = date("Y-m-d H:i:s");
  331. $up=Db::name("order_back")->save($info);
  332. if($up){
  333. $stn = ["order_code"=>$thNo,"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  334. ActionLog::logAdd($this->post['token'],$stn,$info['order_type'] == 2?"ZXCKTHD":"CKTHD",$info['status'],$stn);
  335. $process=["order_code"=>$info['thNo'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>$info['order_type'] == 2?"ZXCKTHD":"CKTHD"];
  336. ProcessOrder::AddProcess($this->post['token'],$process);
  337. Db::commit();
  338. return app_show(0,'更新成功');
  339. }
  340. Db::rollback();
  341. return error_show(1005,'更新失败');
  342. }catch (\Exception $e){
  343. Db::rollback();
  344. return error_show(1004,$e->getMessage());
  345. }
  346. }
  347. //新写一个退货接口
  348. public function ExamNew()
  349. {
  350. $param = $this->request->only(['thNo', 'status', 'status_remark', 'can_sell_wsm' => '', 'can_sell_num' => 0, 'defective_wsm' => '', 'defective_num' => 0, 'loss_num' => 0], 'post', 'trim');
  351. $val = Validate::rule(['thNo|退货编码' => 'require', 'status|状态' => 'require|number|in:4,2,1', 'status_remark|备注' => 'checkRemark:']);
  352. $val->extend('checkRemark', function ($val, $rule, $data) {
  353. return $data['status'] == 4 ? true : (empty($val) ? '请填写备注' : true);
  354. });
  355. if (!$val->check($param)) return error_show(1004, $val->getError());
  356. Db::startTrans();
  357. try {
  358. $info = Db::name("order_back")
  359. ->field('id,order_type,status,outCode,good_code,return_num')
  360. ->where(['thNo' => $param['thNo'], 'is_del' => 0])
  361. ->find();
  362. if (empty($info)) throw new Exception('未找到数据');
  363. if($param['can_sell_num']!=0&& $param['can_sell_wsm']!=''){
  364. $stock = Db::name("good_stock")->where(["spuCode"=>$info['good_code'],'wsm_code'=>$param['can_sell_wsm']])->find();
  365. if(empty($stock)) {
  366. $stock=[
  367. "spuCode"=>$info['good_code'],
  368. "wsm_code"=>$param['can_sell_wsm'],
  369. "usable_stock"=>0,
  370. "wait_out_stock"=>0,
  371. "wait_in_stock"=>0,
  372. "total_stock"=>0,
  373. "addtime"=>date("Y-m-d H:i:s"),
  374. "updatetime"=>date("Y-m-d H:i:s"),
  375. ];
  376. // $order = ["order_code"=>$info['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"create"];
  377. }else{
  378. // $order = ["order_code"=>$info['spuCode'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
  379. }
  380. $stock['usable_stock']+=$param['can_sell_num'];
  381. $stock['updatetime']=date("Y-m-d H:i:s");
  382. $st_up = Db::name("good_stock")->save($stock);
  383. if($st_up==false){
  384. return error_show(1005,'可售商品入库失败');
  385. }
  386. $good_data=['good_log_code'=>$param['thNo'],"stock_id"=>isset($stock['id'])? $stock['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,'stock'=>$param['can_sell_num'],"stock_name"=>"usable_stock"];
  387. GoodLog::LogAdd($this->post['token'],$good_data,'RKTHD');
  388. }
  389. if($param['defective_num']!=0&& $param['defective_wsm']!=''){
  390. $defective = Db::name("good_stock")->where(["spuCode"=>$info['good_code'],'wsm_code'=>$param['defective_wsm']])->find();
  391. if(empty($defective)) {
  392. $defective=[
  393. "spuCode"=>$info['good_code'],
  394. "wsm_code"=>$param['defective_wsm'],
  395. "usable_stock"=>0,
  396. "wait_out_stock"=>0,
  397. "wait_in_stock"=>0,
  398. "total_stock"=>0,
  399. "addtime"=>date("Y-m-d H:i:s"),
  400. "updatetime"=>date("Y-m-d H:i:s"),
  401. ];
  402. $order = ["order_code"=>$info['good_code'],"status"=>1,"action_remark"=>'', "action_type"=>"create"];
  403. }else{
  404. $order = ["order_code"=>$info['good_code'],"status"=>1,"action_remark"=>'', "action_type"=>"edit"];
  405. }
  406. $defective['usable_stock']+=$param['defective_num'];
  407. $defective['updatetime'] = date("Y-m-d H:i:s");
  408. $upd= Db::name("good_stock")->save($defective);
  409. if($upd==false){
  410. Db::rollback();
  411. return error_show(1005,'次品商品入库失败');
  412. }
  413. $good_data=['good_log_code'=>$param['thNo'],"stock_id"=>isset($defective['id'])? $defective['id']:Db::name("good_stock")->getLastInsID(),"type"=>1,'stock'=>$param['defective_num'],"stock_name"=>"usable_stock"];
  414. GoodLog::LogAdd($this->post['token'],$good_data,'RKTHD');
  415. }
  416. // if($info['is_receive']!=1){
  417. // $send=Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  418. // if($send==false){
  419. // Db::rollback();
  420. // return error_show(1005,'未找到对应的发货单');
  421. // }
  422. // $stock_send = Db::name("good_stock")->where(["spuCode"=>$info['good_code'],'wsm_code'=>$send['wsm_code']])->find();
  423. // if($stock_send==false){
  424. // Db::rollback();
  425. // return error_show(1004,'未找到商品库存数据');
  426. // }
  427. //
  428. //// $stock_send['intra_stock']-=$info['return_num'];
  429. // $stock_send['updatetime']=date("Y-m-d H:i:s");
  430. // $st_up = Db::name("good_stock")->save($stock_send);
  431. // if($st_up==false){
  432. // return error_show(1005,'可售商品入库失败');
  433. // }
  434. // $good_data=['good_log_code'=>$param['thNo'],"stock_id"=>$stock_send['id'],"type"=>2,'stock'=>$info['return_num'],"stock_name"=>"intra_stock"];
  435. // GoodLog::LogAdd($this->post['token'],$good_data,'RKTHD');
  436. // }
  437. $update_data = ['status' => $param['status'], 'updatetime' => date('Y-m-d H:i:s')];
  438. //status==4通过,其他值表示驳回
  439. if ($param['status'] != 4) $update_data['status_remark'] = $param['status_remark'];
  440. else {
  441. $update_data['can_sell_wsm'] = $param['can_sell_wsm'];
  442. $update_data['can_sell_num'] = $param['can_sell_num'];
  443. $update_data['defective_wsm'] = $param['defective_wsm'];
  444. $update_data['defective_num'] = $param['defective_num'];
  445. $update_data['loss_num'] = $param['loss_num'];
  446. }
  447. $res = Db::name("order_back")
  448. ->where(['id' => $info['id']])
  449. ->update($update_data);
  450. if ($res) {
  451. $stn = ["order_code" => $param['thNo'], "status" => $param['status'], "action_remark" => '', "action_type" => "edit"];
  452. ActionLog::logAdd($this->post['token'], $stn, $info['order_type'] == 2 ? "ZXCKTHD" : "CKTHD", $info['status'], $stn);
  453. $process = ["order_code" => $param['thNo'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => $info['order_type'] == 2 ? "ZXCKTHD" : "CKTHD"];
  454. ProcessOrder::AddProcess($this->post['token'], $process);
  455. Db::commit();
  456. return app_show(0, '操作成功');
  457. } else throw new Exception('操作失败');
  458. } catch (Exception $exception) {
  459. Db::rollback();
  460. return error_show(1005, $exception->getMessage());
  461. }
  462. }
  463. }