Commit 88e25395 by 赵增煜

有效医师

parent cdeae775
......@@ -200,15 +200,31 @@ public function create(Request $request)
->pluck('prescription_count', 'doctor_id');
Log::info('医师开方统计:'.json_encode($prescriptionCounts));
if (count($prescriptionCounts) > 0) {
foreach ($doctorIds as $doctorId) {
if (isset($prescriptionCounts[$doctorId])) {
// 判断是否达到上限
if (intval($prescriptionCounts[$doctorId]) >= intval($prescription_limit)) {
unset($doctorIds[$doctorId]);
}
}
}
// foreach ($prescriptionCounts as $doctorId => $count) {
// if (intval($count) >= intval($prescription_limit)) {
// unset($doctorIds[$doctorId]);
// }
// if( count($doctorIds) == 0 ) break;
// }
}
// 筛选未达到上限的医师
$availableDoctors = collect($doctorIds)->filter(function ($doctorId) use ($prescriptionCounts, $prescription_limit) {
return $prescriptionCounts->get($doctorId, 0) < $prescription_limit;
})->values()->all();
Log::info('有效的医师:'.json_encode($availableDoctors));
// $availableDoctors = collect($doctorIds)->filter(function ($doctorId) use ($prescriptionCounts, $prescription_limit) {
// return $prescriptionCounts->get($doctorId, 0) < $prescription_limit;
// })->values()->all();
Log::info('有效的医师:'.json_encode($doctorIds));
// 随机取一个随机医师
$randomQuery = DoctorModel::query()->where('status', DoctorModel::STATUS_TRUE);
if (count($availableDoctors) > 0) {
$randomQuery->whereIn('id', $availableDoctors);
if (count($doctorIds) > 0) {
$randomQuery->whereIn('id', $doctorIds);
} else {
return $this->failed('医师开方数超过限制');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment