From a8d3a45b7147b95e2d28f701b578530ab32bdae5 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Mon, 29 Apr 2024 15:56:42 +0800 Subject: [PATCH] rollback ironfanship --- app/mix/dao/mysql_zone.go | 19 ++++++++++++++++++- app/mix/service/logic/vas_zone.go | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/app/mix/dao/mysql_zone.go b/app/mix/dao/mysql_zone.go index fe35c592..fba3e3ed 100644 --- a/app/mix/dao/mysql_zone.go +++ b/app/mix/dao/mysql_zone.go @@ -249,7 +249,24 @@ func (m *Mysql) UnlockZoneIronfanship(ctx *gin.Context, tx *sqlx.Tx, mid, zid, u return err } -// 解锁空间铁粉 +// 铁粉退款 +func (m *Mysql) RefundZoneIronfanship(ctx *gin.Context, tx *sqlx.Tx, mid, zid int64) error { + var err error + sqlStr := "update " + TableVasZoneUnlock + " set ironfanship_ct=?, ironfanship_until=?, ironfanship_unlock_type=? where mid=? and zid=?" + args := []any{0, 0, dbstruct.ZoneUnlockTypeRefund, mid, zid} + if tx != nil { + _, err = tx.ExecContext(ctx, sqlStr, args...) + } else { + db := m.getDBVas() + _, err = db.ExecContext(ctx, sqlStr, args...) + } + if err != nil { + return err + } + return err +} + +// 解锁空间超粉 func (m *Mysql) UnlockZoneSuperfanship(ctx *gin.Context, tx *sqlx.Tx, mid, zid, until int64, orderId string, unlockType int32) error { var err error sqlStr := "update " + TableVasZoneUnlock + " set superfanship_ct=?, superfanship_until=?, superfanship_order_id=?, superfanship_unlock_type=? where mid=? and zid=?" diff --git a/app/mix/service/logic/vas_zone.go b/app/mix/service/logic/vas_zone.go index 3295783f..c07b7672 100644 --- a/app/mix/service/logic/vas_zone.go +++ b/app/mix/service/logic/vas_zone.go @@ -131,6 +131,27 @@ func (v *Vas) RollbackZoneConsume(ctx *gin.Context, tx *sqlx.Tx, orderId string) logger.Error("CreateZoneConsumeHis fail, zch, err: %v", util.ToJson(zch), err) return err } + + // 是否不够解锁铁粉 + zu, _ := v.CheckZoneUnlockExist(ctx, tx, mid, zid) + if zu == nil { + logger.Warn("CheckZoneUnlockExist fail, mid: %v, zid: %v", mid, zid) + return nil + } + zv, _ := v.store.GetZoneVasById(ctx, zid) + if zv == nil { + logger.Warn("GetZoneVasById fail, mid: %v, zid: %v", mid, zid) + return nil + } + if zu.IsUnlockIronfanship() && zu.GetConsume() < zv.IronfanshipPrice { + // 回滚超粉 + err = v.store.RefundZoneIronfanship(ctx, tx, mid, zid) + if err != nil { + logger.Error("RefundZoneIronfanship fail, mid: %v, zid: %v, err: %v", mid, zid, err) + return err + } + } + return nil }