diff --git a/modules/player/service/pet.go b/modules/player/service/pet.go index ab639e04a..9e43894b0 100644 --- a/modules/player/service/pet.go +++ b/modules/player/service/pet.go @@ -82,29 +82,31 @@ func (s *PetService) UPdatePrice(ctime uint32, Price uint32, is_sale uint32) err return nil } func (s *PetService) BuyPet(pid uint32) error { - tt := NewPetService(0).PetInfo_One_ID(pid) - - if tt == nil { - return fmt.Errorf("没有此精灵") - } - if tt.IsVip != 0 { - return fmt.Errorf("不允许交易") - } - if tt.IsSale == 0 { - return fmt.Errorf("未上架") - } - if tt.Free == 0 { - return fmt.Errorf("没有此精灵") - } - if tt.SalePrice == 0 { - return fmt.Errorf("未设置价格") - } - if !tt.UpdateTime.AddDate(0, 0, 1).Before(gtime.Now()) { - return fmt.Errorf("数据异常") - } return g.DB().Transaction(context.TODO(), func(ctx context.Context, tx gdb.TX) error { + m := tx.Model(s.Model).Where("is_vip", 0).Where("id", pid) + var tt *model.Pet + + m.Scan(&tt) + if tt == nil { + return fmt.Errorf("没有此精灵") + } + if tt.IsVip != 0 { + return fmt.Errorf("不允许交易") + } + if tt.IsSale == 0 { + return fmt.Errorf("未上架") + } + if tt.Free == 0 { + return fmt.Errorf("没有此精灵") + } + if tt.SalePrice == 0 { + return fmt.Errorf("未设置价格") + } + if !tt.UpdateTime.AddDate(0, 0, 1).Before(gtime.Now()) { + return fmt.Errorf("数据异常") + } useglod := int64(tt.SalePrice)*102 + int64(tt.SaleCount)*5 var res1 basemodel.BaseSysUser