代码提交

This commit is contained in:
wong
2025-07-29 17:04:00 +08:00
parent 9726518a46
commit 2b67bd6b77
5 changed files with 194 additions and 70 deletions

View File

@@ -216,7 +216,7 @@ class ContentLibraryController extends Controller
->find();
if (empty($library)) {
return json(['code' => 404, 'msg' => '内容库不存在']);
return json(['code' => 500, 'msg' => '内容库不存在']);
}
// 处理JSON字段转数组
@@ -306,7 +306,7 @@ class ContentLibraryController extends Controller
])->find();
if (!$library) {
return json(['code' => 404, 'msg' => '内容库不存在']);
return json(['code' => 500, 'msg' => '内容库不存在']);
}
Db::startTrans();
@@ -361,7 +361,7 @@ class ContentLibraryController extends Controller
])->find();
if (empty($library)) {
return json(['code' => 404, 'msg' => '内容库不存在']);
return json(['code' => 500, 'msg' => '内容库不存在']);
}
try {
@@ -403,7 +403,7 @@ class ContentLibraryController extends Controller
])->find();
if (empty($library)) {
return json(['code' => 404, 'msg' => '内容库不存在或无权限访问']);
return json(['code' => 500, 'msg' => '内容库不存在或无权限访问']);
}
// 构建查询条件
@@ -520,7 +520,7 @@ class ContentLibraryController extends Controller
])->find();
if (!$library) {
return json(['code' => 404, 'msg' => '内容库不存在']);
return json(['code' => 500, 'msg' => '内容库不存在']);
}
try {
@@ -568,7 +568,7 @@ class ContentLibraryController extends Controller
->find();
if (!$item) {
return json(['code' => 404, 'msg' => '内容项目不存在或无权限操作']);
return json(['code' => 500, 'msg' => '内容项目不存在或无权限操作']);
}
try {
@@ -608,7 +608,7 @@ class ContentLibraryController extends Controller
->find();
if (empty($item)) {
return json(['code' => 404, 'msg' => '内容项目不存在或无权限访问']);
return json(['code' => 500, 'msg' => '内容项目不存在或无权限访问']);
}
// 处理数据
@@ -691,7 +691,7 @@ class ContentLibraryController extends Controller
])->find();
if (!$item) {
return json(['code' => 404, 'msg' => '内容项目不存在或无权限操作']);
return json(['code' => 500, 'msg' => '内容项目不存在或无权限操作']);
}
try {
@@ -754,36 +754,50 @@ class ContentLibraryController extends Controller
{
$id = Request::param('id', '');
$aiPrompt = Request::param('aiPrompt', '');
$content = Request::param('content', '');
$companyId = $this->request->userInfo['companyId'];
// 简单验证
if (empty($id)) {
return json(['code' => 400, 'msg' => '参数错误']);
}
// 查询内容项目是否存在并检查权限
$item = ContentItem::where([
['id', '=', $id],
['isDel', '=', 0]
])->find();
$item = ContentItem::alias('ci')
->join('content_library cl', 'ci.libraryId = cl.id')
->where(['ci.id' => $id, 'ci.isDel' => 0, 'cl.isDel' => 0, 'cl.companyId' => $companyId])
->field('ci.*')
->find();
if (empty($item)) {
return json(['code' => 404, 'msg' => '内容项目不存在或无权限操作']);
return json(['code' => 500, 'msg' => '内容项目不存在或无权限操作']);
}
if (empty($item['content'])) {
return json(['code' => 404, 'msg' => '内容不能为空']);
return json(['code' => 500, 'msg' => '内容不能为空']);
}
try {
$contentAi = $this->aiRewrite(['aiEnabled' => true], $item['content']);
if (!empty($contentAi)) {
ContentItem::where(['id' => $item['id']])->update(['contentAi' => $contentAi, 'updateTime' => time()]);
return json(['code' => 200, 'msg' => 'ai编写成功', 'data' => ['editAfter' => $contentAi, 'editFront' => $item['content']]]);
} else {
return json(['code' => 500, 'msg' => 'ai编写失败']);
$contentFront = !empty($item['contentAi']) ? $item['contentAi'] : $item['content'];
if (!$this->request->isPost()) {
try {
$contentAi = $this->aiRewrite(['aiEnabled' => true, 'aiPrompt' => $aiPrompt], $contentFront);
if (!empty($contentAi)) {
return json(['code' => 200, 'msg' => 'ai编写成功', 'data' => ['contentAfter' => $contentAi, 'contentFront' => $contentFront]]);
} else {
return json(['code' => 500, 'msg' => 'ai编写失败']);
}
} catch (\Exception $e) {
return json(['code' => 500, 'msg' => 'ai编写失败' . $e->getMessage()]);
}
} else {
if (empty($content)) {
return json(['code' => 500, 'msg' => '新内容不能为空']);
}
$res = ContentItem::where(['id' => $item['id']])->update(['contentAi' => $content, 'updateTime' => time()]);
if (!empty($res)) {
return json(['code' => 200, 'msg' => '更新成功']);
} else {
return json(['code' => 500, 'msg' => '更新失败']);
}
} catch (\Exception $e) {
return json(['code' => 500, 'msg' => 'ai编写失败' . $e->getMessage()]);
}
}
@@ -1505,10 +1519,10 @@ class ContentLibraryController extends Controller
];
}
}
}else{
} else {
if (strpos($url, 'feishu.cn') !== false) {
$coverImage = 'http://karuosiyujzk.oss-cn-shenzhen.aliyuncs.com/2025/07/09/3db2a5d7fe49011ab68175a42a5094ce.jpeg';
}else{
} else {
$coverImage = 'http://karuosiyujzk.oss-cn-shenzhen.aliyuncs.com/2025/07/09/ec039d96fad6eab1d960f207d3d9ca9f.jpeg';
}