ActivityReward.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Models;
  3. use App\Constants\Util;
  4. use Illuminate\Database\Eloquent\Relations\HasMany;
  5. /**
  6. * @property string $title
  7. * @property string sub_title
  8. * @property string detail_image
  9. * @property string start_time
  10. * @property string end_time
  11. * @property string status
  12. *
  13. */
  14. class ActivityReward extends BaseModel
  15. {
  16. const STATUS_UP = 1;
  17. const STATUS_DOWN = 0;
  18. protected $table = 'activity_rewards';
  19. protected $fillable = ['title', 'sub_title', 'detail_image', 'start_time', 'end_time', 'status','type','lang','content', 'params','pc_image','detail_banner', 'pc_banner',
  20. 'publish_platforms', 'budget', 'reward_quota', 'sort', 'register_time_limited', 'register_start_time', 'register_end_time',
  21. 'register_platforms', 'deposit_limited', 'deposit_min', 'deposit_max', 'show_ineligible'];
  22. protected $casts = [
  23. 'publish_platforms' => 'array', 'register_platforms' => 'array',
  24. 'register_time_limited' => 'boolean', 'deposit_limited' => 'boolean',
  25. 'show_ineligible' => 'boolean', 'reward_quota' => 'integer', 'rewarded_count' => 'integer',
  26. 'quota_enabled' => 'boolean', 'budget' => 'decimal:2', 'budget_used' => 'decimal:2',
  27. 'deposit_min' => 'decimal:2', 'deposit_max' => 'decimal:2', 'sort' => 'integer',
  28. ];
  29. public function activityUser(): HasMany
  30. {
  31. return $this->hasMany(ActivityUser::class, 'activity_id', 'id');
  32. }
  33. protected function getDetailImageAttribute($value)
  34. {
  35. return Util::ensureUrl($value);
  36. }
  37. protected function setDetailImageAttribute($value)
  38. {
  39. $this->attributes['detail_image'] = Util::replacePartInUrl($value);
  40. }
  41. protected function getPcImageAttribute($value)
  42. {
  43. return Util::ensureUrl($value);
  44. }
  45. protected function setPcImageAttribute($value)
  46. {
  47. $this->attributes['pc_image'] = Util::replacePartInUrl($value);
  48. }
  49. protected function getStartTimeAttribute($value): string
  50. {
  51. return date('Y-m-d', $value);
  52. }
  53. protected function getEndTimeAttribute($value): string
  54. {
  55. return date('Y-m-d', $value);
  56. }
  57. }