first commit

This commit is contained in:
Your Name
2026-01-19 14:19:22 +08:00
commit fe2d9c1868
4777 changed files with 665503 additions and 0 deletions

View File

@@ -0,0 +1,156 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\api\logic;
use app\common\enum\YesNoEnum;
use app\common\logic\BaseLogic;
use app\common\model\article\Article;
use app\common\model\article\ArticleCate;
use app\common\model\article\ArticleCollect;
use app\common\model\decorate\{DecorateHint};
use app\common\service\{FileService,UtilsService};
/**
* 文章逻辑
* Class ArticleLogic
* @package app\api\logic
*/
class ArticleLogic extends BaseLogic
{
/**
* @notes 文章详情
* @param $params
* @return array
* @author 段誉
* @date 2022/9/20 17:09
*/
public static function detail($params)
{
//未传语言,则默认使用首个语言
if($params['lang'] == ''){
$first_lang = UtilsService::get_first_lang();
$params['lang'] = $first_lang['symbol'];
}
// 文章详情
$article = Article::getArticleDetailArr($params['id']);
//多语言替换
$data = UtilsService::get_langs_data($article['langs'],$params['lang']);
$data_title = '';
$data_content = '';
if(count($data) > 0){
$data_title = $data['title'];
$data_content = $data['content'];
}
$article['content'] = get_file_domain($data_content);
$article['title'] = $data_title;
unset($article['langs']);
return $article;
}
/**
* @notes 提示内容详情
* @param $params
* @return array
* @author 段誉
* @date 2022/9/20 17:09
*/
public static function hintDetail($params)
{
//未传语言,则默认使用首个语言
if($params['lang'] == ''){
$first_lang = UtilsService::get_first_lang();
$params['lang'] = $first_lang['symbol'];
}
$hint = DecorateHint::field(['content','langs'])->findOrEmpty($params['id'])->toArray();
//多语言替换
$data = UtilsService::get_langs_data($hint['langs'],$params['lang']);
$data_content = '';
if(count($data) > 0){
$data_content = $data['content'];
}
$hint['content'] = get_file_domain($data_content);
unset($hint['langs']);
return $hint;
}
/**
* @notes 加入收藏
* @param $userId
* @param $articleId
* @author 段誉
* @date 2022/9/20 16:52
*/
public static function addCollect($articleId, $userId)
{
$where = ['user_id' => $userId, 'article_id' => $articleId];
$collect = ArticleCollect::where($where)->findOrEmpty();
if ($collect->isEmpty()) {
ArticleCollect::create([
'user_id' => $userId,
'article_id' => $articleId,
'status' => YesNoEnum::YES
]);
} else {
ArticleCollect::update([
'id' => $collect['id'],
'status' => YesNoEnum::YES
]);
}
}
/**
* @notes 取消收藏
* @param $articleId
* @param $userId
* @author 段誉
* @date 2022/9/20 16:59
*/
public static function cancelCollect($articleId, $userId)
{
ArticleCollect::update(['status' => YesNoEnum::NO], [
'user_id' => $userId,
'article_id' => $articleId,
'status' => YesNoEnum::YES
]);
}
/**
* @notes 文章分类
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/23 14:11
*/
public static function cate()
{
return ArticleCate::field('id,name')
->where('is_show', '=', 1)
->order(['sort' => 'desc', 'id' => 'desc'])
->select()->toArray();
}
}