我在做一个预订系统...我遇到了以下问题:
例如,人们可以从11/06/2020 - 10:00到11:00 am…注册了这个。第二个客户端无法注册,例如从11/06/2020 - 10:30到11:30 (因为它很忙),到目前为止一切都很完美……
问题1)但如果预订的时间是2020年11月6日至上午10:00至上午11:00..。不允许客户端在2020年11月6日至上午11:00之间进行注册。至下午12:00..。他们必须在2020年6月11日至上午11:01之间执行此操作。至下午12:00..。
问题2)如果客户注册了11/06/2020 - 11:00至12:00
它允许我注册2020年11月6日-下午1:00至下午3:00例如但不是..。
11/07/2020 - 11:00至12:00
他说日程表已经很忙了,但他不会把这一天和我相比...
public function validarFecha($fecha, $horaInicial, $horaFinal)
{
$agenda = Booking::select("*")
->whereDate('day', $fecha)
->whereBetween('hour_start', [$horaInicial, $horaFinal])
->orWhereBetween('hour_end', [$horaInicial, $horaFinal])
->first();
return $agenda == null ? true : false;
}
-----------------------------
public function store(Request $request)
{
$input = $request->all();
if($this->validarFecha($input["txtFechaInicio"], $input["txtHoraInicio"], $input["txtHoraFinal"])){
$agenda = Booking::create([
"id_user"=>$input["ddlUsuarios"],
"day"=>$input["txtFechaInicio"],
"hour_start"=>$input["txtHoraInicio"],
"hour_end"=>$input["txtHoraFinal"],
"observation"=>$input["txtDescripcion"]
]);
return response()->json(["ok"=>true]);
}else{
return response()->json(["ok"=>false]);
}
dd($input);
}发布于 2020-11-07 05:59:21
只需在三元组中添加一个额外的比较,以确定$horaInicial是否与返回false的$agenda->hour_end匹配,如下所示:
return $agenda === null || $agenda->hour_end === $horaInicial 只要议程不存在,或者议程的结尾与议程的开头相匹配,我们就会有一个valid开始时间。
https://stackoverflow.com/questions/64722079
复制相似问题