|
|
<?php
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Manager;
|
|
|
|
|
|
use AlicFeng\IdentityCard\InfoHelper;
|
|
|
use App\Models\Paramedic;
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
class ParamedicController extends CommonController
|
|
|
{
|
|
|
/**
|
|
|
* @OA\POST(
|
|
|
* path="/manager/create-paramedic",
|
|
|
* summary="V2-新增护工",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Parameter(name="project_id", in="query", @OA\Schema(type="integer"), required=true, description="医院/项目ID"),
|
|
|
* @OA\Parameter(name="name", in="query", @OA\Schema(type="string"), required=true, description="姓名"),
|
|
|
* @OA\Parameter(name="avatar", in="query", @OA\Schema(type="string"), required=true, description="头像图片路径,图片路径获取参见upload-image接口"),
|
|
|
* @OA\Parameter(name="id_card_number", in="query", @OA\Schema(type="string"), required=true, description="身份证号"),
|
|
|
* @OA\Parameter(name="mobile", in="query", @OA\Schema(type="string"), required=true, description="手机号码"),
|
|
|
* @OA\Parameter(name="join_at", in="query", @OA\Schema(type="string"), required=true, description="入职日期"),
|
|
|
* @OA\Parameter(name="work_years", in="query", @OA\Schema(type="string"), required=true, description="护理经验年限"),
|
|
|
* @OA\Parameter(name="paramedic_level_id", in="query", @OA\Schema(type="integer"), required=true, description="项目护工级别ID"),
|
|
|
* @OA\Parameter(name="bank", in="query", @OA\Schema(type="string"), required=false, description="开户行"),
|
|
|
* @OA\Parameter(name="account", in="query", @OA\Schema(type="string"), required=false, description="银行卡号"),
|
|
|
* @OA\Parameter(name="idcard_front", in="query", @OA\Schema(type="integer"), required=false, description="身份证正面图片ID"),
|
|
|
* @OA\Parameter(name="idcard_back", in="query", @OA\Schema(type="integer"), required=false, description="身份证反面图片ID"),
|
|
|
* @OA\Parameter(name="has_health_certificate", in="query", @OA\Schema(type="integer"), required=true, description="是否持有健康证"),
|
|
|
* @OA\Parameter(name="has_work_certificate", in="query", @OA\Schema(type="integer"), required=true, description="是否是有技能资格证"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="新增护工"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
|
|
|
public function createParamedic(Request $request)
|
|
|
{
|
|
|
if (!$request->id_card_number) {
|
|
|
return response()->json([
|
|
|
"errorcode" => "99999",
|
|
|
"errormsg" => "身份证号不可以为空"
|
|
|
]);
|
|
|
}
|
|
|
if (!InfoHelper::identityCard()->validate($request->id_card_number)) {
|
|
|
return response()->json([
|
|
|
"errorcode" => "99999",
|
|
|
"errormsg" => "身份证号不正确"
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
$birthday = InfoHelper::identityCard()->birthday($request->id_card_number);
|
|
|
$sex = InfoHelper::identityCard()->sex($request->id_card_number);
|
|
|
switch ($sex) {
|
|
|
case "M":
|
|
|
$sex = "男";
|
|
|
break;
|
|
|
case "F":
|
|
|
$sex = "女";
|
|
|
break;
|
|
|
default:
|
|
|
//do nothing
|
|
|
}
|
|
|
|
|
|
$paramedic = (new Paramedic())->where("id_card_number", $request->id_card_number)->withTrashed()->first();
|
|
|
if ($paramedic) {
|
|
|
return response()->json([
|
|
|
"errorcode" => "99999",
|
|
|
"errormsg" => "已存在相同身份证号的护工"
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
$data = (new Paramedic())->filterRequestColumns($request);
|
|
|
$data["birthday"] = $birthday;
|
|
|
$data["sex"] = $sex;
|
|
|
$data["creator_type"] = get_class($this->manager);
|
|
|
$data["creator_id"] = $this->manager->id;
|
|
|
$res = (new Paramedic())->create($data);
|
|
|
return response()->json($res);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\POST(
|
|
|
* path="/manager/delete-paramedic/{id}",
|
|
|
* summary="V2-护工离职(删除护工)",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Parameter(name="id", in="path", @OA\Schema(type="integer"), required=true, description="护工ID"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="护工离职"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
|
|
|
public function deleteParamedic($id)
|
|
|
{
|
|
|
$paramedic = (new Paramedic())->find($id);
|
|
|
$paramedic->delete();
|
|
|
return response()->json($paramedic);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\POST(
|
|
|
* path="/manager/toggle-paramedic/{id}",
|
|
|
* summary="V2-护工状态切换(正常与请假两个状态)",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Parameter(name="id", in="path", @OA\Schema(type="integer"), required=true, description="护工ID"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="护工离职"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
|
|
|
public function toggleParamedic($id)
|
|
|
{
|
|
|
$paramedic = (new Paramedic())->find($id);
|
|
|
$paramedic->toggle();
|
|
|
return response()->json($paramedic);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\POST(
|
|
|
* path="/manager/update-paramedic/{id}",
|
|
|
* summary="V2-新增护工",
|
|
|
* description="",
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Parameter(name="id", in="path", @OA\Schema(type="integer"), required=true, description="护工ID"),
|
|
|
* @OA\Parameter(name="project_id", in="query", @OA\Schema(type="integer"), required=true, description="医院/项目ID"),
|
|
|
* @OA\Parameter(name="name", in="query", @OA\Schema(type="string"), required=true, description="姓名"),
|
|
|
* @OA\Parameter(name="avatar", in="query", @OA\Schema(type="string"), required=true, description="头像图片路径,图片路径获取参见upload-image接口"),
|
|
|
* @OA\Parameter(name="mobile", in="query", @OA\Schema(type="string"), required=true, description="手机号码"),
|
|
|
* @OA\Parameter(name="join_at", in="query", @OA\Schema(type="string"), required=true, description="入职日期"),
|
|
|
* @OA\Parameter(name="work_years", in="query", @OA\Schema(type="string"), required=true, description="护理经验年限"),
|
|
|
* @OA\Parameter(name="paramedic_level_id", in="query", @OA\Schema(type="integer"), required=true, description="项目护工级别ID"),
|
|
|
* @OA\Parameter(name="bank", in="query", @OA\Schema(type="string"), required=false, description="开户行"),
|
|
|
* @OA\Parameter(name="account", in="query", @OA\Schema(type="string"), required=false, description="银行卡号"),
|
|
|
* @OA\Parameter(name="idcard_front", in="query", @OA\Schema(type="integer"), required=false, description="身份证正面图片ID"),
|
|
|
* @OA\Parameter(name="idcard_back", in="query", @OA\Schema(type="integer"), required=false, description="身份证反面图片ID"),
|
|
|
* @OA\Parameter(name="has_health_certificate", in="query", @OA\Schema(type="integer"), required=true, description="是否持有健康证"),
|
|
|
* @OA\Parameter(name="has_work_certificate", in="query", @OA\Schema(type="integer"), required=true, description="是否是有技能资格证"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="修改护工"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
|
|
|
public function updateParamedic($id, Request $request)
|
|
|
{
|
|
|
$paramedic = (new Paramedic())->find($id);
|
|
|
|
|
|
if ($request->id_card_number && $request->id_card_number != $paramedic->id_card_number) {
|
|
|
return response()->json([
|
|
|
"errorcode" => "99999",
|
|
|
"errormsg" => "身份证号码不可修改"
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
$data = (new Paramedic())->filterRequestColumns($request, ["id"]);
|
|
|
$paramedic->update($data);
|
|
|
return response()->json($paramedic);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/manager/get-project-paramedics/{project_id}",
|
|
|
* summary="V2-获取医院护工",
|
|
|
* description="获取医院护工",
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Parameter(name="project_id", in="path", @OA\Schema(type="string"), required=true, description="医院id"),
|
|
|
* @OA\Parameter(name="keyword", in="query", @OA\Schema(type="string"), required=true, description=""),
|
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="integer"), required=false, description="当前页码,默认为1"),
|
|
|
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="integer"), required=false, description="每页数量,默认为5"),
|
|
|
* @OA\Parameter(name="has_ongoing_orders", in="query", @OA\Schema(type="integer"), required=false, description="是否空闲的筛选,枚举[0,1]"),
|
|
|
* @OA\Parameter(name="paramedic_level_id", in="query", @OA\Schema(type="integer"), required=false, description="护工等级ID,根据项目护工等级枚举"),
|
|
|
* @OA\Parameter(name="work_years", in="query", @OA\Schema(type="integer"), required=false, description="工作经验,筛选时以大于等于传递的值为筛选条件"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="获取护工"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
|
|
|
public function getProjectParamedics()
|
|
|
{
|
|
|
$paramedics = new Paramedic();
|
|
|
$paramedics = $paramedics->OfProject(request()->project_id);
|
|
|
if (request()->keyword) {
|
|
|
$keyword = request()->keyword;
|
|
|
$paramedics = $paramedics->where(function ($query) use ($keyword) {
|
|
|
$query
|
|
|
->where("name", "like", "%{$keyword}%")
|
|
|
->orWhere("serial", "like", "%{$keyword}%");
|
|
|
});
|
|
|
}
|
|
|
if (request()->paramedic_level_id) {
|
|
|
$paramedics = $paramedics->where("paramedic_level_id", request()->paramedic_level_id);
|
|
|
}
|
|
|
if (request()->work_years) {
|
|
|
$paramedics = $paramedics->where("work_years", ">=", (int)request()->work_years);
|
|
|
}
|
|
|
|
|
|
switch (request()->has_ongoing_orders) {
|
|
|
case "1":
|
|
|
$paramedics = $paramedics->has("ongoingOrders");
|
|
|
break;
|
|
|
case "0":
|
|
|
$paramedics = $paramedics->doesntHave("ongoingOrders");
|
|
|
break;
|
|
|
default:
|
|
|
//do nothing
|
|
|
}
|
|
|
|
|
|
$page_size = request()->page_size ? (int)request()->page_size : 5;
|
|
|
$paramedics = $paramedics
|
|
|
->select("id", "name", "sex", "mobile", "birthday", "avatar", "work_years", "has_health_certificate", "has_work_certificate")
|
|
|
->withCount("ongoingOrders")
|
|
|
->orderBy("ongoing_orders_count")
|
|
|
->paginate($page_size);
|
|
|
return response()->json($paramedics->toArray());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/manager/get-paramedic/{id}",
|
|
|
* summary="V2-获取护工详情",
|
|
|
* description="获取护工详情",
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Parameter(name="id", in="path", @OA\Schema(type="integer"), required=true, description="id"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="获取护工详情"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
|
|
|
public function getParamedic($id)
|
|
|
{
|
|
|
$paramedic = (new Paramedic())->with([
|
|
|
"project" => function ($query) {
|
|
|
$query->select("id", "name", "address");
|
|
|
},
|
|
|
"level" => function ($query) {
|
|
|
$query->select("id", "name");
|
|
|
}
|
|
|
])->find($id);
|
|
|
return response()->json($paramedic ? $paramedic->toArray() : null);
|
|
|
}
|
|
|
}
|