$this->country_code]; $arg_order = ['a.id' => 'desc']; $search = array(); $skeyword = $this->request->get('name', '', 'urldecode,strval'); if ($skeyword != '') { $search['skeyword'] = $skeyword; $arg_where['a.name'] =['like', '%' . $search['skeyword'] . '%']; $search['name'] = $skeyword; Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数 } $cate_list = model('article_category')->where(['country_code' => $this->country_code, 'pid' => 0, 'isshow' => 1, 'stat' => 0])->order(['sort' => 'asc'])->select(); $arg_where['a.cid'] = reset($cate_list)['id']; $arg_order = ['a.id' => 'desc']; $arg_field = ['a.id', 'a.cid', 'a.name', 'a.jump_link','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); //echo Loader::model('Article')->getLastSql(); die; $value = [ 'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray() 'page' => $dataObject->render(), 'category' => ['id' => reset($cate_list)['id'], 'name' => '新闻资讯'], ]; $value['cate_list'] = $cate_list; $value['seo_title'] = config('article_seo_title')? : config('website_seo_title'); $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); $this->assign('search',$search); return $this->fetch(); } public function catelists($id = 0) { if ($id > 0) { $category = Loader::model('ArticleCategory')->getRow($id); } if (empty($category)) { return exception('数据有误,请检查后再操作'); } $arg_where = ['cid' => $id, 'a.country_code' => $this->country_code]; $skeyword = $this->request->get('name', '', '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.jump_link', '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; } //echo "
=="; print_r($dataObject);die;
        $cate_list = model('article_category')->where(['country_code' => $this->country_code, 'pid' => 0, 'isshow' => 1, 'stat' => 0])->order(['sort' => 'asc'])->select();
        $value['cate_list'] = $cate_list;
        $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) {
            //$jssdk=new \JsSdk\JsSdk('wx0d4ac6d59abca442','8103022bb6ed902eb5c685800a78fd51');
            //$signPackage = $jssdk->getSignPackage();
            //$this->assign('singpackage',$signPackage);

            $article = Loader::model('Article')->getRow($id);
            if (empty($article)) {
                return exception('数据有误,请检查后再操作');
            }

            $category = Loader::model('ArticleCategory')->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,
            ];

            $arg_where = ['content_id' => $id, 'stat' => 0, 'display' => 1];
            $arg_order = ['id' => 'desc'];
            $arg_field = ['*'];
            $dataObject = Loader::model('Pinglun')->getPageList($arg_where, $arg_order, $arg_field, 4);
            $list = $dataObject->items();

            foreach ($list as $key => $v) {
                $list[$key]['headimg'] = '';
                $result = Loader::model('customer')->where(['stat' => 0, 'id' => 23])->field('picture')->find();
                if (!empty($result) && isset($result['picture'])) {
                    $list[$key]['headimg'] = $result['picture'];
                }
            }

            $value['list'] = $dataObject->isEmpty() ? null : $list;
            $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->json(-1, '该新闻不存在');
            }
            $article['zancount'] = $article['zancount'] + 1;
            $result = $article->save();
            if ($result) {
                return $this->json(1, '点赞成功',$article['zancount']);
            } else {
                return $this->json(-1, '点赞失败');
            }
        }
        return $this->json(-1, 'id错误');
    }

    protected function viewcount($id) {
        $view = Cookie::get('articleview', 'history'); //print_r($history);exit;
        if (empty($view) || $view != $id) {
            Loader::model('Article')->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]);
        }
    }

}