PetUser.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace App\Module\Pet\Models;
  3. use UCore\ModelCore;
  4. use App\Module\Pet\Enums\PetStatus;
  5. use Illuminate\Database\Eloquent\Relations\HasMany;
  6. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  7. /**
  8. * 宠物模型
  9. *
  10. * field start
  11. *
  12. * @property int $id
  13. * @property int $user_id 用户ID
  14. * @property string $name 宠物名称
  15. * @property int $grade 品阶
  16. * @property int $level 等级
  17. * @property int $experience 经验
  18. * @property int $stamina 体力
  19. * @property int $max_experience 最高经验
  20. * @property int $max_stamina 体力 上限
  21. * @property App\Module\Pet\Enums\PetStatus $status 宠物状态:0未知,1正常,2战斗中,3死亡
  22. * @property \Carbon\Carbon $created_at
  23. * @property \Carbon\Carbon $updated_at
  24. * field end
  25. */
  26. class PetUser extends ModelCore
  27. {
  28. /**
  29. * 与模型关联的表名
  30. *
  31. * @var string
  32. */
  33. protected $table = 'pet_users';
  34. /**
  35. * 可批量赋值的属性
  36. *
  37. * @var array
  38. */
  39. // attrlist start
  40. protected $fillable = [
  41. 'id',
  42. 'user_id',
  43. 'name',
  44. 'grade',
  45. 'level',
  46. 'experience',
  47. 'stamina',
  48. 'max_experience',
  49. 'max_stamina',
  50. 'status',
  51. ];
  52. // attrlist end
  53. /**
  54. * 属性类型转换
  55. *
  56. * @var array
  57. */
  58. protected $casts = [
  59. 'user_id' => 'integer',
  60. 'level' => 'integer',
  61. 'experience' => 'integer',
  62. 'stamina' => 'integer',
  63. 'status' => PetStatus::class,
  64. 'grade' => 'integer',
  65. 'created_at' => 'datetime',
  66. 'updated_at' => 'datetime',
  67. ];
  68. /**
  69. * 获取关联的用户
  70. *
  71. * @return BelongsTo
  72. */
  73. public function user(): BelongsTo
  74. {
  75. return $this->belongsTo(\App\Module\User\Models\User::class, 'user_id');
  76. }
  77. /**
  78. * 获取宠物的技能使用记录
  79. *
  80. * @return HasMany
  81. */
  82. public function skillLogs(): HasMany
  83. {
  84. return $this->hasMany(PetSkillLog::class, 'pet_id');
  85. }
  86. /**
  87. * 获取宠物的洗髓记录
  88. *
  89. * @return HasMany
  90. */
  91. public function remouldLogs(): HasMany
  92. {
  93. return $this->hasMany(PetRemouldLog::class, 'pet_id');
  94. }
  95. /**
  96. * 获取宠物的战斗记录
  97. *
  98. * @return HasMany
  99. */
  100. public function battleLogs(): HasMany
  101. {
  102. return $this->hasMany(PetBattleLog::class, 'pet_id');
  103. }
  104. /**
  105. * 获取宠物的当前等级配置
  106. *
  107. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  108. */
  109. public function levelConfig()
  110. {
  111. return $this->hasOne(PetLevelConfig::class, 'level', 'level');
  112. }
  113. }