From 8fca291eb0e63707f4e7bb641bc8d0d1b31fb5a0 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Fri, 19 Apr 2024 23:33:00 +0800 Subject: [PATCH] fix --- app/mix/dao/mysql_zone.go | 28 ++++++++++++++++++++++++---- app/mix/service/logic/vas_zone.go | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/mix/dao/mysql_zone.go b/app/mix/dao/mysql_zone.go index 50f689bf..ebd7641c 100644 --- a/app/mix/dao/mysql_zone.go +++ b/app/mix/dao/mysql_zone.go @@ -108,15 +108,35 @@ func (m *Mysql) CreateZoneUnlock(ctx *gin.Context, tx *sqlx.Tx, mid, zid int64) return nil } -// 解锁空间动态 +// 添加到空间成员 func (m *Mysql) UnlockZoneMoment(ctx *gin.Context, tx *sqlx.Tx, mid, zid, momentId int64, orderId string) error { var err error - sqlStr := "update " + TableVasZoneMomentUnlock + " set moment_id=?, `status`=?, ct=?, order_id=? where mid=? and zid=?" + // 先获取,没有再添加 + var tmpZm dbstruct.ZoneMomentUnlock if tx != nil { - _, err = tx.ExecContext(ctx, sqlStr, momentId, dbstruct.ZoneMomentUnlockStatusUnlock, time.Now().Unix(), orderId, mid, zid) + err = tx.GetContext(ctx, &tmpZm, fmt.Sprintf("select * from %s where mid=? and zid=? and moment_id=?", TableVasZoneMomentUnlock), mid, zid, momentId) } else { db := m.getDBVas() - _, err = db.ExecContext(ctx, sqlStr, momentId, dbstruct.ZoneMomentUnlockStatusUnlock, time.Now().Unix(), orderId, mid, zid) + err = db.GetContext(ctx, &tmpZm, fmt.Sprintf("select * from %s where mid=? and zid=? and moment_id=?", TableVasZoneMomentUnlock), mid, zid, momentId) + } + if err == sql.ErrNoRows { + err = nil + } + if err != nil { + return err + } + if tmpZm.IsUnlock() { + return nil + } + + // 再添加 + sqlStr := "insert into " + TableVasZoneMember + " (mid,zid,moment_id,status,ct,order_id) " + " values (?,?,?,?,?,?)" + args := []any{mid, zid, momentId, dbstruct.ZoneMomentUnlockStatusLock, time.Now().Unix(), orderId} + if tx != nil { + _, err = tx.ExecContext(ctx, sqlStr, args...) + } else { + db := m.getDBVas() + _, err = db.ExecContext(ctx, sqlStr, args...) } if err != nil { return err diff --git a/app/mix/service/logic/vas_zone.go b/app/mix/service/logic/vas_zone.go index 826b47a5..f752696d 100644 --- a/app/mix/service/logic/vas_zone.go +++ b/app/mix/service/logic/vas_zone.go @@ -417,7 +417,7 @@ func (v *Vas) UnlockZoneIronfanshipReachConsume(ctx *gin.Context, tx *sqlx.Tx, m // 获取空间价格 zVas, _ := v.store.GetZoneVasById(ctx, zid) - if zVas != nil { + if zVas == nil { return fmt.Errorf("zone vas not exist, zid: %v", zid) }