ActivityReward.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Models;
  3. use App\Constants\Util;
  4. use Illuminate\Database\Eloquent\Relations\HasMany;
  5. use App\Support\ActivityCatalog;
  6. /**
  7. * @property string $title
  8. * @property string sub_title
  9. * @property string detail_image
  10. * @property string start_time
  11. * @property string end_time
  12. * @property string status
  13. *
  14. */
  15. class ActivityReward extends BaseModel
  16. {
  17. const STATUS_UP = 1;
  18. const STATUS_DOWN = 0;
  19. protected $table = 'activity_rewards';
  20. protected $fillable = ['title', 'sub_title', 'detail_image', 'start_time', 'end_time', 'status','type','lang','content', 'params','pc_image','detail_banner', 'pc_banner',
  21. 'publish_platforms', 'budget', 'reward_quota', 'sort', 'register_time_limited', 'register_start_time', 'register_end_time',
  22. 'register_platforms', 'deposit_limited', 'deposit_min', 'deposit_max', 'show_ineligible', 'game_category', 'click_type', 'link'];
  23. protected $appends = ['type_name', 'game_category_name', 'click_type', 'link', 'can_jump'];
  24. protected function getClickTypeAttribute($value): string
  25. {
  26. $value = $value ?? ($this->attributes['click_type'] ?? 'none');
  27. return in_array($value, ['none', 'external', 'internal'], true) ? $value : 'none';
  28. }
  29. protected function getLinkAttribute($value): ?string
  30. {
  31. return in_array($this->click_type, ['external', 'internal'], true) ? ($value ?? ($this->attributes['link'] ?? null)) : null;
  32. }
  33. protected function getCanJumpAttribute(): bool
  34. {
  35. return in_array($this->click_type, ['external', 'internal'], true) && !empty($this->link);
  36. }
  37. protected $casts = [
  38. 'publish_platforms' => 'array', 'register_platforms' => 'array',
  39. 'register_time_limited' => 'boolean', 'deposit_limited' => 'boolean',
  40. 'show_ineligible' => 'boolean', 'reward_quota' => 'integer', 'rewarded_count' => 'integer',
  41. 'quota_enabled' => 'boolean', 'budget' => 'decimal:2', 'budget_used' => 'decimal:2',
  42. 'deposit_min' => 'decimal:2', 'deposit_max' => 'decimal:2', 'sort' => 'integer',
  43. ];
  44. public function activityUser(): HasMany
  45. {
  46. return $this->hasMany(ActivityUser::class, 'activity_id', 'id');
  47. }
  48. protected function getTypeNameAttribute(): ?string
  49. {
  50. return ActivityCatalog::activityTypes()[(int) ($this->attributes['type'] ?? 0)] ?? null;
  51. }
  52. protected function getGameCategoryNameAttribute(): ?string
  53. {
  54. return ActivityCatalog::gameTypes()[$this->attributes['game_category'] ?? ''] ?? null;
  55. }
  56. protected function getDetailImageAttribute($value)
  57. {
  58. return Util::ensureUrl($value);
  59. }
  60. protected function setDetailImageAttribute($value)
  61. {
  62. $this->attributes['detail_image'] = Util::replacePartInUrl($value);
  63. }
  64. protected function getPcImageAttribute($value)
  65. {
  66. return Util::ensureUrl($value);
  67. }
  68. protected function setPcImageAttribute($value)
  69. {
  70. $this->attributes['pc_image'] = Util::replacePartInUrl($value);
  71. }
  72. protected function getStartTimeAttribute($value): string
  73. {
  74. return date('Y-m-d', $value);
  75. }
  76. protected function getEndTimeAttribute($value): string
  77. {
  78. return date('Y-m-d', $value);
  79. }
  80. }