| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace App\Module\Friend\Models;
- use UCore\ModelCore;
- use App\Module\User\Models\User;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- /**
- * 好友申请模型
- *
- * 该模型用于表示用户之间的好友申请记录,包含申请状态、消息等信息。
- *
- * field start
- * @property int $id 主键ID
- * @property int $sender_id 发送者ID
- * @property int $receiver_id 接收者ID
- * @property string $message 申请附带消息
- * @property int $status 状态:0待处理,1已同意,2已拒绝,3已过期
- * @property int $read_status 读取状态:0未读,1已读
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * @property \Carbon\Carbon $expired_at 过期时间
- * field end
- * @property-read User $sender 发送者关联
- * @property-read User $receiver 接收者关联
- */
- class FriendRequest extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'friend_requests';
- /**
- * 可批量赋值的属性
- *
- * @var array
- */
- // attrlist start
- protected $fillable = [
- 'id',
- 'sender_id',
- 'receiver_id',
- 'message',
- 'status',
- 'read_status',
- 'expired_at',
- ];
- // attrlist end
- /**
- * 属性默认值
- *
- * @var array
- */
- protected $attributes = [
- 'status' => 0,
- 'read_status' => 0,
- ];
- /**
- * 属性类型转换
- *
- * @var array
- */
- protected $casts = [
- 'sender_id' => 'integer',
- 'receiver_id' => 'integer',
- 'status' => 'integer',
- 'read_status' => 'integer',
- 'expired_at' => 'datetime',
- ];
- /**
- * 申请状态:待处理
- */
- const STATUS_PENDING = 0;
- /**
- * 申请状态:已同意
- */
- const STATUS_ACCEPTED = 1;
- /**
- * 申请状态:已拒绝
- */
- const STATUS_REJECTED = 2;
- /**
- * 申请状态:已过期
- */
- const STATUS_EXPIRED = 3;
- /**
- * 读取状态:未读
- */
- const READ_STATUS_UNREAD = 0;
- /**
- * 读取状态:已读
- */
- const READ_STATUS_READ = 1;
- /**
- * 获取关联的发送者
- *
- * @return BelongsTo
- */
- public function sender(): BelongsTo
- {
- return $this->belongsTo(User::class, 'sender_id');
- }
- /**
- * 获取关联的接收者
- *
- * @return BelongsTo
- */
- public function receiver(): BelongsTo
- {
- return $this->belongsTo(User::class, 'receiver_id');
- }
- }
|