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

363 lines
12 KiB

5 years ago
<?php
/**
* Created by PhpStorm.
* User: weizongsong
* Date: 2019-04-12
* Time: 22:34
*/
namespace App\Http\Controllers\Admin;
3 years ago
use App\Admin;
5 years ago
use App\Events\ProjectSaved;
5 years ago
use App\Exports\CommonExport;
2 years ago
use App\Forms\AskSubmitForm;
5 years ago
use App\Forms\ProjectForm;
3 years ago
use App\Models\AdminAreaLink;
5 years ago
use App\Models\Area;
2 years ago
use App\Models\AskSubmit;
5 years ago
use App\Models\Bed;
use App\Models\Building;
use App\Models\ParamedicLevel;
use App\Models\Project;
use App\Models\Room;
use Illuminate\Http\Request;
3 years ago
use Illuminate\Support\Facades\DB;
5 years ago
use Kris\LaravelFormBuilder\FormBuilder;
5 years ago
use Maatwebsite\Excel\Facades\Excel;
3 years ago
use Spatie\Permission\Models\Role;
5 years ago
class ProjectController extends CommonController
{
public $bladePath = "admin.project";
public $urlPrefix = "admin/project";
public $modelName = "医院/项目";
public $modelClass = Project::class;
public $formClass = ProjectForm::class;
public function index(Request $request)
{
$data = $this->model->with("paramedicLevels")->paginate(10);
return view($this->bladePath . ".index", compact("data"));
}
public function stored($model)
{
event(new ProjectSaved($model));
}
public function edit($id = null, Request $request, FormBuilder $formBuilder)
{
$vo = (new Project())->with("paramedicLevels")->find($id ?: $request->id);
$form = $formBuilder->create($this->formClass, [
"method" => "POST",
"id" => "fm",
"url" => url($this->urlPrefix . "/update/" . $vo->id),
"class" => "form form-horizontal validate-form",
"model" => $vo
]);
$form->add("_previous", "hidden", ["value" => (url()->previous())]);
return view($this->bladePath . ".create", compact("form"));
}
public function updated($model)
{
event(new ProjectSaved($model));
}
public function beds($id)
{
3 years ago
$project = (new Project())->with(["buildings"])->find($id);
$data = (new Bed())->where("project_id", $id)->orderBy("id", "desc")->with(["project", "building", "area", "room"]);
if (request()->room_id) {
$data = $data->where("room_id", request()->room_id);
$room = (new Room())->find(request()->room_id);
$rooms = (new Room())->where("area_id", $room->area_id)->get();
$area = (new Area())->where("id", $room->area_id)->first();
$areas = (new Area())->where("building_id", $area->building_id)->get();
view()->share(compact("rooms", "areas"));
} elseif (request()->area_id) {
$data = $data->where("area_id", request()->area_id);
$area = (new Area())->find(request()->area_id);
$areas = (new Area())->where("building_id", $area->building_id)->get();
$rooms = (new Room())->where("area_id", $area->id)->get();
view()->share(compact("areas", "rooms"));
} elseif (request()->building_id) {
$areas = (new Area())->where("building_id", request()->building_id)->get();
$data = $data->where("building_id", request()->building_id);
view()->share(compact("areas"));
}
5 years ago
3 years ago
$data = $data->paginate(10);
3 years ago
return view($this->bladePath . ".beds", compact("project", "data"));
}
3 years ago
3 years ago
public function getHeadList()
{
$areaId = \request('area_id', 0);
3 years ago
$project_id = \request('project_id');
3 years ago
// 获取护士长
3 years ago
$roleId = Role::where('name', 'like', '%护士长%')->where('guard_name', 'admin')->value('id');
$adminIds = DB::table('model_has_roles')->where('role_id', $roleId)->where('model_type', 'App\Admin')->pluck('model_id');
// 全量护工数据
3 years ago
$headList = Admin::whereIn('id', $adminIds)->whereRaw("find_in_set('$project_id',project_ids)")->get();
3 years ago
// 获取病区选中的护工
foreach ($headList as $item) {
3 years ago
$item->selected = '';
3 years ago
if ($areaId) {
$has = AdminAreaLink::where('area_id', $areaId)->where('admin_id', $item->id)->count();
3 years ago
if ($has) $item->selected = 'selected';
3 years ago
}
}
return $this->ajaxResponse($headList);
5 years ago
}
public function createSub(Request $request)
{
switch ($request->type) {
case "project":
$data = [
"project_id" => $request->id,
"name" => $request->name,
"myindex" => $request->myindex
];
$res = (new Building())->create($data);
break;
case "building":
$parent = Building::find($request->id);
$data = [
"project_id" => $parent->project_id,
"building_id" => $request->id,
"name" => $request->name,
"myindex" => $request->myindex
];
$res = (new Area())->create($data);
3 years ago
// 添加选中的护工
$links = [];
foreach ($request->head as $item) {
$links[] = [
'admin_id' => $item,
'area_id' => $res->id,
3 years ago
'project_id' => $res->project_id,
3 years ago
'created_at' => date('Y-m-d H:i:s')
];
}
AdminAreaLink::insert($links);
5 years ago
break;
case "area":
$parent = Area::find($request->id);
$data = [
"project_id" => $parent->project_id,
"building_id" => $parent->building_id,
"area_id" => $request->id,
"name" => $request->name,
"myindex" => $request->myindex
];
$res = (new Room())->create($data);
break;
case "room":
$parent = Room::find($request->id);
$data = [
"project_id" => $parent->project_id,
"building_id" => $parent->building_id,
"area_id" => $parent->area_id,
"room_id" => $request->id,
"name" => $request->name,
"myindex" => $request->myindex
];
$res = (new Bed())->create($data);
break;
2 years ago
// case "asksubmit":
// $parent = AskSubmit::find($request->id);
// $data = [
// "project_id" => $parent->project_id,
// "building_id" => $parent->building_id,
// "area_id" => $parent->area_id,
// "room_id" => $request->id,
// "name" => $request->name,
// "myindex" => $request->myindex
// ];
// $res = (new Bed())->create($data);
// break;
5 years ago
default:
return $this->error("不正确的类型");
}
5 years ago
return $this->success("添加成功!", '', $res);
5 years ago
}
3 years ago
public function getSubs(Request $request)
{
switch ($request->type) {
case "building":
$res = (new Area())->where("building_id", $request->id)->get();
break;
case "area":
$res = (new Room())->where("area_id", $request->id)->get();
break;
default:
$res = [];
}
return $this->ajaxResponse($res);
}
5 years ago
public function editDepartment(Request $request)
{
$data = [
"name" => $request->name,
"myindex" => $request->myindex
];
switch ($request->type) {
case "building":
$res = (new Building())->find($request->id)->update($data);
break;
case "area":
3 years ago
$res = (new Area())->find($request->id);
$res->update($data);
3 years ago
// 删除原来关联,添加新关联
3 years ago
AdminAreaLink::where('area_id', $request->id)->delete();
3 years ago
$links = [];
foreach ($request->head as $item) {
$links[] = [
'admin_id' => $item,
3 years ago
'area_id' => $request->id,
3 years ago
'project_id' => $res->project_id,
3 years ago
'created_at' => date('Y-m-d H:i:s')
];
}
AdminAreaLink::insert($links);
5 years ago
break;
case "room":
$res = (new Room())->find($request->id)->update($data);
break;
case "bed":
$res = (new Bed())->find($request->id)->update($data);
break;
default:
return $this->error("不正确的类型");
}
return $this->success($res);
}
public function deleteDepartment(Request $request)
{
switch ($request->type) {
case "building":
$vo = (new Building())->find($request->id);
break;
case "area":
$vo = (new Area())->find($request->id);
break;
case "room":
$vo = (new Room())->find($request->id);
break;
case "bed":
$vo = (new Bed())->find($request->id);
break;
default:
return $this->error("不正确的类型");
}
$res = $vo->delete();
if ($res) {
return $this->success("删除成功");
} else {
return $this->success("删除失败");
}
}
5 years ago
5 years ago
function exportBeds(Request $request)
{
$beds = Bed::with(["area", "building", "room"])
->whereHas("area")
->whereHas("building")
->whereHas("room")
5 years ago
->where("project_id", $request->project_id)
->orderBy("building_id")
->orderBy("area_id")
->orderBy("room_id")
->get();
$data = [];
foreach ($beds as $bed) {
$data[] = [
5 years ago
"楼栋" => $bed->building ? $bed->building->name : "",
"病区" => $bed->area ? $bed->area->name : "",
"病房" => $bed->room ? $bed->room->name : "",
5 years ago
"床号" => $bed->name,
];
}
$data = collect($data);
5 years ago
return Excel::download(new CommonExport($data), "beds.xlsx");
5 years ago
}
2 years ago
/**
* 满意度调查
*/
2 years ago
public function askSubmit($project_id)
2 years ago
{
$userId = auth()->id();
// 判断是否护士长
$roleId = Role::where('name', 'like', '%护士长%')->where('guard_name', 'admin')->value('id');
$hushizhang = DB::table('model_has_roles')->where('role_id', $roleId)
->where('model_type', 'App\Admin')
->where('model_id', $userId)->count();
$data = AskSubmit::with("admin", "project")
->where(function ($qeury) use ($hushizhang, $userId) {
2 years ago
if ($hushizhang) $qeury->where('admin_id', $userId);
2 years ago
})->where('project_id', $project_id)->paginate(10);
2 years ago
2 years ago
return view($this->bladePath . ".asksubmit_index", compact("data", "project_id"));
2 years ago
}
2 years ago
2 years ago
public function askSubmitCreate(FormBuilder $formBuilder)
2 years ago
{
2 years ago
$project_id = \request('project_id');
2 years ago
$form = $formBuilder->create(AskSubmitForm::class, [
"method" => "POST",
"id" => "fm",
"url" => url($this->urlPrefix . "/asksubmit_store")
]);
2 years ago
$form->project_id->setValue($project_id);
2 years ago
return view($this->bladePath . ".asksubmit_create", compact("form"));
2 years ago
}
2 years ago
public function askSubmitStore(Request $request)
{
2 years ago
$all = \request()->all();
2 years ago
$content = [];
2 years ago
$socre = 0;
2 years ago
foreach ($all['ask'] as $key => $item) {
$content[] = [
'ask' => AskSubmit::$askList[$key],
'socre' => $item
];
2 years ago
$socre += $item;
2 years ago
}
2 years ago
$all['admin_id'] = auth()->user()->id;
2 years ago
$all['score'] = $socre;
2 years ago
$all['content'] = $content;
2 years ago
$model = AskSubmit::create($all);
2 years ago
$url = "/admin/project/asksubmit/".$all['project_id'];
2 years ago
return $this->success("新增成功", $url, $model);
2 years ago
}
2 years ago
public function askSubmitEdit()
{
$data = [];
return view($this->bladePath . ".asksubmit_create", compact("data"));
}
public function askSubmitDelete()
{
}
5 years ago
}