<?php

namespace app\common\controller;

use app\BaseController;
use app\common\middleware\Auth;
use app\admin\model\Notice as NoticeModel;

/**
 * Description of Notice
 *
 * @author sgq
 */
class Notice extends BaseController {

    protected $middleware = [Auth::class];

    /**
     * 通知列表
     * @return type
     */
    public function index() {
        $total = NoticeModel::count();
        return view("", ["total" => $total]);
    }

    /**
     * 显示通知详情
     */
    public function view() {
        $id = $this->request->param("id");
        $row = \app\common\api\NoticeApi::getOne($id);
        $creater = \app\admin\api\UserApi::getOne($row["creater"]);
        return view("", ["row" => $row, "creater" => $creater]);
    }

    public function list() {
        if ($this->request->isAjax()) {
            $pageSize = $this->request->param("pageSize") ?: 6;
            $page = $this->request->param("page") ?: 1;
            $list = NoticeModel::where('batch', 'null')->whereOr('batch', "")->order(["isTop", "topTime" => "desc", "createTime" => "desc"])->page($page, $pageSize)->select();
            return json($list);
        }
    }

}
