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.
195 lines
6.0 KiB
PHP
195 lines
6.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Hospital;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Requests\EditHospitalInput;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Login;
|
|
use Yo;
|
|
|
|
class HospitalController extends Controller
|
|
{
|
|
public function list()
|
|
{
|
|
Login::admin([11]);
|
|
$list = Hospital::where('del', 2)->get();
|
|
return Yo::echo([
|
|
'list' => $list
|
|
]);
|
|
}
|
|
|
|
public function info(Request $request)
|
|
{
|
|
$id = $request->post('id');
|
|
$latitude = $request->post('latitude');
|
|
$longitude = $request->post('longitude');
|
|
$info = Hospital::select('id', 'address', 'logo', 'name', 'phone', 'latitude', 'longitude',
|
|
DB::raw('(ROUND(6371 * acos(cos(radians(?)) * cos(radians(latitude)) * cos(radians(longitude)
|
|
- radians(?)) + sin(radians(?)) * sin(radians(latitude))), 2)) AS distance'))
|
|
->setBindings([$latitude, $longitude, $latitude])
|
|
->where('id', $id)
|
|
->where('status', 1)
|
|
->where('del', 2)
|
|
->first();
|
|
if (!$info) {
|
|
$info = Hospital::select('id', 'address', 'logo', 'name', 'phone', 'latitude', 'longitude',
|
|
DB::raw('(ROUND(6371 * acos(cos(radians(?)) * cos(radians(latitude)) * cos(radians(longitude)
|
|
- radians(?)) + sin(radians(?)) * sin(radians(latitude))), 2)) AS distance'))
|
|
->setBindings([$latitude, $longitude, $latitude])
|
|
->where('dev', 2)
|
|
->where('status', 1)
|
|
->where('del', 2)
|
|
->first();
|
|
}
|
|
return Yo::echo([
|
|
'info' => $info
|
|
]);
|
|
}
|
|
|
|
public function count()
|
|
{
|
|
Login::user();
|
|
$query = Hospital::where('status', 1)->where('del', 2);
|
|
if (Login::$info->dev != 1) $query->where('dev', 2);
|
|
$count = $query->count();
|
|
return Yo::echo([
|
|
'count' => $count
|
|
]);
|
|
}
|
|
|
|
public function mp_list(Request $request)
|
|
{
|
|
Login::user();
|
|
$latitude = $request->post('latitude');
|
|
$longitude = $request->post('longitude');
|
|
$query = Hospital::select('id', 'address', 'logo', 'name', 'phone', DB::raw('(ROUND(6371 * acos(cos(radians(?)) * cos(radians(latitude)) * cos(radians(longitude) - radians(?)) + sin(radians(?)) * sin(radians(latitude))), 2)) AS distance'))
|
|
->setBindings([$latitude, $longitude, $latitude])
|
|
->where('status', 1)->where('del', 2);
|
|
if (Login::$info->dev != 1) $query->where('dev', 2);
|
|
$list = $query->orderBy('distance', 'asc')->get();
|
|
return Yo::echo([
|
|
'list' => $list
|
|
]);
|
|
}
|
|
|
|
public function select_list()
|
|
{
|
|
Login::admin();
|
|
$list = Hospital::where('del', 2)->get();
|
|
return Yo::echo([
|
|
'list' => $list
|
|
]);
|
|
}
|
|
|
|
public function delete(Request $request)
|
|
{
|
|
Login::admin([11]);
|
|
$id = $request->post('id');
|
|
$hospital = Hospital::where('id', $id)->where('del', 2)->first();
|
|
if (!$hospital) Yo::error_echo(100000, ['机构/医院']);
|
|
$hospital->del = 1;
|
|
$hospital->save();
|
|
return Yo::delete_echo($hospital->id);
|
|
}
|
|
|
|
public function update(EditHospitalInput $request)
|
|
{
|
|
Login::admin([11]);
|
|
$id = $request->post('id');
|
|
$name = $request->post('name');
|
|
$code = $request->post('code');
|
|
$address = $request->post('address');
|
|
$longitude = $request->post('longitude');
|
|
$latitude = $request->post('latitude');
|
|
$logo = $request->post('logo');
|
|
$dev = $request->post('dev');
|
|
$phone = $request->post('phone');
|
|
$status = $request->post('status');
|
|
$hospital = Hospital::where('id', $id)->where('del', 2)->first();
|
|
if (!$hospital) Yo::error_echo(100000, ['机构/医院']);
|
|
$hospital->name = $name;
|
|
$hospital->code = $code;
|
|
$hospital->address = $address;
|
|
$hospital->longitude = $longitude;
|
|
$hospital->latitude = $latitude;
|
|
$hospital->logo = $logo;
|
|
$hospital->dev = $dev;
|
|
$hospital->phone = $phone;
|
|
$hospital->status = $status;
|
|
$hospital->save();
|
|
return Yo::update_echo($hospital->id);
|
|
}
|
|
|
|
public function create(EditHospitalInput $request)
|
|
{
|
|
Login::admin([11]);
|
|
$name = $request->post('name');
|
|
$code = $request->post('code');
|
|
$address = $request->post('address');
|
|
$longitude = $request->post('longitude');
|
|
$latitude = $request->post('latitude');
|
|
$logo = $request->post('logo');
|
|
$dev = $request->post('dev');
|
|
$phone = $request->post('phone');
|
|
$status = $request->post('status');
|
|
$hospital = new Hospital();
|
|
$hospital->name = $name;
|
|
$hospital->code = $code;
|
|
$hospital->address = $address;
|
|
$hospital->longitude = $longitude;
|
|
$hospital->latitude = $latitude;
|
|
$hospital->logo = $logo;
|
|
$hospital->dev = $dev;
|
|
$hospital->phone = $phone;
|
|
$hospital->status = $status;
|
|
$hospital->save();
|
|
return Yo::create_echo($hospital->id);
|
|
}
|
|
|
|
public function hospital_info(Request $request)
|
|
{
|
|
Login::admin([22]);
|
|
if (Login::$info->hospital == -1) Yo::error_echo(100000, ['机构/医院']);
|
|
if (Login::$info->hospital == 0) {
|
|
return Yo::echo([
|
|
'info' => [
|
|
'id' => 0
|
|
]
|
|
]);
|
|
}
|
|
$info = Hospital::where('id', Login::$info->hospital)
|
|
->where('status', 1)
|
|
->where('del', 2)
|
|
->first();
|
|
if (!$info) Yo::error_echo(100000, ['机构/医院']);
|
|
return Yo::echo([
|
|
'info' => $info
|
|
]);
|
|
}
|
|
|
|
public function hospital_update(EditHospitalInput $request)
|
|
{
|
|
Login::admin([22]);
|
|
$id = $request->post('id');
|
|
if (Login::$info->hospital != $id) Yo::error_echo(100000, ['机构/医院']);
|
|
$name = $request->post('name');
|
|
$address = $request->post('address');
|
|
$longitude = $request->post('longitude');
|
|
$latitude = $request->post('latitude');
|
|
$logo = $request->post('logo');
|
|
$phone = $request->post('phone');
|
|
$hospital = Hospital::where('id', $id)->where('del', 2)->first();
|
|
if (!$hospital) Yo::error_echo(100000, ['机构/医院']);
|
|
$hospital->name = $name;
|
|
$hospital->address = $address;
|
|
$hospital->longitude = $longitude;
|
|
$hospital->latitude = $latitude;
|
|
$hospital->logo = $logo;
|
|
$hospital->phone = $phone;
|
|
$hospital->save();
|
|
return Yo::update_echo($hospital->id);
|
|
}
|
|
}
|