id = $item->id; $dto->name = $item->name; $dto->description = $item->description; $dto->categoryId = $item->category_id; $dto->categoryName = $item->category->name ?? null; $dto->type = $item->type->value; $dto->typeName = ITEM_TYPE::getName($item->type->value); $dto->isUnique = $item->is_unique; $dto->maxStack = $item->max_stack; $dto->sellPrice = $item->sell_price; $dto->tradable = $item->tradable; $dto->dismantlable = $item->dismantlable; $dto->defaultExpireSeconds = $item->default_expire_seconds; $dto->displayAttributes = (array)$item->display_attributes; $dto->numericAttributes = (array)$item->numeric_attributes; $dto->globalExpireAt = $item->global_expire_at ? $item->global_expire_at->format('Y-m-d H:i:s') : null; $dto->createdAt = $item->created_at->format('Y-m-d H:i:s'); $dto->updatedAt = $item->updated_at->format('Y-m-d H:i:s'); return $dto; } /** * 转换为数组 * * @return array */ public function toArray(): array { return [ 'id' => $this->id, 'name' => $this->name, 'description' => $this->description, 'category_id' => $this->categoryId, 'category_name' => $this->categoryName, 'type' => $this->type, 'type_name' => $this->typeName, 'is_unique' => $this->isUnique, 'max_stack' => $this->maxStack, 'sell_price' => $this->sellPrice, 'tradable' => $this->tradable, 'dismantlable' => $this->dismantlable, 'default_expire_seconds' => $this->defaultExpireSeconds, 'display_attributes' => $this->displayAttributes, 'numeric_attributes' => $this->numericAttributes, 'global_expire_at' => $this->globalExpireAt, 'created_at' => $this->createdAt, 'updated_at' => $this->updatedAt, ]; } }