审查视图

app/admin/controller/UsersController.php 5.2 KB
anyv authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
<?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'];
            }
        }
anyv authored
88 89 90 91 92 93 94 95 96
        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;
        }
anyv authored
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
        $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();

    }

anyv authored
136 137 138 139
    /**
     * 显示余额明细页
     */
    public function users_money(){
anyv authored
140
anyv authored
141 142 143 144
        $uid = $this -> request -> param();
        $data = Db::name('money_income') -> where('uid',$uid['uid']) -> select();
        $this -> assign('data',$data);
        return $this -> fetch();
anyv authored
145
anyv authored
146
    }
anyv authored
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

























}