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.

158 lines
5.0 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\EditCarouselInput;
use Illuminate\Http\Request;
use App\Models\Carousel;
use Yo;
use Login;
class CarouselController extends Controller
{
public function create(EditCarouselInput $request)
{
Login::admin([], [17, 23]);
$hospital = $request->post('hospital');
if (Login::$info->hospital != 0) {
if ($hospital != Login::$info->hospital) {
Yo::error_echo(100000, ['机构/医院']);
}
}
$name = $request->post('name');
$image = $request->post('image');
$desc = $request->post('desc');
$type = $request->post('type');
$jump_type = $request->post('jump_type');
$jump_path = $request->post('jump_path');
$login_type = $request->post('login_type');
$start_time = $request->post('start_time');
$end_time = $request->post('end_time');
$status = $request->post('status');
if (strtotime($start_time) > strtotime($end_time)) Yo::error_echo(200020);
$carousel = new Carousel();
$carousel->name = $name;
$carousel->image = $image;
$carousel->desc = $desc;
$carousel->hospital = $hospital;
$carousel->type = $type;
$carousel->jump_type = $jump_type;
$carousel->jump_path = $jump_path ?? '';
$carousel->login_type = $login_type;
$carousel->start_time = $start_time;
$carousel->end_time = $end_time;
$carousel->status = $status;
$carousel->save();
return Yo::create_echo($carousel->id);
}
public function update(EditCarouselInput $request)
{
Login::admin([], [17, 23]);
$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');
$image = $request->post('image');
$desc = $request->post('desc');
$type = $request->post('type');
$jump_type = $request->post('jump_type');
$jump_path = $request->post('jump_path');
$login_type = $request->post('login_type');
$start_time = $request->post('start_time');
$end_time = $request->post('end_time');
$status = $request->post('status');
if (strtotime($start_time) > strtotime($end_time)) Yo::error_echo(200020);
$carousel = Carousel::find($id);
if (!$carousel) Yo::error_echo(100000, ['内容']);
$carousel->name = $name;
$carousel->image = $image;
$carousel->desc = $desc;
$carousel->hospital = $hospital;
$carousel->type = $type;
$carousel->jump_type = $jump_type;
$carousel->jump_path = $jump_path ?? '';
$carousel->login_type = $login_type;
$carousel->start_time = $start_time;
$carousel->end_time = $end_time;
$carousel->status = $status;
$carousel->save();
return Yo::update_echo($carousel->id);
}
public function delete(Request $request)
{
Login::admin([], [17, 23]);
$id = $request->post('id');
$carousel = Carousel::find($id);
if (!$carousel) Yo::error_echo(100000, ['内容']);
$hospital = $carousel->hospital;
if (Login::$info->hospital != 0) {
if ($hospital != Login::$info->hospital) {
Yo::error_echo(100000, ['机构/医院']);
}
}
$carousel->delete();
return Yo::delete_echo($carousel->id);
}
public function list(Request $request)
{
Login::admin([], [17, 23]);
$type = $request->post('type');
$hospital = $request->post('hospital');
if (Login::$info->hospital != 0) {
if ($hospital != Login::$info->hospital) {
Yo::error_echo(100000, ['机构/医院']);
}
}
$carousel_list = Carousel::where('hospital', $hospital)->where('type', $type)->get();
return Yo::echo([
'list' => $carousel_list
]);
}
public function mp_list(Request $request)
{
$type = $request->post('type');
$hospital = $request->post('hospital');
$carousel_list = Carousel::where('hospital', $hospital)
->where('type', $type)
->where('start_time', '<=', date('Y-m-d H:i:s'))
->where('end_time', '>=', date('Y-m-d H:i:s'))
->where('status', 1)
->get();
if (count($carousel_list) == 0) $carousel_list = [];
$merged_list = [];
if ($type == 1 || $type == 2) {
$public_list = Carousel::where('hospital', 0)
->where('type', $type)
->where('start_time', '<=', date('Y-m-d H:i:s'))
->where('end_time', '>=', date('Y-m-d H:i:s'))
->where('status', 1)
->get();
if (count($carousel_list) == 0) {
$merged_list = $public_list;
} else {
$merged_list = array_merge($carousel_list->toArray(), $public_list->toArray());
}
} else if ($type == 3 || $type == 4) {
if (count($carousel_list) == 0) {
$merged_list = Carousel::where('hospital', 0)
->where('type', $type)
->where('start_time', '<=', date('Y-m-d H:i:s'))
->where('end_time', '>=', date('Y-m-d H:i:s'))
->where('status', 1)
->get();
}
}
return Yo::echo([
'list' => $merged_list
]);
}
}