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

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

class CinemaScheduling extends BaseController
{

    /**
     * Notes:获取排期列表
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/09
     */
    public function getSchedulingList()
    {
        [$page, $limit] = $this->getPage();
        $keywords = $this->request->get('keywords');
        $result         = SchedulingServer::getSchedulingList($page, $limit, $keywords);
        return json_success($result, '成功');
    }

    /**
     * Notes:获取所有
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/19
     */
    public function getSchedulingAll()
    {
        $result         = SchedulingServer::getSchedulingAll();
        return json_success($result, '成功');
    }

    /**
     * Notes:修改排期
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/09
     */
    public function updateScheduling()
    {
        $scheduling_id      = $this->request->post('scheduling_id');
        $scheduling_start_time    = $this->request->post('scheduling_start_time');
        $scheduling_end_time     = $this->request->post('scheduling_end_time');
        $scheduling_cinema_id    = $this->request->post('scheduling_cinema_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\SchedulingValidate', ['scheduling_id' => $scheduling_id, 'scheduling_start_time' => $scheduling_start_time, 'scheduling_end_time' => $scheduling_end_time, 'scheduling_cinema_id' => $scheduling_cinema_id], 'update');
        $result       = SchedulingServer::updateScheduling($scheduling_id, $scheduling_start_time, $scheduling_end_time, $scheduling_cinema_id, $admin_id);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除排期
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function delScheduling()
    {
        $scheduling_id = $this->request->get('scheduling_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\SchedulingValidate', ['scheduling_id' => $scheduling_id], 'info');
        $result         = SchedulingServer::delScheduling($scheduling_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 addScheduling()
    {
        $admin_id = $this->request->admin_id;
        $scheduling_start_time    = $this->request->post('scheduling_start_time');
        $scheduling_end_time     = $this->request->post('scheduling_end_time');
        $scheduling_cinema_id    = $this->request->post('scheduling_cinema_id');
        $this->validateCheck('life\SchedulingValidate', ['scheduling_start_time' => $scheduling_start_time, 'scheduling_end_time' => $scheduling_end_time, 'scheduling_cinema_id' => $scheduling_cinema_id], 'create');
        $result         = SchedulingServer::insertScheduling($scheduling_start_time, $scheduling_end_time, $scheduling_cinema_id, $admin_id);
        return json_success($result, '添加成功');
    }

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

    /**
     * Notes:排期上架下架
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/09
     */
    public function updateStatus()
    {
        $scheduling_id = $this->request->get('scheduling_id');
        $scheduling_status = $this->request->get('scheduling_status');
        $this->validateCheck('life\SchedulingValidate', ['scheduling_id' => $scheduling_id], 'info');
        $result       = SchedulingServer::updateStatus($scheduling_id, $scheduling_status);
        return json_success($result, '修改成功');
    }

}
