generated from liutk/owl-admin-base
54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use EloquentFilter\Filterable;
|
|
use App\Enums\EmployeeStatus;
|
|
use Slowlyo\OwlAdmin\Models\AdminUser;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use App\Traits\HasDateTimeFormatter;
|
|
|
|
/**
|
|
* 员工
|
|
*/
|
|
class Employee extends Model
|
|
{
|
|
use Filterable, HasDateTimeFormatter;
|
|
|
|
const JOB_KEY = 'job';
|
|
|
|
protected $fillable = ['name', 'phone', 'prize_images', 'skill_images', 'employee_status', 'admin_user_id'];
|
|
|
|
protected $casts = [
|
|
'employee_status' => EmployeeStatus::class,
|
|
'prize_images' => 'json',
|
|
'skill_images' => 'json',
|
|
];
|
|
|
|
protected $attributes = [
|
|
'employee_status' => EmployeeStatus::Online,
|
|
];
|
|
|
|
protected $appends = ['employee_status_text'];
|
|
|
|
// 拥有的职位
|
|
public function jobs()
|
|
{
|
|
return $this->belongsToMany(Keyword::class, 'emplyee_jobs', 'employee_id', 'job');
|
|
}
|
|
|
|
// 关联登录账户
|
|
public function adminUser()
|
|
{
|
|
return $this->belongsTo(AdminUser::class, 'admin_user_id');
|
|
}
|
|
|
|
protected function employeeStatusText(): Attribute
|
|
{
|
|
return new Attribute(
|
|
get: fn () => $this->employee_status ? $this->employee_status->text() : '',
|
|
);
|
|
}
|
|
}
|