|
|
|
|
@ -14,13 +14,14 @@ class PlanListService
|
|
|
|
|
public function GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_type, $appointment_date)
|
|
|
|
|
{
|
|
|
|
|
date_default_timezone_set('PRC');
|
|
|
|
|
// $regnum = request('regnum');
|
|
|
|
|
// $entrustid = request('entrustid');
|
|
|
|
|
// $episodeid = request('episodeid');
|
|
|
|
|
// $appointment_type = request('appointment_type'); //预约类型
|
|
|
|
|
// $appointment_date = request('date'); //预约日期
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询号源渠道是否有合并
|
|
|
|
|
$appointment_types=[$appointment_type];
|
|
|
|
|
$appointment_type_link = DB::table('s_appointment_type_ratio')->where(['appointment_type_id' => $appointment_type])->first();
|
|
|
|
|
if (!empty($appointment_type_link->link)) {
|
|
|
|
|
$appointment_types=json_decode($appointment_type_link->link, true);
|
|
|
|
|
$appointment_types=array_merge($appointment_types, [$appointment_type]);
|
|
|
|
|
}
|
|
|
|
|
$allDevice = [];//所有医嘱检查项目绑定的设备id
|
|
|
|
|
$commPatientType = [];//所有医嘱共同的病人类型
|
|
|
|
|
foreach ($entrustids as $key => $entrustid) {
|
|
|
|
|
@ -32,14 +33,10 @@ class PlanListService
|
|
|
|
|
|
|
|
|
|
$itemInfo = $itemInfo[0];
|
|
|
|
|
$qudaos = explode(',', $itemInfo->reservation_method);
|
|
|
|
|
//只判断主渠道,如果主渠道支持,则子渠道默认也支持,即使项目没绑定子渠道
|
|
|
|
|
if (!in_array($appointment_type, $qudaos)) return \Yz::echoError1('此检查项目不支持在当前渠道预约');
|
|
|
|
|
|
|
|
|
|
// $entrust_time = $info->entrust_date . ' ' . $info->entrust_time; //医嘱时间
|
|
|
|
|
// $date = new DateTime($entrust_time);
|
|
|
|
|
// $date->modify("+" . $itemInfo->check_begin_time . " minutes");
|
|
|
|
|
// $enableCheckTime = $date;//到此时间后可进行预约
|
|
|
|
|
// $current_time = new DateTime();
|
|
|
|
|
// if ($current_time < $enableCheckTime) return \Yz::echoError1("请于" . $enableCheckTime->format("Y-m-d H:i:s") . "后进行预约");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取检查项目绑定的服务组(设备),判断状态正常的
|
|
|
|
|
$devices = DB::table('s_check_item_device')
|
|
|
|
|
@ -70,35 +67,12 @@ class PlanListService
|
|
|
|
|
$department_id = DB::table('s_department')->where(['department_number' => $info->RISRAcceptDeptCode])->first();
|
|
|
|
|
if (!$department_id) return \Yz::echoError1('获取医嘱检查项目科室信息失败');
|
|
|
|
|
|
|
|
|
|
// // 获取当前日期
|
|
|
|
|
// $startDate = date('Y-m-d');
|
|
|
|
|
// // 创建一个空数组来存储日期
|
|
|
|
|
// $datesArray = [];
|
|
|
|
|
// // 循环获取今天及之后7天的日期
|
|
|
|
|
// for ($i = 0; $i <7; $i++) {
|
|
|
|
|
// // 使用DateTime对象方便地进行日期操作
|
|
|
|
|
// $dateObject = new DateTime($startDate);
|
|
|
|
|
// $dateObject->add(new DateInterval('P'.$i.'D')); // P1D表示增加一天
|
|
|
|
|
// // 将日期格式化后存入数组
|
|
|
|
|
// $datesArray[] = $dateObject->format('Y-m-d');
|
|
|
|
|
// }
|
|
|
|
|
//获取对应日期的计划明细
|
|
|
|
|
// $plan = DB::table('s_source_roster_detail as a')
|
|
|
|
|
// ->select('a.*', 'b.department_resources_name', 'c.roster_detail_id', 'c.count', 'c.used_count','e.device_name as devices')
|
|
|
|
|
// ->leftJoin('s_department_resources as b', 'a.resources_id', '=', 'b.id')
|
|
|
|
|
// ->leftJoin('s_source_roster_detail_count as c', 'a.id', '=', 'c.roster_detail_id')
|
|
|
|
|
// ->leftJoin('s_source_roster_detail_device as d','a.id','=','d.roster_detail_id')
|
|
|
|
|
// ->leftJoin('s_devices as e','d.device_id','=','e.id')
|
|
|
|
|
// ->where(['a.department_id' => $department_id->id])
|
|
|
|
|
// ->where('a.date',$appointment_date)
|
|
|
|
|
// ->where(['a.status' => 1, 'a.is_del' => 0, 'b.is_del' => 0, 'c.appointment_type_id' => $appointment_type])
|
|
|
|
|
// ->whereIn('d.device_id',$commonDevice)
|
|
|
|
|
// ->orderBy('a.date')
|
|
|
|
|
// ->get();
|
|
|
|
|
|
|
|
|
|
if(count($commonDevice)==0) return \Yz::echoError1("无可用号源");
|
|
|
|
|
$placeholders = implode(',', array_fill(0, count($commonDevice), '?'));
|
|
|
|
|
$appointment_types_placeholders = implode(',', array_fill(0, count($appointment_types), '?'));
|
|
|
|
|
|
|
|
|
|
$canshu = array_merge($commonDevice, [$department_id->id, $appointment_date, $appointment_type]);
|
|
|
|
|
$canshu = array_merge($commonDevice, [$department_id->id, $appointment_date], $appointment_types);
|
|
|
|
|
$plan = DB::select("SELECT
|
|
|
|
|
a.*,
|
|
|
|
|
dd.devices,
|
|
|
|
|
@ -128,7 +102,23 @@ WHERE
|
|
|
|
|
AND a.STATUS = 1
|
|
|
|
|
AND a.is_del = 0
|
|
|
|
|
AND b.is_del = 0
|
|
|
|
|
AND c.appointment_type_id =?", $canshu);
|
|
|
|
|
AND c.appointment_type_id IN ($appointment_types_placeholders)", $canshu);
|
|
|
|
|
|
|
|
|
|
$mergedPlan = [];
|
|
|
|
|
foreach ($plan as $key => $p) {
|
|
|
|
|
// 如果 roster_detail_id 已经存在,则合并 count 数量
|
|
|
|
|
if (isset($mergedPlan[$p->roster_detail_id])) {
|
|
|
|
|
// 累加 count 数量到已存在的记录中
|
|
|
|
|
$mergedPlan[$p->roster_detail_id]->count += $p->count;
|
|
|
|
|
$mergedPlan[$p->roster_detail_id]->used_count += $p->used_count; // 如果需要合并 used_count,也可以加上
|
|
|
|
|
} else {
|
|
|
|
|
// 初始化新的合并数据
|
|
|
|
|
$mergedPlan[$p->roster_detail_id] = $p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将合并后的数据重新组织为数组
|
|
|
|
|
$plan = array_values($mergedPlan);
|
|
|
|
|
//遍历列表 把超过当前时间的放在后面
|
|
|
|
|
$pl1 = [];
|
|
|
|
|
$pl2 = [];
|
|
|
|
|
@ -164,13 +154,39 @@ WHERE
|
|
|
|
|
// $do_type = request('dotype');//操作类型,1预约,2改约
|
|
|
|
|
// if (!isset($do_type)) return \Yz::echoError1('参数:操作类型 不能为空');
|
|
|
|
|
|
|
|
|
|
//查询号源渠道是否有合并
|
|
|
|
|
$appointment_types=[$appointment_type];
|
|
|
|
|
$appointment_type_link = DB::table('s_appointment_type_ratio')->where(['appointment_type_id' => $appointment_type])->first();
|
|
|
|
|
if (!empty($appointment_type_link->link)) {
|
|
|
|
|
$appointment_types=json_decode($appointment_type_link->link, true);
|
|
|
|
|
$appointment_types=array_merge($appointment_types, [$appointment_type]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$planInfo = DB::table('s_source_roster_detail')->where(['id' => $planid, 'status' => 1, 'is_del' => 0])->first();
|
|
|
|
|
if (!$planInfo) return \Yz::echoError1('当前时段不可用');
|
|
|
|
|
if ($nowdatetime > $planInfo->date . ' ' . $planInfo->end_reservation_time) return \Yz::echoError1('已经超过预约截止时间');
|
|
|
|
|
$planCount = DB::table('s_source_roster_detail_count')->where(['roster_detail_id' => $planid,
|
|
|
|
|
'appointment_type_id' => $appointment_type])->first();
|
|
|
|
|
if ($planCount->count < ($planCount->used_count + count($mainlistids))) return \Yz::echoError1('当前预约时间名额不足');
|
|
|
|
|
$roster_detail_counts = DB::table('s_source_roster_detail_count')
|
|
|
|
|
->where(['roster_detail_id' => $planid])
|
|
|
|
|
->whereIn('appointment_type_id', $appointment_types)
|
|
|
|
|
->get();
|
|
|
|
|
$planZongCount=0;//合并后的各个渠道总名额
|
|
|
|
|
$planZongUsedCount=0;//合并后的各个渠道已预约的名额
|
|
|
|
|
$plan_qudao_tempCount=[];//拆分各个渠道需要占用的名额
|
|
|
|
|
$weifenpeiCount=count($mainlistids);//未分配的名额
|
|
|
|
|
foreach ($roster_detail_counts as $roster_detail_count) {
|
|
|
|
|
$planZongCount+=$roster_detail_count->count;
|
|
|
|
|
$planZongUsedCount+=$roster_detail_count->used_count;
|
|
|
|
|
$keyongCount=$roster_detail_count->count-$roster_detail_count->used_count;
|
|
|
|
|
if($weifenpeiCount-$keyongCount>=0){
|
|
|
|
|
$plan_qudao_tempCount[]=$keyongCount;
|
|
|
|
|
$weifenpeiCount-=$keyongCount;
|
|
|
|
|
}else{
|
|
|
|
|
$plan_qudao_tempCount[]=$weifenpeiCount;
|
|
|
|
|
$weifenpeiCount=0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if ($planZongCount < ($planZongUsedCount + count($mainlistids))) return \Yz::echoError1('当前预约时间名额不足');
|
|
|
|
|
$huchiList=[];//互斥item_id对应关系
|
|
|
|
|
$oldMainInfos = [];//临时存储原来的主表信息,用于改约
|
|
|
|
|
//遍历多个s_list表id,前端多选,一次预约多个检查项目
|
|
|
|
|
@ -293,12 +309,33 @@ WHERE
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
try {
|
|
|
|
|
//更新计划明细表使用数量
|
|
|
|
|
$u = DB::table('s_source_roster_detail_count')->where(['id' => $planCount->id])->whereRaw('count >= (used_count + ?)', [count($mainlistids)])
|
|
|
|
|
->increment('used_count', count($mainlistids));
|
|
|
|
|
$up_plan_count_all_success =true;
|
|
|
|
|
foreach ($roster_detail_counts as $key => $planCount) {
|
|
|
|
|
if($plan_qudao_tempCount[$key]==0) continue;
|
|
|
|
|
$u = DB::table('s_source_roster_detail_count')->where(['id' => $planCount->id])->whereRaw('count >= (used_count + ?)', [$plan_qudao_tempCount[$key]])
|
|
|
|
|
->increment('used_count',$plan_qudao_tempCount[$key]);
|
|
|
|
|
|
|
|
|
|
if(!$u){
|
|
|
|
|
$up_plan_count_all_success=false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($up_plan_count_all_success) {
|
|
|
|
|
foreach ($roster_detail_counts as $key => $planCount) {
|
|
|
|
|
$cha = DB::table('s_source_roster_detail_count')->where(['id' => $planCount->id])->first();
|
|
|
|
|
|
|
|
|
|
if ($cha->count < $cha->used_count) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('操作失败1');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('操作失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($u) {
|
|
|
|
|
$cha = DB::table('s_source_roster_detail_count')->where(['id' => $planCount->id])->first();
|
|
|
|
|
if ($cha->count >= $cha->used_count) {
|
|
|
|
|
//更新主表信息
|
|
|
|
|
$u_data = [
|
|
|
|
|
'list_status' => 1,
|
|
|
|
|
@ -310,8 +347,25 @@ WHERE
|
|
|
|
|
'department_id' => $planInfo->department_id,
|
|
|
|
|
'xuhao' => 0,
|
|
|
|
|
'appointment_type_id' => $appointment_type,
|
|
|
|
|
'qudao_appointment_type_id' => $appointment_type,
|
|
|
|
|
];
|
|
|
|
|
$u_mainList = DB::table('s_list')->whereIn('id', $mainlistids)->update($u_data);
|
|
|
|
|
$list_all_success =true;
|
|
|
|
|
$offset = 0;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
$offset += $length;
|
|
|
|
|
}
|
|
|
|
|
if (!$list_all_success) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('预约失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$note = "预约";
|
|
|
|
|
|
|
|
|
|
foreach ($oldMainInfos as $key => $oldMainInfo) {
|
|
|
|
|
@ -343,14 +397,9 @@ WHERE
|
|
|
|
|
return \Yz::echoError1('预约失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('当前预约时间名额不足');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
return \Yz::echoError1('操作失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
|