ActivityCondition.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace App\Module\Activity\Models;
  3. use App\Module\Activity\Enums\CONDITION_TYPE;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. use UCore\ModelCore;
  6. /**
  7. * 活动条件
  8. *
  9. * field start
  10. * @property int $id 主键
  11. * @property int $activity_id 关联活动ID
  12. * @property int $condition_type 条件类型(1:等级要求, 2:道具要求, 3:时间要求等)
  13. * @property object|array $condition_params 条件参数,JSON格式
  14. * @property int $is_participation_condition 是否为参与条件(0:否, 1:是)
  15. * @property int $is_completion_condition 是否为完成条件(0:否, 1:是)
  16. * @property int $display_order 显示顺序
  17. * @property \Carbon\Carbon $created_at 创建时间
  18. * @property \Carbon\Carbon $updated_at 更新时间
  19. * field end
  20. */
  21. class ActivityCondition extends ModelCore
  22. {
  23. /**
  24. * 与模型关联的表名
  25. *
  26. * @var string
  27. */
  28. protected $table = 'activity_condition';
  29. /**
  30. * 可批量赋值的属性
  31. *
  32. * @var array
  33. */
  34. // attrlist start
  35. protected $fillable = [
  36. 'id',
  37. 'activity_id',
  38. 'condition_type',
  39. 'condition_params',
  40. 'is_participation_condition',
  41. 'is_completion_condition',
  42. 'display_order',
  43. ];
  44. // attrlist end
  45. /**
  46. * 应该被转换为原生类型的属性
  47. *
  48. * @var array
  49. */
  50. protected $casts = [
  51. 'activity_id' => 'integer',
  52. 'condition_type' => 'integer',
  53. 'condition_params' => 'json',
  54. 'is_participation_condition' => 'boolean',
  55. 'is_completion_condition' => 'boolean',
  56. 'display_order' => 'integer',
  57. ];
  58. /**
  59. * 获取关联的活动
  60. *
  61. * @return BelongsTo
  62. */
  63. public function activity(): BelongsTo
  64. {
  65. return $this->belongsTo(ActivityConfig::class, 'activity_id', 'id');
  66. }
  67. /**
  68. * 获取条件类型名称
  69. *
  70. * @return string
  71. */
  72. public function getConditionTypeName(): string
  73. {
  74. return CONDITION_TYPE::getName($this->condition_type);
  75. }
  76. /**
  77. * 检查是否为参与条件
  78. *
  79. * @return bool
  80. */
  81. public function isParticipationCondition(): bool
  82. {
  83. return (bool)$this->is_participation_condition;
  84. }
  85. /**
  86. * 检查是否为完成条件
  87. *
  88. * @return bool
  89. */
  90. public function isCompletionCondition(): bool
  91. {
  92. return (bool)$this->is_completion_condition;
  93. }
  94. }