ai对话功能提交

This commit is contained in:
wong
2025-10-25 17:41:20 +08:00
parent a5b1861e7d
commit aa3c07a0b2
12 changed files with 1883 additions and 24 deletions

View File

@@ -0,0 +1,52 @@
<?php
namespace app\chukebao\model;
use think\Model;
/**
* AI知识库模型
*/
class AiKnowledgeBase extends Model
{
// 设置表名
protected $name = 'ai_knowledge_base';
// 设置主键
protected $pk = 'id';
// 设置JSON字段
protected $json = ['label'];
// 设置JSON字段自动转换为数组
protected $jsonAssoc = true;
/**
* 关联知识库类型
*/
public function type()
{
return $this->belongsTo(AiKnowledgeBaseType::class, 'typeId', 'id');
}
/**
* 获取有效的知识库列表(未删除)
*/
public static function getValidList($companyId, $typeId = null)
{
$where = [
['isDel', '=', 0],
['companyId', '=', $companyId]
];
if ($typeId !== null) {
$where[] = ['typeId', '=', $typeId];
}
return self::where($where)
->with(['type'])
->order('createTime', 'desc')
->select();
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace app\chukebao\model;
use think\Model;
/**
* AI知识库类型模型
*/
class AiKnowledgeBaseType extends Model
{
// 设置表名
protected $name = 'ai_knowledge_base_type';
// 设置主键
protected $pk = 'id';
// 设置JSON字段
protected $json = ['label'];
// 设置JSON字段自动转换为数组
protected $jsonAssoc = true;
// 类型常量
const TYPE_SYSTEM = 0; // 系统类型
const TYPE_USER = 1; // 用户创建类型
/**
* 获取有效的类型列表(未删除)
*/
public static function getValidList($companyId, $includeSystem = true)
{
$where = [
['isDel', '=', 0]
];
if ($includeSystem) {
$where[] = ['type|companyId', 'in', [0, $companyId]];
} else {
$where[] = ['companyId', '=', $companyId];
$where[] = ['type', '=', self::TYPE_USER];
}
return self::where($where)
->order('createTime', 'desc')
->select();
}
/**
* 检查是否为系统类型
*/
public function isSystemType()
{
return $this->type == self::TYPE_SYSTEM;
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace app\chukebao\model;
use think\Model;
class AiSettings extends Model
{
protected $pk = 'id';
protected $name = 'ai_settings';
// 自动写入时间戳
protected $autoWriteTimestamp = true;
protected $createTime = 'createTime';
protected $updateTime = 'updateTime';
}