no message

This commit is contained in:
hajimi
2026-06-11 12:15:29 +08:00
parent 10ebe39c30
commit 96efa1d905
5859 changed files with 815501 additions and 5 deletions
@@ -0,0 +1,33 @@
<?php
namespace app\adminapi\logic\community;
use app\common\logic\BaseLogic;
use app\common\model\community\CommunityComment;
use app\common\model\community\CommunityPost;
class CommunityCommentLogic extends BaseLogic
{
public static function updateStatus(array $params): bool
{
try {
CommunityComment::update([
'id' => $params['id'],
'status' => $params['status'],
]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function delete(array $params)
{
$comment = CommunityComment::findOrEmpty($params['id']);
if (!$comment->isEmpty()) {
CommunityPost::where('id', $comment->post_id)->dec('comment_count')->update();
$comment->delete();
}
}
}
@@ -0,0 +1,95 @@
<?php
namespace app\adminapi\logic\community;
use app\common\logic\BaseLogic;
use app\common\model\community\CommunityPost;
use app\common\service\ai\KbSyncService;
use app\common\model\user\User;
class CommunityPostLogic extends BaseLogic
{
public static function detail($params): array
{
$post = CommunityPost::findOrEmpty($params['id'])->toArray();
if (!empty($post['create_time']) && is_numeric($post['create_time'])) {
$post['create_time'] = date('Y-m-d H:i:s', $post['create_time']);
}
if (!empty($post['update_time']) && is_numeric($post['update_time'])) {
$post['update_time'] = date('Y-m-d H:i:s', $post['update_time']);
}
$user = User::field('nickname,avatar')->findOrEmpty($post['user_id'] ?? 0)->toArray();
$post['nickname'] = $user['nickname'] ?? '-';
$post['avatar'] = $user['avatar'] ?? '';
return $post;
}
public static function updateStatus(array $params): bool
{
try {
CommunityPost::update([
'id' => $params['id'],
'status' => $params['status'],
]);
KbSyncService::enqueue(
'post',
'post',
(int) $params['id'],
(int) $params['status'] === 1 ? 'upsert' : 'delete',
30
);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function setTop(array $params): bool
{
try {
CommunityPost::update([
'id' => $params['id'],
'is_top' => $params['is_top'],
]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function setHot(array $params): bool
{
try {
CommunityPost::update([
'id' => $params['id'],
'is_hot' => $params['is_hot'],
]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function setRecommend(array $params): bool
{
try {
CommunityPost::update([
'id' => $params['id'],
'is_recommend' => $params['is_recommend'],
]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function delete(array $params)
{
CommunityPost::destroy($params['id']);
KbSyncService::enqueue('post', 'post', (int) $params['id'], 'delete', 20);
}
}
@@ -0,0 +1,53 @@
<?php
namespace app\adminapi\logic\community;
use app\common\logic\BaseLogic;
use app\common\model\community\CommunityTag;
class CommunityTagLogic extends BaseLogic
{
public static function add(array $params)
{
CommunityTag::create([
'name' => $params['name'],
'icon' => $params['icon'] ?? '',
'sort' => $params['sort'] ?? 0,
'is_hot' => $params['is_hot'] ?? 0,
'status' => $params['status'] ?? 1,
]);
}
public static function edit(array $params): bool
{
try {
CommunityTag::update([
'id' => $params['id'],
'name' => $params['name'],
'icon' => $params['icon'] ?? '',
'sort' => $params['sort'] ?? 0,
'is_hot' => $params['is_hot'] ?? 0,
'status' => $params['status'] ?? 1,
]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function delete(array $params)
{
CommunityTag::destroy($params['id']);
}
public static function detail($params): array
{
return CommunityTag::findOrEmpty($params['id'])->toArray();
}
public static function all(): array
{
return CommunityTag::where('status', 1)->order('sort', 'desc')->order('id', 'desc')->select()->toArray();
}
}