mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-24 04:01:31 +08:00
抽离文章评论和私有操作
This commit is contained in:
parent
5009ae36a0
commit
acc25bb5dc
@ -5,6 +5,7 @@
|
||||
- 调整登录限制(邮箱|手机)为注册限制
|
||||
- 调整订单发货为每一分钟执行一次
|
||||
- 增强课时安全性,无权限时不返回播放地址或内容
|
||||
- 抽离出文章关闭,仅我可见操作
|
||||
- 增加删除文章和提问接口
|
||||
- 增加首页推荐教师接口
|
||||
- 增加微信公众号支付处理
|
||||
|
@ -7,11 +7,13 @@
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Article\ArticleClose as ArticleCloseService;
|
||||
use App\Services\Logic\Article\ArticleDelete as ArticleDeleteService;
|
||||
use App\Services\Logic\Article\ArticleFavorite as ArticleFavoriteService;
|
||||
use App\Services\Logic\Article\ArticleInfo as ArticleInfoService;
|
||||
use App\Services\Logic\Article\ArticleLike as ArticleLikeService;
|
||||
use App\Services\Logic\Article\ArticleList as ArticleListService;
|
||||
use App\Services\Logic\Article\ArticlePrivate as ArticlePrivateService;
|
||||
use App\Services\Logic\Article\CategoryList as CategoryListService;
|
||||
use App\Services\Logic\Article\CommentList as CommentListService;
|
||||
|
||||
@ -81,6 +83,34 @@ class ArticleController extends Controller
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/close", name="home.article.close")
|
||||
*/
|
||||
public function closeAction($id)
|
||||
{
|
||||
$service = new ArticleCloseService();
|
||||
|
||||
$article = $service->handle($id);
|
||||
|
||||
$msg = $article->closed == 1 ? '关闭评论成功' : '开启评论成功';
|
||||
|
||||
return $this->jsonSuccess(['msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/private", name="home.article.private")
|
||||
*/
|
||||
public function privateAction($id)
|
||||
{
|
||||
$service = new ArticlePrivateService();
|
||||
|
||||
$article = $service->handle($id);
|
||||
|
||||
$msg = $article->private == 1 ? '开启仅我可见成功' : '关闭仅我可见成功';
|
||||
|
||||
return $this->jsonSuccess(['msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/favorite", name="api.article.favorite")
|
||||
*/
|
||||
|
@ -10,12 +10,14 @@ namespace App\Http\Home\Controllers;
|
||||
use App\Http\Home\Services\Article as ArticleService;
|
||||
use App\Http\Home\Services\ArticleQuery as ArticleQueryService;
|
||||
use App\Models\Article as ArticleModel;
|
||||
use App\Services\Logic\Article\ArticleClose as ArticleCloseService;
|
||||
use App\Services\Logic\Article\ArticleCreate as ArticleCreateService;
|
||||
use App\Services\Logic\Article\ArticleDelete as ArticleDeleteService;
|
||||
use App\Services\Logic\Article\ArticleFavorite as ArticleFavoriteService;
|
||||
use App\Services\Logic\Article\ArticleInfo as ArticleInfoService;
|
||||
use App\Services\Logic\Article\ArticleLike as ArticleLikeService;
|
||||
use App\Services\Logic\Article\ArticleList as ArticleListService;
|
||||
use App\Services\Logic\Article\ArticlePrivate as ArticlePrivateService;
|
||||
use App\Services\Logic\Article\ArticleUpdate as ArticleUpdateService;
|
||||
use App\Services\Logic\Article\RelatedArticleList as RelatedArticleListService;
|
||||
use Phalcon\Mvc\View;
|
||||
@ -107,6 +109,14 @@ class ArticleController extends Controller
|
||||
return $this->notFound();
|
||||
}
|
||||
|
||||
$private = $article['private'] == 1;
|
||||
|
||||
$owned = $this->authUser->id == $article['owner']['id'];
|
||||
|
||||
if ($private && !$owned) {
|
||||
return $this->forbidden();
|
||||
}
|
||||
|
||||
$this->seo->prependTitle(['专栏', $article['title']]);
|
||||
$this->seo->setDescription($article['summary']);
|
||||
|
||||
@ -195,6 +205,34 @@ class ArticleController extends Controller
|
||||
return $this->jsonSuccess($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/close", name="home.article.close")
|
||||
*/
|
||||
public function closeAction($id)
|
||||
{
|
||||
$service = new ArticleCloseService();
|
||||
|
||||
$article = $service->handle($id);
|
||||
|
||||
$msg = $article->closed == 1 ? '关闭评论成功' : '开启评论成功';
|
||||
|
||||
return $this->jsonSuccess(['msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/private", name="home.article.private")
|
||||
*/
|
||||
public function privateAction($id)
|
||||
{
|
||||
$service = new ArticlePrivateService();
|
||||
|
||||
$article = $service->handle($id);
|
||||
|
||||
$msg = $article->private == 1 ? '开启仅我可见成功' : '关闭仅我可见成功';
|
||||
|
||||
return $this->jsonSuccess(['msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/favorite", name="home.article.favorite")
|
||||
*/
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
{% set article_edit_url = url({'for':'home.article.edit','id':article.id}) %}
|
||||
{% set article_delete_url = url({'for':'home.article.delete','id':article.id}) %}
|
||||
{% set article_private_url = url({'for':'home.article.private','id':article.id}) %}
|
||||
{% set article_close_url = url({'for':'home.article.close','id':article.id}) %}
|
||||
{% set article_owner_url = url({'for':'home.user.show','id':article.owner.id}) %}
|
||||
{% set article_related_url = url({'for':'home.article.related','id':article.id}) %}
|
||||
{% set article_report_url = url({'for':'home.report.add'},{'item_id':article.id,'item_type':106}) %}
|
||||
@ -44,6 +46,16 @@
|
||||
<div class="right">
|
||||
<span class="kg-report" data-url="{{ article_report_url }}">举报</span>
|
||||
{% if auth_user.id == article.owner.id %}
|
||||
{% if article.closed == 0 %}
|
||||
<span class="article-close" title="关闭评论" data-url="{{ article_close_url }}">关闭</span>
|
||||
{% else %}
|
||||
<span class="article-close" title="开启评论" data-url="{{ article_close_url }}">打开</span>
|
||||
{% endif %}
|
||||
{% if article.private == 0 %}
|
||||
<span class="article-private" title="仅我可见" data-url="{{ article_private_url }}">私密</span>
|
||||
{% else %}
|
||||
<span class="article-private" title="公开可见" data-url="{{ article_private_url }}">共享</span>
|
||||
{% endif %}
|
||||
<span class="article-edit" data-url="{{ article_edit_url }}">编辑</span>
|
||||
<span class="kg-delete" data-url="{{ article_delete_url }}">删除</span>
|
||||
{% endif %}
|
||||
|
36
app/Services/Logic/Article/ArticleClose.php
Normal file
36
app/Services/Logic/Article/ArticleClose.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
||||
* @license https://opensource.org/licenses/GPL-2.0
|
||||
* @link https://www.koogua.com
|
||||
*/
|
||||
|
||||
namespace App\Services\Logic\Article;
|
||||
|
||||
use App\Services\Logic\ArticleTrait;
|
||||
use App\Services\Logic\Service as LogicService;
|
||||
use App\Validators\Validator as AppValidator;
|
||||
|
||||
class ArticleClose extends LogicService
|
||||
{
|
||||
|
||||
use ArticleTrait;
|
||||
|
||||
public function handle($id)
|
||||
{
|
||||
$article = $this->checkArticle($id);
|
||||
|
||||
$user = $this->getLoginUser();
|
||||
|
||||
$validator = new AppValidator();
|
||||
|
||||
$validator->checkOwner($user->id, $article->owner_id);
|
||||
|
||||
$article->closed = $article->closed == 1 ? 0 : 1;
|
||||
|
||||
$article->update();
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
}
|
36
app/Services/Logic/Article/ArticlePrivate.php
Normal file
36
app/Services/Logic/Article/ArticlePrivate.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
||||
* @license https://opensource.org/licenses/GPL-2.0
|
||||
* @link https://www.koogua.com
|
||||
*/
|
||||
|
||||
namespace App\Services\Logic\Article;
|
||||
|
||||
use App\Services\Logic\ArticleTrait;
|
||||
use App\Services\Logic\Service as LogicService;
|
||||
use App\Validators\Validator as AppValidator;
|
||||
|
||||
class ArticlePrivate extends LogicService
|
||||
{
|
||||
|
||||
use ArticleTrait;
|
||||
|
||||
public function handle($id)
|
||||
{
|
||||
$article = $this->checkArticle($id);
|
||||
|
||||
$user = $this->getLoginUser();
|
||||
|
||||
$validator = new AppValidator();
|
||||
|
||||
$validator->checkOwner($user->id, $article->owner_id);
|
||||
|
||||
$article->private = $article->private == 1 ? 0 : 1;
|
||||
|
||||
$article->update();
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
}
|
@ -27,9 +27,30 @@ layui.use(['jquery', 'layer', 'helper'], function () {
|
||||
});
|
||||
|
||||
$('.article-edit').on('click', function () {
|
||||
window.location.href = $(this).data('url');
|
||||
});
|
||||
|
||||
$('.article-close').on('click', function () {
|
||||
var url = $(this).data('url');
|
||||
helper.checkLogin(function () {
|
||||
window.location.href = url;
|
||||
$.post(url, function (res) {
|
||||
if (res.msg) {
|
||||
layer.msg(res.msg, {icon: 1});
|
||||
}
|
||||
setTimeout(function () {
|
||||
window.location.reload()
|
||||
}, 1500);
|
||||
});
|
||||
});
|
||||
|
||||
$('.article-private').on('click', function () {
|
||||
var url = $(this).data('url');
|
||||
$.post(url, function (res) {
|
||||
if (res.msg) {
|
||||
layer.msg(res.msg, {icon: 1});
|
||||
}
|
||||
setTimeout(function () {
|
||||
window.location.reload()
|
||||
}, 1500);
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user