RoleLog.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\admin\model\cms\Channel;
  4. use app\common\controller\Backend;
  5. use app\common\model\UserRoleContent;
  6. use app\common\model\UserRoleLog;
  7. use fast\Tree;
  8. /**
  9. * 用户申请记录管理
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class RoleLog extends Backend
  14. {
  15. /**
  16. * @var \app\common\model\UserRoleLog
  17. */
  18. protected $model = null;
  19. protected $role_list = ['author' => '作者', 'review' => '审稿人', 'chief' => '主编', 'editor' => '编辑'];
  20. protected $adopt_list = ['review' => '审核中', 'fault' => '拒绝', 'correct' => '通过'];
  21. protected $noNeedRight = ['detail', 'is_adopt'];
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = new UserRoleLog();
  26. $this->assignconfig('site_role_list', $this->role_list);
  27. $this->assignconfig('site_adopt_list', $this->adopt_list);
  28. }
  29. /**
  30. * 查看
  31. */
  32. public function index()
  33. {
  34. //设置过滤方法
  35. $this->request->filter(['strip_tags', 'trim']);
  36. if ($this->request->isAjax()) {
  37. //如果发送的来源是Selectpage,则转发到Selectpage
  38. if ($this->request->request('keyField')) {
  39. return $this->selectpage();
  40. }
  41. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  42. $list = $this->model
  43. ->with('user')
  44. ->where($where)
  45. ->order($sort, $order)
  46. ->paginate($limit);
  47. foreach ($list as $k => $v) {
  48. $v->is_adopt_str = $v['is_adopt'];
  49. $v->type_str = $v['type'];
  50. $v->type = $this->role_list[$v['type']];
  51. $v->is_adopt = $this->adopt_list[$v['is_adopt']];
  52. }
  53. $result = array("total" => $list->total(), "rows" => $list->items());
  54. return json($result);
  55. }
  56. return $this->view->fetch();
  57. }
  58. /**
  59. * 用户详情
  60. *
  61. * @param $ids
  62. * @return string
  63. * @throws \think\Exception
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\ModelNotFoundException
  66. * @throws \think\exception\DbException
  67. */
  68. public function detail($user_id = null, $type = null, $ids = null)
  69. {
  70. $user = \app\admin\model\User::where(['id' => $user_id])->find();
  71. if ($user) {
  72. // 如果是审稿或者编辑则走不同页面
  73. if ($type == 'review' || $type == 'chief' || $type == 'editor') {
  74. $user_content = UserRoleContent::where(['log_id' => $ids])->find();
  75. if ($user_content) {
  76. $journal_ids = explode(',', $user_content['journal_ids']);
  77. $channel_name_list = Channel::where(['id' => ['in', $journal_ids]])->column('name');
  78. $user_content['journal_ids'] = $channel_name_list;
  79. $this->view->assign('type', $type);
  80. $this->view->assign('row', $user_content);
  81. }
  82. return $this->view->fetch('user/role_log/user_detail');
  83. }
  84. $this->view->assign('row', $user);
  85. }
  86. return $this->view->fetch();
  87. }
  88. /**
  89. * 用户申请操作
  90. *
  91. * @param $ids
  92. * @param $adopt
  93. * @return void
  94. * @throws \think\db\exception\DataNotFoundException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. * @throws \think\exception\DbException
  97. */
  98. public function is_adopt($ids = null, $adopt = null)
  99. {
  100. $user_log = UserRoleLog::where(['id' => $ids])->find();
  101. if ($user_log) {
  102. $user_log->is_adopt = $adopt;
  103. if ($user_log->save()) {
  104. // 更新用户信息
  105. $user = \app\admin\model\User::where(['id' => $user_log['user_id']])->find();
  106. if ($user) {
  107. if ($user_log->type == 'author') {
  108. $user->is_author = $adopt;
  109. }
  110. if ($user_log->type == 'review') {
  111. $user->is_review = $adopt;
  112. }
  113. if ($user_log->type == 'chief') {
  114. $user->is_chief = $adopt;
  115. if ($adopt == 'correct') {
  116. $user->is_editor = 'fault';
  117. }
  118. }
  119. if ($user_log->type == 'editor') {
  120. $user->is_editor = $adopt;
  121. if ($adopt == 'correct') {
  122. $user->is_chief = 'fault';
  123. }
  124. }
  125. if ($user->save()) {
  126. $this->success();
  127. } else {
  128. $this->error('用户信息保存失败');
  129. }
  130. } else {
  131. $this->error('用户信息不正确');
  132. }
  133. } else {
  134. $this->error('保存失败');
  135. }
  136. } else {
  137. $this->error('未查询到对应信息');
  138. }
  139. }
  140. }