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(){

        if($this -> request -> isPost()){
            $where = [
                'is_audit' => 0,
            ];
            if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
                $start_time = strtotime($_POST['start_time']);
                $end_time = strtotime($_POST['end_time']);
                $where['create_time'] = [['>=',$start_time],['<=',$end_time]];
            }
            if(!empty($_POST['keyword'])){
                $where['phone'] = $_POST['keyword'];
            }
            $data = Db::name('sale_audit') -> where($where) -> paginate(1000000);
            $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'];
            }
        }else{
            $data = Db::name('sale_audit') -> where('is_audit',0) -> paginate(12);
            $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('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();
            $chongfu = Db::name('sale_audit') -> where("id_number=".$id_number['id_number']." and is_audit=1") -> find();
            if(!empty($chongfu)){
                $this -> error('身份证号重复');
            }
            Db::name('my_user') -> where('uid',$uid) -> update(['status'=>2,'audit_time'=>$time]);
            $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;
        }

    }













}