生成号源

wenjuan
yanzai 1 year ago
parent 17dc26fa5c
commit 4d03740434

@ -3,6 +3,8 @@
namespace App\Http\Controllers\API\Admin\YeWu; namespace App\Http\Controllers\API\Admin\YeWu;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Services\TimeService;
use DateTime;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -14,27 +16,96 @@ class PlanController extends Controller
$Info = request('CPlan'); $Info = request('CPlan');
$params = [ $params = [
'model_id' => isset($Info['model_id']) ? $Info['model_id'] : null, 'model_id' => isset($Info['model_id']) ? $Info['model_id'] : null,
'dateRange' => isset($Info['dateRange']) ? $Info['dateRange'] : null,
'week' => isset($Info['week']) ? $Info['week'] : null, 'week' => isset($Info['week']) ? $Info['week'] : null,
'workday_create' => isset($Info['workday_create']) ? $Info['workday_create'] : null, 'workday_create' => isset($Info['workday_create']) ? $Info['workday_create'] : null,
'holiday_create' => isset($Info['holiday_create']) ? $Info['holiday_create'] : null, 'holiday_create' => isset($Info['holiday_create']) ? $Info['holiday_create'] : null,
]; ];
$requiredFields = ['model_id'=>'模板id','week'=>'星期','workday_create'=>'工作日是否生成','holiday_create'=>'节假日是否生成']; $requiredFields = ['model_id' => '模板id', 'dateRange' => '日期', 'week' => '星期', 'workday_create' => '工作日是否生成', 'holiday_create' => '节假日是否生成'];
// 判断是否为空 // 判断是否为空
foreach ($requiredFields as $key => $field) { foreach ($requiredFields as $key => $field) {
if (!isset($params[$key]) || $params[$key] === null) { if (!isset($params[$key]) || $params[$key] === null) {
return \Yz::echoError1('参数 ' . $field . ' 不能为空'); return \Yz::echoError1('参数 ' . $field . ' 不能为空');
} }
} }
if(!isset($Info['TimeRange']) or count($Info['TimeRange'])<>2){ if (!isset($Info['dateRange']) or count($Info['dateRange']) <> 2) {
return \Yz::echoError1('起止时间格式错误'); return \Yz::echoError1('起止时间格式错误');
} }
$model = DB::table('plan_model as a')->where(['a.id' => $params['model_id'], 'a.is_del' => 0, 'a.status' => 1])->first(); $model = DB::table('plan_model as a')->where(['a.id' => $params['model_id'], 'a.is_del' => 0, 'a.status' => 1])->first();
if (!$model) return \Yz::echoError1('模板不可用'); if (!$model) return \Yz::echoError1('模板不可用');
$planType=DB::table('plan_type')->where(['id'=>$model->plan_type,'a.is_del'=>0,'a.status'=>1])->first(); $planType = DB::table('plan_type as a')->where(['a.id' => $model->plan_type, 'a.is_del' => 0, 'a.status' => 1])->first();
if (!$planType) return \Yz::echoError1('号源类型不可用'); if (!$planType) return \Yz::echoError1('号源类型不可用');
//查询此时间段内是否有已经生成的号源
$cha=DB::table('plans')->whereBetween('date',$Info['dateRange'])->get();
if(count($cha)>0){
return \Yz::return(false,'号源重复',['list'=>$cha]);
}
//获取模板的全部时间点
$s=new TimeService();
$timelist=$s->TimePointsArr($model->start_time,$model->end_time,$model->interval_time);
if(count($timelist)<1) return \Yz::echoError1('');
$startDate = new DateTime($Info['dateRange'][0]);
$endDate = new DateTime($Info['dateRange'][1]);
$currentDate = $startDate;
$success_count=0;
while ($currentDate <= $endDate) {
//循环生成
$date_ymd=$currentDate->format('Y-m-d');
//判断节假日是否生成
$s_day=DB::table('plan_holiday')->select('*','type as tp')->where(['date'=>$date_ymd])->first();
if(!!$s_day){
if($s_day->tp==1 and $params['workday_create']===0){
$currentDate->modify('+1 day');
continue;
}
if($s_day->tp==2 and $params['holiday_create']===0){
$currentDate->modify('+1 day');
continue;
}
}
//获取星期几 星期1=1 星期日=7
$dayOfWeek = $currentDate->format('N');
//如果星期匹配上了
if(in_array($dayOfWeek, $params['week'])) {
foreach ($timelist as $key=>$time){
$type=1; //正常
if(in_array($key,json_decode($model->y_number,true))){
$type=0;//预留
}
$data=[
'model_id'=>$model->id,
'date'=>$date_ymd,
'week'=>$dayOfWeek,
'time'=>$time,
'type'=>$type,
'plan_number'=>implode('', explode(':', $time)),
'is_vip'=>$planType->is_vip,
'use_type'=>$planType->use_type,
'sex'=>$planType->sex,
'checkup_type_id'=>$planType->checkup_type_id,
'amount_limit1'=>$planType->amount_limit1,
'amount_limit2'=>$planType->amount_limit2,
'hospital_id'=>$model->hospital_id,
'status'=>1,
'is_del'=>0
];
$i=DB::table('plans')->insert($data);
if($i){
$success_count++;
}
}
}
// 日期加一天
$currentDate->modify('+1 day');
}
if($success_count>0){
return \Yz::Return(true,'',['success_count'=>$success_count]);
}else{
return \Yz::echoError1('没有计划被创建');
}
} }
} }

