| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace App\Repositories;
- use App\Model\KeywordsHotModel;
- use Hyperf\Database\Model\Builder;
- use KZ2\Repositories\Model\Repository;
- use Psr\SimpleCache\CacheInterface;
- class KeywordsHotRepository extends Repository
- {
- public function model()
- {
- return KeywordsHotModel::class;
- }
- /**
- * 关键词热度排行10
- * @return mixed
- */
- public function hotTop()
- {
- $limitNum = 10;
- $ttl = 2 * 24 * 60 * 60;
- $cacheKey = 'keywords_hot_top_'. (string)$limitNum;
- $cacheRepo = make(CacheInterface::class);
- $result = $cacheRepo->remember($cacheKey, $ttl, function () use ($limitNum) {
- $result = [];
- $items = KeywordsHotModel::query()->orderBy('hot_degree', 'DESC')->take($limitNum)->get(['id', 'name', 'hot_degree']);
- if ($items->count()) {
- $result = $items->toArray();
- }
- return $result;
- });
- return $result;
- }
- }
|