<?php

namespace app\admin\controller\sys_manage;

use app\admin\validate\sys_manage\PostageTemplateValidate;
use app\controller\Curd;
use app\model\PostageTemplate;
use support\Request;
use support\Response;

class PostageTemplateController extends Curd
{
    public function __construct()
    {
        $this->model = new PostageTemplate();
        $this->validate = true;
        $this->validateClass = new PostageTemplateValidate();
    }

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

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

        return json_success('success');
    }

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