$this->siteid, 'a.country_code' => $this->country_code]; $arg_order = ['a.id' => 'desc']; $arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.writer', 'a.source', 'a.viewcount', 'a.zancount', 'a.commentcount', 'a.description', 'a.picture', 'a.tags', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname']; $dataObject = Loader::model('article')->getCateArticleLists($arg_where, $arg_order, $arg_field, 12); $value = [ 'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray() 'page' => $dataObject->render(), 'category' => ['id' => 0, 'name' => '新闻资讯'], ]; $value['seo_title'] = config('article_seo_title')? : config('website_seo_title_us'); $value['seo_keyword'] = config('article_seo_keyword')? : config('website_seo_keyword'); $value['seo_description'] = config('article_seo_description')? : config('website_seo_description'); $this->assign($value); return $this->fetch(); } public function catelists($id = 0) { if ($id > 0) { $category = Loader::model('ArticleCategory')->getRow($id); } if (empty($category)) { return exception('数据有误,请检查后再操作'); } switch ($category['classtype']) { case 2: $template = $category['templist']; $arg_where = ['cid' => $id, 'a.siteid' => $this->siteid, 'a.country_code' => $this->country_code]; $arg_order = ['a.id' => 'desc']; $arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.writer', 'a.source', 'a.viewcount', 'a.zancount', 'a.commentcount', 'a.description', 'a.picture', 'a.tags', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname']; $dataObject = Loader::model('Article')->getCateArticleLists($arg_where, $arg_order, $arg_field, 8); $value = [ 'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray() 'page' => $dataObject->render(), ]; break; case 3: header('location:' . $category['url']); exit; break; default: $template = $category['tempindex']; break; } $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) { $article = Loader::model('Article')->getRow($id); if (empty($article)) { return exception('数据有误,请检查后再操作'); } //$addarticle = Loader::model('ArticleAddition')->getRow(['aid' => $article['id']]); $category = Loader::model('article_category')->getRow($article['cid']); if (empty($category)) { return exception('数据有误,请检查后再操作'); } $template = $category['tempdetail']; //$prev_detail = Loader::model('Article')->getRow(['id' => ['gt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'asc']); //$next_detail = Loader::model('Article')->getRow(['id' => ['lt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'desc']); $value = [ 'detail' => $article, //'addarticle' => $addarticle, 'category' => $category, //'prev_detail' => $prev_detail, //'next_detail' => $next_detail, ]; //$topid = Loader::model('ArticleCategory')->getTopParentID($article['cid']); //$value['topid'] = $topid; $arg_where = ['content_id' => $id, 'stat' => 0, 'display' => 1]; $arg_order = ['id' => 'desc']; $arg_field = ['*']; $dataObject = Loader::model('pinglun_id')->getPageList($arg_where, $arg_order, $arg_field, 5); //header('content-type:text/html;charset=utf-8;'); $value['list'] = $dataObject->isEmpty() ? null : $dataObject->items(); $value['total'] = $dataObject->total(); $value['seo_title'] = $article['seo_title']? : $article['name'] . '-' . config('website_seo_title'); $value['seo_keyword'] = $article['seo_keyword']? : config('website_seo_keyword'); $value['seo_description'] = $article['seo_description']? : config('website_seo_description'); $this->assign($value); $this->viewcount($id); return $this->fetch($template); } else { return exception('数据有误,请检查后再操作'); } } public function zan($id = 0) { $id = intval($id); if ($id > 0) { $article = Loader::model('article')->getRow(['id' => $id], ['id', 'zancount']); if (empty($article)) { return $this->error('Error'); } $article['zancount'] = $article['zancount'] + 1; $result = $article->save(); if ($result) { return $this->success('Zan', null, $article['zancount']); } else { return $this->error('Zan Error'); } } return $this->error('Error'); } protected function viewcount($id) { $view = Cookie::get('articleview', 'history'); //print_r($history);exit; if (empty($view) || $view != $id) { Loader::model('article_id')->where(['id' => $id])->setInc('viewcount'); Cookie::set('articleview', $id, ['prefix' => 'history', 'expire' => 3600]); } } protected function historyarticle($id) { $article = Cookie::get('article', 'history'); //print_r($history);exit; if (isset($article) && !empty($article)) { $article_ids = explode(',', $article); if ($article_ids[0] != $id) { array_unshift($article_ids, $id); $article_ids = array_unique($article_ids); $num = Config::get('history_number') > 0 ? Config::get('history_number') : 10; //$article_ids = array_slice($article_ids, 0, $num); while (count($article_ids) > $num) { array_pop($article_ids); } Cookie::set('article', implode(',', $article_ids), ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]); } } else { Cookie::set('article', $id, ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]); } } }