| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App\Module\Game\Dtos;
- use App\Module\Fund\Enums\FUND_TYPE;
- use UCore\Dto\BaseDto;
- /**
- * 资金变更临时数据传输对象
- *
- * 用于存储和传输资金变更的临时数据
- */
- class FundChangeTempDto extends BaseDto
- {
- /**
- * 资金类型ID
- *
- * @var int
- */
- public int $fundId;
- /**
- * 旧余额
- *
- * @var int
- */
- public int $oldBalance;
- /**
- * 新余额
- *
- * @var int
- */
- public int $newBalance;
- /**
- * 变化量
- *
- * @var int
- */
- public int $changeAmount;
- /**
- * 更新时间戳
- *
- * @var int
- */
- public int $updatedAt;
- /**
- * 从数组创建DTO
- *
- * @param array $data 数据数组
- * @return self
- */
- public static function fromArray(array $data): static
- {
- $dto = new self();
- $dto->fundId = $data['fund_id'] ?? 0;
- $dto->oldBalance = $data['old_balance'] ?? 0;
- $dto->newBalance = $data['new_balance'] ?? 0;
- $dto->changeAmount = $data['change_amount'] ?? 0;
- $dto->updatedAt = $data['updated_at'] ?? time();
- return $dto;
- }
- /**
- * 转换为数组
- *
- * @return array
- */
- public function toArray(): array
- {
- return [
- 'fund_id' => $this->fundId instanceof FUND_TYPE ? $this->fundId->value : $this->fundId,
- 'old_balance' => $this->oldBalance,
- 'new_balance' => $this->newBalance,
- 'change_amount' => $this->changeAmount,
- 'updated_at' => $this->updatedAt,
- ];
- }
- }
|