| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Module\Promotion\Models;
- use App\Module\Promotion\Enums\REFERRAL_LEVEL;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use UCore\ModelCore;
- /**
- * 用户关系缓存
- *
- * field start
- * field end
- */
- class PromotionUserRelationCache extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'promotion_user_relation_cache';
- // attrlist start
- protected $fillable = [
- ];
- // attrlist end
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'level' => REFERRAL_LEVEL::class,
- 'depth' => 'integer',
- ];
- /**
- * 获取用户信息
- *
- * @return BelongsTo
- */
- public function user()
- {
- return $this->belongsTo('App\Models\User', 'user_id');
- }
- /**
- * 获取关联用户信息
- *
- * @return BelongsTo
- */
- public function relatedUser()
- {
- return $this->belongsTo('App\Models\User', 'related_user_id');
- }
- /**
- * 获取关系路径数组
- *
- * @return array
- */
- public function getPathArrayAttribute(): array
- {
- if (empty($this->path)) {
- return [];
- }
- return explode(',', $this->path);
- }
- /**
- * 判断是否为直接关系
- *
- * @return bool
- */
- public function isDirectRelation(): bool
- {
- return $this->level == REFERRAL_LEVEL::DIRECT;
- }
- }
|