feat: rank community recommendation feed
This commit is contained in:
@@ -61,6 +61,16 @@ class CommunityPostController extends BaseAdminController
|
||||
return $this->fail(CommunityPostLogic::getError());
|
||||
}
|
||||
|
||||
public function setSort()
|
||||
{
|
||||
$params = (new CommunityPostValidate())->post()->goCheck('sort');
|
||||
$result = CommunityPostLogic::setSort($params);
|
||||
if (true === $result) {
|
||||
return $this->success('设置成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(CommunityPostLogic::getError());
|
||||
}
|
||||
|
||||
public function setTopic()
|
||||
{
|
||||
$params = (new CommunityPostValidate())->post()->goCheck('topic');
|
||||
|
||||
@@ -92,6 +92,20 @@ class CommunityPostLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
public static function setSort(array $params): bool
|
||||
{
|
||||
try {
|
||||
CommunityPost::update([
|
||||
'id' => $params['id'],
|
||||
'sort' => (int) $params['sort'],
|
||||
]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function setTopic(array $params): bool
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -14,6 +14,7 @@ class CommunityPostValidate extends BaseValidate
|
||||
'is_top' => 'require|in:0,1',
|
||||
'is_hot' => 'require|in:0,1',
|
||||
'is_recommend' => 'require|in:0,1',
|
||||
'sort' => 'require|integer|egt:0|elt:1000000',
|
||||
'is_topic' => 'require|in:0,1',
|
||||
'category_id' => 'require|integer|egt:0|checkCategory',
|
||||
];
|
||||
@@ -53,6 +54,11 @@ class CommunityPostValidate extends BaseValidate
|
||||
return $this->only(['id', 'is_recommend']);
|
||||
}
|
||||
|
||||
public function sceneSort()
|
||||
{
|
||||
return $this->only(['id', 'sort']);
|
||||
}
|
||||
|
||||
public function sceneTopic()
|
||||
{
|
||||
return $this->only(['id', 'is_topic']);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user