request->get('skeyword', '', 'urldecode'); $arg_where = ['a.siteid' => $this->siteid, 'country_code']; $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')->getRow($id); } $dataObject = Loader::model('download_th')->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['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 get_filter() { $dl_name = model('download')->where(['stat' => 0, 'country_code' => $this->country_code])->field('name')->select(); $data = [ 'dl_name' => $dl_name, ]; return $this->json(200, 'ok', $data); } public function catelists($id = 0) { $arg_where = [ 'a.siteid' => $this->siteid, 'a.country_code' => $this->country_code ]; $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; } $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();die; // 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, 'country_code' => $this->country_code], ['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('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')->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'); 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'); 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, 'country_code' => $this->country_code]; 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 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); } }