78 lines
2.0 KiB
PHP
78 lines
2.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace app\common\service;
|
||
|
|
|
||
|
|
use app\common\validate\SysOpLogValidate;
|
||
|
|
use app\common\traits\crud\CrudServiceTrait;
|
||
|
|
use app\common\model\SysOpLog;
|
||
|
|
use support\Request;
|
||
|
|
|
||
|
|
class SysOpLogService
|
||
|
|
{
|
||
|
|
|
||
|
|
use CrudServiceTrait;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 指定当前要操作的模型
|
||
|
|
*/
|
||
|
|
protected string $modelClass = SysOpLog::class;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 验证器
|
||
|
|
*/
|
||
|
|
protected $validator = SysOpLogValidate::class;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 获取验证器
|
||
|
|
*/
|
||
|
|
public function getValidator()
|
||
|
|
{
|
||
|
|
return new $this->validator;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 构建查询条件
|
||
|
|
*/
|
||
|
|
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
||
|
|
{
|
||
|
|
$p = $request->all();
|
||
|
|
|
||
|
|
$config = [];
|
||
|
|
$config['model'] = $this->modelClass;
|
||
|
|
switch ($scene) {
|
||
|
|
case 'index':
|
||
|
|
// ====== ====== 排序 ====== ======
|
||
|
|
$config['order']['id'] = 'desc';
|
||
|
|
|
||
|
|
// ====== ====== 筛选 ====== ======
|
||
|
|
// 状态
|
||
|
|
if (isset($p['user_id']) && $p['user_id']) {
|
||
|
|
$config['where']['user_id'] = $p['user_id'];
|
||
|
|
}
|
||
|
|
// ip
|
||
|
|
if (isset($p['ip']) && $p['ip']) {
|
||
|
|
$config['where']['ip'] = $p['ip'];
|
||
|
|
}
|
||
|
|
// ip
|
||
|
|
if (isset($p['method']) && $p['method']) {
|
||
|
|
$config['where']['method'] = $p['method'];
|
||
|
|
}
|
||
|
|
// 关键字
|
||
|
|
if (isset($p['keyword']) && $p['keyword']) {
|
||
|
|
$k = '%' . $p['keyword'] . '%';
|
||
|
|
foreach (['user_name', 'route'] as $col) {
|
||
|
|
$config['orWhere'][] = [$col, 'like', $k];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//$config['where']['status'] = 1;
|
||
|
|
break;
|
||
|
|
case 'show':
|
||
|
|
$config['where']['id'] = $p['id'];
|
||
|
|
//$config['where']['status'] = 1;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $config;
|
||
|
|
}
|
||
|
|
}
|