| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace App\Module\Activity\Models;
- use App\Module\Activity\Enums\ACTIVITY_STATUS;
- use App\Module\Activity\Enums\ACTIVITY_TYPE;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use UCore\ModelCore;
- /**
- * 活动基础配置
- *
- * field start
- * @property int $id
- * @property string $name 活动名称
- * @property int $type 活动类型
- * @property string $description 活动描述
- * @property string $start_time 开始时间
- * @property string $end_time 结束时间
- * @property int $status 活动状态
- * @property int $display_order 显示顺序
- * @property string $icon 活动图标URL
- * @property string $banner 活动横幅URL
- * @property int $reward_group_id 奖励组ID(关联game_reward_groups表)
- * @property string $reward_group_code 奖励组编码(关联game_reward_groups表的code字段)
- * @property object|array $config_params 活动特定配置参数
- * @property \Carbon\Carbon $created_at
- * @property \Carbon\Carbon $updated_at
- * field end
- */
- class ActivityConfig extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'activity_config';
- /**
- * 可批量赋值的属性
- *
- * @var array
- */
- // attrlist start
- protected $fillable = [
- 'id',
- 'name',
- 'type',
- 'description',
- 'start_time',
- 'end_time',
- 'status',
- 'display_order',
- 'icon',
- 'banner',
- 'reward_group_id',
- 'reward_group_code',
- 'config_params',
- ];
- // attrlist end
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'type' => 'integer',
- 'status' => 'integer',
- 'display_order' => 'integer',
- 'reward_group_id' => 'integer',
- 'config_params' => 'json',
- 'start_time' => 'datetime',
- 'end_time' => 'datetime',
- ];
- /**
- * 获取活动类型名称
- *
- * @return string
- */
- public function getTypeName(): string
- {
- return ACTIVITY_TYPE::getName($this->type);
- }
- /**
- * 获取活动状态名称
- *
- * @return string
- */
- public function getStatusName(): string
- {
- return ACTIVITY_STATUS::getName($this->status);
- }
- /**
- * 获取活动的参与记录
- *
- * @return HasMany
- */
- public function participations(): HasMany
- {
- return $this->hasMany(ActivityParticipation::class, 'activity_id', 'id');
- }
- /**
- * 获取活动的用户数据
- *
- * @return HasMany
- */
- public function userData(): HasMany
- {
- return $this->hasMany(UserActivityData::class, 'activity_id', 'id');
- }
- /**
- * 获取活动的条件
- *
- * @return HasMany
- */
- public function conditions(): HasMany
- {
- return $this->hasMany(ActivityCondition::class, 'activity_id', 'id');
- }
- /**
- * 检查活动是否进行中
- *
- * @return bool
- */
- public function isInProgress(): bool
- {
- return $this->status === ACTIVITY_STATUS::IN_PROGRESS->value;
- }
- /**
- * 检查活动是否已结束
- *
- * @return bool
- */
- public function isEnded(): bool
- {
- return $this->status === ACTIVITY_STATUS::ENDED->value || $this->status === ACTIVITY_STATUS::CLOSED->value;
- }
- /**
- * 检查活动是否未开始
- *
- * @return bool
- */
- public function isNotStarted(): bool
- {
- return $this->status === ACTIVITY_STATUS::NOT_STARTED->value;
- }
- }
|