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

use app\admin\controller\BaseController;
use app\admin\server\life\BookSchedulingServer;

class BookScheduling extends BaseController
{

    /**
     * Notes:获取万悦书院课程排期列表
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/25
     */
    public function getBookSchedulingList()
    {
        [$page, $limit] = $this->getPage();
        $keywords = $this->request->get('keywords');
        $result         = BookSchedulingServer::getBookSchedulingList($page, $limit, $keywords);
        return json_success($result, '成功');
    }

    /**
     * Notes:获取所有课程排期
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/25
     */
    public function getBookSchedulingAll()
    {
        $result         = BookSchedulingServer::getBookSchedulingAll();
        return json_success($result, '成功');
    }

    /**
     * Notes:修改万悦书院排期
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/25
     */
    public function updateBookScheduling()
    {
        $scheduling_id      = $this->request->post('scheduling_id');
        $scheduling_book_id    = $this->request->post('scheduling_book_id');
        $scheduling_start_time    = $this->request->post('scheduling_start_time');
        $scheduling_end_time = $this->request->post('scheduling_end_time');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\BookSchedulingValidate', ['scheduling_id'=>$scheduling_id,'scheduling_book_id'=>$scheduling_book_id,'scheduling_start_time'=>$scheduling_start_time,'scheduling_book_id'=>$scheduling_book_id,'scheduling_end_time'=>$scheduling_end_time], 'update');
        $result       = BookSchedulingServer::updateBookScheduling($scheduling_id, $scheduling_book_id, $scheduling_start_time, $scheduling_end_time, $admin_id);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除课程排期
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/25
     */
    public function delBookScheduling()
    {
        $scheduling_id = $this->request->get('scheduling_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\BookSchedulingValidate', ['scheduling_id' => $scheduling_id], 'info');
        $result         = BookSchedulingServer::delBookScheduling($scheduling_id,$admin_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }

    /**
     * Notes:添加课程排期
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/25
     */
    public function addBookScheduling()
    {
        $scheduling_book_id    = $this->request->post('scheduling_book_id');
        $scheduling_start_time    = $this->request->post('scheduling_start_time');
        $scheduling_end_time = $this->request->post('scheduling_end_time');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\BookSchedulingValidate', ['scheduling_book_id'=>$scheduling_book_id,'scheduling_start_time'=>$scheduling_start_time,'scheduling_book_id'=>$scheduling_book_id,'scheduling_end_time'=>$scheduling_end_time], 'create');
        $result         = BookSchedulingServer::insertBookScheduling($scheduling_book_id, $scheduling_start_time, $scheduling_end_time, $admin_id);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:查询课程排期详情
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/25
     */
    public function schedulingInfo()
    {
        $scheduling_id = $this->request->get('scheduling_id');
        $this->validateCheck('life\BookSchedulingValidate', ['scheduling_id' => $scheduling_id], 'info');
        $result         = BookSchedulingServer::schedulingInfo($scheduling_id);
        return json_success($result, '成功');
    }

}
