From a347b5470dd7644786e24aa195e604c248bd3d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sun, 5 Nov 2023 23:18:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AF=81=E4=B9=A6=E6=9C=AA=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E7=A6=81=E6=AD=A2=E5=88=A0=E9=99=A4=E7=BD=91=E7=AB=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/website.go | 2 ++ app/services/website.go | 6 +++++- go.sum | 2 -- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/models/website.go b/app/models/website.go index 55b2333818..39aef3895d 100644 --- a/app/models/website.go +++ b/app/models/website.go @@ -14,4 +14,6 @@ type Website struct { Remark string `gorm:"default:''" json:"remark"` CreatedAt carbon.DateTime `gorm:"autoCreateTime;column:created_at" json:"created_at"` UpdatedAt carbon.DateTime `gorm:"autoUpdateTime;column:updated_at" json:"updated_at"` + + Cert *Cert `gorm:"foreignKey:WebsiteID" json:"cert"` } diff --git a/app/services/website.go b/app/services/website.go index df87eb6557..572ae4762d 100644 --- a/app/services/website.go +++ b/app/services/website.go @@ -295,10 +295,14 @@ server // Delete 删除网站 func (r *WebsiteImpl) Delete(id int) error { var website models.Website - if err := facades.Orm().Query().Where("id", id).FirstOrFail(&website); err != nil { + if err := facades.Orm().Query().With("Cert").Where("id", id).FirstOrFail(&website); err != nil { return err } + if website.Cert != nil { + return errors.New("网站" + website.Name + "已绑定SSL证书,请先删除证书") + } + if _, err := facades.Orm().Query().Delete(&website); err != nil { return err } diff --git a/go.sum b/go.sum index bae59a31c1..ed4812d612 100644 --- a/go.sum +++ b/go.sum @@ -385,8 +385,6 @@ github.com/goravel/file-rotatelogs v0.0.0-20211215053220-2ab31dd9575c h1:obhFK91 github.com/goravel/file-rotatelogs v0.0.0-20211215053220-2ab31dd9575c/go.mod h1:YSWsLXlG16u5CWFaXNZHhEQD10+NwF3xfgDV816OwLE= github.com/goravel/file-rotatelogs/v2 v2.4.1 h1:ogkeIFcTHSBRUBpZYiyJbpul8hkVXxHPuDbOaP78O1M= github.com/goravel/file-rotatelogs/v2 v2.4.1/go.mod h1:euk9qr52WrzM8ICs1hecFcR4CZ/ZZOPdacHfvHgbOf0= -github.com/goravel/framework v1.13.1-0.20231104153423-7bfd9573b12d h1:20bsAUUZWGcB8LvCP3nbO+fxGPuwYITiUJGnyx2xUgQ= -github.com/goravel/framework v1.13.1-0.20231104153423-7bfd9573b12d/go.mod h1:5jKFbJzfqhaQTP3HCgbyrpnrCyoJjxN5JWSXO96H0iQ= github.com/goravel/framework v1.13.1-0.20231105145249-62c723ac8fd1 h1:Bi86UTQtrQIo74ler6NbbXTy0dOGGZaNwtRcBOuZom8= github.com/goravel/framework v1.13.1-0.20231105145249-62c723ac8fd1/go.mod h1:5jKFbJzfqhaQTP3HCgbyrpnrCyoJjxN5JWSXO96H0iQ= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=