123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace App\Admin\Controllers\System;
- use App\Http\Controllers\Controller;
- use App\Models\MembersLog;
- use App\Repositories\MemberLogRepository;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Show;
- class UserLogController extends Controller
- {
- use HasResourceActions;
- protected $memberLogRepository;
- public function __construct(
- MemberLogRepository $memberLogRepository
- )
- {
- $this->memberLogRepository=$memberLogRepository;
- }
- /**
- * Index interface.
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content)
- {
- $grid=$this->grid()->render();
- return $content
- ->header('会员操作日志')
- ->description('系统会自动删除一个月前的日志')
- ->body(view('admin.system.userlog.index')->with('grid', $grid));
- }
- /**
- * Show interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function show($id, Content $content)
- {
- return $content
- ->header('操作日志')
- ->description('详情')
- ->body($this->detail($id));
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new MembersLog());
- $grid->disableActions();
- $grid->disableRowSelector();
- $grid->model()
- // ->whereIn('type',[1002,1003,1006,1007,1009,1008,1000,1001])
- ->orderby('created_at','desc');
- $grid->id('ID');
- $grid->log_username('会员名称')->display(function ($username){
- return "<span style='' title='{$username}' class='vtip' >".$username."</span>";
- })->width(200);
- $grid->log_utype('用户类型')->display(function ($log_utype) {
- $html='';
- if ($log_utype==1) {
- $html.='企业';
- }else{
- $html.="个人";
- }
- return $html;
- })->width(200);
- $grid->log_value('描述')->width(600);
- $grid->log_ip('登陆ip')->display(function ($ip) {
- return long2ip($ip);
- });
- $grid->log_source('操作途径');
- $grid->created_at('操作时间');
- $grid->filter(function ($filter) {
- $filter->column(1/2, function ($filter) {
- // 在这里添加字段过滤器
- $filter->like('log_username', '操作用户');
- $filter->equal('log_utype', '用户类型')->select(['1'=>"企业","2"=>"个人"]);
- });
- $filter->column(1/2, function ($filter) {
- // 在这里添加字段过滤器
- $filter->equal('type', '日志类型')->select($this->memberLogRepository->typeArrs());
- $filter->between('created_at', '操作时间')->datetime();
- });
- });
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(MembersLog::findOrFail($id));
- $show->id('ID');
- $show->log_username('操作用户');
- $show->log_value('日志说明');
- $show->log_ip('登陆ip')->as(function ($ip){
- return long2ip($ip);
- });
- $show->log_source('操作途径');
- $show->created_at('操作时间');
- $show->log_address('登陆地址');
- // $typeArrs=$this->memberLogRepository->type_arrs();
- // $show->type("日志类型")->as(function ($type) use ($typeArrs) {
- // return $typeArrs[$type]['type'];
- // });
- $show->log_utype('用户类型')->as(function ($log_utype) {
- $html='';
- if ($log_utype==1) {
- $html.='企业';
- }else{
- $html.="个人";
- }
- return $html;
- })->width(200);
- $show->created_at('创建时间');
- // $show->updated_at('Updated at');
- return $show;
- }
-
- }
|