| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace App\Module\Pet\Models;
- use UCore\ModelCore;
- use App\Module\Pet\Enums\PetStatus;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- /**
- * 宠物模型
- *
- * field start
- * @property int $id
- * @property int $user_id 用户ID
- * @property string $name 宠物名称
- * @property int $grade 品阶
- * @property int $level 等级
- * @property int $experience 经验
- * @property int $stamina 体力
- * @property int $max_experience 最高经验
- * @property int $max_stamina 体力 上限
- * @property \App\Module\Pet\Enums\PetStatus $status 宠物状态:0未知,1正常,2战斗中,3死亡
- * @property \Carbon\Carbon $created_at
- * @property \Carbon\Carbon $updated_at
- * field end
- */
- class PetUser extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'pet_users';
- /**
- * 可批量赋值的属性
- *
- * @var array
- */
- // attrlist start
- protected $fillable = [
- 'id',
- 'user_id',
- 'name',
- 'grade',
- 'level',
- 'experience',
- 'stamina',
- 'max_experience',
- 'max_stamina',
- 'status',
- ];
- // attrlist end
- /**
- * 属性类型转换
- *
- * @var array
- */
- protected $casts = [
- 'user_id' => 'integer',
- 'level' => 'integer',
- 'experience' => 'integer',
- 'stamina' => 'integer',
- 'status' => PetStatus::class,
- 'grade' => 'integer',
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- ];
- /**
- * 获取关联的用户
- *
- * @return BelongsTo
- */
- public function user(): BelongsTo
- {
- return $this->belongsTo(\App\Module\User\Models\User::class, 'user_id');
- }
- /**
- * 获取宠物的技能使用记录
- *
- * @return HasMany
- */
- public function skillLogs(): HasMany
- {
- return $this->hasMany(PetSkillLog::class, 'pet_id');
- }
- /**
- * 获取宠物的洗髓记录
- *
- * @return HasMany
- */
- public function remouldLogs(): HasMany
- {
- return $this->hasMany(PetRemouldLog::class, 'pet_id');
- }
- /**
- * 获取宠物的战斗记录
- *
- * @return HasMany
- */
- public function battleLogs(): HasMany
- {
- return $this->hasMany(PetBattleLog::class, 'pet_id');
- }
- /**
- * 获取宠物的当前等级配置
- *
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function levelConfig()
- {
- return $this->hasOne(PetLevelConfig::class, 'level', 'level');
- }
- }
|