<?php

namespace app\admin\controller\life;

use app\admin\validate\life\HealthyFoodValidate;
use app\controller\Curd;
use app\model\HealthyFood;
use support\Request;
use support\Response;

class HealthyFoodController extends Curd
{
    public function __construct()
    {
        $this->model = new HealthyFood();
        $this->validate = true;
        $this->validateClass = new HealthyFoodValidate();
    }

    /**
     * @Desc 列表
     * @Author Gorden
     * @Date 2024/2/29 10:26
     *
     * @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 ?? 'food_addTime';
        $where['food_is_del'] = 0;
        $query = $this->doSelect($where, $field, $order);
        return $this->doFormat($query, $format, $limit);
    }

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

        return json_success('success');
    }

    /**
     * @Desc 修改状态
     * @Author Gorden
     * @Date 2024/2/29 10:29
     *
     * @param Request $request
     * @return Response
     */
    public function updateStatus(Request $request)
    {
        return $this->updateField($request->post('food_id'), 'food_status', $request->post('food_status'));
    }
}