feat: rank community recommendation feed

This commit is contained in:
hajimi
2026-08-02 18:39:36 +08:00
parent 3fc4703986
commit 51cd9898a7
9 changed files with 122 additions and 3 deletions
@@ -18,6 +18,7 @@ use app\common\model\community\CommunityLike;
class CommunityPostLists extends BaseApiDataLists
{
private const LIUHE_TAGS = ['旧澳六合', '新澳六合'];
private const FEED_RECOMMEND = 'recommend';
private function buildQuery()
{
@@ -94,8 +95,8 @@ class CommunityPostLists extends BaseApiDataLists
public function lists(): array
{
$list = $this->buildQuery()
->field('id,origin_id,user_id,content,images,ext,post_type,category_id,match_id,is_paid,price_points,paid_count,view_count,like_count,comment_count,share_count,is_top,is_hot,is_recommend,is_topic,create_time')
->orderRaw('is_top DESC, is_hot DESC, create_time DESC')
->field('id,origin_id,user_id,content,images,ext,post_type,category_id,match_id,is_paid,price_points,paid_count,view_count,like_count,comment_count,share_count,is_top,is_hot,is_recommend,is_topic,sort,create_time')
->orderRaw($this->getOrderSql())
->limit($this->limitOffset, $this->limitLength)
->select()
->toArray();
@@ -214,6 +215,15 @@ class CommunityPostLists extends BaseApiDataLists
return $list;
}
private function getOrderSql(): string
{
if (($this->params['feed'] ?? '') === self::FEED_RECOMMEND) {
return 'is_recommend DESC, sort DESC, create_time DESC, id DESC';
}
return 'is_top DESC, is_hot DESC, create_time DESC, id DESC';
}
public function count(): int
{
return $this->buildQuery()->count();