297 lines
15 KiB
PHP
Executable File
297 lines
15 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\vn\controller;
|
|
|
|
use think\Loader;
|
|
use think\Cookie;
|
|
use think\Config;
|
|
|
|
class Download extends BaseController {
|
|
|
|
public function search($id = 0) {
|
|
$skeyword = $this->request->get('skeyword', '', 'urldecode');
|
|
$arg_where = ['a.siteid' => $this->siteid];
|
|
$arg_order = ['a.id' => 'desc'];
|
|
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.app_model', 'a.support_os', 'a.format', 'a.viewcount', 'a.downloadcount', 'a.description', 'a.picture', 'a.tags', 'a.downloadpath', 'a.downloadpath64', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
|
|
if (!empty($skeyword)) {
|
|
$skeyword = trim($skeyword);
|
|
$arg_where['a.name'] = ['like', '%' . $skeyword . '%'];
|
|
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
|
|
}
|
|
if ($id > 0) {
|
|
$category = Loader::model('download_category_vn')->getRow($id);
|
|
}
|
|
$dataObject = Loader::model('download_vn')->getCateDownloadLists($arg_where, $arg_order, $arg_field, 12);
|
|
$value = [
|
|
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
|
|
'page' => $dataObject->render(),
|
|
];
|
|
if ($this->request->isAjax()) {
|
|
return $this->result($value, true, '下载列表');
|
|
}
|
|
$downloadCategory = Loader::model('download_category_vn')->getList(['siteid' => $this->siteid, 'stat' => 0, 'pid' => 2], ['sort', 'id']);
|
|
$value['downloadCategoryEn'] = $downloadCategory;
|
|
$value['skeyword'] = $skeyword;
|
|
$value['category'] = $category;
|
|
$value['seo_title'] = config('download_seo_title')? : config('website_seo_title_us');
|
|
$value['seo_keyword'] = config('download_seo_keyword')? : config('website_seo_keyword');
|
|
$value['seo_description'] = config('download_seo_description')? : config('website_seo_description');
|
|
$this->assign($value);
|
|
return $this->fetch('catelists');
|
|
}
|
|
|
|
public function catelists($id = 0) {
|
|
$arg_where = ['a.siteid' => $this->siteid];
|
|
if ($id > 0) {
|
|
$arg_where['cid'] = $id;
|
|
$category = Loader::model('download_category')->getRow($id);
|
|
}
|
|
if (empty($category)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
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.app_model', 'a.support_os', 'a.format', 'a.viewcount', 'a.downloadcount', 'a.description', 'a.picture', 'a.tags', 'a.downloadpath', 'a.downloadpath64', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
|
|
$dataObject = Loader::model('download')->getCateDownloadLists($arg_where, $arg_order, $arg_field, 12);
|
|
$value = [
|
|
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
|
|
'page' => $dataObject->render(),
|
|
];
|
|
if ($this->request->isAjax()) {
|
|
return $this->result($value, true, '下载列表');
|
|
}
|
|
$downloadCategory = Loader::model('download_category')->getList(['siteid' => $this->siteid, 'stat' => 0, 'pid' => 2], ['sort', 'id']);
|
|
$value['downloadCategory'] = $downloadCategory;
|
|
break;
|
|
case 3:
|
|
header('location:' . $category['url']);
|
|
exit;
|
|
break;
|
|
default:
|
|
$template = $category['tempindex'];
|
|
break;
|
|
}
|
|
$value['skeyword'] = '';
|
|
$value['category'] = $category;
|
|
$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('download')->getRow($id);
|
|
if (empty($detail)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
//$adddownload = Loader::model('DownloadAddition')->getRowAddition(['aid' => $detail['id']]);
|
|
$category = Loader::model('download_category')->getRow($detail['cid']);
|
|
if (empty($category)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
$prev_detail = Loader::model('download')->getRow(['id' => ['gt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'asc']);
|
|
$next_detail = Loader::model('download')->getRow(['id' => ['lt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'desc']);
|
|
$value = [
|
|
'detail' => $detail,
|
|
//'adddownload' => $adddownload,
|
|
'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('数据有误,请检查后再操作');
|
|
}
|
|
}
|
|
|
|
public function download($id = 0, $bit = 0) {
|
|
$id = intval($id);
|
|
$bit = intval($bit);
|
|
if ($id > 0) {
|
|
$detail = Loader::model('download')->getRow($id);
|
|
if (empty($detail)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
$docDir = request()->server('DOCUMENT_ROOT');
|
|
$rootDir = request()->root();
|
|
$directory = $docDir . $rootDir;
|
|
$downloadpath = explode(',', $detail['downloadpath']);
|
|
//$downloadpath64 = explode(',', $detail['downloadpath64']);
|
|
if (empty($downloadpath[$bit])) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
$fileinfo = pathinfo($downloadpath[$bit]);
|
|
$download = $directory . $downloadpath[$bit]; // 文件要下载的地址
|
|
Loader::model('download_id')->updateRow(['downloadcount' => \think\Db::raw('`downloadcount`+1')], ['id' => $id]);
|
|
header('Content-type: application/octet-stream');
|
|
header('Content-Disposition: attachment; filename=' . $fileinfo['basename']);
|
|
header('Content-Length: ' . filesize($download));
|
|
readfile($download);
|
|
exit();
|
|
} else {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
}
|
|
|
|
public function dlcount($id = 0) {
|
|
$id = intval($id);
|
|
if ($id > 0) {
|
|
$download = Loader::model('download')->getRow(['id' => $id], ['id', 'downloadcount']);
|
|
if (empty($download)) {
|
|
return $this->error('Error');
|
|
}
|
|
$download['downloadcount'] = $download['downloadcount'] + 1;
|
|
$result = $download->save();
|
|
if ($result) {
|
|
return $this->success('Download', null, $download['downloadcount']);
|
|
} else {
|
|
return $this->error('Download Error');
|
|
}
|
|
}
|
|
return $this->error('Error');
|
|
}
|
|
|
|
public function prodownload($id = 0) {
|
|
if ($id > 0) {
|
|
$detail = Loader::model('product_dl')->getRow($id);
|
|
if (empty($detail)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
$docDir = request()->server('DOCUMENT_ROOT');
|
|
$rootDir = request()->root();
|
|
$directory = $docDir . $rootDir;
|
|
$fileinfo = pathinfo($detail['dl_url']);
|
|
$download = $directory . $detail['dl_url']; // 文件要下载的地址
|
|
Loader::model('product_dl_id')->updateRow(['dl_count' => \think\Db::raw('`dl_count`+1')], ['id' => $id]);
|
|
header('Content-type: application/octet-stream');
|
|
header('Content-Disposition: attachment; filename=' . $fileinfo['basename']);
|
|
header('Content-Length: ' . filesize($download));
|
|
readfile($download);
|
|
exit();
|
|
} else {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
}
|
|
|
|
protected function viewcount($id) {
|
|
$view = Cookie::get('downloadview', 'history'); //print_r($history);exit;
|
|
if (empty($view) || $view != $id) {
|
|
Loader::model('download_id')->where(['id' => $id])->setInc('viewcount');
|
|
Cookie::set('downloadview', $id, ['prefix' => 'history', 'expire' => 3600]);
|
|
}
|
|
}
|
|
|
|
protected function historydownload($id) {
|
|
$download = Cookie::get('download', 'history'); //print_r($history);exit;
|
|
if (isset($download) && !empty($download)) {
|
|
$download_ids = explode(',', $download);
|
|
if ($download_ids[0] != $id) {
|
|
array_unshift($download_ids, $id);
|
|
$download_ids = array_unique($download_ids);
|
|
$num = Config::get('history_number') > 0 ? Config::get('history_number') : 10;
|
|
//$download_ids = array_slice($download_ids, 0, $num);
|
|
while (count($download_ids) > $num) {
|
|
array_pop($download_ids);
|
|
}
|
|
Cookie::set('download', implode(',', $download_ids), ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
|
|
}
|
|
} else {
|
|
Cookie::set('download', $id, ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
|
|
}
|
|
}
|
|
public function catelists_down($id = 0) {
|
|
//dump($id);die;
|
|
$arg_where = ['a.siteid' => $this->siteid];
|
|
if ($id > 0) {
|
|
$arg_where['cid'] = $id;
|
|
$category = Loader::model('download_category_vn')->getRow($id);
|
|
}
|
|
if (empty($category)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
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.app_model', 'a.support_os', 'a.format', 'a.viewcount', 'a.downloadcount', 'a.description', 'a.picture', 'a.tags', 'a.downloadpath', 'a.downloadpath64', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
|
|
$dataObject = Loader::model('download_id')->getCateDownloadLists($arg_where, $arg_order, $arg_field, 12);
|
|
$value = [
|
|
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
|
|
'page' => $dataObject->render(),
|
|
];
|
|
if ($this->request->isAjax()) {
|
|
return $this->result($value, true, '下载列表');
|
|
}
|
|
$downloadCategory = Loader::model('download_category_vn')->getList(['siteid' => $this->siteid, 'stat' => 0, 'pid' => 2], ['sort', 'id']);
|
|
$value['downloadCategory'] = $downloadCategory;
|
|
break;
|
|
case 3:
|
|
header('location:' . $category['url']);
|
|
exit;
|
|
break;
|
|
default:
|
|
$template = $category['tempindex'];
|
|
break;
|
|
}
|
|
$value['skeyword'] = '';
|
|
$value['category'] = $category;
|
|
$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 index($id = 0) {
|
|
//dump($id);die;
|
|
$arg_where = ['a.siteid' => $this->siteid];
|
|
if ($id > 0) {
|
|
$arg_where['cid'] = $id;
|
|
$category = Loader::model('download_category')->getRow($id);
|
|
}
|
|
if (empty($category)) {
|
|
return exception('数据有误,请检查后再操作');
|
|
}
|
|
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.app_model', 'a.support_os', 'a.format', 'a.viewcount', 'a.downloadcount', 'a.description', 'a.picture', 'a.tags', 'a.downloadpath', 'a.downloadpath64', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
|
|
$dataObject = Loader::model('download')->getCateDownloadLists($arg_where, $arg_order, $arg_field, 12);
|
|
$value = [
|
|
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
|
|
'page' => $dataObject->render(),
|
|
];
|
|
if ($this->request->isAjax()) {
|
|
return $this->result($value, true, '下载列表');
|
|
}
|
|
$downloadCategory = Loader::model('download_category')->getList(['siteid' => $this->siteid, 'stat' => 0, 'pid' => 2], ['sort', 'id']);
|
|
$value['downloadCategory'] = $downloadCategory;
|
|
break;
|
|
case 3:
|
|
header('location:' . $category['url']);
|
|
exit;
|
|
break;
|
|
default:
|
|
$template = $category['tempindex'];
|
|
break;
|
|
}
|
|
$value['skeyword'] = '';
|
|
$value['category'] = $category;
|
|
$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);
|
|
}
|
|
|
|
}
|