WxOrdersRefund.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class WxOrdersRefund extends Auth
  5. {
  6. protected function initialize()
  7. {
  8. parent::initialize(); // TODO: Change the autogenerated stub
  9. }
  10. public function index(){
  11. if(request()->isAjax()){
  12. //分页参数
  13. $length = input('rows',10,'intval'); //每页条数
  14. $page = input('page',1,'intval'); //第几页
  15. $start = ($page - 1) * $length; //分页开始位置
  16. //排序
  17. $sortRow = input('sidx','sort','trim'); //排序列
  18. $sort = input('sord','asc','trim'); //排序方式
  19. $order = $sortRow.' '.$sort.' ,id desc';
  20. $order_sn = input('order_sn','','trim');
  21. if($order_sn){
  22. $ids = Db::name('wx_orders')
  23. ->where('org_id',$this->orgId)
  24. ->where('order_sn',$order_sn)
  25. ->column('id');
  26. if(empty($ids)){
  27. $map[]=['order_id','=',-1];
  28. }else{
  29. $map[]=['order_id','in',$ids];
  30. }
  31. }
  32. $status = input('status','','trim');
  33. if($status != ''){
  34. $map[] = ['status','=',$status];
  35. }
  36. $cate_id = input('cate_id','','trim');
  37. if($cate_id != ''){
  38. $goodIds = Db::name('wx_goods')
  39. ->where('cate_id',$cate_id)
  40. ->column('id');
  41. if(empty($goodIds)){
  42. $map[] = ['id','=',-1];
  43. }else{
  44. $map[] = ['goods_id','in',$goodIds];
  45. }
  46. }
  47. $b = input('begin','','trim');
  48. $e = input('end','','trim');
  49. if($b){
  50. $b = date('Y-m-d 00:00:00',strtotime($b));
  51. $map[] = ['create_time','>=',$b];
  52. }
  53. if($e){
  54. $e = date('Y-m-d 23:59:59',strtotime($e));
  55. $map[] = ['create_time','<=',$e];
  56. }
  57. $map[] = ['org_id','=',cur_org_id()];
  58. $map[] = ['del','=',0];
  59. $map = empty($map) ? true: $map;
  60. //数据查询
  61. $lists = Db::name('wx_orders_refund')
  62. ->where($map)->limit($start,$length)->order($order)->select();
  63. foreach ($lists as $k=>$v){
  64. $lists[$k]['status_name'] =isset(model('WxOrders')->rStatus[$v['status']])?model('WxOrders')->rStatus[$v['status']]:'';
  65. $lists[$k]['user_name'] = Db::name('user')
  66. ->where('id',$v['user_id'])
  67. ->value('real_name');
  68. $lists[$k]['goods_name'] = Db::name('wx_goods')
  69. ->where('id',$v['goods_id'])
  70. ->value('title');
  71. $lists[$k]['order_sn'] = Db::name('wx_orders')
  72. ->where('id',$v['order_id'])
  73. ->value('order_sn');
  74. }
  75. //数据返回
  76. $totalCount = Db::name('wx_orders_refund')->where($map)->count();
  77. $totalPage = ceil($totalCount/$length);
  78. $result['page'] = $page;
  79. $result['total'] = $totalPage;
  80. $result['records'] = $totalCount;
  81. $result['rows'] = $lists;
  82. return json($result);
  83. }else{
  84. $cate = model('WxGoodsCate')->lists($this->orgId);
  85. $status = model('WxOrders')->rStatus;
  86. $this->assign('status',$status);
  87. $this->assign('cate',$cate);
  88. $this->assign('meta_title','订单退款列表');
  89. return $this->fetch();
  90. }
  91. }
  92. public function details($id,$goodsId){
  93. if(!$id){
  94. $this->error('参数错误');
  95. }
  96. $ret = model('WxOrders')->goodsRefundDetail($this->orgId,$id,$goodsId);
  97. $this->assign('info',$ret);
  98. $this->assign('meta_title','退款详情');
  99. return $this->fetch();
  100. }
  101. /**
  102. * 退款
  103. */
  104. public function option($id = 0){
  105. if(request()->isPost()){
  106. $res = model('WxOrders')->refundOrder($this->userId);
  107. if($res){
  108. $this->success('操作成功',url('index'));
  109. }else{
  110. $this->error(model('WxOrders')->getError());
  111. }
  112. }else{
  113. $pay = Db::name('wx_orders_refund')->where('id',$id)->find();
  114. $money = $pay['amount'];
  115. $this->assign('money',$money);
  116. $this->assign('pay',$pay);
  117. $this->assign('id',$id);
  118. return $this->fetch();
  119. }
  120. }
  121. public function goodsRefund($id,$goodsId=0,$type=0){
  122. if(!$id){
  123. $this->error('参数错误');
  124. }
  125. if(request()->isPost()){
  126. $res = model('WxOrders')->orderRefund($this->userId,$this->orgId);
  127. if($res){
  128. $this->success('操作成功',url('index'));
  129. }else{
  130. $this->error(model('WxOrders')->getError());
  131. }
  132. }else{
  133. $ret = model('WxOrders')->checkoutApplyRefund($this->userId,$this->orgId,$type,$id,$goodsId);
  134. $this->assign('info',$ret);
  135. $this->assign('id',$id);
  136. $this->assign('meta_title','商品申请退款');
  137. return $this->fetch();
  138. }
  139. }
  140. }