After.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. class After 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. $outCode = isset($this->post['outCode']) &&$this->post['outCode']!=''?trim($this->post['outCode']) :"";
  17. if($outCode==''){
  18. return error_show(1004,"参数outCode 不能为空");
  19. }
  20. $orderout= Db::name("order_out")->where(["outCode"=>$outCode])->find();
  21. if(empty($orderout)){
  22. return error_show(1005,"未找到订单数据");
  23. }
  24. $oder= Db::name("sale")->where(["orderCode"=>$orderout['orderCode'],"is_del"=>0])->find();
  25. if(empty($oder)){
  26. return error_show(1005,"未找到订单数据");
  27. }
  28. $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
  29. if($outCode==''){
  30. return error_show(1004,"参数errorCode 不能为空");
  31. }
  32. $error =Db::name('result_info')->where(["result_code"=>$errorCode,"is_del"=>0])->find();
  33. if(empty($error)){
  34. return error_show(1005,"未找到退货原因数据");
  35. }
  36. if($orderout['status']==1){
  37. $num=$orderout['send_num'];
  38. $orde_status = 1;
  39. }else{
  40. $orde_status = 2;
  41. $num =isset($this->post['num']) &&$this->post['num']!=''?intval($this->post['num']) :"";
  42. if($num==""){
  43. return error_show(1004,"参数 num 不能为空或零");
  44. }
  45. }
  46. $order_type =isset($this->post['order_type']) &&$this->post['order_type']!=''?intval($this->post['order_type']) :"";
  47. // if($order_type==""){
  48. // return error_show(1004,"参数 order_type 不能为空或零");
  49. // }
  50. $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
  51. $except_code =isset($this->post['except_code']) &&$this->post['except_code']!=''?trim($this->post['except_code']) :"";
  52. $img = isset($this->post['img']) &&$this->post['img']!=''?trim($this->post['img']) :"";
  53. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  54. if($token==''){
  55. return error_show(1005,"参数token不能为空");
  56. }
  57. $user =GetUserInfo($token);
  58. if(empty($user)||$user['code']!=0){
  59. return error_show(1002,"申请人数据不存在");
  60. }
  61. $rm= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  62. $ri= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  63. $returnCode=makeNo("RXS");
  64. Db::startTrans();
  65. try{
  66. $in = [
  67. "returnCode"=>$returnCode,
  68. "outCode"=>$outCode,
  69. "orderCode"=> $oder['orderCode'],
  70. "good_code"=>$oder['good_code'],
  71. "good_name"=>$oder['good_name'],
  72. "customer_code"=>$oder['customer_code'],
  73. "apply_id"=>$rm,
  74. "apply_name"=>$ri,
  75. "order_status"=>$orde_status,
  76. // 'total_num'=>$oder['send_num'],
  77. 'total_num'=>$orderout['send_num'],
  78. "error_code"=>$errorCode,
  79. "error_num"=>$num,
  80. "error_img"=>$img,
  81. "error_msg"=>$error['result'],
  82. "error_remark"=>$remark,
  83. "remark"=>'',
  84. "except_code"=>$except_code,
  85. "order_type"=>$orderout['order_type'],
  86. "status"=>0,
  87. "is_del"=>0,
  88. "addtime"=>date("Y-m-d H:i:s"),
  89. "updatetime"=>date("Y-m-d H:i:s")
  90. ];
  91. $create = Db::name("order_return")->insert($in,true);
  92. $orde = ["order_code"=>$returnCode,"status"=>$in['status'],"action_remark"=>'',"action_type"=>"create"];
  93. ActionLog::logAdd($this->post['token'],$orde,$orderout['order_type']==1?'SHD':"ZXSHD",0,$orde);
  94. if($create>0){
  95. $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>0,"order_type"=>$orderout['order_type']==1?'SHD':"ZXSHD"];
  96. ProcessOrder::AddProcess($token,$process);
  97. Db::commit();
  98. return app_show(0,"售后申请单新建成功");
  99. }
  100. Db::rollback();
  101. return error_show(1005,"售后申请单新建失败");
  102. }catch (\Exception $e){
  103. Db::rollback();
  104. return error_show(1005,$e->getMessage());
  105. }
  106. }
  107. public function list(){
  108. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  109. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  110. $where =[['a.is_del',"=",0]];
  111. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  112. if($bkcode!=""){
  113. $where[]=['a.returnCode',"like", "%{$bkcode}%"];
  114. }
  115. $out = isset($this->post['outCode']) && $this->post['outCode']!="" ? trim($this->post['outCode']):"";
  116. if($out!=""){
  117. $where[]=['a.outCode',"like", "%{$out}%"];
  118. }
  119. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  120. if($status!==""){
  121. $where[]=['a.status',"=", $status];
  122. }
  123. $order_type = isset($this->post['order_type']) && $this->post['order_type']!=="" ? intval($this->post['order_type']):"";
  124. if($order_type!==""){
  125. $where[]=['a.order_type',"=", $order_type];
  126. }
  127. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode'])
  128. :"";
  129. if($orderCode!=""){
  130. $where[]=['a.orderCode',"like", "%{$orderCode}%"];
  131. }
  132. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code'])
  133. :"";
  134. if($good_code!=""){
  135. $where[]=['a.good_code',"like", "%{$good_code}%"];
  136. }
  137. $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name'])
  138. :"";
  139. if($good_name!=""){
  140. $where[]=['a.good_name',"like", "%{$good_name}%"];
  141. }
  142. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code']!="" ? trim($this->post['customer_code'])
  143. :"";
  144. if($customer_code!=""){
  145. $where[]=['a.customer_code',"like", "%{$customer_code}%"];
  146. }
  147. $except_code = isset($this->post['except_code']) && $this->post['except_code']!="" ? trim($this->post['except_code']):"";
  148. if($except_code!=""){
  149. $where[]=['a.except_code',"=", $except_code];
  150. }
  151. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name'])
  152. :"";
  153. if($apply_name!=""){
  154. $where[]=['a.apply_name',"like", "%{$apply_name}%"];
  155. }
  156. $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
  157. if($start!==""){
  158. $where[]=['a.addtime',">=", $start];
  159. }
  160. $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
  161. if($end!==""){
  162. $where[]=['a.addtime',"<=", $end];
  163. }
  164. $count=Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where
  165. ($where)->count();
  166. $total = ceil($count/$size);
  167. $page = $total>=$page ? $page :$total;
  168. $list =Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where($where)
  169. ->field("a.*,b.return_wsm,b.contactor,b.mobile,b.addr,b.addr_code,b.post_code,b.post_company,b.post_fee,b.gys_remark")->page($page,$size)
  170. ->order("addtime desc")->select();
  171. $data=[];
  172. foreach ($list as $value){
  173. $customer = Db::name("customer_info")->where(["companyNo"=>$value['customer_code']])->find();
  174. $value['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  175. $data[]=$value;
  176. }
  177. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  178. }
  179. /**
  180. * @return \think\response\Json|void
  181. * @throws \think\db\exception\DataNotFoundException
  182. * @throws \think\db\exception\DbException
  183. * @throws \think\db\exception\ModelNotFoundException
  184. */
  185. public function info(){
  186. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  187. if($bkcode==""){
  188. return error_show(1005,"参数returnCode 不能为空");
  189. }
  190. $info = Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")
  191. ->field("a.*,b.return_wsm,b.contactor,b.mobile,b.addr,b.addr_code,b.post_code,b.post_company,b.post_fee,b.gys_remark")
  192. ->where(['a.returnCode'=>$bkcode])->find();
  193. if(empty($info)){
  194. return error_show(1005,"未找到售后数据");
  195. }
  196. $orderinfo = Db::name("sale")->where(["orderCode"=>$info["orderCode"]])->find();
  197. $info['origin_price']=$orderinfo['origin_price'];
  198. $info['sale_price']=$orderinfo['sale_price'];
  199. $info['total_price']=sprintf("%1\$.2f",$orderinfo['sale_price']*$info['error_num']);
  200. $goon = Db::name('good')->alias('b')->join("good_type a", "a.good_code=b.good_code", "left")
  201. ->where(['a.type_code' => $info['good_code']])->find();
  202. if (empty($goon)) {
  203. return error_show(1003, "未找到商品数据");
  204. }
  205. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  206. $info["addr_cn"]=GetAddr($info['addr_code']);
  207. $info["addr_code"]=json_decode($info['addr_code'],true);
  208. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  209. $info['out_num'] = isset($out['send_num'])?$out['send_num']:'';
  210. $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
  211. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  212. ->where(["a.wsm_code"=>$info['return_wsm']])->field("a.name as wsm_name,b.name,b.code,a.wsm_code")->find();
  213. $info['wsm_code'] =isset($wsmcode['wsm_code']) ? $wsmcode['wsm_code']:"";
  214. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  215. $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  216. $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  217. $info['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  218. $info['can']=$int;
  219. return app_show(0,"获取成功",$info);
  220. }
  221. public function status(){
  222. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  223. if($bkcode==""){
  224. return error_show(1005,"参数returnCode 不能为空");
  225. }
  226. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  227. if(empty($info)){
  228. return error_show(1005,"未找到售后数据");
  229. }
  230. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status'])
  231. :"";
  232. if($status===""){
  233. return error_show(1005,"参数status 不能为空");
  234. }
  235. $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
  236. if(empty($orde)){
  237. return error_show(1005,"未找到出库单数据");
  238. }
  239. $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
  240. if($remark!=''){
  241. $info['remark'] =$remark;
  242. }
  243. $status = $info['order_status']==1&&$info['order_type']==1 && $status==1?4:$status;
  244. Db::startTrans();
  245. try{
  246. $var=$info['status'];
  247. $info['status']=$status;
  248. $info['updatetime']=date("Y-m-d H:i:s");
  249. $up =Db::name("order_return")->save($info);
  250. if($up){
  251. if($info['order_status']==1&&$info['order_type']==1 && $status==4){
  252. $orderout= Db::name("order_out")->where($orde)->save(['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  253. $order = ["order_code"=>$orde['outCode'],"status"=>$orde['status'],"action_remark"=>'',"action_type"=>"edit"];
  254. ActionLog::logAdd($this->post['token'],$order,$orde['order_type']==1?'CKD':"ZXCKD", 3,['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  255. $process=["order_code"=>$orde['outCode'],"order_id"=>$orde['id'],"order_status"=>3,"order_type"=>$orde['order_type']==1?'CKD':"ZXCKD"];
  256. ProcessOrder::AddProcess($this->post['token'],$process);
  257. if($orderout){
  258. Db::commit();
  259. return app_show(0,"更新成功");
  260. }else{
  261. Db::rollback();
  262. return error_show(1004,"更新失败");
  263. }
  264. }
  265. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  266. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD", $info['status'],$this->post);
  267. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  268. ProcessOrder::AddProcess($this->post['token'],$process);
  269. Db::commit();
  270. return app_show(0,"更新成功");
  271. }else{
  272. Db::rollback();
  273. return error_show(1004,"更新失败");
  274. }
  275. }catch (\Exception $e){
  276. Db::rollback();
  277. return error_show(1004,$e->getMessage());
  278. }
  279. }
  280. /**
  281. * @return \think\response\Json|void
  282. * @throws \think\db\exception\DataNotFoundException
  283. * @throws \think\db\exception\DbException
  284. * @throws \think\db\exception\ModelNotFoundException
  285. */
  286. public function postfeed(){
  287. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  288. if($bkcode==""){
  289. return error_show(1005,"参数returnCode 不能为空");
  290. }
  291. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  292. if(empty($info)){
  293. return error_show(1005,"未找到售后数据");
  294. }
  295. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor']) :"";
  296. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  297. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  298. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ?
  299. $this->post['addr_code']:"";
  300. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  301. if($wsm_code==""){
  302. return error_show(1005,"参数 wsm_code不能为空");
  303. }
  304. // var_dump($contactor);
  305. if($info['is_th']==0&&$info['order_type']==1) {
  306. $wsm = Db::name("warehouse_info")->where(["wsm_code" => $wsm_code])->find();
  307. if (empty($wsm)) {
  308. return error_show(1005, "未找到仓库数据");
  309. }
  310. $sm = Db::name("warehouse_addr")->where(["wsm_code" => $wsm_code,"is_del"=>0])->find();
  311. // var_dump(Db::name("warehouse_addr")->getLastSql());
  312. $contactor==""?(isset($sm['wsm_name']) ? $contactor=$sm['wsm_name']:""):"";
  313. $sm['wsm_name'] =isset($sm['wsm_name']) ? $sm['wsm_name']:"";
  314. $mobile==""?(isset($sm['wsm_mobile']) ? $mobile=$sm['wsm_mobile']:""):"";
  315. $sm['wsm_mobile'] =isset($sm['wsm_mobile']) ? $sm['wsm_mobile']:"";
  316. $addr==""?(isset($sm['wsm_addr']) ? $addr=$sm['wsm_addr']:""):"";
  317. $sm['wsm_addr'] =isset($sm['wsm_addr']) ? $sm['wsm_addr']:"";
  318. $addr_code==""?(isset($sm['addr_code']) ? $addr=$sm['addr_code']:""):"";
  319. $sm['addr_code'] =isset($sm['addr_code']) ? $sm['addr_code']:"";
  320. }
  321. //var_dump($contactor);
  322. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  323. if($info['is_th']==1 && $info['order_type']==1){
  324. if($contactor==''){
  325. return error_show(1005,"参数 contactor 不能为空");
  326. }
  327. if($mobile==''){
  328. return error_show(1005,"参数 mobile 不能为空");
  329. }
  330. if($addr==''){
  331. return error_show(1005,"参数 addr 不能为空");
  332. }
  333. if($addr_code==''){
  334. return error_show(1005,"参数 addr_code 不能为空");
  335. }
  336. if($addr_code!==''&&is_array($addr_code)){
  337. $addrs=[];
  338. $addrs['provice_code'] = $addr_code[0];
  339. $addrs['city_code'] = $addr_code[1];
  340. $addrs['area_code'] = $addr_code[2];
  341. $addr_code = json_encode($addrs);
  342. }
  343. }
  344. Db::startTrans();
  345. try{
  346. $var=$info['status'];
  347. $info['status']=$info['order_type']==1?3:4;
  348. $info['remark']=$remark;
  349. $info['updatetime']=date("Y-m-d H:i:s");
  350. $up =Db::name("order_return")->save($info);
  351. if($up){
  352. // var_dump($contactor);
  353. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  354. if(empty($returninfo)){
  355. $returninfo=[
  356. "returnCode"=>$bkcode,
  357. "return_wsm"=>$wsm_code,
  358. "contactor"=>$contactor,
  359. "mobile"=>$mobile ,
  360. "addr"=>$addr,
  361. "addr_code"=>$addr_code,
  362. "addtime"=>date("Y-m-d H:i:s")
  363. ];
  364. }else{
  365. $returninfo['return_wsm'] = $wsm_code;
  366. //if($info['is_th']==1 && $info['order_type']==1) {
  367. $contactor !==""? $returninfo['contactor'] = $contactor:"";
  368. $mobile!==""?$returninfo['mobile'] = $mobile:"";
  369. $addr!==""? $returninfo['addr'] = $addr:"";
  370. $addr_code!==""?$returninfo['addr_code'] = $addr_code:"";
  371. // }
  372. }
  373. // var_dump($contactor);
  374. // var_dump($returninfo);
  375. $in=Db::name("order_returninfo")->save($returninfo);
  376. if($in){
  377. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  378. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD",$info['status'],$order);
  379. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  380. ProcessOrder::AddProcess($this->post['token'],$process);
  381. Db::commit();
  382. return app_show(0,"更新成功");
  383. }
  384. }
  385. Db::rollback();
  386. return error_show(1004,"更新失败");
  387. }catch (\Exception $e){
  388. Db::rollback();
  389. return error_show(1004,$e->getMessage());
  390. }
  391. }
  392. /**
  393. * @return \think\response\Json|void
  394. * @throws \think\db\exception\DataNotFoundException
  395. * @throws \think\db\exception\DbException
  396. * @throws \think\db\exception\ModelNotFoundException
  397. */
  398. public function addpost(){
  399. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  400. if($bkcode==""){
  401. return error_show(1005,"参数returnCode 不能为空");
  402. }
  403. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  404. if(empty($info)){
  405. return error_show(1005,"未找到售后数据");
  406. }
  407. $return_info = Db::name("order_returninfo")->where(['returnCode'=>$bkcode])->find();
  408. if(empty($return_info)){
  409. $return_info=[
  410. "returnCode"=>$bkcode,
  411. "return_wsm"=>'',
  412. "contactor"=>'',
  413. "mobile"=>'',
  414. "addr"=>'',
  415. "addr_code"=>'',
  416. "addtime"=>date("Y-m-d H:i:s"),
  417. "post_company"=>'',
  418. "post_code"=>'',
  419. "post_fee"=>'',
  420. ];
  421. }
  422. $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
  423. if($post_own==''){
  424. return error_show(1005,"参数own不能为空");
  425. }
  426. $info['post_own'] = $post_own;
  427. $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
  428. if($post_company==''){
  429. return error_show(1005,"参数company不能为空");
  430. }
  431. $return_info['post_company'] = $post_company;
  432. $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
  433. if($post_code==''){
  434. return error_show(1005,"参数post_code不能为空");
  435. }
  436. $return_info['post_code'] = $post_code;
  437. $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
  438. if($fee===''){
  439. return error_show(1005,"参数post_fee不能为空");
  440. }
  441. $return_info['post_fee'] = $fee;
  442. Db::startTrans();
  443. try{
  444. $str=$info['status'];
  445. $info['status']=$info['order_type']==1?4:5;
  446. $info['updatetime']=date("Y-m-d H:i:s");
  447. $up =Db::name("order_return")->save($info);
  448. if($up){
  449. $order = ["order_code"=>$info['orderCode'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  450. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD",$info['status'],$order);
  451. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  452. ProcessOrder::AddProcess($this->post['token'],$process);
  453. $in=Db::name("order_returninfo")->save($return_info);
  454. if($in){
  455. $data=[
  456. 'thNo'=>makeNo("TH"),
  457. "orderCode"=>$info['orderCode'],
  458. "order_type"=>$info['order_type'],
  459. "outCode"=>$info['outCode'],
  460. "returnCode"=>$info['returnCode'],
  461. "good_code"=>$info['good_code'],
  462. "good_name"=>$info['good_name'],
  463. "return_wsm"=>$return_info['return_wsm'],
  464. "return_num"=>$info['error_num'],
  465. "contactor"=>$return_info['contactor'],
  466. "mobile"=>$return_info['mobile'],
  467. "addr"=>$return_info['addr'],
  468. "addr_code"=>$return_info['addr_code'],
  469. "return_code"=>$info['error_code'],
  470. "return_msg"=>$info['error_msg'],
  471. "post_fee"=>$return_info['post_fee'],
  472. "post_code"=>$return_info['post_code'],
  473. "post_company"=>$return_info['post_company'],
  474. "customer_code"=>$info['customer_code'],
  475. "addtime"=>date("Y-m-d H:i:s"),
  476. "updatetime"=>date("Y-m-d H:i:s")
  477. ];
  478. $back =Db::name("order_back")->insert($data,true);
  479. if($back>0){
  480. $order = ["order_code"=>$data['thNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  481. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD", 0,$data);
  482. $process=["order_code"=>$data['thNo'],"order_id"=>$back,"order_status"=>0,"order_type"=>$info['order_type']==1?'CKTHD':"ZXCKTHD"];
  483. ProcessOrder::AddProcess($this->post['token'],$process);
  484. Db::commit();
  485. return app_show(0,"更新成功");
  486. }
  487. }
  488. }
  489. Db::rollback();
  490. return error_show(1004,"更新失败");
  491. }catch (\Exception $e){
  492. Db::rollback();
  493. return error_show(1004,$e->getMessage());
  494. }
  495. }
  496. /**
  497. * @return \think\response\Json|void
  498. * @throws \think\db\exception\DataNotFoundException
  499. * @throws \think\db\exception\DbException
  500. * @throws \think\db\exception\ModelNotFoundException
  501. */
  502. public function GysFeed(){
  503. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  504. if($bkcode==""){
  505. return error_show(1005,"参数returnCode 不能为空");
  506. }
  507. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  508. if(empty($info)){
  509. return error_show(1005,"未找到售后数据");
  510. }
  511. $isth = isset($this->post['is_th']) && $this->post['is_th']!="" ? intval($this->post['is_th']):"0";
  512. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  513. :"";
  514. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  515. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  516. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ? $this->post['addr_code']:"";
  517. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  518. if($isth==1){
  519. if($contactor==''){
  520. return error_show(1005,"参数 contactor 不能为空");
  521. }
  522. if($mobile==''){
  523. return error_show(1005,"参数 mobile 不能为空");
  524. }
  525. if($addr==''){
  526. return error_show(1005,"参数 addr 不能为空");
  527. }
  528. // var_dump(isset($this->post['addr_code']) , $this->post['addr_code']!="",!empty($addr_code));
  529. if($addr_code==''){
  530. return error_show(1005,"参数 addr_code 不能为空");
  531. }
  532. if(is_array($addr_code)){
  533. $addrs=[];
  534. $addrs['provice_code'] = $addr_code[0];
  535. $addrs['city_code'] = $addr_code[1];
  536. $addrs['area_code'] = $addr_code[2];
  537. $addr_code = json_encode($addrs);
  538. }
  539. }
  540. $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
  541. if(empty($orde)){
  542. return error_show(1005,"未找到出库单数据");
  543. }
  544. Db::startTrans();
  545. try{
  546. $stat=$info['status'];
  547. $info['status']=$info['order_status']==1?5:3;
  548. $info['is_th']=$isth;
  549. $info['updatetime']=date("Y-m-d H:i:s");
  550. $up =Db::name("order_return")->save($info);
  551. if($up){
  552. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  553. if(empty($returninfo)){
  554. $returninfo=[
  555. "returnCode"=>$bkcode,
  556. "return_wsm"=>'',
  557. "contactor"=>$contactor,
  558. "mobile"=>$mobile ,
  559. "addr"=>$addr,
  560. "addr_code"=>$addr_code,
  561. "gys_remark"=>$remark,
  562. "addtime"=>date("Y-m-d H:i:s")
  563. ];
  564. }else{
  565. $returninfo['return_wsm'] = '';
  566. $returninfo['contactor'] = $contactor;
  567. $returninfo['mobile'] = $mobile;
  568. $returninfo['addr'] = $addr;
  569. $returninfo['gys_remark'] = $remark;
  570. $returninfo['addr_code'] = $addr_code;
  571. }
  572. $in=Db::name("order_returninfo")->save($returninfo);
  573. if($in){
  574. if( $info['order_status']==1&&$info['order_type']==2){
  575. $orderout= Db::name("order_out")->where($orde)->save(['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  576. $order = ["order_code"=>$orde['outCode'],"status"=>$orde['status'],"action_remark"=>'',"action_type"=>"edit"];
  577. ActionLog::logAdd($this->post['token'],$order,$orde['order_type']==1?'CKD':"ZXCKD", 3,
  578. ['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  579. $process=["order_code"=>$orde['outCode'],"order_id"=>$orde['id'],"order_status"=>3,
  580. "order_type"=>$orde['order_type']==1?'CKD':"ZXCKD"];
  581. ProcessOrder::AddProcess($this->post['token'],$process);
  582. if($orderout){
  583. Db::commit();
  584. return app_show(0,"更新成功");
  585. }else{
  586. Db::rollback();
  587. return error_show(1004,"更新失败");
  588. }
  589. }
  590. $order = ["order_code"=>$info['returnCode'],"status"=>$stat,"action_remark"=>'',"action_type"=>"edit"];
  591. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'CKTHD':"ZXCKTHD",3,$order);
  592. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'CKTHD':"ZXCKTHD"];
  593. ProcessOrder::AddProcess($this->post['token'],$process);
  594. Db::commit();
  595. return app_show(0,"更新成功");
  596. }
  597. }
  598. Db::rollback();
  599. return error_show(1004,"更新失败");
  600. }catch (\Exception $e){
  601. Db::rollback();
  602. return error_show(1004,$e->getMessage());
  603. }
  604. }
  605. public function GetWsm(){
  606. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  607. if($bkcode==""){
  608. return error_show(1005,"参数returnCode 不能为空");
  609. }
  610. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  611. if(empty($info)){
  612. return error_show(1005,"未找到售后数据");
  613. }
  614. $list=[];
  615. if($info['is_th']==1){
  616. if($info["order_type"]==1){
  617. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  618. if(empty($out)){
  619. return error_show(1005,"未找到出库单数据");
  620. }
  621. $ware = Db::name("warehouse_info")->alias("a")->leftJoin("warehouse_addr b","a.wsm_code=b.wsm_code and b.status=1 and b.is_del=0")
  622. ->where(["a.status"=>1,"wsm_type"=>1,"a.is_del"=>0,"a.supplierNo"=>$out['wsm_code']])->field("a.wsm_code,a.name,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code")->find();
  623. if(empty($ware)){
  624. return error_show(1005,"未找到仓库数据");
  625. }
  626. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  627. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  628. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  629. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  630. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  631. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  632. $temp['addr_cn'] =GetAddr( $ware['addr_code']);
  633. $list[]=$temp;
  634. }else {
  635. $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->find();
  636. if (empty($returninfo)) {
  637. return error_show(1005, "未找到供应商仓库数据");
  638. }
  639. $data = [];
  640. $data['wsm_code'] = isset($returninfo['return_wsm']) && $returninfo['return_wsm'] != "" ? $returninfo['return_wsm'] : "-";
  641. $data['wsm_name'] = '供应商仓';
  642. $data['supplier_name'] = '供应商';
  643. $data['contactor'] = $returninfo['contactor'];
  644. $data['mobile'] = $returninfo['mobile'];
  645. $data['addr'] = $returninfo['addr'];
  646. $data['addr_cn'] =GetAddr( $returninfo['addr_code']);
  647. $data['addr_code'] = $returninfo['addr_code'];
  648. $list[] = $data;
  649. }
  650. }
  651. $supplier = Db::name("supplier")->where(["is_platform"=>1,"status"=>1,"is_del"=>0])->column("code,name");
  652. if(empty($supplier)){
  653. return error_show(1005,"未找到供应商仓库数据");
  654. }
  655. foreach ($supplier as $value){
  656. $temp=[];
  657. $ware = Db::name("warehouse_info")->alias("a")->leftJoin("warehouse_addr b","a.wsm_code=b.wsm_code and b.status=1 and b.is_del=0")
  658. ->where(["a.wsm_type"=>1,"a.status"=>1,"a.is_del"=>0,"a.supplierNo"=>$value['code']])->field("a.wsm_code,a.name,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code")->find();
  659. if(empty($ware)){
  660. continue;
  661. }
  662. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  663. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  664. $temp['supplier_name']=$value['name'];
  665. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  666. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  667. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  668. $temp['addr_cn'] =GetAddr($ware['addr_code']);
  669. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  670. $list[]=$temp;
  671. }
  672. return app_show(0,"获取成功",$list);
  673. }
  674. }