After.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\facade\Db;
  5. class After extends \app\BaseController
  6. {
  7. public $post=[];
  8. public function __construct(App $app)
  9. {
  10. parent::__construct($app);
  11. $this->post =$this->request->post();
  12. }
  13. public function create(){
  14. $outCode = isset($this->post['outCode']) &&$this->post['outCode']!=''?trim($this->post['outCode']) :"";
  15. if($outCode==''){
  16. return error_show(1004,"参数outCode 不能为空");
  17. }
  18. $order= Db::name("order_out")->where(["outCode"=>$outCode])->find();
  19. if(empty($order)){
  20. return error_show(1005,"未找到订单数据");
  21. }
  22. $order= Db::name("sale")->where(["orderCode"=>$order['orderCode'],"is_del"=>0])->find();
  23. if(empty($order)){
  24. return error_show(1005,"未找到订单数据");
  25. }
  26. $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
  27. if($outCode==''){
  28. return error_show(1004,"参数errorCode 不能为空");
  29. }
  30. $error =Db::name('result_info')->where(["result_code"=>$errorCode,"is_del"=>0])->find();
  31. if(empty($error)){
  32. return error_show(1005,"未找到退货原因数据");
  33. }
  34. $num =isset($this->post['num']) &&$this->post['num']!=''?intval($this->post['num']) :"";
  35. if($num==""){
  36. return error_show(1004,"参数 num 不能为空或零");
  37. }
  38. $order_type =isset($this->post['order_type']) &&$this->post['order_type']!=''?intval($this->post['order_type']) :"";
  39. // if($order_type==""){
  40. // return error_show(1004,"参数 order_type 不能为空或零");
  41. // }
  42. $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
  43. $except_code =isset($this->post['except_code']) &&$this->post['except_code']!=''?trim($this->post['except_code']) :"";
  44. $img = isset($this->post['img']) &&$this->post['img']!=''?trim($this->post['img']) :"";
  45. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  46. if($token==''){
  47. return error_show(1005,"参数token不能为空");
  48. }
  49. $user =GetUserInfo($token);
  50. if(empty($user)||$user['code']!=0){
  51. return error_show(1002,"申请人数据不存在");
  52. }
  53. $rm= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  54. $ri= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  55. $returnCode=makeNo("RXS");
  56. Db::startTrans();
  57. try{
  58. $in = [
  59. "returnCode"=>$returnCode,
  60. "outCode"=>$outCode,
  61. "orderCode"=> $order['orderCode'],
  62. "good_code"=>$order['good_code'],
  63. "good_name"=>$order['good_name'],
  64. "customer_code"=>$order['customer_code'],
  65. "apply_id"=>$rm,
  66. "apply_name"=>$ri,
  67. 'total_num'=>$order['send_num'],
  68. "error_code"=>$errorCode,
  69. "error_num"=>$num,
  70. "error_img"=>$img,
  71. "error_msg"=>$error['result'],
  72. "error_remark"=>$remark,
  73. "remark"=>'',
  74. "except_code"=>$except_code,
  75. "order_type"=>$order['order_type'],
  76. "status"=>0,
  77. "is_del"=>0,
  78. "addtime"=>date("Y-m-d H:i:s"),
  79. "updatetime"=>date("Y-m-d H:i:s")
  80. ];
  81. $create = Db::name("order_return")->insert($in);
  82. if($create){
  83. Db::commit();
  84. return app_show(0,"售后申请单新建成功");
  85. }
  86. Db::rollback();
  87. return error_show(1005,"售后申请单新建失败");
  88. }catch (\Exception $e){
  89. Db::rollback();
  90. return error_show(1005,$e->getMessage());
  91. }
  92. }
  93. public function list(){
  94. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  95. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  96. $where =[['a.is_del',"=",0]];
  97. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  98. if($bkcode!=""){
  99. $where[]=['a.returnCode',"like", "%{$bkcode}%"];
  100. }
  101. $out = isset($this->post['outCode']) && $this->post['outCode']!="" ? trim($this->post['outCode']):"";
  102. if($out!=""){
  103. $where[]=['a.outCode',"like", "%{$out}%"];
  104. }
  105. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  106. if($status!==""){
  107. $where[]=['a.status',"=", $status];
  108. }
  109. $order_type = isset($this->post['order_type']) && $this->post['order_type']!=="" ? intval($this->post['order_type']):"";
  110. if($order_type!==""){
  111. $where[]=['a.order_type',"=", $order_type];
  112. }
  113. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode'])
  114. :"";
  115. if($orderCode!=""){
  116. $where[]=['a.orderCode',"like", "%{$orderCode}%"];
  117. }
  118. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code'])
  119. :"";
  120. if($good_code!=""){
  121. $where[]=['a.good_code',"like", "%{$good_code}%"];
  122. }
  123. $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name'])
  124. :"";
  125. if($good_name!=""){
  126. $where[]=['a.good_name',"like", "%{$good_name}%"];
  127. }
  128. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code']!="" ? trim($this->post['customer_code'])
  129. :"";
  130. if($customer_code!=""){
  131. $where[]=['a.customer_code',"like", "%{$customer_code}%"];
  132. }
  133. $except_code = isset($this->post['except_code']) && $this->post['except_code']!="" ? trim($this->post['except_code']):"";
  134. if($except_code!=""){
  135. $where[]=['a.except_code',"=", $except_code];
  136. }
  137. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name'])
  138. :"";
  139. if($apply_name!=""){
  140. $where[]=['a.apply_name',"like", "%{$apply_name}%"];
  141. }
  142. $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
  143. if($start!==""){
  144. $where[]=['a.addtime',">=", $start];
  145. }
  146. $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
  147. if($end!==""){
  148. $where[]=['a.addtime',"<=", $end];
  149. }
  150. $count=Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where
  151. ($where)->count();
  152. $total = ceil($count/$size);
  153. $page = $total>=$page ? $page :$total;
  154. $list =Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where($where)
  155. ->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)
  156. ->order("addtime desc")->select();
  157. $data=[];
  158. foreach ($list as $value){
  159. $customer = Db::name("customer_info")->where(["companyNo"=>$value['customer_code']])->find();
  160. $value['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  161. $data[]=$value;
  162. }
  163. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  164. }
  165. /**
  166. * @return \think\response\Json|void
  167. * @throws \think\db\exception\DataNotFoundException
  168. * @throws \think\db\exception\DbException
  169. * @throws \think\db\exception\ModelNotFoundException
  170. */
  171. public function info(){
  172. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  173. if($bkcode==""){
  174. return error_show(1005,"参数returnCode 不能为空");
  175. }
  176. $info = Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")
  177. ->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")
  178. ->where(['a.returnCode'=>$bkcode])->find();
  179. if(empty($info)){
  180. return error_show(1005,"未找到售后数据");
  181. }
  182. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  183. $info['out_num'] = isset($out['send_num'])?$out['send_num']:'';
  184. $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
  185. $info['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  186. return app_show(0,"获取成功",$info);
  187. }
  188. public function status(){
  189. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  190. if($bkcode==""){
  191. return error_show(1005,"参数returnCode 不能为空");
  192. }
  193. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  194. if(empty($info)){
  195. return error_show(1005,"未找到售后数据");
  196. }
  197. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status'])
  198. :"";
  199. if($status===""){
  200. return error_show(1005,"参数status 不能为空");
  201. }
  202. $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
  203. if($remark!=''){
  204. $info['remark'] =$remark;
  205. }
  206. $info['status']=$status;
  207. $info['updatetime']=date("Y-m-d H:i:s");
  208. $up =Db::name("order_return")->save($info);
  209. if($up){
  210. return app_show(0,"更新成功");
  211. }else{
  212. return error_show(1004,"更新失败");
  213. }
  214. }
  215. /**
  216. * @return \think\response\Json|void
  217. * @throws \think\db\exception\DataNotFoundException
  218. * @throws \think\db\exception\DbException
  219. * @throws \think\db\exception\ModelNotFoundException
  220. */
  221. public function postfeed(){
  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. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  231. if($wsm_code==""){
  232. return error_show(1005,"参数 wsm_code不能为空");
  233. }
  234. $wsm = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code])->find();
  235. if(empty($wsm)){
  236. return error_show(1005,"未找到仓库数据");
  237. }
  238. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  239. :"";
  240. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  241. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  242. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!="" ? trim($this->post['addr_code']):"";
  243. if($info['is_th']==0 && $info['order_type']==2){
  244. if($contactor==''){
  245. return error_show(1005,"参数 contactor 不能为空");
  246. }
  247. if($mobile==''){
  248. return error_show(1005,"参数 mobile 不能为空");
  249. }
  250. if($addr==''){
  251. return error_show(1005,"参数 addr 不能为空");
  252. }
  253. if($addr_code==''){
  254. return error_show(1005,"参数 addr_code 不能为空");
  255. }
  256. }
  257. Db::startTrans();
  258. try{
  259. $info['status']=$info['order_type']==1?3:4;
  260. $info['updatetime']=date("Y-m-d H:i:s");
  261. $up =Db::name("order_return")->save($info);
  262. if($up){
  263. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  264. if(empty($returninfo)){
  265. $returninfo=[
  266. "returnCode"=>$bkcode,
  267. "return_wsm"=>$wsm_code,
  268. "contactor"=>$contactor,
  269. "mobile"=>$mobile ,
  270. "addr"=>$addr,
  271. "addr_code"=>$addr_code,
  272. "addtime"=>date("Y-m-d H:i:s")
  273. ];
  274. }else{
  275. $returninfo['return_wsm'] = $wsm_code;
  276. $returninfo['contactor'] = $contactor;
  277. $returninfo['mobile'] = $mobile;
  278. $returninfo['addr'] = $addr;
  279. $returninfo['addr_code'] = $addr_code;
  280. }
  281. $in=Db::name("order_returninfo")->save($returninfo);
  282. if($in){
  283. Db::commit();
  284. return app_show(0,"更新成功");
  285. }
  286. }
  287. Db::rollback();
  288. return error_show(1004,"更新失败");
  289. }catch (\Exception $e){
  290. Db::rollback();
  291. return error_show(1004,$e->getMessage());
  292. }
  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 addpost(){
  301. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  302. if($bkcode==""){
  303. return error_show(1005,"参数returnCode 不能为空");
  304. }
  305. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  306. if(empty($info)){
  307. return error_show(1005,"未找到售后数据");
  308. }
  309. $return_info = Db::name("order_returninfo")->where(['returnCode'=>$bkcode])->find();
  310. if(empty($return_info)){
  311. $return_info=[
  312. "returnCode"=>$bkcode,
  313. "return_wsm"=>'',
  314. "contactor"=>'',
  315. "mobile"=>'',
  316. "addr"=>'',
  317. "addr_code"=>'',
  318. "addtime"=>date("Y-m-d H:i:s"),
  319. "post_company"=>'',
  320. "post_code"=>'',
  321. "post_fee"=>'',
  322. ];
  323. }
  324. $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
  325. if($post_own==''){
  326. return error_show(1005,"参数own不能为空");
  327. }
  328. $info['post_own'] = $post_own;
  329. $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
  330. if($post_company==''){
  331. return error_show(1005,"参数company不能为空");
  332. }
  333. $return_info['post_company'] = $post_company;
  334. $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
  335. if($post_code==''){
  336. return error_show(1005,"参数post_code不能为空");
  337. }
  338. $return_info['post_code'] = $post_code;
  339. $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
  340. if($fee===''){
  341. return error_show(1005,"参数post_fee不能为空");
  342. }
  343. $return_info['post_fee'] = $fee;
  344. Db::startTrans();
  345. try{
  346. $info['status']=$info['order_type']==1?4:5;
  347. $info['updatetime']=date("Y-m-d H:i:s");
  348. $up =Db::name("order_return")->save($info);
  349. if($up){
  350. $in=Db::name("order_returninfo")->save($return_info);
  351. if($in){
  352. $data=[
  353. 'thNo'=>makeNo("TH"),
  354. "orderCode"=>$info['orderCode'],
  355. "order_type"=>$info['order_type'],
  356. "outCode"=>$info['outCode'],
  357. "returnCode"=>$info['returnCode'],
  358. "good_code"=>$info['good_code'],
  359. "good_name"=>$info['good_name'],
  360. "return_wsm"=>$return_info['return_wsm'],
  361. "return_num"=>$info['error_num'],
  362. "contactor"=>$return_info['contactor'],
  363. "mobile"=>$return_info['mobile'],
  364. "addr"=>$return_info['addr'],
  365. "addr_code"=>$return_info['addr_code'],
  366. "return_code"=>$info['error_code'],
  367. "return_msg"=>$info['error_msg'],
  368. "post_fee"=>$return_info['post_fee'],
  369. "post_code"=>$return_info['post_code'],
  370. "post_company"=>$return_info['post_company'],
  371. "customer_code"=>$info['customer_code'],
  372. "addtime"=>date("Y-m-d H:i:s"),
  373. "updatetime"=>date("Y-m-d H:i:s")
  374. ];
  375. $back =Db::name("order_back")->insert($data);
  376. if($back){
  377. Db::commit();
  378. return app_show(0,"更新成功");
  379. }
  380. }
  381. }
  382. Db::rollback();
  383. return error_show(1004,"更新失败");
  384. }catch (\Exception $e){
  385. Db::rollback();
  386. return error_show(1004,$e->getMessage());
  387. }
  388. }
  389. /**
  390. * @return \think\response\Json|void
  391. * @throws \think\db\exception\DataNotFoundException
  392. * @throws \think\db\exception\DbException
  393. * @throws \think\db\exception\ModelNotFoundException
  394. */
  395. public function GysFeed(){
  396. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  397. if($bkcode==""){
  398. return error_show(1005,"参数returnCode 不能为空");
  399. }
  400. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  401. if(empty($info)){
  402. return error_show(1005,"未找到售后数据");
  403. }
  404. $isth = isset($this->post['is_th']) && $this->post['is_th']!="" ? intval($this->post['is_th']):"0";
  405. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  406. :"";
  407. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  408. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  409. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!="" ? trim($this->post['addr_code']):"";
  410. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  411. if($isth==1){
  412. if($contactor==''){
  413. return error_show(1005,"参数 contactor 不能为空");
  414. }
  415. if($mobile==''){
  416. return error_show(1005,"参数 mobile 不能为空");
  417. }
  418. if($addr==''){
  419. return error_show(1005,"参数 addr 不能为空");
  420. }
  421. if($addr_code==''){
  422. return error_show(1005,"参数 addr_code 不能为空");
  423. }
  424. }
  425. Db::startTrans();
  426. try{
  427. $info['status']=3;
  428. $info['is_th']=$isth;
  429. $info['updatetime']=date("Y-m-d H:i:s");
  430. $up =Db::name("order_return")->save($info);
  431. if($up){
  432. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  433. if(empty($returninfo)){
  434. $returninfo=[
  435. "returnCode"=>$bkcode,
  436. "return_wsm"=>'',
  437. "contactor"=>$contactor,
  438. "mobile"=>$mobile ,
  439. "addr"=>$addr,
  440. "addr_code"=>$addr_code,
  441. "gys_remark"=>$remark,
  442. "addtime"=>date("Y-m-d H:i:s")
  443. ];
  444. }else{
  445. $returninfo['return_wsm'] = '';
  446. $returninfo['contactor'] = $contactor;
  447. $returninfo['mobile'] = $mobile;
  448. $returninfo['addr'] = $addr;
  449. $returninfo['gys_remark'] = $remark;
  450. $returninfo['addr_code'] = $addr_code;
  451. }
  452. $in=Db::name("order_returninfo")->save($returninfo);
  453. if($in){
  454. Db::commit();
  455. return app_show(0,"更新成功");
  456. }
  457. }
  458. Db::rollback();
  459. return error_show(1004,"更新失败");
  460. }catch (\Exception $e){
  461. Db::rollback();
  462. return error_show(1004,$e->getMessage());
  463. }
  464. }
  465. }