reportModel = $reportModel; $this->examModel = $examModel; $this->studyModel = $studyModel; $this->institutionModel = $institutionModel; $this->qcModel = $qcModel; } public function testAnalysis() { $limit = 100; $exams = $this->examModel ->where('institution_id', '06300006') ->where('qc_status', 1) ->where('exam_status', 9) ->order('createdAt', 'desc') ->limit($limit) ->select(); foreach($exams as $exam) { $this->analysis($exam['id']); } if(count($exams) === $limit) { $this->testAnalysis(); } } public function getInstitutionName($institution_id) { $name = $this->institutionModel->where('id', $institution_id)->value('name'); return $name; } public function analysis($exam_id) { $exam = $this->examModel->where('id', $exam_id)->find(); $report = $this->reportModel->where('exam_id', $exam_id)->find(); $study = $this->studyModel->where('id', $exam['study_id'])->find(); $studyDay = $exam['exam_datetime']; $studyTime = $study['studytime']; $studyDate = $this->getStudyDate($studyDay, $studyTime); // 判断报告医生和审核医生是否同一人; // 判断检查时间和审核时间是否超过2个小时; // 判断是否存在身份证号、手机号、检查日期、报告日期、审核日期为空, $time = $this->diffTime($studyDate, $report['review_datetime']); $qcExam = [ 'exam_id' => $exam_id, 'institution_id' => $exam['institution_id'], 'name' => $exam['name'], 'card_num' => $exam['card_num'], 'exam_class' => $exam['exam_class'], 'phone' => $exam['phone'], 'studydate' => $studyDate, 'studyday' => $this->date2day($studyDate), 'reportdate' => $report['report_datetime'], 'reportday' => $this->date2day($report['report_datetime']), 'reviewdate' => $report['review_datetime'], 'reviewday' => $this->date2day($report['review_datetime']), 'study_doctor_id' => null, 'report_doctor_id' => $report['report_doctor_id'], 'review_doctor_id' => $report['review_doctor_id'], 'study_doctor_name' => null, 'report_doctor_name' => $report['report_doctor_name'], 'review_doctor_name' => $report['review_doctor_name'], 'report_interval' => $time, 'institution_name' => $this->getInstitutionName($exam['institution_id']), ]; $this->saveQcExam($qcExam); $exam['qc_status'] = 2; $exam->save(); } private function saveQcExam($qcExam) { // $qcModel = $this->qcModel; $qcModel = new QcExamModel(); $old = $qcModel->where('exam_id', $qcExam['exam_id'])->find(); if($old) { $old->save($qcExam); } else { $qcModel->save($qcExam); } } private function getStudyDate($studyDay, $studyTime) { if(!$studyDay) { return null; } if(!$studyTime) { return null; } // strtotime() $studyTime = explode('.', $studyTime)[0]; $formattedDateTime = date('Y-m-d H:i:s', strtotime($studyDay . ' ' . $studyTime)); return $formattedDateTime; } public function diffTime($studyDate, $reviewDate) { return strtotime($reviewDate) - strtotime($studyDate); } public function date2day($date) { $formattedDate = date("Ymd", strtotime($date)); $intDate = (int)$formattedDate; return $intDate; } }