From 561afa8755d74950de620d3641b1bbbd7830dde1 Mon Sep 17 00:00:00 2001 From: lwl0608 Date: Tue, 23 Apr 2024 17:29:27 +0800 Subject: [PATCH] fix tx --- app/mix/service/logic/vas.go | 66 +++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index 4e855c43..cd115d1b 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -762,40 +762,44 @@ func (v *Vas) OneStepUnlockContact(ctx *gin.Context, req *vasproto.OneStepUnlock return } - // 扣金币 - err = v.store.DecCoins(ctx, tx, req.Mid, coinPrice) - if err != nil { - logger.Error("DecCoins fail, mid: %v, coinPrice: %v, err: %v", req.Mid, coinPrice, err) - return - } + if coinPrice > 0 { + // 扣金币 + err = v.store.DecCoins(ctx, tx, req.Mid, coinPrice) + if err != nil { + logger.Error("DecCoins fail, mid: %v, coinPrice: %v, err: %v", req.Mid, coinPrice, err) + return + } - // 计算收入 - var totalDias = coinPrice - // h5解锁情况 - if originalContactProductId == dbstruct.ProductIdH5ContactWechat { - totalDias = uVasInfo.GetWechatCoinPrice() - } - incomeList, err := v.calcAndUpdateIncome(ctx, tx, uid, mid, req.Did, orderId, contactProductId, totalDias, dbstruct.CHSTypeIncomeContact) - if err != nil { - logger.Error("calcAndUpdateIncome fail, coinOrder: %v, err: %v", util.ToJson(coinOrder), err) - return - } + // 计算收入 + var totalDias = coinPrice + // h5解锁情况 + if originalContactProductId == dbstruct.ProductIdH5ContactWechat { + totalDias = uVasInfo.GetWechatCoinPrice() + } + incomeList, err := v.calcAndUpdateIncome(ctx, tx, uid, mid, req.Did, orderId, contactProductId, totalDias, dbstruct.CHSTypeIncomeContact) + if err != nil { + logger.Error("calcAndUpdateIncome fail, coinOrder: %v, err: %v", util.ToJson(coinOrder), err) + return + } - // 把分成信息写到金币订单ext里面 - orderExt := map[string]any{ - "total_dias": totalDias, - "income_list": incomeList, - } - err = v.store.UpdateCoinOrderExt(ctx, tx, orderId, util.ToJson(orderExt)) - if err != nil { - logger.Error("UpdateCoinOrderExt fail, order_id: %v, ext: %v, err: %v", orderId, util.ToJson(orderExt), err) - return - } + // 把分成信息写到金币订单ext里面 + orderExt := map[string]any{ + "total_dias": totalDias, + "income_list": incomeList, + } + err = v.store.UpdateCoinOrderExt(ctx, tx, orderId, util.ToJson(orderExt)) + if err != nil { + logger.Error("UpdateCoinOrderExt fail, order_id: %v, ext: %v, err: %v", orderId, util.ToJson(orderExt), err) + return + } - // 增加空间消费 - _err := v.IncZoneConsume(ctx, tx, 0, mid, uid, coinPrice, orderId, contactProductId) - if _err != nil { - logger.Error("IncZoneConsume fail, mid: %v, streamerMid: %v, orderId: %v, err: %v", mid, uid, orderId, err) + // 增加空间消费 + if coinPrice > 0 { + _err := v.IncZoneConsume(ctx, tx, 0, mid, uid, coinPrice, orderId, contactProductId) + if _err != nil { + logger.Error("IncZoneConsume fail, mid: %v, streamerMid: %v, orderId: %v, err: %v", mid, uid, orderId, err) + } + } } return }