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

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

class CinemaMold extends BaseController
{

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

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

    /**
     * Notes:修改影片类型
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/09
     */
    public function updateMold()
    {
        $mold_id      = $this->request->post('mold_id');
        $mold_name    = $this->request->post('mold_name');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\MoldValidate', ['mold_id' => $mold_id, 'mold_name' => $mold_name], 'update');
        $result       = MoldServer::updateMold ($mold_id, $mold_name, $admin_id);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除影片类型
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function delMold()
    {
        $mold_id = $this->request->get('mold_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\MoldValidate', ['mold_id' => $mold_id], 'info');
        $result         = MoldServer::delMold($mold_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 addMold()
    {
        $mold_name    = $this->request->post('mold_name');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\MoldValidate', ['mold_name' => $mold_name], 'create');
        $result         = MoldServer::insertMold($mold_name, $admin_id);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:查询影片类型详情
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function moldInfo()
    {
        $mold_id = $this->request->get('mold_id');
        $this->validateCheck('life\MoldValidate', ['mold_id' => $mold_id], 'info');
        $result         = MoldServer::moldInfo($mold_id);
        return json_success($result, '成功');
    }

    /**
     * Notes:影片类型上架下架
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/09
     */
    public function updateStatus()
    {
        $mold_id = $this->request->get('mold_id');
        $mold_status = $this->request->get('mold_status');
        $this->validateCheck('life\MoldValidate', ['mold_id' => $mold_id], 'info');
        $result       = MoldServer::updateStatus($mold_id, $mold_status);
        return json_success($result, '修改成功');
    }

}
