mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-29 22:01:38 +08:00
优化排序条件,改善分页重复问题
This commit is contained in:
parent
5a061ad9fb
commit
56bbb7d6fe
@ -56,10 +56,10 @@ class Answer extends Repository
|
||||
|
||||
switch ($sort) {
|
||||
case 'popular':
|
||||
$orderBy = 'like_count DESC';
|
||||
$orderBy = 'like_count DESC, id DESC';
|
||||
break;
|
||||
case 'accepted':
|
||||
$orderBy = 'accepted DESC, like_count DESC';
|
||||
$orderBy = 'accepted DESC, id DESC';
|
||||
break;
|
||||
case 'oldest':
|
||||
$orderBy = 'id ASC';
|
||||
|
@ -107,10 +107,10 @@ class Article extends Repository
|
||||
|
||||
switch ($sort) {
|
||||
case 'like':
|
||||
$orderBy = 'like_count DESC';
|
||||
$orderBy = 'like_count DESC, id DESC';
|
||||
break;
|
||||
case 'popular':
|
||||
$orderBy = 'score DESC';
|
||||
$orderBy = 'score DESC, id DESC';
|
||||
break;
|
||||
case 'oldest':
|
||||
$orderBy = 'id ASC';
|
||||
|
@ -66,7 +66,7 @@ class Comment extends Repository
|
||||
|
||||
switch ($sort) {
|
||||
case 'popular':
|
||||
$orderBy = 'like_count DESC';
|
||||
$orderBy = 'like_count DESC, id DESC';
|
||||
break;
|
||||
case 'oldest':
|
||||
$orderBy = 'id ASC';
|
||||
|
@ -119,13 +119,13 @@ class Course extends Repository
|
||||
|
||||
switch ($sort) {
|
||||
case 'score':
|
||||
$orderBy = 'score DESC';
|
||||
$orderBy = 'score DESC, id DESC';
|
||||
break;
|
||||
case 'rating':
|
||||
$orderBy = 'rating DESC';
|
||||
$orderBy = 'rating DESC, id DESC';
|
||||
break;
|
||||
case 'popular':
|
||||
$orderBy = 'user_count DESC';
|
||||
$orderBy = 'user_count DESC, id DESC';
|
||||
break;
|
||||
case 'oldest':
|
||||
$orderBy = 'id ASC';
|
||||
|
@ -50,7 +50,7 @@ class PointGift extends Repository
|
||||
|
||||
switch ($sort) {
|
||||
case 'popular':
|
||||
$orderBy = 'redeem_count DESC';
|
||||
$orderBy = 'redeem_count DESC, id DESC';
|
||||
break;
|
||||
case 'oldest':
|
||||
$orderBy = 'id ASC';
|
||||
|
@ -100,10 +100,10 @@ class Question extends Repository
|
||||
|
||||
switch ($sort) {
|
||||
case 'active':
|
||||
$orderBy = 'last_reply_time DESC';
|
||||
$orderBy = 'last_reply_time DESC, id DESC';
|
||||
break;
|
||||
case 'score':
|
||||
$orderBy = 'score DESC';
|
||||
$orderBy = 'score DESC, id DESC';
|
||||
break;
|
||||
case 'oldest':
|
||||
$orderBy = 'id ASC';
|
||||
|
@ -45,8 +45,14 @@ class Slide extends Repository
|
||||
}
|
||||
|
||||
switch ($sort) {
|
||||
case 'oldest':
|
||||
$orderBy = 'id ASC';
|
||||
break;
|
||||
case 'latest':
|
||||
$orderBy = 'id DESC';
|
||||
break;
|
||||
default:
|
||||
$orderBy = 'priority ASC';
|
||||
$orderBy = 'priority ASC, id DESC';
|
||||
break;
|
||||
}
|
||||
|
||||
|
95
app/Repos/Task.php
Normal file
95
app/Repos/Task.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
||||
* @license https://opensource.org/licenses/GPL-2.0
|
||||
* @link https://www.koogua.com
|
||||
*/
|
||||
|
||||
namespace App\Repos;
|
||||
|
||||
use App\Library\Paginator\Adapter\QueryBuilder as PagerQueryBuilder;
|
||||
use App\Models\Task as TaskModel;
|
||||
use Phalcon\Mvc\Model;
|
||||
use Phalcon\Mvc\Model\Resultset;
|
||||
use Phalcon\Mvc\Model\ResultsetInterface;
|
||||
|
||||
class Task extends Repository
|
||||
{
|
||||
|
||||
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
|
||||
{
|
||||
$builder = $this->modelsManager->createBuilder();
|
||||
|
||||
$builder->from(TaskModel::class);
|
||||
|
||||
$builder->where('1 = 1');
|
||||
|
||||
if (!empty($where['id'])) {
|
||||
$builder->andWhere('id = :id:', ['id' => $where['id']]);
|
||||
}
|
||||
|
||||
if (!empty($where['item_id'])) {
|
||||
$builder->andWhere('item_id = :item_id:', ['item_id' => $where['item_id']]);
|
||||
}
|
||||
|
||||
if (!empty($where['item_type'])) {
|
||||
$builder->andWhere('item_type = :item_type:', ['item_type' => $where['item_type']]);
|
||||
}
|
||||
|
||||
if (!empty($where['status'])) {
|
||||
$builder->andWhere('status = :status:', ['status' => $where['status']]);
|
||||
}
|
||||
|
||||
if (isset($where['locked'])) {
|
||||
$builder->andWhere('locked = :locked:', ['locked' => $where['locked']]);
|
||||
}
|
||||
|
||||
switch ($sort) {
|
||||
case 'oldest':
|
||||
$orderBy = 'id ASC';
|
||||
break;
|
||||
case 'latest':
|
||||
$orderBy = 'id DESC';
|
||||
break;
|
||||
default:
|
||||
$orderBy = 'priority ASC, id ASC';
|
||||
break;
|
||||
}
|
||||
|
||||
$builder->orderBy($orderBy);
|
||||
|
||||
$pager = new PagerQueryBuilder([
|
||||
'builder' => $builder,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
]);
|
||||
|
||||
return $pager->paginate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return TaskModel|Model|bool
|
||||
*/
|
||||
public function findById($id)
|
||||
{
|
||||
return TaskModel::findFirst([
|
||||
'conditions' => 'id = :id:',
|
||||
'bind' => ['id' => $id],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @param array|string $columns
|
||||
* @return ResultsetInterface|Resultset|TaskModel[]
|
||||
*/
|
||||
public function findByIds($ids, $columns = '*')
|
||||
{
|
||||
return TaskModel::query()
|
||||
->columns($columns)
|
||||
->inWhere('id', $ids)
|
||||
->execute();
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user