deploy: auto commit repo-root changes 2026-07-05 12:33:57

This commit is contained in:
hajimi
2026-07-05 12:33:57 +08:00
parent 1954948445
commit f641276b9d
123 changed files with 1182 additions and 572 deletions
+39 -188
View File
@@ -10,11 +10,11 @@ use app\common\model\lottery\LotteryDrawResult;
use app\common\model\lottery\LotteryAiAnalysis;
use app\common\model\lottery\LotteryNumberMapping;
use app\common\model\lottery\LotteryRegion;
use app\common\service\ai\AiService;
use app\common\service\ai\AiAnalysisRequestService;
class LotteryController extends BaseApiController
{
public array $notNeedLogin = ['categoryList', 'regionList', 'drawList', 'drawDetail', 'latestDraw', 'aiPredict', 'gameList', 'latestDrawResult', 'drawResultList', 'aiHistory', 'aiHotCold', 'aiTrend', 'aiStats', 'aiColorZodiac', 'aiAnalysisHistory'];
public array $notNeedLogin = ['categoryList', 'regionList', 'drawList', 'drawDetail', 'latestDraw', 'gameList', 'latestDrawResult', 'drawResultList', 'aiHistory', 'aiAnalysisHistory'];
/**
* 彩种游戏列表(一级分类 + 二级彩种)
@@ -341,87 +341,7 @@ class LotteryController extends BaseApiController
*/
public function aiPredict()
{
$categoryId = $this->request->get('category_id/d', 0);
$code = $this->request->get('code', '');
// 支持两种查找方式:category_id(旧表)或 code(新表)
if (!empty($code)) {
$game = LotteryGame::where('code', $code)->findOrEmpty();
if ($game->isEmpty()) {
return $this->fail('彩种不存在');
}
$recentDraws = LotteryDrawResult::where('code', $code)
->where('draw_code', '<>', '')
->order('draw_time desc, issue desc')
->limit(30)
->field('issue,draw_time,draw_code')
->select()
->toArray();
foreach ($recentDraws as &$d) {
$d['numbers'] = $d['draw_code'] ? explode(',', $d['draw_code']) : [];
}
$lotteryData = [
'lottery_type' => $code,
'lottery_name' => $game['name'],
'draw_rule' => $game['template'] ?? '',
'recent_draws' => $recentDraws,
];
$result = AiService::analyzeLottery($lotteryData, $this->userId);
if (!$result['success']) {
return $this->fail($result['error'] ?? 'AI分析失败');
}
return $this->data([
'analysis' => $result['data'],
'from_cache' => $result['from_cache'] ?? false,
'category_name' => $game['name'],
]);
}
if (empty($categoryId)) {
return $this->fail('参数缺失');
}
$category = LotteryCategory::where('id', $categoryId)->findOrEmpty();
if ($category->isEmpty()) {
return $this->fail('彩种不存在');
}
// 获取最近30期已开奖数据
$recentDraws = LotteryDraw::where('category_id', $categoryId)
->where('status', 1)
->where('is_show', 1)
->order('draw_date desc, period desc')
->limit(30)
->field('period,draw_date,numbers,special_number,zodiac,color')
->select()
->toArray();
foreach ($recentDraws as &$d) {
$d['numbers'] = is_string($d['numbers']) ? json_decode($d['numbers'], true) : $d['numbers'];
$d['zodiac'] = is_string($d['zodiac']) ? json_decode($d['zodiac'], true) : $d['zodiac'];
$d['color'] = is_string($d['color']) ? json_decode($d['color'], true) : $d['color'];
}
$lotteryData = [
'lottery_type' => $category['code'],
'lottery_name' => $category['name'],
'draw_rule' => $category['draw_rule'],
'recent_draws' => $recentDraws,
];
$result = AiService::analyzeLottery($lotteryData, $this->userId);
if (!$result['success']) {
return $this->fail($result['error'] ?? 'AI分析失败');
}
return $this->data([
'analysis' => $result['data'],
'from_cache' => $result['from_cache'] ?? false,
'category_name' => $category['name'],
]);
return $this->respondAnalysis(AiAnalysisRequestService::analyzeLotteryOverview($this->request->get(), $this->userId));
}
/**
@@ -465,29 +385,7 @@ class LotteryController extends BaseApiController
*/
public function aiHotCold()
{
$code = $this->request->get('code', '');
if (empty($code)) {
return $this->fail('参数缺失');
}
$game = LotteryGame::where('code', $code)->findOrEmpty();
if ($game->isEmpty()) {
return $this->fail('彩种不存在');
}
$recentDraws = $this->getRecentDrawCodes($code, 30);
$lotteryData = [
'lottery_type' => $code,
'lottery_name' => $game['name'],
'draw_rule' => $game['template'] ?? '',
'recent_draws' => $recentDraws,
];
$result = AiService::analyzeLotteryModule($lotteryData, 'hot_cold', $this->userId);
if (!$result['success']) {
return $this->fail($result['error'] ?? 'AI分析失败');
}
return $this->data($result['data']);
return $this->respondLotteryModule('hot_cold');
}
/**
@@ -495,29 +393,7 @@ class LotteryController extends BaseApiController
*/
public function aiTrend()
{
$code = $this->request->get('code', '');
if (empty($code)) {
return $this->fail('参数缺失');
}
$game = LotteryGame::where('code', $code)->findOrEmpty();
if ($game->isEmpty()) {
return $this->fail('彩种不存在');
}
$recentDraws = $this->getRecentDrawCodes($code, 30);
$lotteryData = [
'lottery_type' => $code,
'lottery_name' => $game['name'],
'draw_rule' => $game['template'] ?? '',
'recent_draws' => $recentDraws,
];
$result = AiService::analyzeLotteryModule($lotteryData, 'trend', $this->userId);
if (!$result['success']) {
return $this->fail($result['error'] ?? 'AI分析失败');
}
return $this->data($result['data']);
return $this->respondLotteryModule('trend');
}
/**
@@ -525,29 +401,7 @@ class LotteryController extends BaseApiController
*/
public function aiStats()
{
$code = $this->request->get('code', '');
if (empty($code)) {
return $this->fail('参数缺失');
}
$game = LotteryGame::where('code', $code)->findOrEmpty();
if ($game->isEmpty()) {
return $this->fail('彩种不存在');
}
$recentDraws = $this->getRecentDrawCodes($code, 30);
$lotteryData = [
'lottery_type' => $code,
'lottery_name' => $game['name'],
'draw_rule' => $game['template'] ?? '',
'recent_draws' => $recentDraws,
];
$result = AiService::analyzeLotteryModule($lotteryData, 'stats', $this->userId);
if (!$result['success']) {
return $this->fail($result['error'] ?? 'AI分析失败');
}
return $this->data($result['data']);
return $this->respondLotteryModule('stats');
}
/**
@@ -555,42 +409,7 @@ class LotteryController extends BaseApiController
*/
public function aiColorZodiac()
{
$code = $this->request->get('code', '');
if (empty($code)) {
return $this->fail('参数缺失');
}
$game = LotteryGame::where('code', $code)->findOrEmpty();
if ($game->isEmpty()) {
return $this->fail('彩种不存在');
}
if (($game['template'] ?? '') !== 'HK6') {
return $this->fail('该彩种不支持波色生肖分析');
}
$recentDraws = $this->getRecentDrawCodes($code, 30);
$year = (int) date('Y');
$colorMap = LotteryNumberMapping::getMapByType($year, LotteryNumberMapping::TYPE_COLOR);
$zodiacMap = LotteryNumberMapping::getMapByType($year, LotteryNumberMapping::TYPE_ZODIAC);
$lotteryData = [
'lottery_type' => $code,
'lottery_name' => $game['name'],
'draw_rule' => $game['template'] ?? '',
'recent_draws' => $recentDraws,
'number_mapping' => [
'color' => $colorMap,
'zodiac' => $zodiacMap,
],
];
$result = AiService::analyzeLotteryModule($lotteryData, 'color_zodiac', $this->userId);
if (!$result['success']) {
return $this->fail($result['error'] ?? 'AI分析失败');
}
return $this->data($result['data']);
return $this->respondLotteryModule('color_zodiac');
}
/**
@@ -638,4 +457,36 @@ class LotteryController extends BaseApiController
return $this->data($result);
}
private function respondLotteryModule(string $module)
{
$result = AiAnalysisRequestService::analyzeLotteryModule(
$this->request->get('code', ''),
$module,
$this->userId
);
if (empty($result['success'])) {
return $this->fail($result['error'] ?? 'AI分析失败', [
'remain_count' => $result['remain_count'] ?? null,
]);
}
$data = is_array($result['data'] ?? null) ? $result['data'] : [];
$data['remain_count'] = $result['remain_count'] ?? 0;
$data['unlocked'] = $result['unlocked'] ?? true;
$data['charged'] = $result['charged'] ?? false;
return $this->data($data);
}
private function respondAnalysis(array $result)
{
if (empty($result['success'])) {
return $this->fail($result['error'] ?? 'AI分析失败', [
'remain_count' => $result['remain_count'] ?? null,
]);
}
unset($result['success'], $result['error'], $result['code']);
return $this->data($result);
}
}