no message

This commit is contained in:
hajimi
2026-06-11 12:15:29 +08:00
parent 10ebe39c30
commit 96efa1d905
5859 changed files with 815501 additions and 5 deletions
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace app\common\model\ai;
use app\common\model\BaseModel;
class AiAnalysis extends BaseModel
{
// 分析类型
const TYPE_MATCH_PREDICT = 1;
const TYPE_ARTICLE_ANALYSIS = 2;
const TYPE_USER_CREDIBILITY = 3;
const TYPE_LOTTERY_ANALYSIS = 4;
const TYPE_POST_ANALYSIS = 5;
const TYPE_KB_RETRIEVAL = 6;
const TYPE_ASSISTANT_CHAT = 7;
// 状态
const STATUS_SUCCESS = 1;
const STATUS_FAILED = 2;
const STATUS_PROCESSING = 3;
/**
* 获取有效缓存
*/
public static function getCache(int $type, int $refId): ?array
{
$row = self::where('type', $type)
->where('ref_id', $refId)
->where('status', self::STATUS_SUCCESS)
->where('expire_time', '>', time())
->order('id', 'desc')
->findOrEmpty();
if ($row->isEmpty()) {
return null;
}
return $row->toArray();
}
}
@@ -0,0 +1,16 @@
<?php
namespace app\common\model\ai;
use app\common\model\BaseModel;
class AiChatMessage extends BaseModel
{
protected $name = 'ai_chat_message';
public const ROLE_USER = 'user';
public const ROLE_ASSISTANT = 'assistant';
public const STATUS_SUCCESS = 1;
public const STATUS_FAILED = 2;
}
@@ -0,0 +1,10 @@
<?php
namespace app\common\model\ai;
use app\common\model\BaseModel;
class AiChatSession extends BaseModel
{
protected $name = 'ai_chat_session';
}
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace app\common\model\ai;
use app\common\model\BaseModel;
class AiConfig extends BaseModel
{
public static function getVal(string $name, string $default = ''): string
{
$val = AiConfig::where('name', $name)->value('value');
return $val !== null ? $val : $default;
}
public static function setVal(string $name, string $value): void
{
$row = AiConfig::where('name', $name)->findOrEmpty();
if ($row->isEmpty()) {
AiConfig::create(['name' => $name, 'value' => $value]);
} else {
$row->value = $value;
$row->save();
}
}
}
+14
View File
@@ -0,0 +1,14 @@
<?php
namespace app\common\model\ai;
use app\common\model\BaseModel;
class AiKbChunk extends BaseModel
{
protected $name = 'ai_kb_chunk';
protected $json = ['embedding_json'];
protected $jsonAssoc = true;
}
@@ -0,0 +1,14 @@
<?php
namespace app\common\model\ai;
use app\common\model\BaseModel;
class AiKbDocument extends BaseModel
{
protected $name = 'ai_kb_document';
protected $json = ['metadata_json'];
protected $jsonAssoc = true;
}
@@ -0,0 +1,17 @@
<?php
namespace app\common\model\ai;
use app\common\model\BaseModel;
class AiKbQueryLog extends BaseModel
{
protected $name = 'ai_kb_query_log';
protected $json = ['filters_json', 'hit_docs_json'];
protected $jsonAssoc = true;
public const STATUS_SUCCESS = 1;
public const STATUS_FAILED = 2;
}
@@ -0,0 +1,19 @@
<?php
namespace app\common\model\ai;
use app\common\model\BaseModel;
class AiKbSyncJob extends BaseModel
{
protected $name = 'ai_kb_sync_job';
public const STATUS_PENDING = 0;
public const STATUS_PROCESSING = 1;
public const STATUS_SUCCESS = 2;
public const STATUS_FAILED = 3;
public const ACTION_UPSERT = 'upsert';
public const ACTION_DELETE = 'delete';
public const ACTION_REBUILD = 'rebuild';
}
+9
View File
@@ -0,0 +1,9 @@
<?php
namespace app\common\model\ai;
use app\common\model\BaseModel;
class AiLog extends BaseModel
{
}
+87
View File
@@ -0,0 +1,87 @@
<?php
namespace app\common\model\ai;
use app\common\model\BaseModel;
use app\common\model\user\User;
class AiUnlock extends BaseModel
{
/**
* 检查用户是否已解锁某场比赛
*/
public static function isUnlocked(int $userId, int $matchId): bool
{
return self::where('user_id', $userId)->where('match_id', $matchId)->count() > 0;
}
/**
* 解锁比赛(扣次数 + 写记录)
* @return array ['ok' => bool, 'msg' => string]
*/
public static function unlock(int $userId, int $matchId): array
{
// 已解锁则直接返回
if (self::isUnlocked($userId, $matchId)) {
return ['ok' => true, 'msg' => '已解锁'];
}
// 检查今日剩余次数
$user = User::findOrEmpty($userId);
if ($user->isEmpty()) {
return ['ok' => false, 'msg' => '用户不存在'];
}
// VIP用户不限次数
if ($user->is_vip && $user->vip_expire_time > time()) {
self::create([
'user_id' => $userId,
'match_id' => $matchId,
]);
return ['ok' => true, 'msg' => 'VIP解锁'];
}
// 重置每日次数(跨天时)
$today = date('Y-m-d');
if ($user->ai_free_date !== $today) {
$user->ai_free_count = 3;
$user->ai_free_date = $today;
$user->save();
}
if ($user->ai_free_count <= 0) {
return ['ok' => false, 'msg' => '今日免费次数已用完,升级VIP可无限使用'];
}
// 扣次数 + 写解锁记录
$user->ai_free_count = $user->ai_free_count - 1;
$user->save();
self::create([
'user_id' => $userId,
'match_id' => $matchId,
]);
return ['ok' => true, 'msg' => '解锁成功', 'remain' => $user->ai_free_count];
}
/**
* 获取用户今日剩余次数
*/
public static function getRemainCount(int $userId): int
{
$user = User::findOrEmpty($userId);
if ($user->isEmpty()) {
return 0;
}
// VIP不限
if ($user->is_vip && $user->vip_expire_time > time()) {
return 999;
}
$today = date('Y-m-d');
if ($user->ai_free_date !== $today) {
return 3;
}
return max(0, (int)$user->ai_free_count);
}
}