作者 李宇航

合并分支 'lyh-server' 到 'master'

Lyh server



查看合并请求 !2831
... ... @@ -1588,4 +1588,27 @@ if (!function_exists('httpGetSsl')) {
$result = json_decode($res, true);
return is_array($result) ? $result : $res;
}
/**
* @remark :截取自付出啊
* @name :truncate_words
* @author :lyh
* @method :post
* @time :2025/9/22 14:46
*/
function truncate_text($text, $limit = 300) {
// 长度小于限制直接返回
if (mb_strlen($text, 'UTF-8') <= $limit) {
return $text;
}
// 先取前 $limit 个字符
$truncated = mb_substr($text, 0, $limit, 'UTF-8');
// 如果这一段包含空格(说明有英文单词),尽量在最后一个空格处截断
$lastSpace = mb_strrpos($truncated, ' ', 0, 'UTF-8');
if ($lastSpace !== false) {
// 在最后一个空格处截断,避免英文单词被截断
$truncated = mb_substr($truncated, 0, $lastSpace, 'UTF-8');
}
return $truncated;
}
}
... ...
... ... @@ -229,13 +229,11 @@ class AiBlogController extends BaseController
'image'=>['required'],
'author_id'=>['required'],
'text'=>['required'],
'description'=>['required'],
],[
'new_title.required' => '标题不能为空',
'image.required' => '缩略图不能为空',
'author_id.required' => '作者id不能为空',
'text.required' => '作者id不能为空',
'description.required' => '短描述不能为空',
'text.required' => '内容不能为空',
]);
$data = $aiBlogLogic->customSaveBlog($this->param);
$this->response('success',Code::SUCCESS,$data);
... ...
... ... @@ -179,6 +179,9 @@ class AiBlogLogic extends BaseLogic
'title'=>$param['new_title'], 'thumb'=>$param['image'], 'foreword'=>$param['description'] ?? '',
'author_id'=>$this->param['author_id'], 'url'=>$param['route'],
];
if(!isset($param['description']) || empty($param['description'])){
$param['description'] = truncate_text($param['text']);
}
if(isset($param['id']) && !empty($param['id'])){
$id = $param['id'];
$data['task_id'] = $param['task_id'];
... ... @@ -196,13 +199,6 @@ class AiBlogLogic extends BaseLogic
$text1 = Common::deal_str($text1);
$param['seo_keyword'] = $text1;
}
if(!isset($param['description']) || empty($param['description'])){
$ai = "According to the keyword {$param['title']}, write a seo meta description show to purchaser within 100 characters";
$text2 = Gpt::instance()->openai_chat_qqs($ai);
$text2 = Common::deal_keywords($text2);
$text2 = Common::deal_str($text2);
$param['description'] = $text2;
}
$param['route'] = RouteMap::setRoute($param['route'], RouteMap::SOURCE_AI_BLOG, $id, $this->user['project_id']);
$this->model->edit($param,['id'=>$param['id']]);
}else{
... ...