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

use app\admin\controller\BaseController;
use app\admin\server\raise\RaiseOldGoodsServer;

class RaiseOldGoods extends BaseController
{

    /**
     * Notes:获取养老产品列表
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/31
     */
    public function getGoodsList()
    {
        [$page, $limit] = $this->getPage();
        $keywords = $this->request->get('keywords');
        $result         = RaiseOldGoodsServer::getGoodsList($page, $limit, $keywords);
        return json_success($result, '成功');
    }

    /**
     * Notes:获取所有养老产品
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/31
     */
    public function getGoodsAll()
    {
        $result         = RaiseOldGoodsServer::getGoodsAll();
        return json_success($result, '成功');
    }

    /**
     * Notes:修改养老产品
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/31
     */
    public function updateGoods()
    {
        $goods_id      = $this->request->post('goods_id');
        $goods_name    = $this->request->post('goods_name');
        $goods_shop_id = $this->request->post('goods_shop_id');
        $goods_title   = $this->request->post('goods_title','');
        $goods_banner    = $this->request->post('goods_banner','');
        $goods_category_id = $this->request->post('goods_category_id');
        $goods_label = $this->request->post('goods_label','');
        $goods_price = $this->request->post('goods_price');
        $goods_status = $this->request->post('goods_status');
        $goods_time = $this->request->post('goods_time','');
        $goods_service_population = $this->request->post('goods_service_population','');
        $goods_service_consumables = $this->request->post('goods_service_consumables','');
        $goods_service_qualifications = $this->request->post('goods_service_qualifications','');
        $goods_service_explain = $this->request->post('goods_service_explain','');
        $goods_service_standard = $this->request->post('goods_service_standard','');
        $goods_service_process = $this->request->post('goods_service_process','');
        $goods_technological = $this->request->post('goods_technological','');
        $goods_tips = $this->request->post('goods_tips','');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('raise\RaiseOldGoodsValidate', ['goods_id'=>$goods_id,'goods_name'=>$goods_name,'goods_price'=>$goods_price,'goods_time'=>$goods_time,'goods_category_id'=>$goods_category_id,'goods_shop_id'=>$goods_shop_id,'goods_status'=>$goods_status], 'update');
        $result       = RaiseOldGoodsServer::updateGoods($goods_id, $goods_name, $goods_title, $goods_time, $goods_category_id, $goods_banner, $goods_label, $goods_status, $goods_service_population, $goods_service_consumables, $goods_service_qualifications, $goods_service_explain, $goods_service_standard, $goods_service_process, $goods_technological, $goods_tips, $goods_shop_id, $goods_price, $admin_id);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除养老产品
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/31
     */
    public function delGoods()
    {
        $goods_id = $this->request->get('goods_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('raise\RaiseOldGoodsValidate', ['goods_id' => $goods_id], 'info');
        $result         = RaiseOldGoodsServer::delGoods($goods_id,$admin_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }

    /**
     * Notes:添加养老产品
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/31
     */
    public function addGoods()
    {
        $goods_name    = $this->request->post('goods_name');
        $goods_shop_id = $this->request->post('goods_shop_id');
        $goods_title   = $this->request->post('goods_title','');
        $goods_banner    = $this->request->post('goods_banner','');
        $goods_category_id = $this->request->post('goods_category_id');
        $goods_label = $this->request->post('goods_label','');
        $goods_price = $this->request->post('goods_price');
        $goods_status = $this->request->post('goods_status');
        $goods_time = $this->request->post('goods_time','');
        $goods_service_population = $this->request->post('goods_service_population','');
        $goods_service_consumables = $this->request->post('goods_service_consumables','');
        $goods_service_qualifications = $this->request->post('goods_service_qualifications','');
        $goods_service_explain = $this->request->post('goods_service_explain','');
        $goods_service_standard = $this->request->post('goods_service_standard','');
        $goods_service_process = $this->request->post('goods_service_process','');
        $goods_technological = $this->request->post('goods_technological','');
        $goods_tips = $this->request->post('goods_tips','');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('raise\RaiseOldGoodsValidate', ['goods_name'=>$goods_name,'goods_price'=>$goods_price,'goods_time'=>$goods_time,'goods_category_id'=>$goods_category_id,'goods_shop_id'=>$goods_shop_id,'goods_status'=>$goods_status], 'create');
        $result       = RaiseOldGoodsServer::insertGoods($goods_name, $goods_title, $goods_time, $goods_category_id, $goods_banner, $goods_label, $goods_status, $goods_service_population, $goods_service_consumables, $goods_service_qualifications, $goods_service_explain, $goods_service_standard, $goods_service_process, $goods_technological, $goods_tips, $goods_shop_id, $goods_price, $admin_id);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:查询养老产品详情
     * @return \support\Response
     * User: ZQ
     * Date: 2022/10/31
     */
    public function goodsInfo()
    {
        $goods_id = $this->request->get('goods_id');
        $this->validateCheck('raise\RaiseOldGoodsValidate', ['goods_id' => $goods_id], 'info');
        $result         = RaiseOldGoodsServer::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('raise\RaiseOldGoodsValidate', ['goods_id' => $goods_id], 'info');
        $result       = RaiseOldGoodsServer::updateStatus($goods_id, $goods_status);
        return json_success($result, '修改成功');
    }

}
