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

use app\admin\controller\BaseController;
use app\admin\server\home\HomeBannerServer;

class HomeBanner extends BaseController
{

    /**
     * Notes:获取项目列表
     * @return \support\Response
     * User: YCP
     * Date: 2022/11/1
     */
    public function getBannerList()
    {
        $result         = HomeBannerServer::getBannerList();
        return json_success($result, '成功');
    }

    /**
     * Notes:修改项目
     * @return \support\Response
     * User: YCP
     * Date: 2022/11/1
     */
    public function updateBanner()
    {
        $params    = $this->request->post();
        $admin_id  = $this->request->admin_id;
        $this->validateCheck('home\HomeBannerValidate',
            [
                'banner_id'        => $params['banner_id']?? '',
                'banner_category_id' => $params['banner_category_id']?? '',
                'banner_name'      => $params['banner_name']?? '',
                'banner_img'     => $params['banner_img']?? '',
            ],
            'update');
        $result       = HomeBannerServer::updateBanner($params, $admin_id);
        return json_success($result, '修改成功');

    }

    /**
     * Notes:删除项目
     * @return \support\Response
     * User: YCP
     * Date: 2022/11/1
     */
    public function delBanner()
    {
        $banner_id = $this->request->get('banner_id');
        $admin_id = $this->request->admin_id;
        $this->validateCheck('home\HomeBannerValidate', ['banner_id' => $banner_id], 'info');
        $result         = HomeBannerServer::delBanner($banner_id,$admin_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }

    /**
     * Notes:添加项目
     * @return \support\Response
     * User: YCP
     * Date: 2022/11/1
     */
    public function addBanner()
    {
        
        $params    = $this->request->post();
        $admin_id  = $this->request->admin_id;
        $this->validateCheck('home\HomeBannerValidate',
            [
                'banner_category_id' => $params['banner_category_id']?? '',
                'banner_name'      => $params['banner_name']?? '',
                'banner_img'     => $params['banner_img']?? '',
            ],
            'create');
        $result         = HomeBannerServer::insertBanner($params, $admin_id);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:查询项目详情
     * @return \support\Response
     * User: YCP
     * Date: 2022/11/1
     */
    public function bannerInfo()
    {
        $banner_id = $this->request->get('banner_id');
        $this->validateCheck('home\HomeBannerValidate', ['banner_id' => $banner_id], 'info');
        $result         = HomeBannerServer::bannerInfo($banner_id);
        return json_success($result, '成功');
    }


}
