@@ -80,12 +80,15 @@ func initConsumes() { | |||||
//////////////////////////////////////// oneCircles ///////////////////////////////////////////////////// | //////////////////////////////////////// oneCircles ///////////////////////////////////////////////////// | ||||
//jobs[consumeMd.OneCirclesSignInGreenEnergyFunName] = OneCirclesSignInGreenEnergyConsume | //jobs[consumeMd.OneCirclesSignInGreenEnergyFunName] = OneCirclesSignInGreenEnergyConsume | ||||
//jobs[consumeMd.OneCirclesStartLevelDividendFunName] = OneCirclesStartLevelDividendConsume | |||||
jobs[consumeMd.OneCirclesStartLevelDividendFunName] = OneCirclesStartLevelDividendConsume | |||||
jobs[consumeMd.OneCirclesActivityCoinAutoExchangeGreenEnergyFunName] = OneCirclesActivityCoinAutoExchangeGreenEnergyConsume | |||||
jobs[consumeMd.OneCirclesActivityCoinAutoExchangeGreenEnergyForTeamFunName] = OneCirclesActivityCoinAutoExchangeGreenEnergyForTeamConsume | |||||
jobs[consumeMd.OneCirclesSettlementPublicGiveActivityCoinFunName] = OneCirclesSettlementPublicGiveActivityCoinConsume | |||||
//jobs[consumeMd.OneCirclesSignInCopyGreenEnergyFunName] = OneCirclesSignInCopyGreenEnergyConsume | //jobs[consumeMd.OneCirclesSignInCopyGreenEnergyFunName] = OneCirclesSignInCopyGreenEnergyConsume | ||||
//////////////////////////////////////// withdraw ///////////////////////////////////////////////////// | //////////////////////////////////////// withdraw ///////////////////////////////////////////////////// | ||||
jobs[consumeMd.WithdrawConsumeFunName] = WithdrawConsume | |||||
jobs[consumeMd.FlexibleEmploymentWithdrawForGongMaoConsumeFunName] = FlexibleEmploymentWithdrawForGongMaoConsume | |||||
//jobs[consumeMd.WithdrawConsumeFunName] = WithdrawConsume | |||||
//jobs[consumeMd.FlexibleEmploymentWithdrawForGongMaoConsumeFunName] = FlexibleEmploymentWithdrawForGongMaoConsume | |||||
//jobs[consumeMd.FlexibleEmploymentWithdrawForPupiaoConsumeFunName] = FlexibleEmploymentWithdrawForPupiaoConsume | //jobs[consumeMd.FlexibleEmploymentWithdrawForPupiaoConsumeFunName] = FlexibleEmploymentWithdrawForPupiaoConsume | ||||
//jobs[consumeMd.ZhiosMallGreenCoinConsumeFunName] = ZhiosMallGreenCoinConsume //绿色双链积分 | //jobs[consumeMd.ZhiosMallGreenCoinConsumeFunName] = ZhiosMallGreenCoinConsume //绿色双链积分 | ||||
@@ -425,6 +425,33 @@ var RabbitMqQueueKeyList = []*MqQueue{ | |||||
BindKey: "", | BindKey: "", | ||||
ConsumeFunName: "OneCirclesStartLevelDividendConsume", | ConsumeFunName: "OneCirclesStartLevelDividendConsume", | ||||
}, | }, | ||||
{ | |||||
ExchangeName: "one.circles", | |||||
Name: "one_circles_auto_exchange_green_energy_to_person", | |||||
Type: TopicQueueType, | |||||
IsPersistent: false, | |||||
RoutKey: "auto_exchange_green_energy_to_person", | |||||
BindKey: "", | |||||
ConsumeFunName: "OneCirclesActivityCoinAutoExchangeGreenEnergyConsume", | |||||
}, | |||||
{ | |||||
ExchangeName: "one.circles", | |||||
Name: "one_circles_auto_exchange_green_energy_to_team", | |||||
Type: TopicQueueType, | |||||
IsPersistent: false, | |||||
RoutKey: "auto_exchange_green_energy_to_team", | |||||
BindKey: "", | |||||
ConsumeFunName: "OneCirclesActivityCoinAutoExchangeGreenEnergyForTeamConsume", | |||||
}, | |||||
{ | |||||
ExchangeName: "one.circles", | |||||
Name: "one_circles_settlement_public_give_activity_coin", | |||||
Type: TopicQueueType, | |||||
IsPersistent: false, | |||||
RoutKey: "settlement_public_give_activity_coin", | |||||
BindKey: "", | |||||
ConsumeFunName: "OneCirclesSettlementPublicGiveActivityCoinConsume", | |||||
}, | |||||
{ | { | ||||
ExchangeName: "one.circles", | ExchangeName: "one.circles", | ||||
Name: "one_circles_sign_in_green_energy_copy", | Name: "one_circles_sign_in_green_energy_copy", | ||||
@@ -464,55 +491,58 @@ var RabbitMqQueueKeyList = []*MqQueue{ | |||||
} | } | ||||
const ( | const ( | ||||
ZhiosUserRelateFunName = "ZhiosUserRelate" | |||||
ZhiosIntegralProxyRechargeFunName = "ZhiosIntegralProxyRecharge" | |||||
ZhiosMallGreenCoinConsumeFunName = "ZhiosMallGreenCoinConsume" | |||||
ZhiosOneCirclesCoinConsumeFunName = "ZhiosOneCirclesCoinConsume" | |||||
ZhiosUserUpLvFunName = "ZhiosUserUpLv" | |||||
CanalGuideOrderByUserUpLvConsume = "CanalGuideOrderByUserUpLvConsume" | |||||
ZhiosOrderFreeFunName = "ZhiosOrderFree" | |||||
ZhiosOrderSettleTotalFunName = "ZhiosOrderSettleTotal" | |||||
ZhiosOrderTotalFunName = "ZhiosOrderTotal" | |||||
ZhiosOrderTotalSecondFunName = "ZhiosOrderTotalSecond" | |||||
ZhiosOrderHjyFunName = "ZhiosOrderHjy" | |||||
ZhiosOrderBuckleFunName = "ZhiosOrderBuckle" | |||||
ZhiosSupplierAfterOrderFunName = "ZhiosSupplierAfterOrder" | |||||
CanalOrderConsumeFunName = "CanalOrderConsume" | |||||
CanalGuideOrderConsumeFunName = "CanalGuideOrderConsume" | |||||
ZhiOsUserVisitIpAddressConsumeFunName = "ZhiOsUserVisitIpAddressConsume" | |||||
DouShenUserRegisterConsumeForOfficialFunName = "DouShenUserRegisterConsumeForOfficial" | |||||
DouShenUserRegisterConsumeForOperationCenterFunName = "DouShenUserRegisterConsumeForOperationCenter" | |||||
DouShenUserRegisterConsumeForMyRecommenderFunName = "DouShenUserRegisterConsumeForMyRecommender" | |||||
DouShenUserRegisterConsumeForMyFansFunName = "DouShenUserRegisterConsumeForMyFans" | |||||
DouShenUserRegisterConsumeForUserRegisterUpLvFunName = "DouShenUserRegisterConsumeForUserRegisterUpLv" | |||||
ZhiosFastReturnOrderPayFunName = "ZhiosFastReturnOrderPay" | |||||
ZhiosFastReturnOrderSuccessFunName = "ZhiosFastReturnOrderSuccess" | |||||
ZhiosFastReturnOrderRefundFunName = "ZhiosFastReturnOrderRefund" | |||||
ZhiosFastReturnOrderRefundSecondFunName = "ZhiosFastReturnOrderRefundSecond" | |||||
CanalMallOrdForYouMiShangFunName = "CanalMallOrdForYouMiShang" | |||||
YoumishangExchangeStoreFunName = "YoumishangExchangeStore" | |||||
ZhiosRechargeOrderFailFunName = "ZhiosRechargeOrderFail" | |||||
ZhiosRechargeOrderFailDevFunName = "ZhiosRechargeOrderFailDev" | |||||
ZhiosCapitalPoolOrderTotalFunName = "ZhiosCapitalPoolOrderTotal" | |||||
ZhiosExpressOrderFail = "zhiosExpressOrderFail" | |||||
ZhiosWithdrawReward = "zhiosWithdrawReward" | |||||
ZhiosTikTokUpdateFunName = "ZhiosTikTokUpdate" | |||||
ZhiosTikTokAllUpdateFunName = "ZhiosTikTokAllUpdate" | |||||
CloudIssuanceAsyncMLoginFunName = "CloudIssuanceAsyncMLoginConsume" | |||||
CloudIssuanceMsgCallBackFunName = "CloudIssuanceMsgCallBackConsume" | |||||
ZhiosAcquisitionConditionFunName = "ZhiosAcquisitionCondition" | |||||
ZhiosValidUserFunName = "ZhiosValidUser" | |||||
ZhiosAppreciationFunName = "ZhiosAppreciation" | |||||
ZhiosAppreciationDevFunName = "ZhiosAppreciationDev" | |||||
ZhiosGuideStoreOrderFunName = "ZhiosGuideStoreOrder" | |||||
ZhiosAcquisitionConditionDevFunName = "ZhiosAcquisitionConditionDev" | |||||
SupplyCloudChainFenxiaoNewChangeFunName = "SupplyCloudChainFenxiaoNewChangeConsume" | |||||
MallAddSupplyGoodsFunName = "MallAddSupplyGoodsConsume" | |||||
CanalUserVirtualCcoinFlowFunName = "CanalUserVirtualCoinFlowConsume" | |||||
OneCirclesSignInGreenEnergyFunName = "OneCirclesSignInGreenEnergyConsume" | |||||
OneCirclesStartLevelDividendFunName = "OneCirclesStartLevelDividendConsume" | |||||
OneCirclesSignInCopyGreenEnergyFunName = "OneCirclesSignInCopyGreenEnergyConsume" | |||||
WithdrawConsumeFunName = "WithdrawConsume" | |||||
FlexibleEmploymentWithdrawForGongMaoConsumeFunName = "FlexibleEmploymentWithdrawForGongMaoConsume" | |||||
FlexibleEmploymentWithdrawForPupiaoConsumeFunName = "FlexibleEmploymentWithdrawForPupiaoConsume" | |||||
ZhiosUserRelateFunName = "ZhiosUserRelate" | |||||
ZhiosIntegralProxyRechargeFunName = "ZhiosIntegralProxyRecharge" | |||||
ZhiosMallGreenCoinConsumeFunName = "ZhiosMallGreenCoinConsume" | |||||
ZhiosOneCirclesCoinConsumeFunName = "ZhiosOneCirclesCoinConsume" | |||||
ZhiosUserUpLvFunName = "ZhiosUserUpLv" | |||||
CanalGuideOrderByUserUpLvConsume = "CanalGuideOrderByUserUpLvConsume" | |||||
ZhiosOrderFreeFunName = "ZhiosOrderFree" | |||||
ZhiosOrderSettleTotalFunName = "ZhiosOrderSettleTotal" | |||||
ZhiosOrderTotalFunName = "ZhiosOrderTotal" | |||||
ZhiosOrderTotalSecondFunName = "ZhiosOrderTotalSecond" | |||||
ZhiosOrderHjyFunName = "ZhiosOrderHjy" | |||||
ZhiosOrderBuckleFunName = "ZhiosOrderBuckle" | |||||
ZhiosSupplierAfterOrderFunName = "ZhiosSupplierAfterOrder" | |||||
CanalOrderConsumeFunName = "CanalOrderConsume" | |||||
CanalGuideOrderConsumeFunName = "CanalGuideOrderConsume" | |||||
ZhiOsUserVisitIpAddressConsumeFunName = "ZhiOsUserVisitIpAddressConsume" | |||||
DouShenUserRegisterConsumeForOfficialFunName = "DouShenUserRegisterConsumeForOfficial" | |||||
DouShenUserRegisterConsumeForOperationCenterFunName = "DouShenUserRegisterConsumeForOperationCenter" | |||||
DouShenUserRegisterConsumeForMyRecommenderFunName = "DouShenUserRegisterConsumeForMyRecommender" | |||||
DouShenUserRegisterConsumeForMyFansFunName = "DouShenUserRegisterConsumeForMyFans" | |||||
DouShenUserRegisterConsumeForUserRegisterUpLvFunName = "DouShenUserRegisterConsumeForUserRegisterUpLv" | |||||
ZhiosFastReturnOrderPayFunName = "ZhiosFastReturnOrderPay" | |||||
ZhiosFastReturnOrderSuccessFunName = "ZhiosFastReturnOrderSuccess" | |||||
ZhiosFastReturnOrderRefundFunName = "ZhiosFastReturnOrderRefund" | |||||
ZhiosFastReturnOrderRefundSecondFunName = "ZhiosFastReturnOrderRefundSecond" | |||||
CanalMallOrdForYouMiShangFunName = "CanalMallOrdForYouMiShang" | |||||
YoumishangExchangeStoreFunName = "YoumishangExchangeStore" | |||||
ZhiosRechargeOrderFailFunName = "ZhiosRechargeOrderFail" | |||||
ZhiosRechargeOrderFailDevFunName = "ZhiosRechargeOrderFailDev" | |||||
ZhiosCapitalPoolOrderTotalFunName = "ZhiosCapitalPoolOrderTotal" | |||||
ZhiosExpressOrderFail = "zhiosExpressOrderFail" | |||||
ZhiosWithdrawReward = "zhiosWithdrawReward" | |||||
ZhiosTikTokUpdateFunName = "ZhiosTikTokUpdate" | |||||
ZhiosTikTokAllUpdateFunName = "ZhiosTikTokAllUpdate" | |||||
CloudIssuanceAsyncMLoginFunName = "CloudIssuanceAsyncMLoginConsume" | |||||
CloudIssuanceMsgCallBackFunName = "CloudIssuanceMsgCallBackConsume" | |||||
ZhiosAcquisitionConditionFunName = "ZhiosAcquisitionCondition" | |||||
ZhiosValidUserFunName = "ZhiosValidUser" | |||||
ZhiosAppreciationFunName = "ZhiosAppreciation" | |||||
ZhiosAppreciationDevFunName = "ZhiosAppreciationDev" | |||||
ZhiosGuideStoreOrderFunName = "ZhiosGuideStoreOrder" | |||||
ZhiosAcquisitionConditionDevFunName = "ZhiosAcquisitionConditionDev" | |||||
SupplyCloudChainFenxiaoNewChangeFunName = "SupplyCloudChainFenxiaoNewChangeConsume" | |||||
MallAddSupplyGoodsFunName = "MallAddSupplyGoodsConsume" | |||||
CanalUserVirtualCcoinFlowFunName = "CanalUserVirtualCoinFlowConsume" | |||||
OneCirclesSignInGreenEnergyFunName = "OneCirclesSignInGreenEnergyConsume" | |||||
OneCirclesStartLevelDividendFunName = "OneCirclesStartLevelDividendConsume" | |||||
OneCirclesSignInCopyGreenEnergyFunName = "OneCirclesSignInCopyGreenEnergyConsume" | |||||
OneCirclesActivityCoinAutoExchangeGreenEnergyFunName = "OneCirclesActivityCoinAutoExchangeGreenEnergyConsume" | |||||
OneCirclesActivityCoinAutoExchangeGreenEnergyForTeamFunName = "OneCirclesActivityCoinAutoExchangeGreenEnergyForTeamConsume" | |||||
OneCirclesSettlementPublicGiveActivityCoinFunName = "OneCirclesSettlementPublicGiveActivityCoinConsume" | |||||
WithdrawConsumeFunName = "WithdrawConsume" | |||||
FlexibleEmploymentWithdrawForGongMaoConsumeFunName = "FlexibleEmploymentWithdrawForGongMaoConsume" | |||||
FlexibleEmploymentWithdrawForPupiaoConsumeFunName = "FlexibleEmploymentWithdrawForPupiaoConsume" | |||||
) | ) |
@@ -0,0 +1,150 @@ | |||||
package consume | |||||
import ( | |||||
"applet/app/cfg" | |||||
"applet/app/db" | |||||
utils2 "applet/app/utils" | |||||
"applet/app/utils/logx" | |||||
"applet/consume/md" | |||||
"applet/mall/utils" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | |||||
db2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db" | |||||
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/enum" | |||||
"encoding/json" | |||||
"errors" | |||||
"fmt" | |||||
"github.com/streadway/amqp" | |||||
"time" | |||||
) | |||||
func OneCirclesActivityCoinAutoExchangeGreenEnergyConsume(queue md.MqQueue) { | |||||
fmt.Println(">>>>>>>>>>>>OneCirclesActivityCoinAutoExchangeGreenEnergyConsume>>>>>>>>>>>>") | |||||
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) | |||||
one_circles.Init(cfg.RedisAddr) | |||||
var res amqp.Delivery | |||||
var ok bool | |||||
for { | |||||
res, ok = <-delivery | |||||
if ok == true { | |||||
err = handleOneCirclesActivityCoinAutoExchangeGreenEnergyConsume(res.Body) | |||||
if err != nil { | |||||
fmt.Println("OneCirclesActivityCoinAutoExchangeGreenEnergyConsume_ERR:::::", err.Error()) | |||||
utils2.FilePutContents("OneCirclesActivityCoinAutoExchangeGreenEnergyConsume_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")) | |||||
} | |||||
} | |||||
fmt.Println("get msg done") | |||||
} | |||||
func handleOneCirclesActivityCoinAutoExchangeGreenEnergyConsume(msgData []byte) error { | |||||
time.Sleep(time.Duration(2) * time.Millisecond) //休眠2毫秒 | |||||
//1、解析mq中queue的数据结构体 | |||||
var msg *md2.OneCirclesStructForAutoExchangeGreenEnergy | |||||
err := json.Unmarshal(msgData, &msg) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
engine := db.DBs[msg.MasterId] | |||||
//2、查找 `one_circles_green_energy_basic_setting` 基础设置 | |||||
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() | |||||
defer func() { | |||||
session.Close() | |||||
if err := recover(); err != nil { | |||||
_ = logx.Error(err) | |||||
} | |||||
}() | |||||
session.Begin() | |||||
//3.1计算涨价公式 | |||||
err1, values, _, afterPriceValue := one_circles.NewCalcPriceIncreaseFormula(msg.AutoExchangeNumsAmount, oneCirclesGreenEnergyBasicSetting) | |||||
if err1 != nil { | |||||
_ = session.Rollback() | |||||
return err1 | |||||
} | |||||
//3.2给相应的用户加上个人的绿色积分(可用数量) | |||||
err = one_circles.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给相应的用户减去个人活跃积分 | |||||
err = one_circles.DealUserCoin(session, md2.DealUserCoinReq{ | |||||
Kind: "sub", | |||||
Mid: msg.MasterId, | |||||
Title: md2.OneCirclesPersonalActiveCoinExchangeToBeGreenEnergy, | |||||
TransferType: md2.OneCirclesPersonalActiveCoinExchangeToBeGreenEnergyForUserVirtualCoinFlow, | |||||
OrdId: "", | |||||
CoinId: msg.CoinId, | |||||
Uid: msg.Uid, | |||||
Amount: utils.StrToFloat64(msg.Amount), | |||||
}) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::33333", err.Error()) | |||||
return err | |||||
} | |||||
//4.2减少“原始数量”中的绿色能量 | |||||
err = one_circles.DealAvailableGreenEnergyCoin(session, int(enum.PersonalActivePointRedemption), utils.StrToFloat64(values), utils.StrToFloat64(msg.AutoExchangeNumsAmount), enum.PersonalActivePointRedemption.String(), oneCirclesGreenEnergyBasicSetting, afterPriceValue) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::44444", err.Error()) | |||||
return err | |||||
} | |||||
//5、修改 one_circles_green_energy_basic_setting 的 now_price | |||||
_, err = db2.OneCirclesGreenEnergyBasicSettingUpdate(session, oneCirclesGreenEnergyBasicSetting.Id, oneCirclesGreenEnergyBasicSetting) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::77777", err.Error()) | |||||
return err | |||||
} | |||||
err = session.Commit() | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
return errors.New("事务提交失败") | |||||
} | |||||
return nil | |||||
} |
@@ -0,0 +1,150 @@ | |||||
package consume | |||||
import ( | |||||
"applet/app/cfg" | |||||
"applet/app/db" | |||||
utils2 "applet/app/utils" | |||||
"applet/app/utils/logx" | |||||
"applet/consume/md" | |||||
"applet/mall/utils" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | |||||
db2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db" | |||||
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/enum" | |||||
"encoding/json" | |||||
"errors" | |||||
"fmt" | |||||
"github.com/streadway/amqp" | |||||
"time" | |||||
) | |||||
func OneCirclesActivityCoinAutoExchangeGreenEnergyForTeamConsume(queue md.MqQueue) { | |||||
fmt.Println(">>>>>>>>>>>>OneCirclesActivityCoinAutoExchangeGreenEnergyForTeamConsume>>>>>>>>>>>>") | |||||
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) | |||||
one_circles.Init(cfg.RedisAddr) | |||||
var res amqp.Delivery | |||||
var ok bool | |||||
for { | |||||
res, ok = <-delivery | |||||
if ok == true { | |||||
err = handleOneCirclesActivityCoinAutoExchangeGreenEnergyForTeamConsume(res.Body) | |||||
if err != nil { | |||||
fmt.Println("OneCirclesActivityCoinAutoExchangeGreenEnergyForTeamConsume_ERR:::::", err.Error()) | |||||
utils2.FilePutContents("OneCirclesActivityCoinAutoExchangeGreenEnergyForTeamConsume_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")) | |||||
} | |||||
} | |||||
fmt.Println("get msg done") | |||||
} | |||||
func handleOneCirclesActivityCoinAutoExchangeGreenEnergyForTeamConsume(msgData []byte) error { | |||||
time.Sleep(time.Duration(2) * time.Millisecond) //休眠2毫秒 | |||||
//1、解析mq中queue的数据结构体 | |||||
var msg *md2.OneCirclesStructForAutoExchangeGreenEnergy | |||||
err := json.Unmarshal(msgData, &msg) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
engine := db.DBs[msg.MasterId] | |||||
//2、查找 `one_circles_green_energy_basic_setting` 基础设置 | |||||
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() | |||||
defer func() { | |||||
session.Close() | |||||
if err := recover(); err != nil { | |||||
_ = logx.Error(err) | |||||
} | |||||
}() | |||||
session.Begin() | |||||
//3.1计算涨价公式 | |||||
err1, values, _, afterPriceValue := one_circles.NewCalcPriceIncreaseFormula(msg.AutoExchangeNumsAmount, oneCirclesGreenEnergyBasicSetting) | |||||
if err1 != nil { | |||||
_ = session.Rollback() | |||||
return err1 | |||||
} | |||||
//3.2给相应的用户加上个人的绿色积分(结算数量) | |||||
err = one_circles.DealUserCoin(session, md2.DealUserCoinReq{ | |||||
Kind: "add", | |||||
Mid: msg.MasterId, | |||||
Title: md2.OneCirclesTeamActiveCoinExchangeGreenEnergy, | |||||
TransferType: md2.OneCirclesTeamActiveCoinExchangeGreenEnergyForUserVirtualCoinFlow, | |||||
OrdId: "", | |||||
CoinId: oneCirclesGreenEnergyBasicSetting.TeamGreenEnergyCoinId, | |||||
Uid: msg.Uid, | |||||
Amount: utils.StrToFloat64(values), | |||||
}) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::33333", err.Error()) | |||||
return err | |||||
} | |||||
//4.1给相应的用户减去团队活跃积分 | |||||
err = one_circles.DealUserCoin(session, md2.DealUserCoinReq{ | |||||
Kind: "sub", | |||||
Mid: msg.MasterId, | |||||
Title: md2.OneCirclesTeamActiveCoinExchangeToBeGreenEnergy, | |||||
TransferType: md2.OneCirclesTeamActiveCoinExchangeToBeGreenEnergyForUserVirtualCoinFlow, | |||||
OrdId: "", | |||||
CoinId: msg.CoinId, | |||||
Uid: msg.Uid, | |||||
Amount: utils.StrToFloat64(msg.Amount), | |||||
}) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::33333", err.Error()) | |||||
return err | |||||
} | |||||
//4.2减少“原始数量”中的绿色能量 | |||||
err = one_circles.DealAvailableGreenEnergyCoin(session, int(enum.TeamActivePointRedemption), utils.StrToFloat64(values), utils.StrToFloat64(msg.AutoExchangeNumsAmount), enum.TeamActivePointRedemption.String(), oneCirclesGreenEnergyBasicSetting, afterPriceValue) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::44444", err.Error()) | |||||
return err | |||||
} | |||||
//5、修改 one_circles_green_energy_basic_setting 的 now_price | |||||
_, err = db2.OneCirclesGreenEnergyBasicSettingUpdate(session, oneCirclesGreenEnergyBasicSetting.Id, oneCirclesGreenEnergyBasicSetting) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::77777", err.Error()) | |||||
return err | |||||
} | |||||
err = session.Commit() | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
return errors.New("事务提交失败") | |||||
} | |||||
return nil | |||||
} |
@@ -0,0 +1,99 @@ | |||||
package consume | |||||
import ( | |||||
"applet/app/cfg" | |||||
"applet/app/db" | |||||
utils2 "applet/app/utils" | |||||
"applet/app/utils/logx" | |||||
"applet/consume/md" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | |||||
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles" | |||||
"encoding/json" | |||||
"errors" | |||||
"fmt" | |||||
"github.com/streadway/amqp" | |||||
"time" | |||||
) | |||||
func OneCirclesSettlementPublicGiveActivityCoinConsume(queue md.MqQueue) { | |||||
fmt.Println(">>>>>>>>>>>>OneCirclesSettlementPublicGiveActivityCoinConsume>>>>>>>>>>>>") | |||||
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) | |||||
one_circles.Init(cfg.RedisAddr) | |||||
var res amqp.Delivery | |||||
var ok bool | |||||
for { | |||||
res, ok = <-delivery | |||||
if ok == true { | |||||
err = handleOneCirclesSettlementPublicGiveActivityCoinConsume(res.Body) | |||||
if err != nil { | |||||
fmt.Println("OneCirclesSettlementPublicGiveActivityCoinConsume_ERR:::::", err.Error()) | |||||
utils2.FilePutContents("OneCirclesSettlementPublicGiveActivityCoinConsume_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")) | |||||
} | |||||
} | |||||
fmt.Println("get msg done") | |||||
} | |||||
func handleOneCirclesSettlementPublicGiveActivityCoinConsume(msgData []byte) error { | |||||
time.Sleep(time.Duration(2) * time.Millisecond) //休眠2毫秒 | |||||
//1、解析mq中queue的数据结构体 | |||||
var msg *md2.DealUserCoinReq | |||||
err := json.Unmarshal(msgData, &msg) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
engine := db.DBs[msg.Mid] | |||||
session := engine.NewSession() | |||||
defer func() { | |||||
session.Close() | |||||
if err := recover(); err != nil { | |||||
_ = logx.Error(err) | |||||
} | |||||
}() | |||||
session.Begin() | |||||
err = one_circles.DealUserCoin(session, md2.DealUserCoinReq{ | |||||
Kind: "add", | |||||
Mid: msg.Mid, | |||||
Title: msg.Title, | |||||
TransferType: msg.TransferType, | |||||
OrdId: "", | |||||
CoinId: msg.CoinId, | |||||
Uid: msg.Uid, | |||||
Amount: msg.Amount, | |||||
}) | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
fmt.Println("err:::::2222", err) | |||||
return err | |||||
} | |||||
err = session.Commit() | |||||
if err != nil { | |||||
_ = session.Rollback() | |||||
return errors.New("事务提交失败") | |||||
} | |||||
return nil | |||||
} |
@@ -44,7 +44,7 @@ func FlexibleEmploymentWithdrawForGongMaoConsume(queue md.MqQueue) { | |||||
fmt.Println("err ::: ", err) | fmt.Println("err ::: ", err) | ||||
if err != nil { | if err != nil { | ||||
fmt.Println("FlexibleEmploymentWithdrawForGongMaoConsume_ERR:::::", err.Error()) | fmt.Println("FlexibleEmploymentWithdrawForGongMaoConsume_ERR:::::", err.Error()) | ||||
_ = res.Reject(true) | |||||
_ = res.Reject(true) //TODO::拒绝 Ack | |||||
//_ = res.Reject(false) | //_ = res.Reject(false) | ||||
var msg interface{} | var msg interface{} | ||||
json.Unmarshal(res.Body, &msg) | json.Unmarshal(res.Body, &msg) | ||||
@@ -6,7 +6,7 @@ require ( | |||||
code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git v1.1.2-0.20240222023917-c31b53f7e8cb | code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git v1.1.2-0.20240222023917-c31b53f7e8cb | ||||
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.0 | code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.0 | ||||
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.4 | code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.4 | ||||
code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20240315113731-a22c0fb96812 | |||||
code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20240424130228-5cf091d03973 | |||||
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20231116085701-9ba6e19f877b | code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20231116085701-9ba6e19f877b | ||||
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240126015516-38ca248db2fd | code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240126015516-38ca248db2fd | ||||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 | github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 | ||||