Przeglądaj źródła

update

withdrawal
shenjiachi 4 dni temu
rodzic
commit
7f5b2a487c
1 zmienionych plików z 65 dodań i 31 usunięć
  1. +65
    -31
      consume/egg_recover_consume.go

+ 65
- 31
consume/egg_recover_consume.go Wyświetl plik

@@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"github.com/streadway/amqp"
"math"
"strconv"
"time"
)
@@ -76,51 +77,69 @@ func handleEggRecoverDataConsume(msgData []byte) error {
return err
}

//1、分布式锁阻拦
requestIdPrefix1 := fmt.Sprintf(md2.DealUserCoinRequestIdPrefix, setting.PersonEggEnergyCoinId, msg.Uid)
cb1, err := svc.HandleDistributedLock(zhios_order_relate_utils.Int64ToStr(msg.Uid), strconv.Itoa(setting.PersonEggEnergyCoinId), requestIdPrefix1)
if err != nil {
return err
}
if cb1 != nil {
defer cb1() // 释放锁
}
requestIdPrefix2 := fmt.Sprintf(md2.DealUserCoinRequestIdPrefix, setting.TeamEggEnergyCoinId, msg.Uid)
cb2, err := svc.HandleDistributedLock(zhios_order_relate_utils.Int64ToStr(msg.Uid), strconv.Itoa(setting.TeamEggEnergyCoinId), requestIdPrefix2)
if err != nil {
return err
}
if cb2 != nil {
defer cb2() // 释放锁
}

session := db.Db.NewSession()
defer session.Close()
session.Begin()
var personalDel model.UserVirtualCoinFlow
var teamDel model.UserVirtualCoinFlow
has1, err := session.Table("user_virtual_coin_flow").
Where("transfer_type = ?", int(enum.EggEnergyMaliciousAccountFlashingDeductionPersonal)).And("uid = ?", msg.Uid).Get(&personalDel)
var personalDel []model.UserVirtualCoinFlow
var teamDel []model.UserVirtualCoinFlow
err = session.Table("user_virtual_coin_flow").
In("transfer_type", 17, 19, 21).
Where("uid = ?", msg.Uid).
Find(&personalDel)
if err != nil {
session.Rollback()
return err
}
var personalAmount float64
for _, flow := range personalDel {
if flow.Direction == 1 {
personalAmount += utils2.StrToFloat64(flow.Amount)
}
if flow.Direction == 2 {
personalAmount -= utils2.StrToFloat64(flow.Amount)
}
}

has2, err := session.Table("user_virtual_coin_flow").
Where("transfer_type = ?", int(enum.EggEnergyMaliciousAccountFlashingDeductionTeam)).And("uid = ?", msg.Uid).Get(&teamDel)
err = session.Table("user_virtual_coin_flow").
In("transfer_type", 18, 20).
Where("uid = ?", msg.Uid).
Find(&teamDel)
if err != nil {
session.Rollback()
return err
}
var teamAmount float64
for _, flow := range teamDel {
if flow.Direction == 1 {
teamAmount += utils2.StrToFloat64(flow.Amount)
}
if flow.Direction == 2 {
teamAmount -= utils2.StrToFloat64(flow.Amount)
}
}

if has1 {
if personalAmount != 0 {
requestIdPrefix1 := fmt.Sprintf(md2.DealUserCoinRequestIdPrefix, setting.PersonEggEnergyCoinId, msg.Uid)
cb1, err := svc.HandleDistributedLock(zhios_order_relate_utils.Int64ToStr(msg.Uid), strconv.Itoa(setting.PersonEggEnergyCoinId), requestIdPrefix1)
if err != nil {
return err
}
if cb1 != nil {
defer cb1() // 释放锁
}
var kind string
if personalAmount > 0 {
kind = "sub"
} else {
kind = "add"
}
err = rule.DealUserVirtualCoinMinus(session, md3.DealUserVirtualCoinReq{
Kind: "add",
Kind: kind,
Title: enum.EggEnergyMaliciousAccountFlashingDeductionRecoverPersonal.String(),
TransferType: int(enum.EggEnergyMaliciousAccountFlashingDeductionRecoverPersonal),
CoinId: setting.PersonEggEnergyCoinId,
Uid: msg.Uid,
Amount: utils2.StrToFloat64(personalDel.Amount),
Amount: math.Abs(personalAmount - 0),
})
if err != nil {
session.Rollback()
@@ -128,14 +147,29 @@ func handleEggRecoverDataConsume(msgData []byte) error {
}
}

if has2 {
if teamAmount != 0 {
//1、分布式锁阻拦
requestIdPrefix2 := fmt.Sprintf(md2.DealUserCoinRequestIdPrefix, setting.TeamEggEnergyCoinId, msg.Uid)
cb2, err := svc.HandleDistributedLock(zhios_order_relate_utils.Int64ToStr(msg.Uid), strconv.Itoa(setting.TeamEggEnergyCoinId), requestIdPrefix2)
if err != nil {
return err
}
if cb2 != nil {
defer cb2() // 释放锁
}
var kind string
if teamAmount > 0 {
kind = "sub"
} else {
kind = "add"
}
err = rule.DealUserVirtualCoinMinus(session, md3.DealUserVirtualCoinReq{
Kind: "add",
Kind: kind,
Title: enum.EggEnergyMaliciousAccountFlashingDeductionRecoverTeam.String(),
TransferType: int(enum.EggEnergyMaliciousAccountFlashingDeductionRecoverTeam),
CoinId: setting.TeamEggEnergyCoinId,
Uid: msg.Uid,
Amount: utils2.StrToFloat64(teamDel.Amount),
Amount: math.Abs(teamAmount - 0),
})
if err != nil {
session.Rollback()
@@ -146,7 +180,7 @@ func handleEggRecoverDataConsume(msgData []byte) error {
_, err = session.Table("punishment_record").
Where("uid = ?", msg.Uid).Cols("complete").
Update(model.PunishmentRecord{
Complete: 0,
Complete: 1,
})
if err != nil {
return err


Ładowanie…
Anuluj
Zapisz