authInitialize(); $this->patient_model = new Patient(); $this->his_client = app('HisHttpService'); } /** * 获取缴费记录列表 * @param string $patient_number * @param string $start_date * @param string $end_date * @return array * @throws GeneralException */ public function getRecordLists(string $patient_number, string $start_date, string $end_date): array { $patient_info = $this->getPatientInfo($this->open_id, $patient_number); $patient_id = $patient_info->patient_id; $response = $this->his_client->getPaidLists($patient_id, $start_date, $end_date); if (!isset($response['success']) || !$response['success']) { throw new GeneralException($response['msg'] ?? '暂无相关缴费记录!', Response::HTTP_SERVICE_UNAVAILABLE); } // 重写一下patientId if (!empty($response['response'])) { foreach ($response['response'] as $k => $v) { $response['response'][$k]['patientId'] = $patient_number; } } // 缓存2小时 Redis::setex('Outpatient.Record.'. $this->open_id.'.'. $patient_id, 2 * 60 * 60, json_encode($response, JSON_UNESCAPED_UNICODE)); return $response; } /** * 获取缴费记录详情 * @param string $patient_number * @param string $serial_no * @return array * @throws GeneralException */ public function getRecordDetails(string $patient_number, string $serial_no): array { $patient_info = $this->getPatientInfo($this->open_id, $patient_number); $patient_id = $patient_info->patient_id; $this->getCacheRecordInfo($patient_id, $serial_no); $response = $this->his_client->getPaidDetails($serial_no); if (!isset($response['success']) || !$response['success']) { throw new GeneralException($response['msg'] ?? '暂无相关缴费详情!', Response::HTTP_SERVICE_UNAVAILABLE); } return $response; } /** * 获取缓存里的记录详情 * @param string $patient_id * @param string $serial_no * @return mixed * @throws GeneralException */ protected function getCacheRecordInfo(string $patient_id, string $serial_no): mixed { $cache_key = 'Outpatient.Record.'. $this->open_id.'.'. $patient_id; $record_info = Redis::get($cache_key); if (empty($record_info)) { throw new GeneralException($response['msg'] ?? '查询不到缴费记录,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); } $record_info = json_decode($record_info, true); // 获取具体的缴费详情 foreach ($record_info['response'] as $v) { if ($v['payId'] === $serial_no) { $info = $v; break; } } if (empty($info)) { throw new GeneralException('查询不到缴费记录,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); } return $info; } /** * 获取患者信息 * @param string $open_id * @param string $patient_number * @return mixed * @throws GeneralException */ protected function getPatientInfo(string $open_id, string $patient_number): mixed { $info = $this->patient_model->getBindPatientInfoByPatientNumber($open_id, $patient_number); if (empty($info)) { throw new GeneralException('找不到患者信息,请重新再试!', Response::HTTP_BAD_REQUEST); } return $info; } }