diff --git a/consume/egg_energy_deal_user_virtual_coin_consume.go b/consume/egg_energy_deal_user_virtual_coin_consume.go index 874a465..e787251 100644 --- a/consume/egg_energy_deal_user_virtual_coin_consume.go +++ b/consume/egg_energy_deal_user_virtual_coin_consume.go @@ -78,5 +78,5 @@ func handleEggEnergyDealUserVirtualCoinDataConsume(msgData []byte) error { return err } - return nil + return session.Commit() } diff --git a/consume/egg_energy_platform_revenue_data.go b/consume/egg_energy_platform_revenue_data_consume.go similarity index 100% rename from consume/egg_energy_platform_revenue_data.go rename to consume/egg_energy_platform_revenue_data_consume.go diff --git a/consume/egg_energy_settlement_public_give_activity_coin.go b/consume/egg_energy_settlement_public_give_activity_coin_consume.go similarity index 98% rename from consume/egg_energy_settlement_public_give_activity_coin.go rename to consume/egg_energy_settlement_public_give_activity_coin_consume.go index 293f1eb..b98cae1 100644 --- a/consume/egg_energy_settlement_public_give_activity_coin.go +++ b/consume/egg_energy_settlement_public_give_activity_coin_consume.go @@ -77,5 +77,5 @@ func handleEggEnergySettlementPublicGiveActivityCoinConsume(msgData []byte) erro session.Rollback() return err } - return session.Begin() + return session.Commit() } diff --git a/consume/egg_new_user_register_consume.go b/consume/egg_new_user_register_consume.go new file mode 100644 index 0000000..24d178d --- /dev/null +++ b/consume/egg_new_user_register_consume.go @@ -0,0 +1,72 @@ +package consume + +import ( + "applet/app/cfg" + utils2 "applet/app/utils" + "applet/app/utils/logx" + "applet/consume/md" + "code.fnuoos.com/EggPlanet/egg_system_rules.git" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" + md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" + "encoding/json" + "errors" + "fmt" + "github.com/streadway/amqp" + "time" +) + +func EggEnergyNewUserRegisterDataConsume(queue md.MqQueue) { + fmt.Println(">>>>>>>>>>>>EggEnergyNewUserRegisterDataConsume>>>>>>>>>>>>") + 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 = handleEggEnergyNewUserRegisterDataConsume(res.Body) + if err != nil { + fmt.Println("EggEnergyNewUserRegisterDataConsume_ERR:::::", err.Error()) + utils2.FilePutContents("EggEnergyNewUserRegisterDataConsume_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 handleEggEnergyNewUserRegisterDataConsume(msgData []byte) error { + time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 + // 1.解析mq中queue的数据结构体 + var msg *md2.EggNewUserRegisterData + err := json.Unmarshal(msgData, &msg) + if err != nil { + return err + } + + // 2.为新注册的用户新增蛋蛋分记录 + err = egg_energy.ExistOrDefaultUserEggScore(msg.Uid) + if err != nil { + return err + } + + return nil +} diff --git a/consume/init.go b/consume/init.go index 44afce0..ec1cd00 100644 --- a/consume/init.go +++ b/consume/init.go @@ -18,19 +18,20 @@ func Init() { // 增加消费任务队列 func initConsumes() { jobs[consumeMd.EggEnergyStartLevelDividendFunName] = EggEnergyStartLevelDividendConsume - jobs[consumeMd.EggEnergyDealPlatformRevenueDataFunName] = EggEnergyDealPlatformRevenueDataConsume - jobs[consumeMd.EggEnergyDealFundDataFunName] = EggEnergyDealFundDataConsume - jobs[consumeMd.AliyunSmsRecordFunName] = AliyunSmsRecordConsume //阿里云短信 - jobs[consumeMd.JpushRecordFunName] = JpushRecordConsume //极光推送 - jobs[consumeMd.AdvertisingSmashConsume] = AdvertisingSmashConsume //砸蛋 - jobs[consumeMd.AdvertisingSignConsume] = AdvertisingSignConsume //签到 - jobs[consumeMd.EggEnergyDealUserVirtualCoinDataFunName] = EggEnergyDealUserVirtualCoinDataConsume - jobs[consumeMd.IMEggEnergyBatchSendMessageDataFunName] = IMEggEnergyBatchSendMessageDataConsume - jobs[consumeMd.IMEggEnergyDelFriendCircleDataFunName] = IMEggEnergyDelFriendCircleDataConsume - jobs[consumeMd.EggFinWithdrawApplyDataConsumeFunName] = EggFinWithdrawApplyDataConsume + jobs[consumeMd.EggEnergyDealPlatformRevenueDataFunName] = EggEnergyDealPlatformRevenueDataConsume // 平台营收 + jobs[consumeMd.EggEnergyDealFundDataFunName] = EggEnergyDealFundDataConsume // 资金数据 + jobs[consumeMd.AliyunSmsRecordFunName] = AliyunSmsRecordConsume //阿里云短信 + jobs[consumeMd.JpushRecordFunName] = JpushRecordConsume //极光推送 + jobs[consumeMd.AdvertisingSmashConsume] = AdvertisingSmashConsume //砸蛋 + jobs[consumeMd.AdvertisingSignConsume] = AdvertisingSignConsume //签到 + jobs[consumeMd.EggEnergyDealUserVirtualCoinDataFunName] = EggEnergyDealUserVirtualCoinDataConsume // 视频奖励给相应团队发放积分 + jobs[consumeMd.IMEggEnergyBatchSendMessageDataFunName] = IMEggEnergyBatchSendMessageDataConsume // 批量发送信息 + jobs[consumeMd.IMEggEnergyDelFriendCircleDataFunName] = IMEggEnergyDelFriendCircleDataConsume // 删除朋友圈 + jobs[consumeMd.EggFinWithdrawApplyDataConsumeFunName] = EggFinWithdrawApplyDataConsume // 支付宝打款 jobs[consumeMd.EggEnergySettlementPublicGiveActivityCoinFunName] = EggEnergySettlementPublicGiveActivityCoinConsume jobs[consumeMd.EggEnergyStartExchangeGreenEnergyFunName] = EggEnergyStartExchangeGreenEnergyConsume jobs[consumeMd.EggEnergyAutoExchangeGreenEnergyFunName] = EggEnergyAutoExchangeGreenEnergyConsume + jobs[consumeMd.EggEnergyNewUserRegisterDataFunName] = EggEnergyNewUserRegisterDataConsume // 新用户注册 } func Run() { diff --git a/consume/md/consume_key.go b/consume/md/consume_key.go index e389a91..e6717ff 100644 --- a/consume/md/consume_key.go +++ b/consume/md/consume_key.go @@ -137,6 +137,15 @@ var RabbitMqQueueKeyList = []*MqQueue{ BindKey: "", ConsumeFunName: "AdvertisingSignConsume", }, + { + ExchangeName: "egg.app", + Name: "egg_new_user_register_queue", + Type: DirectQueueType, + IsPersistent: false, + RoutKey: "egg_new_user_register", + BindKey: "", + ConsumeFunName: "EggEnergyNewUserRegisterDataConsume", + }, } const ( @@ -154,4 +163,5 @@ const ( EggEnergySettlementPublicGiveActivityCoinFunName = "EggEnergySettlementPublicGiveActivityCoinConsume" EggEnergyStartExchangeGreenEnergyFunName = "EggEnergyStartExchangeGreenEnergyConsume" EggEnergyAutoExchangeGreenEnergyFunName = "EggEnergyAutoExchangeGreenEnergyConsume" + EggEnergyNewUserRegisterDataFunName = "EggEnergyNewUserRegisterDataConsume" ) diff --git a/go.mod b/go.mod index 5879475..05b0a64 100644 --- a/go.mod +++ b/go.mod @@ -7,8 +7,8 @@ go 1.19 //replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules require ( - code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241204145112-7b4c29691a6d - code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241205022841-e4ca039b4006 + code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241205041102-0e106357c399 + code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241205061938-91f42710d6cd 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