Browse Source

update

withdrawal
shenjiachi 2 weeks ago
parent
commit
4110ef2725
5 changed files with 142 additions and 3 deletions
  1. +2
    -2
      consume/egg_recover_consume.go
  2. +128
    -0
      consume/egg_restore_consume.go
  3. +1
    -0
      consume/init.go
  4. +10
    -0
      consume/md/consume_key.go
  5. +1
    -1
      go.mod

+ 2
- 2
consume/egg_recover_consume.go View File

@@ -100,14 +100,14 @@ func handleEggRecoverDataConsume(msgData []byte) error {
var personalDel model.UserVirtualCoinFlow
var teamDel model.UserVirtualCoinFlow
has1, err := session.Table("user_virtual_coin_flow").
Where("transfer_type = ?", int(enum.EggEnergyMaliciousAccountFlashingDeductionPersonal)).Get(&personalDel)
Where("transfer_type = ?", int(enum.EggEnergyMaliciousAccountFlashingDeductionPersonal)).And("uid = ?", msg.Uid).Get(&personalDel)
if err != nil {
session.Rollback()
return err
}

has2, err := session.Table("user_virtual_coin_flow").
Where("transfer_type = ?", int(enum.EggEnergyMaliciousAccountFlashingDeductionTeam)).Get(&teamDel)
Where("transfer_type = ?", int(enum.EggEnergyMaliciousAccountFlashingDeductionTeam)).And("uid = ?", msg.Uid).Get(&teamDel)
if err != nil {
session.Rollback()
return err


+ 128
- 0
consume/egg_restore_consume.go View File

@@ -0,0 +1,128 @@
package consume

import (
"applet/app/cfg"
"applet/app/db"
utils2 "applet/app/utils"
"applet/app/utils/logx"
"applet/consume/md"
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
zhios_order_relate_utils "code.fnuoos.com/EggPlanet/egg_models.git/utils"
"code.fnuoos.com/EggPlanet/egg_system_rules.git"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule"
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/svc"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"encoding/json"
"errors"
"fmt"
"github.com/streadway/amqp"
"strconv"
"time"
)

// EggRestoreDataConsume 恢复返还用户流水
func EggRestoreDataConsume(queue md.MqQueue) {
fmt.Println(">>>>>>>>>>>>EggRestoreDataConsume>>>>>>>>>>>>")
ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {
logx.Error(err)
return
}
defer ch.Release()
//1、将自己绑定到交换机上
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
//2、取出数据进行消费
ch.Qos(1)
delivery := ch.Consume(queue.Name, false)

egg_system_rules.Init(cfg.RedisAddr)
var res amqp.Delivery
var ok bool
for {
res, ok = <-delivery
if ok == true {
err = handleEggRestoreDataConsume(res.Body)
if err != nil {
fmt.Println("EggRestoreDataConsume_ERR:::::", err.Error())
utils2.FilePutContents("EggRestoreDataConsume_ERR", utils2.SerializeStr(map[string]interface{}{
"body": res.Body,
"err": err.Error(),
}))
}
//_ = res.Reject(false)
err = res.Ack(true)
fmt.Println("err ::: ", err)
} else {
panic(errors.New("error getting message"))
}
}
}

func handleEggRestoreDataConsume(msgData []byte) error {
time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒
// 1.解析mq中queue的数据结构体
var msg *md2.EggRoutKeyForRestoreRecordData
err := json.Unmarshal(msgData, &msg)
if err != nil {
return err
}
settingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
setting, err := settingDb.EggEnergyBasicSettingGetOne()
if err != nil {
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() // 释放锁
}

session := db.Db.NewSession()
defer session.Close()
session.Begin()
var personalDel model.UserVirtualCoinFlow
has1, err := session.Table("user_virtual_coin_flow").
Where("transfer_type = ?", int(enum.EggEnergyMaliciousAccountFlashingDeductionRecoverPersonal)).
And("uid = ?", msg.Uid).Get(&personalDel)
if err != nil {
session.Rollback()
return err
}

if has1 {
err = rule.DealUserVirtualCoinMinus(session, md3.DealUserVirtualCoinReq{
Kind: "sub",
Title: enum.EggEnergyMaliciousAccountFlashingDeductionRestorePersonal.String(),
TransferType: int(enum.EggEnergyMaliciousAccountFlashingDeductionRestorePersonal),
CoinId: setting.PersonEggEnergyCoinId,
Uid: msg.Uid,
Amount: utils2.StrToFloat64(personalDel.Amount),
})
if err != nil {
session.Rollback()
return err
}
}

_, err = session.Table("punishment_record").
Where("uid = ?", msg.Uid).Cols("complete").
Update(model.PunishmentRecord{
Complete: 1,
})
if err != nil {
return err
}

session.Commit()
fmt.Println("handleEggRestoreDataConsume_succeed ====>", msg.Uid)
return nil
}

+ 1
- 0
consume/init.go View File

@@ -62,6 +62,7 @@ func initConsumes() {
jobs[consumeMd.EggCanalUserVirtualCoinFlowAggregationConsumeFunName] = EggCanalUserVirtualCoinFlowAggregationConsume // 聚合流水数据
jobs[consumeMd.EggPublishDataFunName] = EggPublishDataConsume // 聚合流水数据
jobs[consumeMd.EggRecoverDataFunName] = EggRecoverDataConsume // 聚合流水数据
jobs[consumeMd.EggRestoreDataFunName] = EggRestoreDataConsume // 聚合流水数据
}

func Run() {


+ 10
- 0
consume/md/consume_key.go View File

@@ -365,6 +365,15 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "EggRecoverDataConsume",
},
{
ExchangeName: "egg.app",
Name: "egg_restore_queue",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "egg_restore",
BindKey: "",
ConsumeFunName: "EggRestoreDataConsume",
},
}

const (
@@ -405,4 +414,5 @@ const (
EggCommentDataFunName = "EggCommentDataConsume"
EggPublishDataFunName = "EggPublishDataConsume"
EggRecoverDataFunName = "EggRecoverDataConsume"
EggRestoreDataFunName = "EggRestoreDataConsume"
)

+ 1
- 1
go.mod View File

@@ -8,7 +8,7 @@ go 1.19

require (
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20250104182559-3f1d190a6c31
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20250104215111-75ab6a7eeb06
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20250104230219-410c5822c551
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
github.com/boombuler/barcode v1.0.1


Loading…
Cancel
Save