123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- namespace app\admin\controller\user;
- use app\common\controller\Backend;
- use app\common\model\UserRoleContent;
- use app\common\model\UserRoleLog;
- use fast\Tree;
- /**
- * 用户申请记录管理
- *
- * @icon fa fa-circle-o
- */
- class RoleLog extends Backend
- {
- /**
- * @var \app\common\model\UserRoleLog
- */
- protected $model = null;
- protected $role_list = ['author' => '作者', 'review' => '审稿人', 'editor' => '编辑'];
- protected $adopt_list = ['review' => '审核中', 'fault' => '拒绝', 'correct' => '通过'];
- protected $noNeedRight = ['detail', 'is_adopt'];
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new UserRoleLog();
- $this->assignconfig('site_role_list', $this->role_list);
- $this->assignconfig('site_adopt_list', $this->adopt_list);
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $list = $this->model
- ->with('user')
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $k => $v) {
- $v->is_adopt_str = $v['is_adopt'];
- $v->type_str = $v['type'];
- $v->type = $this->role_list[$v['type']];
- $v->is_adopt = $this->adopt_list[$v['is_adopt']];
- }
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 用户详情
- *
- * @param $ids
- * @return string
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function detail($user_id = null, $type = null, $ids = null)
- {
- $user = \app\admin\model\User::where(['id' => $user_id])->find();
- if ($user) {
- // 如果是审稿或者编辑则走不同页面
- if ($type == 'review' || $type == 'editor') {
- $user_content = UserRoleContent::where(['log_id' => $ids])->find();
- if ($user_content) {
- $this->view->assign('type', $type);
- $this->view->assign('row', $user_content);
- return $this->view->fetch('user/role_log/user_detail');
- }
- }
- $this->view->assign('row', $user);
- }
- return $this->view->fetch();
- }
- /**
- * 用户申请操作
- *
- * @param $ids
- * @param $adopt
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function is_adopt($ids = null, $adopt = null)
- {
- $user_log = UserRoleLog::where(['id' => $ids])->find();
- if ($user_log) {
- $user_log->is_adopt = $adopt;
- if ($user_log->save()) {
- // 更新用户信息
- $user = \app\admin\model\User::where(['id' => $user_log['user_id']])->find();
- if ($user) {
- if ($user_log->type == 'author') {
- $user->is_author = $adopt;
- }
- if ($user_log->type == 'review') {
- $user->is_review = $adopt;
- }
- if ($user_log->type == 'editor') {
- $user->is_editor = $adopt;
- }
- if ($user->save()) {
- $this->success();
- } else {
- $this->error('用户信息保存失败');
- }
- } else {
- $this->error('用户信息不正确');
- }
- } else {
- $this->error('保存失败');
- }
- } else {
- $this->error('未查询到对应信息');
- }
- }
- }
|