PetConfig.php 1.5 KB

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