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

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

class Play extends BaseController
{

    /**
     * Notes:获取农庄美食/采摘游玩列表
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/18
     */
    public function getPlayList()
    {
        [$page, $limit] = $this->getPage();
        $keywords = $this->request->get('keywords');
        $result         = PlayServer::getPlayList($page, $limit, $keywords);
        return json_success($result, '成功');
    }

    /**
     * Notes:获取所有农庄美食/采摘游玩单品
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/18
     */
    public function getPlayAll()
    {
//        $play_category_id = $this->request->get('play_category_id');
        $result         = PlayServer::getPlayAll();
        return json_success($result, '成功');
    }

    /**
     * Notes:修改农庄美食/采摘游玩
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/18
     */
    public function updatePlay()
    {
        $play_id            = $this->request->post('play_id');
        $play_name          = $this->request->post('play_name');
        $play_img           = $this->request->post('play_img');
        $play_price         = $this->request->post('play_price');
        $play_shop_id       = $this->request->post('play_shop_id');
        $play_valid         = $this->request->post('play_valid','');
        $play_time          = $this->request->post('play_time','');
        $play_type          = $this->request->post('play_type');
        $play_package       = $this->request->post('play_package','');
        $play_label         = $this->request->post('play_label');
        $play_content       = $this->request->post('play_content');
        $play_category      = $this->request->post('play_category');
        $play_status        = $this->request->post('play_status');
        $admin_id           = $this->request->admin_id;
        $this->validateCheck('life\PlayValidate', ['play_id'=>$play_id,'play_name'=>$play_name,'play_img'=>$play_img,'play_price'=>$play_price,'play_shop_id'=>$play_shop_id,'play_valid'=>$play_valid,'play_time'=>$play_time,'play_type'=>$play_type,'play_label'=>$play_label,'play_status'=>$play_status,'play_content'=>$play_content,'play_category'=>$play_category], 'update');
        $result       = PlayServer::updatePlay($play_id, $play_name, $play_img, $play_price, $play_shop_id, $play_valid, $play_time, $play_type, $play_package, $play_label, $play_status, $play_content, $play_category, $admin_id);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除农庄美食/采摘游玩
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/18
     */
    public function delPlay()
    {
        $play_id = $this->request->get('play_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\PlayValidate', ['play_id' => $play_id], 'info');
        $result         = PlayServer::delPlay($play_id,$admin_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }

    /**
     * Notes:添加农庄美食/采摘游玩
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/18
     */
    public function addPlay()
    {
        $play_name          = $this->request->post('play_name');
        $play_img           = $this->request->post('play_img');
        $play_price         = $this->request->post('play_price');
        $play_shop_id       = $this->request->post('play_shop_id');
        $play_valid         = $this->request->post('play_valid','');
        $play_time          = $this->request->post('play_time','');
        $play_type          = $this->request->post('play_type');
        $play_package       = $this->request->post('play_package','');
        $play_label         = $this->request->post('play_label');
        $play_content        = $this->request->post('play_content');
        $play_status        = $this->request->post('play_status');
        $play_category      = $this->request->post('play_category');
        $admin_id           = $this->request->admin_id;
        $this->validateCheck('life\PlayValidate', ['play_name'=>$play_name,'play_img'=>$play_img,'play_price'=>$play_price,'play_shop_id'=>$play_shop_id,'play_valid'=>$play_valid,'play_time'=>$play_time,'play_type'=>$play_type,'play_label'=>$play_label,'play_status'=>$play_status,'play_content'=>$play_content,'play_category'=>$play_category], 'create');
        $result         = PlayServer::insertPlay($play_name, $play_img, $play_price, $play_shop_id, $play_valid, $play_time, $play_type, $play_package, $play_label, $play_status, $play_content, $play_category, $admin_id);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:查询农庄美食/采摘游玩详情
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/18
     */
    public function playInfo()
    {
        $play_id = $this->request->get('play_id');
        $this->validateCheck('life\PlayValidate', ['play_id' => $play_id], 'info');
        $result         = PlayServer::playInfo($play_id);
        return json_success($result, '成功');
    }

    /**
     * Notes:农庄美食/采摘游玩上架下架
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/18
     */
    public function updateStatus()
    {
        $play_id = $this->request->get('play_id');
        $play_status = $this->request->get('play_status');
        $this->validateCheck('life\PlayValidate', ['play_id' => $play_id], 'info');
        $result       = PlayServer::updateStatus($play_id, $play_status);
        return json_success($result, '修改成功');
    }

}
