From 609058056031fc6515efe50814ef5d66e8a22e98 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Fri, 17 Oct 2025 19:23:38 +0000 Subject: [PATCH] =?UTF-8?q?```fix(pet):=20=E4=BF=AE=E5=A4=8D=E5=AE=A0?= =?UTF-8?q?=E7=89=A9=E6=B7=BB=E5=8A=A0=E6=97=B6=E6=8D=95=E6=8D=89=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=86=B2=E7=AA=81=E9=97=AE=E9=A2=98=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=94=AF=E4=B8=80=E9=94=AE=E7=BA=A6=E6=9D=9F=E5=92=8C?= =?UTF-8?q?=E8=87=AA=E5=A2=9E=E9=87=8D=E8=AF=95=E9=80=BB=E8=BE=91```?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/blazing/model/pet.go | 4 ++-- modules/blazing/service/pet.go | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/modules/blazing/model/pet.go b/modules/blazing/model/pet.go index 4a127fb7..6a5b5217 100644 --- a/modules/blazing/model/pet.go +++ b/modules/blazing/model/pet.go @@ -11,8 +11,8 @@ const TableNamePet = "pet" type Pet struct { *cool.Model PlayerID uint32 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"` - InBag int `gorm:"not null;comment:'是否在背包中'" json:"in_bag"` //"0为放入仓库,1为放入背包 - CatchTime uint32 `gorm:"not null;comment:'捕捉时间'" json:"catch_time"` + InBag int `gorm:"not null;comment:'是否在背包中'" json:"in_bag"` //"0为放入仓库,1为放入背包 + CatchTime uint32 `gorm:"not null;unique;comment:'捕捉时间'" json:"catch_time"` //唯一键 // Owner uint32 `struc:"skip"` //仅作为存储 // FreedTime uint32 `struc:"skip"` //放生时间 //是否可交易,这里应该定义在精灵ID里 diff --git a/modules/blazing/service/pet.go b/modules/blazing/service/pet.go index 950a5562..150ad023 100644 --- a/modules/blazing/service/pet.go +++ b/modules/blazing/service/pet.go @@ -34,14 +34,21 @@ func (s *UserService) PetInfo_One(cachetime uint32) model.PetEX { } func (s *UserService) PetAdd(y model.PetInfo) { - m1 := cool.DBM(s.pet.Model).Where("player_id", s.userid) - var player model.PetEX - player.PlayerID = s.userid - player.Data = y - player.CatchTime = y.CatchTime - player.InBag = 0 + for { + m1 := cool.DBM(s.pet.Model).Where("player_id", s.userid) + var player model.PetEX + player.PlayerID = s.userid + player.Data = y + player.CatchTime = y.CatchTime + player.InBag = 0 - m1.Insert(player) + _, err := m1.Insert(player) + if err == nil { + break + + } + y.CatchTime += 1//自增保持时间排序 + } }