优化搜索界面及控制器
This commit is contained in:
@@ -28,14 +28,14 @@ class SearchController extends BaseController
|
||||
$detailUrl = '/index/articles/detail';
|
||||
$categoryUrl = '/index/articles/category';
|
||||
$status = 2; // 文章状态为2
|
||||
$fields = 'id, title, cate, image, author, create_time as publishdate';
|
||||
$fields = 'id, title, cate, image, author, FROM_UNIXTIME(create_time, "%Y-%m-%d") as publishdate';
|
||||
} else if ($type == 'resource') {
|
||||
$model = new Resources();
|
||||
$categoryModel = new ResourcesCategory();
|
||||
$detailUrl = '/index/resources/detail';
|
||||
$categoryUrl = '/index/resources/category';
|
||||
$status = 1; // 资源状态为1
|
||||
$fields = 'id, title, cate, icon, author, create_time as publishdate';
|
||||
$fields = 'id, title, cate, icon, uploader, FROM_UNIXTIME(create_time, "%Y-%m-%d") as publishdate';
|
||||
} else {
|
||||
$this->error('无效的搜索类型');
|
||||
}
|
||||
@@ -61,6 +61,7 @@ class SearchController extends BaseController
|
||||
->find();
|
||||
|
||||
$item['category'] = $category ?: ['id' => 0, 'name' => '未分类', 'image' => ''];
|
||||
$item['cate'] = $item['category']['name']; // 使用分类名称替换分类ID
|
||||
|
||||
// 如果文章的图片为空,使用分类的图片
|
||||
if (empty($item['image'])) {
|
||||
@@ -71,10 +72,11 @@ class SearchController extends BaseController
|
||||
}
|
||||
} else {
|
||||
$category = $categoryModel->where('id', $item['cate'])
|
||||
->field('id, name, icon')
|
||||
->field('id, name, icon, cid')
|
||||
->find();
|
||||
|
||||
$item['category'] = $category ?: ['id' => 0, 'name' => '未分类', 'icon' => ''];
|
||||
$item['category'] = $category ?: ['id' => 0, 'name' => '未分类', 'icon' => '', 'cid' => 0];
|
||||
$item['cate'] = $item['category']['name']; // 使用分类名称替换分类ID
|
||||
|
||||
// 如果资源的图片为空,使用分类的图片
|
||||
if (empty($item['icon'])) {
|
||||
@@ -83,6 +85,13 @@ class SearchController extends BaseController
|
||||
if (empty($item['icon'])) {
|
||||
$item['icon'] = '/static/images/default.jpg';
|
||||
}
|
||||
|
||||
// 根据分类cid判断资源类型
|
||||
if ($item['category']['cid'] == 8) {
|
||||
$item['detail_url'] = url('game/detail', ['id' => $item['id']]);
|
||||
} else {
|
||||
$item['detail_url'] = url('program/detail', ['id' => $item['id']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user