| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- namespace App\Module\Activity\Models;
- use App\Module\Activity\Enums\PARTICIPATION_STATUS;
- use App\Module\Activity\Enums\REWARD_STATUS;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use UCore\ModelCore;
- /**
- * 活动参与记录
- *
- * field start
- * @property int $id 主键
- * @property int $user_id 用户ID
- * @property int $activity_id 活动ID
- * @property \Carbon\Carbon $participate_time 参与时间
- * @property int $reward_status 奖励状态(0:未领取, 1:已领取, 2:已过期)
- * @property int $completion_status 完成状态(0:进行中, 1:已完成, 2:已失败)
- * @property \Carbon\Carbon $completion_time 完成时间
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class ActivityParticipation extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'activity_participation';
- /**
- * 可批量赋值的属性
- *
- * @var array
- */
- // attrlist start
- protected $fillable = [
- 'id',
- 'user_id',
- 'activity_id',
- 'participate_time',
- 'reward_status',
- 'completion_status',
- 'completion_time',
- ];
- // attrlist end
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'user_id' => 'integer',
- 'activity_id' => 'integer',
- 'reward_status' => 'integer',
- 'completion_status' => 'integer',
- 'participate_time' => 'datetime',
- 'completion_time' => 'datetime',
- ];
- /**
- * 获取关联的活动
- *
- * @return BelongsTo
- */
- public function activity(): BelongsTo
- {
- return $this->belongsTo(ActivityConfig::class, 'activity_id', 'id');
- }
- /**
- * 获取奖励状态名称
- *
- * @return string
- */
- public function getRewardStatusName(): string
- {
- return REWARD_STATUS::getName($this->reward_status);
- }
- /**
- * 获取完成状态名称
- *
- * @return string
- */
- public function getCompletionStatusName(): string
- {
- return PARTICIPATION_STATUS::getName($this->completion_status);
- }
- /**
- * 检查是否已完成
- *
- * @return bool
- */
- public function isCompleted(): bool
- {
- return $this->completion_status === PARTICIPATION_STATUS::COMPLETED;
- }
- /**
- * 检查是否进行中
- *
- * @return bool
- */
- public function isInProgress(): bool
- {
- return $this->completion_status === PARTICIPATION_STATUS::IN_PROGRESS;
- }
- /**
- * 检查是否已失败
- *
- * @return bool
- */
- public function isFailed(): bool
- {
- return $this->completion_status === PARTICIPATION_STATUS::FAILED;
- }
- /**
- * 检查奖励是否已领取
- *
- * @return bool
- */
- public function isRewardClaimed(): bool
- {
- return $this->reward_status === REWARD_STATUS::CLAIMED;
- }
- /**
- * 检查奖励是否未领取
- *
- * @return bool
- */
- public function isRewardNotClaimed(): bool
- {
- return $this->reward_status === REWARD_STATUS::NOT_CLAIMED;
- }
- /**
- * 检查奖励是否已过期
- *
- * @return bool
- */
- public function isRewardExpired(): bool
- {
- return $this->reward_status === REWARD_STATUS::EXPIRED;
- }
- }
|