<?php
namespace app\admin\controller\notice;

use app\admin\controller\BaseController;
use app\admin\server\notice\NoticetServer;

class Notice extends BaseController
{

    /**
     * Notes:获取预约科目列表
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/29
     */
    public function getNoticeList()
    {
        $keywords = $this->request->get('keywords');
        $result         = NoticeServer::getNoticeList($keywords);
        return json_success($result, '成功');
    }

    /**
     * Notes:修改预约科目
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/29
     */
    public function updateNotice()
    {
        $notice_id      = $this->request->post('notice_id');
        $notice_title    = $this->request->post('notice_title','');
        $notice_introduce     = $this->request->post('notice_introduce','');
        $notic_content    = $this->request->post('notic_content','');
        $this->validateCheck('notice\NoticeValidate', ['notice_id'=>$notice_id], 'update');
        $result         = NoticeServer::updateNotice($notice_id, $notice_title, $notice_introduce, $notic_content);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除预约科目
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/27
     */
    public function delNotice()
    {
        $notice_id = $this->request->get('notice_id');
        $this->validateCheck('notice\NoticeValidate', ['notice_id' => $notice_id], 'info');
        $result         = NoticeServer::delNotice($notice_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }

    /**
     * Notes:添加预约科目
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/27
     */
    public function addNotice()
    {
        $notice_title    = $this->request->post('notice_title','');
        $notice_introduce     = $this->request->post('notice_introduce','');
        $notic_content    = $this->request->post('notic_content','');
        $this->validateCheck('notice\NoticeValidate', ['notice_title' => $notice_title, 'notice_introduce' => $notice_introduce, 'notic_content' => $notic_content], 'create');
        $result         = NoticeServer::insertNotice($notice_title, $notice_introduce, $notic_content);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:查询预约科目详情
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/27
     */
    public function noticeInfo()
    {
        $notice_id = $this->request->get('notice_id');
        $this->validateCheck('notice\NoticeValidate', ['notice_id' => $notice_id], 'info');
        $result         = NoticeServer::noticeInfo($notice_id);
        if (!empty($result))
        return json_success($result, '成功');
    }

}
