$instance
$instance : object
Reference to the CI singleton
管理员管理
This class object is the super class that every library in CodeIgniter will be assigned to.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* 管理员管理
* @author lxn
*/
class Adminuser extends CI_Controller
{
private static $data = array();
public function __construct()
{
parent::__construct();
$this->load->model('Role_model', 'role');
$this->load->model('Admin_model', 'admin');
$this->load->model('Public_model', 'public');
$this->load->model('Webcommon_model','common');//积分流水表
self::$data['header'] = $this->public->header('管理员');
self::$data['left'] = $this->public->leftmenu('adminuser');
self::$data['footer'] = $this->public->footer();
$this->load->library('Session');
$this->public->authentication();
}
/**
* 顾问列表
*/
public function index()
{
if($_GET){
//获取Datatables发送的参数 必要
$draw = $_GET['draw'];//这个值作者会直接返回给前台
//排序
$order_column = $_GET['order']['0']['column'];//那一列排序,从0开始
$order_dir = $_GET['order']['0']['dir'];//ase desc 升序或者降序
//拼接排序sql
$orderSql = "";
if(isset($order_column)){
$i = intval($order_column);
switch($i){
case 0;$orderSql = " order by adminId ".$order_dir;break; //ID
case 3;$orderSql = " order by roleId ".$order_dir;break; //分类
default;$orderSql = '';
}
}
//搜索
$search = $_GET['search']['value'];//获取前台传过来的过滤条件
//分页
$start = $_GET['start'];//从多少开始
$length = $_GET['length'];//数据长度
$limitSql = '';
$limitFlag = isset($_GET['start']) && $length != -1 ;
if ($limitFlag ) {
$limitSql = " LIMIT ".intval($start).", ".intval($length);
}
//定义查询数据总记录数sql
$sumSql = "SELECT count(*) as sum FROM admin as a WHERE a.deleteFlag=0";
//定义过滤条件查询过滤后的记录数sql
$sumSqlWhere =" and (a.adminName LIKE '%".$search."%' or a.realName LIKE '%".$search."%')";
//条件过滤后记录数 必要
$recordsFiltered = 0;
//表的总记录数 必要
$recordsTotal = 0;
//查询总数
$total = $this->common->getsqldata($sumSql);
// var_dump($total);exit;
$recordsTotal = $total[0]['sum'];
$totalResultSql = "SELECT a.* FROM admin as a WHERE a.deleteFlag=0";
if(strlen($search)>0){
//记录总数
$total = $this->common->getsqldata($sumSql.$sumSqlWhere);
$recordsFiltered = $total[0]['sum'];
$list =$this->common->getsqldata($totalResultSql.$sumSqlWhere.$orderSql.$limitSql);
}else{
//记录总数
$recordsFiltered = $recordsTotal;
$list = $this->common->getsqldata($totalResultSql.$orderSql.$limitSql);
}
header("Content-Type:text/html;charset=utf-8");
// $list = $this->catsort($list,0,1);
foreach($list as $key=>$value)
{
$roleInfo = $this->role->getRoleRow( $value['roleId']);
$list[$key]['roleName'] = $roleInfo['roleName'];
}
exit(json_encode(array(
"draw" => intval($draw),
"recordsTotal" => intval($recordsTotal),
"recordsFiltered" => intval($recordsFiltered),
"data" => $list
)));
}else {
$this->load->view('admincp/adminuser/adminuserlist', self::$data);
}
}
/**
* 添加/修改页
*/
public function edit($adminId = 0)
{
$adminId = $this->input->get_post('adminId');
// 获取栏目信息
$roleInfo = $this->role->getRoleList('','roleId,roleName',100);
$adminUserInfo = $this->admin->getAdminRow($adminId);
self::$data['adminId'] = $adminId;
self::$data['adminUserInfo'] = $adminUserInfo;
self::$data['roleList'] = $roleInfo;
$this->load->view('admincp/adminuser/adminuserinfo', self::$data);
}
/**
* 添加/修改页
*/
public function editpass()
{
self::$data['adminName'] = $_SESSION['adminName'];
$this->load->view('admincp/adminuser/editpass', self::$data);
}
/**
* 添加/修改数据库
*/
public function updatepass()
{
$referer = !empty($url) ? $this->config->item('base_url') . base64_decode($url) : $this->config->item('base_url') . '/admincp/adminuser/editpass';
$oldpassword = $this->input->post('password');
$newpassword = $this->input->post('newpassword');
$newpassword2 = $this->input->post('newpassword2');
if ($newpassword!=$newpassword2){
$msg = '修改失败!,两次密码不同';
$isok = 1;
echo $this ->public->message( $msg, $referer, $isok, array(), array('keyword'=>'adminuser'));exit;
}
// var_dump($_SESSION);exit;
$adminId = $_SESSION['adminId'];
$adminUserInfo = $this->admin->getAdminRow($adminId);
if (md5($oldpassword)!=$adminUserInfo['password']){
$msg = '修改失败!,原密码错误';
$isok = 1;
echo $this ->public->message( $msg, $referer, $isok, array(), array('keyword'=>'adminuser'));exit;
}
$userData = array(
'password' => md5($newpassword),
);
// var_dump($userData);exit;
$bool = $this->admin->setAdminByID($userData, $adminId);
$msg = $bool ? '修改成功!' : '修改失败!';
$isok = $bool ? 0 : 1;
echo $this ->public->message( $msg, $referer, $isok, array(), array('keyword'=>'adminuser'));exit;
}
/**
* 添加/修改数据库
*/
public function updateData()
{
$url = trim($this->input->get_post('backurl'));
$referer = !empty($url) ? $this->config->item('base_url') . base64_decode($url) : $this->config->item('base_url') . '/admincp/adminuser';
$adminId = $this->input->post('adminId');
$adminName = $this->input->post('adminName');
$realName = $this->input->post('realName');
$password = $this->input->post('password');
$roleId = $this->input->post('roleId');
if (empty($adminId))
{
$password = md5($password);
$userData = array(
'adminName' => $adminName,
'realName' => $realName,
'password' => $password,
'roleId' => $roleId
);
$bool = $this->admin->insertData( $userData );
$msg = $bool ? '添加成功!' : '添加失败!';
$isok = $bool ? 0 : 1;
}
else
{
$userData = array(
'adminName' => $adminName,
'realName' => $realName,
'roleId' => $roleId
);
if(!empty($password))
{
$password = md5($password);
$userData = array_merge($userData,array('password'=>$password));
}
$bool = $this->admin->setAdminByID($userData, $adminId);
$msg = $bool ? '修改成功!' : '修改失败!';
$isok = $bool ? 0 : 1;
}
echo $this ->public -> message( $msg, $referer, $isok, array(), array('keyword'=>'adminuser'));exit;
}
/**
* 检查栏目名称和关键字唯一
* */
public function ajaxcheck()
{
$res = array('status' => 0);
$adminId = $this->input->post('adminId');
$adminName = $this->input->post('adminName');
$data = $this->admin->checkUnique(trim($adminName),$adminId);
if(!empty($data))
{
$res['status'] = 1;
}
echo json_encode($res);
}
/**
* 删除角色
*/
public function delete()
{
$res = array(
'err' => 1,
'msg' => '系统错误'
);
$adminId = trim($this->input->get_post('adminId'));
$adminInfo = $this->admin->getAdminRow($adminId);
if (empty($adminInfo))
{
$res['msg'] = '参数错误';
echo json_encode($res);
exit();
}
$bool = $this->admin->delete( $adminId );
$res['err'] = $bool ? 0 : 1;
$res['msg'] = $bool ? '删除成功' : '删除失败';
echo json_encode($res);
exit();
}
public function qrcode()
{
$this->load->view('admincp/adminuser/qrcode', self::$data);
}
public function generateQRfromGoogle($widhtHeight ='150')
{
$chl = "http://m-dev.zhiyuntcm.com/#/register";
$chl = urlencode($chl);
echo '<img src="https://api.qrserver.com/v1/create-qr-code/?size='.$widhtHeight.'x'.$widhtHeight.'
&data='.$chl.'" alt="QR code" />';
}
}