$data) { if (is_array($data)) { $dto = new self(); $dto->landId = $data['land_id'] ?? $landId; $dto->position = $data['position'] ?? 0; $dto->landType = $data['land_type'] ?? 0; $dto->oldType = $data['old_type'] ?? null; $dto->newType = $data['new_type'] ?? null; $dto->oldStatus = $data['old_status'] ?? null; $dto->newStatus = $data['new_status'] ?? null; $dto->cropId = $data['crop_id'] ?? null; $dto->seedId = $data['seed_id'] ?? null; $dto->changeType = $data['change_type'] ?? 'type'; $dto->updatedAt = $data['updated_at'] ?? time(); $result[$landId] = $dto; } elseif ($data instanceof self) { $result[$landId] = $data; } } return $result; } /** * 转换为数组 * * @return array */ public function toArray(): array { return [ 'land_id' => $this->landId, 'position' => $this->position, 'land_type' => $this->landType, 'old_type' => $this->oldType, 'new_type' => $this->newType, 'old_status' => $this->oldStatus, 'new_status' => $this->newStatus, 'crop_id' => $this->cropId, 'seed_id' => $this->seedId, 'change_type' => $this->changeType, 'updated_at' => $this->updatedAt, ]; } /** * 判断是否为类型变更 * * @return bool */ public function isTypeChange(): bool { return $this->changeType === 'type'; } /** * 判断是否为状态变更 * * @return bool */ public function isStatusChange(): bool { return $this->changeType === 'status'; } }