refactor(typesetting): Wave1 - UPSERT改造 + 移除历史记录后端接口

- PhoneImage.php: saveConfigOnly/createOutput改为find-then-update-or-create
- Post.php: 移除6个历史记录方法(postOutputList/getOutputListJson等)
- 删除post_output/index.html模板
This commit is contained in:
augushong
2026-05-17 00:22:04 +08:00
parent e3a4cd000c
commit aa067ad202
3 changed files with 30 additions and 316 deletions

View File

@@ -383,23 +383,6 @@ class Post extends Common
return View::fetch();
}
/**
* 输出管理列表页
*/
public function postOutputList($id)
{
$model_post = ModelPost::find($id);
if (empty($model_post)) {
$this->error('文章不存在');
}
$output_list = \app\model\PostOutput::where('post_id', $id)
->order('id', 'desc')
->paginate(10);
View::assign('post', $model_post);
View::assign('list', $output_list);
return View::fetch('post_output/index');
}
/**
* 保存输出记录
*/
@@ -468,96 +451,6 @@ class Post extends Common
}
}
/**
* 加载历史记录配置
*/
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,
],
]);
}
/**
* 获取输出记录列表(JSON)
*/
public function getOutputListJson()
{
$id = $this->request->param('id', 0);
$list = \app\model\PostOutput::where('post_id', $id)
->where('output_type', 'phone_image')
->order('id', 'desc')
->limit(20)
->select();
$result = [];
foreach ($list as $item) {
$result[] = [
'id' => $item->id,
'status' => $item->status,
'page_count' => $item->page_count,
'create_time' => $item->create_time,
];
}
return json(['code' => 0, 'data' => $result]);
}
/**
* 删除输出记录
*/
public function deletePostOutput()
{
$id = $this->request->param('id', 0);
if (empty($id)) {
return json(['code' => 500, 'msg' => '缺少ID']);
}
$phoneImage = new \app\common\tools\PhoneImage();
$phoneImage->deleteOutput((int) $id);
return json(['code' => 0, 'msg' => '删除成功']);
}
/**
* 重新生成(用相同配置)
*/
public function regeneratePostOutput()
{
$id = $this->request->param('id', 0);
if (empty($id)) {
return json(['code' => 500, 'msg' => '缺少ID']);
}
$output = \app\model\PostOutput::find($id);
if (empty($output)) {
return json(['code' => 500, 'msg' => '输出记录不存在']);
}
$phoneImage = new \app\common\tools\PhoneImage();
$phoneImage->deleteOutput((int) $id);
return json(['code' => 0, 'msg' => '请重新排版', 'data' => ['config' => $output->config]]);
}
/**
* 下载ZIP
*/
@@ -641,40 +534,6 @@ class Post extends Common
return View::fetch('post/output_view');
}
/**
* 获取输出文件列表(AJAX)
*/
public function getOutputFiles()
{
$outputId = $this->request->param('output_id', 0);
if (empty($outputId)) {
return json(['code' => 500, 'msg' => '缺少输出ID']);
}
$output = \app\model\PostOutput::find((int) $outputId);
if (empty($output)) {
return json(['code' => 500, 'msg' => '输出记录不存在']);
}
$files = \app\model\PostOutputFile::getByOutput((int) $outputId);
$result = [];
foreach ($files as $file) {
$result[] = [
'id' => $file->id,
'page' => $file->page,
'file_url' => $file->file_url,
'file_size' => $file->file_size,
'width' => $file->width,
'height' => $file->height,
'image_data' => $file->image_data ?: null,
];
}
return json(['code' => 0, 'data' => $result]);
}
/**
* AI智能排版推荐.
*/

View File

@@ -250,6 +250,22 @@ class PhoneImage implements PostOutputManagerInterface
*/
public function createOutput(int $postId, array $config, int $adminId): PostOutput
{
$existing = PostOutput::where('post_id', $postId)
->where('output_type', 'phone_image')
->where('delete_time', 0)
->find();
if ($existing) {
PostOutputFile::where('output_id', $existing->id)->delete();
$existing->config = $config;
$existing->status = PostOutput::STATUS_PROCESSING;
$existing->page_count = 0;
$existing->admin_id = $adminId;
$existing->save();
return $existing;
}
return PostOutput::create([
'post_id' => $postId,
'output_type' => 'phone_image',
@@ -280,6 +296,20 @@ class PhoneImage implements PostOutputManagerInterface
*/
public static function saveConfigOnly(int $postId, array $config, int $adminId): PostOutput
{
$existing = PostOutput::where('post_id', $postId)
->where('output_type', 'phone_image')
->where('delete_time', 0)
->find();
if ($existing) {
$existing->config = $config;
$existing->content_html = $config['content_html'] ?? $existing->content_html;
$existing->admin_id = $adminId;
$existing->save();
return $existing;
}
return PostOutput::create([
'post_id' => $postId,
'output_type' => 'phone_image',