// 列表
public function index()
{
// 分类
$cate_id = input('cate_id','');
$base = Db::name('base')
-> where('is_show',1)
-> where('base_category_id', $cate_id)
-> order('show_time desc,id desc')
-> paginate(16, false, ['query' => ['cate_id' => $cate_id, 'page' => request()->param('page')]]);
return view('index', compact('cate_id','base'));
}
// 详情
public function baseInfo()
{
$id = input('id','');
if (empty($id)) {
return $this->redirect(url('home/Base/index'));
}
$top = Db::name('about_top') -> order('create_time','desc') -> find();
Db::name('base') -> where('id',$id) -> setInc('view');
$base_info = Db::name('base') -> where('id', $id) -> find();
if (empty($base_info)) {
return $this->redirect(url('home/Base/index'));
}
$cate = Db::name('base_category') -> where('id', $base_info['base_category_id']) -> find();
// 下一条数据
$after = Db::name('base')
-> where('is_show','=',1)
-> where('id','>',$id)
-> order('show_time asc')
-> find();
// 上一条数据
$before = Db::name('base')
-> where('is_show','=',1)
-> where('id','<',$id)
-> order('show_time desc')
-> find();
// 推荐数据
$num = 10;
$count = Db::name('base') -> where('is_show','=',1) -> count();
$tuijian_like = Db::name('base') -> where('is_show','=',1) -> limit($count) -> select();
shuffle($tuijian_like); // 打乱数组
$tuijian_like = array_slice($tuijian_like,0, $num); // 抽取指定数据
return view('info', compact('top','base_info','after','before','tuijian_like','cate'));
}
智享笔记