| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace App\Module\Farm\Dtos;
- use App\Module\Farm\Models\FarmHarvestLog;
- /**
- * 收获结果数据传输对象
- */
- class HarvestResultDto
- {
- /**
- * 收获记录ID
- *
- * @var int
- */
- public $id;
- /**
- * 用户ID
- *
- * @var int
- */
- public $userId;
- /**
- * 土地ID
- *
- * @var int
- */
- public $landId;
- /**
- * 作物ID
- *
- * @var int
- */
- public $cropId;
- /**
- * 种子ID
- *
- * @var int
- */
- public $seedId;
- /**
- * 产出物品ID
- *
- * @var int
- */
- public $outputItemId;
- /**
- * 产出数量
- *
- * @var int
- */
- public $outputAmount;
- /**
- * 收获时间
- *
- * @var string
- */
- public $harvestTime;
- /**
- * 从模型创建DTO
- *
- * @param FarmHarvestLog $harvestLog
- * @param int $outputItemId
- * @return self
- */
- public static function fromModel(FarmHarvestLog $harvestLog, int $outputItemId): self
- {
- $dto = new self();
- $dto->id = $harvestLog->id;
- $dto->userId = $harvestLog->user_id;
- $dto->landId = $harvestLog->land_id;
- $dto->cropId = $harvestLog->crop_id;
- $dto->seedId = $harvestLog->seed_id;
- $dto->outputItemId = $outputItemId;
- $dto->outputAmount = $harvestLog->output_amount;
- $dto->harvestTime = $harvestLog->harvest_time->toDateTimeString();
- return $dto;
- }
- /**
- * 转换为数组
- *
- * @return array
- */
- public function toArray(): array
- {
- return [
- 'id' => $this->id,
- 'user_id' => $this->userId,
- 'land_id' => $this->landId,
- 'crop_id' => $this->cropId,
- 'seed_id' => $this->seedId,
- 'output_item_id' => $this->outputItemId,
- 'output_amount' => $this->outputAmount,
- 'harvest_time' => $this->harvestTime,
- ];
- }
- }
|