You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.6 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\EditAppointmentTemplateInput;
use App\Models\AppointmentTemplate;
use Illuminate\Http\Request;
use Login;
use Yo;
class AppointmentTemplateController extends Controller
{
public function list(Request $request)
{
Login::admin([], [13, 27]);
$hospital = $request->post('hospital');
$list = AppointmentTemplate::where('hospital', $hospital)->get();
return Yo::echo([
'list' => $list
]);
}
public function select_list(Request $request)
{
Login::admin([15]);
$hospital = $request->post('hospital');
$list = AppointmentTemplate::whereIn('hospital', [$hospital, 0])->get();
return Yo::echo([
'list' => $list
]);
}
public function delete(Request $request)
{
Login::admin([], [13, 27]);
$id = $request->post('id');
$appointment_template = AppointmentTemplate::find($id);
if (!$appointment_template) Yo::error_echo(100000, ['计划模板']);
$appointment_template->delete();
return Yo::delete_echo($appointment_template->id);
}
public function update(EditAppointmentTemplateInput $request)
{
Login::admin([], [13, 27]);
$hospital = $request->post('hospital');
if (Login::$info->hospital != 0) {
if ($hospital != Login::$info->hospital) {
Yo::error_echo(100000, ['机构/医院']);
}
}
$id = $request->post('id');
$name = $request->post('name');
$weeks = $request->post('weeks');
$weekday = $request->post('weekday');
$holidays = $request->post('holidays');
$start_time = $request->post('start_time');
$end_time = $request->post('end_time');
$stop_time = $request->post('stop_time');
$max_count = $request->post('max_count');
$appointment_template = AppointmentTemplate::find($id);
if (!$appointment_template) Yo::error_echo(100000, ['计划模板']);
$appointment_template->name = $name;
$appointment_template->weeks = $weeks;
$appointment_template->hospital = $hospital;
$appointment_template->weekday = $weekday;
$appointment_template->holidays = $holidays;
$appointment_template->start_time = $start_time;
$appointment_template->end_time = $end_time;
$appointment_template->stop_time = $stop_time;
$appointment_template->max_count = $max_count;
$appointment_template->save();
return Yo::update_echo($appointment_template->id);
}
public function create(EditAppointmentTemplateInput $request)
{
Login::admin([], [13, 27]);
$hospital = $request->post('hospital');
if (Login::$info->hospital != 0) {
if ($hospital != Login::$info->hospital) {
Yo::error_echo(100000, ['机构/医院']);
}
}
$name = $request->post('name');
$weeks = $request->post('weeks');
$weekday = $request->post('weekday');
$holidays = $request->post('holidays');
$start_time = $request->post('start_time');
$end_time = $request->post('end_time');
$stop_time = $request->post('stop_time');
$max_count = $request->post('max_count');
$appointment_template = new AppointmentTemplate();
$appointment_template->name = $name;
$appointment_template->weeks = $weeks;
$appointment_template->hospital = $hospital;
$appointment_template->weekday = $weekday;
$appointment_template->holidays = $holidays;
$appointment_template->start_time = $start_time;
$appointment_template->end_time = $end_time;
$appointment_template->stop_time = $stop_time;
$appointment_template->max_count = $max_count;
$appointment_template->save();
return Yo::create_echo($appointment_template->id);
}
}