feat(history): 新增历史开奖数据分析功能

- 添加History控制器和模型实现开奖数据统计分析
- 实现遗漏号码、走势图、冷热号码等基础分析功能
- 添加波色分析、生肖分析、奇偶分析等专项统计
- 集成尾号转移矩阵和首号转移矩阵概率分析
- 在后台仪表板展示综合统计数据表格
This commit is contained in:
2026-04-30 22:45:03 +08:00
parent d18c23cd57
commit 6a782c2d65
4 changed files with 212 additions and 5 deletions
+31 -1
View File
@@ -22,7 +22,7 @@ class History extends Backend
* 无需额外权限检查的方法(但仍在 admin 模块内,需要 admin 登录)
* @var array
*/
protected $noNeedRight = ['missingNum', 'trendData', 'hotColdNumbers', 'colorWaveAnalysis', 'zodiacAnalysis', 'oddEvenAnalysis', 'bigSmallAnalysis', 'specialTrend', 'consecutiveNumbers', 'tailNumbers', 'dashboard', 'specialHeatmap', 'specialHotColdAction', 'zoneTransition', 'colorWaveTransition', 'zoneToColorTransition', 'zodiacTransition'];
protected $noNeedRight = ['missingNum', 'trendData', 'hotColdNumbers', 'colorWaveAnalysis', 'zodiacAnalysis', 'oddEvenAnalysis', 'bigSmallAnalysis', 'specialTrend', 'consecutiveNumbers', 'tailNumbers', 'dashboard', 'specialHeatmap', 'specialHotColdAction', 'zoneTransition', 'colorWaveTransition', 'zoneToColorTransition', 'zodiacTransition', 'tailNumberTransition', 'headNumberTransition'];
public function _initialize()
{
@@ -358,5 +358,35 @@ class History extends Backend
}
}
/**
* 尾号转移概率统计
*/
public function tailNumberTransition()
{
if ($this->request->isAjax()) {
$periods = $this->request->get('periods', 100, 'intval');
if ($periods < 10 || $periods > 500) {
$this->error('期数范围必须在 10-500 之间');
}
$result = $this->model->getTailNumberTransition($periods);
$this->success('查询成功', null, $result);
}
}
/**
* 首号转移概率统计
*/
public function headNumberTransition()
{
if ($this->request->isAjax()) {
$periods = $this->request->get('periods', 100, 'intval');
if ($periods < 10 || $periods > 500) {
$this->error('期数范围必须在 10-500 之间');
}
$result = $this->model->getHeadNumberTransition($periods);
$this->success('查询成功', null, $result);
}
}
}
+124 -1
View File
@@ -468,7 +468,9 @@ class History extends Model
'zonetransition' => $this->getZoneTransition($periods),
'colorwavetransition' => $this->getColorWaveTransition($periods),
'zonetocolortransition' => $this->getZoneToZoneColor($periods),
'zodiactransition' => $this->getZodiacTransition($periods)
'zodiactransition' => $this->getZodiacTransition($periods),
'tailnumbertransition' => $this->getTailNumberTransition($periods),
'headnumbertransition' => $this->getHeadNumberTransition($periods)
];
}
@@ -861,6 +863,127 @@ class History extends Model
];
}
/**
* 尾号转移概率统计
* 统计特码从一个尾号转移到另一个尾号的概率(尾号0-9)
* @param int $periods 查询最近多少期
* @return array {tails: [], matrix: [], probabilities: [], row_totals: [], total_transitions: int}
*/
public function getTailNumberTransition($periods = 100)
{
$history = $this
->field('expect,num7,openTime')
->order('openTime', 'desc')
->limit($periods)
->select();
if (empty($history) || count($history) < 2) {
return ['tails' => ['尾0','尾1','尾2','尾3','尾4','尾5','尾6','尾7','尾8','尾9'], 'matrix' => [], 'probabilities' => [], 'row_totals' => [], 'total_transitions' => 0];
}
$history = array_reverse($history);
$tailLabels = ['尾0', '尾1', '尾2', '尾3', '尾4', '尾5', '尾6', '尾7', '尾8', '尾9'];
$numTails = 10;
$matrix = array_fill(0, $numTails, array_fill(0, $numTails, 0));
$rowTotals = array_fill(0, $numTails, 0);
$getTail = function ($num) {
return $num % 10;
};
$totalTransitions = 0;
for ($i = 0; $i < count($history) - 1; $i++) {
$currentNum = (int)$history[$i]['num7'];
$nextNum = (int)$history[$i + 1]['num7'];
if ($currentNum < 1 || $currentNum > 49 || $nextNum < 1 || $nextNum > 49) continue;
$from = $getTail($currentNum);
$to = $getTail($nextNum);
$matrix[$from][$to]++;
$rowTotals[$from]++;
$totalTransitions++;
}
$probabilities = array_fill(0, $numTails, array_fill(0, $numTails, 0));
for ($i = 0; $i < $numTails; $i++) {
if ($rowTotals[$i] > 0) {
for ($j = 0; $j < $numTails; $j++) {
$probabilities[$i][$j] = round($matrix[$i][$j] / $rowTotals[$i] * 100, 1);
}
}
}
return [
'tails' => $tailLabels,
'matrix' => $matrix,
'probabilities' => $probabilities,
'row_totals' => $rowTotals,
'total_transitions' => $totalTransitions
];
}
/**
* 首号转移概率统计
* 统计特码从一个首号转移到另一个首号的概率(首号0-4)
* 首号定义:1-9首号=010-19首号=120-29首号=230-39首号=340-49首号=4
* @param int $periods 查询最近多少期
* @return array {heads: [], matrix: [], probabilities: [], row_totals: [], total_transitions: int}
*/
public function getHeadNumberTransition($periods = 100)
{
$history = $this
->field('expect,num7,openTime')
->order('openTime', 'desc')
->limit($periods)
->select();
if (empty($history) || count($history) < 2) {
return ['heads' => ['首号0','首号1','首号2','首号3','首号4'], 'matrix' => [], 'probabilities' => [], 'row_totals' => [], 'total_transitions' => 0];
}
$history = array_reverse($history);
$headLabels = ['首号0', '首号1', '首号2', '首号3', '首号4'];
$numHeads = 5;
$matrix = array_fill(0, $numHeads, array_fill(0, $numHeads, 0));
$rowTotals = array_fill(0, $numHeads, 0);
$getHead = function ($num) {
return intval(floor($num / 10));
};
$totalTransitions = 0;
for ($i = 0; $i < count($history) - 1; $i++) {
$currentNum = (int)$history[$i]['num7'];
$nextNum = (int)$history[$i + 1]['num7'];
if ($currentNum < 1 || $currentNum > 49 || $nextNum < 1 || $nextNum > 49) continue;
$from = $getHead($currentNum);
$to = $getHead($nextNum);
$matrix[$from][$to]++;
$rowTotals[$from]++;
$totalTransitions++;
}
$probabilities = array_fill(0, $numHeads, array_fill(0, $numHeads, 0));
for ($i = 0; $i < $numHeads; $i++) {
if ($rowTotals[$i] > 0) {
for ($j = 0; $j < $numHeads; $j++) {
$probabilities[$i][$j] = round($matrix[$i][$j] / $rowTotals[$i] * 100, 1);
}
}
}
return [
'heads' => $headLabels,
'matrix' => $matrix,
'probabilities' => $probabilities,
'row_totals' => $rowTotals,
'total_transitions' => $totalTransitions
];
}
/**
* 区域→区域转移矩阵,单元格内显示波色概率
* 统计上一期特码所在区域后,下一期特码在各区域的分布,以及每个区域内的波色占比