| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace App\Module\Farm\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- /**
- * 果实生长周期配置模型
- * field start
- * @property int $id 主键ID
- * @property int $fruit_item_id 果实物品ID
- * @property int $sprout_time 发芽期时间(秒)
- * @property int $growth_time 成长期时间(秒)
- * @property int $mature_time 成熟期时间(秒,0表示无限)
- * @property int $wither_time 枯萎期时间(秒,0表示无限)
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class FarmFruitGrowthCycle extends Model
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'farm_fruit_growth_cycles';
- /**
- * 可批量赋值的属性
- *
- * @var array
- */
- protected $fillable = [
- 'fruit_item_id',
- 'sprout_time',
- 'growth_time',
- 'mature_time',
- 'wither_time',
- ];
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'sprout_time' => 'integer',
- 'growth_time' => 'integer',
- 'mature_time' => 'integer',
- 'wither_time' => 'integer',
- ];
- /**
- * 获取关联的果实物品
- *
- * @return BelongsTo
- */
- public function fruitItem(): BelongsTo
- {
- return $this->belongsTo(\App\Module\GameItems\Models\Item::class, 'fruit_item_id', 'id');
- }
- /**
- * 检查成熟期是否无限
- *
- * @return bool
- */
- public function isMatureTimeInfinite(): bool
- {
- return $this->mature_time === 0;
- }
- /**
- * 检查枯萎期是否无限
- *
- * @return bool
- */
- public function isWitherTimeInfinite(): bool
- {
- return $this->wither_time === 0;
- }
- /**
- * 获取总生长时间(不包括无限期)
- *
- * @return int
- */
- public function getTotalGrowthTime(): int
- {
- $total = $this->sprout_time + $this->growth_time;
- if (!$this->isMatureTimeInfinite()) {
- $total += $this->mature_time;
- }
- if (!$this->isWitherTimeInfinite()) {
- $total += $this->wither_time;
- }
- return $total;
- }
- }
|