PetUser.php 2.5 KB

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