After.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
  39. $except_code =isset($this->post['except_code']) &&$this->post['except_code']!=''?trim($this->post['except_code']) :"";
  40. $img = isset($this->post['img']) &&$this->post['img']!=''?trim($this->post['img']) :"";
  41. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  42. if($token==''){
  43. return error_show(1005,"参数token不能为空");
  44. }
  45. $user =GetUserInfo($token);
  46. if(empty($user)||$user['code']!=0){
  47. return error_show(1002,"申请人数据不存在");
  48. }
  49. $rm= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  50. $ri= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  51. $returnCode=makeNo("RXS");
  52. Db::startTrans();
  53. try{
  54. $in = [
  55. "returnCode"=>$returnCode,
  56. "outCode"=>$outCode,
  57. "orderCode"=> $order['orderCode'],
  58. "good_code"=>$order['good_code'],
  59. "good_name"=>$order['good_name'],
  60. "customer_code"=>$order['customer_code'],
  61. "apply_id"=>$rm,
  62. "apply_name"=>$ri,
  63. 'total_num'=>$order['send_num'],
  64. "error_code"=>$errorCode,
  65. "error_num"=>$num,
  66. "error_img"=>$img,
  67. "error_msg"=>$error['result'],
  68. "error_remark"=>$remark,
  69. "except_code"=>$except_code,
  70. "return_wsm"=>'',
  71. "contactor"=>'',
  72. "mobile"=>'',
  73. "addr"=>'',
  74. "addr_code"=>'',
  75. "status"=>0,
  76. "is_del"=>0,
  77. "addtime"=>date("Y-m-d H:i:s"),
  78. "updatetime"=>date("Y-m-d H:i:s")
  79. ];
  80. $create = Db::name("order_return")->insert($in);
  81. if($create){
  82. Db::commit();
  83. return app_show(0,"售后申请单新建成功");
  84. }
  85. Db::rollback();
  86. return error_show(1005,"售后申请单新建失败");
  87. }catch (\Exception $e){
  88. Db::rollback();
  89. return error_show(1005,$e->getMessage());
  90. }
  91. }
  92. public function list(){
  93. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  94. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  95. $where =[['is_del',"=",0]];
  96. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  97. if($bkcode!=""){
  98. $where[]=['returnCode',"like", "%{$bkcode}%"];
  99. }
  100. $out = isset($this->post['outCode']) && $this->post['outCode']!="" ? trim($this->post['outCode']):"";
  101. if($out!=""){
  102. $where[]=['outCode',"like", "%{$out}%"];
  103. }
  104. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  105. if($status!==""){
  106. $where[]=['status',"=", $status];
  107. }
  108. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode'])
  109. :"";
  110. if($orderCode!=""){
  111. $where[]=['orderCode',"like", "%{$orderCode}%"];
  112. }
  113. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code'])
  114. :"";
  115. if($good_code!=""){
  116. $where[]=['good_code',"like", "%{$good_code}%"];
  117. }
  118. $except_code = isset($this->post['except_code']) && $this->post['except_code']!="" ? trim($this->post['except_code']):"";
  119. if($except_code!=""){
  120. $where[]=['except_code',"=", $except_code];
  121. }
  122. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name'])
  123. :"";
  124. if($apply_name!=""){
  125. $where[]=['apply_name',"like", "%{$apply_name}%"];
  126. }
  127. $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
  128. if($start!==""){
  129. $where[]=['addtime',">=", $start];
  130. }
  131. $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
  132. if($end!==""){
  133. $where[]=['addtime',"<=", $end];
  134. }
  135. $count=Db::name("order_return")->where($where)->count();
  136. $total = ceil($count/$size);
  137. $page = $total>=$page ? $page :$total;
  138. $list = Db::name("order_return")->where($where)->page($page,$size)->select();
  139. $data=[];
  140. foreach ($list as $value){
  141. $customer = Db::name("customer_info")->where(["companyNo"=>$value['customer_code']])->find();
  142. $value['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  143. $data[]=$value;
  144. }
  145. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  146. }
  147. /**
  148. * @return \think\response\Json|void
  149. * @throws \think\db\exception\DataNotFoundException
  150. * @throws \think\db\exception\DbException
  151. * @throws \think\db\exception\ModelNotFoundException
  152. */
  153. public function info(){
  154. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  155. if($bkcode==""){
  156. return error_show(1005,"参数returnCode 不能为空");
  157. }
  158. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  159. if(empty($info)){
  160. return error_show(1005,"未找到售后数据");
  161. }
  162. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  163. $info['out_num'] = isset($out['send_num'])?$out['send_num']:'';
  164. $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
  165. $info['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  166. return app_show(0,"获取成功",$info);
  167. }
  168. public function status(){
  169. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  170. if($bkcode==""){
  171. return error_show(1005,"参数returnCode 不能为空");
  172. }
  173. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  174. if(empty($info)){
  175. return error_show(1005,"未找到售后数据");
  176. }
  177. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status'])
  178. :"";
  179. if($status===""){
  180. return error_show(1005,"参数status 不能为空");
  181. }
  182. $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
  183. if($remark!=''){
  184. $info['remark'] =$remark;
  185. }
  186. $info['status']=$status;
  187. $info['updatetime']=date("Y-m-d H:i:s");
  188. $up =Db::name("order_return")->save($info);
  189. if($up){
  190. return app_show(0,"更新成功");
  191. }else{
  192. return error_show(1004,"更新失败");
  193. }
  194. }
  195. /**
  196. * @return \think\response\Json|void
  197. * @throws \think\db\exception\DataNotFoundException
  198. * @throws \think\db\exception\DbException
  199. * @throws \think\db\exception\ModelNotFoundException
  200. */
  201. public function postfeed(){
  202. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  203. if($bkcode==""){
  204. return error_show(1005,"参数returnCode 不能为空");
  205. }
  206. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  207. if(empty($info)){
  208. return error_show(1005,"未找到售后数据");
  209. }
  210. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  211. if($wsm_code==""){
  212. return error_show(1005,"参数 wsm_code不能为空");
  213. }
  214. $wsm = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code])->find();
  215. if(empty($wsm)){
  216. return error_show(1005,"未找到仓库数据");
  217. }
  218. $info['return_wsm']=$wsm_code;
  219. $info['status']=3;
  220. $info['updatetime']=date("Y-m-d H:i:s");
  221. $up =Db::name("order_return")->save($info);
  222. if($up){
  223. return app_show(0,"更新成功");
  224. }else{
  225. return error_show(1004,"更新失败");
  226. }
  227. }
  228. /**
  229. * @return \think\response\Json|void
  230. * @throws \think\db\exception\DataNotFoundException
  231. * @throws \think\db\exception\DbException
  232. * @throws \think\db\exception\ModelNotFoundException
  233. */
  234. public function addpost(){
  235. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  236. if($bkcode==""){
  237. return error_show(1005,"参数returnCode 不能为空");
  238. }
  239. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  240. if(empty($info)){
  241. return error_show(1005,"未找到售后数据");
  242. }
  243. $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
  244. if($post_own==''){
  245. return error_show(1005,"参数own不能为空");
  246. }
  247. $info['post_own'] = $post_own;
  248. $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
  249. if($post_company==''){
  250. return error_show(1005,"参数company不能为空");
  251. }
  252. $info['post_company'] = $post_company;
  253. $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
  254. if($post_code==''){
  255. return error_show(1005,"参数post_code不能为空");
  256. }
  257. $info['post_code'] = $post_code;
  258. $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
  259. if($fee===''){
  260. return error_show(1005,"参数post_code不能为空");
  261. }
  262. $info['post_fee'] = $fee;
  263. $info['status'] =4;
  264. $info['updatetime']=date("Y-m-d H:i:s");
  265. $up =Db::name("order_return")->save($info);
  266. if($up){
  267. return app_show(0,"更新成功");
  268. }else{
  269. return error_show(1004,"更新失败");
  270. }
  271. }
  272. }