<?php
/**
 *
 * @file:BannerController.php
 * @Date: 2023/6/7
 * @Time: 14:04
 */


namespace Modules\Operation\Http\Controllers;

use Catch\Base\CatchController;
use Catch\Exceptions\FailedException;
use Illuminate\Http\Request;
use Modules\Operation\Http\Requests\BannerRequest;
use Modules\Operation\Service\BannerService;

class BannerController extends CatchController
{

    /**
     *  轮播图类列表
     * name: list
     */
    public function list(Request $request)
    {
        $param  = $request->all();
        return BannerService::getBannerLists($param);
    }
    /*
     * 添加
     */
    public function add(BannerRequest $request){
        $param = $request->all();
        return BannerService::addBanner($param);
    }

    /*
     * 编辑
     */
    public function edit($id,BannerRequest $request)
    {
        return BannerService::updateBanner($id,$request->all());
    }

    /*
     *  更新状态
     */
    public function updateStatus($id,Request $request)
    {
        if (!$request->has('status')){
            throw  new FailedException("参数错误");
        }
        $status = $request->input('status');
        if (!in_array($status,[1,0])){
            throw  new FailedException("状态值不正确");
        }
        return BannerService::updateBanner($id,['status' => $status]);
    }

    /*
     *  删除
     */
    public function del($id){
        return BannerService::delBannerById($id);
    }
}
