ActivityReward.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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'];
  23. protected $appends = ['type_name', 'game_category_name'];
  24. protected $casts = [
  25. 'publish_platforms' => 'array', 'register_platforms' => 'array',
  26. 'register_time_limited' => 'boolean', 'deposit_limited' => 'boolean',
  27. 'show_ineligible' => 'boolean', 'reward_quota' => 'integer', 'rewarded_count' => 'integer',
  28. 'quota_enabled' => 'boolean', 'budget' => 'decimal:2', 'budget_used' => 'decimal:2',
  29. 'deposit_min' => 'decimal:2', 'deposit_max' => 'decimal:2', 'sort' => 'integer',
  30. ];
  31. public function activityUser(): HasMany
  32. {
  33. return $this->hasMany(ActivityUser::class, 'activity_id', 'id');
  34. }
  35. protected function getTypeNameAttribute(): ?string
  36. {
  37. return ActivityCatalog::activityTypes()[(int) ($this->attributes['type'] ?? 0)] ?? null;
  38. }
  39. protected function getGameCategoryNameAttribute(): ?string
  40. {
  41. return ActivityCatalog::gameTypes()[$this->attributes['game_category'] ?? ''] ?? null;
  42. }
  43. protected function getDetailImageAttribute($value)
  44. {
  45. return Util::ensureUrl($value);
  46. }
  47. protected function setDetailImageAttribute($value)
  48. {
  49. $this->attributes['detail_image'] = Util::replacePartInUrl($value);
  50. }
  51. protected function getPcImageAttribute($value)
  52. {
  53. return Util::ensureUrl($value);
  54. }
  55. protected function setPcImageAttribute($value)
  56. {
  57. $this->attributes['pc_image'] = Util::replacePartInUrl($value);
  58. }
  59. protected function getStartTimeAttribute($value): string
  60. {
  61. return date('Y-m-d', $value);
  62. }
  63. protected function getEndTimeAttribute($value): string
  64. {
  65. return date('Y-m-d', $value);
  66. }
  67. }