PetUser.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. use Illuminate\Database\Eloquent\SoftDeletes;
  8. /**
  9. * 宠物模型
  10. *
  11. * field start
  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. * @property \Carbon\Carbon $deleted_at 删除时间
  25. * field end
  26. */
  27. class PetUser extends ModelCore
  28. {
  29. use SoftDeletes;
  30. /**
  31. * 与模型关联的表名
  32. *
  33. * @var string
  34. */
  35. protected $table = 'pet_users';
  36. /**
  37. * 可批量赋值的属性
  38. *
  39. * @var array
  40. */
  41. // attrlist start
  42. protected $fillable = [
  43. 'id',
  44. 'user_id',
  45. 'name',
  46. 'grade',
  47. 'level',
  48. 'experience',
  49. 'stamina',
  50. 'max_experience',
  51. 'max_stamina',
  52. 'status',
  53. ];
  54. // attrlist end
  55. /**
  56. * 属性类型转换
  57. *
  58. * @var array
  59. */
  60. protected $casts = [
  61. 'user_id' => 'integer',
  62. 'level' => 'integer',
  63. 'experience' => 'integer',
  64. 'stamina' => 'integer',
  65. 'status' => PetStatus::class,
  66. 'grade' => 'integer',
  67. 'created_at' => 'datetime',
  68. 'updated_at' => 'datetime',
  69. 'deleted_at' => 'datetime',
  70. ];
  71. /**
  72. * 获取关联的用户
  73. *
  74. * @return BelongsTo
  75. */
  76. public function user(): BelongsTo
  77. {
  78. return $this->belongsTo(\App\Module\User\Models\User::class, 'user_id');
  79. }
  80. /**
  81. * 获取宠物的技能使用记录
  82. *
  83. * @return HasMany
  84. */
  85. public function skillLogs(): HasMany
  86. {
  87. return $this->hasMany(PetSkillLog::class, 'pet_id');
  88. }
  89. /**
  90. * 获取宠物的洗髓记录
  91. *
  92. * @return HasMany
  93. */
  94. public function remouldLogs(): HasMany
  95. {
  96. return $this->hasMany(PetRemouldLog::class, 'pet_id');
  97. }
  98. /**
  99. * 获取宠物的战斗记录
  100. *
  101. * @return HasMany
  102. */
  103. public function battleLogs(): HasMany
  104. {
  105. return $this->hasMany(PetBattleLog::class, 'pet_id');
  106. }
  107. /**
  108. * 获取宠物的当前等级配置
  109. *
  110. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  111. */
  112. public function levelConfig()
  113. {
  114. return $this->hasOne(PetLevelConfig::class, 'level', 'level');
  115. }
  116. }