AuditController.php 3.1 KB
<?php
namespace app\admin\controller;

use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use think\Db;
class AuditController extends AdminBaseController{

    /**
     *业务员审核列表
     */
    public function audit_list(){
        $param = $this->request->param();
        $where = [
            'is_audit' => 0,
        ];
        if(!empty($param['start_time']) && !empty($param['end_time'])){
            $start_time = strtotime($param['start_time']);
            $end_time = strtotime($param['end_time']);
            $where['create_time'] = [['>=',$start_time],['<=',$end_time]];
        }
        if(!empty($param['keyword'])){
            $where['phone'] = ['like','%'.trim($param['keyword']).'%'];
        }
        $data = Db::name('sale_audit')->where($where)->order('create_time','DESC')->paginate(12);
        $data->appends($param);
        $data_arr = $data -> toArray();
        foreach($data_arr['data'] as $key => $val){
            $data_user = Db::name('user') -> where('id',$val['uid']) -> find();
            $data_arr['data'][$key]['wname'] = $data_user['user_nickname'];
        }
        $this->assign('start_time',!empty($param['start_time']) ? $param['start_time'] : '');
        $this->assign('end_time',!empty($param['end_time']) ? $param['end_time'] : '');
        $this->assign('keyword',!empty($param['keyword']) ? trim($param['keyword']) : '');
        $this -> assign('data',$data);
        $this -> assign('data_arr',$data_arr['data']);
        return $this -> fetch();

    }

    /**
     * 业务员审核编辑
     */
    public function audit_edit(){

        if($this -> request -> isPost()){
            $id = $_POST['id'];
            $time = time();
            $uid = $_POST['uid'];
            //判断身份证号不能重复
            $id_number = Db::name('sale_audit') -> where('id',$id) -> find();
            $id_number_id = $id_number['id_number'];
            $chongfu = Db::name('sale_audit') -> where("id_number='$id_number_id' and is_audit=1") -> find();
            if(!empty($chongfu)){
                $this -> error('身份证号重复');
            }
            Db::name('my_user') -> where('uid',$uid) -> update(['status'=>2,'audit_time'=>$time,'is_pro'=>1]);
            $data = Db::name('sale_audit') -> where('id',$id) -> update(['is_audit'=>1]);
            if($data){
                $this -> success('审核通过',url('Audit/audit_list'));
            }else{
                $this -> error('审核失败');
            }
        }else{
            $id = $this -> request -> param();
            $data = Db::name('sale_audit') -> where('id',$id['id']) -> find();
            $this -> assign('data',$data);
            return $this -> fetch();
        }

    }

    /**
     * 业务员审核驳回
     */
    public function turn_down(){

        $uid = $_POST['uid'];
        $data = Db::name('my_user') -> where('uid',$uid) -> update(['status'=>6]);
        Db::name('sale_audit') -> where('uid',$uid) -> delete();
        if($data){
            return true;
        }else{
            return false;
        }

    }













}