|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use App\Scopes\AdminProjectScope;
|
|
|
|
|
|
|
|
|
|
class Paramedic extends SoftDeletesModel
|
|
|
|
|
{
|
|
|
|
|
protected $table = "paramedic";
|
|
|
|
|
public $appends = ["avatar_url", "age"];
|
|
|
|
|
const STATUS_ACTIVE = 1;
|
|
|
|
|
const TEXT_ACTIVE = "正常";
|
|
|
|
|
|
|
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
static::addGlobalScope(new AdminProjectScope());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAvatarUrlAttribute()
|
|
|
|
|
{
|
|
|
|
|
$protocol = request()->secure() ? "https" : "http";
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|