mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-26 12:23:06 +08:00
Merge branch 'koogua/v1.6.0' into demo
This commit is contained in:
commit
a22e949170
@ -48,6 +48,12 @@ class HotQuestionList extends Cache
|
||||
return $this->handleQuestions($questions);
|
||||
}
|
||||
|
||||
$questions = $this->findFullyHotQuestions();
|
||||
|
||||
if ($questions->count() > 0) {
|
||||
return $this->handleQuestions($questions);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -102,6 +108,17 @@ class HotQuestionList extends Cache
|
||||
return $this->findHotQuestions($createTime, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $limit
|
||||
* @return ResultsetInterface|Resultset|QuestionModel[]
|
||||
*/
|
||||
protected function findFullyHotQuestions($limit = 10)
|
||||
{
|
||||
$createTime = 0;
|
||||
|
||||
return $this->findHotQuestions($createTime, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $createTime
|
||||
* @param int $limit
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
namespace App\Caches;
|
||||
|
||||
use App\Models\Article as ArticleModel;
|
||||
use App\Models\ArticleLike as ArticleLikeModel;
|
||||
use App\Models\Answer as AnswerModel;
|
||||
use App\Models\AnswerLike as AnswerLikeModel;
|
||||
use App\Repos\User as UserRepo;
|
||||
use Phalcon\Mvc\Model\Resultset;
|
||||
use Phalcon\Mvc\Model\ResultsetInterface;
|
||||
@ -37,10 +37,24 @@ class TopAnswererList extends Cache
|
||||
return $this->handleUsers($userIds);
|
||||
}
|
||||
|
||||
$randOwners = $this->findRandArticleOwners();
|
||||
$rankings = $this->findMonthlyAuthorRankings();
|
||||
|
||||
if ($randOwners->count() > 0) {
|
||||
$userIds = kg_array_column($randOwners->toArray(), 'owner_id');
|
||||
if ($rankings->count() > 0) {
|
||||
$userIds = kg_array_column($rankings->toArray(), 'author_id');
|
||||
return $this->handleUsers($userIds);
|
||||
}
|
||||
|
||||
$rankings = $this->findYearlyAuthorRankings();
|
||||
|
||||
if ($rankings->count() > 0) {
|
||||
$userIds = kg_array_column($rankings->toArray(), 'author_id');
|
||||
return $this->handleUsers($userIds);
|
||||
}
|
||||
|
||||
$rankings = $this->findFullyAuthorRankings();
|
||||
|
||||
if ($rankings->count() > 0) {
|
||||
$userIds = kg_array_column($rankings->toArray(), 'author_id');
|
||||
return $this->handleUsers($userIds);
|
||||
}
|
||||
|
||||
@ -73,23 +87,53 @@ class TopAnswererList extends Cache
|
||||
* @param int $limit
|
||||
* @return ResultsetInterface|Resultset
|
||||
*/
|
||||
protected function findRandArticleOwners($limit = 10)
|
||||
protected function findWeeklyAuthorRankings($limit = 10)
|
||||
{
|
||||
return ArticleModel::query()
|
||||
->columns(['owner_id'])
|
||||
->orderBy('RAND()')
|
||||
->limit($limit)
|
||||
->execute();
|
||||
$createTime = strtotime('monday this week');
|
||||
|
||||
return $this->findAuthorRankings($createTime, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $limit
|
||||
* @return ResultsetInterface|Resultset
|
||||
*/
|
||||
protected function findWeeklyAuthorRankings($limit = 10)
|
||||
protected function findMonthlyAuthorRankings($limit = 10)
|
||||
{
|
||||
$createTime = strtotime('monday this week');
|
||||
$createTime = strtotime(date('Y-m-01'));
|
||||
|
||||
return $this->findAuthorRankings($createTime, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $limit
|
||||
* @return ResultsetInterface|Resultset
|
||||
*/
|
||||
protected function findYearlyAuthorRankings($limit = 10)
|
||||
{
|
||||
$createTime = strtotime(date('Y-01-01'));
|
||||
|
||||
return $this->findAuthorRankings($createTime, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $limit
|
||||
* @return ResultsetInterface|Resultset
|
||||
*/
|
||||
protected function findFullyAuthorRankings($limit = 10)
|
||||
{
|
||||
$createTime = 0;
|
||||
|
||||
return $this->findAuthorRankings($createTime, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $createTime
|
||||
* @param int $limit
|
||||
* @return ResultsetInterface|Resultset
|
||||
*/
|
||||
protected function findAuthorRankings($createTime, $limit = 10)
|
||||
{
|
||||
$columns = [
|
||||
'author_id' => 'a.owner_id',
|
||||
'like_count' => 'count(al.user_id)',
|
||||
@ -97,8 +141,8 @@ class TopAnswererList extends Cache
|
||||
|
||||
return $this->modelsManager->createBuilder()
|
||||
->columns($columns)
|
||||
->addFrom(ArticleLikeModel::class, 'al')
|
||||
->join(ArticleModel::class, 'al.article_id = a.id', 'a')
|
||||
->addFrom(AnswerLikeModel::class, 'al')
|
||||
->join(AnswerModel::class, 'al.answer_id = a.id', 'a')
|
||||
->where('al.create_time > :create_time:', ['create_time' => $createTime])
|
||||
->groupBy('author_id')
|
||||
->orderBy('like_count DESC')
|
||||
|
@ -1,27 +1,24 @@
|
||||
{% if questions|length > 0 %}
|
||||
{% if answerers|length > 0 %}
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">热门问题</div>
|
||||
<div class="layui-card-header">热门答主</div>
|
||||
<div class="layui-card-body">
|
||||
{% for item in questions %}
|
||||
{% set url = url({'for':'home.question.show','id':item.id}) %}
|
||||
{% set rank = loop.index %}
|
||||
<div class="sidebar-rank-card">
|
||||
<div class="rank">
|
||||
{% if rank == 1 %}
|
||||
<span class="layui-badge layui-bg-red">{{ rank }}</span>
|
||||
{% elseif rank == 2 %}
|
||||
<span class="layui-badge layui-bg-blue">{{ rank }}</span>
|
||||
{% elseif rank == 3 %}
|
||||
<span class="layui-badge layui-bg-green">{{ rank }}</span>
|
||||
{% else %}
|
||||
<span class="layui-badge layui-bg-gray">{{ rank }}</span>
|
||||
{% endif %}
|
||||
<div class="sidebar-user-list">
|
||||
{% for author in answerers %}
|
||||
{% set author.title = author.title ? author.title : '暂露头角' %}
|
||||
{% set author_url = url({'for':'home.user.show','id':author.id}) %}
|
||||
<div class="sidebar-user-card">
|
||||
<div class="avatar">
|
||||
<img src="{{ author.avatar }}!avatar_160" alt="{{ author.name }}">
|
||||
</div>
|
||||
<div class="info">
|
||||
<div class="name layui-elip">
|
||||
<a href="{{ author_url }}" title="{{ author.about }}" target="_blank">{{ author.name }}</a>
|
||||
</div>
|
||||
<div class="title layui-elip">{{ author.title }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="title">
|
||||
<a href="{{ url }}">{{ item.title }}</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
@ -6,7 +6,7 @@ layui.use(['jquery', 'helper'], function () {
|
||||
var $questionList = $('#question-list');
|
||||
var $sidebarMyTags = $('#sidebar-my-tags');
|
||||
var $sidebarHotQuestions = $('#sidebar-hot-questions');
|
||||
var $sidebarTopAnswerers = $('#sidebar-top-answerer');
|
||||
var $sidebarTopAnswerers = $('#sidebar-top-answerers');
|
||||
|
||||
if ($questionList.length > 0) {
|
||||
helper.ajaxLoadHtml($questionList.data('url'), $questionList.attr('id'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user