feat: 开始复制类型记录

This commit is contained in:
augushong
2025-05-04 18:23:21 +08:00
parent e6a8d46222
commit 0b2bc05cd7
3 changed files with 49 additions and 25 deletions

View File

@@ -4,22 +4,19 @@ declare(strict_types=1);
namespace app\admin\controller; namespace app\admin\controller;
use app\common\tools\PostBlock; use app\model\Nav;
use app\model\Category;
use app\model\Post as ModelPost; use app\model\Post as ModelPost;
use app\model\PostCategory; use app\model\PostCategory;
use app\model\PostTag; use app\model\PostTag;
use app\model\Tag;
use League\HTMLToMarkdown\HtmlConverter; use League\HTMLToMarkdown\HtmlConverter;
use think\facade\Cache; use think\facade\Cache;
use think\facade\Route;
use think\facade\View; use think\facade\View;
use think\Request; use think\Request;
class Post extends Common class Post extends Common
{ {
/** /**
* 显示资源列表 * 显示资源列表.
* *
* @return \think\Response * @return \think\Response
*/ */
@@ -33,12 +30,12 @@ class Post extends Common
$category_id = $this->request->param('category_id', 0); $category_id = $this->request->param('category_id', 0);
if(!empty($category_id)){ if (!empty($category_id)) {
$model_list = $model_list->where('category_id', $category_id); $model_list = $model_list->where('category_id', $category_id);
} }
$list = $model_list->paginate([ $list = $model_list->paginate([
'query' => $this->request->get() 'query' => $this->request->get(),
]); ]);
View::assign('list', $list); View::assign('list', $list);
@@ -59,9 +56,9 @@ class Post extends Common
} }
/** /**
* 保存新建的资源 * 保存新建的资源.
* *
* @param \think\Request $request * @param Request $request
* @return \think\Response * @return \think\Response
*/ */
public function save(Request $request) public function save(Request $request)
@@ -87,19 +84,19 @@ class Post extends Common
foreach ($categorys as $category) { foreach ($categorys as $category) {
PostCategory::create([ PostCategory::create([
'post_id' => $model_post->id, 'post_id' => $model_post->id,
'category_id' => $category 'category_id' => $category,
]); ]);
} }
foreach ($tags as $tag) { foreach ($tags as $tag) {
PostTag::create([ PostTag::create([
'post_id' => $model_post->id, 'post_id' => $model_post->id,
'tag_id' => $tag 'tag_id' => $tag,
]); ]);
} }
return $this->success('添加成功', url('index', [ return $this->success('添加成功', url('index', [
'type' => $this->request->param('type'), 'type' => $this->request->param('type'),
'category_id'=>$this->request->param('category_id'), 'category_id' => $this->request->param('category_id'),
])); ]));
} }
@@ -115,7 +112,7 @@ class Post extends Common
} }
/** /**
* 显示指定的资源 * 显示指定的资源.
* *
* @param int $id * @param int $id
* @return \think\Response * @return \think\Response
@@ -137,7 +134,6 @@ class Post extends Common
$model_post = ModelPost::find($id); $model_post = ModelPost::find($id);
View::assign('post', $model_post); View::assign('post', $model_post);
return View::fetch(); return View::fetch();
@@ -147,23 +143,32 @@ class Post extends Common
{ {
$model_post = ModelPost::find($id); $model_post = ModelPost::find($id);
View::assign('post', $model_post); View::assign('post', $model_post);
return View::fetch(); return View::fetch();
} }
public function output($id) public function output($id)
{ {
$model_post = ModelPost::find($id); $model_post = ModelPost::find($id);
$list_post_platform = Nav::where('type', 12)->order('sort asc')->select();
foreach ($list_post_platform as $model_platform) {
$platform_info = explode("\n",$model_platform->desc);
$model_platform->home_url = $platform_info[0]?? '';
$model_platform->account = $platform_info[1] ?? '';
}
View::assign('post', $model_post); View::assign('post', $model_post);
View::assign('list_post_platform', $list_post_platform);
return View::fetch(); return View::fetch();
} }
/** /**
* 保存更新的资源 * 保存更新的资源.
* *
* @param \think\Request $request * @param Request $request
* @param int $id * @param int $id
* @return \think\Response * @return \think\Response
*/ */
@@ -181,7 +186,7 @@ class Post extends Common
unset($post_data['categorys']); unset($post_data['categorys']);
$old_category_list = PostCategory::where('post_id', $id)->select(); $old_category_list = PostCategory::where('post_id', $id)->select();
$old_category_id_list = array_column((array)$old_category_list, 'id'); $old_category_id_list = array_column((array) $old_category_list, 'id');
// 旧的有新的没有 // 旧的有新的没有
foreach ($old_category_list as $model_category) { foreach ($old_category_list as $model_category) {
@@ -193,10 +198,9 @@ class Post extends Common
// 旧的没有新的有 // 旧的没有新的有
foreach ($categorys as $category) { foreach ($categorys as $category) {
if (!in_array($category, $old_category_id_list)) { if (!in_array($category, $old_category_id_list)) {
PostCategory::create([ PostCategory::create([
'post_id' => $model_post->id, 'post_id' => $model_post->id,
'category_id' => $category 'category_id' => $category,
]); ]);
} }
} }
@@ -206,7 +210,7 @@ class Post extends Common
unset($post_data['tags']); unset($post_data['tags']);
$old_tag_list = PostTag::where('post_id', $id)->select(); $old_tag_list = PostTag::where('post_id', $id)->select();
$old_tag_id_list = array_column((array)$old_tag_list, 'id'); $old_tag_id_list = array_column((array) $old_tag_list, 'id');
foreach ($old_tag_list as $model_tag) { foreach ($old_tag_list as $model_tag) {
if (!in_array($model_tag->id, $tags)) { if (!in_array($model_tag->id, $tags)) {
@@ -216,10 +220,9 @@ class Post extends Common
foreach ($tags as $tag) { foreach ($tags as $tag) {
if (!in_array($tag, $old_tag_id_list)) { if (!in_array($tag, $old_tag_id_list)) {
PostTag::create([ PostTag::create([
'post_id' => $model_post->id, 'post_id' => $model_post->id,
'tag_id' => $tag 'tag_id' => $tag,
]); ]);
} }
} }
@@ -233,7 +236,7 @@ class Post extends Common
} }
/** /**
* 删除指定资源 * 删除指定资源.
* *
* @param int $id * @param int $id
* @return \think\Response * @return \think\Response

View File

@@ -8,6 +8,9 @@
<li class="layui-nav-item layui-nav-itemed left-nav-item" data-name="others"> <li class="layui-nav-item layui-nav-itemed left-nav-item" data-name="others">
<a class="" href="{:url('admin/System/others')}">第三方管理</a> <a class="" href="{:url('admin/System/others')}">第三方管理</a>
</li> </li>
<li class="layui-nav-item layui-nav-itemed left-nav-item" data-name="others">
<a class="" href="{:url('Nav/index',['type'=>12,'show_target'=>1])}">三方同步平台</a>
</li>
<li class="layui-nav-item layui-nav-itemed left-nav-item" data-name="agreement"> <li class="layui-nav-item layui-nav-itemed left-nav-item" data-name="agreement">
<a class="" href="{:url('admin/System/agreement')}">用户协议管理</a> <a class="" href="{:url('admin/System/agreement')}">用户协议管理</a>

View File

@@ -30,7 +30,7 @@
.options-box { .options-box {
position: fixed; position: fixed;
right: 0; right: 0;
top: 20%; top: 0;
margin: 15px; margin: 15px;
padding: 15px; padding: 15px;
border-radius: 5; border-radius: 5;
@@ -102,6 +102,24 @@
</div> </div>
<hr> <hr>
<a class=" select-markdown" href="#post-markdown">选中markdown</a> <a class=" select-markdown" href="#post-markdown">选中markdown</a>
<hr>
<div class="post-platform-list" >
{volist name='list_post_platform' id='vo'}
<div class="post-platform-item">
<div class="post-platform-label" style="text-align: left;">
<span>
{$vo.title}
</span>
</div>
<div class="post-platform-label">
<input type="hidden" name="post-platform[{$vo.id}]" placeholder="请输入文章链接">
</div>
</div>
<hr>
{/volist}
</div>
</div> </div>
<script> <script>