app更新提示

This commit is contained in:
wong
2025-10-30 10:58:45 +08:00
parent 8ae8e66a3a
commit 903a29ed09
5 changed files with 233 additions and 7 deletions

View File

@@ -39,14 +39,13 @@ class AiKnowledgeBaseController extends BaseController
if ($includeSystem == 1) {
// 包含系统类型和本公司创建的类型
$where[] = ['type', '=', AiKnowledgeBaseType::TYPE_SYSTEM];
$where[] = ['companyId|type', 'in', [$companyId, 0]];
$where[] = ['companyId', 'in', [$companyId, 0]];
} else {
// 只显示本公司创建的类型
$where[] = ['companyId', '=', $companyId];
$where[] = ['type', '=', AiKnowledgeBaseType::TYPE_USER];
}
// 查询数据
$list = AiKnowledgeBaseType::where($where)
->order('type', 'asc') // 系统类型排在前面
@@ -80,6 +79,7 @@ class AiKnowledgeBaseController extends BaseController
$description = $this->request->param('description', '');
$label = $this->request->param('label', []);
$prompt = $this->request->param('prompt', '');
$status = $this->request->param('status', 1); // 默认启用
// 参数验证
if (empty($name)) {
@@ -103,8 +103,9 @@ class AiKnowledgeBaseController extends BaseController
'type' => AiKnowledgeBaseType::TYPE_USER,
'name' => $name,
'description' => $description,
'label' => json_decode($label,256),
'label' => json_encode($label,256),
'prompt' => $prompt,
'status' => $status,
'companyId' => $companyId,
'userId' => $userId,
'createTime' => time(),
@@ -142,6 +143,7 @@ class AiKnowledgeBaseController extends BaseController
$description = $this->request->param('description', '');
$label = $this->request->param('label', []);
$prompt = $this->request->param('prompt', '');
$status = $this->request->param('status', '');
// 参数验证
if (empty($id)) {
@@ -187,8 +189,11 @@ class AiKnowledgeBaseController extends BaseController
// 更新数据
$typeModel->name = $name;
$typeModel->description = $description;
$typeModel->label = $label;
$typeModel->label = json_encode($label,256);
$typeModel->prompt = $prompt;
if ($status !== '') {
$typeModel->status = $status;
}
$typeModel->updateTime = time();
if ($typeModel->save()) {
@@ -202,6 +207,111 @@ class AiKnowledgeBaseController extends BaseController
}
}
/**
* 修改知识库类型状态
*
* @return \think\response\Json
*/
public function updateTypeStatus()
{
try {
$companyId = $this->getUserInfo('companyId');
if (empty($companyId)) {
return ResponseHelper::error('公司信息获取失败');
}
// 获取参数
$id = $this->request->param('id', 0);
$status = $this->request->param('status', -1);
// 参数验证
if (empty($id)) {
return ResponseHelper::error('类型ID不能为空');
}
if ($status != 0 && $status != 1) {
return ResponseHelper::error('状态参数错误');
}
// 查找类型
$typeModel = AiKnowledgeBaseType::where([
['id', '=', $id],
['isDel', '=', 0]
])->find();
if (!$typeModel) {
return ResponseHelper::error('类型不存在');
}
// 检查是否为系统类型
if ($typeModel->isSystemType()) {
return ResponseHelper::error('系统类型不允许修改状态');
}
// 检查权限(只能修改本公司的类型)
if ($typeModel->companyId != $companyId) {
return ResponseHelper::error('无权限修改该类型');
}
// 更新状态
$typeModel->status = $status;
$typeModel->updateTime = time();
if ($typeModel->save()) {
$message = $status == 0 ? '禁用成功' : '启用成功';
return ResponseHelper::success([], $message);
} else {
return ResponseHelper::error('操作失败');
}
} catch (\Exception $e) {
return ResponseHelper::error('系统异常:' . $e->getMessage());
}
}
/**
* 获取知识库类型详情
*
* @return \think\response\Json
*/
public function detailType()
{
try {
$companyId = $this->getUserInfo('companyId');
if (empty($companyId)) {
return ResponseHelper::error('公司信息获取失败');
}
// 获取参数
$id = $this->request->param('id', 0);
// 参数验证
if (empty($id)) {
return ResponseHelper::error('类型ID不能为空');
}
// 查找类型
$typeModel = AiKnowledgeBaseType::where([
['id', '=', $id],
['isDel', '=', 0]
])->find();
if (!$typeModel) {
return ResponseHelper::error('类型不存在');
}
// 检查权限(系统类型或本公司的类型都可以查看)
if ($typeModel->companyId != 0 && $typeModel->companyId != $companyId) {
return ResponseHelper::error('无权限查看该类型');
}
return ResponseHelper::success($typeModel, '获取成功');
} catch (\Exception $e) {
return ResponseHelper::error('系统异常:' . $e->getMessage());
}
}
/**
* 删除知识库类型
*