Files
orico-official-website-old/app/index/controller/Video.php
2024-10-29 14:04:59 +08:00

187 lines
9.0 KiB
PHP
Executable File

<?php
namespace app\index\controller;
use think\Loader;
use think\Cookie;
use think\Config;
class Video extends BaseController {
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['a.siteid' => $this->siteid, 'country_code' => $this->country_code, 'isshow' => 1, 'stat' => 0];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['a.name'] = ['like', '%' . $skeyword . '%'];
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
}
$videoCategory = Loader::model('VideoCategory')->getList(['siteid' => $this->siteid, 'stat' => 0, 'isshow' => 1, 'country_code' => $this->country_code], ['sort', 'id'], ['id', 'pid', 'haschild', 'name', 'shortname', 'description', 'sort', 'isshow', 'recommend', 'picture', 'image1', 'image2', 'classtype', 'url']);
$value = [
'videoCategory' => $videoCategory,
];
$value['seo_title'] = config('video_seo_title')? : config('website_seo_title');
$value['seo_keyword'] = config('video_seo_keyword')? : config('website_seo_keyword');
$value['seo_description'] = config('video_seo_description')? : config('website_seo_description');
$this->assign($value);
return $this->fetch();
}
public function catelists($id = 0) {
$arg_where = ['a.siteid' => $this->siteid, 'a.country_code' => $this->country_code];
$id = intval($id);
if ($id > 0) {
$category = Loader::model('VideoCategory')->getRow($id);
if ($category['haschild']) {
$ids = Loader::model('VideoCategory')->getChildIDArray($id);
$arg_where['cid'] = ['in', $ids];
} else {
$arg_where['cid'] = $id;
}
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
unset($category['siteid']);
$value['category'] = $category;
$skeyword = $this->request->get('skeyword', '', 'urldecode,strval');
if ($skeyword != '') {
$skeyword = trim($skeyword);
$search['skeyword'] = $skeyword;
$arg_where['a.name'] = ['like', '%' . $search['skeyword'] . '%'];
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
$value['search'] = $search;
}
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.viewcount', 'a.videopath', 'a.videourl', 'a.description', 'a.picture', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
$dataObject = Loader::model('Video')->getCateVideoLists($arg_where, $arg_order, $arg_field, 10);
$value['list'] = $dataObject->isEmpty() ? null : $dataObject->items();
$value['page'] = $dataObject->render();
if ($this->request->isAjax()) {
return $this->result($value, true, '视频列表');
}
$videoCategory = Loader::model('VideoCategory')->getList(['siteid' => $this->siteid, 'stat' => 0, 'isshow' => 1, 'country_code' => $this->country_code], ['sort', 'id'], ['id', 'pid', 'haschild', 'name', 'shortname', 'description', 'sort', 'isshow', 'recommend', 'picture', 'image1', 'image2', 'classtype', 'url']);
$value['videoCategory'] = $videoCategory;
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
$this->assign($value);
return $this->fetch($template);
}
public function detail($id = 0) {
if ($id > 0) {
$detail = Loader::model('Video')->getRow($id);
if (empty($detail)) {
return exception('数据有误,请检查后再操作');
}
//$addvideo = Loader::model('VideoAddition')->getRowAddition(['aid' => $detail['id']]);
$category = Loader::model('VideoCategory')->getRow($detail['cid']);
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
//$prev_detail = Loader::model('Video')->getRow(['id' => ['gt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'asc']);
//$next_detail = Loader::model('Video')->getRow(['id' => ['lt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'desc']);
$value = [
'detail' => $detail,
//'addvideo' => $addvideo,
'category' => $category,
//'prev_detail' => $prev_detail,
//'next_detail' => $next_detail,
];
$value['seo_title'] = $detail['seo_title']? : $detail['name'] . '-' . config('website_seo_title');
$value['seo_keyword'] = $detail['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $detail['seo_description']? : config('website_seo_description');
$this->assign($value);
$this->viewcount($id);
return $this->fetch();
} else {
return exception('数据有误,请检查后再操作');
}
}
protected function viewcount($id) {
$view = Cookie::get('videoview', 'history'); //print_r($history);exit;
if (empty($view) || $view != $id) {
Loader::model('Video')->where(['id' => $id])->setInc('viewcount');
Cookie::set('videoview', $id, ['prefix' => 'history', 'expire' => 3600]);
}
}
protected function historyvideo($id) {
$video = Cookie::get('video', 'history'); //print_r($history);exit;
if (isset($video) && !empty($video)) {
$video_ids = explode(',', $video);
if ($video_ids[0] != $id) {
array_unshift($video_ids, $id);
$video_ids = array_unique($video_ids);
$num = Config::get('history_number') > 0 ? Config::get('history_number') : 10;
//$video_ids = array_slice($video_ids, 0, $num);
while (count($video_ids) > $num) {
array_pop($video_ids);
}
Cookie::set('video', implode(',', $video_ids), ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
} else {
Cookie::set('video', $id, ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
}
public function items($id = 0) {
$arg_where = ['a.siteid' => $this->siteid, 'a.country_code' => $this->country_code];
$id = intval($id);
$category = array();
if ($id > 0) {
$category = Loader::model('VideoCategory')->getRow($id);
if ($category['haschild']) {
$ids = Loader::model('VideoCategory')->getChildIDArray($id);
//$arg_where['cid'] = ['in', $ids];
}
}
unset($category['siteid']);
$value['category'] = $category;
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.viewcount', 'a.videopath', 'a.videourl', 'a.description', 'a.picture', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
$dataObject = Loader::model('Video')->getCateVideoLists($arg_where, $arg_order, $arg_field, 10);
$value['list'] = $dataObject->isEmpty() ? null : $dataObject->items();
$value['page'] = $dataObject->render();
if ($this->request->isAjax()) {
return $this->result($value, true, '视频列表');
}
$videoCategory = Loader::model('VideoCategory')->getList(['siteid' => $this->siteid, 'stat' => 0, 'isshow' => 1, 'country_code' => $this->country_code], ['sort', 'id'], ['id', 'pid', 'haschild', 'name', 'shortname', 'description', 'sort', 'isshow', 'recommend', 'picture', 'image1', 'image2', 'classtype', 'url']);
$value['videoCategory'] = $videoCategory;
//echo "<pre>=="; print_r($dataObject->items());
$value['seo_title'] = isset($category['seo_title']) ? : config('website_seo_title');
$value['seo_keyword'] = isset($category['seo_keyword'])? : config('website_seo_keyword');
$value['seo_description'] = isset($category['seo_description'])? : config('website_seo_description');
$this->assign($value);
return $this->fetch();
}
}