UserLogController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace App\Admin\Controllers\System;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\MembersLog;
  5. use App\Repositories\MemberLogRepository;
  6. use Encore\Admin\Controllers\HasResourceActions;
  7. use Encore\Admin\Grid;
  8. use Encore\Admin\Layout\Content;
  9. use Encore\Admin\Show;
  10. class UserLogController extends Controller
  11. {
  12. use HasResourceActions;
  13. protected $memberLogRepository;
  14. public function __construct(
  15. MemberLogRepository $memberLogRepository
  16. )
  17. {
  18. $this->memberLogRepository=$memberLogRepository;
  19. }
  20. /**
  21. * Index interface.
  22. *
  23. * @param Content $content
  24. * @return Content
  25. */
  26. public function index(Content $content)
  27. {
  28. $grid=$this->grid()->render();
  29. return $content
  30. ->header('会员操作日志')
  31. ->description('系统会自动删除一个月前的日志')
  32. ->body(view('admin.system.userlog.index')->with('grid', $grid));
  33. }
  34. /**
  35. * Show interface.
  36. *
  37. * @param mixed $id
  38. * @param Content $content
  39. * @return Content
  40. */
  41. public function show($id, Content $content)
  42. {
  43. return $content
  44. ->header('操作日志')
  45. ->description('详情')
  46. ->body($this->detail($id));
  47. }
  48. /**
  49. * Make a grid builder.
  50. *
  51. * @return Grid
  52. */
  53. protected function grid()
  54. {
  55. $grid = new Grid(new MembersLog());
  56. $grid->disableActions();
  57. $grid->disableRowSelector();
  58. $grid->model()
  59. // ->whereIn('type',[1002,1003,1006,1007,1009,1008,1000,1001])
  60. ->orderby('created_at','desc');
  61. $grid->id('ID');
  62. $grid->log_username('会员名称')->display(function ($username){
  63. return "<span style='' title='{$username}' class='vtip' >".$username."</span>";
  64. })->width(200);
  65. $grid->log_utype('用户类型')->display(function ($log_utype) {
  66. $html='';
  67. if ($log_utype==1) {
  68. $html.='企业';
  69. }else{
  70. $html.="个人";
  71. }
  72. return $html;
  73. })->width(200);
  74. $grid->log_value('描述')->width(600);
  75. $grid->log_ip('登陆ip')->display(function ($ip) {
  76. return long2ip($ip);
  77. });
  78. $grid->log_source('操作途径');
  79. $grid->created_at('操作时间');
  80. $grid->filter(function ($filter) {
  81. $filter->column(1/2, function ($filter) {
  82. // 在这里添加字段过滤器
  83. $filter->like('log_username', '操作用户');
  84. $filter->equal('log_utype', '用户类型')->select(['1'=>"企业","2"=>"个人"]);
  85. });
  86. $filter->column(1/2, function ($filter) {
  87. // 在这里添加字段过滤器
  88. $filter->equal('type', '日志类型')->select($this->memberLogRepository->typeArrs());
  89. $filter->between('created_at', '操作时间')->datetime();
  90. });
  91. });
  92. return $grid;
  93. }
  94. /**
  95. * Make a show builder.
  96. *
  97. * @param mixed $id
  98. * @return Show
  99. */
  100. protected function detail($id)
  101. {
  102. $show = new Show(MembersLog::findOrFail($id));
  103. $show->id('ID');
  104. $show->log_username('操作用户');
  105. $show->log_value('日志说明');
  106. $show->log_ip('登陆ip')->as(function ($ip){
  107. return long2ip($ip);
  108. });
  109. $show->log_source('操作途径');
  110. $show->created_at('操作时间');
  111. $show->log_address('登陆地址');
  112. // $typeArrs=$this->memberLogRepository->type_arrs();
  113. // $show->type("日志类型")->as(function ($type) use ($typeArrs) {
  114. // return $typeArrs[$type]['type'];
  115. // });
  116. $show->log_utype('用户类型')->as(function ($log_utype) {
  117. $html='';
  118. if ($log_utype==1) {
  119. $html.='企业';
  120. }else{
  121. $html.="个人";
  122. }
  123. return $html;
  124. })->width(200);
  125. $show->created_at('创建时间');
  126. // $show->updated_at('Updated at');
  127. return $show;
  128. }
  129. }