|
|
|
|
@ -7,6 +7,7 @@ use App\Services\Admin\YeWu\PlanListService;
|
|
|
|
|
use DateTime;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
use Tools;
|
|
|
|
|
|
|
|
|
|
class PlanListController extends Controller
|
|
|
|
|
@ -19,6 +20,8 @@ class PlanListController extends Controller
|
|
|
|
|
$department_id = $userInfo[0]->department_id;
|
|
|
|
|
$dateRange = request('dateRange');
|
|
|
|
|
$planModelIds = request('ids');
|
|
|
|
|
$HolidayEnable = request('HolidayEnable');
|
|
|
|
|
$date_type = request('date_type');
|
|
|
|
|
//循环日期和勾选的模板创建明细
|
|
|
|
|
if (count($dateRange) == 2 && count($planModelIds) > 0) {
|
|
|
|
|
$models = DB::table('s_source_roster')->whereIn('id', $planModelIds)->get();
|
|
|
|
|
@ -39,31 +42,47 @@ class PlanListController extends Controller
|
|
|
|
|
->where('date', '<=', $end_date->format('Y-m-d'))
|
|
|
|
|
->where('is_del', 0)
|
|
|
|
|
->get();
|
|
|
|
|
$msg='</br>当前选中的';
|
|
|
|
|
$msglist='';
|
|
|
|
|
$msgIds='';
|
|
|
|
|
$msg = '</br>当前选中的';
|
|
|
|
|
$msglist = '';
|
|
|
|
|
$msgIds = '';
|
|
|
|
|
if (count($checkList) > 0) {
|
|
|
|
|
foreach ($models as $model ){
|
|
|
|
|
foreach ($models as $model) {
|
|
|
|
|
foreach ($checkList as $item) {
|
|
|
|
|
$msglist.=$item->date.' ';
|
|
|
|
|
$msgIds.=$item->id.' ';
|
|
|
|
|
$msglist .= $item->date . ' ';
|
|
|
|
|
$msgIds .= $item->id . ' ';
|
|
|
|
|
}
|
|
|
|
|
if($item->roster_id==$model->id){
|
|
|
|
|
$msg.=" ".$model->weekname.$model->begin_time.'-'.$model->end_time." ";
|
|
|
|
|
if ($item->roster_id == $model->id) {
|
|
|
|
|
$msg .= " " . $model->weekname . $model->begin_time . '-' . $model->end_time . " ";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return \Yz::Return(false,'已有重复的计划明细,禁止创建!'.$msg.'已存在相同记录,</br>存在于:</br>'.$msglist.'</br>对应记录Id为:'.$msgIds.'</br>请先删除后再操作', $checkList);
|
|
|
|
|
return \Yz::Return(false, '已有重复的计划明细,禁止创建!' . $msg . '已存在相同记录,</br>存在于:</br>' . $msglist . '</br>对应记录Id为:' . $msgIds . '</br>请先删除后再操作', $checkList);
|
|
|
|
|
}
|
|
|
|
|
//查询勾选的时间范围内所有的节假日
|
|
|
|
|
$holiday_list=DB::table('s_holiday')->whereBetween('date',$dateRange)->where(['type'=>2])->pluck('date')->toArray();
|
|
|
|
|
|
|
|
|
|
// 循环日期并判断星期
|
|
|
|
|
$current_date = clone $start_date;
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
$success_count=0;//成功创建的数量
|
|
|
|
|
$success_count = 0;//成功创建的数量
|
|
|
|
|
while ($current_date <= $end_date) {
|
|
|
|
|
//如果是节假日模板,则判断当前日期是否是节假日,不是则跳过
|
|
|
|
|
if ($date_type == 2) {
|
|
|
|
|
if (!in_array($current_date->format('Y-m-d'),$holiday_list)){
|
|
|
|
|
// 将当前日期增加一天
|
|
|
|
|
$current_date->modify('+1 day');
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//如果选择节假日不可用,并且当前日期是节假日,则跳过
|
|
|
|
|
if($HolidayEnable==0 and in_array($current_date->format('Y-m-d'),$holiday_list)){
|
|
|
|
|
// 将当前日期增加一天
|
|
|
|
|
$current_date->modify('+1 day');
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取当前日期的星期几(0表示星期日,1表示星期一,以此类推)
|
|
|
|
|
$weekday = $current_date->format('w');
|
|
|
|
|
$weekname = '';
|
|
|
|
|
@ -91,77 +110,79 @@ class PlanListController extends Controller
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
foreach ($models as $model) {
|
|
|
|
|
if ($model->weekname == $weekname) {
|
|
|
|
|
// 插入明细表
|
|
|
|
|
$data = [
|
|
|
|
|
'roster_id' => $model->id,
|
|
|
|
|
'date' => $current_date,
|
|
|
|
|
'weekname' => $weekname,
|
|
|
|
|
'department_id' => $model->department_id,
|
|
|
|
|
'resources_id' => $model->resources_id,
|
|
|
|
|
'device_id' => $model->device_id,
|
|
|
|
|
'period_id' => $model->period_id,
|
|
|
|
|
'patient_type' => $model->patient_type,
|
|
|
|
|
'begin_time' => $model->begin_time,
|
|
|
|
|
'end_time' => $model->end_time,
|
|
|
|
|
'end_reservation_time' => $model->end_reservation_time,
|
|
|
|
|
'time_unit' => $model->time_unit,
|
|
|
|
|
'status' => 1,
|
|
|
|
|
'adduser' => $userid,
|
|
|
|
|
'is_del' => 0,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$plan_id = DB::table('s_source_roster_detail')->insertGetId($data);
|
|
|
|
|
if($plan_id){
|
|
|
|
|
$success_count++;
|
|
|
|
|
}
|
|
|
|
|
// 插入数量表
|
|
|
|
|
$model_count_info = DB::table('s_source_roster_count')->where(['roster_id' => $model->id])->get();
|
|
|
|
|
if (count($model_count_info) > 0) {
|
|
|
|
|
foreach ($model_count_info as $info) {
|
|
|
|
|
$i_c = DB::table('s_source_roster_detail_count')->insert([
|
|
|
|
|
'roster_detail_id' => $plan_id,
|
|
|
|
|
'appointment_type_id' => $info->appointment_type_id,
|
|
|
|
|
'count' => $info->count,
|
|
|
|
|
'max_total' => $info->max_total,
|
|
|
|
|
]);
|
|
|
|
|
if (!$i_c) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('渠道数量创建失败');
|
|
|
|
|
}
|
|
|
|
|
if ($date_type == 1 and $model->date_type==1) {
|
|
|
|
|
if ($model->weekname <> $weekname) continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 插入明细表
|
|
|
|
|
$data = [
|
|
|
|
|
'roster_id' => $model->id,
|
|
|
|
|
'date' => $current_date,
|
|
|
|
|
'weekname' => $weekname,
|
|
|
|
|
'department_id' => $model->department_id,
|
|
|
|
|
'resources_id' => $model->resources_id,
|
|
|
|
|
'device_id' => $model->device_id,
|
|
|
|
|
'period_id' => $model->period_id,
|
|
|
|
|
'patient_type' => $model->patient_type,
|
|
|
|
|
'begin_time' => $model->begin_time,
|
|
|
|
|
'end_time' => $model->end_time,
|
|
|
|
|
'end_reservation_time' => $model->end_reservation_time,
|
|
|
|
|
'time_unit' => $model->time_unit,
|
|
|
|
|
'status' => 1,
|
|
|
|
|
'adduser' => $userid,
|
|
|
|
|
'is_del' => 0,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$plan_id = DB::table('s_source_roster_detail')->insertGetId($data);
|
|
|
|
|
if ($plan_id) {
|
|
|
|
|
$success_count++;
|
|
|
|
|
}
|
|
|
|
|
// 插入数量表
|
|
|
|
|
$model_count_info = DB::table('s_source_roster_count')->where(['roster_id' => $model->id])->get();
|
|
|
|
|
if (count($model_count_info) > 0) {
|
|
|
|
|
foreach ($model_count_info as $info) {
|
|
|
|
|
$i_c = DB::table('s_source_roster_detail_count')->insert([
|
|
|
|
|
'roster_detail_id' => $plan_id,
|
|
|
|
|
'appointment_type_id' => $info->appointment_type_id,
|
|
|
|
|
'count' => $info->count,
|
|
|
|
|
'max_total' => $info->max_total,
|
|
|
|
|
]);
|
|
|
|
|
if (!$i_c) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('渠道数量创建失败');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('模板数量信息异常,请重新选择!异常模板Id:' . $model->id);
|
|
|
|
|
}
|
|
|
|
|
if(isset($model->device_id)){
|
|
|
|
|
$device_ids =explode(",", $model->device_id);
|
|
|
|
|
foreach ($device_ids as $dv_key=>$dv_value){
|
|
|
|
|
$i_dev = DB::table('s_source_roster_detail_device')->insert([
|
|
|
|
|
'roster_detail_id' => $plan_id,
|
|
|
|
|
'device_id' => $dv_value,
|
|
|
|
|
]);
|
|
|
|
|
if (!$i_dev) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('设备关联创建失败');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('模板数量信息异常,请重新选择!异常模板Id:' . $model->id);
|
|
|
|
|
}
|
|
|
|
|
if (isset($model->device_id)) {
|
|
|
|
|
$device_ids = explode(",", $model->device_id);
|
|
|
|
|
foreach ($device_ids as $dv_key => $dv_value) {
|
|
|
|
|
$i_dev = DB::table('s_source_roster_detail_device')->insert([
|
|
|
|
|
'roster_detail_id' => $plan_id,
|
|
|
|
|
'device_id' => $dv_value,
|
|
|
|
|
]);
|
|
|
|
|
if (!$i_dev) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('设备关联创建失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('模板未关联设备,请重新选择!异常模板Id:' . $model->id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('模板未关联设备,请重新选择!异常模板Id:' . $model->id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// 将当前日期增加一天
|
|
|
|
|
$current_date->modify('+1 day');
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
DB::commit();
|
|
|
|
|
return \Yz::Return(true, '执行完成,范围:'.$dateRange[0].'-'.$dateRange[1].',共计生成计划 '.$success_count.' 条', ['dateRange'=>$dateRange,'success_count'=>$success_count]);
|
|
|
|
|
return \Yz::Return(true, '执行完成,范围:' . $dateRange[0] . '-' . $dateRange[1] . ',共计生成计划 ' . $success_count . ' 条', ['dateRange' => $dateRange, 'success_count' => $success_count]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -242,7 +263,7 @@ class PlanListController extends Controller
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return \Yz::Return(true, '获取成功', ['list' => $list,'count' => $count]);
|
|
|
|
|
return \Yz::Return(true, '获取成功', ['list' => $list, 'count' => $count]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function GetDetail()
|
|
|
|
|
@ -320,12 +341,13 @@ class PlanListController extends Controller
|
|
|
|
|
$appointment_type = request('appointment_type'); //预约类型
|
|
|
|
|
$appointment_date = request('date'); //预约日期
|
|
|
|
|
$service = new PlanListService();
|
|
|
|
|
return $service->GetEnablePlan($regnum,$entrustid,$episodeid,$appointment_type,$appointment_date);
|
|
|
|
|
return $service->GetEnablePlan($regnum, $entrustid, $episodeid, $appointment_type, $appointment_date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取最近可用的,计划 日期
|
|
|
|
|
public function NearestEnablePlanDate()
|
|
|
|
|
{
|
|
|
|
|
$dateRange=7;
|
|
|
|
|
$dateRange = 7;
|
|
|
|
|
$regnum = request('regnum');
|
|
|
|
|
$entrustids = request('entrustid');
|
|
|
|
|
$episodeid = request('episodeid');
|
|
|
|
|
@ -333,31 +355,31 @@ class PlanListController extends Controller
|
|
|
|
|
$appointment_date = request('date'); //预约日期
|
|
|
|
|
$service = new PlanListService();
|
|
|
|
|
|
|
|
|
|
$date_arr=[];
|
|
|
|
|
$date_arr = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$startDate = new DateTime();
|
|
|
|
|
// 设定结束日期为当前日期加7天
|
|
|
|
|
// 设定结束日期为当前日期加7天
|
|
|
|
|
$endDate = new DateTime();
|
|
|
|
|
$endDate->modify('+'.$dateRange.' day');
|
|
|
|
|
// 循环遍历每一天
|
|
|
|
|
$endDate->modify('+' . $dateRange . ' day');
|
|
|
|
|
// 循环遍历每一天
|
|
|
|
|
$currentDate = $startDate;
|
|
|
|
|
while ($currentDate <= $endDate) {
|
|
|
|
|
$nowdate= $currentDate->format('Y-m-d');
|
|
|
|
|
$s=$service->GetEnablePlan($regnum,$entrustids,$episodeid,$appointment_type,$nowdate);
|
|
|
|
|
if($s['status']){
|
|
|
|
|
$list= $s['data']['plan_list'];
|
|
|
|
|
if(count($list)>0){
|
|
|
|
|
$date_arr[]= $s['data']['appointment_date'];
|
|
|
|
|
$nowdate = $currentDate->format('Y-m-d');
|
|
|
|
|
$s = $service->GetEnablePlan($regnum, $entrustids, $episodeid, $appointment_type, $nowdate);
|
|
|
|
|
if ($s['status']) {
|
|
|
|
|
$list = $s['data']['plan_list'];
|
|
|
|
|
if (count($list) > 0) {
|
|
|
|
|
$date_arr[] = $s['data']['appointment_date'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(count($date_arr)>=2){
|
|
|
|
|
if (count($date_arr) >= 2) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// 每次循环增加一天
|
|
|
|
|
$currentDate->modify('+1 day');
|
|
|
|
|
}
|
|
|
|
|
return \Yz::Return(true,'查询完成',['list'=>$date_arr]);
|
|
|
|
|
return \Yz::Return(true, '查询完成', ['list' => $date_arr]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -374,7 +396,7 @@ class PlanListController extends Controller
|
|
|
|
|
if (!isset($do_type)) return \Yz::echoError1('参数:操作类型 不能为空');
|
|
|
|
|
|
|
|
|
|
$service = new PlanListService();
|
|
|
|
|
return $service->YuYue($planid,$appointment_type,$mainlistid,$do_type);
|
|
|
|
|
return $service->YuYue($planid, $appointment_type, $mainlistid, $do_type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function CancelYuYue(Request $request)
|
|
|
|
|
@ -386,10 +408,10 @@ class PlanListController extends Controller
|
|
|
|
|
$password = request('password');
|
|
|
|
|
$userid = $request->get('userid');//中间件产生的参数
|
|
|
|
|
$query = DB::table('users')->where(['id' => $userid])->get();
|
|
|
|
|
if(password_verify($password,$query[0]->pwd)) {
|
|
|
|
|
if (password_verify($password, $query[0]->pwd)) {
|
|
|
|
|
|
|
|
|
|
$service = new PlanListService();
|
|
|
|
|
return $service->CancelYuYue($MainListId,$reg_num);
|
|
|
|
|
return $service->CancelYuYue($MainListId, $reg_num);
|
|
|
|
|
|
|
|
|
|
// $mainInfo = DB::table('s_list')->where(['id' => $MainListId])->first();
|
|
|
|
|
// if (!$mainInfo) return \Yz::echoError1('医嘱不存在');
|
|
|
|
|
@ -421,7 +443,7 @@ class PlanListController extends Controller
|
|
|
|
|
// return \Yz::echoError1('取消异常');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
return \Yz::echoError1('密码不正确');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -430,24 +452,24 @@ class PlanListController extends Controller
|
|
|
|
|
public function GetUsedList()
|
|
|
|
|
{
|
|
|
|
|
$planid = request('planid');
|
|
|
|
|
$qudaoid= request('qudaoid');
|
|
|
|
|
$list=DB::table('s_list')
|
|
|
|
|
->leftJoin('s_department_resources','s_list.reservation_sources','=','s_department_resources.id')
|
|
|
|
|
->select('s_list.*','s_department_resources.department_resources_name')
|
|
|
|
|
->where(['s_list.roster_id'=>$planid,'s_list.is_del'=>0,'s_list.is_nullify'=>0])->whereIn('s_list.list_status',[1,2,3]);
|
|
|
|
|
$qudaoid = request('qudaoid');
|
|
|
|
|
$list = DB::table('s_list')
|
|
|
|
|
->leftJoin('s_department_resources', 's_list.reservation_sources', '=', 's_department_resources.id')
|
|
|
|
|
->select('s_list.*', 's_department_resources.department_resources_name')
|
|
|
|
|
->where(['s_list.roster_id' => $planid, 's_list.is_del' => 0, 's_list.is_nullify' => 0])->whereIn('s_list.list_status', [1, 2, 3]);
|
|
|
|
|
if (!empty($qudaoid)) {
|
|
|
|
|
$list=$list->where(['s_list.appointment_type_id'=>$qudaoid]);
|
|
|
|
|
$list = $list->where(['s_list.appointment_type_id' => $qudaoid]);
|
|
|
|
|
}
|
|
|
|
|
$list=$list->get();
|
|
|
|
|
$qudao=DB::table('s_appointment_type')->get();
|
|
|
|
|
foreach ($list as $key=>$item){
|
|
|
|
|
foreach ($qudao as $q){
|
|
|
|
|
if($q->id==$item->appointment_type_id){
|
|
|
|
|
$item->qudao_name=$q->name;
|
|
|
|
|
$list = $list->get();
|
|
|
|
|
$qudao = DB::table('s_appointment_type')->get();
|
|
|
|
|
foreach ($list as $key => $item) {
|
|
|
|
|
foreach ($qudao as $q) {
|
|
|
|
|
if ($q->id == $item->appointment_type_id) {
|
|
|
|
|
$item->qudao_name = $q->name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return \Yz::Return(true,'查询完成',$list);
|
|
|
|
|
return \Yz::Return(true, '查询完成', $list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|