94 lines
2.5 KiB
PHP
94 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace app\api\service;
|
|
|
|
use app\common\repository\SkitsLibraryReposotpry;
|
|
|
|
class SearchService
|
|
{
|
|
|
|
protected $skitsLibraryReposotpry;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->skitsLibraryReposotpry = new SkitsLibraryReposotpry;
|
|
}
|
|
|
|
/**
|
|
* 搜索首页过程 function
|
|
*
|
|
* @author dotdotdot <6383846@qq.com>
|
|
* @date 2022-08-10
|
|
* @return array
|
|
*/
|
|
public function index()
|
|
{
|
|
$skitsLibraryLatestFields = ['id', 'cover', 'name'];
|
|
$skitsLibraryLatestOrder = ['addtime' => 'desc'];
|
|
$skitsLibraryLatestLimit = 5;
|
|
$latestData = $this->skitsLibraryReposotpry->selectByRand($skitsLibraryLatestFields, $skitsLibraryLatestOrder, $skitsLibraryLatestLimit);
|
|
|
|
$skitsLibraryPopularFields = ['id', 'cover', 'name', 'description'];
|
|
$skitsLibraryPopularOrder = ['sort' => 'desc'];
|
|
|
|
$popularData = $this->skitsLibraryReposotpry->selectByRand($skitsLibraryPopularFields, $skitsLibraryPopularOrder);
|
|
|
|
$maxCount = count($popularData);
|
|
|
|
foreach ($popularData as $popularKey => $popular) {
|
|
$popularData[$popularKey]['heat_degree'] = sprintf("%d%d", $maxCount--, mt_rand(1000, 9999));
|
|
}
|
|
|
|
return [
|
|
'latest_data' => $latestData,
|
|
'popular_data' => $popularData
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 搜索过程 function
|
|
*
|
|
* @author dotdotdot <6383846@qq.com>
|
|
* @date 2022-08-10
|
|
* @param array $params
|
|
* @return array
|
|
*/
|
|
public function search(array $params)
|
|
{
|
|
$limit = $params['limit'];
|
|
|
|
$page = ($params['page'] - 1) * $params['limit'];
|
|
|
|
$keyWords = $params['keywords'];
|
|
|
|
$searchData = $this->skitsLibraryReposotpry->selectSearch($keyWords, $page, $limit);
|
|
|
|
return $searchData;
|
|
}
|
|
|
|
/**
|
|
* 短剧排行过程 function
|
|
*
|
|
* @author dotdotdot <6383846@qq.com>
|
|
* @date 2022-08-10
|
|
* @return array
|
|
*/
|
|
public function popularRank()
|
|
{
|
|
|
|
$skitsLibraryPopularFields = ['id', 'cover', 'name', 'description'];
|
|
$skitsLibraryPopularOrder = ['sort' => 'desc'];
|
|
$skitsLibraryPopularLimit = 10;
|
|
|
|
$popularData = $this->skitsLibraryReposotpry->selectByRand($skitsLibraryPopularFields, $skitsLibraryPopularOrder, $skitsLibraryPopularLimit);
|
|
|
|
$maxCount = count($popularData);
|
|
|
|
foreach ($popularData as $popularKey => $popular) {
|
|
$popularData[$popularKey]['heat_degree'] = sprintf("%d%d", $maxCount--, mt_rand(1000, 9999));
|
|
}
|
|
|
|
return $popularData;
|
|
}
|
|
}
|