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

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

class Book extends BaseController
{

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

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

    /**
     * Notes:修改万悦书院
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/09
     */
    public function updateBook()
    {
        $life_book_id      = $this->request->post('life_book_id');
        $life_book_name    = $this->request->post('life_book_name');
        $life_book_title   = $this->request->post('life_book_title');
        $life_book_time    = $this->request->post('life_book_time');
        $life_book_week    = $this->request->post('life_book_week');
        $life_book_category_id = $this->request->post('life_book_category_id');
        $life_book_teacher_id = $this->request->post('life_book_teacher_id');
        $life_book_num = $this->request->post('life_book_num');
        $life_book_long = $this->request->post('life_book_long','');
        $life_book_week = $this->request->post('life_book_week','');
        $life_book_status = $this->request->post('life_book_status');
        $life_book_img = $this->request->post('life_book_img');
        $life_book_type = $this->request->post('life_book_type');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\BookValidate', ['life_book_id'=>$life_book_id,'life_book_name'=>$life_book_name,'life_book_title'=>$life_book_title,'life_book_time'=>$life_book_time,'life_book_category_id'=>$life_book_category_id,'life_book_teacher_id'=>$life_book_teacher_id,'life_book_num'=>$life_book_num,'life_book_status'=>$life_book_status,'life_book_img'=>$life_book_img,'life_book_type'=>$life_book_type], 'update');
        $result       = BookServer::updateBook($life_book_id, $life_book_name, $life_book_title, $life_book_time, $life_book_category_id, $life_book_teacher_id, $life_book_num, $life_book_status, $life_book_img, $life_book_type, $life_book_long, $life_book_week, $admin_id);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除课程
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function delBook()
    {
        $life_book_id = $this->request->get('life_book_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\BookValidate', ['life_book_id' => $life_book_id], 'info');
        $result         = BookServer::delBook($life_book_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 addBook()
    {
        $life_book_name    = $this->request->post('life_book_name');
        $life_book_title   = $this->request->post('life_book_title');
        $life_book_time    = $this->request->post('life_book_time');
        $life_book_week    = $this->request->post('life_book_week');
        $life_book_category_id = $this->request->post('life_book_category_id');
        $life_book_teacher_id = $this->request->post('life_book_teacher_id');
        $life_book_num = $this->request->post('life_book_num');
        $life_book_long = $this->request->post('life_book_long','');
        $life_book_week = $this->request->post('life_book_week','');
        $life_book_status = $this->request->post('life_book_status');
        $life_book_img = $this->request->post('life_book_img');
        $life_book_type = $this->request->post('life_book_type');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\BookValidate', ['life_book_name'=>$life_book_name,'life_book_title'=>$life_book_title,'life_book_time'=>$life_book_time,'life_book_category_id'=>$life_book_category_id,'life_book_teacher_id'=>$life_book_teacher_id,'life_book_num'=>$life_book_num,'life_book_status'=>$life_book_status,'life_book_img'=>$life_book_img,'life_book_type'=>$life_book_type], 'create');
        $result         = BookServer::insertBook($life_book_name, $life_book_title, $life_book_time, $life_book_category_id, $life_book_teacher_id, $life_book_num, $life_book_status, $life_book_img, $life_book_type, $life_book_long, $life_book_week, $admin_id);
        return json_success($result, '添加成功');
    }

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

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

}
