<?php
namespace Smi\Controller;

use Think\Controller;

header("Content-Type:text/html;CharSet=UTF-8");
class UsersController extends BaseController
{
    /**
     * 用户列表
     */
    public function userList($search = '')
    {   
        $where = array();
        if (!empty($search)) {
            $where['id|nickname'] = array('like', '%'.$search.'%');
        }
        if (session('is_business') == 1) {
            $where['admin_id'] = session('admin_id');
        }

        $count = M("users")->where($where)->count();// 查询满足要求的总记录数
        // 实例化分页类 传入总记录数和每页显示的记录数($l)
        $Page = new \Think\Page($count, 15);
        $show = $Page->show();// 分页显示输出
        $list = M('users')->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->order('create_time DESC')->select();
        $this->assign('page', $show);
        $this->assign('list', $list);
        $this->assign('search', $search);
        $this->display();
    }

    /**
     * 删除用户
     */
    public function usersDel()
    {
//        auth_check("users_opt");
        //接收 ID
        $id = I("id");
        if (!$id) $this->error('系统错误，参数id不能为空');
        $bool = M("users")->delete($id);

        if ($bool) {
            $this->success('删除成功');
        } else {
            $this->error('参数失败');
        }
        
    }
}