83 lines
1.9 KiB
PHP
83 lines
1.9 KiB
PHP
<?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');
|
|
}
|
|
}
|