@ -3,6 +3,7 @@
namespace App\Http\Controllers\API\Admin\YeWu; namespace App\Http\Controllers\API\Admin\YeWu;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Services\TimeService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -11,18 +12,11 @@ class PlanModelController extends Controller
public function timeList() public function timeList()
{ {
$TimeRange = request('TimeRange'); $TimeRange = request('TimeRange');
if(count($TimeRange)<>2){ if(count($TimeRange)<>2) return \Yz::echoError1('起止时间格式错误');
return \Yz::echoError1('起止时间格式错误');
}
$start_time=$TimeRange[0];
$end_time=$TimeRange[1];
if (count(explode(':', $start_time)) == 1) $start_time = date('H:i:s', $start_time / 1000);
if (count(explode(':', $end_time)) == 1) $end_time = date('H:i:s', $end_time / 1000);
$interval_time = request('interval_time'); $interval_time = request('interval_time');
$list=$this->timeArr($start_time, $end_time, $interval_time); $s=new TimeService();
$list=$s->TimePointsArr($TimeRange[0],$TimeRange[1],$interval_time);
return \Yz::Return(true,"查询完成",['list' =>$list]); return \Yz::Return(true,"查询完成",['list' =>$list]);
} }
public function GetList() public function GetList()
{ {
@ -53,6 +47,7 @@ class PlanModelController extends Controller
{ {
$Info =request('Info'); $Info =request('Info');
$params = [ $params = [
'hospital_id' => isset($Info['hospital_id']) ? $Info['hospital_id'] :null,
'name' => isset($Info['name']) ? $Info['name'] : null, 'name' => isset($Info['name']) ? $Info['name'] : null,
'interval_time' => isset($Info['interval_time']) ? $Info['interval_time'] : null, 'interval_time' => isset($Info['interval_time']) ? $Info['interval_time'] : null,
'plan_type' => isset($Info['plan_type']) ? $Info['plan_type'] : null, 'plan_type' => isset($Info['plan_type']) ? $Info['plan_type'] : null,
@ -60,7 +55,7 @@ class PlanModelController extends Controller
'count' => isset($Info['count']) ? $Info['count'] : 0, 'count' => isset($Info['count']) ? $Info['count'] : 0,
'status'=>isset($Info['status']) ? $Info['status'] : 0, 'status'=>isset($Info['status']) ? $Info['status'] : 0,
]; ];
$requiredFields = ['name'=>'名称','interval_time'=>'时间间隔','plan_type'=>'号源类型']; $requiredFields = ['hospital_id'=>'医院','name'=>'名称','interval_time'=>'时间间隔','plan_type'=>'号源类型'];
// 判断是否为空 // 判断是否为空
foreach ($requiredFields as $key=> $field) { foreach ($requiredFields as $key=> $field) {
if (!isset($params[$key]) || $params[$key] === null) { if (!isset($params[$key]) || $params[$key] === null) {
@ -111,12 +106,5 @@ class PlanModelController extends Controller
return \Yz::echoError1('操作失败'); return \Yz::echoError1('操作失败');
} }
} }
function timeArr($start_time, $end_time, $interval_time, $arr = [])
{
if (strtotime($start_time) > strtotime($end_time)) return $arr;
$arr[] = date('H:i', strtotime($start_time));
return $this->timeArr(date('Y-m-d H:i:s', strtotime($start_time) + ($interval_time * 60)), $end_time, $interval_time, $arr);
}
} }

@ -0,0 +1,23 @@
<?php
namespace App\Services;
class TimeService
{
//根据时间段获取时间点
public function TimePointsArr($start_time,$end_time,$interval_time)
{
if (count(explode(':', $start_time)) == 1) $start_time = date('H:i:s', $start_time / 1000);
if (count(explode(':', $end_time)) == 1) $end_time = date('H:i:s', $end_time / 1000);
return $this->timeArr($start_time, $end_time, $interval_time);
}
function timeArr($start_time, $end_time, $interval_time, $arr = [])
{
if (strtotime($start_time) > strtotime($end_time)) return $arr;
$arr[] = date('H:i', strtotime($start_time));
return $this->timeArr(date('Y-m-d H:i:s', strtotime($start_time) + ($interval_time * 60)), $end_time, $interval_time, $arr);
}
}

@ -47,6 +47,12 @@
<el-dialog v-model="dialogVisible" title="号源模板设置"> <el-dialog v-model="dialogVisible" title="号源模板设置">
<div class="chuansuokuang" v-loading="loading"> <div class="chuansuokuang" v-loading="loading">
<el-form :model="Info" label-width="150" style="max-width: 600px"> <el-form :model="Info" label-width="150" style="max-width: 600px">
<el-form-item label="医院">
<el-select :filterable="true" clearable v-model="Info.hospital_id" placeholder="选择医院">
<el-option label="海南现代妇女儿童医院"
:value="1" />
</el-select>
</el-form-item>
<el-form-item label="名称"> <el-form-item label="名称">
<el-input v-model="Info.name" /> <el-input v-model="Info.name" />
</el-form-item> </el-form-item>
@ -99,6 +105,7 @@
<el-date-picker <el-date-picker
v-model="CPlan.dateRange" v-model="CPlan.dateRange"
type="daterange" type="daterange"
value-format="YYYY-MM-DD"
range-separator="至" range-separator="至"
start-placeholder="开始日期" start-placeholder="开始日期"
end-placeholder="结束日期"> end-placeholder="结束日期">
@ -137,6 +144,21 @@
</span> </span>
</template> </template>
</el-dialog> </el-dialog>
<el-dialog v-model="CreatTiShiDialogVisible" title="生成号源">
<div style="margin-bottom: 10px;">当前选择的时间段和现有如下计划时间段有重叠</div>
<div style="display: flex; justify-content: space-between;flex-wrap: wrap;">
<el-tag style="margin: 4px;" size="large" v-for="(item,index) in ChongFuList" :key="index" type="primary">{{item.date +' '+item.time}}</el-tag>
</div>
<template #footer>
<span class="dialog-footer">
<el-button @click="CreatTiShiDialogVisible = false">取消</el-button>
<el-button type="primary" @click="CreatePlans()">
确定
</el-button>
</span>
</template>
</el-dialog>
</div> </div>
</template> </template>
@ -193,6 +215,7 @@
const Add = () => { const Add = () => {
Info.value = {} Info.value = {}
Info.value.id = 0 Info.value.id = 0
Info.value.hospital_id=1
Info.value.status = 1 Info.value.status = 1
Info.value.TimeRange = ['08:00:00', '12:00:00'] Info.value.TimeRange = ['08:00:00', '12:00:00']
Info.value.interval_time = 5 // Info.value.interval_time = 5 //
@ -331,6 +354,8 @@
} }
let CPlan=ref({}); let CPlan=ref({});
let CreatPlanDialogVisible = ref(false) let CreatPlanDialogVisible = ref(false)
let CreatTiShiDialogVisible= ref(false)
let ChongFuList=ref([]);
const CreatPlanClick = (row) => { const CreatPlanClick = (row) => {
CreatPlanDialogVisible.value = true CreatPlanDialogVisible.value = true
CPlan.value.name=row.name CPlan.value.name=row.name
@ -350,8 +375,16 @@
}).then(res => { }).then(res => {
loading.value = false loading.value = false
if (res.status) { if (res.status) {
CreatPlanDialogVisible.value = false
ElMessage({
message: "成功创建"+res.data.success_count+"条计划",
type: 'success',
})
} else { } else {
if(res.msg=='号源重复'){
CreatTiShiDialogVisible.value=true
ChongFuList.value=res.data.list
}
ElMessage.error(res.msg) ElMessage.error(res.msg)
} }
}) })

Loading…
Cancel
Save