From 13c78a5fec050ba15c878a3ef1c96fd3157041e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sat, 17 Dec 2022 15:16:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9/=E5=8F=96=E6=B6=88=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=A5=97=E9=A4=90=E5=90=8C=E6=97=B6=E6=8C=89=E9=9C=80?= =?UTF-8?q?=E5=8F=98=E6=9B=B4DNS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/models/server_dao.go | 49 ++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/internal/db/models/server_dao.go b/internal/db/models/server_dao.go index 8562cc68..3a1db33a 100644 --- a/internal/db/models/server_dao.go +++ b/internal/db/models/server_dao.go @@ -2494,6 +2494,14 @@ func (this *ServerDAO) UpdateServersClusterIdWithPlanId(tx *dbs.Tx, planId int64 // UpdateServerUserPlanId 设置服务所属套餐 func (this *ServerDAO) UpdateServerUserPlanId(tx *dbs.Tx, serverId int64, userPlanId int64) error { + oldClusterId, err := this.Query(tx). + Pk(serverId). + Result("clusterId"). + FindInt64Col(0) + if err != nil { + return err + } + // 取消套餐 if userPlanId <= 0 { // 所属用户 @@ -2524,7 +2532,24 @@ func (this *ServerDAO) UpdateServerUserPlanId(tx *dbs.Tx, serverId int64, userPl if err != nil { return err } - return this.NotifyUpdate(tx, serverId) + err = this.NotifyUpdate(tx, serverId) + if err != nil { + return err + } + + // 通知DNS更新 + if oldClusterId != clusterId { + if oldClusterId > 0 { + err = this.NotifyClusterDNSUpdate(tx, oldClusterId, serverId) + if err != nil { + return err + } + } + + return this.NotifyClusterDNSUpdate(tx, clusterId, serverId) + } + + return nil } // 设置新套餐 @@ -2544,16 +2569,34 @@ func (this *ServerDAO) UpdateServerUserPlanId(tx *dbs.Tx, serverId int64, userPl return errors.New("can not find plan with id '" + types.String(userPlan.PlanId) + "'") } + var clusterId = int64(plan.ClusterId) err = this.Query(tx). Pk(serverId). Set("userPlanId", userPlanId). Set("lastUserPlanId", userPlanId). - Set("clusterId", plan.ClusterId). + Set("clusterId", clusterId). UpdateQuickly() if err != nil { return err } - return this.NotifyUpdate(tx, serverId) + err = this.NotifyUpdate(tx, serverId) + if err != nil { + return err + } + + // 通知DNS更新 + if oldClusterId != clusterId { + if oldClusterId > 0 { + err = this.NotifyClusterDNSUpdate(tx, oldClusterId, serverId) + if err != nil { + return err + } + } + + return this.NotifyClusterDNSUpdate(tx, clusterId, serverId) + } + + return nil } // FindServerLastUserPlanIdAndUserId 查找最后使用的套餐