ai对话功能提交
This commit is contained in:
52
Server/application/chukebao/model/AiKnowledgeBase.php
Normal file
52
Server/application/chukebao/model/AiKnowledgeBase.php
Normal 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();
|
||||
}
|
||||
}
|
||||
|
||||
57
Server/application/chukebao/model/AiKnowledgeBaseType.php
Normal file
57
Server/application/chukebao/model/AiKnowledgeBaseType.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
17
Server/application/chukebao/model/AiSettings.php
Normal file
17
Server/application/chukebao/model/AiSettings.php
Normal 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';
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user