|
@@ -4,6 +4,9 @@ namespace app\admin\controller\user;
|
|
|
|
|
|
use app\common\controller\Backend;
|
|
use app\common\controller\Backend;
|
|
use app\common\library\Auth;
|
|
use app\common\library\Auth;
|
|
|
|
+use think\Db;
|
|
|
|
+use think\exception\PDOException;
|
|
|
|
+use think\exception\ValidateException;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 会员管理
|
|
* 会员管理
|
|
@@ -27,6 +30,9 @@ class User extends Backend
|
|
parent::_initialize();
|
|
parent::_initialize();
|
|
$this->model = model('User');
|
|
$this->model = model('User');
|
|
$this->view->assign("typesList", $this->model->getTypesList());
|
|
$this->view->assign("typesList", $this->model->getTypesList());
|
|
|
|
+
|
|
|
|
+ $group_list = ['author' => __('Author'), 'review' => __('Review'), 'editor' => __('editor')];
|
|
|
|
+ $this->view->assign('group_list', $group_list);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -42,16 +48,23 @@ class User extends Backend
|
|
return $this->selectpage();
|
|
return $this->selectpage();
|
|
}
|
|
}
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
-// $filter = $this->request->get("filter", '');
|
|
|
|
-// $filter = (array)json_decode($filter, true);
|
|
|
|
-// $filter = $filter ? $filter : [];
|
|
|
|
-// $type = $filter['type'];
|
|
|
|
|
|
|
|
-// if ()
|
|
|
|
|
|
+ $type = $this->request->param('type');
|
|
|
|
+ $new_where = [];
|
|
|
|
+ if ($type == 'author') {
|
|
|
|
+ $new_where['is_author'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ if ($type == 'review') {
|
|
|
|
+ $new_where['is_review'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ if ($type == 'editor') {
|
|
|
|
+ $new_where['is_editor'] = 'correct';
|
|
|
|
+ }
|
|
|
|
|
|
$list = $this->model
|
|
$list = $this->model
|
|
->with('group')
|
|
->with('group')
|
|
->where($where)
|
|
->where($where)
|
|
|
|
+ ->where($new_where)
|
|
->order($sort, $order)
|
|
->order($sort, $order)
|
|
->paginate($limit);
|
|
->paginate($limit);
|
|
foreach ($list as $k => $v) {
|
|
foreach ($list as $k => $v) {
|
|
@@ -101,8 +114,185 @@ class User extends Backend
|
|
if (!$row) {
|
|
if (!$row) {
|
|
$this->error(__('No Results were found'));
|
|
$this->error(__('No Results were found'));
|
|
}
|
|
}
|
|
|
|
+ $group = [];
|
|
$this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
|
|
$this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
|
|
- return parent::edit($ids);
|
|
|
|
|
|
+
|
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
|
+ if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
|
|
|
|
+ $this->error(__('You have no permission'));
|
|
|
|
+ }
|
|
|
|
+ if (false === $this->request->isPost()) {
|
|
|
|
+ if ($row['is_author'] == 'correct') {
|
|
|
|
+ $group[] = 'author';
|
|
|
|
+ }
|
|
|
|
+ if ($row['is_review'] == 'correct') {
|
|
|
|
+ $group[] = 'review';
|
|
|
|
+ }
|
|
|
|
+ if ($row['is_editor'] == 'correct') {
|
|
|
|
+ $group[] = 'editor';
|
|
|
|
+ }
|
|
|
|
+ $row->group = implode(',', $group);
|
|
|
|
+ $this->view->assign('row', $row);
|
|
|
|
+ return $this->view->fetch();
|
|
|
|
+ }
|
|
|
|
+ $params = $this->request->post('row/a');
|
|
|
|
+ if (empty($params)) {
|
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
|
+ }
|
|
|
|
+ $params = $this->preExcludeFields($params);
|
|
|
|
+ $result = false;
|
|
|
|
+ Db::startTrans();
|
|
|
|
+ try {
|
|
|
|
+ // 用户原来有的角色信息
|
|
|
|
+ $row_group = [];
|
|
|
|
+ // 如用户有角色需要删除角色可用
|
|
|
|
+ if ($row['is_author'] == 'correct') {
|
|
|
|
+ $row_group[] = 'author';
|
|
|
|
+ }
|
|
|
|
+ if ($row['is_review'] == 'correct') {
|
|
|
|
+ $row_group[] = 'review';
|
|
|
|
+ }
|
|
|
|
+ if ($row['is_editor'] == 'correct') {
|
|
|
|
+ $row_group[] = 'editor';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 用户选中的角色
|
|
|
|
+ $groups = $params['group'];
|
|
|
|
+ if ($groups[0] == '') {
|
|
|
|
+ unset($groups[0]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 原来角色有多个
|
|
|
|
+ if (count($row_group) > 0) {
|
|
|
|
+ // 新修改的身份全部取消
|
|
|
|
+ if (count($groups) == 0) {
|
|
|
|
+ $group_data['is_author'] = 'fault';
|
|
|
|
+ $group_data['is_review'] = 'fault';
|
|
|
|
+ $group_data['is_editor'] = 'fault';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 用户身份
|
|
|
|
+ if (count($row_group) == 0 && count($groups) == 0) {
|
|
|
|
+ $group_data['is_author'] = 'fault';
|
|
|
|
+ $group_data['is_review'] = 'fault';
|
|
|
|
+ $group_data['is_editor'] = 'fault';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 修改的角色数组大于0
|
|
|
|
+ if (count($groups) > 0) {
|
|
|
|
+ // 传入角色比原来角色数量多说明增加
|
|
|
|
+ if (count($groups) > count($row_group)) {
|
|
|
|
+ if (count($row_group) > 0) {
|
|
|
|
+ foreach ($groups as $item) {
|
|
|
|
+ // 如果当前角色不在原来角色内容中
|
|
|
|
+ if (!in_array($item, $row_group)) {
|
|
|
|
+ if ($item == 'author') {
|
|
|
|
+ $group_data['is_author'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ if ($item == 'review') {
|
|
|
|
+ $group_data['is_review'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ if ($item == 'editor') {
|
|
|
|
+ $group_data['is_editor'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else { // 如果是空角色时则直接添加
|
|
|
|
+ foreach ($groups as $group) {
|
|
|
|
+ if ($group == 'author') {
|
|
|
|
+ $group_data['is_author'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ if ($group == 'review') {
|
|
|
|
+ $group_data['is_review'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ if ($group == 'editor') {
|
|
|
|
+ $group_data['is_editor'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 如果更改的数量相同则判断是否是增加还是无增加
|
|
|
|
+ if (count($row_group) == count($groups)) {
|
|
|
|
+ foreach ($groups as $item) {
|
|
|
|
+ // 如果当前角色不在原来角色内容中
|
|
|
|
+ if (!in_array($item, $row_group)) {
|
|
|
|
+ if ($item == 'author') {
|
|
|
|
+ $group_data['is_author'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ if ($item == 'review') {
|
|
|
|
+ $group_data['is_review'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ if ($item == 'editor') {
|
|
|
|
+ $group_data['is_editor'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ foreach ($row_group as $item) {
|
|
|
|
+ if (!in_array($item, $groups)) {
|
|
|
|
+ if ($item == 'author') {
|
|
|
|
+ $group_data['is_author'] = 'fault';
|
|
|
|
+ }
|
|
|
|
+ if ($item == 'review') {
|
|
|
|
+ $group_data['is_review'] = 'fault';
|
|
|
|
+ }
|
|
|
|
+ if ($item == 'editor') {
|
|
|
|
+ $group_data['is_editor'] = 'fault';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 不更改用户角色时
|
|
|
|
+ if ($groups === $row_group) {
|
|
|
|
+ foreach ($groups as $group) {
|
|
|
|
+ if ($group == 'author') {
|
|
|
|
+ $group_data['is_author'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ if ($group == 'review') {
|
|
|
|
+ $group_data['is_review'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ if ($group == 'editor') {
|
|
|
|
+ $group_data['is_editor'] = 'correct';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 在原来的基础上减少角色时
|
|
|
|
+ // 传入角色比原来角色数量少说明减少
|
|
|
|
+ if (count($groups) < count($row_group)) {
|
|
|
|
+ foreach ($row_group as $item) {
|
|
|
|
+ if (!in_array($item, $groups)) {
|
|
|
|
+ if ($item == 'author') {
|
|
|
|
+ $group_data['is_author'] = 'fault';
|
|
|
|
+ }
|
|
|
|
+ if ($item == 'review') {
|
|
|
|
+ $group_data['is_review'] = 'fault';
|
|
|
|
+ }
|
|
|
|
+ if ($item == 'editor') {
|
|
|
|
+ $group_data['is_editor'] = 'fault';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 对应的角色信息插入到
|
|
|
|
+ foreach ($group_data as $key => $item) {
|
|
|
|
+ $params[$key] = $item;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $result = $row->allowField(true)->save($params);
|
|
|
|
+ Db::commit();
|
|
|
|
+ } catch (ValidateException|PDOException|Exception $e) {
|
|
|
|
+ Db::rollback();
|
|
|
|
+ $this->error($e->getMessage());
|
|
|
|
+ }
|
|
|
|
+ if (false === $result) {
|
|
|
|
+ $this->error(__('No rows were updated'));
|
|
|
|
+ }
|
|
|
|
+ $this->success();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|