新增每日签到与补签卡功能

This commit is contained in:
2026-04-24 22:47:27 +08:00
parent 34356a26ae
commit be9fc09d9d
46 changed files with 3934 additions and 55 deletions
+82
View File
@@ -0,0 +1,82 @@
<?php
/**
* 文件功能:每日签到记录模型。
*
* 保存用户每天签到、连续天数、命中奖励规则与实际奖励快照。
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 类功能:封装每日签到流水的字段类型与用户、规则关联。
*/
class DailySignIn extends Model
{
/** @use HasFactory<\Database\Factories\DailySignInFactory> */
use HasFactory;
/**
* 允许批量赋值的字段。
*
* @var array<int, string>
*/
protected $fillable = [
'user_id',
'room_id',
'is_makeup',
'makeup_purchase_id',
'makeup_at',
'sign_in_date',
'streak_days',
'reward_rule_id',
'gold_reward',
'exp_reward',
'charm_reward',
'identity_badge_code',
'identity_badge_name',
'identity_badge_icon',
'identity_badge_color',
];
/**
* 属性类型转换。
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'room_id' => 'integer',
'is_makeup' => 'boolean',
'makeup_purchase_id' => 'integer',
'makeup_at' => 'datetime',
'sign_in_date' => 'date',
'streak_days' => 'integer',
'reward_rule_id' => 'integer',
'gold_reward' => 'integer',
'exp_reward' => 'integer',
'charm_reward' => 'integer',
];
}
/**
* 关联:签到记录所属用户。
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* 关联:本次签到命中的奖励规则。
*/
public function rewardRule(): BelongsTo
{
return $this->belongsTo(SignInRewardRule::class, 'reward_rule_id');
}
}
+10
View File
@@ -13,6 +13,8 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
class ShopItem extends Model
{
public const TYPE_SIGN_REPAIR = 'sign_repair';
protected $table = 'shop_items';
protected $fillable = [
@@ -41,6 +43,14 @@ class ShopItem extends Model
return $this->type === 'auto_fishing';
}
/**
* 是否为签到补签卡。
*/
public function isSignRepairCard(): bool
{
return $this->type === self::TYPE_SIGN_REPAIR;
}
/**
* 是否为特效类商品(instant durationslug once_ week_ 开头)
*/
+67
View File
@@ -0,0 +1,67 @@
<?php
/**
* 文件功能:每日签到奖励规则模型。
*
* 通过连续签到天数门槛配置金币、经验、魅力与身份徽章奖励。
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* 类功能:封装签到奖励规则字段、类型转换与命中签到记录关联。
*/
class SignInRewardRule extends Model
{
/** @use HasFactory<\Database\Factories\SignInRewardRuleFactory> */
use HasFactory;
/**
* 允许批量赋值的字段。
*
* @var array<int, string>
*/
protected $fillable = [
'streak_days',
'gold_reward',
'exp_reward',
'charm_reward',
'identity_badge_code',
'identity_badge_name',
'identity_badge_icon',
'identity_badge_color',
'identity_duration_days',
'is_enabled',
'sort_order',
];
/**
* 属性类型转换。
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'streak_days' => 'integer',
'gold_reward' => 'integer',
'exp_reward' => 'integer',
'charm_reward' => 'integer',
'identity_duration_days' => 'integer',
'is_enabled' => 'boolean',
'sort_order' => 'integer',
];
}
/**
* 关联:命中过该规则的签到记录。
*/
public function dailySignIns(): HasMany
{
return $this->hasMany(DailySignIn::class, 'reward_rule_id');
}
}
+43
View File
@@ -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();
}
// ── 职务相关关联 ──────────────────────────────────────────────────────
/**
+65
View File
@@ -0,0 +1,65 @@
<?php
/**
* 文件功能:用户身份徽章模型。
*
* 管理用户从签到等来源获得的当前身份展示标识。
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 类功能:封装用户身份徽章字段、类型转换与用户关联。
*/
class UserIdentityBadge extends Model
{
/** @use HasFactory<\Database\Factories\UserIdentityBadgeFactory> */
use HasFactory;
public const SOURCE_SIGN_IN = 'sign_in';
/**
* 允许批量赋值的字段。
*
* @var array<int, string>
*/
protected $fillable = [
'user_id',
'source',
'badge_code',
'badge_name',
'badge_icon',
'badge_color',
'acquired_at',
'expires_at',
'is_active',
'metadata',
];
/**
* 属性类型转换。
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'acquired_at' => 'datetime',
'expires_at' => 'datetime',
'is_active' => 'boolean',
'metadata' => 'array',
];
}
/**
* 关联:身份徽章所属用户。
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}