|
@@ -32,7 +32,7 @@ func OneCirclesActivityCoinAutoExchangeGreenEnergyConsume(queue md.MqQueue) { |
|
|
//1、将自己绑定到交换机上 |
|
|
//1、将自己绑定到交换机上 |
|
|
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey) |
|
|
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey) |
|
|
//2、取出数据进行消费 |
|
|
//2、取出数据进行消费 |
|
|
ch.Qos(40) |
|
|
|
|
|
|
|
|
ch.Qos(50) |
|
|
delivery := ch.Consume(queue.Name, false) |
|
|
delivery := ch.Consume(queue.Name, false) |
|
|
|
|
|
|
|
|
one_circles.Init(cfg.RedisAddr) |
|
|
one_circles.Init(cfg.RedisAddr) |
|
@@ -61,7 +61,7 @@ func OneCirclesActivityCoinAutoExchangeGreenEnergyConsume(queue md.MqQueue) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func handleOneCirclesActivityCoinAutoExchangeGreenEnergyConsume(msgData []byte) error { |
|
|
func handleOneCirclesActivityCoinAutoExchangeGreenEnergyConsume(msgData []byte) error { |
|
|
time.Sleep(time.Duration(100) * time.Microsecond) //休眠0.1毫秒 |
|
|
|
|
|
|
|
|
time.Sleep(time.Duration(10) * time.Microsecond) //休眠0.1毫秒 |
|
|
//1、解析mq中queue的数据结构体 |
|
|
//1、解析mq中queue的数据结构体 |
|
|
var msg *md2.OneCirclesStructForAutoExchangeGreenEnergy |
|
|
var msg *md2.OneCirclesStructForAutoExchangeGreenEnergy |
|
|
err := json.Unmarshal(msgData, &msg) |
|
|
err := json.Unmarshal(msgData, &msg) |
|
@@ -77,16 +77,6 @@ func handleOneCirclesActivityCoinAutoExchangeGreenEnergyConsume(msgData []byte) |
|
|
if cb != nil { |
|
|
if cb != nil { |
|
|
defer cb() // 释放锁 |
|
|
defer cb() // 释放锁 |
|
|
} |
|
|
} |
|
|
//oneCirclesGreenEnergyBasicSetting, err := db2.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ |
|
|
|
|
|
// "key": "is_open", |
|
|
|
|
|
// "value": 1, |
|
|
|
|
|
//}) |
|
|
|
|
|
//if err != nil { |
|
|
|
|
|
// return err |
|
|
|
|
|
//} |
|
|
|
|
|
//if oneCirclesGreenEnergyBasicSetting == nil { |
|
|
|
|
|
// return nil |
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
|
|
session := engine.NewSession() |
|
|
session := engine.NewSession() |
|
|
defer func() { |
|
|
defer func() { |
|
@@ -96,30 +86,8 @@ func handleOneCirclesActivityCoinAutoExchangeGreenEnergyConsume(msgData []byte) |
|
|
} |
|
|
} |
|
|
}() |
|
|
}() |
|
|
session.Begin() |
|
|
session.Begin() |
|
|
//3.1计算涨价公式 |
|
|
|
|
|
err1, values, _, afterPriceValue := one_circles.NewCalcPriceIncreaseFormula(msg.AutoExchangeNumsAmount, oneCirclesGreenEnergyBasicSetting) |
|
|
|
|
|
if err1 != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
return err1 |
|
|
|
|
|
} |
|
|
|
|
|
//3.2给相应的用户加上个人的绿色积分(可用数量) |
|
|
|
|
|
err = rule.DealUserCoin(session, md2.DealUserCoinReq{ |
|
|
|
|
|
Kind: "add", |
|
|
|
|
|
Mid: msg.MasterId, |
|
|
|
|
|
Title: md2.OneCirclesPersonalActiveCoinExchangeGreenEnergy, |
|
|
|
|
|
TransferType: md2.OneCirclesPersonalActiveCoinExchangeGreenEnergyForUserVirtualCoinFlow, |
|
|
|
|
|
OrdId: "", |
|
|
|
|
|
CoinId: oneCirclesGreenEnergyBasicSetting.PersonGreenEnergyCoinId, |
|
|
|
|
|
Uid: msg.Uid, |
|
|
|
|
|
Amount: utils.StrToFloat64(values), |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
fmt.Println("err:::::33333", err.Error()) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//4.1给相应的用户减去个人活跃积分 |
|
|
|
|
|
|
|
|
//3给相应的用户减去个人活跃积分 |
|
|
err = rule.DealUserCoin(session, md2.DealUserCoinReq{ |
|
|
err = rule.DealUserCoin(session, md2.DealUserCoinReq{ |
|
|
Kind: "sub", |
|
|
Kind: "sub", |
|
|
Mid: msg.MasterId, |
|
|
Mid: msg.MasterId, |
|
@@ -135,21 +103,45 @@ func handleOneCirclesActivityCoinAutoExchangeGreenEnergyConsume(msgData []byte) |
|
|
fmt.Println("err:::::33333", err.Error()) |
|
|
fmt.Println("err:::::33333", err.Error()) |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
//4.2减少“原始数量”中的绿色能量 |
|
|
|
|
|
err = one_circles.DealAvailableGreenEnergyCoin(session, int(enum.PersonalActivePointRedemption), utils.StrToFloat64(values), utils.StrToFloat64(msg.AutoExchangeNumsAmount), enum.PersonalActivePointRedemption.String(), oneCirclesGreenEnergyBasicSetting, afterPriceValue) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//4.1计算涨价公式 |
|
|
|
|
|
err1, values, _, afterPriceValue := one_circles.NewCalcPriceIncreaseFormula(msg.AutoExchangeNumsAmount, oneCirclesGreenEnergyBasicSetting) |
|
|
|
|
|
if err1 != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
return err1 |
|
|
|
|
|
} |
|
|
|
|
|
//4.2给相应的用户加上个人的绿色积分(可用数量) |
|
|
|
|
|
err = rule.DealUserCoin(session, md2.DealUserCoinReq{ |
|
|
|
|
|
Kind: "add", |
|
|
|
|
|
Mid: msg.MasterId, |
|
|
|
|
|
Title: md2.OneCirclesPersonalActiveCoinExchangeGreenEnergy, |
|
|
|
|
|
TransferType: md2.OneCirclesPersonalActiveCoinExchangeGreenEnergyForUserVirtualCoinFlow, |
|
|
|
|
|
OrdId: "", |
|
|
|
|
|
CoinId: oneCirclesGreenEnergyBasicSetting.PersonGreenEnergyCoinId, |
|
|
|
|
|
Uid: msg.Uid, |
|
|
|
|
|
Amount: utils.StrToFloat64(values), |
|
|
|
|
|
}) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
_ = session.Rollback() |
|
|
_ = session.Rollback() |
|
|
fmt.Println("err:::::44444", err.Error()) |
|
|
fmt.Println("err:::::44444", err.Error()) |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//5、修改 one_circles_green_energy_basic_setting 的 now_price |
|
|
|
|
|
_, err = db2.OneCirclesGreenEnergyBasicSettingUpdate(session, oneCirclesGreenEnergyBasicSetting.Id, oneCirclesGreenEnergyBasicSetting) |
|
|
|
|
|
|
|
|
//5减少“原始数量”中的绿色能量 |
|
|
|
|
|
err = one_circles.DealAvailableGreenEnergyCoin(session, int(enum.PersonalActivePointRedemption), utils.StrToFloat64(values), utils.StrToFloat64(msg.AutoExchangeNumsAmount), enum.PersonalActivePointRedemption.String(), oneCirclesGreenEnergyBasicSetting, afterPriceValue) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
_ = session.Rollback() |
|
|
_ = session.Rollback() |
|
|
fmt.Println("err:::::77777", err.Error()) |
|
|
|
|
|
|
|
|
fmt.Println("err:::::555555", err.Error()) |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//6、修改 one_circles_green_energy_basic_setting 的 now_price |
|
|
|
|
|
db2.OneCirclesGreenEnergyBasicSettingUpdate(session, oneCirclesGreenEnergyBasicSetting.Id, oneCirclesGreenEnergyBasicSetting) |
|
|
|
|
|
//if err != nil { |
|
|
|
|
|
// _ = session.Rollback() |
|
|
|
|
|
// fmt.Println("err:::::666666", err.Error()) |
|
|
|
|
|
// return err |
|
|
|
|
|
//} |
|
|
err = session.Commit() |
|
|
err = session.Commit() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
_ = session.Rollback() |
|
|
_ = session.Rollback() |
|
|