管理员列表 #7

Merged
pengda merged 1 commits from wpd_user_list into master 2 months ago
  1. 2
      config/define.php
  2. 31
      control/index.php
  3. 13
      index.php
  4. 51
      model/mUser.php
  5. 6
      view/css/index.css
  6. 172
      view/templates/index/user_list.html

2
config/define.php

@ -28,7 +28,7 @@
define('CSS_URL', '//zhishiku.yizherenxin.cn');
//css/js版本
define('CSS_JS_VERSION', '1.0.0000001');
define('CSS_JS_VERSION', '1.0.0000002');
define('ALIYUN_OSS_ACCESS_KEY_ID', 'LTAI5tRBq7yr1vcdvhqNMb7P');
define('ALIYUN_OSS_ACCESS_KEY_SECRET', 'E4No4AjlWGrHSULsR8apZkTAC8DMw6');

31
control/index.php

@ -21,4 +21,35 @@ class index extends publicBase {
header('location:/');
exit();
}
public function user_list() {
$user_info = $this->get_user_info();
if (!$user_info['is_super_admin']) $this->show_message('您没有权限', 'goback');
$uobj = new mUser();
$this->view['user_list'] = $uobj->getAdminUserList();
$this->view['login_list'] = $uobj->getLoginUserList();
}
public function ajax_change_user_status() {
$id = $this->post('id') + 0;
$status = $this->post('status') + 0;
$uobj = new mUser();
$res = $uobj->updateAdminUser($id, array('status' => $status));
if (!$res) $this->ajax_json(false, '设置失败');
$this->ajax_json(true, '设置成功');
}
public function ajax_pass_user() {
$id = $this->post('id') + 0;
$aid = 1; //当前默认aid为1
$uobj = new mUser();
$res = $uobj->passLoginUser($id, $aid);
if (!$res) $this->ajax_json(false, $uobj->getError());
$this->ajax_json(true, '设置成功');
}
}

13
index.php

@ -80,6 +80,19 @@ error_reporting(E_ERROR); // 记录所有级别的错误
header("Location: /login?url=".$_SERVER['REQUEST_URI']);
exit();
}
$uobj = new mUser();
$user_info = $uobj->getAdminUserByOpenid($_SESSION['openid']);
if(empty($user_info)){
header("Location: /login?url=".$_SERVER['REQUEST_URI']);
exit();
}
if($this->control_name == 'weibo' && $user_info['aid'] != 1 && $user_info['is_super_admin'] != 1){
exit('No permission 暂无权限,请联系管理员');
}
$this->view['_user_info'] = $this->para['_user_info'] = $user_info;
}
}

51
model/mUser.php

@ -21,11 +21,62 @@ class mUser extends mBase {
return $this->obj->select($this->tbl, array('sql' => '`openid`=?', 'vals' => array($openid)));
}
public function getAdminUserList() {
return $this->obj->selectAll($this->tbl, array(), 'id desc ');
}
public function updateAdminUser($id, $data) {
return $this->obj->update($this->tbl, $data, array('sql' => '`id`=?', 'vals' => array($id)));
}
public function getLoginUserByOpenid($openid) {
return $this->obj->select($this->login_tbl, array('sql' => '`openid`=?', 'vals' => array($openid)));
}
public function getLoginUserById($id) {
return $this->obj->select($this->login_tbl, array('sql' => '`id`=?', 'vals' => array($id)));
}
public function addLoginUser($data) {
return $this->obj->insert($this->login_tbl, $data);
}
public function getLoginUserList() {
return $this->obj->selectAll($this->login_tbl, array(), 'id desc ', array(0, 10));
}
public function passLoginUser($id, $aid) {
$login_user = $this->getLoginUserById($id);
if (empty($login_user)) {
$this->setError('用户不存在');
return false;
}
$admin_user = $this->getAdminUserByOpenid($login_user['openid']);
if (!empty($admin_user)) {
$this->setError('审核员已存在');
return false;
}
$data = array(
'aid' => $aid,
'nickname' => $login_user['nickname'],
'openid' => $login_user['openid'],
'status' => 1,
);
$res = $this->obj->insert($this->tbl, $data);
if (!$res) {
$this->setError('添加失败');
return false;
}
$res = $this->obj->delete($this->login_tbl, array('sql' => 'id=?', 'vals' => array($id)));
if (!$res) {
$this->setError('删除申请失败');
return false;
}
return true;
}
}

