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

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

class CinemaPerformers extends BaseController
{

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

    /**
     * Notes:获取所有
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/19
     */
    public function getPerformersAll()
    {
        $type = $this->request->get('type');
        $result         = PerformersServer::getPerformersAll($type);
        return json_success($result, '成功');
    }

    /**
     * Notes:修改演职
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/09
     */
    public function updatePerformers()
    {
        $performers_id      = $this->request->post('performers_id');
        $performers_name    = $this->request->post('performers_name');
        $performers_img     = $this->request->post('performers_img');
        $performers_type    = $this->request->post('performers_type');
        $performers_introduction    = $this->request->post('performers_introduction');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\PerformersValidate', ['performers_id' => $performers_id, 'performers_name' => $performers_name, 'performers_img' => $performers_img, 'performers_type' => $performers_type], 'update');
        $result       = PerformersServer::updatePerformers($performers_id, $performers_name, $performers_img, $performers_type, $performers_introduction, $admin_id);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除演职
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function delPerformers()
    {
        $performers_id = $this->request->get('performers_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\PerformersValidate', ['performers_id' => $performers_id], 'info');
        $result         = PerformersServer::delPerformers($performers_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 addPerformers()
    {
        $performers_name    = $this->request->post('performers_name');
        $admin_id = $this->request->admin_id;
        $performers_img     = $this->request->post('performers_img');
        $performers_type    = $this->request->post('performers_type');
        $performers_introduction    = $this->request->post('performers_introduction');
        $this->validateCheck('life\PerformersValidate', ['performers_name' => $performers_name,'performers_img'=>$performers_img,'performers_type'=>$performers_type], 'create');
        $result         = PerformersServer::insertPerformers($performers_name, $performers_img, $performers_type, $performers_introduction, $admin_id);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:查询演职详情
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function performersInfo()
    {
        $performers_id = $this->request->get('performers_id');
        $this->validateCheck('life\PerformersValidate', ['performers_id' => $performers_id], 'info');
        $result         = PerformersServer::performersInfo($performers_id);
        return json_success($result, '成功');
    }

    /**
     * Notes:演职上架下架
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/09
     */
    public function updateStatus()
    {
        $performers_id = $this->request->get('performers_id');
        $performers_status = $this->request->get('performers_status');
        $this->validateCheck('life\PerformersValidate', ['performers_id' => $performers_id], 'info');
        $result       = PerformersServer::updateStatus($performers_id, $performers_status);
        return json_success($result, '修改成功');
    }

}
