<?php
namespace app\mainapp\controller;

use think\facade\Session;
use app\mainapp\BaseController;
use app\common\model\Notice as NoticeModel;
use app\common\model\NoticeCate as NoticeCateModel;

class Notice extends BaseController
{

	// 详情
	public function getNotice()
	{
		$noticeid = input('noticeid/d', 0);
		$notice = NoticeModel::with('noticeCate')->append(['createtime_text'])->findOrEmpty($noticeid);
		if ($notice->isEmpty()){
			page_result(1, "通知公告信息不存在");
		}
		$notice->volume += 1;
		$notice->save();
		page_result(0, "", array(
			'notice' => $notice
			));
	}
	 
	// 列表
	public function listNotice()
	{
		$ppage = input('ppage/d', 1);
		$psize = input('psize/d', 20);
		$map[] = ['status','=',1];
		$map[] = ['createtime','<=',time()];
		$cateid = input('cateid/d');
		if ($cateid!=0){
			$map[] = ['cateid', '=', $cateid];
		}
		$plist = NoticeModel::with('noticeCate')->where($map)->order(['priority'=>'desc','id'=>'desc'])->page($ppage)->limit($psize)->append(['createtime_text'])->select();
		page_result(0, "", array(
			'plist' => $plist,
			'pstatus' => $psize > count($plist) ? 'noMore' : 'more'
			));
	}

	// 全部分类
	public function allCate()
	{
		$allcate = NoticeCateModel::where('status',1)->order(['priority'=>'desc','id'=>'desc'])->select()->toArray();
		array_unshift( $allcate, array('id'=>0,'title'=>'全部') );
		page_result(0, "", array('allcate'=>$allcate));
	}


}