吴昊天 f9ba517389 fix(通知日志): 修复统计恒为 0、状态筛选丢失并补全列表分页
后端
- NoticeLogDao::getStatistics() 原实现复用同一个查询构造器,where 条件累积,
  导致 failed 恒为 0、success 含全部状态;改为每次基于独立条件 count。
- 抽出 buildWhere() 统一组装条件,列表与统计共用;统计不叠加状态条件。
- status=0(待发送)是合法筛选值,原 empty() 判断会丢弃,改为 isset + 非空串判断。
- page/limit 做整数与上限(100)校验,避免非法分页参数。
- 列表接口返回 { list, count },供前端分页使用。

前端
- 补充分页组件,搜索/重置/清理后回到第一页并同时刷新列表与统计。
- 兼容列表接口旧格式(数组)与新格式({ list, count })。
2026-10-23 14:17:15 +08:00

92 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\adminapi\controller\setting\notification;
use app\adminapi\controller\AuthController;
use app\services\message\admin\NoticeLogServices;
use think\facade\App;
class NoticeLogController extends AuthController
{
protected $services;
public function __construct(App $app, NoticeLogServices $services)
{
parent::__construct($app);
$this->services = $services;
}
public function index()
{
$filter = $this->request->getMore([
['mark', ''],
['uid', ''],
['channel_key', ''],
['status', ''],
['start_time', ''],
['end_time', ''],
]);
$page = max(1, (int)$this->request->get('page', 1));
$limit = (int)$this->request->get('limit', 20);
$limit = $limit > 0 && $limit <= 100 ? $limit : 20;
return app('json')->success($this->services->getList($filter, $page, $limit));
}
public function detail(int $id)
{
if (!$id) {
return app('json')->fail('参数错误');
}
$info = $this->services->getDetail($id);
if (empty($info)) {
return app('json')->fail('记录不存在');
}
return app('json')->success($info);
}
public function statistics()
{
// 与列表保持同一套筛选条件(状态筛选不参与统计)
$filter = $this->request->getMore([
['mark', ''],
['uid', ''],
['channel_key', ''],
['start_time', ''],
['end_time', ''],
]);
return app('json')->success($this->services->getStatistics($filter));
}
public function retry(int $id)
{
if (!$id) {
return app('json')->fail('参数错误');
}
$info = $this->services->getDetail($id);
if (empty($info)) {
return app('json')->fail('记录不存在');
}
// 日志只有渲染后的内容,没有原始变量;重新执行会发送残缺信息。
return app('json')->fail('该日志未保存原始变量,无法安全重试');
}
public function clean()
{
$days = $this->request->post('days', 30);
$count = $this->services->cleanLogs((int)$days);
return app('json')->success('清理成功,共删除 ' . $count . ' 条记录');
}
}