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

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

class BookCourse extends BaseController
{

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

    /**
     * Notes:获取所有课程目录
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/14
     */
    public function getBookCourseAll()
    {
        $result         = BookCourseServer::getBookCourseAll();
        return json_success($result, '成功');
    }

    /**
     * Notes:修改万悦书院
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/09
     */
    public function updateBookCourse()
    {
        $course_id      = $this->request->post('course_id');
        $course_name    = $this->request->post('course_name');
        $course_time    = $this->request->post('course_time');
        $course_book_id = $this->request->post('course_book_id');
        $course_price = $this->request->post('course_price');
        $course_status = $this->request->post('course_status');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\BookCourseValidate', ['course_id'=>$course_id,'course_name'=>$course_name,'course_time'=>$course_time,'course_book_id'=>$course_book_id,'course_price'=>$course_price,'course_status'=>$course_status], 'update');
        $result       = BookCourseServer::updateBookCourse($course_id, $course_name, $course_time, $course_book_id, $course_price, $course_status, $admin_id);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除课程目录
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function delBookCourse()
    {
        $course_id = $this->request->get('course_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\BookCourseValidate', ['course_id' => $course_id], 'info');
        $result         = BookCourseServer::delBookCourse($course_id,$admin_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }

    /**
     * Notes:添加课程目录
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function addBookCourse()
    {
        $course_name    = $this->request->post('course_name');
        $course_time    = $this->request->post('course_time');
        $course_book_id = $this->request->post('course_book_id');
        $course_price = $this->request->post('course_price');
        $course_status = $this->request->post('course_status');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\BookCourseValidate', ['course_name'=>$course_name,'course_time'=>$course_time,'course_book_id'=>$course_book_id,'course_price'=>$course_price,'course_status'=>$course_status], 'create');
        $result         = BookCourseServer::insertBookCourse($course_name, $course_time, $course_book_id, $course_price, $course_status, $admin_id);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:查询课程目录详情
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function courseInfo()
    {
        $course_id = $this->request->get('course_id');
        $this->validateCheck('life\BookCourseValidate', ['course_id' => $course_id], 'info');
        $result         = BookCourseServer::courseInfo($course_id);
        return json_success($result, '成功');
    }

    /**
     * Notes:课程目录上架下架
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/09
     */
    public function updateStatus()
    {
        $course_id = $this->request->get('course_id');
        $course_status = $this->request->get('course_status');
        $this->validateCheck('life\BookCourseValidate', ['course_id' => $course_id], 'info');
        $result       = BookCourseServer::updateStatus($course_id, $course_status);
        return json_success($result, '修改成功');
    }

}
