quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
 
namespace app\operations\controller\plus\region;
 
use app\operations\controller\Controller;
use app\operations\model\plus\region\UserLogin as UserLoginModel;
use app\operations\model\plus\region\UserRole as UserRoleModel;
use app\operations\model\plus\region\Role as RoleModel;
 
/**
 * 区域代理管理员控制器
 */
class UserLogin extends Controller
{
    /**
     * 管理员列表
     */
    public function index()
    {
        $model = new UserLoginModel();
        $list = $model->getList($this->postData());
        // 获取角色列表
        $roleList = (new RoleModel)->getTreeData();
 
        return $this->renderSuccess('', compact('list', 'roleList'));
    }
 
    /**
     * 添加区域代理管理员
     */
    public function add()
    {
        $model = new UserLoginModel();
        $data = $this->postData();
 
        if ($model->add($data)) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError($model->getError() ?: '添加失败');
    }
 
    /**
     * 编辑管理员需要的数据
     */
    public function editInfo()
    {
        $model = UserLoginModel::detail($this->getData('operations_user_id'));
        $model['roles'] = UserRoleModel::where('operations_user_id', '=', $model['operations_user_id'])
            ->column('role_id');
        
        // 获取角色列表
        $roleList = RoleModel::getList();
        
        return $this->renderSuccess('', compact('model', 'roleList'));
    }
 
    /**
     * 编辑管理员
     */
    public function edit()
    {
        $data = $this->postData();
        $model = UserLoginModel::detail($data['operations_user_id']);
 
        if ($model->edit($data)) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError($model->getError() ?: '更新失败');
    }
 
    /**
     * 删除管理员
     */
    public function delete()
    {
        $model = UserLoginModel::detail($this->postData('operations_user_id'));
        
        // 超级管理员不允许删除
        if ($model['is_super'] == 1) {
            return $this->renderError('超级管理员不允许删除');
        }
 
        if ($model->del(['operations_user_id' => $model['operations_user_id']])) {
            return $this->renderSuccess('删除成功');
        }
        return $this->renderError($model->getError() ?: '删除失败');
    }
 
    /**
     * 修改状态
     */
    public function status()
    {
        $model = UserLoginModel::detail($this->postData('operations_user_id'));
        
        // 超级管理员不允许修改状态
        if ($model['is_super'] == 1) {
            return $this->renderError('超级管理员不允许修改状态');
        }
 
        $status = $this->postData('status');
        // 注意:这里应该是 is_delete 字段,但状态修改可能需要其他字段
        // 根据 auth 模块,这里可能使用的是启用/禁用字段
        if ($model->save(['is_delete' => $status]) !== false) {
            return $this->renderSuccess('修改成功');
        }
        return $this->renderError('修改失败');
    }
}