PetConfig.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Module\Pet\Models;
  3. use UCore\ModelCore;
  4. use App\Module\Pet\Casts\DisplayAttributesCast;
  5. use App\Module\Pet\Casts\NumericAttributesCast;
  6. /**
  7. * 宠物配置模型
  8. *
  9. * field start
  10. * @property int $id
  11. * @property string $pet_type 宠物类型
  12. * @property object|array $grade_probability 品阶概率配置
  13. * @property object|array $feed_effect 喂养效果配置
  14. * @property int $max_level 最大等级
  15. * @property int $stamina_recovery 体力恢复值/分钟
  16. * @property object|array $display_attributes 显示属性配置
  17. * @property object|array $numeric_attributes 数值属性配置
  18. * @property \Carbon\Carbon $created_at
  19. * @property \Carbon\Carbon $updated_at
  20. * field end
  21. */
  22. class PetConfig extends ModelCore
  23. {
  24. /**
  25. * 与模型关联的表名
  26. *
  27. * @var string
  28. */
  29. protected $table = 'pet_configs';
  30. // attrlist start
  31. protected $fillable = [
  32. 'id',
  33. 'pet_type',
  34. 'grade_probability',
  35. 'feed_effect',
  36. 'max_level',
  37. 'stamina_recovery',
  38. 'display_attributes',
  39. 'numeric_attributes',
  40. ];
  41. // attrlist end
  42. /**
  43. * 应该被转换为原生类型的属性
  44. *
  45. * @var array
  46. */
  47. protected $casts = [
  48. 'grade_probability' => 'json',
  49. 'feed_effect' => 'json',
  50. 'max_level' => 'integer',
  51. 'stamina_recovery' => 'integer',
  52. 'display_attributes' => DisplayAttributesCast::class,
  53. 'numeric_attributes' => NumericAttributesCast::class,
  54. ];
  55. /**
  56. * 获取指定宠物类型的配置
  57. *
  58. * @param string $petType
  59. * @return self|null
  60. */
  61. public static function getByType(string $petType): ?self
  62. {
  63. return self::where('pet_type', $petType)->first();
  64. }
  65. }