mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-22 19:44:02 +08:00
* 更新版本号 * 完善后台今日统计,增加权限白名单,增加后台首页菜单,调整后台登录页样式 * Merge branch 'koogua/I1XFCF' of https://gitee.com/koogua/course-tencen… * 前台学习资料部分完成 * !2 后台运营统计合并 * 后台学习资料部分完成 * Merge branch 'master' into develop * Merge branch 'master' of https://github.com/xiaochong0302/course-tencent-cloud * 1.增加changelog.md * 1.简化部分路由地址 * Merge pull request #2 from xiaochong0302/dependabot/composer/symfony/h… * Bump symfony/http-foundation from 4.3.4 to 5.1.6
88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Repos;
|
|
|
|
use App\Library\Paginator\Adapter\QueryBuilder as PagerQueryBuilder;
|
|
use App\Models\Audit as AuditModel;
|
|
use Phalcon\Mvc\Model;
|
|
use Phalcon\Mvc\Model\Resultset;
|
|
use Phalcon\Mvc\Model\ResultsetInterface;
|
|
|
|
class Audit extends Repository
|
|
{
|
|
|
|
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
|
|
{
|
|
$builder = $this->modelsManager->createBuilder();
|
|
|
|
$builder->from(AuditModel::class);
|
|
|
|
$builder->where('1 = 1');
|
|
|
|
if (!empty($where['user_id'])) {
|
|
$builder->andWhere('user_id = :user_id:', ['user_id' => $where['user_id']]);
|
|
}
|
|
|
|
if (!empty($where['user_ip'])) {
|
|
$builder->andWhere('user_ip = :user_ip:', ['user_ip' => $where['user_ip']]);
|
|
}
|
|
|
|
if (!empty($where['user_name'])) {
|
|
$builder->andWhere('user_name = :user_name:', ['user_name' => $where['user_name']]);
|
|
}
|
|
|
|
if (!empty($where['req_route'])) {
|
|
$builder->andWhere('req_route = :req_route:', ['req_route' => $where['req_route']]);
|
|
}
|
|
|
|
if (!empty($where['req_path'])) {
|
|
$builder->andWhere('req_path = :req_path:', ['req_path' => $where['req_path']]);
|
|
}
|
|
|
|
if (!empty($where['start_time']) && !empty($where['end_time'])) {
|
|
$startTime = strtotime($where['start_time']);
|
|
$endTime = strtotime($where['end_time']);
|
|
$builder->betweenWhere('create_time', $startTime, $endTime);
|
|
}
|
|
|
|
switch ($sort) {
|
|
default:
|
|
$orderBy = 'id DESC';
|
|
break;
|
|
}
|
|
|
|
$builder->orderBy($orderBy);
|
|
|
|
$pager = new PagerQueryBuilder([
|
|
'builder' => $builder,
|
|
'page' => $page,
|
|
'limit' => $limit,
|
|
]);
|
|
|
|
return $pager->paginate();
|
|
}
|
|
|
|
/**
|
|
* @param int $id
|
|
* @return AuditModel|Model|bool
|
|
*/
|
|
public function findById($id)
|
|
{
|
|
return AuditModel::findFirst($id);
|
|
}
|
|
|
|
/**
|
|
* @param array $ids
|
|
* @param array|string $columns
|
|
* @return ResultsetInterface|Resultset|AuditModel[]
|
|
*/
|
|
public function findByIds($ids, $columns = '*')
|
|
{
|
|
return AuditModel::query()
|
|
->columns($columns)
|
|
->inWhere('id', $ids)
|
|
->execute();
|
|
}
|
|
|
|
}
|