'integer', 'depth' => 'integer', 'user_id' => 'integer', 'related_user_id' => 'integer', 'urs_user_id' => 'integer', 'urs_related_user_id' => 'integer', ]; /** * 获取农场用户信息 */ public function user(): BelongsTo { return $this->belongsTo('App\Models\User', 'user_id'); } /** * 获取关联农场用户信息(上级) */ public function relatedUser(): BelongsTo { return $this->belongsTo('App\Models\User', 'related_user_id'); } /** * 获取农场用户关系路径数组 */ public function getPathArrayAttribute(): array { if (empty($this->path)) { return []; } return array_map('intval', explode(',', $this->path)); } /** * 获取URS用户关系路径数组 */ public function getUrsPathArrayAttribute(): array { if (empty($this->urs_path)) { return []; } return array_map('intval', explode(',', $this->urs_path)); } /** * 判断是否为直接关系 */ public function isDirectRelation(): bool { return $this->level == UrsPromotionRelationLevel::DIRECT; } /** * 判断是否为间接关系 */ public function isIndirectRelation(): bool { return $this->level == UrsPromotionRelationLevel::INDIRECT; } /** * 获取关系层级名称 */ public function getLevelNameAttribute(): string { return match ($this->level) { UrsPromotionRelationLevel::DIRECT => '直推', UrsPromotionRelationLevel::INDIRECT => '间推', default => '未知' }; } }