After.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode'])
  110. :"";
  111. if($orderCode!=""){
  112. $where[]=['a.orderCode',"like", "%{$orderCode}%"];
  113. }
  114. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code'])
  115. :"";
  116. if($good_code!=""){
  117. $where[]=['a.good_code',"like", "%{$good_code}%"];
  118. }
  119. $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name'])
  120. :"";
  121. if($good_name!=""){
  122. $where[]=['a.good_name',"like", "%{$good_name}%"];
  123. }
  124. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code']!="" ? trim($this->post['customer_code'])
  125. :"";
  126. if($customer_code!=""){
  127. $where[]=['a.customer_code',"like", "%{$customer_code}%"];
  128. }
  129. $except_code = isset($this->post['except_code']) && $this->post['except_code']!="" ? trim($this->post['except_code']):"";
  130. if($except_code!=""){
  131. $where[]=['a.except_code',"=", $except_code];
  132. }
  133. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name'])
  134. :"";
  135. if($apply_name!=""){
  136. $where[]=['a.apply_name',"like", "%{$apply_name}%"];
  137. }
  138. $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
  139. if($start!==""){
  140. $where[]=['a.addtime',">=", $start];
  141. }
  142. $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
  143. if($end!==""){
  144. $where[]=['a.addtime',"<=", $end];
  145. }
  146. $count=Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where
  147. ($where)->count();
  148. $total = ceil($count/$size);
  149. $page = $total>=$page ? $page :$total;
  150. $list =Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where($where)
  151. ->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)
  152. ->order("addtime desc")->select();
  153. $data=[];
  154. foreach ($list as $value){
  155. $customer = Db::name("customer_info")->where(["companyNo"=>$value['customer_code']])->find();
  156. $value['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  157. $data[]=$value;
  158. }
  159. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  160. }
  161. /**
  162. * @return \think\response\Json|void
  163. * @throws \think\db\exception\DataNotFoundException
  164. * @throws \think\db\exception\DbException
  165. * @throws \think\db\exception\ModelNotFoundException
  166. */
  167. public function info(){
  168. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  169. if($bkcode==""){
  170. return error_show(1005,"参数returnCode 不能为空");
  171. }
  172. $info = Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")
  173. ->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")
  174. ->where(['a.returnCode'=>$bkcode])->find();
  175. if(empty($info)){
  176. return error_show(1005,"未找到售后数据");
  177. }
  178. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  179. $info['out_num'] = isset($out['send_num'])?$out['send_num']:'';
  180. $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
  181. $info['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  182. return app_show(0,"获取成功",$info);
  183. }
  184. public function status(){
  185. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  186. if($bkcode==""){
  187. return error_show(1005,"参数returnCode 不能为空");
  188. }
  189. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  190. if(empty($info)){
  191. return error_show(1005,"未找到售后数据");
  192. }
  193. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status'])
  194. :"";
  195. if($status===""){
  196. return error_show(1005,"参数status 不能为空");
  197. }
  198. $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
  199. if($remark!=''){
  200. $info['remark'] =$remark;
  201. }
  202. $info['status']=$status;
  203. $info['updatetime']=date("Y-m-d H:i:s");
  204. $up =Db::name("order_return")->save($info);
  205. if($up){
  206. return app_show(0,"更新成功");
  207. }else{
  208. return error_show(1004,"更新失败");
  209. }
  210. }
  211. /**
  212. * @return \think\response\Json|void
  213. * @throws \think\db\exception\DataNotFoundException
  214. * @throws \think\db\exception\DbException
  215. * @throws \think\db\exception\ModelNotFoundException
  216. */
  217. public function postfeed(){
  218. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  219. if($bkcode==""){
  220. return error_show(1005,"参数returnCode 不能为空");
  221. }
  222. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  223. if(empty($info)){
  224. return error_show(1005,"未找到售后数据");
  225. }
  226. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  227. if($wsm_code==""){
  228. return error_show(1005,"参数 wsm_code不能为空");
  229. }
  230. $wsm = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code])->find();
  231. if(empty($wsm)){
  232. return error_show(1005,"未找到仓库数据");
  233. }
  234. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  235. :"";
  236. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  237. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  238. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!="" ? trim($this->post['addr_code']):"";
  239. if($info['is_th']==0 && $info['order_type']==2){
  240. if($contactor==''){
  241. return error_show(1005,"参数 contactor 不能为空");
  242. }
  243. if($mobile==''){
  244. return error_show(1005,"参数 mobile 不能为空");
  245. }
  246. if($addr==''){
  247. return error_show(1005,"参数 addr 不能为空");
  248. }
  249. if($addr_code==''){
  250. return error_show(1005,"参数 addr_code 不能为空");
  251. }
  252. }
  253. Db::startTrans();
  254. try{
  255. $info['status']=$info['order_type']==1?3:4;
  256. $info['updatetime']=date("Y-m-d H:i:s");
  257. $up =Db::name("order_return")->save($info);
  258. if($up){
  259. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  260. if(empty($returninfo)){
  261. $returninfo=[
  262. "returnCode"=>$bkcode,
  263. "return_wsm"=>$wsm_code,
  264. "contactor"=>$contactor,
  265. "mobile"=>$mobile ,
  266. "addr"=>$addr,
  267. "addr_code"=>$addr_code,
  268. "addtime"=>date("Y-m-d H:i:s")
  269. ];
  270. }else{
  271. $returninfo['return_wsm'] = $wsm_code;
  272. $returninfo['contactor'] = $contactor;
  273. $returninfo['mobile'] = $mobile;
  274. $returninfo['addr'] = $addr;
  275. $returninfo['addr_code'] = $addr_code;
  276. }
  277. $in=Db::name("order_returninfo")->save($returninfo);
  278. if($in){
  279. Db::commit();
  280. return app_show(0,"更新成功");
  281. }
  282. }
  283. Db::rollback();
  284. return error_show(1004,"更新失败");
  285. }catch (\Exception $e){
  286. Db::rollback();
  287. return error_show(1004,$e->getMessage());
  288. }
  289. }
  290. /**
  291. * @return \think\response\Json|void
  292. * @throws \think\db\exception\DataNotFoundException
  293. * @throws \think\db\exception\DbException
  294. * @throws \think\db\exception\ModelNotFoundException
  295. */
  296. public function addpost(){
  297. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  298. if($bkcode==""){
  299. return error_show(1005,"参数returnCode 不能为空");
  300. }
  301. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  302. if(empty($info)){
  303. return error_show(1005,"未找到售后数据");
  304. }
  305. $return_info = Db::name("order_returninfo")->where(['returnCode'=>$bkcode])->find();
  306. if(empty($return_info)){
  307. $return_info=[
  308. "returnCode"=>$bkcode,
  309. "return_wsm"=>'',
  310. "contactor"=>'',
  311. "mobile"=>'',
  312. "addr"=>'',
  313. "addr_code"=>'',
  314. "addtime"=>date("Y-m-d H:i:s"),
  315. "post_company"=>'',
  316. "post_code"=>'',
  317. "post_fee"=>'',
  318. ];
  319. }
  320. $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
  321. if($post_own==''){
  322. return error_show(1005,"参数own不能为空");
  323. }
  324. $info['post_own'] = $post_own;
  325. $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
  326. if($post_company==''){
  327. return error_show(1005,"参数company不能为空");
  328. }
  329. $return_info['post_company'] = $post_company;
  330. $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
  331. if($post_code==''){
  332. return error_show(1005,"参数post_code不能为空");
  333. }
  334. $return_info['post_code'] = $post_code;
  335. $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
  336. if($fee===''){
  337. return error_show(1005,"参数post_fee不能为空");
  338. }
  339. $return_info['post_fee'] = $fee;
  340. Db::startTrans();
  341. try{
  342. $info['status']=$info['order_type']==1?4:5;
  343. $info['updatetime']=date("Y-m-d H:i:s");
  344. $up =Db::name("order_return")->save($info);
  345. if($up){
  346. $in=Db::name("order_returninfo")->save($return_info);
  347. if($in){
  348. $data=[
  349. 'thNo'=>makeNo("TH"),
  350. "orderCode"=>$info['orderCode'],
  351. "order_type"=>$info['order_type'],
  352. "outCode"=>$info['outCode'],
  353. "returnCode"=>$info['returnCode'],
  354. "good_code"=>$info['good_code'],
  355. "good_name"=>$info['good_name'],
  356. "return_wsm"=>$return_info['return_wsm'],
  357. "return_num"=>$info['error_num'],
  358. "contactor"=>$return_info['contactor'],
  359. "mobile"=>$return_info['mobile'],
  360. "addr"=>$return_info['addr'],
  361. "addr_code"=>$return_info['addr_code'],
  362. "return_code"=>$info['error_code'],
  363. "return_msg"=>$info['error_msg'],
  364. "post_fee"=>$return_info['post_fee'],
  365. "post_code"=>$return_info['post_code'],
  366. "post_company"=>$return_info['post_company'],
  367. "customer_code"=>$info['customer_code'],
  368. "addtime"=>date("Y-m-d H:i:s"),
  369. "updatetime"=>date("Y-m-d H:i:s")
  370. ];
  371. $back =Db::name("order_back")->insert($data);
  372. if($back){
  373. Db::commit();
  374. return app_show(0,"更新成功");
  375. }
  376. }
  377. }
  378. Db::rollback();
  379. return error_show(1004,"更新失败");
  380. }catch (\Exception $e){
  381. Db::rollback();
  382. return error_show(1004,$e->getMessage());
  383. }
  384. }
  385. /**
  386. * @return \think\response\Json|void
  387. * @throws \think\db\exception\DataNotFoundException
  388. * @throws \think\db\exception\DbException
  389. * @throws \think\db\exception\ModelNotFoundException
  390. */
  391. public function GysFeed(){
  392. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  393. if($bkcode==""){
  394. return error_show(1005,"参数returnCode 不能为空");
  395. }
  396. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  397. if(empty($info)){
  398. return error_show(1005,"未找到售后数据");
  399. }
  400. $isth = isset($this->post['is_th']) && $this->post['is_th']!="" ? intval($this->post['is_th']):"0";
  401. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  402. :"";
  403. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  404. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  405. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!="" ? trim($this->post['addr_code']):"";
  406. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  407. if($isth==1){
  408. if($contactor==''){
  409. return error_show(1005,"参数 contactor 不能为空");
  410. }
  411. if($mobile==''){
  412. return error_show(1005,"参数 mobile 不能为空");
  413. }
  414. if($addr==''){
  415. return error_show(1005,"参数 addr 不能为空");
  416. }
  417. if($addr_code==''){
  418. return error_show(1005,"参数 addr_code 不能为空");
  419. }
  420. }
  421. Db::startTrans();
  422. try{
  423. $info['status']=3;
  424. $info['is_th']=$isth;
  425. $info['updatetime']=date("Y-m-d H:i:s");
  426. $up =Db::name("order_return")->save($info);
  427. if($up){
  428. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  429. if(empty($returninfo)){
  430. $returninfo=[
  431. "returnCode"=>$bkcode,
  432. "return_wsm"=>'',
  433. "contactor"=>$contactor,
  434. "mobile"=>$mobile ,
  435. "addr"=>$addr,
  436. "addr_code"=>$addr_code,
  437. "gys_remark"=>$remark,
  438. "addtime"=>date("Y-m-d H:i:s")
  439. ];
  440. }else{
  441. $returninfo['return_wsm'] = '';
  442. $returninfo['contactor'] = $contactor;
  443. $returninfo['mobile'] = $mobile;
  444. $returninfo['addr'] = $addr;
  445. $returninfo['gys_remark'] = $remark;
  446. $returninfo['addr_code'] = $addr_code;
  447. }
  448. $in=Db::name("order_returninfo")->save($returninfo);
  449. if($in){
  450. Db::commit();
  451. return app_show(0,"更新成功");
  452. }
  453. }
  454. Db::rollback();
  455. return error_show(1004,"更新失败");
  456. }catch (\Exception $e){
  457. Db::rollback();
  458. return error_show(1004,$e->getMessage());
  459. }
  460. }
  461. }