<?php

use App\Base\Base;
use App\Services\goods\GoodsService;
use App\Services\goods\CategoryService;
use \Validate\CheckGoodsNameValidate;
use \Validate\GoodsAuditValidate;
use \Validate\GoodsAddValidate;
use \Validate\GoodsEditValidate;
use \Validate\GoodsInfoOpValidate;
use \Validate\GoodsInfoFeValidate;


class GoodsController extends Base
{
    /**
     * 获取商品分类列表
     */
    public function get_goods_category_listAction()
    {
        $categoryList = CategoryService::getCategoryList();
        $this->success(["data" => $categoryList]);
    }

    /**
     * 增加商品
     */
    public function addAction()
    {
        (new GoodsAddValidate())->validate();

        $params = $this->params;
        GoodsService::addGoods($params);
        $this->success();
    }

    /**
     * 编辑商品
     */
    public function editAction()
    {
        (new GoodsEditValidate())->validate();

        $params = $this->params;
        GoodsService::editGoods($params);
        $this->success();
    }

    /**
     * 后台商品详情
     */
    public function info_opAction()
    {
        (new GoodsInfoOpValidate())->validate();

        $params = $this->params;
        $data = GoodsService::getGoodsSpuInfo($params);
        $this->success(["data"=>$data]);
    }

    /**
     * 前端商品详情
     */
    public function info_feAction()
    {
        (new GoodsInfoFeValidate())->validate();

        $params = $this->params;
        $data = GoodsService::getGoodsSkuInfo($params);
        $this->success(["data"=>$data]);
    }

    /**
     * 上下架
     * @throws \App\Exception\custom\GoodsException
     * @throws \App\Exception\custom\ParamException
     */
    public function online_offlineAction()
    {
        (new GoodsAuditValidate())->validate();

        $params = $this->params;
        GoodsService::onlineOrOffline($params);
        $this->success();
    }

    /**
     * 审核通过/驳回
     */
    public function auditAction()
    {
        (new GoodsAuditValidate())->validate();

        $params = $this->params;
        GoodsService::audit($params);
        $this->success();
    }

    /**
     * 判断商品名称是否可用
     */
    public function check_goods_nameAction()
    {
        (new CheckGoodsNameValidate())->validate();

        $params = $this->params;
        $res = GoodsService::checkGoodsName($params["name"], $params["life_account_id"]);
        $this->success(["data" => $res]);
    }

    /**
     * op后台：商品列表 (spu list)
     */
    public function goods_list_opAction()
    {

    }

    /**
     * b端：商品列表（spu list）
     */
    public function goods_list_bAction()
    {

    }

    /**
     * c端 es：商品列表 (sku list)
     */
    public function goods_list_cAction()
    {

    }
}