|
|
|
|
@ -339,7 +339,9 @@ WHERE
|
|
|
|
|
return \Yz::echoError1('操作失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//排队号
|
|
|
|
|
$xvhao=0;
|
|
|
|
|
$xvhao= $this->generateQueueNumber($planInfo->id);
|
|
|
|
|
//更新主表信息
|
|
|
|
|
$u_data = [
|
|
|
|
|
'list_status' => 1,
|
|
|
|
|
@ -349,7 +351,7 @@ WHERE
|
|
|
|
|
'services_group' => $planInfo->device_id,
|
|
|
|
|
'roster_id' => $planInfo->id,
|
|
|
|
|
'department_id' => $planInfo->department_id,
|
|
|
|
|
'xuhao' => 0,
|
|
|
|
|
'xuhao' => $xvhao,
|
|
|
|
|
'appointment_type_id' => $appointment_type,
|
|
|
|
|
'qudao_appointment_type_id' => $appointment_type,
|
|
|
|
|
];
|
|
|
|
|
@ -358,11 +360,25 @@ WHERE
|
|
|
|
|
foreach($plan_qudao_tempCount as $key=>$length){
|
|
|
|
|
if($length==0) continue;
|
|
|
|
|
$u_data['appointment_type_id']= $appointment_types[$key];
|
|
|
|
|
$u_mainList = DB::table('s_list')->whereIn('id', array_slice($mainlistids,$offset,$length))->update($u_data);
|
|
|
|
|
if(!$u_mainList){
|
|
|
|
|
$list_all_success=false;
|
|
|
|
|
break;
|
|
|
|
|
// 获取当前批次的记录 ID
|
|
|
|
|
$currentBatchIds = array_slice($mainlistids, $offset, $length);
|
|
|
|
|
|
|
|
|
|
foreach ($currentBatchIds as $id) {
|
|
|
|
|
// 为当前记录生成唯一的排队号
|
|
|
|
|
$xuhao = $this->generateQueueNumber($planInfo->id);
|
|
|
|
|
|
|
|
|
|
// 更新当前记录的数据(包括 xuhao)
|
|
|
|
|
$u_data['xuhao'] = $xuhao;
|
|
|
|
|
$u_mainList = DB::table('s_list')
|
|
|
|
|
->where('id', $id)
|
|
|
|
|
->update($u_data);
|
|
|
|
|
|
|
|
|
|
if (!$u_mainList) {
|
|
|
|
|
$list_all_success = false;
|
|
|
|
|
break 2; // 如果更新失败,跳出外层循环
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$offset += $length;
|
|
|
|
|
}
|
|
|
|
|
if (!$list_all_success) {
|
|
|
|
|
@ -537,4 +553,34 @@ WHERE
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
//获取排队号,思路:获取主表内使用这个plan_id的医嘱,获取已生成排队号最大的一个数,加1。如果中间有断号,则选择断号中最小的一个
|
|
|
|
|
function generateQueueNumber($planId)
|
|
|
|
|
{
|
|
|
|
|
DB::transaction(function () use ($planId, &$queueNumbers) {
|
|
|
|
|
// 使用悲观锁锁定相关行,确保同一时间只有一个进程操作
|
|
|
|
|
$queueNumbers = DB::table('s_list')
|
|
|
|
|
->where(['roster_id' => $planId, 'is_del' => 0, 'is_nullify' => 0])
|
|
|
|
|
->lockForUpdate() // 关键修改:添加行级锁
|
|
|
|
|
->pluck('xuhao')
|
|
|
|
|
->filter()
|
|
|
|
|
->map(fn($num) => (int)$num)
|
|
|
|
|
->sort();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if ($queueNumbers->isEmpty()) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$maxQueueNumber = $queueNumbers->max();
|
|
|
|
|
$minAvailableNumber = null;
|
|
|
|
|
|
|
|
|
|
for ($i = 1; $i <= $maxQueueNumber; $i++) {
|
|
|
|
|
if (!$queueNumbers->contains($i)) {
|
|
|
|
|
$minAvailableNumber = $i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $minAvailableNumber ?? $maxQueueNumber + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|