UsersController.php 4.5 KB
<?php
namespace app\admin\controller;

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

    /**
     * 显示用户列表
     */
    public function user_list(){

        if($this -> request -> isPost()){
            $where = [
                'a.create_time' => ['>=', 0],
            ];
            if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
                $start_time = strtotime($_POST['start_time']);
                $end_time = strtotime($_POST['end_time']);
                $where['a.create_time'] = [['>=',$start_time],['<=',$end_time]];
            }
            if(!empty($_POST['keyword'])){
                $keyword = $_POST['keyword'];
                $where['b.user_nickname'] = ['like',"%$keyword%"];
            }
            if($_POST['identity'] != ""){
                $where['a.status'] = $_POST['identity'];
            }
            $data = Db::name('my_user') -> alias('a') -> field('a.*,b.user_nickname') -> join('user b','a.uid = b.id','LEFT') -> where($where) -> paginate(12);
        }else{
            $data = Db::name('my_user') -> alias('a') -> field('a.*,b.user_nickname') -> join('user b','a.uid = b.id','LEFT') ->  paginate(12);

        }
        $this -> assign('data',$data);
        return $this -> fetch();

    }

    /**
     * 设置为业务员
     */
    public function set_salesman(){

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

    }

    /**
     * 下线老师列表
     */
    public function teacher_list(){

        if($this -> request -> isPost()){
            $where = [
                'status' => 3,
                'pid' => $_POST['salesman_id']
            ];
            if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
                $start_time = strtotime($_POST['start_time']);
                $end_time = strtotime($_POST['end_time']);
                $where['a.create_time'] = [['>=',$start_time],['<=',$end_time]];
            }
            if(!empty($_POST['keyword'])){
                $keyword = $_POST['keyword'];
                $where['user_nickname'] = ['like',"%$keyword%"];
            }
            $this -> assign('salesman_id',$_POST['salesman_id']);
            $data = Db::name('my_user') -> alias('a') -> field('a.*,b.user_nickname') -> join('user b','a.uid = b.id','left') -> where($where) -> paginate(12);
            $data_arr = $data -> toArray();
        }else{
            $id = $this -> request -> param();
            $this -> assign('salesman_id',$id['id']);
            $data = Db::name('my_user') -> where("status = 3 and pid =".$id['id']) -> paginate(12);
            $data_arr = $data -> toArray();
            foreach($data_arr['data'] as $key => $val){
                $data_nick = Db::name('user') -> where('id',$data[$key]['uid']) -> find();
                $data_arr['data'][$key]['user_nickname'] = $data_nick['user_nickname'];
            }
        }

        $this -> assign('data',$data);
        $this -> assign('data_arr',$data_arr['data']);
        return $this -> fetch();

    }

    /**
     * 下线学生列表
     */
    public function student_list(){

        if($this -> request -> isPost()){
            $teacher_id = $_POST['teacher_id'];
            $where = [
                'a.status' => 4,
                'a.pid' => $teacher_id
            ];
            if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
                $start_time = strtotime($_POST['start_time']);
                $end_time = strtotime($_POST['end_time']);
                $where['a.create_time'] = [['>=',$start_time],['<=',$end_time]];
            }
            if(!empty($_POST['keyword'])){
                $keyword = $_POST['keyword'];
                $where['b.user_nickname'] = ['like',"%$keyword%"];
            }
            $data = Db::name('my_user') -> alias('a') -> field('a.*,b.user_nickname') -> join('user b','a.uid = b.id','left') -> where($where) -> paginate(12);
        }else{
            $id = $this -> request -> param();
            $teacher_id = $id['teacher_id'];
            $data = Db::name('my_user') -> alias('a') -> field('a.*,b.user_nickname') -> join('user b','a.uid = b.id','left') -> where("a.status = 4 and a.pid =".$teacher_id) -> paginate(12);
        }
        $this -> assign('teacher_id',$teacher_id);
        $this -> assign('data',$data);
        return $this -> fetch();

    }





























}