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

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

class Package extends BaseController
{
    /**
     * Notes:获取权益包列表
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/19
     */
    public function getPackageList()
    {
        $keywords = $this->request->get('keywords');
        [$page, $limit] = $this->getPage();

        $result         = PackageServer::getPackageList($page, $limit,$keywords);
        return json_success($result, '成功');
    }
    /**
     * Notes:添加权益包
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/19
     *
     */
    public function addPackage()
    {
        $param     = $this->request->post();
        $this->validateCheck('package\PackageValidate',
            [
                'package_name'          => $param['package_name'],
                'package_img'           => $param['package_img'],
                'package_logo'          => $param['package_logo'],
                'package_type'          => $param['package_type'],
                'package_content'       => $param['package_content'],
                'package_product_ids'   => $param['package_product_ids'],
            ],
            'add');
        $result         = PackageServer::insertPackage($param);
        return json_success($result, '添加成功');
    }
    /**
     * Notes:修改权益包
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/19
     */
    public function updatePackage()
    {
        $param      = $this->request->post();
        $this->validateCheck('package\PackageValidate',
            [
                'package_id'            => $param['package_id'],
            ], 'update');
         $result         = PackageServer::updatePackage($param);
        return json_success($result, '修改成功');
    }

    /**
     * Notes:删除权益包
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/19
     */
    public function delPackage()
    {
        $package_id = $this->request->get('package_id');
        $this->validateCheck('package\PackageValidate', ['package_id' => $package_id], 'del');
        $result         = PackageServer::delPackage($package_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }


    /**
     * Notes:查看权益包详情
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/19
     */
    public function infoPackage()
    {
        $package_id = $this->request->get('package_id');
        $this->validateCheck('package\PackageValidate', ['package_id' => $package_id], 'info');
        $result         = PackageServer::infoPackage($package_id);
        if ($result){
            return json_success($result, '获取成功');
        }else{
            throw new \Exception('获取失败！');
        }

    }
}
