diff --git a/app/Http/Controllers/Manager/OrdersController.php b/app/Http/Controllers/Manager/OrdersController.php index 25052f1..11d7665 100644 --- a/app/Http/Controllers/Manager/OrdersController.php +++ b/app/Http/Controllers/Manager/OrdersController.php @@ -2124,78 +2124,6 @@ class OrdersController extends CommonController return response()->json($paramedic_levels->toArray()); } - /** - * @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)->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/upload-image", diff --git a/app/Http/Controllers/Manager/ParamedicController.php b/app/Http/Controllers/Manager/ParamedicController.php new file mode 100644 index 0000000..4f72036 --- /dev/null +++ b/app/Http/Controllers/Manager/ParamedicController.php @@ -0,0 +1,167 @@ +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); + } +} diff --git a/app/Models/Paramedic.php b/app/Models/Paramedic.php index 49381bc..9066497 100755 --- a/app/Models/Paramedic.php +++ b/app/Models/Paramedic.php @@ -7,15 +7,30 @@ use App\Scopes\AdminProjectScope; class Paramedic extends SoftDeletesModel { protected $table = "paramedic"; - public $appends = ["avatar_url", "age"]; - const STATUS_ACTIVE = 1; + public $appends = ["avatar_url", "age", "status_name"]; + const STATUS_ACTIVE = "active"; + const STATUS_INACTIVE = "inactive"; const TEXT_ACTIVE = "正常"; + const TEXT_INACTIVE = "请假"; protected static function booted() { static::addGlobalScope(new AdminProjectScope()); } + public function getStatusNameAttribute() { + $status_name = $this->status; + switch ($this->status) { + case self::STATUS_ACTIVE: + $status_name = self::TEXT_ACTIVE; + break; + case self::STATUS_INACTIVE: + $status_name = self::TEXT_INACTIVE; + break; + } + return $status_name; + } + public function getAvatarUrlAttribute() { $protocol = request()->secure() ? "https" : "http"; @@ -32,9 +47,10 @@ class Paramedic extends SoftDeletesModel return $this->avatar ? $protocol . "://" . request()->getHost() . $this->avatar : $this->avatar; } - public function getAgeAttribute() { - if (date("Y-m-d",strtotime($this->birthday)) == $this->birthday) { - return date("Y") - date("Y",strtotime($this->birthday)); + public function getAgeAttribute() + { + if (date("Y-m-d", strtotime($this->birthday)) == $this->birthday) { + return date("Y") - date("Y", strtotime($this->birthday)); } return ""; } @@ -54,8 +70,9 @@ class Paramedic extends SoftDeletesModel return $this->belongsTo(ParamedicLevel::class, "paramedic_level_id", "id"); } - public function levelInProject() { - return $this->hasOneThrough(ProductParamedicLevel::class, ParamedicLevel::class,"id","paramedic_level_id","paramedic_level_id","id"); + public function levelInProject() + { + return $this->hasOneThrough(ProductParamedicLevel::class, ParamedicLevel::class, "id", "paramedic_level_id", "paramedic_level_id", "id"); } public function orders() diff --git a/database/migrations/2020_07_17_212159_update_paramedic_add_status.php b/database/migrations/2020_07_17_212159_update_paramedic_add_status.php index 6b3db1b..397d295 100644 --- a/database/migrations/2020_07_17_212159_update_paramedic_add_status.php +++ b/database/migrations/2020_07_17_212159_update_paramedic_add_status.php @@ -14,7 +14,7 @@ class UpdateParamedicAddStatus extends Migration public function up() { Schema::table("paramedic", function (Blueprint $table) { - $table->string("status")->default(1); + $table->string("status")->default("active"); }); } diff --git a/database/seeds/UpdateParamedicStatus.php b/database/seeds/UpdateParamedicStatus.php new file mode 100644 index 0000000..02a885b --- /dev/null +++ b/database/seeds/UpdateParamedicStatus.php @@ -0,0 +1,18 @@ +withTrashed()->update([ + "status" => (string)\App\Models\Paramedic::STATUS_ACTIVE + ]); + } +} diff --git a/routes/web.php b/routes/web.php index ed11145..567f77c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -128,6 +128,11 @@ Route::group(["namespace" => "Manager", "prefix" => "manager"], function () { Route::get('get-video/{id}', 'TrainingController@getVideo'); Route::group(['middleware' => ['authorize.jwt:manager']], function () { + Route::post('create-paramedic', 'ParamedicController@createParamedic'); + Route::post('update-paramedic/{id}', 'ParamedicController@updateParamedic'); + Route::post('delete-paramedic/{id}', 'ParamedicController@deleteParamedic'); + Route::post('toggle-paramedic/{id}', 'ParamedicController@toggleParamedic'); + Route::post('me', 'AuthController@me'); Route::get('get-projects', 'OrdersController@getProjects'); Route::get('get-notifications', 'AuthController@getNotifications'); @@ -141,6 +146,7 @@ Route::group(["namespace" => "Manager", "prefix" => "manager"], function () { Route::get('get-project-paramedic-levels/{project_id}', 'OrdersController@getProjectParamedicLevels'); Route::get('get-project-areas/{project_id}', 'OrdersController@getProjectAreas'); Route::get('get-area-beds/{area_id}', 'OrdersController@getAreaBeds'); + Route::post('upload-image', 'OrdersController@uploadImage'); Route::post('create-patient', 'OrdersController@createPatient'); Route::post('create-order', 'OrdersController@createOrder'); Route::post('scan-pay/{order_id}', 'OrdersController@scanPay'); @@ -164,8 +170,6 @@ Route::group(["namespace" => "Manager", "prefix" => "manager"], function () { Route::post('get-balance/{customer_id}', 'OrdersController@getBalance'); Route::post('recharge-for-order/{id}', 'OrdersController@rechargeForOrder'); Route::post('refund-for-order/{id}', 'OrdersController@refundForOrder'); - Route::post('create-paramedic', 'OrdersController@createParamedic'); - Route::post('upload-image', 'OrdersController@uploadImage'); Route::get('statistics/beds', 'StatisticsController@beds'); }); });