field('name')->where(['stat' => 0, 'country_code' => $this->country_code])->select();
$data = [
'dl_name' => $dl_name,
];
return $this->json(200, 'ok', $data);
}
public function catelists()
{
$arg_where = [
'a.siteid' => $this->siteid,
'c.id' => 1,
];
$skeyword = $this->request->get('skeyword', '', 'urldecode,strval');
if ($skeyword != '') {
$skeyword = trim($skeyword);
$search['skeyword'] = $skeyword;
$arg_where['a.name|a.app_model'] = ['like', '%' . $search['skeyword'] . '%'];
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
$value['search'] = $search;
}
$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);
// echo \think\Db::table('download')->getLastSql(), '
';
// tiaoshi($dataObject->items());die;
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
];
if ($this->request->isAjax()) {
return $this->result($value, true, '下载列表');
}
$downloadCategory = Loader::model('DownloadCategory')->getList(['siteid' => $this->siteid, 'stat' => 0, 'pid' => 2], ['sort', 'id']);
// tiaoshi($downloadCategory);die;
$value['downloadCategory'] = $downloadCategory;
$value['skeyword'] = '';
$this->assign($value);
return $this->fetch();
}
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('DownloadCategory')->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')->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));
ob_clean();
flush();
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('ProductDl')->getRow($id);
if (empty($detail)) {
return exception('数据有误,请检查后再操作');
}
$docDir = request()->server('DOCUMENT_ROOT');
$rootDir = request()->root();
$directory = $docDir . $rootDir;
$fileinfo = pathinfo($detail['dl_url']);
$file = $directory . $detail['dl_url']; // 文件要下载的地址
//在session里面存ip和id 查这个上次访问时间
$ip = $this->get_real_ip();
$name = 'ip_' . $ip . '_' . $id;
$time = time();
$dl = session($name);
//如果没有则创建session
if ($dl == '') {
$dl = session($name, $time);
}
$a = 180 - (time() - $dl);
if ($dl && time() - $dl < 180) {
return $this->error('操作过于频繁,请' . $a . '秒后再试');
}
// echo $file, '
';
// var_dump(file_exists($file));echo '
';
// echo filesize($file), '
';
// echo 'Content-type: application/octet-stream', '
';
// echo 'Content-Disposition: attachment; filename=' . $fileinfo['basename'], '
';
// echo 'Content-Length: ' . filesize($file), '
';
// die;
ini_set('memory_limit', '500M');
set_time_limit(0);
$dl = session($name, $time);
Loader::model('ProductDl')->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($file));
readfile($file);
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')->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('DownloadCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
$skeyword = $this->request->get('skeyword', '', 'urldecode,strval');
if ($skeyword != '') {
$skeyword = trim($skeyword);
$search['skeyword'] = $skeyword;
$arg_where['a.name|a.app_model'] = ['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.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('DownloadCategory')->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)
{
$arg_where = ['a.siteid' => $this->siteid];
if ($id > 0) {
$arg_where['cid'] = $id;
$category = Loader::model('DownloadCategory')->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('DownloadCategory')->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);
}
function get_real_ip()
{
$ip = false;
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = explode(', ', $_SERVER['HTTP_X_FORWARDED_FOR']);
if ($ip) {
array_unshift($ips, $ip);
$ip = FALSE;
}
for ($i = 0; $i < count($ips); $i++) {
if (!eregi('^(10│172.16│192.168).', $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
public function dlsearch($id)
{
$where = ['id' => $id];
$view = Loader::model('Download')->where($where)->find();
$category = Loader::model('DownloadCategory')->getRow();
$this->assign('view',$view);
$this->assign('category',$category);
return $this->fetch();
}
}