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

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

class PackageGoods extends BaseController
{

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

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

    /**
     * Notes:修改套餐项目
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/18
     */
    public function updatePackageGoods()
    {
        $params    = $this->request->post();
        $admin_id  = $this->request->admin_id;
        $this->validateCheck('life\PackageGoodsValidate',
            [
                'goods_id'        => $params['goods_id']?? '',
                'package_id'           => $params['package_id']?? '',
                'goods_name'      => $params['goods_name']?? '',
                'goods_num'     => $params['goods_num']?? '',
                'goods_price'    => $params['goods_price']?? '',
                'goods_weigh'   => $params['goods_weigh']?? '',
            ],
            'update');
        $result       = PackageGoodsServer::updatePackageGoods($params, $admin_id);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除套餐项目
     * @return \support\Response
     * User: YCP
     * Date: 2022/10/18
     */
    public function delPackageGoods()
    {
        $goods_id = $this->request->get('goods_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\PackageGoodsValidate', ['goods_id' => $goods_id], 'info');
        $result         = PackageGoodsServer::delPackageGoods($goods_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 addPackageGoods()
    {
        
        $params    = $this->request->post();
        $admin_id  = $this->request->admin_id;
        $this->validateCheck('life\PackageGoodsValidate',
            [
                'package_id'      => $params['package_id']?? '',
                'goods_name'      => $params['goods_name']?? '',
                'goods_num'     => $params['goods_num']?? '',
                'goods_price'    => $params['goods_price']?? '',
                'goods_weigh'   => $params['goods_weigh']?? '',
            ],
            'create');
        $result         = PackageGoodsServer::insertPackageGoods($params, $admin_id);
        return json_success($result, '添加成功');
    }

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


}
