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.

111 lines
2.9 KiB

1 week ago
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
class Teacher extends Model
{
use SoftDeletes;
protected $fillable = [
'name',
'university_id',
'university_text',
5 days ago
'department',
1 week ago
'city',
'title',
'phone',
'email',
'miniapp_user_id',
'source_dict_item_id',
'star_level_dict_item_id',
'status_dict_item_id',
'next_follow_date',
'next_follow_subject',
'is_partner',
'converted_at',
'remark',
'sort',
];
protected $casts = [
'university_id' => 'integer',
'miniapp_user_id' => 'integer',
'source_dict_item_id' => 'integer',
'star_level_dict_item_id' => 'integer',
'status_dict_item_id' => 'integer',
'next_follow_date' => 'date',
'is_partner' => 'boolean',
'converted_at' => 'datetime',
'sort' => 'integer',
];
public function university(): BelongsTo
{
return $this->belongsTo(University::class);
}
/** 列表/详情展示用:优先高校库名称,否则抓取原文 */
public function displayUniversityName(): ?string
{
$linked = $this->university?->name;
if ($linked !== null && $linked !== '') {
return $linked;
}
$text = trim((string) ($this->university_text ?? ''));
return $text !== '' ? $text : null;
}
public function miniappUser(): BelongsTo
{
return $this->belongsTo(MiniappUser::class);
}
public function sourceItem(): BelongsTo
{
return $this->belongsTo(DictItem::class, 'source_dict_item_id');
}
public function starLevelItem(): BelongsTo
{
return $this->belongsTo(DictItem::class, 'star_level_dict_item_id');
}
public function statusItem(): BelongsTo
{
return $this->belongsTo(DictItem::class, 'status_dict_item_id');
}
public function followRecords(): HasMany
{
return $this->hasMany(TeacherFollowRecord::class)->orderByDesc('followed_at')->orderByDesc('id');
}
public function researchDirections(): BelongsToMany
{
return $this->belongsToMany(
ResearchDirection::class,
'teacher_research_direction',
'teacher_id',
'research_direction_id'
)->orderBy('research_directions.sort')->orderBy('research_directions.name');
}
public function papers(): BelongsToMany
{
return $this->belongsToMany(Paper::class, 'teacher_papers')->withTimestamps();
}
public function demands(): HasMany
{
return $this->hasMany(Demand::class);
}
}