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.

168 lines
8.0 KiB

5 years ago
<?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)
{
if ($request->id_card_number) {
return response()->json([
"errorcode" => "99999",
"errormsg" => "身份证号码不可修改"
]);
}
$paramedic = (new Paramedic())->find($id);
$data = (new Paramedic())->filterRequestColumns($request, ["id"]);
$paramedic->update($data);
return response()->json($paramedic);
}
}