After.php 31 KB

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