新增每日签到与补签卡功能
This commit is contained in:
@@ -252,6 +252,49 @@ class User extends Authenticatable
|
||||
return $this->hasMany(VipPaymentOrder::class, 'user_id')->latest('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联:用户每日签到记录。
|
||||
*/
|
||||
public function dailySignIns(): HasMany
|
||||
{
|
||||
return $this->hasMany(DailySignIn::class, 'user_id')->latest('sign_in_date');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联:用户全部身份徽章。
|
||||
*/
|
||||
public function identityBadges(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserIdentityBadge::class, 'user_id')->latest('acquired_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联:用户当前启用的签到身份徽章。
|
||||
*/
|
||||
public function currentSignInIdentityBadge(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserIdentityBadge::class, 'user_id')
|
||||
->where('source', UserIdentityBadge::SOURCE_SIGN_IN)
|
||||
->where('is_active', true)
|
||||
->where(function ($query) {
|
||||
$query->whereNull('expires_at')
|
||||
->orWhere('expires_at', '>', now());
|
||||
})
|
||||
->latestOfMany('acquired_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前签到身份徽章辅助方法。
|
||||
*/
|
||||
public function currentSignInIdentity(): ?UserIdentityBadge
|
||||
{
|
||||
if ($this->relationLoaded('currentSignInIdentityBadge')) {
|
||||
return $this->getRelation('currentSignInIdentityBadge');
|
||||
}
|
||||
|
||||
return $this->currentSignInIdentityBadge()->first();
|
||||
}
|
||||
|
||||
// ── 职务相关关联 ──────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user