fix
This commit is contained in:
@@ -37,6 +37,19 @@ class StaticConfig
|
||||
'dao' => '倒叙',
|
||||
];
|
||||
|
||||
static $arrVideoStatus = [
|
||||
'all' => '所有',
|
||||
'lianzai' => '连载中',
|
||||
'wanjie' => '已完结',
|
||||
];
|
||||
|
||||
static $arrVideoSortType = [
|
||||
'all' => '全部排序',
|
||||
'news' => '最新入库',
|
||||
'tuijian' => '推荐',
|
||||
'update' => '最新更新',
|
||||
];
|
||||
|
||||
/**
|
||||
* GetCategoryFilter
|
||||
*
|
||||
|
||||
579
code/app/services/VideoService.php
Normal file
579
code/app/services/VideoService.php
Normal file
@@ -0,0 +1,579 @@
|
||||
<?php
|
||||
|
||||
namespace app\services;
|
||||
|
||||
use app\model\CategoryModel;
|
||||
use app\model\ChapterModel;
|
||||
use app\model\ConverterMovel;
|
||||
use app\model\DomainModel;
|
||||
use app\model\VideoClicksModel;
|
||||
use app\model\VideoModel;
|
||||
use template\page\CusteomPage02;
|
||||
|
||||
class VideoService
|
||||
{
|
||||
/**
|
||||
* SiteContext
|
||||
*
|
||||
* @var SiteContext
|
||||
*/
|
||||
public $SiteContext;
|
||||
|
||||
/**
|
||||
* VideoModel
|
||||
*
|
||||
* @var VideoModel
|
||||
*/
|
||||
public $VideoModel;
|
||||
|
||||
/**
|
||||
* VideoClicksModel
|
||||
*
|
||||
* @var VideoClicksModel
|
||||
*/
|
||||
public $VideoClicksModel;
|
||||
|
||||
public function __construct(SiteContext $SiteContext)
|
||||
{
|
||||
$this->SiteContext = $SiteContext;
|
||||
$this->VideoModel = VideoModel::getInstance();
|
||||
$this->VideoClicksModel = VideoClicksModel::getInstance();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param int $intVId
|
||||
* @param string $intPinYin
|
||||
* @return string
|
||||
*/
|
||||
public function getVideoInfoUrl($intVId, $intPinYin): string
|
||||
{
|
||||
$strKey = 'VIDEO_INFO_URL';
|
||||
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
|
||||
'intVId' => $intVId,
|
||||
'strPinYin' => $intPinYin
|
||||
]);
|
||||
return (string)$strUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取小说分类URl
|
||||
*
|
||||
* @param string $strGender
|
||||
* @param string $strCategory
|
||||
* @param string $strStatus
|
||||
* @param string $strOrder
|
||||
* @param integer $intPage
|
||||
* @return string
|
||||
*/
|
||||
public function getVideoCategoryUrl(string|NULL $strGender, string|NULL $strCategory, string|NULL $strStatus, string|NULL $strOrder, int|string|NULL $intPage): string
|
||||
{
|
||||
$strKey = 'CATEGORY_INFO_URL';
|
||||
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
|
||||
'strGender' => !empty($strGender) ? $strGender : '',
|
||||
'strCategory' => !empty($strCategory) ? $strCategory : 'all',
|
||||
'strStatus' => !empty($strStatus) ? $strStatus : 'all',
|
||||
'strOrder' => !empty($strOrder) ? $strOrder : 'all',
|
||||
'intPage' => $intPage ?? 1,
|
||||
]);
|
||||
|
||||
$strUrl = preg_replace('#/{2,}#', '/', $strUrl);
|
||||
return (string)$strUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 排行榜url
|
||||
*
|
||||
* @param string $strGender
|
||||
* @param string $strCategory
|
||||
* @param string $strStatus
|
||||
* @param string $strOrder
|
||||
* @param integer $intPage
|
||||
* @return string
|
||||
*/
|
||||
public function getVideoRankUrl(string $strGender, string $strCategory, string $strStatus, string $strOrder, int $intPage): string
|
||||
{
|
||||
|
||||
$strKey = 'RANK_LIST_URL';
|
||||
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
|
||||
'strGender' => !empty($strGender) ? $strGender : '',
|
||||
'strCategory' => !empty($strCategory) ? $strCategory : 'all',
|
||||
'strStatus' => !empty($strStatus) ? $strStatus : 'all',
|
||||
'strOrder' => !empty($strOrder) ? $strOrder : 'all',
|
||||
'intPage' => $intPage ?? 1,
|
||||
]);
|
||||
|
||||
$strUrl = preg_replace('#/{2,}#', '/', $strUrl);
|
||||
return (string)$strUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* 小说目录
|
||||
* @param int $intVId
|
||||
* @param string $intPinYin
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public function getVideoCatalogUrl($intVId, $intPinYin, $strOrder, $intPage = 1): string
|
||||
{
|
||||
$strKey = 'VIDEO_CATALOG_URL';
|
||||
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
|
||||
'intVId' => $intVId,
|
||||
'strPinYin' => $intPinYin,
|
||||
'strOrder' => $strOrder,
|
||||
'intPage' => $intPage,
|
||||
]);
|
||||
return (string)$strUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param int $intPage
|
||||
* @param string $strKeyWords
|
||||
* @return string
|
||||
*/
|
||||
public function getVideoSearchUrl($strKeyWords, $intPage = 1): string
|
||||
{
|
||||
$strKey = 'SEARCH_INFO_URL';
|
||||
$strUrl = $this->SiteContext->DomainModel->getFomartUrl($strKey, [
|
||||
'intPage' => $intPage,
|
||||
'strSearchKeywords' => $strKeyWords
|
||||
]);
|
||||
return (string)$strUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取排行榜小说
|
||||
*
|
||||
* @param array $arrParams
|
||||
* @return array
|
||||
*/
|
||||
public function getRankList(array $arrParams): array
|
||||
{
|
||||
$intCount = (int)$arrParams['count'] ?? 10;
|
||||
$strSortType = (string)$arrParams['sort_type'] ?? '';
|
||||
$strNStatus = (string) $arrParams['v_isend'] ?? '';
|
||||
|
||||
$strDiffKey = (string) $arrParams['diff_key'] ?? '';
|
||||
$intCacheLifeTime = (int)$arrParams['cache_life'] ?? 0;
|
||||
|
||||
$arrFilter = [];
|
||||
|
||||
# v_isend filter
|
||||
if (!empty($strNStatus)) {
|
||||
switch ($strNStatus) {
|
||||
case 'lianzai':
|
||||
$arrFilter['v_isend'] = 0;
|
||||
break;
|
||||
case 'wanjie':
|
||||
$arrFilter['v_isend'] = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$arrSort = [];
|
||||
|
||||
# sort filter
|
||||
if (!empty($strSortType)) {
|
||||
switch ($strSortType) {
|
||||
case 'daily':
|
||||
$arrSort['v_sort_type'] = 'daily';
|
||||
break;
|
||||
case 'weekly':
|
||||
$arrSort['v_sort_type'] = 'weekly';
|
||||
break;
|
||||
case 'monthly':
|
||||
$arrSort['v_sort_type'] = 'monthly';
|
||||
break;
|
||||
case 'total':
|
||||
$arrSort['v_sort_type'] = 'total';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$strCacheKey = '';
|
||||
$intLifeTime = 0;
|
||||
|
||||
# cache filter
|
||||
if ($intCacheLifeTime > 0) {
|
||||
$strCacheKey = sprintf(
|
||||
'VideoService:getRankList:%s:%s:%s:%s:%s',
|
||||
$this->SiteContext->DomainModel->d_domain,
|
||||
md5(serialize($arrFilter)),
|
||||
md5(serialize($arrSort)),
|
||||
$intCount,
|
||||
$strDiffKey,
|
||||
);
|
||||
|
||||
$intLifeTime = $intLifeTime;
|
||||
}
|
||||
|
||||
$arrVideo = $this->VideoModel->getRankVideoOnCache(
|
||||
$strCacheKey,
|
||||
$intCount,
|
||||
$arrFilter['v_category_sex_zh'] ?? 0,
|
||||
$arrSort['v_sort_type'] ?? 'daily',
|
||||
$arrFilter['v_isend'] ?? NULL,
|
||||
$intLifeTime,
|
||||
);
|
||||
|
||||
return $arrVideo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取小说数据
|
||||
*
|
||||
* @param array $arrParams
|
||||
* @return array
|
||||
*/
|
||||
public function getVideoList(array $arrParams): array
|
||||
{
|
||||
$intCount = (int)$arrParams['count'] ?? 10;
|
||||
$strNCategory = $arrParams['v_category'] ?? '';
|
||||
$strSortType = (string)$arrParams['sort_type'] ?? '';
|
||||
$strNStatus = (string) $arrParams['v_isend'] ?? '';
|
||||
|
||||
$strDiffKey = (string) $arrParams['diff_key'] ?? '';
|
||||
$intCacheLifeTime = (int)$arrParams['cache_life'] ?? 0;
|
||||
|
||||
$arrFilter = [];
|
||||
|
||||
# v_category filter
|
||||
if (!empty($strNCategory)) {
|
||||
$strNCategory = CategoryModel::getZhByPinYin($strNCategory);
|
||||
if ($strNCategory) {
|
||||
$arrFilter['v_category'] = $strNCategory;
|
||||
}
|
||||
}
|
||||
|
||||
# v_isend filter
|
||||
if (!empty($strNStatus)) {
|
||||
switch ($strNStatus) {
|
||||
case 'lianzai':
|
||||
$arrFilter['v_isend'] = StaticConfig::$arrVideoStatus[$strNStatus];
|
||||
break;
|
||||
case 'wanjie':
|
||||
$arrFilter['v_isend'] = StaticConfig::$arrVideoStatus[$strNStatus];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$arrSort = [];
|
||||
|
||||
# sort filter
|
||||
if (!empty($strSortType)) {
|
||||
switch ($strSortType) {
|
||||
case 'news':
|
||||
$arrSort['created_at'] = -1;
|
||||
break;
|
||||
case 'tuijian':
|
||||
$arrSort['v_level'] = -1;
|
||||
break;
|
||||
case 'update':
|
||||
$arrSort['v_update_time'] = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$strCacheKey = '';
|
||||
$intLifeTime = 0;
|
||||
|
||||
# cache filter
|
||||
if ($intCacheLifeTime > 0) {
|
||||
$strCacheKey = sprintf(
|
||||
'VideoService:getVideoList:%s:%s:%s:%s:%s',
|
||||
$this->SiteContext->DomainModel->d_domain,
|
||||
md5(serialize($arrFilter)),
|
||||
md5(serialize($arrSort)),
|
||||
$intCount,
|
||||
$strDiffKey,
|
||||
);
|
||||
|
||||
$intLifeTime = $intLifeTime;
|
||||
}
|
||||
|
||||
$arrVideo = $this->VideoModel->findManyShuffledWithCache(
|
||||
$arrFilter,
|
||||
$intCount,
|
||||
$arrSort,
|
||||
$strCacheKey,
|
||||
$intLifeTime,
|
||||
);
|
||||
|
||||
return $arrVideo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取小说分页数据
|
||||
*
|
||||
* @param array $arrParams
|
||||
* @return array
|
||||
*/
|
||||
public function getVideoPager(array $arrParams): array
|
||||
{
|
||||
$arrParams = [
|
||||
'page' => max((int)($arrParams['page'] ?? 1), 1),
|
||||
'limit' => (int)($arrParams['limit'] ?? 10),
|
||||
'buttov_num' => (int)($arrParams['buttov_num'] ?? 0),
|
||||
'v_category' => (string)($arrParams['v_category'] ?? ''),
|
||||
'sort_type' => (string)($arrParams['sort_type'] ?? ''),
|
||||
'v_isend' => (string)($arrParams['v_isend'] ?? ''),
|
||||
'v_sex' => (string)($arrParams['v_sex'] ?? ''),
|
||||
'diff_key' => (string)($arrParams['diff_key'] ?? ''),
|
||||
'key' => (string)($arrParams['key'] ?? ''),
|
||||
'cache_life' => (int)($arrParams['cache_life'] ?? 0),
|
||||
'func' => (string)($arrParams['func']),
|
||||
];
|
||||
|
||||
$intPage = $arrParams['page'];
|
||||
$intLimit = $arrParams['limit'];
|
||||
$strNCategory = $arrParams['v_category'];
|
||||
$strSortType = $arrParams['sort_type'];
|
||||
$strNStatus = $arrParams['v_isend'];
|
||||
|
||||
$strDiffKey = $arrParams['diff_key'];
|
||||
$strKey = $arrParams['key'];
|
||||
$intCacheLifeTime = $arrParams['cache_life'];
|
||||
$Func = $arrParams['func'];
|
||||
|
||||
if ($intPage <= 0) {
|
||||
$intPage = 1;
|
||||
}
|
||||
|
||||
$arrFilter = [
|
||||
'$and' => [],
|
||||
];
|
||||
|
||||
# v_category filter
|
||||
if (!empty($strNCategory)) {
|
||||
$strNCategory = CategoryModel::getZhByPinYin($strNCategory);
|
||||
if ($strNCategory) {
|
||||
$arrFilter['$and'][] = ['v_category' => $strNCategory];
|
||||
} else {
|
||||
$arrParams['v_category'] = 'all';
|
||||
}
|
||||
}
|
||||
|
||||
# v_isend filter
|
||||
if (!empty($strNStatus)) {
|
||||
switch ($strNStatus) {
|
||||
case 'lianzai':
|
||||
$arrFilter['$and'][] = ['v_isend' => StaticConfig::$arrVideoStatus[$strNStatus]];
|
||||
break;
|
||||
case 'wanjie':
|
||||
$arrFilter['$and'][] = ['v_isend' => StaticConfig::$arrVideoStatus[$strNStatus]];
|
||||
break;
|
||||
default:
|
||||
$arrParams['v_isend'] = 'all';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# key filter
|
||||
if (!empty($strKey)) {
|
||||
|
||||
$strKey = mb_substr($strKey, 0, 30);
|
||||
$arrFilter['$and'][] = [
|
||||
'$or' => [
|
||||
['v_name' => ['$regex' => $strKey, '$options' => 'i']],
|
||||
['v_author' => ['$regex' => $strKey, '$options' => 'i']],
|
||||
['v_category' => ['$regex' => $strKey, '$options' => 'i']],
|
||||
['v_description' => ['$regex' => $strKey, '$options' => 'i']],
|
||||
]
|
||||
];
|
||||
$arrParams['key'] = $strKey;
|
||||
}
|
||||
|
||||
$arrSort = [];
|
||||
|
||||
# sort filter
|
||||
if (!empty($strSortType)) {
|
||||
switch ($strSortType) {
|
||||
case 'news':
|
||||
$arrSort['created_at'] = -1;
|
||||
break;
|
||||
case 'tuijian':
|
||||
$arrSort['v_level'] = -1;
|
||||
break;
|
||||
case 'update':
|
||||
$arrSort['v_update_time'] = -1;
|
||||
break;
|
||||
default:
|
||||
$arrParams['sort_type'] = 'all';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$strCacheKey = '';
|
||||
$intLifeTime = 0;
|
||||
|
||||
# cache filter
|
||||
if ($intCacheLifeTime > 0) {
|
||||
$strCacheKey = sprintf(
|
||||
'VideoService:getVideoList:%s:%s:%s:%s:%s:%s',
|
||||
$this->SiteContext->DomainModel->d_domain,
|
||||
md5(serialize($arrFilter)),
|
||||
md5(serialize($arrSort)),
|
||||
$intPage,
|
||||
$intLimit,
|
||||
$strDiffKey,
|
||||
);
|
||||
|
||||
$intLifeTime = $intLifeTime;
|
||||
}
|
||||
|
||||
// 更新值
|
||||
$strGender = $this->SiteContext->Request->param('strGender');
|
||||
$strNanUrlTemp = $this->SiteContext->DomainModel->getFomartSubject('NAN_SHENG_URL', '', false);
|
||||
$strNanUrl = str_replace("/", "", $strNanUrlTemp);
|
||||
$strCNSex = '全部';
|
||||
if ($strGender) {
|
||||
$strCNSex = $strGender == $strNanUrl ? '男生' : '女生';
|
||||
}
|
||||
ConverterMovel::setVal([
|
||||
'intPage' => $intPage,
|
||||
'strVideoSex' => $strCNSex,
|
||||
'strVideoCategoryName' => empty($strNCategory) ? '' : str_replace("小说", "", $strNCategory),
|
||||
'strVideoStatus' => empty($strNStatus) ? '' : StaticConfig::$arrVideoStatus[$strNStatus],
|
||||
'strVideoOrder' => empty($strSortType) ? '' : StaticConfig::$arrVideoSortType[$strSortType],
|
||||
'strSearchKeywords' => $strKey,
|
||||
]);
|
||||
|
||||
if (empty($arrFilter['$and'])) {
|
||||
$arrFilter = [];
|
||||
}
|
||||
|
||||
$arrVideo = $this->VideoModel->findPaginatedWithCache(
|
||||
$arrFilter,
|
||||
$intPage,
|
||||
$intLimit,
|
||||
$arrSort,
|
||||
$strCacheKey,
|
||||
$intLifeTime,
|
||||
);
|
||||
|
||||
$arrPager = $arrVideo;
|
||||
unset($arrPager['data']);
|
||||
$arrPager['pager'] = call_user_func([$this, $Func], $arrParams, $arrSort, $arrVideo);
|
||||
|
||||
$arrResult = [
|
||||
'data' => $arrVideo['data'],
|
||||
'p_data' => $arrPager,
|
||||
];
|
||||
|
||||
return $arrResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索定制分页
|
||||
*
|
||||
* @param array $arrFilter 查询条件字段
|
||||
* @param array $arrSort 查询排序字段
|
||||
* @param array $arrVideo 查询出来的数据
|
||||
* @return array
|
||||
*/
|
||||
public function generateSearchPager(array $arrParams, array $arrSort, array $arrVideo): array
|
||||
{
|
||||
$strKey = $arrParams['key'];
|
||||
$intPage = $arrVideo['page'];
|
||||
$intLimit = $arrVideo['limit'];
|
||||
$intButtomNum = $arrParams['buttov_num'];
|
||||
$strBaseUrl = app(VideoService::class)->getVideoSearchUrl($strKey, '{page}');
|
||||
$arrPaginator = CusteomPage02::generate($intPage, $arrVideo['total'], $intLimit, $strBaseUrl, $intButtomNum);
|
||||
|
||||
return $arrPaginator;
|
||||
}
|
||||
|
||||
/**
|
||||
* 书库/分类定制分页
|
||||
*
|
||||
* @param array $arrFilter 查询条件字段
|
||||
* @param array $arrSort 查询排序字段
|
||||
* @param array $arrVideo 查询出来的数据
|
||||
* @return array
|
||||
*/
|
||||
public function generateCategoryPager(array $arrParams, array $arrSort, array $arrVideo): array
|
||||
{
|
||||
$strGender = $arrParams['v_sex'];
|
||||
$strCategory = $arrParams['v_category'];
|
||||
$strStatus = $arrParams['v_isend'];
|
||||
$strOrder = $arrParams['sort_type'];
|
||||
$intPage = $arrVideo['page'] ?? 1;
|
||||
$intLimit = $arrVideo['limit'] ?? 10;
|
||||
$intTotal = $arrVideo['total'] ?? 0;
|
||||
$intButtomNum = $arrParams['buttov_num'];
|
||||
$strBaseUrl = $this->getVideoCategoryUrl($strGender, $strCategory, $strStatus, $strOrder, '{page}');
|
||||
|
||||
$arrPaginator = CusteomPage02::generate($intPage, $intTotal, $intLimit, $strBaseUrl, $intButtomNum);
|
||||
|
||||
return $arrPaginator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据VId获取小说详情
|
||||
*
|
||||
* @param integer $intVId
|
||||
* @return void
|
||||
*/
|
||||
public function getVideoByVId(int $intVId, int|null $intNForgeId = 0)
|
||||
{
|
||||
|
||||
// 小说详情
|
||||
$arrVideo = $this->VideoModel->getVideoByVId($intVId);
|
||||
|
||||
if ($intNForgeId > 0) {
|
||||
foreach ($arrVideo['v_forge_novel'] as $arrForgeVideo) {
|
||||
if ($arrForgeVideo['v_forge_id'] == $intNForgeId) {
|
||||
$arrVideo['v_name'] = $arrForgeVideo['v_forge_title'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 分类拼音
|
||||
$arrVideo['v_category_pinyin'] = CategoryModel::getPinYin($arrVideo['v_category']);
|
||||
$arrVideo['v_category_sex_en'] = $arrVideo['v_category_sex_en'] ?? 'man';
|
||||
|
||||
// 点击数
|
||||
$arrVideoClicks = $this->VideoClicksModel->getStats($intVId);
|
||||
|
||||
// 推荐小说
|
||||
$arrRelateveVId = array_column($arrVideo['v_related_novel'], 'v_id');
|
||||
|
||||
$arrRelateveVideo = $this->VideoModel->findMany(['v_id' => [
|
||||
'$in' => $arrRelateveVId,
|
||||
]], 10);
|
||||
|
||||
|
||||
// 更新值
|
||||
ConverterMovel::setVal([
|
||||
'intPage' => 1,
|
||||
'strVideoName' => $arrVideo['v_name'],
|
||||
'strVideoAuthor' => $arrVideo['v_author'],
|
||||
'strVideoCategoryName' => $arrVideo['v_category'],
|
||||
'strVideoSex' => $arrVideo['v_category_sex_en'] == 'man' ? '男生' : '女生',
|
||||
'strVideoStatus' => $arrVideo['v_isend'],
|
||||
'strVideoDescription' => $arrVideo['v_description'],
|
||||
]);
|
||||
|
||||
$arrVideo['arrVideoClicks'] = $arrVideoClicks;
|
||||
$arrVideo['arrRelateveVideo'] = $arrRelateveVideo;
|
||||
|
||||
|
||||
return $arrVideo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user