From a65025add9893fc0aba2ea92f727b46eb9e7a57d Mon Sep 17 00:00:00 2001 From: augushong Date: Sun, 3 May 2026 21:08:58 +0800 Subject: [PATCH] feat(post-output): add save-only and load-history endpoints --- app/admin/controller/Post.php | 53 +++++++++++++++++++++++++++++++++ app/common/tools/PhoneImage.php | 19 ++++++++++++ 2 files changed, 72 insertions(+) diff --git a/app/admin/controller/Post.php b/app/admin/controller/Post.php index 0102099..0cc80fa 100644 --- a/app/admin/controller/Post.php +++ b/app/admin/controller/Post.php @@ -436,6 +436,59 @@ class Post extends Common return json(['code' => 0, 'msg' => '保存成功', 'data' => ['output_id' => $output->id]]); } + /** + * 仅保存配置(不生成图片) + */ + public function savePostOutputConfig() + { + $data = json_decode(file_get_contents('php://input'), true); + if (empty($data['post_id'])) { + return json(['code' => 500, 'msg' => '缺少文章ID']); + } + + try { + $config = $data['config'] ?? []; + if (isset($data['content_html']) && !isset($config['content_html'])) { + $config['content_html'] = $data['content_html']; + } + + $admin_id = session('admin_id') ?? 0; + $output = \app\common\tools\PhoneImage::saveConfigOnly((int) $data['post_id'], $config, (int) $admin_id); + + return json(['code' => 0, 'msg' => '', 'data' => ['output_id' => $output->id]]); + } catch (\Exception $e) { + return json(['code' => 500, 'msg' => $e->getMessage()]); + } + } + + /** + * 加载历史记录配置 + */ + public function loadPostOutputConfig() + { + $id = $this->request->param('id', 0); + if (empty($id)) { + return json(['code' => 500, 'msg' => '缺少ID']); + } + + $output = \app\model\PostOutput::find((int) $id); + if (empty($output)) { + return json(['code' => 500, 'msg' => '记录不存在']); + } + + $config = (array) $output->config; + + return json([ + 'code' => 0, + 'msg' => '', + 'data' => [ + 'config' => $config, + 'content_html' => $config['content_html'] ?? '', + 'output_id' => $output->id, + ], + ]); + } + /** * 删除输出记录 */ diff --git a/app/common/tools/PhoneImage.php b/app/common/tools/PhoneImage.php index 37711c7..5124c1d 100644 --- a/app/common/tools/PhoneImage.php +++ b/app/common/tools/PhoneImage.php @@ -212,4 +212,23 @@ class PhoneImage implements PostOutputManagerInterface 'page_count' => $pageCount, ]) > 0; } + + /** + * 仅保存配置(不生成图片),创建新的历史记录 + * @param int $postId 文章ID + * @param array $config 配置(含 size/fontSize/watermark/pageAlignments/content_html) + * @param int $adminId 管理员ID + * @return PostOutput + */ + public static function saveConfigOnly(int $postId, array $config, int $adminId): PostOutput + { + return PostOutput::create([ + 'post_id' => $postId, + 'output_type' => 'phone_image', + 'config' => $config, + 'status' => PostOutput::STATUS_PROCESSING, + 'page_count' => 0, + 'admin_id' => $adminId, + ]); + } }