PetUser.php 2.7 KB

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