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.
124 lines
3.9 KiB
PHP
124 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\EditHospitalPostInput;
|
|
use App\Models\HospitalPost;
|
|
use Illuminate\Http\Request;
|
|
use Yo;
|
|
use Login;
|
|
|
|
class HospitalPostController extends Controller
|
|
{
|
|
public function delete(Request $request)
|
|
{
|
|
Login::admin([17]);
|
|
$ids = $request->post('ids');
|
|
HospitalPost::whereIn('id', $ids)->update([
|
|
'del' => 1
|
|
]);
|
|
return Yo::delete_echo($ids);
|
|
}
|
|
|
|
public function update(EditHospitalPostInput $request)
|
|
{
|
|
Login::admin([], [17, 25]);
|
|
$hospital = $request->post('hospital');
|
|
if (Login::$info->hospital != 0) {
|
|
if ($hospital != Login::$info->hospital) {
|
|
Yo::error_echo(100000, ['机构/医院']);
|
|
}
|
|
}
|
|
$id = $request->post('id');
|
|
$title = $request->post('title');
|
|
$author = $request->post('author');
|
|
$date = $request->post('date');
|
|
$desc = $request->post('desc');
|
|
$content = $request->post('content');
|
|
$cover = $request->post('cover');
|
|
$type = $request->post('type');
|
|
$status = $request->post('status');
|
|
$hospital_post = HospitalPost::find($id);
|
|
if (!$hospital_post) Yo::error_echo(100000, ['新闻']);
|
|
$hospital_post->hospital = $hospital;
|
|
$hospital_post->title = $title;
|
|
$hospital_post->author = $author;
|
|
$hospital_post->date = $date;
|
|
$hospital_post->desc = $desc;
|
|
$hospital_post->content = $content;
|
|
$hospital_post->cover = $cover ?? '';
|
|
$hospital_post->type = $type;
|
|
$hospital_post->status = $status;
|
|
$hospital_post->save();
|
|
return Yo::update_echo($hospital_post->id);
|
|
}
|
|
|
|
public function create(EditHospitalPostInput $request)
|
|
{
|
|
Login::admin([], [17, 25]);
|
|
$hospital = $request->post('hospital');
|
|
if (Login::$info->hospital != 0) {
|
|
if ($hospital != Login::$info->hospital) {
|
|
Yo::error_echo(100000, ['机构/医院']);
|
|
}
|
|
}
|
|
$title = $request->post('title');
|
|
$author = $request->post('author');
|
|
$date = $request->post('date');
|
|
$desc = $request->post('desc');
|
|
$content = $request->post('content');
|
|
$cover = $request->post('cover');
|
|
$type = $request->post('type');
|
|
$status = $request->post('status');
|
|
$hospital_post = new HospitalPost();
|
|
$hospital_post->hospital = $hospital;
|
|
$hospital_post->title = $title;
|
|
$hospital_post->author = $author;
|
|
$hospital_post->date = $date;
|
|
$hospital_post->desc = $desc;
|
|
$hospital_post->content = $content;
|
|
$hospital_post->cover = $cover ?? '';
|
|
$hospital_post->type = $type;
|
|
$hospital_post->status = $status;
|
|
$hospital_post->save();
|
|
return Yo::create_echo($hospital_post->id);
|
|
}
|
|
|
|
public function admin_list(Request $request)
|
|
{
|
|
$hospital = $request->post('hospital');
|
|
$type = $request->post('type');
|
|
$hospital_post_list = HospitalPost::where('hospital', $hospital)
|
|
->where(function ($query) use ($type) {
|
|
if ($type != 0) $query->where('type', $type);
|
|
})
|
|
->where('del', 2)->orderBy('id', 'desc')
|
|
->paginate(15);
|
|
return Yo::echo($hospital_post_list);
|
|
}
|
|
|
|
public function list(Request $request)
|
|
{
|
|
$hospital = $request->post('hospital');
|
|
$type = $request->post('type');
|
|
$hospital_post_list = HospitalPost::select('id', 'title', 'author', 'date', 'desc', 'cover')->where('hospital', $hospital)
|
|
->where('type', $type)
|
|
->where('status', 1)->where('del', 2)->orderBy('id', 'desc')->get();
|
|
if (count($hospital_post_list) == 0) {
|
|
$hospital_post_list = HospitalPost::where('hospital', 0)
|
|
->where('type', $type)
|
|
->where('status', 1)->where('del', 2)->orderBy('id', 'desc')->get();
|
|
}
|
|
return Yo::echo(['list' => $hospital_post_list]);
|
|
}
|
|
|
|
public function info(Request $request)
|
|
{
|
|
$id = $request->post('id');
|
|
$hospital_post = HospitalPost::where('id', $id)
|
|
->where('status', 1)->where('del', 2)->first();
|
|
if (!$hospital_post) Yo::error_echo(100000, ['文章']);
|
|
return Yo::echo(['info' => $hospital_post]);
|
|
}
|
|
}
|