rollback ironfanship

This commit is contained in:
lwl0608 2024-04-29 15:56:42 +08:00
parent c470a8e77f
commit a8d3a45b71
2 changed files with 39 additions and 1 deletions

View File

@ -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=?"

View File

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