| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace App\Module\Activity\Models;
- use App\Module\Activity\Enums\CONDITION_TYPE;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use UCore\ModelCore;
- /**
- * 活动条件
- *
- * field start
- * @property int $id 主键
- * @property int $activity_id 关联活动ID
- * @property int $condition_type 条件类型(1:等级要求, 2:道具要求, 3:时间要求等)
- * @property object|array $condition_params 条件参数,JSON格式
- * @property int $is_participation_condition 是否为参与条件(0:否, 1:是)
- * @property int $is_completion_condition 是否为完成条件(0:否, 1:是)
- * @property int $display_order 显示顺序
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class ActivityCondition extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'activity_condition';
- /**
- * 可批量赋值的属性
- *
- * @var array
- */
- // attrlist start
- protected $fillable = [
- 'id',
- 'activity_id',
- 'condition_type',
- 'condition_params',
- 'is_participation_condition',
- 'is_completion_condition',
- 'display_order',
- ];
- // attrlist end
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'activity_id' => 'integer',
- 'condition_type' => 'integer',
- 'condition_params' => 'json',
- 'is_participation_condition' => 'boolean',
- 'is_completion_condition' => 'boolean',
- 'display_order' => 'integer',
- ];
- /**
- * 获取关联的活动
- *
- * @return BelongsTo
- */
- public function activity(): BelongsTo
- {
- return $this->belongsTo(ActivityConfig::class, 'activity_id', 'id');
- }
- /**
- * 获取条件类型名称
- *
- * @return string
- */
- public function getConditionTypeName(): string
- {
- return CONDITION_TYPE::getName($this->condition_type);
- }
- /**
- * 检查是否为参与条件
- *
- * @return bool
- */
- public function isParticipationCondition(): bool
- {
- return (bool)$this->is_participation_condition;
- }
- /**
- * 检查是否为完成条件
- *
- * @return bool
- */
- public function isCompletionCondition(): bool
- {
- return (bool)$this->is_completion_condition;
- }
- }
|