UsersController.php 6.1 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'] != ""){
                if($_POST['identity'] == -1){
                    $where['a.status'] = 0;
                }else{
                    $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(1000000);
        }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(1000000);
            $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'];
            }
        }

        foreach ($data_arr['data'] as $key => $val){
            $money_income = Db::name('money_income') -> where('uid',$val['uid']) -> select();
            $m_money = 0;
            foreach ($money_income as $key1 => $val1){
                $m_money += $val1['money'];
            }
            $data_arr['data'][$key]['money'] = $m_money;
        }

        $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(1000000);
        }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();

    }


    /**
     * 显示余额明细页
     */
    public function users_money(){

        $uid = $this -> request -> param();
        $data = Db::name('money_income') -> where('uid',$uid['uid']) -> select() -> toArray();
        if(!empty($data)){
            foreach ($data as $key => $val){
                if($val['type'] == 2){
                    $data[$key]['indent'] = Db::name('indent') -> where('id',$val['indent_id']) -> find();
                    $indent_good = Db::name('indent_goods') -> where('indent_id',$val['indent_id']) -> select() -> toArray();
                    $indent_goods = '';
                    foreach ($indent_good as $key1 => $val1){
                        $indent_goods .= $val1['book_name'].',';
                    }
                    $data[$key]['indent_good'] = $indent_goods;
                }else{
                    $data[$key]['indent'] = Db::name('indent') -> where('id',$val['indent_id']) -> find();
                    $data[$key]['indent_good'] = $val['book_name'];
                }
            }
        }
        $this -> assign('data',$data);
        return $this -> fetch();

    }

























}