Files
chatroom/app/Models/RedPacketClaim.php

52 lines
1022 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 文件功能:红包领取记录 Model
*
* 每条记录代表某个用户领取了某个红包的一份,
* envelope_id + user_id 联合唯一约束保证幂等性。
*
* @author ChatRoom Laravel
*
* @version 1.0.0
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class RedPacketClaim extends Model
{
/** 无自动 updated_at只记录 claimed_at */
public $timestamps = false;
protected $fillable = [
'envelope_id',
'user_id',
'username',
'amount',
'claimed_at',
];
/**
* 类型转换。
*/
public function casts(): array
{
return [
'claimed_at' => 'datetime',
];
}
/**
* 关联红包主表。
*
* @return BelongsTo<RedPacketEnvelope, RedPacketClaim>
*/
public function envelope(): BelongsTo
{
return $this->belongsTo(RedPacketEnvelope::class, 'envelope_id');
}
}