From 0dbb7d9a8dc2ad730f2dceb2aefcaaa4581394af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <1@72wo.cn> Date: Mon, 1 Sep 2025 01:31:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor(pet):=20=E9=87=8D=E6=9E=84=E7=B2=BE?= =?UTF-8?q?=E7=81=B5=E4=BF=A1=E6=81=AF=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=B9=B6=E4=B8=B0=E5=AF=8C=E7=B2=BE=E7=81=B5=E7=AE=80=E8=A6=81?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用 copier 库简化精灵信息复制过程 - 在 PetShortInfo 结构体中添加更多精灵属性: - ID - Level - SkinID - Shiny - 优化 GetPetList 函数返回值结构 --- logic/controller/pet.go | 10 +++++----- logic/service/pet/list.go | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/logic/controller/pet.go b/logic/controller/pet.go index 03ea1010f..cf701ec6b 100644 --- a/logic/controller/pet.go +++ b/logic/controller/pet.go @@ -6,6 +6,8 @@ import ( "blazing/logic/service/pet" "blazing/modules/blazing/service" blservice "blazing/modules/blazing/service" + + "github.com/jinzhu/copier" ) // 获取精灵信息 @@ -30,13 +32,11 @@ func (h *Controller) GetPetList( tt := blservice.NewUserService(c.Info.UserID).GetPetList(0) //获得未放生的精灵 result.ShortInfoList = make([]pet.PetShortInfo, len(tt)) for i, v := range tt { - result.ShortInfoList[i] = pet.PetShortInfo{ - TypeId: v.ID, - CatchTime: v.CatchTime, - } + copier.Copy(&result.ShortInfoList[i], &v) + } - return + return result, 0 } diff --git a/logic/service/pet/list.go b/logic/service/pet/list.go index 56d7eb491..6eb3feb9e 100644 --- a/logic/service/pet/list.go +++ b/logic/service/pet/list.go @@ -12,6 +12,9 @@ type GetPetListOutboundInfo struct { // PetShortInfo 精灵简要信息结构体 type PetShortInfo struct { - TypeId uint32 // 精灵类型ID + ID uint32 // 精灵类型ID(对应Java中的id) CatchTime uint32 // 精灵生成时间 + Level uint32 // 精灵等级 + SkinID uint32 // 精灵皮肤ID + Shiny uint32 // 精灵是否闪光(0=否,1=是) }