其余文件

This commit is contained in:
2026-04-14 17:46:22 +08:00
parent 294b68fe37
commit 3691f4db22
1343 changed files with 189847 additions and 0 deletions

View File

@ -0,0 +1,203 @@
<?php
namespace app\admin\logic\community;
use app\common\basics\Logic;
use app\common\enum\CommunityLikeEnum;
use app\common\model\community\CommunityArticle;
use app\common\model\community\CommunityComment;
use app\common\model\community\CommunityLike;
use app\common\model\community\CommunityTopic;
use app\common\logic\CommunityArticleLogic as CommonArticleLogic;
use app\common\server\UrlServer;
use think\Exception;
use think\facade\Db;
/**
* 种草社区文章逻辑
* Class CommunityArticleLogic
* @package app\admin\logic\community
*/
class CommunityArticleLogic extends Logic
{
/**
* @notes 文章列表
* @param $get
* @return array
* @author 段誉
* @date 2022/5/10 11:07
*/
public static function lists($get)
{
$where = [
['a.del', '=', 0]
];
if (!empty($get['keyword'])) {
$where[] = ['u.sn|u.nickname|u.mobile', 'like', '%' . $get['keyword'] . '%'];
}
if (!empty($get['content'])) {
$where[] = ['a.content', 'like', '%' . $get['content'] . '%'];
}
if (isset($get['status']) && $get['status'] != '') {
$where[] = ['a.status', '=', $get['status']];
}
if (isset($get['start_time']) && $get['start_time'] != '') {
$where[] = ['a.audit_time', '>=', strtotime($get['start_time'])];
}
if (isset($get['end_time']) && $get['end_time'] != '') {
$where[] = ['a.audit_time', '<=', strtotime($get['end_time'])];
}
$model = new CommunityArticle();
$lists = $model->with(['images'])->alias('a')
->field('a.*,u.nickname,u.avatar,u.sn')
->join('user u', 'u.id = a.user_id')
->where($where)
->order(['id' => 'desc'])
->append(['status_desc'])
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
foreach ($lists['data'] as &$item) {
$item['avatar'] = !empty($item['avatar']) ? UrlServer::getFileUrl($item['avatar']) : '';
}
return ['count' => $lists['total'], 'lists' => $lists['data']];
}
/**
* @notes 文章详情
* @param $id
* @return array
* @author 段誉
* @date 2022/5/10 16:53
*/
public static function detail($id)
{
$detail = CommunityArticle::with(['images', 'topic', 'user' => function ($query) {
$query->field(['id', 'nickname', 'sn']);
}])
->append(['shop_data', 'goods_data', 'status_desc'])
->findOrEmpty($id);
$detail['cate_name'] = $detail['topic']['cate']['name'] ?? '';
$detail['audit_time'] = date('Y-m-d H:i:s', $detail['audit_time']);
return $detail->toArray();
}
/**
* @notes 删除文章
* @param $id
* @return bool
* @author 段誉
* @date 2022/5/10 16:34
*/
public static function del($id)
{
Db::startTrans();
try {
$article = CommunityArticle::find($id);
$article->del = 1;
$article->update_time = time();
$article->save();
if (!empty($article['topic_id'])) {
CommunityTopic::decArticleNum($article['topic_id']);
}
Db::commit();
return true;
} catch (Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 审核文章
* @param $post
* @return bool
* @author 段誉
* @date 2022/5/12 16:57
*/
public static function audit($post)
{
Db::startTrans();
try {
$article = CommunityArticle::findOrEmpty($post['id']);
$article->status = $post['status'];
$article->audit_remark = $post['audit_remark'] ?? '';
$article->audit_time = time();
$article->save();
// 通知粉丝有新文章发布
CommonArticleLogic::noticeFans($article['user_id'], $post['status']);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 文章关联评论及点赞
* @param $get
* @return array
* @throws \think\db\exception\DbException
* @author 段誉
* @date 2022/5/11 10:14
*/
public static function getRelationData($get)
{
$type = $get['type'] ?? 'comment';
if ($type == 'comment') {
$lists = CommunityComment::with(['user'])
->where([
'del' => 0,
'article_id' => $get['id'],
])->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
} else {
$lists = CommunityLike::with(['user'])
->where([
'relation_id' => $get['id'],
'type' => CommunityLikeEnum::TYPE_ARTICLE
])
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
}
return ['count' => $lists['total'], 'lists' => $lists['data']];
}
}

View File

@ -0,0 +1,167 @@
<?php
namespace app\admin\logic\community;
use app\common\basics\Logic;
use app\common\model\community\CommunityCategory;
use app\common\model\community\CommunityTopic;
use think\Exception;
/**
* 种草社区分类逻辑
* Class CommunityCategoryLogic
* @package app\admin\logic\content
*/
class CommunityCategoryLogic extends Logic
{
/**
* @notes 获取分类
* @param $get
* @return array
* @throws \think\db\exception\DbException
* @author 段誉
* @date 2022/4/28 10:09
*/
public static function lists($get)
{
$where = [
['del', '=', 0]
];
if (!empty($get['name'])) {
$where[] = ['name', 'like', '%'.$get['name'].'%'];
}
$model = new CommunityCategory();
$lists = $model->field(true)
->where($where)
->order(['sort' => 'asc', 'id' => 'desc'])
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
return ['count' => $lists['total'], 'lists' => $lists['data']];
}
/**
* @notes 获取分类
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/4/28 10:11
*/
public static function getCategory()
{
return CommunityCategory::where(['del' => 0, 'is_show' => 1])
->order(['sort' => 'asc', 'id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取分类详情
* @param $id
* @return array
* @author 段誉
* @date 2022/4/28 10:11
*/
public static function detail($id)
{
return CommunityCategory::findOrEmpty($id)->toArray();
}
/**
* @notes 添加分类
* @param $post
* @return CommunityCategory|\think\Model
* @author 段誉
* @date 2022/4/28 10:23
*/
public static function add($post)
{
return CommunityCategory::create([
'name' => $post['name'],
'is_show' => $post['is_show'],
'sort' => $post['sort'] ?? 255,
'create_time' => time()
]);
}
/**
* @notes 编辑分类
* @param $post
* @return CommunityCategory
* @author 段誉
* @date 2022/4/28 10:24
*/
public static function edit($post)
{
return CommunityCategory::update([
'name' => $post['name'],
'is_show' => $post['is_show'],
'sort' => $post['sort'] ?? 255,
'update_time' => time()
], ['id' => $post['id']]);
}
/**
* @notes 删除分类
* @param $id
* @return bool
* @author 段誉
* @date 2022/4/28 15:19
*/
public static function del($id)
{
try {
$topic = CommunityTopic::where(['del' => 0, 'cid'=> $id])->findOrEmpty();
if (!$topic->isEmpty()) {
throw new Exception('该分类已关联话题,暂无法删除');
}
CommunityCategory::update([
'id' => $id,
'del' => 1,
'update_time' => time()
]);
return true;
} catch (Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 设置显示状态
* @param $post
* @author 段誉
* @date 2022/4/28 10:50
*/
public static function setShowStatus($post)
{
CommunityCategory::update([
'is_show' => $post['is_show'],
'update_time' => time()
], ['id' => $post['id']]);
}
}

View File

@ -0,0 +1,127 @@
<?php
namespace app\admin\logic\community;
use app\common\basics\Logic;
use app\common\enum\CommunityCommentEnum;
use app\common\model\community\CommunityArticle;
use app\common\model\community\CommunityComment;
use app\common\server\UrlServer;
/**
* 种草社区评论
* Class CommunityCommentLogic
* @package app\admin\logic\community
*/
class CommunityCommentLogic extends Logic
{
/**
* @notes 评论列表
* @param $get
* @return array
* @author 段誉
* @date 2022/5/10 12:06
*/
public static function lists($get)
{
$where = [
['c.del', '=', 0]
];
if (!empty($get['keyword'])) {
$where[] = ['u.sn|u.nickname|u.mobile', 'like', '%' . $get['keyword'] . '%'];
}
if (!empty($get['comment'])) {
$where[] = ['c.comment', 'like', '%' . $get['comment'] . '%'];
}
if (isset($get['status']) && $get['status'] != '') {
$where[] = ['c.status', '=', $get['status']];
}
$model = new CommunityComment();
$lists = $model->alias('c')
->with(['article' => function($query) {
$query->field('id,content,topic_id');
}])
->field('c.*,u.nickname,u.avatar,u.sn')
->join('user u', 'u.id = c.user_id')
->where($where)
->order(['id' => 'desc'])
->append(['status_desc'])
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
]);
foreach ($lists as &$item) {
$item['avatar'] = !empty($item['avatar']) ? UrlServer::getFileUrl($item['avatar']) : '';
$item['status_desc'] = CommunityCommentEnum::getStatusDesc($item['status']);
$item['topic_name'] = $item['article']['topic']['name'] ?? '';
}
return ['count' => $lists->total(), 'lists' => $lists->getCollection()];
}
/**
* @notes 详情
* @param $id
* @return array
* @author 段誉
* @date 2022/5/10 12:15
*/
public static function detail($id)
{
return CommunityComment::with(['article'])->findOrEmpty($id)->toArray();
}
/**
* @notes 审核成功
* @param $post
* @return CommunityComment
* @author 段誉
* @date 2022/5/10 15:11
*/
public static function audit($post)
{
return CommunityComment::where(['id' => $post['id']])->update([
'status' => $post['status'],
'update_time' => time()
]);
}
/**
* @notes 删除评论
* @param $id
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/5/10 15:23
*/
public static function del($id)
{
// 删除评论
$comment = CommunityComment::find($id);
$comment->del = 1;
$comment->update_time = time();
$comment->save();
// 更新文章评论数
CommunityArticle::where([
['id', '=', $comment['article_id']],
['comment', '>=', 1]]
)->dec('comment')->update();
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace app\admin\logic\community;
use app\common\basics\Logic;
use app\common\server\ConfigServer;
/**
* 种草社区设置
* Class CommunityTopicLogic
* @package app\admin\logic\content
*/
class CommunitySettingLogic extends Logic
{
/**
* @notes 获取社区配置
* @return array
* @author 段誉
* @date 2022/4/28 16:13
*/
public static function getConfig()
{
$config = [
'status' => ConfigServer::get('community', 'status', 1),
'audit_article' => ConfigServer::get('community', 'audit_article', 1),
'audit_comment' => ConfigServer::get('community', 'audit_comment', 1),
];
return $config;
}
/**
* @notes 设置社区配置
* @param $post
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/4/28 16:14
*/
public static function setConfig($post)
{
ConfigServer::set('community', 'status', $post['status']);
ConfigServer::set('community', 'audit_article', $post['audit_article']);
ConfigServer::set('community', 'audit_comment', $post['audit_comment']);
}
}

View File

@ -0,0 +1,160 @@
<?php
namespace app\admin\logic\community;
use app\common\basics\Logic;
use app\common\model\community\CommunityArticle;
use app\common\model\community\CommunityTopic;
/**
* 种草社区话题逻辑
* Class CommunityTopicLogic
* @package app\admin\logic\content
*/
class CommunityTopicLogic extends Logic
{
/**
* @notes 获取话题
* @param $get
* @return array
* @throws \think\db\exception\DbException
* @author 段誉
* @date 2022/4/28 10:09
*/
public static function lists($get)
{
$where = [
['del', '=', 0]
];
if (!empty($get['name'])) {
$where[] = ['name', 'like', '%'.$get['name'].'%'];
}
if (!empty($get['cid'])) {
$where[] = ['cid', '=', $get['cid']];
}
$model = new CommunityTopic();
$lists = $model->with(['cate'])
->where($where)
->order(['sort' => 'asc', 'id' => 'desc'])
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
foreach ($lists['data'] as &$item) {
$item['cate_name'] = $item['cate']['name'] ?? '';
}
return ['count' => $lists['total'], 'lists' => $lists['data']];
}
/**
* @notes 获取话题详情
* @param $id
* @return array
* @author 段誉
* @date 2022/4/28 10:11
*/
public static function detail($id)
{
return CommunityTopic::findOrEmpty($id)->toArray();
}
/**
* @notes 添加话题
* @param $post
* @return CommunityTopic|\think\Model
* @author 段誉
* @date 2022/4/28 10:23
*/
public static function add($post)
{
return CommunityTopic::create([
'name' => $post['name'],
'image' => $post['image'],
'cid' => $post['cid'],
'is_show' => $post['is_show'],
'is_recommend' => $post['is_recommend'],
'sort' => $post['sort'] ?? 255,
'create_time' => time()
]);
}
/**
* @notes 编辑话题
* @param $post
* @return CommunityTopic
* @author 段誉
* @date 2022/4/28 10:24
*/
public static function edit($post)
{
return CommunityTopic::update([
'name' => $post['name'],
'image' => $post['image'],
'cid' => $post['cid'],
'is_show' => $post['is_show'],
'is_recommend' => $post['is_recommend'],
'sort' => $post['sort'] ?? 255,
'update_time' => time()
], ['id' => $post['id']]);
}
/**
* @notes 删除话题
* @param $id
* @return bool
* @author 段誉
* @date 2022/5/10 15:53
*/
public static function del($id)
{
try {
$check = CommunityArticle::where(['topic_id' => $id, 'del' => 0])->findOrEmpty();
if (!$check->isEmpty()) {
throw new \Exception('该话题下已关联文章,不可删除');
}
CommunityTopic::where(['id' => $id])->update([
'del' => 1,
'update_time' => time()
]);
return true;
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 设置显示状态
* @param $post
* @author 段誉
* @date 2022/4/28 10:50
*/
public static function setStatus($post)
{
CommunityTopic::update([
$post['field'] => $post['value'],
'update_time' => time()
], ['id' => $post['id']]);
}
}