|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use App\Scopes\AdminProjectScope;
|
|
|
|
|
|
|
|
|
|
class Paramedic extends SoftDeletesModel
|
|
|
|
|
{
|
|
|
|
|
protected $table = "paramedic";
|
|
|
|
|
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 toggle()
|
|
|
|
|
{
|
|
|
|
|
switch ($this->status) {
|
|
|
|
|
case self::STATUS_ACTIVE:
|
|
|
|
|
$this->update([
|
|
|
|
|
"status" => self::STATUS_INACTIVE
|
|
|
|
|
]);
|
|
|
|
|
break;
|
|
|
|
|
case self::STATUS_INACTIVE:
|
|
|
|
|
$this->update([
|
|
|
|
|
"status" => self::STATUS_ACTIVE
|
|
|
|
|
]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAvatarUrlAttribute()
|
|
|
|
|
{
|
|
|
|
|
$protocol = request()->secure() ? "https" : "http";
|
|
|
|
|
if (!$this->avatar) {
|
|
|
|
|
switch ($this->sex) {
|
|
|
|
|
case "男":
|
|
|
|
|
$this->avatar = "/images/male.png";
|
|
|
|
|
break;
|
|
|
|
|
case "女":
|
|
|
|
|
$this->avatar = "/images/female.png";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeOfProject($query, $project_id)
|
|
|
|
|
{
|
|
|
|
|
return $query->whereIn("project_id", (array)$project_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function project()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Project::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function level()
|
|
|
|
|
{
|
|
|
|
|
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 orders()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Orders::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function ongoingOrders()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Orders::class)->where("status", Orders::STATUS_ONGOING);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function orderItems()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(OrderItems::class);
|
|
|
|
|
}
|
|
|
|
|
}
|