<?php
|
|
namespace app\admin\controller;
|
|
use think\facade\Db;
|
use think\facade\View;
|
use think\facade\Request;
|
|
class Administrators extends Common {
|
|
public function index() {
|
////////
|
View::assign('menuitem', strtolower('administrators-index'));
|
|
$other['title'] = '管理员';
|
$guide['one']['text'] = '安全中心';
|
$guide['two']['text'] = '管理员';
|
$guide['two']['url'] = url('/admin/administrators/index')->build();
|
View::assign('guide', $guide);
|
|
|
View::assign('other', $other);
|
return View::fetch('index');
|
}
|
|
public function adminlist() {
|
if (Request::isPost()) {
|
$kw = input('kw');
|
$condition = [];
|
if (!empty($kw)) {
|
$condition[] = array('user_name|real_name', 'like', "%$kw%");
|
}
|
$p = input('p', 1);
|
$_GET['p'] = $p;
|
$other['page_size'] = input('page_size', 20);
|
$order = 'initialize desc,id asc';
|
$count = Db::name('administrators')->where($condition)->count();
|
$list = Db::name('administrators')->field("id,user_name,real_name,ban_access,phone,initialize,login_time,login_ip")->where($condition)->order($order)->page($p, $other['page_size'])->select()->toArray();
|
$other['count'] = $count;
|
if (!$list) {
|
$list = [];
|
}
|
$other['admin_info'] = $this->cinfo;
|
$d['code'] = 200;
|
$d['list'] = $list;
|
$d['other'] = $other;
|
return $d;
|
}
|
}
|
|
public function update_ban_access() {
|
header('Content-Type:text/html;charset=utf-8');
|
if (Request::isPost()) {
|
|
$id = input('id');
|
$sub_ban_access = input('ban_access');
|
$info = Db::name('administrators')->field('id')->where('id', $id)->find();
|
if (empty($info)) {
|
$d['code'] = 400;
|
$d['message'] = '信息不存在';
|
return $d;
|
}
|
///
|
|
if (is_numeric($id)) {
|
if ($sub_ban_access == '1') {
|
$dd['ban_access'] = 1;
|
$d['ban_access'] = 1;
|
$d['message'] = '允许登录';
|
} else {
|
$dd['ban_access'] = 0;
|
$d['ban_access'] = 0;
|
$d['message'] = '禁止登录';
|
}
|
$backval = Db::name('administrators')->where('id', $id)->save($dd);
|
if ($backval === FALSE) {
|
$d['code'] = 400;
|
} else {
|
$d['code'] = 200;
|
}
|
} else {
|
$d['code'] = 400;
|
}
|
} else {
|
$d['code'] = 400;
|
}
|
return $d;
|
}
|
|
|
public function save_admin() {
|
if (Request::isPost()) {
|
header('Content-Type:text/html;charset=utf-8');
|
$data = Request::post();
|
$id = input('post.id');
|
$password = input('pwd');
|
if (empty($password)) {
|
} else {
|
$data['password'] = joinmd5($password);
|
}
|
|
if (is_numeric($id)) {//更新数据
|
/////验证密码复杂度///////////
|
$validate = new \app\admin\validate\Administrators();
|
$result = $validate->scene('edit')->check($data);
|
if (!$result) {
|
$d['code'] = 400;
|
$d['message'] = $validate->getError();
|
return $d;
|
}
|
|
$backval = Db::name('administrators')->where('id', $id)->withoutField('id')->save($data);
|
if ($backval === false) {
|
$d['code'] = 400;
|
$d['message'] = '编辑失败';
|
} else {
|
////增加系统操作记录//
|
$d['code'] = 200;
|
$d['message'] = '编辑成功';
|
}
|
} else {
|
unset($data['id']);
|
$data['add_time'] = time();
|
$data['start_time'] = time();
|
$data['end_time'] = time() + 3600 * 24 * 7;
|
/////验证试卷名称是否存在///////////
|
$validate = new \app\admin\validate\Administrators();
|
$result = $validate->check($data);
|
if (!$result) {
|
$d['code'] = 400;
|
$d['message'] = $validate->getError();
|
return $d;
|
}
|
//添加数据
|
$result = Db::name('administrators')->insertGetId($data);
|
if ($result !== false) {
|
$d['code'] = 200;
|
$d['message'] = '添加成功';
|
} else {
|
$d['code'] = 400;
|
$d['message'] = '添加失败';
|
}
|
}
|
} else {
|
$d['code'] = 400;
|
$d['message'] = '非法请求';
|
}
|
return $d;
|
}
|
|
public function delete_admin() {
|
if (Request::isPost()) {
|
$id = input('id');
|
if (is_numeric($id)) {
|
$condition['id'] = $id;
|
$info = Db::name('administrators')->field('id,initialize')->where($condition)->find();
|
if ($info) {
|
///////////////////
|
if ($info['initialize'] == '1') {
|
$d['code'] = 400;
|
$d['message'] = '该账号不能删除!';
|
return $d;
|
}
|
if ($this->cinfo['initialize'] == 1 || $this->admin_id == $info['id']) {
|
Db::name('administrators')->where('id', $id)->delete();
|
/////////////////////////////
|
$d['code'] = 200;
|
$d['message'] = '删除成功!';
|
} else {
|
$d['code'] = 400;
|
$d['message'] = '您没有删除权限';
|
}
|
} else {
|
$d['code'] = 400;
|
$d['message'] = '子账号不存在';
|
}
|
} else {
|
$d['code'] = 400;
|
$d['message'] = '参数有误!';
|
}
|
return $d;
|
}
|
}
|
|
|
}
|