RefundController.php 6.4 KB
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\AdminBaseController;
use think\Db;
use think\Loader;
use think\Request;

class RefundController extends AdminBaseController
{

//    提现申请
    public function index(){
        $data = $this->request->param();
        $arr = array();
        if($data){
            $startTime = empty($data['start_time']) ? 0 : strtotime($data['start_time']);
            $endTime   = empty($data['end_time']) ? 0 : strtotime($data['end_time']);
            if ($startTime && $endTime) {
                $arr['start_time'] = $data['start_time'];
                $arr['end_time'] = $data['end_time'];
                $where_money['r.create_time'] = array('between',"$startTime,$endTime");
                $this->assign('start_time', $data['start_time']);
                $this->assign('end_time', $data['end_time']);
            }else{
                if($startTime){
                    $arr['start_time'] = $data['start_time'];
                    $where_money['r.create_time'] = array('egt',$startTime);
                    $this->assign('start_time', $data['start_time']);
                }
                if($endTime){
                    $arr['end_time'] = $data['end_time'];
                    $where_money['r.create_time'] = array('elt',$endTime);
                    $this->assign('end_time', $data['end_time']);
                }
            }
            if(!empty($data['name'])){
                $arr['name'] = $data['name'];
                $where_money['m.name'] = array('like','%'.$data['name'].'%');
                $this->assign('name', $data['name']);
            }
            if(!empty($data['tel'])){
                $arr['tel'] = $data['tel'];
                $where_money['m.tel'] = array('like','%'.$data['tel'].'%');
                $this->assign('tel', $data['tel']);
            }
        }
        $where_money['r.status'] = array('neq',9);
        $money_list = Db::name('Refund')->alias('r')
            ->join("Member m",'m.id = r.user_id')
            ->where($where_money)
            ->field("m.name,m.tel,r.*")
            ->order('r.create_time desc')
            ->paginate(10,false,['query'=>$arr]);
        $page = $money_list->render();
        $this->assign('page',$page);
        $this->assign('lists',$money_list);
        return $this->fetch('index');
    }



//    同意投诉
    public function agree(){
        $data = $this->request->param();
        $where_money['id'] = $data['id'];
        $where_money['status'] = array('neq',9);
        $money = Db::name('Complaint')->where($where_money)->find();
        if($money){
            $save['status'] = 2;
            $save['update_time'] = time();
            $update = Db::name('Complaint')->where($where_money)->update($save);
            if($update){
                $this->success('成功');
            }else{
                $this->error('失败');
            }
        }else{
            $this->error('投诉状态不正确');
        }
    }

    //    拒绝投诉
    public function refuse(){
        $data = $this->request->param();
        $where_money['id'] = $data['id'];
        $where_money['status'] = array('neq',9);
        $money = Db::name('Complaint')->where($where_money)->find();
        if($money){
            $save['status'] = 3;
            $save['update_time'] = time();
            $update = Db::name('Complaint')->where($where_money)->update($save);
            if($update){
                $where_need['id'] = $money['need_id'];
                $where_need['status'] = array('neq',9);
                $findNeed = Db::name('UserNeed')->where($where_need)->find();
                $needTime = ($findNeed['next_choose_time']+259200)-$findNeed['complaint_time'];
                $change_need['refuse_complaint_time'] = time()+$needTime;
                $change_need['status'] = 14;
                $saveNeed = Db::name('UserNeed')->where($where_need)->update($change_need);
                if(!$saveNeed){
                    $this->error('拒绝失败');
                }
                $where_agency['id'] = $money['intermediary_id'];
                $where_agency['status'] = array('neq',9);
                $findAgency = Db::name('UserNeed')->where($where_agency)->find();
                $agencyTime = ($findAgency['choose_time']+259200)-$findAgency['complaint_time'];
                $change_agency['refuse_complaint_time'] = time()+$agencyTime;
                $change_agency['status'] = 14;
                $saveAgency = Db::name('UserNeed')->where($where_agency)->update($change_agency);
                if(!$saveAgency){
                    $this->error('拒绝失败');
                }
                $this->success('成功');
            }else{
                $this->error('失败');
            }
        }else{
            $this->error('订单状态不正确');
        }
    }




    /**
     * 后台删除第三方用户绑定
     * @adminMenu(
     *     'name'   => '删除第三方用户绑定',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除第三方用户绑定',
     *     'param'  => ''
     * )
     */
    public function del()
    {
        $ids = $this->request->post();
        $id = $this->request->param('id');
        if ($ids) {
            $where_del['id'] = array('in', $ids['ids']);
        } else if ($id) {
            $where_del['id'] = $this->request->param('id');
        } else {
            $this->error('删除失败');
        }
        $add_del['status'] = 9;
        $add_del['update_time'] = time();
//        $model = new NewModel();
        $del = Db::name('Refund')->where($where_del)->update($add_del);
        if ($del) {
            $this->success('删除成功', url('index'));
        } else {
            $this->error('删除失败');
        }
    }
}