mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-07-09 01:02:47 +08:00
feat(post-output): add save-only and load-history endpoints
This commit is contained in:
@@ -436,6 +436,59 @@ class Post extends Common
|
|||||||
return json(['code' => 0, 'msg' => '保存成功', 'data' => ['output_id' => $output->id]]);
|
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,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除输出记录
|
* 删除输出记录
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -212,4 +212,23 @@ class PhoneImage implements PostOutputManagerInterface
|
|||||||
'page_count' => $pageCount,
|
'page_count' => $pageCount,
|
||||||
]) > 0;
|
]) > 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,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user