FriendRequest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace App\Module\Friend\Models;
  3. use UCore\ModelCore;
  4. use App\Module\User\Models\User;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. /**
  7. * 好友申请模型
  8. *
  9. * 该模型用于表示用户之间的好友申请记录,包含申请状态、消息等信息。
  10. *
  11. * field start
  12. * @property int $id 主键ID
  13. * @property int $sender_id 发送者ID
  14. * @property int $receiver_id 接收者ID
  15. * @property string $message 申请附带消息
  16. * @property int $status 状态:0待处理,1已同意,2已拒绝,3已过期
  17. * @property int $read_status 读取状态:0未读,1已读
  18. * @property \Carbon\Carbon $created_at 创建时间
  19. * @property \Carbon\Carbon $updated_at 更新时间
  20. * @property \Carbon\Carbon $expired_at 过期时间
  21. * field end
  22. * @property-read User $sender 发送者关联
  23. * @property-read User $receiver 接收者关联
  24. */
  25. class FriendRequest extends ModelCore
  26. {
  27. /**
  28. * 与模型关联的表名
  29. *
  30. * @var string
  31. */
  32. protected $table = 'friend_requests';
  33. /**
  34. * 可批量赋值的属性
  35. *
  36. * @var array
  37. */
  38. // attrlist start
  39. protected $fillable = [
  40. 'id',
  41. 'sender_id',
  42. 'receiver_id',
  43. 'message',
  44. 'status',
  45. 'read_status',
  46. 'expired_at',
  47. ];
  48. // attrlist end
  49. /**
  50. * 属性默认值
  51. *
  52. * @var array
  53. */
  54. protected $attributes = [
  55. 'status' => 0,
  56. 'read_status' => 0,
  57. ];
  58. /**
  59. * 属性类型转换
  60. *
  61. * @var array
  62. */
  63. protected $casts = [
  64. 'sender_id' => 'integer',
  65. 'receiver_id' => 'integer',
  66. 'status' => 'integer',
  67. 'read_status' => 'integer',
  68. 'expired_at' => 'datetime',
  69. ];
  70. /**
  71. * 申请状态:待处理
  72. */
  73. const STATUS_PENDING = 0;
  74. /**
  75. * 申请状态:已同意
  76. */
  77. const STATUS_ACCEPTED = 1;
  78. /**
  79. * 申请状态:已拒绝
  80. */
  81. const STATUS_REJECTED = 2;
  82. /**
  83. * 申请状态:已过期
  84. */
  85. const STATUS_EXPIRED = 3;
  86. /**
  87. * 读取状态:未读
  88. */
  89. const READ_STATUS_UNREAD = 0;
  90. /**
  91. * 读取状态:已读
  92. */
  93. const READ_STATUS_READ = 1;
  94. /**
  95. * 获取关联的发送者
  96. *
  97. * @return BelongsTo
  98. */
  99. public function sender(): BelongsTo
  100. {
  101. return $this->belongsTo(User::class, 'sender_id');
  102. }
  103. /**
  104. * 获取关联的接收者
  105. *
  106. * @return BelongsTo
  107. */
  108. public function receiver(): BelongsTo
  109. {
  110. return $this->belongsTo(User::class, 'receiver_id');
  111. }
  112. }