This commit is contained in:
mkm 2024-02-18 17:31:11 +08:00
parent 3b25807f24
commit 2afb129b7b
18 changed files with 1143 additions and 10 deletions

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\controller\article;
use app\admin\controller\BaseAdminController;
use app\admin\lists\article\ArticleCommentLists;
use app\admin\logic\article\ArticleCommentLogic;
use app\admin\validate\article\ArticleCommentValidate;
/**
* 评论控制器
* Class ArticleCommentController
* @package app\admin\controller\article
*/
class ArticleCommentController extends BaseAdminController
{
/**
* @notes 获取评论列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:03
*/
public function lists()
{
return $this->dataLists(new ArticleCommentLists());
}
/**
* @notes 添加评论
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:03
*/
public function add()
{
$params = (new ArticleCommentValidate())->post()->goCheck('add');
$result = ArticleCommentLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ArticleCommentLogic::getError());
}
/**
* @notes 编辑评论
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:03
*/
public function edit()
{
$params = (new ArticleCommentValidate())->post()->goCheck('edit');
$result = ArticleCommentLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ArticleCommentLogic::getError());
}
/**
* @notes 删除评论
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:03
*/
public function delete()
{
$params = (new ArticleCommentValidate())->post()->goCheck('delete');
ArticleCommentLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取评论详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:03
*/
public function detail()
{
$params = (new ArticleCommentValidate())->goCheck('detail');
$result = ArticleCommentLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\controller\article;
use app\admin\controller\BaseAdminController;
use app\admin\lists\article\ArticleCommentLikeLists;
use app\admin\logic\article\ArticleCommentLikeLogic;
use app\admin\validate\article\ArticleCommentLikeValidate;
/**
* 评论点赞控制器
* Class ArticleCommentLikeController
* @package app\admin\controller\article
*/
class ArticleCommentLikeController extends BaseAdminController
{
/**
* @notes 获取评论点赞列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:41
*/
public function lists()
{
return $this->dataLists(new ArticleCommentLikeLists());
}
/**
* @notes 添加评论点赞
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:41
*/
public function add()
{
$params = (new ArticleCommentLikeValidate())->post()->goCheck('add');
$result = ArticleCommentLikeLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ArticleCommentLikeLogic::getError());
}
/**
* @notes 编辑评论点赞
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:41
*/
public function edit()
{
$params = (new ArticleCommentLikeValidate())->post()->goCheck('edit');
$result = ArticleCommentLikeLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ArticleCommentLikeLogic::getError());
}
/**
* @notes 删除评论点赞
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:41
*/
public function delete()
{
$params = (new ArticleCommentLikeValidate())->post()->goCheck('delete');
ArticleCommentLikeLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取评论点赞详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:41
*/
public function detail()
{
$params = (new ArticleCommentLikeValidate())->goCheck('detail');
$result = ArticleCommentLikeLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\controller\article;
use app\admin\controller\BaseAdminController;
use app\admin\lists\article\ArticleLikeLists;
use app\admin\logic\article\ArticleLikeLogic;
use app\admin\validate\article\ArticleLikeValidate;
/**
* 文章点赞控制器
* Class ArticleLikeController
* @package app\admin\controller\article
*/
class ArticleLikeController extends BaseAdminController
{
/**
* @notes 获取文章点赞列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:47
*/
public function lists()
{
return $this->dataLists(new ArticleLikeLists());
}
/**
* @notes 添加文章点赞
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:47
*/
public function add()
{
$params = (new ArticleLikeValidate())->post()->goCheck('add');
$result = ArticleLikeLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ArticleLikeLogic::getError());
}
/**
* @notes 编辑文章点赞
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:47
*/
public function edit()
{
$params = (new ArticleLikeValidate())->post()->goCheck('edit');
$result = ArticleLikeLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ArticleLikeLogic::getError());
}
/**
* @notes 删除文章点赞
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:47
*/
public function delete()
{
$params = (new ArticleLikeValidate())->post()->goCheck('delete');
ArticleLikeLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取文章点赞详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/18 15:47
*/
public function detail()
{
$params = (new ArticleLikeValidate())->goCheck('detail');
$result = ArticleLikeLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace app\admin\lists\article;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\article\ArticleCommentLike;
use app\common\lists\ListsSearchInterface;
/**
* 评论点赞列表
* Class ArticleCommentLikeLists
* @package app\admin\listsarticle
*/
class ArticleCommentLikeLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/02/18 15:41
*/
public function setSearch(): array
{
return [
'=' => ['comment_id', 'state', 'like_user'],
];
}
/**
* @notes 获取评论点赞列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/02/18 15:41
*/
public function lists(): array
{
return ArticleCommentLike::where($this->searchWhere)
->field(['id', 'comment_id', 'state', 'like_user'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取评论点赞数量
* @return int
* @author likeadmin
* @date 2024/02/18 15:41
*/
public function count(): int
{
return ArticleCommentLike::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace app\admin\lists\article;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\article\ArticleComment;
use app\common\lists\ListsSearchInterface;
/**
* 评论列表
* Class ArticleCommentLists
* @package app\admin\listsarticle
*/
class ArticleCommentLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/02/18 15:03
*/
public function setSearch(): array
{
return [
'=' => ['article_id', 'state', 'comment_user'],
];
}
/**
* @notes 获取评论列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/02/18 15:03
*/
public function lists(): array
{
return ArticleComment::where($this->searchWhere)
->with(['title'])
->field(['id', 'pre_id', 'content', 'article_id', 'state', 'comment_user'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取评论数量
* @return int
* @author likeadmin
* @date 2024/02/18 15:03
*/
public function count(): int
{
return ArticleComment::where($this->searchWhere)->count();
}
}

View File

@ -6,7 +6,8 @@ namespace app\admin\lists\article;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\article\ArticleLabel;
use app\common\lists\ListsSearchInterface;
use app\common\model\article\Article;
use app\common\model\setting\Label;
/**
* 文章标签列表
@ -47,6 +48,10 @@ class ArticleLabelLists extends BaseAdminDataLists implements ListsSearchInterfa
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->each(function($item){
$item['article_id']=Article::where('id',$item['article_id'])->value('title');
$item['label_id']=Label::where('id',$item['label_id'])->value('label_name');
})
->toArray();
}

View File

@ -0,0 +1,65 @@
<?php
namespace app\admin\lists\article;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\article\ArticleLike;
use app\common\lists\ListsSearchInterface;
/**
* 文章点赞列表
* Class ArticleLikeLists
* @package app\admin\listsarticle
*/
class ArticleLikeLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/02/18 15:47
*/
public function setSearch(): array
{
return [
'=' => ['article_id', 'state', 'like_user'],
];
}
/**
* @notes 获取文章点赞列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/02/18 15:47
*/
public function lists(): array
{
return ArticleLike::where($this->searchWhere)
->field(['id', 'article_id', 'state', 'like_user'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取文章点赞数量
* @return int
* @author likeadmin
* @date 2024/02/18 15:47
*/
public function count(): int
{
return ArticleLike::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,98 @@
<?php
namespace app\admin\logic\article;
use app\common\model\article\ArticleCommentLike;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 评论点赞逻辑
* Class ArticleCommentLikeLogic
* @package app\admin\logic\article
*/
class ArticleCommentLikeLogic extends BaseLogic
{
/**
* @notes 添加评论点赞
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/18 15:41
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
ArticleCommentLike::create([
'comment_id' => $params['comment_id'],
'state' => $params['state'],
'like_user' => $params['like_user']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑评论点赞
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/18 15:41
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ArticleCommentLike::where('id', $params['id'])->update([
'comment_id' => $params['comment_id'],
'state' => $params['state'],
'like_user' => $params['like_user']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除评论点赞
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/18 15:41
*/
public static function delete(array $params): bool
{
return ArticleCommentLike::destroy($params['id']);
}
/**
* @notes 获取评论点赞详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/02/18 15:41
*/
public static function detail($params): array
{
return ArticleCommentLike::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\logic\article;
use app\common\model\article\ArticleComment;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 评论逻辑
* Class ArticleCommentLogic
* @package app\admin\logic\article
*/
class ArticleCommentLogic extends BaseLogic
{
/**
* @notes 添加评论
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/18 15:03
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
ArticleComment::create([
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑评论
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/18 15:03
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ArticleComment::where('id', $params['id'])->update([
'content' => $params['content'],
'state' => $params['state']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除评论
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/18 15:03
*/
public static function delete(array $params): bool
{
return ArticleComment::destroy($params['id']);
}
/**
* @notes 获取评论详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/02/18 15:03
*/
public static function detail($params): array
{
return ArticleComment::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,98 @@
<?php
namespace app\admin\logic\article;
use app\common\model\article\ArticleLike;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 文章点赞逻辑
* Class ArticleLikeLogic
* @package app\admin\logic\article
*/
class ArticleLikeLogic extends BaseLogic
{
/**
* @notes 添加文章点赞
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/18 15:47
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
ArticleLike::create([
'article_id' => $params['article_id'],
'state' => $params['state'],
'like_user' => $params['like_user']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑文章点赞
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/18 15:47
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ArticleLike::where('id', $params['id'])->update([
'article_id' => $params['article_id'],
'state' => $params['state'],
'like_user' => $params['like_user']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除文章点赞
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/18 15:47
*/
public static function delete(array $params): bool
{
return ArticleLike::destroy($params['id']);
}
/**
* @notes 获取文章点赞详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/02/18 15:47
*/
public static function detail($params): array
{
return ArticleLike::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -6,6 +6,8 @@ namespace app\admin\logic\article;
use app\common\model\article\Article;
use app\common\logic\BaseLogic;
use app\common\model\article\ArticleContent;
use app\common\model\article\ArticleLabel;
use app\common\model\setting\Label;
use think\facade\Db;
@ -29,12 +31,21 @@ class ArticleLogic extends BaseLogic
{
Db::startTrans();
try {
$res= Article::create([
$res = Article::create([
'title' => $params['title'],
'state' => $params['state'],
'top' => $params['top']
]);
ArticleContent::create(['article_id'=>$res->id,'content'=>$params['content']]);
ArticleContent::create(['article_id' => $res->id, 'content' => $params['content']]);
if ($params['tag']) {
$label_id = Label::whereIn('label_name', $params['tag'])->column('id');
foreach ($label_id as $v) {
$find = ArticleLabel::where('label_id', $v)->find();
if (!$find) {
ArticleLabel::create(['article_id' => $res->id, ['label_id'] => $v]);
}
}
}
Db::commit();
return true;
} catch (\Exception $e) {
@ -65,11 +76,31 @@ class ArticleLogic extends BaseLogic
// 'create_user' => $params['create_user'],
// 'update_user' => $params['update_user']
]);
$find=ArticleContent::where('article_id',$params['id'])->find();
if($find){
ArticleContent::where('article_id',$params['id'])->update(['content'=>$params['content']]);
}else{
ArticleContent::create(['article_id'=>$params['id'],'content'=>$params['content']]);
$find = ArticleContent::where('article_id', $params['id'])->find();
if ($find) {
ArticleContent::where('article_id', $params['id'])->update(['content' => $params['content']]);
} else {
ArticleContent::create(['article_id' => $params['id'], 'content' => $params['content']]);
}
if ($params['tag']) {
$arr = [];
$label_arr_id = [];
foreach ($params['tag'] as $vv) {
$arr[] = ['label_name' => $vv];
$label_id = Label::where('label_name', $vv)->value('id');
if ($label_id) {
$label_arr_id[] = $label_id;
} else {
$label = Label::create(['label_name' => $vv]);
$label_arr_id[] = $label->id;
}
}
foreach ($label_arr_id as $v) {
$find = ArticleLabel::where('label_id', $v)->find();
if (!$find) {
ArticleLabel::create(['article_id' => $params['id'], 'label_id' => $v]);
}
}
}
Db::commit();
return true;
@ -103,6 +134,13 @@ class ArticleLogic extends BaseLogic
*/
public static function detail($params): array
{
return Article::with('detail')->findOrEmpty($params['id'])->toArray();
$detail = Article::with('detail')->findOrEmpty($params['id'])->toArray();
if ($detail) {
$arr = ArticleLabel::where('article_id', $params['id'])->column('label_id');
if ($arr) {
$detail['tag'] = Label::whereIn('id', $arr)->column('label_name');
}
}
return $detail;
}
}
}

View File

@ -0,0 +1,82 @@
<?php
namespace app\admin\validate\article;
use app\common\validate\BaseValidate;
/**
* 评论点赞验证器
* Class ArticleCommentLikeValidate
* @package app\admin\validate\article
*/
class ArticleCommentLikeValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
];
/**
* @notes 添加场景
* @return ArticleCommentLikeValidate
* @author likeadmin
* @date 2024/02/18 15:41
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 编辑场景
* @return ArticleCommentLikeValidate
* @author likeadmin
* @date 2024/02/18 15:41
*/
public function sceneEdit()
{
return $this->only(['id']);
}
/**
* @notes 删除场景
* @return ArticleCommentLikeValidate
* @author likeadmin
* @date 2024/02/18 15:41
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ArticleCommentLikeValidate
* @author likeadmin
* @date 2024/02/18 15:41
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,82 @@
<?php
namespace app\admin\validate\article;
use app\common\validate\BaseValidate;
/**
* 评论验证器
* Class ArticleCommentValidate
* @package app\admin\validate\article
*/
class ArticleCommentValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
];
/**
* @notes 添加场景
* @return ArticleCommentValidate
* @author likeadmin
* @date 2024/02/18 15:03
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 编辑场景
* @return ArticleCommentValidate
* @author likeadmin
* @date 2024/02/18 15:03
*/
public function sceneEdit()
{
return $this->only(['id']);
}
/**
* @notes 删除场景
* @return ArticleCommentValidate
* @author likeadmin
* @date 2024/02/18 15:03
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ArticleCommentValidate
* @author likeadmin
* @date 2024/02/18 15:03
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,82 @@
<?php
namespace app\admin\validate\article;
use app\common\validate\BaseValidate;
/**
* 文章点赞验证器
* Class ArticleLikeValidate
* @package app\admin\validate\article
*/
class ArticleLikeValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
];
/**
* @notes 添加场景
* @return ArticleLikeValidate
* @author likeadmin
* @date 2024/02/18 15:47
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 编辑场景
* @return ArticleLikeValidate
* @author likeadmin
* @date 2024/02/18 15:47
*/
public function sceneEdit()
{
return $this->only(['id']);
}
/**
* @notes 删除场景
* @return ArticleLikeValidate
* @author likeadmin
* @date 2024/02/18 15:47
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ArticleLikeValidate
* @author likeadmin
* @date 2024/02/18 15:47
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace app\common\model\article;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 评论模型
* Class ArticleComment
* @package app\common\model\article
*/
class ArticleComment extends BaseModel
{
use SoftDelete;
protected $name = 'article_comment';
protected $deleteTime = 'delete_time';
public function title()
{
return $this->hasOne(Article::class,'id','article_id')->bind(['article_title'=>'title']);
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace app\common\model\article;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 评论点赞模型
* Class ArticleCommentLike
* @package app\common\model\article
*/
class ArticleCommentLike extends BaseModel
{
use SoftDelete;
protected $name = 'article_comment_like';
protected $deleteTime = 'delete_time';
}

View File

@ -0,0 +1,22 @@
<?php
namespace app\common\model\article;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 文章点赞模型
* Class ArticleLike
* @package app\common\model\article
*/
class ArticleLike extends BaseModel
{
use SoftDelete;
protected $name = 'article_like';
protected $deleteTime = 'delete_time';
}

View File

@ -19,6 +19,8 @@ return [
'prefix' => 'la_',
'strict' => true,
'engine' => null,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
],
],
];