| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace App\Module\Farm\Models;
- use App\Module\Farm\Enums\GROWTH_STAGE;
- use App\Module\GameItems\Models\Item;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasOne;
- use Illuminate\Database\Eloquent\SoftDeletes;
- /**
- * 作物信息模型
- *
- * field start
- * @property int $id 主键ID
- * @property int $land_id 土地ID
- * @property int $user_id 用户ID
- * @property int $seed_id 种子ID
- * @property int $land_level 种植时的土地等级
- * @property \Carbon\Carbon $plant_time 种植时间
- * @property \App\Module\Farm\Enums\GROWTH_STAGE $growth_stage 生长阶段:1种子期,2发芽期,3生长期,4成熟期,5枯萎期
- * @property \Carbon\Carbon $stage_start_time 当前阶段结束时间
- * @property \Carbon\Carbon $stage_end_time 当前阶段结束时间
- * @property array $disasters 灾害情况
- * @property bool $fertilized 当前阶段是否已使用化肥
- * @property \Carbon\Carbon $last_disaster_check_time 上次灾害检查时间
- * @property bool $can_disaster 当前阶段是否可以产生灾害:0否,1是
- * @property int $final_output_item_id 最终产出果实ID(发芽期确定)
- * @property int $final_output_amount 最终产出数量(成熟期确定)
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * @property \Carbon\Carbon $deleted_at 删除时间
- * field end
- *
- *
- */
- class FarmCrop extends Model
- {
- use SoftDeletes;
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'farm_crops';
- /**
- * 可批量赋值的属性
- *
- * @var array
- */
- protected $fillable = [
- 'land_id',
- 'user_id',
- 'seed_id',
- 'land_level',
- 'plant_time',
- 'growth_stage',
- 'stage_start_time',
- 'stage_end_time',
- 'disasters',
- 'fertilized',
- 'last_disaster_check_time',
- 'can_disaster',
- 'final_output_item_id',
- 'final_output_amount',
- ];
- /**
- * 应该被转换为原生类型的属性
- *
- * @var array
- */
- protected $casts = [
- 'disasters' => 'json',
- 'growth_stage' => GROWTH_STAGE::class,
- 'fertilized' => 'boolean',
- 'plant_time' => 'datetime',
- 'stage_start_time' => 'datetime',
- 'stage_end_time' => 'datetime',
- 'last_disaster_check_time' => 'datetime',
- 'can_disaster' => 'boolean',
- 'deleted_at' => 'datetime',
- ];
- /**
- * 获取关联的土地
- *
- * @return BelongsTo
- */
- public function land(): BelongsTo
- {
- return $this->belongsTo(FarmLand::class, 'land_id', 'id');
- }
- /**
- * 获取关联的种子
- *
- * @return BelongsTo
- */
- public function seed(): BelongsTo
- {
- return $this->belongsTo(FarmSeed::class, 'seed_id', 'id');
- }
- /**
- * 用户农场信息(房屋)
- * @return BelongsTo
- */
- public function user(): BelongsTo
- {
- return $this->belongsTo(FarmUser::class, 'user_id', 'user_id');
- }
- public function final_output_item():HasOne
- {
- return $this->hasOne(Item::class, 'id', 'final_output_item_id');
- }
- }
|