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

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

class Package extends BaseController
{

    /**
     * Notes:获取套餐列表
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/18
     */
    public function getPackageList()
    {
        [$page, $limit] = $this->getPage();
        $keywords = $this->request->get('keywords');
        $package_type = $this->request->get('package_type');
        $result         = PackageServer::getPackageList($page, $limit, $keywords,$package_type);
        return json_success($result, '成功');
    }

    /**
     * Notes:获取所有
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/18
     */
    public function getPackageAll()
    {
        $result         = PackageServer::getPackageAll();
        return json_success($result, '成功');
    }

    /**
     * Notes:修改套餐
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/18
     */
    public function updatePackage()
    {
        $params    = $this->request->post();
        $admin_id  = $this->request->admin_id;
        $this->validateCheck('life\PackageValidate',
            [
                'package_id'        => $params['package_id']?? '',
                'package_category_id' => $params['package_category_id']?? '',
                'shop_id'           => $params['shop_id']?? '',
                'package_name'      => $params['package_name']?? '',
                'package_type'      => $params['package_type']?? '',
                'package_image'     => $params['package_image']?? '',
                'package_images'    => $params['package_images']?? '',
                'package_usetime'   => $params['package_usetime']?? '',
                'package_tags'      => $params['package_tags']?? '',
                'package_price'     => $params['package_price']?? '',
                'package_grade'     => $params['package_grade']?? '',
                'package_usefulday' => $params['package_usefulday']?? '',
                'package_starttime' => $params['package_starttime']?? '',
                'package_endtime'   => $params['package_endtime']?? '',
                'package_intro'     => $params['package_intro']?? '',
                'package_sales'     => $params['package_sales']?? '',
                'package_limit'     => $params['package_limit']?? '',
                'package_notice'    => $params['package_notice']?? '',
                'package_guarantee' => $params['package_guarantee']?? '',
            ],
            'update');
        $result       = PackageServer::updatePackage($params, $admin_id);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除套餐
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/18
     */
    public function delPackage()
    {
        $package_id = $this->request->get('package_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\PackageValidate', ['package_id' => $package_id], 'info');
        $result         = PackageServer::delPackage($package_id,$admin_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }

    /**
     * Notes:添加套餐
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/18
     */
    public function addPackage()
    {
        
        $params    = $this->request->post();
        $admin_id  = $this->request->admin_id;
        $this->validateCheck('life\PackageValidate',
            [
                'shop_id'           => $params['shop_id']?? '',
                'package_category_id' => $params['package_category_id']?? '',
                'package_name'      => $params['package_name']?? '',
                'package_type'      => $params['package_type']?? '',
                'package_image'     => $params['package_image']?? '',
                'package_images'    => $params['package_images']?? '',
                'package_usetime'   => $params['package_usetime']?? '',
                'package_tags'      => $params['package_tags']?? '',
                'package_price'     => $params['package_price']?? '',
                'package_grade'     => $params['package_grade']?? '',
                'package_usefulday' => $params['package_usefulday']?? '',
                'package_starttime' => $params['package_starttime']?? '',
                'package_endtime'   => $params['package_endtime']?? '',
                'package_intro'     => $params['package_intro']?? '',
                'package_sales'     => $params['package_sales']?? '',
                'package_limit'     => $params['package_limit']?? '',
                'package_notice'    => $params['package_notice']?? '',
                'package_guarantee' => $params['package_guarantee']?? '',
            ],
            'create');
        $result         = PackageServer::insertPackage($params, $admin_id);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:查询套餐详情
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/18
     */
    public function packageInfo()
    {
        $package_id = $this->request->get('package_id');
        $this->validateCheck('life\PackageValidate', ['package_id' => $package_id], 'info');
        $result         = PackageServer::packageInfo($package_id);
        return json_success($result, '成功');
    }


}
