RoleLog.php 4.4 KB

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