1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-24 20:06:09 +08:00
course-tencent-cloud/app/Services/Logic/Question/RelatedQuestionList.php
2021-05-07 19:34:31 +08:00

34 lines
669 B
PHP

<?php
namespace App\Services\Logic\Question;
use App\Caches\TaggedQuestionList as TaggedQuestionListCache;
use App\Services\Logic\QuestionTrait;
use App\Services\Logic\Service as LogicService;
class RelatedQuestionList extends LogicService
{
use QuestionTrait;
public function handle($id)
{
$question = $this->checkQuestion($id);
if (empty($question->tags)) return [];
$tagIds = kg_array_column($question->tags, 'id');
$randKey = array_rand($tagIds);
$tagId = $tagIds[$randKey];
$cache = new TaggedQuestionListCache();
$result = $cache->get($tagId);
return $result ?: [];
}
}