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.

66 lines
1.6 KiB

5 years ago
<?php
namespace App\Models;
use App\Scopes\AdminProjectScope;
class Paramedic extends SoftDeletesModel
{
protected $table = "paramedic";
5 years ago
public $appends = ["avatar_url", "age"];
5 years ago
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;
}
5 years ago
public function getAgeAttribute() {
if (date("Y-m-d",strtotime($this->birthday)) == $this->birthday) {
return date("Y") - date("Y",strtotime($this->birthday));
}
return "";
}
5 years ago
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");
}
5 years ago
public function levelInProject() {
return $this->hasOneThrough(ProductParamedicLevel::class, ParamedicLevel::class,"id","paramedic_level_id","paramedic_level_id","id");
}
5 years ago
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);
}
}