<?php

namespace App\Http\Controllers\Admin;


use App\Http\Response\ResponseJson;
use App\Models\OperationLog;
use Illuminate\Http\Request;

class LogController
{
   use ResponseJson;
   
   public function index(Request $request)
   {
        $keyword = $request->get('keyword');
        $page_size = $request->get('page_size',15);
        $list = OperationLog::when($keyword,function ($query) use ($keyword){
                $query->where('admin_name','like',"%$keyword%")
                    ->orWhere('admin_mobile', 'like', '%'.$keyword.'%');
            })
            ->orderByDesc('id')
            ->select()
            ->paginate($page_size);

        foreach ($list as $item){
//            $item->details = json_decode($item->details,true);
            //加这些只是为了兼容他之前的数据。。。
            if(!is_array($item->input) && json_decode($item->input) !== null && json_last_error() === JSON_ERROR_NONE){
                $item->input = json_decode($item->input,true);
            }
            $item->response = json_decode($item->response,true);
        }
        return $this->success('ok',$list);
   }
   
}
