98 lines
2.2 KiB
PHP
98 lines
2.2 KiB
PHP
<?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();
|
|
}
|
|
} |