1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-24 04:01:31 +08:00
course-tencent-cloud/app/Services/Logic/Article/RelatedArticleList.php
koogua 0336a54911 1.源文件增加版权信息
2.群组状态和课程协同
2021-06-13 15:49:47 +08:00

39 lines
817 B
PHP

<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Services\Logic\Article;
use App\Caches\TaggedArticleList as TaggedArticleListCache;
use App\Services\Logic\ArticleTrait;
use App\Services\Logic\Service as LogicService;
class RelatedArticleList extends LogicService
{
use ArticleTrait;
public function handle($id)
{
$article = $this->checkArticle($id);
if (empty($article->tags)) return [];
$tagIds = kg_array_column($article->tags, 'id');
$randKey = array_rand($tagIds);
$tagId = $tagIds[$randKey];
$cache = new TaggedArticleListCache();
$result = $cache->get($tagId);
return $result ?: [];
}
}