mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-07-08 03:42:48 +08:00
feat(post): 新增手机图片排版与AI智能排版功能
- 新增手机图片排版功能,支持小红书/抖音尺寸输出 - 新增AI智能排版顾问,支持内容分析与优化推荐 - 新增AI供应商管理,支持多渠道配置与同步 - 新增文章输出管理页面,支持图片预览与批量下载 - 新增字体文件与排版样式配置
This commit is contained in:
87
app/common/tools/AiLayoutAdvisor.php
Normal file
87
app/common/tools/AiLayoutAdvisor.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\tools;
|
||||
|
||||
use app\common\tools\ai\AiChannelManager;
|
||||
use app\model\Post;
|
||||
|
||||
/**
|
||||
* AI 智能排版顾问.
|
||||
*
|
||||
* 分析文章内容并推荐排版配置,或优化内容以适配手机图片排版.
|
||||
*/
|
||||
class AiLayoutAdvisor
|
||||
{
|
||||
/**
|
||||
* 分析文章并推荐排版配置.
|
||||
*
|
||||
* @param Post $post 文章模型
|
||||
*
|
||||
* @return array ['success'=>bool, 'data'=>..., 'msg'=>...]
|
||||
*/
|
||||
public function analyzeAndRecommend(Post $post): array
|
||||
{
|
||||
try {
|
||||
$manager = new AiChannelManager();
|
||||
$provider = $manager->getDefaultProvider();
|
||||
|
||||
if (!$provider) {
|
||||
return ['success' => false, 'msg' => 'AI 功能暂不可用,请检查后台 AI 设置'];
|
||||
}
|
||||
|
||||
$systemPrompt = "你是一位专业的手机图文排版设计师。根据文章内容,推荐最适合的排版配置。"
|
||||
. "你必须返回JSON格式:{\"template\":\"minimal|magazine|mixed\",\"font\":\"source-han-sans|alibaba-puhuiti|lxgw-wenkai\","
|
||||
. "\"font_size\":14,\"reason\":\"推荐理由\"}"
|
||||
. "模板特点:minimal=白底黑字留白多适合长文,magazine=装饰线首字下沉适合正式文章,mixed=图文穿插适合图片多的文章。"
|
||||
. "字体特点:source-han-sans=思源黑体通用,alibaba-puhuiti=阿里巴巴普惠体现代感,lxgw-wenkai=霞鹜文楷文艺感。";
|
||||
|
||||
$contentPreview = mb_substr(strip_tags($post->content_html ?? ''), 0, 500);
|
||||
$imageCount = substr_count($post->content_html ?? '', '<img');
|
||||
|
||||
$userPrompt = "文章标题:{$post->title}\n"
|
||||
. '摘要:' . ($post->desc ?? '无') . "\n"
|
||||
. "正文前500字:{$contentPreview}\n"
|
||||
. "图片数量:{$imageCount}\n"
|
||||
. '分类:' . ($post->category_name ?? '未分类');
|
||||
|
||||
$result = $provider->chatJson($systemPrompt, $userPrompt);
|
||||
|
||||
return ['success' => true, 'data' => $result];
|
||||
} catch (\Exception $e) {
|
||||
return ['success' => false, 'msg' => 'AI 分析失败: ' . $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 优化内容以适配手机图片排版.
|
||||
*
|
||||
* @param Post $post 文章模型
|
||||
*
|
||||
* @return array ['success'=>bool, 'data'=>..., 'msg'=>...]
|
||||
*/
|
||||
public function optimizeContent(Post $post): array
|
||||
{
|
||||
try {
|
||||
$manager = new AiChannelManager();
|
||||
$provider = $manager->getDefaultProvider();
|
||||
|
||||
if (!$provider) {
|
||||
return ['success' => false, 'msg' => 'AI 功能暂不可用,请检查后台 AI 设置'];
|
||||
}
|
||||
|
||||
$systemPrompt = "你是一位专业的内容编辑。优化以下文章内容,使其更适合在手机图片上展示。"
|
||||
. "要求:1.标题更简短有力 2.段落精简(每段不超过100字) 3.提炼3-5个要点"
|
||||
. "返回JSON:{\"optimized_title\":\"标题\",\"optimized_paragraphs\":[\"段落1\",\"段落2\"],\"summary_points\":[\"要点1\",\"要点2\"]}";
|
||||
|
||||
$content = mb_substr(strip_tags($post->content_html ?? ''), 0, 1000);
|
||||
|
||||
$userPrompt = "文章标题:{$post->title}\n原文内容:{$content}";
|
||||
|
||||
$result = $provider->chatJson($systemPrompt, $userPrompt);
|
||||
|
||||
return ['success' => true, 'data' => $result];
|
||||
} catch (\Exception $e) {
|
||||
return ['success' => false, 'msg' => 'AI 内容优化失败: ' . $e->getMessage()];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user