更新666
This commit is contained in:
@@ -10,6 +10,8 @@ use app\index\QfShop;
|
||||
use app\model\Source as SourceModel;
|
||||
use app\model\SourceCategory as SourceCategoryModel;
|
||||
|
||||
use Lizhichao\Word\VicWord;
|
||||
|
||||
|
||||
class Index extends QfShop
|
||||
{
|
||||
@@ -48,9 +50,26 @@ class Index extends QfShop
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
//热门排行榜数据
|
||||
$hotList = [];
|
||||
$cacheDir = root_path('runtime/api/cache'); // runtime/cache 目录
|
||||
foreach ($rankList as $value) {
|
||||
$cacheFile = $cacheDir . "ranking_data_{$value['name']}.cache";
|
||||
if (file_exists($cacheFile)) {
|
||||
$hotList[] = array(
|
||||
'name'=> $value['name'],
|
||||
'image'=> $value['image'],
|
||||
'list'=> json_decode(file_get_contents($cacheFile), true),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$config = config("qfshop");
|
||||
|
||||
View::assign('newList', $newList);
|
||||
View::assign('hotList', $hotList);
|
||||
View::assign('config', $config);
|
||||
View::assign('rankList', $rankList);
|
||||
View::assign('fixed', 1);
|
||||
@@ -80,9 +99,25 @@ class Index extends QfShop
|
||||
|
||||
$category = $this->SourceCategoryModel->field('name,source_category_id as id')->where([['status','=',0]])->order('sort desc')->select();
|
||||
|
||||
|
||||
//热门排行榜数据
|
||||
$hotList = [];
|
||||
$cacheDir = root_path('runtime/api/cache'); // runtime/cache 目录
|
||||
foreach ($rankList as $value) {
|
||||
$cacheFile = $cacheDir . "ranking_data_{$value['name']}.cache";
|
||||
if (file_exists($cacheFile)) {
|
||||
$hotList[] = array(
|
||||
'name'=> $value['name'],
|
||||
'image'=> $value['image'],
|
||||
'list'=> json_decode(file_get_contents($cacheFile), true),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$config = config("qfshop");
|
||||
|
||||
View::assign('hotList', $hotList);
|
||||
View::assign('rankList', $rankList);
|
||||
View::assign('category', $category);
|
||||
View::assign('list', $list);
|
||||
@@ -118,9 +153,53 @@ class Index extends QfShop
|
||||
}
|
||||
|
||||
$rankList = $this->SourceCategoryModel->field('name,image')->where([['status','=',0],['is_sys','=',1]])->order('sort desc')->select();
|
||||
|
||||
//热门排行榜数据
|
||||
$hotList = [];
|
||||
$cacheDir = root_path('runtime/api/cache'); // runtime/cache 目录
|
||||
foreach ($rankList as $value) {
|
||||
$cacheFile = $cacheDir . "ranking_data_{$value['name']}.cache";
|
||||
if (file_exists($cacheFile)) {
|
||||
$hotList[] = array(
|
||||
'name'=> $value['name'],
|
||||
'image'=> $value['image'],
|
||||
'list'=> json_decode(file_get_contents($cacheFile), true),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//相关资源
|
||||
$map[] = ['status', '=', 1];
|
||||
$map[] = ['is_delete', '=', 0];
|
||||
$fc = new VicWord();
|
||||
$keywords = $fc->getAutoWord(preg_replace('/[\(\(][^\)]*[\)\)]/u', '', $detail['title']));
|
||||
$keywords = filterAndExtractWords($keywords);
|
||||
$keywords[] = '';//这个是为了在没有相关资源时不至于获取不到资源
|
||||
$weightExpr = [];
|
||||
foreach ($keywords as $keyword) {
|
||||
$weightExpr[] = "IF(title LIKE '%{$keyword}%' OR description LIKE '%{$keyword}%', 1, 0)";
|
||||
$searchTitle[] = $keyword;
|
||||
}
|
||||
$weightExpr = implode(' + ', $weightExpr);
|
||||
// 在查询中添加权重计算和排序
|
||||
$query = $this->SourceModel->alias('a')
|
||||
->field('a.*, (' . $weightExpr . ') as weight')->where($map)
|
||||
->where(function($query) use ($keywords) {
|
||||
foreach ($keywords as $keyword) {
|
||||
$query->whereOr('title', 'like', '%' . trim($keyword) . '%')
|
||||
->whereOr('description', 'like', '%' . trim($keyword) . '%');
|
||||
}
|
||||
});
|
||||
$order = ['weight' => 'desc', 'source_id' => 'desc'];
|
||||
$sameList = $query->where('source_id','<>',$detail['id'])->order($order)->limit(10)->select();
|
||||
|
||||
|
||||
|
||||
$config = config("qfshop");
|
||||
|
||||
View::assign('sameList', $sameList);
|
||||
View::assign('hotList', $hotList);
|
||||
View::assign('rankList', $rankList);
|
||||
View::assign('detail', $detail);
|
||||
View::assign('config', $config);
|
||||
|
||||
Reference in New Issue
Block a user