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

use app\admin\controller\BaseController;
use app\admin\server\intelligence\ProductServer;

class Product extends BaseController
{

    /**
     * Notes:获取智能产品列表
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/19
     */
    public function getProductList()
    {
        [$page, $limit] = $this->getPage();
        $keywords = $this->request->get('keywords');
        $result         = ProductServer::getProductList($page, $limit, $keywords);
        return json_success($result, '成功');
    }

    /**
     * Notes:获取所有智能产品
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/19
     */
    public function getProductAll()
    {
        $result         = ProductServer::getProductAll();
        return json_success($result, '成功');
    }

    /**
     * Notes:修改智能产品
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function updateProduct()
    {
        $product_id      = $this->request->post('product_id');
        $product_category_id    = $this->request->post('product_category_id');
        $product_name   = $this->request->post('product_name');
        $product_content    = $this->request->post('product_content');
        $this->validateCheck('intelligence\ProductValidate', ['product_id' => $product_id], 'update');
        $result       = ProductServer::updateProduct($product_id, $product_category_id, $product_name, $product_content);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除智能产品
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/119
     */
    public function delProduct()
    {
        $product_id = $this->request->get('product_id');
        $this->validateCheck('intelligence\ProductValidate', ['product_id' => $product_id], 'info');
        $result         = ProductServer::delProduct($product_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }

    /**
     * Notes:添加智能产品
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/19
     */
    public function addProduct()
    {
        $product_category_id = $this->request->post('product_category_id');
        $product_name         = $this->request->post('product_name');
        $product_content      = $this->request->post('product_content');
        $this->validateCheck('intelligence\ProductValidate', ['product_category_id' => $product_category_id, 'product_name' => $product_name], 'create');
        $result               = ProductServer::insertProduct($product_name, $product_category_id, $product_content);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:查询智能产品详情
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/19
     */
    public function productInfo()
    {
        $product_id = $this->request->get('product_id');
        $this->validateCheck('intelligence\ProductValidate', ['product_id' => $product_id], 'info');
        $result         = ProductServer::productInfo($product_id);
        return json_success($result, '成功');
    }

}
