<?php
/**
 * 退款申请请求
 * @file:OrderRefundRequest.php
 * @Date: 2023/5/29
 * @Time: 10:52
 */


namespace Modules\OrderRefund\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Modules\OrderRefund\Models\OrdersRefundVerify;

class OrderRefundRequest extends FormRequest
{
    /**
     * rules
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            'order_id' => [
                'required',
                'Integer',
                "gt:0",
                function ($attribute, $value, $fail) {
                    $has = OrdersRefundVerify::where('order_id', $value)->value('id');
                    if (!empty($has)) {
                        $fail("此订单已申请退款！");
                    }
                }
            ],
            'price'=>[
                'required',
                "gt:0"
            ]
        ];
    }

    /**
     * messages
     *
     * @return string[]
     */
    public function messages(): array
    {
        return [
            'order_id.required' => '申请退款订单必填',
            'order_id.Integer' => '申请退款订单不正确',
            'order_id.gt' => '申请退款订单不正确',
            'price.gt' => '退款金额必须大于0',
            'price.required' => '退款金额必填',
        ];
    }

}
