|
|
|
@ -15,13 +15,14 @@ class PlanModelController extends Controller
|
|
|
|
$searchInfo = request('searchInfo');
|
|
|
|
$searchInfo = request('searchInfo');
|
|
|
|
$page = request('page');
|
|
|
|
$page = request('page');
|
|
|
|
$pageSize = request('pageSize');
|
|
|
|
$pageSize = request('pageSize');
|
|
|
|
|
|
|
|
$searchInfo['date_type']=$searchInfo['date_type']?$searchInfo['date_type']:1;
|
|
|
|
$department_id = 0;
|
|
|
|
$department_id = 0;
|
|
|
|
$list = DB::table('s_source_roster')
|
|
|
|
$list = DB::table('s_source_roster')
|
|
|
|
->leftJoin('s_department_resources', 's_source_roster.resources_id', '=', 's_department_resources.id')
|
|
|
|
->leftJoin('s_department_resources', 's_source_roster.resources_id', '=', 's_department_resources.id')
|
|
|
|
// ->leftJoin('s_devices', 's_source_roster.device_id', '=', 's_devices.id')
|
|
|
|
// ->leftJoin('s_devices', 's_source_roster.device_id', '=', 's_devices.id')
|
|
|
|
->leftJoin('s_period', 's_source_roster.period_id', '=', 's_period.id')
|
|
|
|
->leftJoin('s_period', 's_source_roster.period_id', '=', 's_period.id')
|
|
|
|
->select('s_source_roster.*', 's_department_resources.department_resources_name', 's_period.period_name')
|
|
|
|
->select('s_source_roster.*', 's_department_resources.department_resources_name', 's_period.period_name')
|
|
|
|
->where(['s_source_roster.is_del' => 0]);
|
|
|
|
->where(['s_source_roster.is_del' => 0,'s_source_roster.date_type' => $searchInfo['date_type']]);
|
|
|
|
if ($group == 1) {//如果是管理员
|
|
|
|
if ($group == 1) {//如果是管理员
|
|
|
|
if (!empty($searchInfo['department_id'])) {
|
|
|
|
if (!empty($searchInfo['department_id'])) {
|
|
|
|
$list = $list->where('s_source_roster.department_id', $searchInfo['department_id']);
|
|
|
|
$list = $list->where('s_source_roster.department_id', $searchInfo['department_id']);
|
|
|
|
@ -95,24 +96,29 @@ class PlanModelController extends Controller
|
|
|
|
public function Save(Request $request)
|
|
|
|
public function Save(Request $request)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$userid = $request->get('userid');//中间件产生的参数
|
|
|
|
$userid = $request->get('userid');//中间件产生的参数
|
|
|
|
$bitian = array('xingqi', 'max_total', 'qudao_total', 'period_id', 'begin_time', 'end_time', 'end_reservation_time', 'resources_id', 'devices', 'patientType');
|
|
|
|
$date_type = request('date_type');
|
|
|
|
$bitian_zh = array('星期', '当日总量', '渠道数量', '时间段', '开始时间', '结束时间', '停止预约时间', '资源', '设备', '患者类型');
|
|
|
|
|
|
|
|
$planInfo = request('planInfo');
|
|
|
|
$planInfo = request('planInfo');
|
|
|
|
|
|
|
|
$bitian = array('max_total', 'qudao_total', 'period_id', 'begin_time', 'end_time', 'end_reservation_time', 'resources_id', 'devices', 'patientType');
|
|
|
|
|
|
|
|
$bitian_zh = array('当日总量', '渠道数量', '时间段', '开始时间', '结束时间', '停止预约时间', '资源', '设备', '患者类型');
|
|
|
|
|
|
|
|
if($date_type==1){//如果是普通类型计划 1普通2节假日
|
|
|
|
|
|
|
|
$bitian[]='xingqi';
|
|
|
|
|
|
|
|
$bitian_zh[]='星期';
|
|
|
|
|
|
|
|
}
|
|
|
|
foreach ($bitian as $key => $field) { //必填项不能为空
|
|
|
|
foreach ($bitian as $key => $field) { //必填项不能为空
|
|
|
|
if (array_key_exists($field, $planInfo) && $planInfo[$field] !== '' && $planInfo[$field] !== null && $planInfo[$field] !== [] && $planInfo[$field] !== 0) {
|
|
|
|
if (array_key_exists($field, $planInfo) && $planInfo[$field] !== '' && $planInfo[$field] !== null && $planInfo[$field] !== [] && $planInfo[$field] !== 0) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return \Yz::echoError1($bitian_zh[$key] . ' 不能为空');
|
|
|
|
return \Yz::echoError1($bitian_zh[$key] . ' 不能为空');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($planInfo['end_reservation_time']>$planInfo['end_time']) return \Yz::echoError1('停止预约时间不能超过结束时间');
|
|
|
|
$userInfo = DB::table('users')->where(['id' => $userid])->first();
|
|
|
|
$userInfo = DB::table('users')->where(['id' => $userid])->first();
|
|
|
|
if (!isset($userInfo->department_id)) return \Yz::echoError1('该用户未绑定科室');
|
|
|
|
if (!isset($userInfo->department_id)) return \Yz::echoError1('该用户未绑定科室');
|
|
|
|
$department_id = $userInfo->department_id;
|
|
|
|
$department_id = $userInfo->department_id;
|
|
|
|
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
DB::beginTransaction();
|
|
|
|
foreach ($planInfo['xingqi'] as $key => $value) {
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
$data = [
|
|
|
|
'department_id' => $department_id,
|
|
|
|
'department_id' => $department_id,
|
|
|
|
'weekname' => $value,
|
|
|
|
'weekname' => '',
|
|
|
|
'resources_id' => $planInfo['resources_id'],
|
|
|
|
'resources_id' => $planInfo['resources_id'],
|
|
|
|
'device_id' => isset($planInfo['devices']) ? implode(',', $planInfo['devices']) : '',
|
|
|
|
'device_id' => isset($planInfo['devices']) ? implode(',', $planInfo['devices']) : '',
|
|
|
|
'period_id' => $planInfo['period_id'], //时间段id
|
|
|
|
'period_id' => $planInfo['period_id'], //时间段id
|
|
|
|
@ -123,45 +129,52 @@ class PlanModelController extends Controller
|
|
|
|
'time_unit' => $planInfo['time_unit'],
|
|
|
|
'time_unit' => $planInfo['time_unit'],
|
|
|
|
'status' => $planInfo['status'],
|
|
|
|
'status' => $planInfo['status'],
|
|
|
|
'adduser' => $userid,
|
|
|
|
'adduser' => $userid,
|
|
|
|
|
|
|
|
'date_type' => $date_type,
|
|
|
|
];
|
|
|
|
];
|
|
|
|
if($planInfo['end_reservation_time']>$planInfo['end_time']) return \Yz::echoError1('停止预约时间不能超过结束时间');
|
|
|
|
$param=[
|
|
|
|
|
|
|
|
|
|
|
|
//判断记录是否存在
|
|
|
|
|
|
|
|
$is_ex = DB::table('s_source_roster')->where([
|
|
|
|
|
|
|
|
'department_id' => $department_id,
|
|
|
|
'department_id' => $department_id,
|
|
|
|
'weekname' => $value,
|
|
|
|
|
|
|
|
'resources_id' => $planInfo['resources_id'],
|
|
|
|
'resources_id' => $planInfo['resources_id'],
|
|
|
|
// 'period_id' => $planInfo['period_id'], //时间段id
|
|
|
|
|
|
|
|
'is_del' => 0,
|
|
|
|
'is_del' => 0,
|
|
|
|
|
|
|
|
'date_type' => $date_type,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
if($date_type==1){
|
|
|
|
|
|
|
|
foreach ($planInfo['xingqi'] as $key => $value) {
|
|
|
|
|
|
|
|
$data['weekname'] = $value;
|
|
|
|
|
|
|
|
//判断记录是否存在
|
|
|
|
|
|
|
|
$param['weekname'] = $value;
|
|
|
|
|
|
|
|
$check=$this->Check($planInfo,$param,$value);
|
|
|
|
|
|
|
|
if(!$check['status']){
|
|
|
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
|
|
|
return \Yz::echoError1($check['msg']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($planInfo['id'] == 0) {//新增
|
|
|
|
|
|
|
|
$roster_id = DB::table('s_source_roster')->insertGetId($data);
|
|
|
|
|
|
|
|
if ($roster_id) {
|
|
|
|
|
|
|
|
foreach ($planInfo['qudao_total'] as $k => $v) {
|
|
|
|
|
|
|
|
$i_c = DB::table('s_source_roster_count')->insert([
|
|
|
|
|
|
|
|
'roster_id' => $roster_id,
|
|
|
|
|
|
|
|
'appointment_type_id' => $v['id'],
|
|
|
|
|
|
|
|
'max_total' => $planInfo['max_total'],
|
|
|
|
|
|
|
|
'count' => $v['count'],
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
if ($planInfo['id'] > 0) {
|
|
|
|
if (!$i_c) {
|
|
|
|
$is_ex = $is_ex->where('id', '<>', $planInfo['id']);
|
|
|
|
DB::rollBack();
|
|
|
|
|
|
|
|
return \Yz::echoError1('保存失败');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
$start = $planInfo['begin_time'];
|
|
|
|
} else {
|
|
|
|
$end = $planInfo['end_time'];
|
|
|
|
|
|
|
|
$is_ex = $is_ex->where(function ($query) use ($start, $end) {
|
|
|
|
|
|
|
|
// 情况1:开始时间在查询区间内
|
|
|
|
|
|
|
|
$query->whereBetween('begin_time', [$start, $end])
|
|
|
|
|
|
|
|
->orWhereBetween('end_time', [$start, $end]);
|
|
|
|
|
|
|
|
// 情况2:查询区间的开始时间在数据库记录的开始和结束时间之间
|
|
|
|
|
|
|
|
// 注意:对于时间类型的比较,直接使用字符串比较可能不够精确,特别是跨天情况,以下逻辑需根据实际情况调整
|
|
|
|
|
|
|
|
$query->orWhere(function ($query) use ($start, $end) {
|
|
|
|
|
|
|
|
$query->where('begin_time', '<=', $start)
|
|
|
|
|
|
|
|
->where('end_time', '>=', $end);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})->get();
|
|
|
|
|
|
|
|
// dd($is_ex);
|
|
|
|
|
|
|
|
//遍历判断设备是否有重叠,有则返回错误
|
|
|
|
|
|
|
|
foreach ($is_ex as $k => $v) {
|
|
|
|
|
|
|
|
$db_device_ids = explode(',', $v->device_id);
|
|
|
|
|
|
|
|
$overlap = array_intersect($planInfo['devices'], $db_device_ids);
|
|
|
|
|
|
|
|
if (count($overlap) > 0) {
|
|
|
|
|
|
|
|
DB::rollBack();
|
|
|
|
DB::rollBack();
|
|
|
|
return \Yz::echoError1($value . '时段服务组关联重复,计划id为:' . $v->id);
|
|
|
|
return \Yz::echoError1('保存失败');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}elseif ($date_type==2){
|
|
|
|
|
|
|
|
$check=$this->Check($planInfo,$param,"当前选定的");
|
|
|
|
|
|
|
|
if(!$check['status']){
|
|
|
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
|
|
|
return \Yz::echoError1($check['msg']);
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($planInfo['id'] == 0) {//新增
|
|
|
|
if ($planInfo['id'] == 0) {//新增
|
|
|
|
$roster_id = DB::table('s_source_roster')->insertGetId($data);
|
|
|
|
$roster_id = DB::table('s_source_roster')->insertGetId($data);
|
|
|
|
if ($roster_id) {
|
|
|
|
if ($roster_id) {
|
|
|
|
@ -181,7 +194,10 @@ class PlanModelController extends Controller
|
|
|
|
DB::rollBack();
|
|
|
|
DB::rollBack();
|
|
|
|
return \Yz::echoError1('保存失败');
|
|
|
|
return \Yz::echoError1('保存失败');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {//修改
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if($planInfo['id'] > 0) {//修改
|
|
|
|
$data['id'] = $planInfo['id'];
|
|
|
|
$data['id'] = $planInfo['id'];
|
|
|
|
|
|
|
|
|
|
|
|
$i = DB::table('s_source_roster')->where(['id' => $planInfo['id'], 'is_del' => 0])->update($data);
|
|
|
|
$i = DB::table('s_source_roster')->where(['id' => $planInfo['id'], 'is_del' => 0])->update($data);
|
|
|
|
@ -200,10 +216,40 @@ class PlanModelController extends Controller
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DB::commit();
|
|
|
|
DB::commit();
|
|
|
|
return \Yz::Return(true, '保存成功', []);
|
|
|
|
return \Yz::Return(true, '保存成功', []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//检测提交的信息是否有效
|
|
|
|
|
|
|
|
function Check($planInfo,$param,$shiduan)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$is_ex = DB::table('s_source_roster')->where($param);
|
|
|
|
|
|
|
|
if ($planInfo['id'] > 0) {
|
|
|
|
|
|
|
|
$is_ex = $is_ex->where('id', '<>', $planInfo['id']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$start = $planInfo['begin_time'];
|
|
|
|
|
|
|
|
$end = $planInfo['end_time'];
|
|
|
|
|
|
|
|
$is_ex = $is_ex->where(function ($query) use ($start, $end) {
|
|
|
|
|
|
|
|
// 情况1:开始时间在查询区间内
|
|
|
|
|
|
|
|
$query->whereBetween('begin_time', [$start, $end])
|
|
|
|
|
|
|
|
->orWhereBetween('end_time', [$start, $end]);
|
|
|
|
|
|
|
|
// 情况2:查询区间的开始时间在数据库记录的开始和结束时间之间
|
|
|
|
|
|
|
|
// 注意:对于时间类型的比较,直接使用字符串比较可能不够精确,特别是跨天情况,以下逻辑需根据实际情况调整
|
|
|
|
|
|
|
|
$query->orWhere(function ($query) use ($start, $end) {
|
|
|
|
|
|
|
|
$query->where('begin_time', '<=', $start)
|
|
|
|
|
|
|
|
->where('end_time', '>=', $end);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})->get();
|
|
|
|
|
|
|
|
//遍历判断设备是否有重叠,有则返回错误
|
|
|
|
|
|
|
|
foreach ($is_ex as $k => $v) {
|
|
|
|
|
|
|
|
$db_device_ids = explode(',', $v->device_id);
|
|
|
|
|
|
|
|
$overlap = array_intersect($planInfo['devices'], $db_device_ids);
|
|
|
|
|
|
|
|
if (count($overlap) > 0) {
|
|
|
|
|
|
|
|
return ['status'=>false,'msg'=>$shiduan . '时段服务组关联重复,计划id为:' . $v->id];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ['status'=>true,'msg'=>''];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取模板信息详情
|
|
|
|
//获取模板信息详情
|
|
|
|
public function GetDetailInfo()
|
|
|
|
public function GetDetailInfo()
|
|
|
|
|