GameConditionGroup.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Module\Game\Models;
  3. use Illuminate\Database\Eloquent\Relations\HasMany;
  4. use UCore\ModelCore;
  5. /**
  6. * 条件组
  7. *
  8. * field start
  9. * @property int $id 主键
  10. * @property string $name 条件组名称
  11. * @property string $code 条件组编码(唯一)
  12. * @property string $description 条件组描述
  13. * @property int $logic_type 逻辑类型(1:全部满足, 2:任一满足)
  14. * @property \Carbon\Carbon $created_at 创建时间
  15. * @property \Carbon\Carbon $updated_at 更新时间
  16. * field end
  17. */
  18. class GameConditionGroup extends ModelCore
  19. {
  20. /**
  21. * 与模型关联的表名
  22. *
  23. * @var string
  24. */
  25. protected $table = 'game_condition_groups';
  26. // attrlist start
  27. protected $fillable = [
  28. 'id',
  29. 'name',
  30. 'code',
  31. 'description',
  32. 'logic_type',
  33. ];
  34. // attrlist end
  35. /**
  36. * 应该被转换为原生类型的属性
  37. *
  38. * @var array
  39. */
  40. protected $casts = [
  41. 'logic_type' => 'integer',
  42. ];
  43. /**
  44. * 逻辑类型:全部满足
  45. */
  46. const LOGIC_TYPE_ALL = 1;
  47. /**
  48. * 逻辑类型:任一满足
  49. */
  50. const LOGIC_TYPE_ANY = 2;
  51. /**
  52. * 获取逻辑类型列表
  53. *
  54. * @return array
  55. */
  56. public static function getLogicTypes(): array
  57. {
  58. return [
  59. self::LOGIC_TYPE_ALL => '全部满足',
  60. self::LOGIC_TYPE_ANY => '任一满足',
  61. ];
  62. }
  63. /**
  64. * 获取条件组中的所有条件项
  65. *
  66. * @return HasMany
  67. */
  68. public function conditionItems(): HasMany
  69. {
  70. return $this->hasMany(GameConditionItem::class, 'group_id', 'id');
  71. }
  72. }