|
@@ -34,10 +34,14 @@ class User extends Backend
|
|
|
$this->model = model('User');
|
|
|
$this->view->assign("typesList", $this->model->getTypesList());
|
|
|
|
|
|
- $journal_list = Channel::where(['chief_id' => 0, 'parent_id' => 1])->column('name', 'id');
|
|
|
+ $journal_list = Channel::where(['parent_id' => 1])->column('name', 'id');
|
|
|
$this->view->assign('journal_list', $journal_list);
|
|
|
|
|
|
+ $review_journal_list = Channel::where(['parent_id' => 1])->column('name', 'id');
|
|
|
+ $this->view->assign('review_journal_list', $review_journal_list);
|
|
|
+
|
|
|
$group_list = ['author' => __('Author'), 'review' => __('Review'), 'chief' => __('chief'), 'editor' => __('editor')];
|
|
|
+ $this->assignconfig('site_group_list', $group_list);
|
|
|
$this->view->assign('group_list', $group_list);
|
|
|
}
|
|
|
|
|
@@ -55,24 +59,58 @@ class User extends Backend
|
|
|
}
|
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
|
|
|
- $type = $this->request->param('type');
|
|
|
+ $filter = $this->request->get("filter", '');
|
|
|
+ $filter = (array)json_decode($filter, true);
|
|
|
+ $filter = $filter ? $filter : [];
|
|
|
$new_where = [];
|
|
|
- if ($type == 'author') {
|
|
|
- $new_where['is_author'] = 'correct';
|
|
|
+ if (array_key_exists('type', $filter)) {
|
|
|
+ if ($filter['type'] == 'author') {
|
|
|
+ $new_where['is_author'] = 'correct';
|
|
|
+ }
|
|
|
+ if ($filter['type'] == 'review') {
|
|
|
+ $new_where['is_review'] = 'correct';
|
|
|
+ }
|
|
|
+ if ($filter['type'] == 'chief') {
|
|
|
+ $new_where['is_chief'] = 'correct';
|
|
|
+ }
|
|
|
+ if ($filter['type'] == 'editor') {
|
|
|
+ $new_where['is_editor'] = 'correct';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (array_key_exists('workplace', $filter)) {
|
|
|
+ $new_where['workplace'] = ['like', '%'. $filter['workplace'] .'%'];
|
|
|
+ }
|
|
|
+ if (array_key_exists('job_type', $filter)) {
|
|
|
+ $new_where['job_type'] = ['like', '%'. $filter['job_type'] .'%'];
|
|
|
}
|
|
|
- if ($type == 'review') {
|
|
|
- $new_where['is_review'] = 'correct';
|
|
|
+ if (array_key_exists('title', $filter)) {
|
|
|
+ $new_where['title'] = ['like', '%'. $filter['title'] .'%'];
|
|
|
}
|
|
|
- if ($type == 'chief') {
|
|
|
- $new_where['is_chief'] = 'correct';
|
|
|
+ if (array_key_exists('first_name', $filter)) {
|
|
|
+ $new_where['first_name'] = ['like', '%'. $filter['first_name'] .'%'];
|
|
|
}
|
|
|
- if ($type == 'editor') {
|
|
|
- $new_where['is_editor'] = 'correct';
|
|
|
+ if (array_key_exists('middle_name', $filter)) {
|
|
|
+ $new_where['middle_name'] = ['like', '%'. $filter['middle_name'] .'%'];
|
|
|
+ }
|
|
|
+ if (array_key_exists('last_name', $filter)) {
|
|
|
+ $new_where['last_name'] = ['like', '%'. $filter['last_name'] .'%'];
|
|
|
+ }
|
|
|
+ if (array_key_exists('facebook', $filter)) {
|
|
|
+ $new_where['facebook'] = ['like', '%'. $filter['facebook'] .'%'];
|
|
|
+ }
|
|
|
+ if (array_key_exists('twitter', $filter)) {
|
|
|
+ $new_where['twitter'] = ['like', '%'. $filter['twitter'] .'%'];
|
|
|
+ }
|
|
|
+ if (array_key_exists('email', $filter)) {
|
|
|
+ $new_where['email'] = ['like', '%'. $filter['email'] .'%'];
|
|
|
+ }
|
|
|
+ if (array_key_exists('status', $filter)) {
|
|
|
+ $new_where['user.status'] = $filter['status'];
|
|
|
}
|
|
|
|
|
|
$list = $this->model
|
|
|
->with('group')
|
|
|
- ->where($where)
|
|
|
+// ->where($where)
|
|
|
->where($new_where)
|
|
|
->order($sort, $order)
|
|
|
->paginate($limit);
|
|
@@ -122,8 +160,20 @@ class User extends Backend
|
|
|
$this->token();
|
|
|
}
|
|
|
$row = $this->model->get($ids);
|
|
|
- $channel = Channel::where(['chief_id' => $row->id])->find();
|
|
|
- $row->journal = $channel->id ?? 0;
|
|
|
+ $row->review_journal = 0;
|
|
|
+ $row->journal = 0;
|
|
|
+ $user_review_role_content = UserRoleContent::where(['user_id' => $row->id, 'type' => 'review'])->find();
|
|
|
+ $user_editor_role_content = UserRoleContent::where(['user_id' => $row->id, 'type' => 'editor'])->find();
|
|
|
+ $user_chief_role_content = UserRoleContent::where(['user_id' => $row->id, 'type' => 'chief'])->find();
|
|
|
+ if ($user_review_role_content) {
|
|
|
+ $row->review_journal = $user_review_role_content['journal_ids'];
|
|
|
+ }
|
|
|
+ if ($user_editor_role_content) {
|
|
|
+ $row->journal = $user_editor_role_content['journal_ids'];
|
|
|
+ }
|
|
|
+ if ($user_chief_role_content) {
|
|
|
+ $row->journal = $user_chief_role_content['journal_ids'];
|
|
|
+ }
|
|
|
$this->modelValidate = true;
|
|
|
if (!$row) {
|
|
|
$this->error(__('No Results were found'));
|
|
@@ -160,227 +210,71 @@ class User extends Backend
|
|
|
$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';
|
|
|
- }
|
|
|
- if ($row['is_chief'] == 'correct') {
|
|
|
- $row_group[] = 'chief';
|
|
|
- }
|
|
|
-
|
|
|
- // 用户选中的角色
|
|
|
- $groups = $params['group'];
|
|
|
- if ($groups[0] == '') {
|
|
|
- unset($groups[0]);
|
|
|
+ if (in_array('chief', $params['group'])) {
|
|
|
+ if (in_array('editor', $params['group'])) {
|
|
|
+ $this->error(__('Editors and chief editors can only have one'));
|
|
|
+ }
|
|
|
+ if (empty($params['journal'])) {
|
|
|
+ $this->error(__('Please select a journal'));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // 原来角色有多个
|
|
|
- if (count($row_group) > 0) {
|
|
|
- // 新修改的身份全部取消
|
|
|
- if (count($groups) == 0) {
|
|
|
- $group_data['is_author'] = 'fault';
|
|
|
- $group_data['is_review'] = 'fault';
|
|
|
- $group_data['is_editor'] = 'fault';
|
|
|
- $group_data['is_chief'] = 'fault';
|
|
|
+ if ($row['is_chief'] == 'correct' && !in_array('chief', $params['group'])) {
|
|
|
+ $params['is_chief'] = 'fault';
|
|
|
+ // 如果去掉主编角色则需要把对应的期刊主编数据移除
|
|
|
+ $channels = Channel::where(['chief_id' => $row->id])->select();
|
|
|
+ foreach ($channels as $channel) {
|
|
|
+ $channel->chief_id = 0;
|
|
|
+ $channel->save();
|
|
|
}
|
|
|
+ $this->syncDelUserRole($row->id, 'chief');
|
|
|
}
|
|
|
|
|
|
- // 用户身份
|
|
|
- if (count($row_group) == 0 && count($groups) == 0) {
|
|
|
- $group_data['is_author'] = 'fault';
|
|
|
- $group_data['is_review'] = 'fault';
|
|
|
- $group_data['is_editor'] = 'fault';
|
|
|
- $group_data['is_chief'] = 'fault';
|
|
|
+ if ($row['is_author'] == 'correct' && !in_array('author', $params['group'])) {
|
|
|
+ $params['is_author'] = 'fault';
|
|
|
+ $this->syncDelUserRole($row->id, 'author');
|
|
|
}
|
|
|
-
|
|
|
- // 修改的角色数组大于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';
|
|
|
- }
|
|
|
- if ($item == 'chief') {
|
|
|
- $group_data['is_chief'] = '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 ($group == 'chief') {
|
|
|
- $group_data['is_chief'] = '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';
|
|
|
- }
|
|
|
- if ($item == 'chief') {
|
|
|
- $group_data['is_chief'] = '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 ($item == 'chief') {
|
|
|
- $group_data['is_chief'] = '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 ($group == 'chief') {
|
|
|
- $group_data['is_chief'] = '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';
|
|
|
- }
|
|
|
- if ($item == 'chief') {
|
|
|
- $group_data['is_chief'] = 'fault';
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if ($row['is_review'] == 'correct' && !in_array('review', $params['group'])) {
|
|
|
+ $params['is_review'] = 'fault';
|
|
|
+ $this->syncDelUserRole($row->id, 'review');
|
|
|
+ }
|
|
|
+ if ($row['is_editor'] == 'correct' && !in_array('editor', $params['group'])) {
|
|
|
+ $params['is_editor'] = 'fault';
|
|
|
+ $this->syncDelUserRole($row->id, 'editor');
|
|
|
}
|
|
|
|
|
|
// 对应的角色信息插入到
|
|
|
- foreach ($group_data as $key => $item) {
|
|
|
- $params[$key] = $item;
|
|
|
- if ($key == 'is_author') {
|
|
|
- $type = 'author';
|
|
|
- }
|
|
|
- if ($key == 'is_review') {
|
|
|
- $type = 'review';
|
|
|
- }
|
|
|
- // 如果是新增编辑角色则需要判断是否拥有主编,如拥有主编则需要去除掉
|
|
|
- if ($key == 'is_editor') {
|
|
|
- $type = 'editor';
|
|
|
- if ($row->is_chief == 'correct') {
|
|
|
- $params['is_chief'] = 'fault';
|
|
|
- }
|
|
|
+ foreach ($params['group'] as $value) {
|
|
|
+ if ($value == 'author') {
|
|
|
+ $params['is_author'] = 'correct';
|
|
|
+ $this->syncUserRole($row->id, 'author', 'correct');
|
|
|
}
|
|
|
- // 如果是新增主编角色则需要判断是否拥有编辑,如拥有编辑则需要去除掉
|
|
|
- if ($key == 'is_chief') {
|
|
|
- $type = 'chief';
|
|
|
- if ($row->is_editor == 'correct') {
|
|
|
- $params['is_editor'] = 'fault';
|
|
|
- }
|
|
|
-
|
|
|
- // 判断如果选择了主编则需要填写期刊
|
|
|
- if (empty($params['journal'])) {
|
|
|
+ if ($value == 'review') {
|
|
|
+ $params['is_review'] = 'correct';
|
|
|
+ if (!$params['review_journal']) {
|
|
|
$this->error(__('Please select a journal'));
|
|
|
}
|
|
|
+ $this->syncUserRole($row->id, 'review', 'correct', $params['review_journal']);
|
|
|
+ }
|
|
|
+ if ($value == 'chief') {
|
|
|
+ $params['is_chief'] = 'correct';
|
|
|
+ $params['is_editor'] = 'fault';
|
|
|
|
|
|
// 对应期刊绑定主编
|
|
|
$channel = Channel::get($params['journal']);
|
|
|
+ if ($channel->chief_id > 0) {
|
|
|
+ if ($channel->chief_id != $row->id) {
|
|
|
+ $this->error(__('There is already an editor in chief under this journal'));
|
|
|
+ }
|
|
|
+ }
|
|
|
$channel->chief_id = $row->id;
|
|
|
$channel->save();
|
|
|
+ $this->syncUserRole($row->id, 'chief', 'correct', $params['journal']);
|
|
|
}
|
|
|
-
|
|
|
- // 增加user_role_content数据
|
|
|
- if ($item == 'correct') {
|
|
|
- // 如果是增加角色则需要添加user_role_log 和 user_role_content
|
|
|
- $user_role_log_model = new UserRoleLog();
|
|
|
- $user_role_log_model->user_id = $row->id;
|
|
|
- $user_role_log_model->type = $type;
|
|
|
- $user_role_log_model->is_adopt = $item;
|
|
|
- if ($user_role_log_model->save()) {
|
|
|
- $user_role_model = new UserRoleContent();
|
|
|
- $user_role_model->user_id = $row->id;
|
|
|
- $user_role_model->log_id = $user_role_log_model->id;
|
|
|
- $user_role_model->type = $type;
|
|
|
- $user_role_model->affiliation = $row->affiliation;
|
|
|
- $user_role_model->save();
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 如果是删减角色则需要删除user_role_log 和 user_role_content
|
|
|
- $user_role_log_model = UserRoleLog::where(['user_id' => $row->id, 'type' => $type])->select();
|
|
|
- if (count($user_role_log_model) > 0) {
|
|
|
- foreach ($user_role_log_model as $user_log) {
|
|
|
- $user_role_model = UserRoleContent::where(['user_id' => $row->id, 'type' => $type, 'log_id' => $user_log->id])->select();
|
|
|
- $user_log->delete();
|
|
|
- if (count($user_role_model) > 0) {
|
|
|
- foreach ($user_role_model as $user_role) {
|
|
|
- $user_role->delete();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if ($value == 'editor') {
|
|
|
+ $params['is_editor'] = 'correct';
|
|
|
+ $params['is_chief'] = 'fault';
|
|
|
+ $this->syncUserRole($row->id, 'editor', 'correct', $params['journal']);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -443,4 +337,83 @@ class User extends Backend
|
|
|
}
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步删除用户角色数据
|
|
|
+ *
|
|
|
+ * @param $user_id
|
|
|
+ * @param $type
|
|
|
+ * @return true
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function syncDelUserRole($user_id, $type)
|
|
|
+ {
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $user_role_log_model = UserRoleLog::where(['user_id' => $user_id, 'type' => $type])->select();
|
|
|
+ if (count($user_role_log_model) > 0) {
|
|
|
+ foreach ($user_role_log_model as $user_log) {
|
|
|
+ $user_role_model = UserRoleContent::where(['user_id' => $user_id, 'type' => $type, 'log_id' => $user_log->id])->select();
|
|
|
+ $user_log->delete();
|
|
|
+ if (count($user_role_model) > 0) {
|
|
|
+ foreach ($user_role_model as $user_role) {
|
|
|
+ $user_role->delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ } catch (ValidateException|PDOException|Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步用户角色数据
|
|
|
+ *
|
|
|
+ * @param $user_id
|
|
|
+ * @param $type
|
|
|
+ * @param $adopt
|
|
|
+ * @param $journal_id
|
|
|
+ * @return true
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
+ */
|
|
|
+ public function syncUserRole($user_id, $type, $adopt, $journal_id = 0)
|
|
|
+ {
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ // 如果是增加角色则需要添加user_role_log 和 user_role_content
|
|
|
+ $user_role_log_model = UserRoleLog::where(['user_id' => $user_id, 'type' => $type, 'is_adopt' => $adopt])->find();
|
|
|
+ if (empty($user_role_log_model)) {
|
|
|
+ $user_role_log_model = new UserRoleLog();
|
|
|
+ $user_role_log_model->user_id = $user_id;
|
|
|
+ $user_role_log_model->type = $type;
|
|
|
+ $user_role_log_model->is_adopt = $adopt;
|
|
|
+ $user_role_log_model->save();
|
|
|
+ }
|
|
|
+ $user_role_model = UserRoleContent::where(['user_id' => $user_id, 'type' => $type, 'log_id' => $user_role_log_model->id])->find();
|
|
|
+ if (empty($user_role_model)) {
|
|
|
+ $user_role_model = new UserRoleContent();
|
|
|
+ $user_role_model->user_id = $user_id;
|
|
|
+ $user_role_model->log_id = $user_role_log_model->id;
|
|
|
+ $user_role_model->type = $type;
|
|
|
+ $user_role_model->journal_ids = $journal_id ?? 0;
|
|
|
+ $user_role_model->save();
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ } catch (ValidateException|PDOException|Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|