EgameItem.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. 'icon',
  48. 'logo_langs',
  49. 'status',
  50. 'sort',
  51. ];
  52. protected $casts = [
  53. 'game_type' => 'integer',
  54. 'lobby_enabled' => 'integer',
  55. 'logo_langs' => 'array',
  56. 'status' => 'integer',
  57. 'sort' => 'integer',
  58. ];
  59. public function isCategory(): bool
  60. {
  61. return $this->item_type === self::TYPE_CATEGORY;
  62. }
  63. public function isGlobalPlatform(): bool
  64. {
  65. return $this->item_type === self::TYPE_PLATFORM && $this->game_type === 0;
  66. }
  67. public function isPlatformRelation(): bool
  68. {
  69. return $this->item_type === self::TYPE_PLATFORM && $this->game_type > 0;
  70. }
  71. public static function ingressValues(): array
  72. {
  73. return array_keys(self::INGRESS_LABELS);
  74. }
  75. public static function networkValues(): array
  76. {
  77. return array_keys(self::NETWORK_LABELS);
  78. }
  79. public static function ingressName(?string $ingress): string
  80. {
  81. return self::INGRESS_LABELS[(string) $ingress] ?? '';
  82. }
  83. public static function networkName(?string $network): string
  84. {
  85. $network = (string) $network;
  86. if ($network === '') {
  87. return '不限制';
  88. }
  89. return self::NETWORK_LABELS[$network] ?? '';
  90. }
  91. public static function optionList(array $labels): array
  92. {
  93. $options = [];
  94. foreach ($labels as $value => $label) {
  95. $options[] = ['value' => $value, 'label' => $label];
  96. }
  97. return $options;
  98. }
  99. }