no message
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?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\lists;
|
||||
|
||||
use app\common\enum\user\AccountLogEnum;
|
||||
use app\common\model\user\UserAccountLog;
|
||||
|
||||
|
||||
/**
|
||||
* 账户流水列表
|
||||
* Class AccountLogLists
|
||||
* @package app\shopapi\lists
|
||||
*/
|
||||
class AccountLogLists extends BaseApiDataLists
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 搜索条件
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 14:43
|
||||
*/
|
||||
public function queryWhere()
|
||||
{
|
||||
// 指定用户
|
||||
$where[] = ['user_id', '=', $this->userId];
|
||||
|
||||
// 用户余额明细
|
||||
if (isset($this->params['type']) && $this->params['type'] == 'um') {
|
||||
$where[] = ['change_type', 'in', AccountLogEnum::getUserMoneyChangeType()];
|
||||
}
|
||||
|
||||
// 用户积分明细
|
||||
if (isset($this->params['type']) && $this->params['type'] == 'up') {
|
||||
$where[] = ['change_type', 'in', AccountLogEnum::getUserPointsChangeType()];
|
||||
}
|
||||
|
||||
// 变动类型
|
||||
if (!empty($this->params['action'])) {
|
||||
$where[] = ['action', '=', $this->params['action']];
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 14:43
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$field = 'change_type,change_amount,action,create_time,remark';
|
||||
$lists = UserAccountLog::field($field)
|
||||
->where($this->queryWhere())
|
||||
->order('id', 'desc')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['type_desc'] = AccountLogEnum::getChangeTypeDesc($item['change_type']);
|
||||
$symbol = $item['action'] == AccountLogEnum::DEC ? '-' : '+';
|
||||
$item['change_amount_desc'] = $symbol . $item['change_amount'];
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 14:44
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return UserAccountLog::where($this->queryWhere())->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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\lists;
|
||||
|
||||
use app\common\lists\BaseDataLists;
|
||||
|
||||
abstract class BaseApiDataLists extends BaseDataLists
|
||||
{
|
||||
protected array $userInfo = [];
|
||||
protected int $userId = 0;
|
||||
|
||||
public string $export;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if (isset($this->request->userId)) {
|
||||
$this->userId = (int) $this->request->userId;
|
||||
}
|
||||
if (isset($this->request->userInfo) && is_array($this->request->userInfo)) {
|
||||
$this->userInfo = $this->request->userInfo;
|
||||
}
|
||||
$this->export = $this->request->get('export', '');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?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\lists\article;
|
||||
|
||||
use app\api\lists\BaseApiDataLists;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\model\article\Article;
|
||||
|
||||
/**
|
||||
* 文章收藏列表
|
||||
* Class ArticleCollectLists
|
||||
* @package app\api\lists\article
|
||||
*/
|
||||
class ArticleCollectLists extends BaseApiDataLists
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取收藏列表
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 16:29
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$field = "c.id,c.article_id,a.title,a.image,a.desc,a.is_show,
|
||||
a.click_virtual, a.click_actual,a.create_time, c.create_time as collect_time";
|
||||
|
||||
$lists = (new Article())->alias('a')
|
||||
->join('article_collect c', 'c.article_id = a.id')
|
||||
->field($field)
|
||||
->where([
|
||||
'c.user_id' => $this->userId,
|
||||
'c.status' => YesNoEnum::YES,
|
||||
'a.is_show' => YesNoEnum::YES,
|
||||
])
|
||||
->order(['sort' => 'desc', 'c.id' => 'desc'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->append(['click'])
|
||||
->hidden(['click_virtual', 'click_actual'])
|
||||
->select()->toArray();
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['collect_time'] = date('Y-m-d H:i', $item['collect_time']);
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取收藏数量
|
||||
* @return int
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 16:29
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return (new Article())->alias('a')
|
||||
->join('article_collect c', 'c.article_id = a.id')
|
||||
->where([
|
||||
'c.user_id' => $this->userId,
|
||||
'c.status' => YesNoEnum::YES,
|
||||
'a.is_show' => YesNoEnum::YES,
|
||||
])
|
||||
->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<?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\lists\article;
|
||||
|
||||
use app\api\lists\BaseApiDataLists;
|
||||
use app\api\logic\ArticleLogic;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\article\ArticleCollect;
|
||||
use app\common\service\article\ArticleImageProxyService;
|
||||
use app\common\model\user\UserChannelConfig;
|
||||
|
||||
|
||||
/**
|
||||
* 文章列表
|
||||
* Class ArticleLists
|
||||
* @package app\api\lists\article
|
||||
*/
|
||||
class ArticleLists extends BaseApiDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 搜索条件
|
||||
* @return \string[][]
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:54
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['cid']
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 自定查询条件
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/10/25 16:53
|
||||
*/
|
||||
public function queryWhere()
|
||||
{
|
||||
$where[] = ['is_show', '=', 1];
|
||||
if (!empty($this->params['keyword'])) {
|
||||
$where[] = ['title', 'like', '%' . $this->params['keyword'] . '%'];
|
||||
}
|
||||
if (isset($this->params['is_recommend']) && $this->params['is_recommend'] !== '') {
|
||||
$where[] = ['is_recommend', '=', $this->params['is_recommend']];
|
||||
}
|
||||
if (!empty($this->params['is_mychannel'])) {
|
||||
if ($this->userId) {
|
||||
$config = UserChannelConfig::where('user_id', $this->userId)->findOrEmpty();
|
||||
$channelIds = [];
|
||||
if (!$config->isEmpty()) {
|
||||
$raw = $config['channel_ids'];
|
||||
if (is_string($raw)) {
|
||||
$channelIds = json_decode($raw, true) ?: [];
|
||||
} elseif (is_array($raw)) {
|
||||
$channelIds = $raw;
|
||||
}
|
||||
}
|
||||
if (!empty($channelIds)) {
|
||||
$where[] = ['cid', 'in', $channelIds];
|
||||
} else {
|
||||
$where[] = ['id', '=', 0];
|
||||
}
|
||||
} else {
|
||||
$where[] = ['id', '=', 0];
|
||||
}
|
||||
}
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取文章列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:55
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$orderRaw = 'published_at desc, id desc';
|
||||
$sortType = $this->params['sort'] ?? 'default';
|
||||
$cid = (int) ($this->params['cid'] ?? 0);
|
||||
// 最新排序
|
||||
if ($sortType == 'new') {
|
||||
$orderRaw = 'published_at desc, id desc';
|
||||
}
|
||||
// 最热排序
|
||||
if ($sortType == 'hot') {
|
||||
$orderRaw = 'click_actual + click_virtual desc, id desc';
|
||||
}
|
||||
|
||||
$field = 'id,cid,title,desc,content,author,image,is_video,duration,video_url,click_virtual,click_actual,create_time,ext';
|
||||
$result = Article::field($field)
|
||||
->withCount(['comments' => 'comment_count'])
|
||||
->where($this->queryWhere())
|
||||
->where($this->searchWhere)
|
||||
->orderRaw($orderRaw)
|
||||
->append(['click'])
|
||||
->hidden(['click_virtual', 'click_actual'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->select()->toArray();
|
||||
|
||||
$articleIds = array_column($result, 'id');
|
||||
|
||||
$collectIds = ArticleCollect::where(['user_id' => $this->userId, 'status' => YesNoEnum::YES])
|
||||
->whereIn('article_id', $articleIds)
|
||||
->column('article_id');
|
||||
|
||||
foreach ($result as &$item) {
|
||||
$item['collect'] = in_array($item['id'], $collectIds);
|
||||
if (!empty($item['content'])) {
|
||||
$item['content'] = mb_substr(strip_tags($item['content']), 0, 100);
|
||||
}
|
||||
$item['translated_content'] = $cid === 22 ? ArticleLogic::getCachedTranslatedContent($item) : '';
|
||||
$item = ArticleImageProxyService::rewriteArticlePayload($item);
|
||||
unset($item['ext']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取文章数量
|
||||
* @return int
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:55
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Article::where($this->searchWhere)
|
||||
->where($this->queryWhere())
|
||||
->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\lists\community;
|
||||
|
||||
use app\api\lists\BaseApiDataLists;
|
||||
use app\common\model\community\CommunityPost;
|
||||
use app\common\model\community\CommunityFollow;
|
||||
use app\common\model\community\CommunityTag;
|
||||
use app\common\model\user\User;
|
||||
use app\common\enum\user\AccountLogEnum;
|
||||
use app\common\service\ai\AiService;
|
||||
use app\common\service\VipService;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
use app\common\model\community\CommunityLike;
|
||||
|
||||
class CommunityPostLists extends BaseApiDataLists
|
||||
{
|
||||
private const LIUHE_TAGS = ['旧澳六合', '新澳六合'];
|
||||
|
||||
private function buildQuery()
|
||||
{
|
||||
$query = CommunityPost::where($this->queryWhere());
|
||||
$trumpTagId = (int) CommunityTag::where('name', '特朗普')->value('id');
|
||||
if ($trumpTagId > 0) {
|
||||
$query->whereRaw(
|
||||
"NOT (id IN (SELECT post_id FROM la_community_post_tag WHERE tag_id = {$trumpTagId})" .
|
||||
" AND TRIM(IFNULL(content, '')) = ''" .
|
||||
" AND IFNULL(images, '[]') <> '[]')"
|
||||
);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function queryWhere(): array
|
||||
{
|
||||
$where = [['status', '=', 1]];
|
||||
|
||||
if (!empty($this->params['post_type'])) {
|
||||
$where[] = ['post_type', '=', $this->params['post_type']];
|
||||
}
|
||||
if (!empty($this->params['user_id'])) {
|
||||
$where[] = ['user_id', '=', $this->params['user_id']];
|
||||
}
|
||||
if (!empty($this->params['follow']) && $this->userId) {
|
||||
$followUserIds = CommunityFollow::where('user_id', $this->userId)
|
||||
->column('follow_user_id');
|
||||
if ($followUserIds) {
|
||||
$where[] = ['user_id', 'in', $followUserIds];
|
||||
} else {
|
||||
$where[] = ['id', '=', 0];
|
||||
}
|
||||
}
|
||||
if (!empty($this->params['tag_id'])) {
|
||||
$postIds = Db::name('community_post_tag')
|
||||
->where('tag_id', $this->params['tag_id'])
|
||||
->column('post_id');
|
||||
if ($postIds) {
|
||||
$where[] = ['id', 'in', $postIds];
|
||||
} else {
|
||||
$where[] = ['id', '=', 0];
|
||||
}
|
||||
}
|
||||
return $where;
|
||||
}
|
||||
|
||||
private function isLiuhePost(array $tags, array $ext = []): bool
|
||||
{
|
||||
foreach (self::LIUHE_TAGS as $tag) {
|
||||
if (in_array($tag, $tags, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$lotteryKey = (string) ($ext['lottery_key'] ?? '');
|
||||
return in_array($lotteryKey, ['a6', 'xa6'], true);
|
||||
}
|
||||
|
||||
private function getLiuheAnalysisContent(array $ext): string
|
||||
{
|
||||
if (($ext['lottery_analysis_source'] ?? '') !== 'image_only') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return (string) ($ext['lottery_analysis_content'] ?? '');
|
||||
}
|
||||
|
||||
public function lists(): array
|
||||
{
|
||||
$list = $this->buildQuery()
|
||||
->field('id,origin_id,user_id,content,images,ext,post_type,match_id,is_paid,price_points,paid_count,view_count,like_count,comment_count,share_count,is_top,is_hot,is_recommend,create_time')
|
||||
->orderRaw('is_top DESC, is_hot DESC, create_time DESC')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 批量预加载:用户、标签、翻译状态
|
||||
$postIds = array_column($list, 'id');
|
||||
$userIds = array_unique(array_column($list, 'user_id'));
|
||||
|
||||
// 批量查询用户 → id 为 key
|
||||
$userMap = [];
|
||||
if ($userIds) {
|
||||
$users = User::field('id,sn,nickname,avatar,sex')->whereIn('id', $userIds)->select()->toArray();
|
||||
foreach ($users as $u) {
|
||||
$userMap[$u['id']] = $u;
|
||||
}
|
||||
}
|
||||
|
||||
// 批量查询帖子标签 → post_id => [tag_name, ...]
|
||||
$tagMap = [];
|
||||
if ($postIds) {
|
||||
$postTags = Db::name('community_post_tag')->whereIn('post_id', $postIds)->select()->toArray();
|
||||
$tagIdsByPost = [];
|
||||
foreach ($postTags as $pt) {
|
||||
$tagIdsByPost[$pt['post_id']][] = $pt['tag_id'];
|
||||
}
|
||||
$allTagIds = array_unique(array_column($postTags, 'tag_id'));
|
||||
$tagNames = $allTagIds ? CommunityTag::whereIn('id', $allTagIds)->column('name', 'id') : [];
|
||||
foreach ($tagIdsByPost as $pid => $tids) {
|
||||
$tagMap[$pid] = array_values(array_intersect_key($tagNames, array_flip($tids)));
|
||||
}
|
||||
}
|
||||
|
||||
// 已付费翻译的帖子ID集合(带缓存)
|
||||
$translatedPostIds = [];
|
||||
if ($this->userId) {
|
||||
$translatedPostIds = self::getUserTranslatedPostIds($this->userId);
|
||||
}
|
||||
|
||||
// 批量查询已购买的付费帖子ID
|
||||
$purchasedPostIds = [];
|
||||
if ($this->userId && $postIds) {
|
||||
$purchasedPostIds = Db::name('user_account_log')
|
||||
->where('user_id', $this->userId)
|
||||
->where('change_type', AccountLogEnum::UP_DEC_PURCHASE_POST)
|
||||
->whereIn('relation_id', $postIds)
|
||||
->column('relation_id');
|
||||
}
|
||||
|
||||
// VIP权益:解锁帖子免费、翻译免费
|
||||
$vipUnlockFree = $this->userId ? VipService::hasUnlockFree($this->userId) : false;
|
||||
$vipTranslateFree = $this->userId ? VipService::hasTranslateFree($this->userId) : false;
|
||||
|
||||
foreach ($list as &$item) {
|
||||
$ext = $item['ext'] ?? '';
|
||||
$ext = $ext ? (is_string($ext) ? json_decode($ext, true) : $ext) : [];
|
||||
|
||||
// 判断是否已解锁(自己发的 或 已购买 或 VIP解锁免费)
|
||||
$item['is_unlocked'] = 0;
|
||||
if ($item['is_paid']) {
|
||||
if ($item['user_id'] == $this->userId || in_array($item['id'], $purchasedPostIds) || $vipUnlockFree) {
|
||||
$item['is_unlocked'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 付费帖子:未解锁 → 截断内容并隐藏全文
|
||||
if ($item['is_paid'] && !$item['is_unlocked']) {
|
||||
$item['content_short'] = mb_substr($item['content'], 0, 20) . '...';
|
||||
$item['content'] = $item['content_short'];
|
||||
} elseif (mb_strlen($item['content']) > 120) {
|
||||
$item['content_short'] = mb_substr($item['content'], 0, 120) . '...';
|
||||
} else {
|
||||
$item['content_short'] = $item['content'];
|
||||
}
|
||||
|
||||
$item['user'] = $userMap[$item['user_id']] ?? null;
|
||||
$item['tags'] = $tagMap[$item['id']] ?? [];
|
||||
$item['source_url'] = $ext['url'] ?? '';
|
||||
$item['is_liked'] = false;
|
||||
if ($this->userId) {
|
||||
$item['is_liked'] = CommunityLike::where([
|
||||
'user_id' => $this->userId,
|
||||
'target_id' => $item['id'],
|
||||
'target_type' => 1
|
||||
])->count() > 0;
|
||||
}
|
||||
|
||||
$item['translated_content'] = '';
|
||||
$isTrumpPost = in_array('特朗普', $item['tags']);
|
||||
$isLiuhePost = $this->isLiuhePost($item['tags'], $ext);
|
||||
if ($isTrumpPost) {
|
||||
if (empty($ext['translated_content']) && !empty($item['content'])) {
|
||||
$result = AiService::translateCommunityPost($item['content']);
|
||||
if (!empty($result['success']) && !empty($result['content'])) {
|
||||
$ext['translated_content'] = trim($result['content']);
|
||||
CommunityPost::where('id', $item['id'])->update([
|
||||
'ext' => json_encode($ext, JSON_UNESCAPED_UNICODE),
|
||||
'update_time' => time(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
$item['translated_content'] = $ext['translated_content'] ?? '';
|
||||
} elseif ((!empty($item['origin_id']) || $isLiuhePost) && (in_array($item['id'], $translatedPostIds) || $vipTranslateFree)) {
|
||||
$item['translated_content'] = $isLiuhePost
|
||||
? $this->getLiuheAnalysisContent($ext)
|
||||
: (string) ($ext['translated_content'] ?? '');
|
||||
}
|
||||
unset($item['ext']);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return $this->buildQuery()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户已付费翻译的帖子ID集合(优先缓存)
|
||||
*/
|
||||
public static function getUserTranslatedPostIds(int $userId): array
|
||||
{
|
||||
$cacheKey = 'translate_paid:' . $userId;
|
||||
$postIds = Cache::get($cacheKey);
|
||||
if ($postIds !== null) {
|
||||
return $postIds;
|
||||
}
|
||||
|
||||
$remarks = Db::name('user_account_log')
|
||||
->where('user_id', $userId)
|
||||
->where('change_type', AccountLogEnum::UP_DEC_TRANSLATE_POST)
|
||||
->column('remark');
|
||||
|
||||
$postIds = [];
|
||||
foreach ($remarks as $remark) {
|
||||
if (preg_match('/(?:翻译|分析)帖子#(\d+)/', $remark, $m)) {
|
||||
$postIds[] = (int) $m[1];
|
||||
}
|
||||
}
|
||||
|
||||
Cache::set($cacheKey, $postIds, 3600);
|
||||
return $postIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 翻译扣分后刷新缓存:追加新帖子ID
|
||||
*/
|
||||
public static function refreshTranslateCache(int $userId, int $postId): void
|
||||
{
|
||||
$cacheKey = 'translate_paid:' . $userId;
|
||||
$postIds = Cache::get($cacheKey);
|
||||
if (is_array($postIds)) {
|
||||
if (!in_array($postId, $postIds)) {
|
||||
$postIds[] = $postId;
|
||||
Cache::set($cacheKey, $postIds, 3600);
|
||||
}
|
||||
} else {
|
||||
Cache::delete($cacheKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\lists\match;
|
||||
|
||||
use app\api\lists\BaseApiDataLists;
|
||||
use app\common\model\match\MatchEvent;
|
||||
use app\common\model\league\League;
|
||||
|
||||
class MatchLists extends BaseApiDataLists
|
||||
{
|
||||
private function queryWhere(): array
|
||||
{
|
||||
$where = [['is_show', '=', 1]];
|
||||
if (!empty($this->params['sport_type'])) {
|
||||
$where[] = ['sport_type', '=', $this->params['sport_type']];
|
||||
} else {
|
||||
$validSportTypes = League::where('is_show', 1)
|
||||
->where('type', 'sport')
|
||||
->where('sport_type', '>', 0)
|
||||
->column('sport_type');
|
||||
if (!empty($validSportTypes)) {
|
||||
$where[] = ['sport_type', 'in', $validSportTypes];
|
||||
}
|
||||
}
|
||||
if (!empty($this->params['league_name'])) {
|
||||
$where[] = ['league_name', '=', $this->params['league_name']];
|
||||
} elseif (empty($this->params['sport_type'])) {
|
||||
$validLeagues = League::where('is_show', 1)
|
||||
->where('type', 'league')
|
||||
->column('label');
|
||||
if (!empty($validLeagues)) {
|
||||
$where[] = ['league_name', 'in', $validLeagues];
|
||||
}
|
||||
}
|
||||
if (isset($this->params['status']) && $this->params['status'] !== '') {
|
||||
$where[] = ['status', '=', $this->params['status']];
|
||||
}
|
||||
return $where;
|
||||
}
|
||||
|
||||
public function lists(): array
|
||||
{
|
||||
return MatchEvent::where($this->queryWhere())
|
||||
->field('id,league_name,league_icon,home_team,home_icon,home_score,away_team,away_icon,away_score,sport_type,status,match_time,current_minute,half_score,home_odds,draw_odds,away_odds,home_corner,away_corner,home_yellow,away_yellow,home_red,away_red,is_hot')
|
||||
->orderRaw('FIELD(status, 1, 0, 3, 2), CASE WHEN status = 2 THEN -match_time ELSE match_time END ASC')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return MatchEvent::where($this->queryWhere())->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?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\lists\recharge;
|
||||
|
||||
use app\api\lists\BaseApiDataLists;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\model\recharge\RechargeOrder;
|
||||
|
||||
|
||||
/**
|
||||
* 充值记录列表
|
||||
* Class RechargeLists
|
||||
* @package app\api\lists\recharge
|
||||
*/
|
||||
class RechargeLists extends BaseApiDataLists
|
||||
{
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2023/2/23 18:43
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$lists = RechargeOrder::field('order_amount,create_time')
|
||||
->where([
|
||||
'user_id' => $this->userId,
|
||||
'pay_status' => PayEnum::ISPAID
|
||||
])
|
||||
->order('id', 'desc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach($lists as &$item) {
|
||||
$item['tips'] = '充值' . format_amount($item['order_amount']) . '元';
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author 段誉
|
||||
* @date 2023/2/23 18:43
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return RechargeOrder::where([
|
||||
'user_id' => $this->userId,
|
||||
'pay_status' => PayEnum::ISPAID
|
||||
])
|
||||
->count();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user