After.php 22 KB

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