89 lines
2.8 KiB
PHP
89 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Request;
|
|
|
|
use App\Constants\HttpEnumCode;
|
|
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
|
|
use Hyperf\Validation\Request\FormRequest;
|
|
use Hyperf\Validation\Rule;
|
|
|
|
class PatientFamilyRequest extends FormRequest
|
|
{
|
|
/**
|
|
* @Inject
|
|
* @var ValidatorFactoryInterface
|
|
*/
|
|
protected ValidatorFactoryInterface $validationFactory;
|
|
|
|
protected array $scenes = [
|
|
'addFamily' => [ // 新增家庭成员
|
|
'relation',
|
|
'is_default',
|
|
'card_name',
|
|
'mobile',
|
|
'type',
|
|
'id_number',
|
|
'province_id',
|
|
'city_id',
|
|
'county_id',
|
|
'height',
|
|
'weight',
|
|
'marital_status',
|
|
]
|
|
];
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'card_name' => 'required',
|
|
'type' => ['required',Rule::in(['1', '2', '3', '4'])],
|
|
'id_number' => "required",
|
|
'mobile' => ['required','regex:/^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/'],
|
|
'relation' => ['required',Rule::in(['1', '2', '3', '4', '5', '6'])],
|
|
'city_id' => 'required_with:province_id',
|
|
'province_id' => 'required_with:city_id,county_id',
|
|
'is_default' => ['sometimes',Rule::in(['0', '1'])],
|
|
'height' => ['sometimes','numeric'], // 身高
|
|
'weight' => ['sometimes','numeric'], // 体重
|
|
'marital_status' => ['sometimes',Rule::in(['0', '1'])], // 婚姻状况(0:未婚 1:已婚)
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 获取已定义验证规则的错误消息.
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'name.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
|
'type.required' => "请选择证件类型",
|
|
'type.in' => "证件类型错误",
|
|
'id_number.required' => "请选择证件号",
|
|
'mobile.required' => "手机号不能为空",
|
|
'mobile.regex' => "手机号格式错误",
|
|
'relation.required' => "请选择患者关系",
|
|
'relation.in' => "患者关系错误",
|
|
'city_id.required_with' => "请选择城市",
|
|
'province_id.required_with' => "请选择省份",
|
|
'is_default.in' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
|
'height.numeric' => "身高错误",
|
|
'weight.numeric' => "体重错误",
|
|
'blood_type.in' => "血型错误",
|
|
'marital_status.in' => "婚姻状况错误",
|
|
];
|
|
}
|
|
}
|