first commit
This commit is contained in:
137
app/adminapi/logic/article/ArticleCateLogic.php
Normal file
137
app/adminapi/logic/article/ArticleCateLogic.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?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\adminapi\logic\article;
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\ArticleCate;
|
||||
|
||||
/**
|
||||
* 资讯分类管理逻辑
|
||||
* Class ArticleCateLogic
|
||||
* @package app\adminapi\logic\article
|
||||
*/
|
||||
class ArticleCateLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加资讯分类
|
||||
* @param array $params
|
||||
* @author heshihu
|
||||
* @date 2022/2/18 10:17
|
||||
*/
|
||||
public static function add(array $params)
|
||||
{
|
||||
ArticleCate::create([
|
||||
'name' => $params['name'],
|
||||
'is_show' => $params['is_show'],
|
||||
'sort' => $params['sort'] ?? 0,
|
||||
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑资讯分类
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author heshihu
|
||||
* @date 2022/2/21 17:50
|
||||
*/
|
||||
public static function edit(array $params) : bool
|
||||
{
|
||||
try {
|
||||
ArticleCate::update([
|
||||
'id' => $params['id'],
|
||||
'name' => $params['name'],
|
||||
'is_show' => $params['is_show'],
|
||||
'sort' => $params['sort'] ?? 0,
|
||||
'langs' => json_encode($params['langs'], JSON_UNESCAPED_UNICODE),
|
||||
]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除资讯分类
|
||||
* @param array $params
|
||||
* @author heshihu
|
||||
* @date 2022/2/21 17:52
|
||||
*/
|
||||
public static function delete(array $params)
|
||||
{
|
||||
ArticleCate::destroy($params['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 查看资讯分类详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author heshihu
|
||||
* @date 2022/2/21 17:54
|
||||
*/
|
||||
public static function detail($params) : array
|
||||
{
|
||||
|
||||
$articleCate = ArticleCate::findOrEmpty($params['id'])->toArray();
|
||||
|
||||
$langs = json_decode($articleCate['langs'], true);
|
||||
if(empty($langs)){
|
||||
$langs = [];
|
||||
}
|
||||
$articleCate['langs'] = $langs;
|
||||
return $articleCate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更改资讯分类状态
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author heshihu
|
||||
* @date 2022/2/21 18:04
|
||||
*/
|
||||
public static function updateStatus(array $params)
|
||||
{
|
||||
ArticleCate::update([
|
||||
'id' => $params['id'],
|
||||
'is_show' => $params['is_show']
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 文章分类数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/10/13 10:53
|
||||
*/
|
||||
public static function getAllData()
|
||||
{
|
||||
return ArticleCate::where(['is_show' => YesNoEnum::YES])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
201
app/adminapi/logic/article/ArticleLogic.php
Normal file
201
app/adminapi/logic/article/ArticleLogic.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?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\adminapi\logic\article;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\service\FileService;
|
||||
|
||||
use app\common\model\user\{User,UserNotice};
|
||||
|
||||
/**
|
||||
* 资讯管理逻辑
|
||||
* Class ArticleLogic
|
||||
* @package app\adminapi\logic\article
|
||||
*/
|
||||
class ArticleLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 添加资讯
|
||||
* @param array $params
|
||||
* @author heshihu
|
||||
* @date 2022/2/22 9:57
|
||||
*/
|
||||
public static function add(array $params)
|
||||
{
|
||||
$langs = $params['langs'];
|
||||
|
||||
foreach ($langs as &$content_lang) {
|
||||
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
|
||||
$content_lang['content'] = clear_file_domain($content_lang['content']);
|
||||
}
|
||||
|
||||
$article = Article::create([
|
||||
'title' => $params['title'],
|
||||
'desc' => $params['desc'] ?? '',
|
||||
'author' => $params['author'] ?? '', //作者
|
||||
'sort' => $params['sort'] ?? 0, // 排序
|
||||
'abstract' => $params['abstract'], // 文章摘要
|
||||
'click_virtual' => $params['click_virtual'] ?? 0,
|
||||
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
|
||||
'cid' => $params['cid'],
|
||||
'is_show' => $params['is_show'],
|
||||
'is_popup' => $params['is_popup'],
|
||||
'is_notice' => $params['is_notice'],
|
||||
'is_sys_notice' => $params['is_sys_notice'],
|
||||
'content' => $params['content'] ?? '',
|
||||
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
|
||||
]);
|
||||
|
||||
if($params['is_sys_notice'] == 1){
|
||||
$users = User::select()->toArray();
|
||||
foreach ($users as &$user) {
|
||||
UserNotice::create([
|
||||
'user_id' => $user['id'],
|
||||
'article_id' => $article['id'],
|
||||
'title' => $article['title'],
|
||||
'content' => $article['content'] ?? '',
|
||||
'langs' => $article['langs'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑资讯
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author heshihu
|
||||
* @date 2022/2/22 10:12
|
||||
*/
|
||||
public static function edit(array $params) : bool
|
||||
{
|
||||
try {
|
||||
$langs = $params['langs'];
|
||||
|
||||
foreach ($langs as &$content_lang) {
|
||||
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
|
||||
$content_lang['content'] = clear_file_domain($content_lang['content']);
|
||||
}
|
||||
$article = Article::update([
|
||||
'id' => $params['id'],
|
||||
'title' => $params['title'],
|
||||
'desc' => $params['desc'] ?? '', // 简介
|
||||
'author' => $params['author'] ?? '', //作者
|
||||
'sort' => $params['sort'] ?? 0, // 排序
|
||||
'abstract' => $params['abstract'], // 文章摘要
|
||||
'click_virtual' => $params['click_virtual'] ?? 0,
|
||||
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
|
||||
'cid' => $params['cid'],
|
||||
'is_show' => $params['is_show'],
|
||||
'is_popup' => $params['is_popup'],
|
||||
'is_notice' => $params['is_notice'],
|
||||
'is_sys_notice' => $params['is_sys_notice'],
|
||||
'content' => $params['content'] ?? '',
|
||||
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
|
||||
]);
|
||||
|
||||
if($params['is_sys_notice'] == 1){
|
||||
$notices = UserNotice::where(['article_id' => $params['id']])->select()->toArray();
|
||||
foreach ($notices as &$notice) {
|
||||
UserNotice::update([
|
||||
'id' => $notice['id'],
|
||||
'title' => $article['title'],
|
||||
'content' => $article['content'] ?? '',
|
||||
'langs' => $article['langs'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除资讯
|
||||
* @param array $params
|
||||
* @author heshihu
|
||||
* @date 2022/2/22 10:17
|
||||
*/
|
||||
public static function delete(array $params)
|
||||
{
|
||||
Article::destroy($params['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 查看资讯详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author heshihu
|
||||
* @date 2022/2/22 10:15
|
||||
*/
|
||||
public static function detail($params) : array
|
||||
{
|
||||
$article = Article::findOrEmpty($params['id'])->toArray();
|
||||
|
||||
$langs = json_decode($article['langs'], true);
|
||||
|
||||
if(!empty($langs)){
|
||||
foreach ($langs as &$content_lang) {
|
||||
$content_lang['image'] = FileService::getFileUrl($content_lang['image']);
|
||||
$content_lang['content'] = get_file_domain($content_lang['content']);
|
||||
}
|
||||
}else{
|
||||
$langs = [];
|
||||
}
|
||||
$article['langs'] = $langs;
|
||||
return $article;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更改资讯状态
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author heshihu
|
||||
* @date 2022/2/22 10:18
|
||||
*/
|
||||
public static function updateStatus(array $params)
|
||||
{
|
||||
Article::update([
|
||||
'id' => $params['id'],
|
||||
'is_show' => $params['is_show']
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 资讯列表
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/03/17 17:01
|
||||
*/
|
||||
public static function all($params) : array
|
||||
{
|
||||
$field = ['id', 'title'];
|
||||
$articles = Article::field($field)
|
||||
->where(['cid' => $params['cid'],'is_show' => 1])
|
||||
->order(['sort' => 'desc','id' => 'desc'])
|
||||
->select()->toArray();
|
||||
return $articles;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user