2
0

Channel.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use Illuminate\Database\Eloquent\SoftDeletes;
  7. /**
  8. * 译文集(channel)。表 `channels`,界面上叫「版本风格」。
  9. *
  10. * `owner_uid` 是用户 uuid 或团队(`group_infos.uid`)uuid——团队空间里的 channel 属于团队。
  11. * `status`:30 全网公开;20 公开不列出(拿到链接谁都能看,但不出现在社区目录、
  12. * 章节版本列表等任何面向他人的列表里);10 私有(0 / 1 / 5 是历史值,按私有对待)。
  13. *
  14. * 软删除(2026-11-16 起):v2 与 v3 的删除都只标 `deleted_at`,查询自动排除。
  15. * 删除前要求 channel 下没有译文、术语、逐词(v2 / v3 同口径),所以被删的 channel
  16. * 不会再出现在 progress_chapters 等派生表里。
  17. */
  18. class Channel extends Model
  19. {
  20. use HasFactory;
  21. use SoftDeletes;
  22. public const STATUS_PRIVATE = 10;
  23. public const STATUS_UNLISTED = 20;
  24. public const STATUS_PUBLIC = 30;
  25. protected $fillable = ['name', 'summary', 'type', 'lang', 'status', 'updated_at', 'created_at'];
  26. protected $primaryKey = 'uid';
  27. /** 主键是 uuid:不声明的话关系预加载会按整数走 whereIntegerInRaw,把 uuid 全转成 0 */
  28. protected $keyType = 'string';
  29. protected $casts = [
  30. 'uid' => 'string',
  31. ];
  32. public $incrementing = false;
  33. /**
  34. * 反向关联到 ProgressChapter
  35. */
  36. public function progressChapters()
  37. {
  38. return $this->hasMany(ProgressChapter::class, 'channel_id', 'uid');
  39. }
  40. public function owner()
  41. {
  42. return $this->belongsTo(UserInfo::class, 'owner_uid', 'userid');
  43. }
  44. /**
  45. * 拥有它的团队(owner 是团队时才有)。
  46. */
  47. public function ownerGroup(): BelongsTo
  48. {
  49. return $this->belongsTo(GroupInfo::class, 'owner_uid', 'uid');
  50. }
  51. }