57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
namespace App\Domains\Log\Http\Controllers;
|
|
|
|
use App\Models\Log\Log;
|
|
use App\Core\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Domains\Log\Repositories\LogRepository;
|
|
|
|
class LogController extends Controller
|
|
{
|
|
protected $request;
|
|
protected $logRepository;
|
|
|
|
/**
|
|
* 构造函数,自动注入.
|
|
*/
|
|
public function __construct(Request $request, LogRepository $logRepository)
|
|
{
|
|
$this->request = $request;
|
|
$this->logRepository = $logRepository;
|
|
}
|
|
|
|
/**
|
|
* 列表.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
if ($starttime = $this->request->time('starttime')) {
|
|
$this->logRepository->where('created_at', '>=', $starttime);
|
|
}
|
|
|
|
if ($endtime = $this->request->time('endtime')) {
|
|
$this->logRepository->where('created_at', '<=', $endtime);
|
|
}
|
|
|
|
$limit = $this->request->get('limit', 20);
|
|
|
|
$logs = $this->logRepository->applyConditions()->orderBy('id', 'desc')->paginate($limit);
|
|
|
|
return res($logs, '日志列表', 201);
|
|
}
|
|
|
|
/**
|
|
* 删除.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy()
|
|
{
|
|
$ids = $this->request->ids();
|
|
$this->logRepository->destroy($ids);
|
|
return res(true, '删除成功');
|
|
}
|
|
}
|