'string', 'version' => 'integer', 'modify_time' => 'integer', 'create_time' => 'integer', ]; public $incrementing = false; protected $fillable = ['id', 'guid', 'word', 'word_en', 'meaning', 'channal', 'language', 'owner', 'editor_id', 'editor_uid', 'create_time', 'modify_time']; /** 所属 channel(channal 列);studio 级术语为空 */ public function channel(): BelongsTo { return $this->belongsTo(Channel::class, 'channal', 'uid'); } /** * 所属 channel 的 uid;studio 级术语给 null。 * * studio 级术语的 channal 有两种写法:NULL,以及 2022 年以前 v2 写入的空串(库里一千多条), * 判断「是不是 studio 级」一律走这里,不要直接比 `channal !== null`。 */ public function channelUid(): ?string { return $this->channal === null || $this->channal === '' ? null : (string) $this->channal; } /** * 只要 studio 级术语(channal 为 NULL 或空串,见 {@see self::channelUid()})。 * * @param Builder $query */ public function scopeStudioLevel(Builder $query): void { $query->where(fn (Builder $q) => $q->whereNull('channal')->orWhere('channal', '')); } /** 编辑者(人类用户)。editor_uid 对 user_infos.userid */ public function user(): BelongsTo { return $this->belongsTo(UserInfo::class, 'editor_uid', 'userid'); } /** 编辑者(AI 助手)。存量数据里 AI 写的行 editor_uid 直接是模型 */ public function aiModel(): BelongsTo { return $this->belongsTo(AiModel::class, 'editor_uid', 'uid'); } /** 协作者:人类授权代写的 AI 模型。此时 editor 是授权人 */ public function coEditor(): BelongsTo { return $this->belongsTo(AiModel::class, 'co_editor_uid', 'uid'); } /** 百科分类,按正文里出现的顺序 */ public function categories(): HasMany { return $this->hasMany(TermCategory::class, 'term_guid', 'guid')->orderBy('position'); } /** 实际方言:v2 写入的行库里是默认值 markdown */ public function effectiveContentType(): string { return $this->content_type ?: 'markdown'; } /** 乐观锁用的 ETag:v3 修改 +version,v2 修改只动 modify_time,两者都要算进去 */ public function etag(): string { return '"'.((int) $this->version).'.'.((int) $this->modify_time).'"'; } }