| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 | 
							- <?php
 
- namespace app\admin\controller;
 
- use think\Db;
 
- use think\Exception;
 
- class WxCashRefund extends Auth
 
- {
 
-     public function index(){
 
-         if(request()->isAjax()){
 
-             //分页参数
 
-             $length = input('rows',10,'intval');   //每页条数
 
-             $page = input('page',1,'intval');      //第几页
 
-             $start = ($page - 1) * $length;     //分页开始位置
 
-             //排序
 
-             $sortRow = input('sidx','sort','trim');      //排序列
 
-             $sort = input('sord','asc','trim');        //排序方式
 
-             $order = $sortRow.' '.$sort.' ,id desc';
 
-             $order_sn = input('order_sn','','trim');
 
-             if($order_sn){
 
-                 $map[] = ['sn','=',$order_sn];
 
-             }
 
-             $name = input('name','','trim');
 
-             if($name){
 
-                 $map1[] = ['nickname','like','%'.$name.'%'];
 
-                 $u = Db::name('wxuser')
 
-                     ->where($map1)
 
-                     ->where('type',1)
 
-                     ->column('id');
 
-                 if(empty($u)){
 
-                     $map[] = ['id','=',-1];
 
-                 }else{
 
-                     $map[] = ['user_id','in',$u];
 
-                 }
 
-             }
 
-             $status = input('status','','trim');
 
-             if($status != ''){
 
-                 $map[] = ['status','=',$status];
 
-             }
 
- //            if($this->user_id > 1){
 
- //                $map[] = ['user_id','=',$this->user_id];
 
- //            }
 
-             $b = input('begin','','trim');
 
-             $e = input('end','','trim');
 
-             if($b){
 
-                 $b = date('Y-m-d 00:00:00',strtotime($b));
 
-                 $map[] = ['create_time','>=',$b];
 
-             }
 
-             if($e){
 
-                 $e = date('Y-m-d 23:59:59',strtotime($e));
 
-                 $map[] = ['create_time','<=',$e];
 
-             }
 
-             $map[] = ['org_id','=',cur_org_id()];
 
-             $map[] = ['del','=',0];
 
-             $map = empty($map) ? true: $map;
 
-             //数据查询
 
-             $lists = Db::name('wx_cash_refund')->where($map)
 
-                 ->limit($start,$length)
 
-                 ->order($order)->select();
 
-             foreach ($lists as $k=>$v){
 
-                 $lists[$k]['status_name'] =isset(model('WxCash')->status[$v['status']])?model('WxCash')->status[$v['status']]:'';
 
-                 $lists[$k]['barrel_name'] = Db::name('wx_barrel')
 
-                         ->where('id',$v['barrel_id'])
 
-                     ->value('title');
 
-                 $lists[$k]['user_name'] = Db::name('wxuser')
 
-                     ->where('id',$v['user_id'])
 
-                     ->value('phone');
 
-             }
 
-             //数据返回
 
-             $totalCount = Db::name('wx_cash_refund')->where($map)->count();
 
-             $totalPage = ceil($totalCount/$length);
 
-             $result['page'] = $page;
 
-             $result['total'] = $totalPage;
 
-             $result['records'] = $totalCount;
 
-             $result['rows'] = $lists;
 
-             return json($result);
 
-         }else{
 
-             $status = model('WxCash')->status;
 
-             $this->assign('status',$status);
 
-             $this->assign('meta_title','押金退款列表');
 
-             return $this->fetch();
 
-         }
 
-     }
 
-     public function details($id){
 
-         if(!$id){
 
-             $this->error('参数错误');
 
-         }
 
-         $ret = Db::name('wx_cash_refund')->where('id',$id)
 
-             ->find();
 
-         $ret['status_name'] =isset(model('WxCash')->status[$ret['status']])?model('WxCash')->status[$ret['status']]:'';
 
-         $ret['barrel_name'] = Db::name('wx_barrel')
 
-             ->where('id',$ret['barrel_id'])
 
-             ->value('title');
 
-         $ret['user_name'] = Db::name('wxuser')
 
-             ->where('id',$ret['user_id'])
 
-             ->value('phone');
 
-         $ret['deal_user_name'] = Db::name('user')
 
-             ->where('id',$ret['deal_user_id'])
 
-             ->value('real_name');
 
-         $this->assign('info',$ret);
 
-         $this->assign('meta_title','押金退款详情');
 
-         return $this->fetch();
 
-     }
 
-     public function option($id = 0){
 
-         $pay = Db::name('wx_cash_refund')->where('id',$id)->find();
 
-         if(request()->isPost()){
 
-             if(empty($pay)){
 
-                 $this->error('退款申请不存在');
 
-             }
 
-             if($pay['status']!=0){
 
-                 $this->error('当前状态不能操作');
 
-             }
 
-             $status = input('status/d',0);
 
-             if(!in_array($status,[1,2])){
 
-                 $this->error('状态值错误');
 
-             }
 
-             Db::startTrans();
 
-             try{
 
-                 $res  = Db::name('wx_cash_refund')
 
-                     ->where('id',$id)
 
-                     ->update([
 
-                         'deal_user_id'=>$this->userId,
 
-                         'deal_time'=>getTime(),
 
-                         'status'=>$status,
 
-                         'update_time'=>getTime(),
 
-                         'remark'=>input('remark'),
 
-                     ]);
 
-                 if(!$res){
 
-                     \exception('操作失败');
 
-                 }
 
-                 if($status==1){
 
-                     $cash = Db::name('wx_cash')
 
-                         ->where('id',$pay['cash_id'])
 
-                         ->find();
 
-                     $tkSn = get_unique_id('TPH');
 
-                     $config = config('app.wx_mini_config');
 
-                     $app = \EasyWeChat\Factory::payment($config);
 
-                     $ret = $app->refund->byOutTradeNumber($cash['sn'], $tkSn, $cash['total_money']*100, $pay['amount']*100);
 
-                     if($ret['return_code'] != 'SUCCESS' || $ret['result_code'] != 'SUCCESS'){
 
-                         trace(json_encode($ret));
 
-                         \exception('退款申请提交失败');
 
-                     }
 
-                     Db::name('wx_cash')
 
-                         ->where('del',0)
 
-                         ->where('num',0)
 
-                         ->update(['del'=>1]);
 
-                     Db::commit();
 
-                     $this->success('操作成功',url('index'));
 
-                 }
 
-                 if($status==2){
 
-                     $res =Db::name('wx_cash')
 
-                         ->where('id',$pay['cash_id'])
 
-                         ->setInc('num',$pay['num']);
 
-                     if(!$res){
 
-                         \exception('操作失败');
 
-                     }
 
-                     $res =Db::name('wx_cash')
 
-                         ->where('id',$pay['cash_id'])
 
-                         ->setInc('amount',$pay['amount']);
 
-                     if(!$res){
 
-                         \exception('操作失败');
 
-                     }
 
-                     Db::commit();
 
-                     $this->success('操作成功',url('index'));
 
-                 }
 
-             }catch (Exception $e){
 
-                 Db::rollback();
 
-                 $this->error($e->getMessage());
 
-             }
 
-             if($res){
 
-                 $this->success('操作成功',url('index'));
 
-             }else{
 
-                 $this->error(model('WxCash')->getError());
 
-             }
 
-         }else{
 
-             $this->assign('pay',$pay);
 
-             $this->assign('id',$id);
 
-             return $this->fetch();
 
-         }
 
-     }
 
- }
 
 
  |