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

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

class Goods extends BaseController
{

    /**
     * Notes:获取健康超市商品列表
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/09
     */
    public function getGoodsList()
    {
        [$page, $limit] = $this->getPage();
        $keywords = $this->request->get('keywords');
        $result         = GoodsServer::getGoodsList($page, $limit, $keywords);
        return json_success($result, '成功');
    }

    /**
     * Notes:获取所有角色
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/19
     */
    public function getGoodsAll()
    {
        $result         = GoodsServer::getGoodsAll();
        return json_success($result, '成功');
    }

    /**
     * Notes:修改健康超市商品
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/09
     */
    public function updateGoods()
    {
        $goods_id      = $this->request->post('goods_id');
        $goods_name    = $this->request->post('goods_name','');
        $goods_img   = $this->request->post('goods_img','');
        $goods_category_id    = $this->request->post('goods_category_id','');
        $goods_shop_id = $this->request->post('goods_shop_id');
        $goods_is_new = $this->request->post('goods_is_new');
        $goods_price = $this->request->post('goods_price');
        $goods_content = $this->request->post('goods_content');
        $goods_sell_num = $this->request->post('goods_sell_num');
        $goods_postage_id = $this->request->post('goods_postage_id');
        $goods_status = $this->request->post('goods_status');
        $goods_weight = $this->request->post('goods_weight');
        $goods_sort = $this->request->post('goods_sort');
        $goods_slide = $this->request->post('goods_slide','');
        $goods_pack_price = $this->request->post('goods_pack_price','');
        $food_attr = $this->request->post('goods_attr','');
        $food_varieties = $this->request->post('goods_varieties','');
        $food_packaging = $this->request->post('goods_packaging','');
        $food_storage = $this->request->post('goods_storage','');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\GoodsValidate', ['goods_id' => $goods_id, 'goods_name' => $goods_name, 'goods_img' => $goods_img, 'goods_category_id' => $goods_category_id, 'goods_shop_id' => $goods_shop_id, 'goods_is_new' => $goods_is_new, 'goods_price' => $goods_price, 'goods_content' => $goods_content, 'goods_status' => $goods_status, 'goods_postage_id' => $goods_postage_id], 'update');
        $result       = GoodsServer::updateGoods($goods_id,$goods_name,$goods_img,$goods_category_id,$goods_shop_id,$goods_is_new,$goods_price,$goods_content,$goods_sell_num,$goods_postage_id,$goods_status,$goods_weight,$goods_sort,$goods_slide,$goods_pack_price,$food_attr,$food_varieties,$food_packaging,$food_storage,$admin_id);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除商品
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function delGoods()
    {
        $goods_id = $this->request->get('goods_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\GoodsValidate', ['goods_id' => $goods_id], 'info');
        $result         = GoodsServer::delGoods($goods_id,$admin_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }

    /**
     * Notes:添加商品
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function addGoods()
    {
        $goods_name    = $this->request->post('goods_name','');
        $goods_img   = $this->request->post('goods_img');
        $goods_category_id    = $this->request->post('goods_category_id');
        $goods_shop_id = $this->request->post('goods_shop_id');
        $goods_is_new = $this->request->post('goods_is_new');
        $goods_price = $this->request->post('goods_price');
        $goods_content = $this->request->post('goods_content');
        $goods_sell_num = $this->request->post('goods_sell_num');
        $goods_postage_id = $this->request->post('goods_postage_id');
        $goods_status = $this->request->post('goods_status');
        $goods_weight = $this->request->post('goods_weight');
        $goods_sort = $this->request->post('goods_sort');
        $goods_slide = $this->request->post('goods_slide','');
        $goods_pack_price = $this->request->post('goods_pack_price','');
        $food_attr = $this->request->post('goods_attr','');
        $food_varieties = $this->request->post('goods_varieties','');
        $food_packaging = $this->request->post('goods_packaging','');
        $food_storage = $this->request->post('goods_storage','');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('life\GoodsValidate', ['goods_name' => $goods_name, 'goods_img' => $goods_img, 'goods_category_id' => $goods_category_id, 'goods_shop_id' => $goods_shop_id, 'goods_is_new' => $goods_is_new, 'goods_price' => $goods_price, 'goods_content' => $goods_content, 'goods_status' => $goods_status, 'goods_postage_id' => $goods_postage_id], 'create');
        $result         = GoodsServer::insertGoods($goods_name,$goods_img,$goods_category_id,$goods_shop_id,$goods_is_new,$goods_price,$goods_content,$goods_sell_num,$goods_postage_id,$goods_status,$goods_weight,$goods_sort,$goods_slide,$goods_pack_price,$food_attr,$food_varieties,$food_packaging,$food_storage,$admin_id);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:查询商品详情
     * @return \support\Response
     * User: ZQ
     * Date: 2022/9/13
     */
    public function goodsInfo()
    {
        $goods_id = $this->request->get('goods_id');
        $this->validateCheck('life\GoodsValidate', ['goods_id' => $goods_id], 'info');
        $result         = GoodsServer::goodsInfo($goods_id);
        return json_success($result, '成功');
    }

    /**
     * Notes:商品上架下架
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/09
     */
    public function updateStatus()
    {
        $goods_id = $this->request->get('goods_id');
        $goods_status = $this->request->get('goods_status');
        $this->validateCheck('life\GoodsValidate', ['goods_id' => $goods_id], 'info');
        $result       = GoodsServer::updateStatus($goods_id, $goods_status);
        return json_success($result, '修改成功');
    }

}
