feat(phase-2): add trend chart analysis - grid view of number history

This commit is contained in:
2026-04-21 23:33:39 +08:00
parent f2b432a9f4
commit 616239392a
5 changed files with 203 additions and 1 deletions
+21 -1
View File
@@ -22,7 +22,7 @@ class History extends Backend
* 无需额外权限检查的方法(但仍在 admin 模块内,需要 admin 登录)
* @var array
*/
protected $noNeedRight = ['missingNum'];
protected $noNeedRight = ['missingNum', 'trendData'];
public function _initialize()
{
@@ -52,5 +52,25 @@ class History extends Backend
}
}
/**
* 获取走势图数据
* @return void
*/
public function trendData()
{
if ($this->request->isAjax()) {
$periods = $this->request->get('periods', 30, 'intval');
if ($periods < 10 || $periods > 100) {
$this->error('期数范围必须在 10-100 之间');
}
$type = $this->request->get('type', 'all');
if (!in_array($type, ['all', 'special'])) {
$this->error('查询类型不正确');
}
$result = $this->model->getTrendData($periods, $type);
$this->success('查询成功', null, $result);
}
}
}
+2
View File
@@ -15,4 +15,6 @@ return [
'Query Type' => '查询类型',
'All Numbers' => '全部号码',
'Special Only' => '仅特码',
'Trend Chart' => '走势图',
'No data available' => '暂无数据',
];
+50
View File
@@ -30,6 +30,56 @@ class History extends Model
];
/**
* 获取走势图数据
* @param int $periods 查询最近多少期
* @param string $type 查询类型 all=全部号码 special=仅特码
* @return array {expects: [], data: [[num1,...], ...], colorMap: []}
*/
public function getTrendData($periods = 30, $type = 'all')
{
// 查询波色映射
$num_model = new Num();
$colorMap = $num_model->column('color', 'num');
$history = $this
->field('expect,num1,num2,num3,num4,num5,num6,num7,openTime')
->order('openTime', 'asc')
->limit($periods)
->select();
if (empty($history)) {
return ['expects' => [], 'data' => [], 'colorMap' => []];
}
$expects = [];
$data = [];
foreach ($history as $row) {
$expects[] = (string)$row['expect'];
if ($type === 'special') {
$num = (int)$row['num7'];
$data[] = [
'num7' => $num,
'num7_color' => isset($colorMap[$num]) ? $colorMap[$num] : '—'
];
} else {
$row_data = [];
for ($i = 1; $i <= 7; $i++) {
$num = (int)$row['num' . $i];
$row_data['num' . $i] = $num;
$row_data['num' . $i . '_color'] = isset($colorMap[$num]) ? $colorMap[$num] : '—';
}
$data[] = $row_data;
}
}
return [
'expects' => $expects,
'data' => $data,
'colorMap' => $colorMap
];
}
/**
* 计算遗漏号码
* @param int $periods 查询最近多少期
@@ -8,6 +8,7 @@
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-warning btn-missingnum" title="{:__('Missing Number Analysis')}"><i class="fa fa-search"></i> {:__('Missing Number Analysis')}</a>
<a href="javascript:;" class="btn btn-info btn-trend" title="{:__('Trend Chart')}"><i class="fa fa-area-chart"></i> {:__('Trend Chart')}</a>
<!-- <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('history/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>-->
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"