From f70c4fb92bf3cf68a5620e58d9f4d753380a1a99 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Mon, 6 Jan 2025 20:10:22 +0800 Subject: [PATCH] 1 --- app/md/mq.go | 10 +- .../egg_energy_auto_exchange_green_energy.go | 14 ++- consume/egg_energy_recruit_new_user_reward.go | 119 ++++++++++++++++++ consume/init.go | 2 + consume/md/consume_key.go | 10 ++ go.mod | 2 +- 6 files changed, 145 insertions(+), 12 deletions(-) create mode 100644 consume/egg_energy_recruit_new_user_reward.go diff --git a/app/md/mq.go b/app/md/mq.go index feb85e3..b96e144 100644 --- a/app/md/mq.go +++ b/app/md/mq.go @@ -1,11 +1,5 @@ package md -const OrdExchange = "order" - -const ( - OrdRoutKeyForJudgePackageOrdOrdState = "judge_package_ord_state" //订单状态 -) - -type JudgePackageOrdOrdState struct { - OrdNo string `json:"ord_no"` +type EggEnergyRecruitNewUserRewardMq struct { + Uid int64 `json:"uid"` } diff --git a/consume/egg_energy_auto_exchange_green_energy.go b/consume/egg_energy_auto_exchange_green_energy.go index ba3bac6..7e9a2f3 100644 --- a/consume/egg_energy_auto_exchange_green_energy.go +++ b/consume/egg_energy_auto_exchange_green_energy.go @@ -3,6 +3,7 @@ package consume import ( "applet/app/cfg" "applet/app/db" + md4 "applet/app/md" utils2 "applet/app/utils" "applet/app/utils/logx" "applet/consume/md" @@ -36,7 +37,7 @@ func EggEnergyAutoExchangeGreenEnergyConsume(queue md.MqQueue) { for { res, ok = <-delivery if ok == true { - err = handleEggEnergyAutoExchangeGreenEnergyConsume(res.Body) + err = handleEggEnergyAutoExchangeGreenEnergyConsume(res.Body, ch) if err != nil { fmt.Println("EggEnergyAutoExchangeGreenEnergyConsume_ERR:::::", err.Error()) utils2.FilePutContents("EggEnergyAutoExchangeGreenEnergyConsume_ERR", utils2.SerializeStr(map[string]interface{}{ @@ -55,7 +56,7 @@ func EggEnergyAutoExchangeGreenEnergyConsume(queue md.MqQueue) { fmt.Println("get msg done") } -func handleEggEnergyAutoExchangeGreenEnergyConsume(msgData []byte) error { +func handleEggEnergyAutoExchangeGreenEnergyConsume(msgData []byte, ch *rabbit.Channel) error { //1、解析mq中queue的数据结构体 var msg *md2.EggEnergyStructForAutoExchangeGreenEnergy err := json.Unmarshal(msgData, &msg) @@ -66,5 +67,12 @@ func handleEggEnergyAutoExchangeGreenEnergyConsume(msgData []byte) error { //2、调用制度方法 err = egg_energy.ActivityCoinAutoExchangeEggPersonEnergy(engine, *msg) - return err + if err != nil { + return err + } + //3、给到直推奖励 + ch.Publish(md2.EggEnergyExchange, md4.EggEnergyRecruitNewUserRewardMq{ + Uid: msg.Uid, + }, "egg_energy_recruit_new_user_reward") + return nil } diff --git a/consume/egg_energy_recruit_new_user_reward.go b/consume/egg_energy_recruit_new_user_reward.go new file mode 100644 index 0000000..dde624e --- /dev/null +++ b/consume/egg_energy_recruit_new_user_reward.go @@ -0,0 +1,119 @@ +package consume + +import ( + "applet/app/cfg" + "applet/app/db" + md4 "applet/app/md" + 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_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/go_rely_warehouse/zyos_go_mq.git/rabbit" + "encoding/json" + "errors" + "fmt" + "github.com/streadway/amqp" +) + +func EggEnergyRecruitNewUserRewardConsume(queue md.MqQueue) { + fmt.Println(">>>>>>>>>>>>EggEnergyRecruitNewUserRewardConsume>>>>>>>>>>>>") + 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 = handleEggEnergyRecruitNewUserRewardConsume(res.Body) + if err != nil { + fmt.Println("EggEnergyRecruitNewUserRewardConsume_ERR:::::", err.Error()) + utils2.FilePutContents("EggEnergyRecruitNewUserRewardConsume_ERR", utils2.SerializeStr(map[string]interface{}{ + "body": res.Body, + "err": err.Error(), + })) + _ = res.Reject(true) //TODO::拒绝 + } else { + err = res.Ack(true) + fmt.Println("err ::: ", err) + } + } else { + panic(errors.New("error getting message")) + } + } + fmt.Println("get msg done") +} + +func handleEggEnergyRecruitNewUserRewardConsume(msgData []byte) error { + //1、解析mq中queue的数据结构体 + var msg *md4.EggEnergyRecruitNewUserRewardMq + err := json.Unmarshal(msgData, &msg) + if err != nil { + return err + } + engine := db.Db + + //2、给到直推奖励 + eggEnergyRecruitNewUserRewardDb := implement.NewEggEnergyRecruitNewUserRewardDb(engine) + _, exist, _ := eggEnergyRecruitNewUserRewardDb.EggEnergyRecruitNewUserRewardGet(msg.Uid) + if !exist { //TODO::判断是否签到过 + eggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) + eggEnergyBasicSetting, err1 := eggEnergyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ + "key": "is_open", + "value": 1, + }) + if err1 != nil { + return err1 + } + if eggEnergyBasicSetting != nil { + userDb := implement.NewUserDb(db.Db) + user, err1 := userDb.GetUser(msg.Uid) + if err1 != nil { + return err1 + } + if user != nil { + userDeleteInfoDb := implement.NewUserDeleteInfoDb(db.Db) + userDelete := userDeleteInfoDb.GetUserDeleteInfo(user.Phone) + fmt.Println("userDelete>>>>>>>>>>>>>>>", userDelete) + if userDelete == nil { + var newUserRewardRules *md2.NewUserRewardRules + err1 = json.Unmarshal([]byte(eggEnergyBasicSetting.NewUserIncentiveRules), &newUserRewardRules) + if err1 != nil { + fmt.Println("handleAddPublicPlatoonUserRelationCommissionConsume___ERR>>>>", err1.Error()) + } + rewardValue := newUserRewardRules.InviteUserRewardValue + session := db.Db.NewSession() + err1 = rule.DealUserVirtualCoin(session, md3.DealUserVirtualCoinReq{ + Kind: "add", + Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggEnergyRecruitNewUsersReward), + TransferType: int(enum.EggEnergyRecruitNewUsersReward), + CoinId: eggEnergyBasicSetting.PersonEggPointsCoinId, + Uid: user.ParentUid, + Amount: float64(rewardValue), + }) + if err1 != nil { + return err1 + } + session.Commit() + } + } + } + } + + return nil +} diff --git a/consume/init.go b/consume/init.go index b778b9a..8b2ab7b 100644 --- a/consume/init.go +++ b/consume/init.go @@ -58,6 +58,8 @@ func initConsumes() { jobs[consumeMd.EggEnergySettlementPublicGiveActivityCoinFunName] = EggEnergySettlementPublicGiveActivityCoinConsume jobs[consumeMd.EggEnergyStartExchangeGreenEnergyFunName] = EggEnergyStartExchangeGreenEnergyConsume jobs[consumeMd.EggEnergyAutoExchangeGreenEnergyFunName] = EggEnergyAutoExchangeGreenEnergyConsume + jobs[consumeMd.EggEnergyRecruitNewUserRewardFunName] = EggEnergyRecruitNewUserRewardConsume + jobs[consumeMd.EggEnergyTeamAssistanceConsumeFunName] = EggEnergyTeamAssistanceConsume // 更新团队助力数据 jobs[consumeMd.EggCanalUserVirtualCoinFlowAggregationConsumeFunName] = EggCanalUserVirtualCoinFlowAggregationConsume // 聚合流水数据 jobs[consumeMd.EggPublishDataFunName] = EggPublishDataConsume // 聚合流水数据 diff --git a/consume/md/consume_key.go b/consume/md/consume_key.go index 2fa8f33..97fca73 100644 --- a/consume/md/consume_key.go +++ b/consume/md/consume_key.go @@ -101,6 +101,15 @@ var RabbitMqQueueKeyList = []*MqQueue{ BindKey: "", ConsumeFunName: "EggEnergyAutoExchangeGreenEnergyConsume", }, + { + ExchangeName: "egg.energy", + Name: "egg_energy_recruit_new_user_reward", + Type: DirectQueueType, + IsPersistent: false, + RoutKey: "egg_energy_recruit_new_user_reward", + BindKey: "", + ConsumeFunName: "EggEnergyRecruitNewUserRewardConsume", + }, { ExchangeName: "egg.app", Name: "add_public_platoon_user_relation_commission", @@ -394,6 +403,7 @@ const ( EggEnergySettlementPublicGiveActivityCoinFunName = "EggEnergySettlementPublicGiveActivityCoinConsume" EggEnergyStartExchangeGreenEnergyFunName = "EggEnergyStartExchangeGreenEnergyConsume" EggEnergyAutoExchangeGreenEnergyFunName = "EggEnergyAutoExchangeGreenEnergyConsume" + EggEnergyRecruitNewUserRewardFunName = "EggEnergyRecruitNewUserRewardConsume" EggEnergyNewUserRegisterDataFunName = "EggEnergyNewUserRegisterDataConsume" EggEnergyDealUserECPMFunName = "EggEnergyDealUserECPMConsume" EggEnergyTemporaryDealUserECPMFunName = "TemporaryEggEnergyDealUserECPMConsume" diff --git a/go.mod b/go.mod index a3f2e58..9efcbd8 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ 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.20250104182559-3f1d190a6c31 + code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20250106115148-27e932d9ac3d 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