6
view/css/index.css

@ -462,6 +462,12 @@ button:hover {
border: none;
}
.button-danger {
background: #cc0303;
color: #FFFFFF;
border: none;
}
.button-normal {}
.button.checkBtn{
width: 119px !important;

172
view/templates/index/user_list.html

@ -0,0 +1,172 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>知识库</title>
<link rel="stylesheet" href="{$smarty.const.CSS_URL}/css/common.css?v={$smarty.const.CSS_JS_VERSION}">
<link rel="stylesheet" href="{$smarty.const.CSS_URL}/css/index.css?v={$smarty.const.CSS_JS_VERSION}">
<script src="{$smarty.const.CSS_URL}/js/jquery-3.6.0.min.js"></script>
</head>
{literal}
<style>
table {
width: 100%;
border-collapse: collapse;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
margin-bottom: 50px;
}
caption {
font-size: 18px;
font-weight: bold;
padding: 10px;
color: #333;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #4CAF50;
color: white;
}
tr:hover {
background-color: #f1f1f1;
}
/* 响应式表格 */
@media (max-width: 600px) {
table {
width: 100%;
}
th, td {
display: block;
text-align: right;
padding: 10px;
}
th {
text-align: left;
background-color: #3b8c40;
}
}
</style>
{/literal}
<body>
<div class="home-page">
<div class="header-wrap">
<img class="home-logo" src="{$smarty.const.CSS_URL}/images/home-logo.png" alt="">
<div class="header-right flex">
<img src="{$smarty.const.CSS_URL}/images/home-more.png" alt="">
<div class="dropdown">
<button class="dropdown-toggle">
{$nickname}
<img class="icon" src="{$smarty.const.CSS_URL}/images/drop-icon.svg" alt="">
</button>
<div class="dropdown-panel">
<a href="/loginout">退出</a>
</div>
</div>
</div>
</div>
<div class="home-main-content">
<table>
<caption>审核员列表</caption>
<tr>
<td>ID</td>
<td>昵称</td>
<td>真实姓名</td>
<td>操作</td>
</tr>
{foreach from=$user_list key=key item=item}
<tr>
<td>{$item.id}</td>
<td>{$item.nickname}</td>
<td>{$item.real_name}</td>
<td>
{if $item.is_super_admin == 0}
<button data-id="{$item.id}" class="change-status button {if $item.status==0}button-primary{else}button-danger{/if}">{if $item.status==0}启用{else}禁用{/if}</button>
{/if}
</td>
</tr>
{/foreach}
</table>
{if $login_list}
<table>
<caption>申请列表</caption>
<tr>
<td>ID</td>
<td>昵称</td>
<td>登陆时间</td>
<td>操作</td>
</tr>
{foreach from=$login_list key=key item=item}
<tr>
<td>{$item.id}</td>
<td>{$item.nickname}</td>
<td>{$item.addtime}</td>
<td>
<button data-id="{$item.id}" class="button button-primary passBtn">审核通过</button>
</td>
</tr>
{/foreach}
</table>
{/if}
</div>
<div class="leftSideFooterNew">
<p>Copyright &copy;2012-2025 .</p>
<p><span>All Rights Reserved</span> 底部随便写的</p>
</div>
</div>
</body>
{literal}
<script>
$('.change-status').click(function (){
var id = $(this).data('id');
var status = $(this).hasClass('button-danger') ? 0 : 1;
var that = $(this);
$.ajax({
type: "post",
dataType: 'json',
url: '/index/ajax_change_user_status',
data: {
id,
status
},
success: function (res) {
alert(res.info)
if(res.status){
if(status==1){
that.html('禁用').removeClass('button-primary').addClass('button-danger');
}else{
that.html('启用').addClass('button-primary').removeClass('button-danger');
}
}
}
})
})
$('.passBtn').click(function (){
var id = $(this).data('id');
$.ajax({
type: "post",
dataType: 'json',
url: '/index/ajax_pass_user',
data: {
id,
status
},
success: function (res) {
alert(res.info)
if(res.status){
window.location.reload();
}
}
})
})
</script>
{/literal}
</html>
Loading…
Cancel
Save