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',

View File

@@ -1,175 +0,0 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{$post.title} - 输出管理</title>
{include file="common/_require"}
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
{include file="common/_header"}
{include file="common/left_post"}
<div class="layui-body">
<div style="padding:15px">
<div class="main-header">
<span class="layui-breadcrumb">
<a>首页</a>
<a href="{:url('post/index')}">内容管理</a>
<a><cite>输出管理 - {$post.title}</cite></a>
</span>
</div>
<div class="main-container">
<div>
<a href="{:url('post/phoneImage',['id'=>$post.id])}" class="layui-btn">
<i class="layui-icon layui-icon-add-1"></i> 新建排版
</a>
<a href="{:url('post/index')}" class="layui-btn layui-btn-primary">
<i class="layui-icon layui-icon-return"></i> 返回列表
</a>
</div>
</div>
<div>
<table class="layui-table" lay-skin="line">
<thead>
<tr>
<th>ID</th>
<th>类型</th>
<th>尺寸</th>
<th>页数</th>
<th>状态</th>
<th>创建时间</th>
<th>图片</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{volist name='list' id='vo'}
<tr class="item" data-id="{$vo.id}">
<td>{$vo.id}</td>
<td>{$vo.output_type_text}</td>
<td>
{if $vo.config && $vo.config.size}
{if $vo.config.size == 'xiaohongshu'}小红书{/if}
{if $vo.config.size == 'douyin'}抖音{/if}
{else/}
-
{/if}
</td>
<td>{$vo.page_count}</td>
<td>{$vo.status_text}</td>
<td>{$vo.create_time}</td>
<td>
<button type="button" class="layui-btn layui-btn-xs btn-view-images"
data-output-id="{$vo.id}">
<i class="layui-icon layui-icon-picture"></i> 查看图片
</button>
</td>
<td>
<div class="layui-btn-container">
<a class="layui-btn layui-btn-xs layui-btn-warm"
href="{:url('post/downloadPostOutputZip',['id'=>$vo.id])}">
<i class="layui-icon layui-icon-download-circle"></i> 下载ZIP
</a>
<button type="button" class="layui-btn layui-btn-xs layui-btn-danger btn-delete-output"
data-output-id="{$vo.id}">
<i class="layui-icon layui-icon-delete"></i> 删除
</button>
</div>
</td>
</tr>
{/volist}
{if condition="count($list) == 0"}
<tr>
<td colspan="8">暂无输出记录,点击"新建排版"创建</td>
</tr>
{/if}
</tbody>
</table>
<div>
{$list|raw}
</div>
</div>
<!-- 图片预览弹窗容器 -->
<div id="image-preview-panel" style="display:none; margin-top:15px; padding:15px; background:#fff; border:1px solid #e8e8e8; border-radius:4px;">
<div style="margin-bottom:10px; display:flex; justify-content:space-between; align-items:center;">
<strong>图片预览</strong>
<button type="button" class="layui-btn layui-btn-xs layui-btn-primary" id="btn-close-preview">
<i class="layui-icon layui-icon-close"></i> 关闭
</button>
</div>
<div id="image-preview-list" style="display:flex; flex-wrap:wrap; gap:10px;"></div>
</div>
</div>
</div>
{include file="common/_footer"}
</div>
<script>
// 查看图片
$('.btn-view-images').click(function () {
var outputId = $(this).data('output-id');
var $panel = $('#image-preview-panel');
var $list = $('#image-preview-list');
$list.html('<div style="padding:20px;">加载中...</div>');
$panel.show();
$.get('{:url("post/getOutputFiles")}', { output_id: outputId }, function (res) {
if (res.code !== 0) {
$list.html('<div style="color:red;">' + (res.msg || '加载失败') + '</div>');
return;
}
if (!res.data || res.data.length === 0) {
$list.html('<div style="color:#999;">暂无图片</div>');
return;
}
var html = '';
for (var i = 0; i < res.data.length; i++) {
var f = res.data[i];
html += '<div style="width:120px; text-align:center;">';
html += '<img src="' + f.file_url + '" style="max-width:120px; max-height:200px; border:1px solid #eee; border-radius:4px;" alt="第' + f.page + '页">';
html += '<div style="font-size:12px; color:#999; margin-top:4px;">第' + f.page + '页</div>';
html += '</div>';
}
$list.html(html);
}).fail(function () {
$list.html('<div style="color:red;">网络错误</div>');
});
});
// 关闭预览
$('#btn-close-preview').click(function () {
$('#image-preview-panel').hide();
});
// 删除输出
$('.btn-delete-output').click(function () {
var btn = $(this);
var outputId = btn.data('output-id');
layer.confirm('确定要删除该输出记录吗?图片文件将一并删除。', function () {
$.get('{:url("post/deletePostOutput")}', { id: outputId }, function (res) {
if (res.code === 0) {
layer.msg('删除成功');
btn.parents('.item').remove();
$('#image-preview-panel').hide();
} else {
layer.msg(res.msg || '删除失败');
}
}).fail(function () {
layer.msg('网络错误');
});
});
});
</script>
</body>
</html>