This commit is contained in:
lwl0608 2024-04-19 23:33:00 +08:00
parent 23b4d166ec
commit 8fca291eb0
2 changed files with 25 additions and 5 deletions

View File

@ -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

View File

@ -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)
}