Adminlog.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * ----------------------------------------------------------------------------
  4. * 行到水穷处,坐看云起时
  5. * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
  6. * ----------------------------------------------------------------------------
  7. * Author: 老成
  8. * email:85556713@qq.com
  9. */
  10. declare(strict_types=1);
  11. namespace app\admin\controller\auth;
  12. use app\common\model\AdminLog as LogModel;
  13. use app\common\model\Admin;
  14. use app\common\controller\Backend;
  15. use think\annotation\route\Group;
  16. use think\annotation\route\Route;
  17. /**
  18. * 管理员日志
  19. */
  20. #[Group("auth/adminlog")]
  21. class Adminlog extends Backend
  22. {
  23. protected $relationField=[];
  24. public function _initialize()
  25. {
  26. parent::_initialize();
  27. $this->model = new LogModel();
  28. }
  29. #[Route('GET,JSON','index')]
  30. public function index()
  31. {
  32. if (false === $this->request->isAjax()) {
  33. return $this->fetch();
  34. }
  35. [$where, $order, $limit, $with] = $this->buildparams();
  36. $list = $this->model
  37. ->where(function ($query){
  38. if(!$this->auth->isSuperAdmin()){
  39. $query->whereIn('admin_id',$this->getChildrenAdminIds());
  40. }
  41. })
  42. ->order($order)
  43. ->paginate($limit);
  44. $result = ['total' => $list->total(), 'rows' => $list->items()];
  45. return json($result);
  46. }
  47. #[Route('POST','del')]
  48. public function del()
  49. {
  50. $adminids=$this->getChildrenAdminIds();
  51. $ids = $this->request->post('ids');
  52. foreach ($ids as $id){
  53. if(!in_array($id,$adminids)){
  54. $this->error(__('没有权限'));
  55. }
  56. }
  57. if ($ids) {
  58. $this->model->whereIn('id', $ids)->delete();
  59. }
  60. $this->success();
  61. }
  62. #[Route('GET','detail')]
  63. public function detail($ids)
  64. {
  65. $row = $this->model->where(['id' => $ids])->find();
  66. $adminids=$this->getChildrenAdminIds();
  67. if(!in_array($row->admin_id,$adminids)){
  68. $this->error(__('没有权限'));
  69. }
  70. $row->content=htmlspecialchars_decode($row->content);
  71. $this->assign("row", $row);
  72. return $this->fetch();
  73. }
  74. private function getChildrenAdminIds()
  75. {
  76. $groupids=$this->auth->getChildrenGroupIds();
  77. $or=[];
  78. foreach ($groupids as $v){
  79. $or[]="FIND_IN_SET({$v},groupids)";
  80. }
  81. $where=implode(' or ',$or);
  82. $adminids=Admin::where($where)->column('id');
  83. return $adminids;
  84. }
  85. }