<?php

namespace app\admin\controller\life;

use app\admin\validate\life\FarmPackageGoodsValidate;
use app\controller\Curd;
use app\model\FarmPackageGoods;
use support\Request;
use support\Response;

class FarmPackageGoodsController extends Curd
{
    public function __construct()
    {
        $this->model = new FarmPackageGoods();
        $this->validate = true;
        $this->validateClass = new FarmPackageGoodsValidate();
    }

    /**
     * @Desc 列表
     * @Author Gorden
     * @Date 2024/2/28 16:49
     *
     * @param Request $request
     * @return Response
     * @throws \support\exception\BusinessException
     */
    public function select(Request $request): Response
    {
        [$where, $format, $limit, $field, $order] = $this->selectInput($request);
        $order = $request->get('order', 'desc');
        $field = $field ?? 'goods_sort';
        $where['goods_is_del'] = 0;
        $query = $this->doSelect($where, $field, $order);
        return $this->doFormat($query, $format, $limit);
    }

    /**
     * @Desc 软删除
     * @Author Gorden
     * @Date 2024/2/28 16:50
     *
     * @param Request $request
     * @return Response
     * @throws \support\exception\BusinessException
     */
    public function delete(Request $request): Response
    {
        $ids = $this->deleteInput($request);
        $this->doSoftDelete($ids, ['goods_is_del' => 1]);

        return json_success('success');
    }
}