<?php
namespace app\web\controller;

use app\web\BaseController;
use app\common\model\Article as ArticleModel;
use app\common\model\ArticleCate as ArticleCateModel;

class Article extends BaseController
{
	
	

	public function detail()
	{
		$articleid = input('articleid/d', 0);
		$article = ArticleModel::with('articleCate')->append(['createtime_text'])->findOrEmpty($articleid);
		if (!$article->isEmpty()){
			$article->volume	+=  1;
			$article->save();
		}
		return view('article/detail', [
			'article'		=> $article
		]);
	}
	
	
	public function article()
	{
		$catelist = ArticleCateModel::field('id as value, title, priority')->order(['priority'=>'desc','id'=>'desc'])->select()->toArray();
		array_unshift( $catelist, array('value'=>0,'title'=>'不限') );

		$page = input('page/d',1);
		$map = array();
		$keywords = input('keywords/s', "");
		if (!empty($keywords)){
			$map[] =['title', 'like', '%'.$keywords.'%'];
		}
		$cateid = input('cateid/d', 0);
		if (!empty($cateid)){
			$map[] = ['cateid', '=', $cateid];
		}
		$list = ArticleModel::with(['articleCate'])->where($map)->order(['priority'=>'desc','id'=>'desc',])->page($page)->paginate(['list_rows'=>10,'query' => request()->param()]);
		$pageview = $list->render();
		return view('article/article', [
			'keywords'	=> $keywords,
			'cateid'	=> $cateid,
			'catelist'	=> $catelist,
			'list'		=> $list,
			'pageview'	=> $pageview
		]);
	}
	
}
		