| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace App\Models;
- use App\Constants\Util;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use App\Support\ActivityCatalog;
- /**
- * @property string $title
- * @property string sub_title
- * @property string detail_image
- * @property string start_time
- * @property string end_time
- * @property string status
- *
- */
- class ActivityReward extends BaseModel
- {
- const STATUS_UP = 1;
- const STATUS_DOWN = 0;
- protected $table = 'activity_rewards';
- protected $fillable = ['title', 'sub_title', 'detail_image', 'start_time', 'end_time', 'status','type','lang','content', 'params','pc_image','detail_banner', 'pc_banner',
- 'publish_platforms', 'budget', 'reward_quota', 'sort', 'register_time_limited', 'register_start_time', 'register_end_time',
- 'register_platforms', 'deposit_limited', 'deposit_min', 'deposit_max', 'show_ineligible', 'game_category', 'click_type', 'link'];
- protected $appends = ['type_name', 'game_category_name', 'click_type', 'link', 'can_jump'];
- protected function getClickTypeAttribute($value): string
- {
- $value = $value ?? ($this->attributes['click_type'] ?? 'none');
- return in_array($value, ['none', 'external', 'internal'], true) ? $value : 'none';
- }
- protected function getLinkAttribute($value): ?string
- {
- return in_array($this->click_type, ['external', 'internal'], true) ? ($value ?? ($this->attributes['link'] ?? null)) : null;
- }
- protected function getCanJumpAttribute(): bool
- {
- return in_array($this->click_type, ['external', 'internal'], true) && !empty($this->link);
- }
- protected $casts = [
- 'publish_platforms' => 'array', 'register_platforms' => 'array',
- 'register_time_limited' => 'boolean', 'deposit_limited' => 'boolean',
- 'show_ineligible' => 'boolean', 'reward_quota' => 'integer', 'rewarded_count' => 'integer',
- 'quota_enabled' => 'boolean', 'budget' => 'decimal:2', 'budget_used' => 'decimal:2',
- 'deposit_min' => 'decimal:2', 'deposit_max' => 'decimal:2', 'sort' => 'integer',
- ];
- public function activityUser(): HasMany
- {
- return $this->hasMany(ActivityUser::class, 'activity_id', 'id');
- }
- protected function getTypeNameAttribute(): ?string
- {
- return ActivityCatalog::activityTypes()[(int) ($this->attributes['type'] ?? 0)] ?? null;
- }
- protected function getGameCategoryNameAttribute(): ?string
- {
- return ActivityCatalog::gameTypes()[$this->attributes['game_category'] ?? ''] ?? null;
- }
- protected function getDetailImageAttribute($value)
- {
- return Util::ensureUrl($value);
- }
- protected function setDetailImageAttribute($value)
- {
- $this->attributes['detail_image'] = Util::replacePartInUrl($value);
- }
- protected function getPcImageAttribute($value)
- {
- return Util::ensureUrl($value);
- }
- protected function setPcImageAttribute($value)
- {
- $this->attributes['pc_image'] = Util::replacePartInUrl($value);
- }
- protected function getStartTimeAttribute($value): string
- {
- return date('Y-m-d', $value);
- }
- protected function getEndTimeAttribute($value): string
- {
- return date('Y-m-d', $value);
- }
- }
|