占用号源加锁

main
岩仔88 4 days ago
parent 130ba4c3cd
commit a5fa190d4c

@ -319,6 +319,10 @@ WHERE
}
DB::beginTransaction();
try {
//查询号源渠道是否有合并
$appointment_types=[$appointment_type];
$appointment_type_link = DB::table('s_appointment_type_ratio')->where(['department_id'=>$planInfo->department_id,'appointment_type_id' => $appointment_type])->first();
@ -332,6 +336,7 @@ WHERE
->where(['roster_detail_id' => $planid])
->whereIn('appointment_type_id', $appointment_types)
->orderBy('appointment_type_id','asc')
->lockForUpdate() // 添加行级锁 ★ 关键
->get();
$planZongCount=0;//合并后的各个渠道总名额
$planZongUsedCount=0;//合并后的各个渠道已预约的名额
@ -388,20 +393,28 @@ WHERE
return \Yz::echoError1($personEntry[0]['user_name'].'勾选的项目存在互斥,不可同时预约');
}
}
DB::beginTransaction();
try {
//更新计划明细表使用数量
$up_plan_count_all_success =true;
$appointment_use_plan_detail_arr=[];//预约各个号源占用号源详情
foreach ($roster_detail_counts as $key => $planCount) {
if($plan_qudao_tempCount[$key]==0) continue;
$currentVersion = $planCount->version ?? 0;
$query = DB::table('s_source_roster_detail_count')->where(['id' => $planCount->id]);
$query = DB::table('s_source_roster_detail_count')
->where(['id' => $planCount->id])
->where('version', $currentVersion);
// 【核心修改】只有非紧急预约时,才检查名额是否充足
if ($is_emergency!==1) {
$query->whereRaw('count >= (used_count + IFNULL(locked_count, 0) + ?)', [$plan_qudao_tempCount[$key]]);
}
$u = $query->increment('used_count', $plan_qudao_tempCount[$key]);
// $u = $query->increment('used_count', $plan_qudao_tempCount[$key]);
$u = $query->update([
'used_count' => DB::raw("used_count + {$plan_qudao_tempCount[$key]}"),
'version' => DB::raw("version + 1"),
// 如果需要更新更新时间,可以在这里加 'updated_at' => now()
]);
if(!$u){
$up_plan_count_all_success=false;

Loading…
Cancel
Save