getFamilyList(); return $this->response->json($data); } /** * 新增家庭成员 * @return array|ResponseInterface * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function addFamily(): array|ResponseInterface { $request = $this->container->get(PatientFamilyRequest::class); $request->scene('addFamily')->validateResolved(); // 检测入参身份证号 $res = $this->checkRequestIdCard(); if (!empty($res)) { return fail(HttpEnumCode::HTTP_ERROR, $res); } $patientFamilyService = new PatientFamilyService(); $data = $patientFamilyService->addFamily(); return $this->response->json($data); } /** * 检测入参身份证号 * @return string */ private function checkRequestIdCard(): string { $messages = [ 'id_number.regex' => '证件号错误', ]; $validator = $this->validationFactory->make($this->request->all(), [ 'type' => 'required', ], $messages); $validator->sometimes( ['id_number'], ['regex:/^(?:1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5])\d{4}(?:1[89]|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dxX]$/'], function ($input) { return $input->type == 1; } ); if ($validator->fails()) { return $validator->errors()->first(); } return ""; } }