EgameItem.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace App\Models;
  3. class EgameItem extends BaseModel
  4. {
  5. public const TYPE_CATEGORY = 'category';
  6. public const TYPE_PLATFORM = 'platform';
  7. public const TYPE_GAME = 'game';
  8. public const PLATFORM_SCOPE_GLOBAL = 'global';
  9. public const PLATFORM_SCOPE_CATEGORY = 'category';
  10. public const STATUS_DISABLED = 0;
  11. public const STATUS_ENABLED = 1;
  12. public const INGRESS_PC = '1';
  13. public const INGRESS_MOBILE = '2';
  14. public const INGRESS_BOTH = '3';
  15. public const NETWORK_MAINLAND = 'mainland';
  16. public const NETWORK_HK = 'hk';
  17. public const NETWORK_KR = 'kr';
  18. public const NETWORK_JP = 'jp';
  19. public const INGRESS_LABELS = [
  20. self::INGRESS_PC => '电脑网页',
  21. self::INGRESS_MOBILE => '手机网页',
  22. self::INGRESS_BOTH => '电脑/手机网页',
  23. ];
  24. public const NETWORK_LABELS = [
  25. self::NETWORK_MAINLAND => '大陆',
  26. self::NETWORK_HK => '香港',
  27. self::NETWORK_KR => '韩国',
  28. self::NETWORK_JP => '日本',
  29. ];
  30. public const STATUS_LABELS = [
  31. self::STATUS_ENABLED => '启用',
  32. self::STATUS_DISABLED => '停用',
  33. ];
  34. protected $table = 'egame_items';
  35. protected $fillable = [
  36. 'item_type',
  37. 'plat_type',
  38. 'game_type',
  39. 'game_code',
  40. 'name',
  41. 'description',
  42. 'ingress',
  43. 'network',
  44. 'lobby_enabled',
  45. 'logo',
  46. 'logo_h5',
  47. 'logo_langs',
  48. 'status',
  49. 'sort',
  50. ];
  51. protected $casts = [
  52. 'game_type' => 'integer',
  53. 'lobby_enabled' => 'integer',
  54. 'logo_langs' => 'array',
  55. 'status' => 'integer',
  56. 'sort' => 'integer',
  57. ];
  58. public function isCategory(): bool
  59. {
  60. return $this->item_type === self::TYPE_CATEGORY;
  61. }
  62. public function isGlobalPlatform(): bool
  63. {
  64. return $this->item_type === self::TYPE_PLATFORM && $this->game_type === 0;
  65. }
  66. public function isPlatformRelation(): bool
  67. {
  68. return $this->item_type === self::TYPE_PLATFORM && $this->game_type > 0;
  69. }
  70. public static function ingressValues(): array
  71. {
  72. return array_keys(self::INGRESS_LABELS);
  73. }
  74. public static function networkValues(): array
  75. {
  76. return array_keys(self::NETWORK_LABELS);
  77. }
  78. public static function ingressName(?string $ingress): string
  79. {
  80. return self::INGRESS_LABELS[(string) $ingress] ?? '';
  81. }
  82. public static function networkName(?string $network): string
  83. {
  84. $network = (string) $network;
  85. if ($network === '') {
  86. return '不限制';
  87. }
  88. return self::NETWORK_LABELS[$network] ?? '';
  89. }
  90. public static function optionList(array $labels): array
  91. {
  92. $options = [];
  93. foreach ($labels as $value => $label) {
  94. $options[] = ['value' => $value, 'label' => $label];
  95. }
  96. return $options;
  97. }
  98. }