| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace App\Module\Game\Dtos;
- /**
- * 物品变更临时数据DTO
- *
- * 用于存储和传输物品变更的临时数据
- */
- class ItemChangeTempDto
- {
- /**
- * 物品ID
- *
- * @var int
- */
- public int $itemId;
- /**
- * 物品实例ID(单独属性物品)
- *
- * @var int|null
- */
- public ?int $instanceId;
- /**
- * 旧数量
- *
- * @var int
- */
- public int $oldQuantity;
- /**
- * 新数量
- *
- * @var int
- */
- public int $newQuantity;
- /**
- * 变化量
- *
- * @var int
- */
- public int $changeAmount;
- /**
- * 用户物品记录ID
- *
- * @var int
- */
- public int $userItemId;
- /**
- * 更新时间戳
- *
- * @var int
- */
- public int $updatedAt;
- /**
- * 从数组创建DTO对象
- *
- * @param array $data 物品变更数据数组
- * @return self
- */
- public static function fromArray(array $data): self
- {
- $dto = new self();
- $dto->itemId = $data['item_id'];
- $dto->instanceId = $data['instance_id'];
- $dto->oldQuantity = $data['old_quantity'];
- $dto->newQuantity = $data['new_quantity'];
- $dto->changeAmount = $data['change_amount'];
- $dto->userItemId = $data['user_item_id'];
- $dto->updatedAt = $data['updated_at'];
- return $dto;
- }
- /**
- * 转换为数组
- *
- * @return array
- */
- public function toArray(): array
- {
- return [
- 'item_id' => $this->itemId,
- 'instance_id' => $this->instanceId,
- 'old_quantity' => $this->oldQuantity,
- 'new_quantity' => $this->newQuantity,
- 'change_amount' => $this->changeAmount,
- 'user_item_id' => $this->userItemId,
- 'updated_at' => $this->updatedAt,
- ];
- }
- }
|