mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-07-03 07:26:49 +08:00
增加删除和还原用户功能
This commit is contained in:
parent
d95b218812
commit
af4b570681
@ -140,4 +140,42 @@ class UserController extends Controller
|
||||
return $this->jsonSuccess($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/delete", name="admin.user.delete")
|
||||
*/
|
||||
public function deleteAction($id)
|
||||
{
|
||||
$userService = new UserService();
|
||||
|
||||
$userService->deleteUser($id);
|
||||
|
||||
$location = $this->url->get(['for' => 'admin.user.list']);
|
||||
|
||||
$content = [
|
||||
'location' => $location,
|
||||
'msg' => '删除用户成功',
|
||||
];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/restore", name="admin.user.restore")
|
||||
*/
|
||||
public function restoreAction($id)
|
||||
{
|
||||
$userService = new UserService();
|
||||
|
||||
$userService->restoreUser($id);
|
||||
|
||||
$location = $this->url->get(['for' => 'admin.user.list']);
|
||||
|
||||
$content = [
|
||||
'location' => $location,
|
||||
'msg' => '还原用户成功',
|
||||
];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ use App\Http\Admin\Services\Traits\AccountSearchTrait;
|
||||
use App\Library\Paginator\Query as PaginateQuery;
|
||||
use App\Library\Utils\Password as PasswordUtil;
|
||||
use App\Models\Account as AccountModel;
|
||||
use App\Models\Role as RoleModel;
|
||||
use App\Models\User as UserModel;
|
||||
use App\Repos\Account as AccountRepo;
|
||||
use App\Repos\Online as OnlineRepo;
|
||||
@ -242,6 +243,48 @@ class User extends Service
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function deleteUser($id)
|
||||
{
|
||||
$user = $this->findOrFail($id);
|
||||
|
||||
if ($user->admin_role == RoleModel::ROLE_ROOT) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user->deleted = 1;
|
||||
|
||||
$user->update();
|
||||
|
||||
$accountRepo = new AccountRepo();
|
||||
|
||||
$account = $accountRepo->findById($id);
|
||||
|
||||
$account->deleted = 1;
|
||||
|
||||
$account->update();
|
||||
|
||||
$this->rebuildUserCache($user);
|
||||
}
|
||||
|
||||
public function restoreUser($id)
|
||||
{
|
||||
$user = $this->findOrFail($id);
|
||||
|
||||
$user->deleted = 0;
|
||||
|
||||
$user->update();
|
||||
|
||||
$accountRepo = new AccountRepo();
|
||||
|
||||
$account = $accountRepo->findById($id);
|
||||
|
||||
$account->deleted = 0;
|
||||
|
||||
$account->update();
|
||||
|
||||
$this->rebuildUserCache($user);
|
||||
}
|
||||
|
||||
public function updateAccount($id)
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
|
@ -51,6 +51,8 @@
|
||||
{% set user_url = url({'for':'home.user.show','id':item.id}) %}
|
||||
{% set online_url = url({'for':'admin.user.online','id':item.id}) %}
|
||||
{% set edit_url = url({'for':'admin.user.edit','id':item.id}) %}
|
||||
{% set delete_url = url({'for':'admin.user.delete','id':item.id}) %}
|
||||
{% set restore_url = url({'for':'admin.user.restore','id':item.id}) %}
|
||||
<tr>
|
||||
<td class="center">
|
||||
<img class="kg-avatar-sm" src="{{ item.avatar }}!avatar_160" alt="{{ item.name }}">
|
||||
@ -87,7 +89,14 @@
|
||||
<ul>
|
||||
<li><a href="{{ user_url }}" target="_blank">用户主页</a></li>
|
||||
<li><a href="javascript:" class="kg-online" data-url="{{ online_url }}">在线记录</a></li>
|
||||
<li><a href="{{ edit_url }}">编辑用户</a></li>
|
||||
{% if item.admin_role.id != 1 %}
|
||||
<li><a href="{{ edit_url }}">编辑用户</a></li>
|
||||
{% if item.deleted == 0 %}
|
||||
<li><a href="javascript:" class="kg-delete" data-url="{{ delete_url }}">删除用户</a></li>
|
||||
{% else %}
|
||||
<li><a href="javascript:" class="kg-restore" data-url="{{ restore_url }}">还原用户</a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
|
@ -68,6 +68,13 @@
|
||||
<input type="radio" name="locked" value="0" title="否">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">是否删除</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="deleted" value="1" title="是">
|
||||
<input type="radio" name="deleted" value="0" title="否">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"></label>
|
||||
<div class="layui-input-block">
|
||||
|
Loading…
x
Reference in New Issue
Block a user