From 4d0e3361569f655fe32cbec97c8fc1d7b82759a2 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Mon, 30 Dec 2024 19:00:11 +0800 Subject: [PATCH] update --- ...public_platoon_user_relation_commission.go | 109 ------ consume/aliyun_sms_record_consume.go | 98 ----- ...g_canal_energy_exchange_account_consume.go | 109 ------ ...al_energy_exchange_account_consume_test.go | 53 --- consume/egg_canal_invite_user_nums_consume.go | 107 ------ ...canal_person_add_activity_value_consume.go | 118 ------ ..._person_add_activity_value_consume_test.go | 49 --- consume/egg_canal_user_consume.go | 79 ---- consume/egg_canal_violate_nums_consume.go | 124 ------- ..._virtual_ coin_flow_aggregation_consume.go | 116 ------ ...ual_ coin_flow_aggregation_consume_test.go | 49 --- consume/egg_comment_consume.go | 97 ----- .../egg_energy_auto_exchange_green_energy.go | 70 ---- consume/egg_energy_auto_score_consume.go | 140 ------- consume/egg_energy_deal_user_ecpm.go | 97 ----- consume/egg_energy_deal_user_ecpm_test.go | 24 -- ...g_energy_deal_user_virtual_coin_consume.go | 82 ----- consume/egg_energy_fund_data_consume.go | 176 --------- ...gg_energy_platform_revenue_data_consume.go | 184 ---------- ...ement_public_give_activity_coin_consume.go | 83 ----- .../egg_energy_start_exchange_green_energy.go | 73 ---- ...egg_energy_start_level_dividend_consume.go | 106 ------ consume/egg_energy_team_assistance_consume.go | 129 ------- ...egg_energy_team_assistance_consume_test.go | 43 --- consume/egg_energy_user_activity_consume.go | 83 ----- consume/egg_fin_withdraw_apply_consume.go | 256 ------------- .../egg_fin_withdraw_apply_consume_test.go | 54 --- consume/egg_new_user_register_consume.go | 102 ------ consume/egg_record_active_consume.go | 135 ------- consume/egg_send_friend_circle_consume.go | 97 ----- consume/egg_slow_auto_up_lv_consume.go | 60 --- ...m_egg_energy_batch_send_message_consume.go | 86 ----- ...nergy_del_friend_circle_comment_consume.go | 77 ---- .../im_egg_energy_send_red_package_consume.go | 96 ----- consume/init.go | 41 +-- consume/jpush_record_consume.go | 95 ----- consume/md/consume_key.go | 344 +----------------- consume/playlet_reward_consume.go | 147 -------- consume/user_delete_consume.go | 168 --------- consume/user_register_for_my_my_fans.go | 138 +++++++ .../user_register_for_my_my_recommender.go | 202 ++++++++++ consume/user_register_for_official_consume.go | 8 +- consume/video_reward_consume.go | 144 -------- 43 files changed, 365 insertions(+), 4283 deletions(-) delete mode 100644 consume/add_public_platoon_user_relation_commission.go delete mode 100644 consume/aliyun_sms_record_consume.go delete mode 100644 consume/egg_canal_energy_exchange_account_consume.go delete mode 100644 consume/egg_canal_energy_exchange_account_consume_test.go delete mode 100644 consume/egg_canal_invite_user_nums_consume.go delete mode 100644 consume/egg_canal_person_add_activity_value_consume.go delete mode 100644 consume/egg_canal_person_add_activity_value_consume_test.go delete mode 100644 consume/egg_canal_user_consume.go delete mode 100644 consume/egg_canal_violate_nums_consume.go delete mode 100644 consume/egg_cannal_user_virtual_ coin_flow_aggregation_consume.go delete mode 100644 consume/egg_cannal_user_virtual_ coin_flow_aggregation_consume_test.go delete mode 100644 consume/egg_comment_consume.go delete mode 100644 consume/egg_energy_auto_exchange_green_energy.go delete mode 100644 consume/egg_energy_auto_score_consume.go delete mode 100644 consume/egg_energy_deal_user_ecpm.go delete mode 100644 consume/egg_energy_deal_user_ecpm_test.go delete mode 100644 consume/egg_energy_deal_user_virtual_coin_consume.go delete mode 100644 consume/egg_energy_fund_data_consume.go delete mode 100644 consume/egg_energy_platform_revenue_data_consume.go delete mode 100644 consume/egg_energy_settlement_public_give_activity_coin_consume.go delete mode 100644 consume/egg_energy_start_exchange_green_energy.go delete mode 100644 consume/egg_energy_start_level_dividend_consume.go delete mode 100644 consume/egg_energy_team_assistance_consume.go delete mode 100644 consume/egg_energy_team_assistance_consume_test.go delete mode 100644 consume/egg_energy_user_activity_consume.go delete mode 100644 consume/egg_fin_withdraw_apply_consume.go delete mode 100644 consume/egg_fin_withdraw_apply_consume_test.go delete mode 100644 consume/egg_new_user_register_consume.go delete mode 100644 consume/egg_record_active_consume.go delete mode 100644 consume/egg_send_friend_circle_consume.go delete mode 100644 consume/egg_slow_auto_up_lv_consume.go delete mode 100644 consume/im_egg_energy_batch_send_message_consume.go delete mode 100644 consume/im_egg_energy_del_friend_circle_comment_consume.go delete mode 100644 consume/im_egg_energy_send_red_package_consume.go delete mode 100644 consume/jpush_record_consume.go delete mode 100644 consume/playlet_reward_consume.go delete mode 100644 consume/user_delete_consume.go create mode 100644 consume/user_register_for_my_my_fans.go create mode 100644 consume/user_register_for_my_my_recommender.go delete mode 100644 consume/video_reward_consume.go diff --git a/consume/add_public_platoon_user_relation_commission.go b/consume/add_public_platoon_user_relation_commission.go deleted file mode 100644 index 4d946d5..0000000 --- a/consume/add_public_platoon_user_relation_commission.go +++ /dev/null @@ -1,109 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - "applet/app/db" - "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 AddPublicPlatoonUserRelationCommissionConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>AddPublicPlatoonUserRelationCommissionConsume>>>>>>>>>>>>") - 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 = handleAddPublicPlatoonUserRelationCommissionConsume(res.Body) - if err != nil { - fmt.Println("err ::: ", err) - utils.FilePutContents("AddPublicPlatoonUserRelationCommissionConsume_ERR", "[err]:"+err.Error()) - _ = res.Reject(false) - //TODO::重新推回队列末尾,避免造成队列堵塞 - //var msg *md2.AddPublicPlatoonUserRelationCommissionReq - //json.Unmarshal(res.Body, &msg) - //ch.Publish(queue.ExchangeName, msg, queue.RoutKey) - } else { - _ = res.Ack(true) - } - } else { - panic(errors.New("error getting message")) - } - } - fmt.Println("get msg done") -} - -func handleAddPublicPlatoonUserRelationCommissionConsume(msgData []byte) error { - //1、解析mq中queue的数据结构体 - var msg *md2.AddPublicPlatoonUserRelationCommissionReq - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - - //3、加入公排 - var req []*md2.AddPublicPlatoonUserRelationCommissionReq - req = append(req, msg) - _, err = rule.AddPublicPlatoonUserRelationCommission(db.Db, req) - fmt.Println("err::::", err) - if err != nil { - return err - } - - //2、给到直推奖励 - eggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) - eggEnergyBasicSetting, err := eggEnergyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ - "key": "is_open", - "value": 1, - }) - if err != nil { - return err - } - if eggEnergyBasicSetting != nil { - var newUserRewardRules *md2.NewUserRewardRules - err = json.Unmarshal([]byte(eggEnergyBasicSetting.NewUserIncentiveRules), &newUserRewardRules) - if err != nil { - fmt.Println("handleAddPublicPlatoonUserRelationCommissionConsume___ERR>>>>", err.Error()) - } - rewardValue := newUserRewardRules.InviteUserRewardValue - session := db.Db.NewSession() - err = rule.DealUserVirtualCoin(session, md3.DealUserVirtualCoinReq{ - Kind: "add", - Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggEnergyRecruitNewUsersReward), - TransferType: int(enum.EggEnergyRecruitNewUsersReward), - CoinId: eggEnergyBasicSetting.PersonEggPointsCoinId, - Uid: utils.StrToInt64(msg.RecommendUid), - Amount: float64(rewardValue), - }) - if err != nil { - return err - } - session.Commit() - } - return nil -} diff --git a/consume/aliyun_sms_record_consume.go b/consume/aliyun_sms_record_consume.go deleted file mode 100644 index 19ecf00..0000000 --- a/consume/aliyun_sms_record_consume.go +++ /dev/null @@ -1,98 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - "applet/app/db" - "applet/app/svc/sys_cfg" - "code.fnuoos.com/EggPlanet/egg_system_rules.git" - - utils2 "applet/app/utils" - "applet/app/utils/logx" - "applet/consume/md" - "code.fnuoos.com/EggPlanet/egg_models.git/src/model" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/aliyun" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/streadway/amqp" - "time" -) - -func AliyunSmsRecordConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>AliyunSmsRecordConsume>>>>>>>>>>>>") - 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 = handleAliyunSmsRecordConsume(res.Body) - if err != nil { - fmt.Println("AliyunSmsRecordConsume_ERR:::::", err.Error()) - utils2.FilePutContents("AliyunSmsRecordConsume_ERR", utils2.SerializeStr(map[string]interface{}{ - "body": res.Body, - "err": err.Error(), - })) - _ = res.Reject(false) - //TODO::重新推回队列末尾,避免造成队列堵塞 - var msg *md.AliyunSmsRecordFundData - json.Unmarshal(res.Body, &msg) - msg.Num = "1" - ch.Publish(queue.ExchangeName, msg, queue.RoutKey) - } else { - //_ = res.Reject(false) - err = res.Ack(true) - } - - fmt.Println("err ::: ", err) - } else { - panic(errors.New("error getting message")) - } - } - fmt.Println("get msg done") -} - -func handleAliyunSmsRecordConsume(msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md.AliyunSmsRecordFundData - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - engine := db.Db - sysCfgDb := sys_cfg.NewSysCfgDb(engine) - aliyunSmsId := sysCfgDb.SysCfgGetWithDb("aliyun_sms_id") - aliyunSmsSecret := sysCfgDb.SysCfgGetWithDb("aliyun_sms_secret") - aliyunSmsSignName := sysCfgDb.SysCfgGetWithDb("aliyun_sms_sign_name") - aliyunSmsSaleCode := sysCfgDb.SysCfgGetWithDb("aliyun_sms_sale_code") - extra := "{\"content\":\"" + msg.Content + "\"}" - if msg.Code != "" { - aliyunSmsSaleCode = msg.Code - extra = msg.Extra - } - if aliyunSmsSaleCode == "" || msg.Phone == "" { - return nil - } - err = aliyun.AliyunSendSms(aliyunSmsId, aliyunSmsSecret, msg.Phone, aliyunSmsSignName, aliyunSmsSaleCode, extra) - if err != nil && msg.Num != "1" { - return err - } - if msg.Id != "" { - engine.Where("id=?", msg.Id).Cols("state").Update(&model.AliyunSmsRecord{State: 1}) - } - return nil -} diff --git a/consume/egg_canal_energy_exchange_account_consume.go b/consume/egg_canal_energy_exchange_account_consume.go deleted file mode 100644 index 780c1f4..0000000 --- a/consume/egg_canal_energy_exchange_account_consume.go +++ /dev/null @@ -1,109 +0,0 @@ -package consume - -import ( - utils2 "applet/app/utils" - "applet/app/utils/logx" - "applet/consume/md" - md2 "applet/es/md" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" - es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "context" - "encoding/json" - "errors" - "fmt" - "github.com/olivere/elastic/v7" - "github.com/streadway/amqp" - "strings" - "time" -) - -func EggCanalEnergyExchangeAccountConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>EggCanalEnergyExchangeAccountConsume>>>>>>>>>>>>>") - 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(1000) - delivery := ch.Consume(queue.Name, true) //设置自动应答 - - var res amqp.Delivery - var ok bool - for { - res, ok = <-delivery - if ok == true { - //fmt.Println(string(res.Body)) - fmt.Println(">>>>>>>>>>>>>>>>>>EggCanalEnergyExchangeAccountConsume<<<<<<<<<<<<<<<<<<<<<<<<<") - err = handleEggCanalEnergyExchangeAccountConsume(res.Body) - if err != nil { - fmt.Println("EggCanalEnergyExchangeAccountConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggCanalEnergyExchangeAccountConsume_ERR", utils2.SerializeStr(map[string]interface{}{ - "body": res.Body, - "err": err.Error(), - })) - } - //_ = res.Reject(false) - //_ = res.Ack(true) - } else { - panic(errors.New("error getting message")) - } - } -} - -func handleEggCanalEnergyExchangeAccountConsume(msg []byte) error { - //1.解析canal采集至mq中queue的数据结构体 - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - var canalMsg *md.CanalEnergyExchangeAccountMessage[md.CanalEnergyExchangeAccount] - err := json.Unmarshal(msg, &canalMsg) - if err != nil { - fmt.Println("EggCanalEnergyExchangeAccountConsumeUnMarshalFailed_ERR:::::", err.Error()) - return nil - } - - year, week := time.Now().ISOWeek() - yearStr := utils2.IntToStr(year) - weekStr := utils2.IntToStr(week) - index := es2.GetAppointIndexFromAlias(yearStr, weekStr) - // 2. 监听插入信息 - if canalMsg.Type == md2.CanalMsgInsertSqlType { - for _, item := range canalMsg.Data { - uid := item.Uid - id := fmt.Sprintf("%d%d_%s", year, week, uid) - - if item.Title != enum.EggEnergyExchangeAccountBalance.String() { - continue - } - - // 3. 增加 蛋蛋能量兑换余额 数量 - amount := utils2.StrToFloat64(item.Amount) - script := elastic.NewScript("ctx._source.egg_energy_exchange_account_balance += params.inc").Param("inc", amount) - updateDoc, err := es.EsClient.Update(). - Index(index). - Id(id). - Script(script). - Do(context.Background()) - if err != nil { - if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { - // 蛋蛋分数据还不存在,创建蛋蛋分数据 - now := time.Now().Format("2006-01-02 15:04:05") - err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, id, utils2.StrToInt64(uid), enum.EsEggEnergyExchangeAccountBalance, utils2.Float64ToStr(amount), now) - if err1 != nil { - return err1 - } - return nil - } - fmt.Println("EggCanalPersonAddActivityValueConsumeUpdateDoc_ERR::::", err.Error()) - return err - } - fmt.Println("updateDoc==========>", updateDoc) - } - } - return nil -} diff --git a/consume/egg_canal_energy_exchange_account_consume_test.go b/consume/egg_canal_energy_exchange_account_consume_test.go deleted file mode 100644 index 511526c..0000000 --- a/consume/egg_canal_energy_exchange_account_consume_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package consume - -import ( - "applet/consume/md" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "testing" - "time" -) - -func TestEggCanalEnergyExchangeAccountConsume(t *testing.T) { - data := md.CanalEnergyExchangeAccount{ - Id: "1", - Uid: "16", - Direction: "1", - Amount: "4.88000000", - BeforeAmount: "0", - AfterAmount: "3.88000000", - SysFee: "0", - OrdId: "", - Title: "蛋蛋能量兑换余额", - Kind: "3", - State: "0", - Memo: "手动测试数据", - CreateAt: "", - UpdateAt: "", - } - - message := md.CanalEnergyExchangeAccountMessage[md.CanalEnergyExchangeAccount]{ - Data: []md.CanalEnergyExchangeAccount{data}, - Database: "test_db", - ES: time.Now().UnixNano(), - ID: 1, - IsDdl: false, - Old: nil, - PkNames: []string{"id"}, - Table: "egg_canal_user_wallet_flow", - TS: time.Now().Unix(), - Type: "INSERT", - } - - err := rabbit.Init("120.77.153.180", "5672", "guest", "guest") - if err != nil { - return - } - ch, err := rabbit.Cfg.Pool.GetChannel() - if err != nil { - return - } - defer ch.Release() - ch.Publish(md2.EggCanalExchange, message, "egg_canal_user_wallet_flow") - -} diff --git a/consume/egg_canal_invite_user_nums_consume.go b/consume/egg_canal_invite_user_nums_consume.go deleted file mode 100644 index 6672786..0000000 --- a/consume/egg_canal_invite_user_nums_consume.go +++ /dev/null @@ -1,107 +0,0 @@ -package consume - -import ( - utils2 "applet/app/utils" - "applet/app/utils/logx" - "applet/consume/md" - md2 "applet/es/md" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" - es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "context" - "encoding/json" - "errors" - "fmt" - "github.com/olivere/elastic/v7" - "github.com/streadway/amqp" - "strings" - "time" -) - -func EggCanalInviteUserNumsConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>EggCanalInviteUserNumsConsume>>>>>>>>>>>>>") - 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(1000) - delivery := ch.Consume(queue.Name, true) //设置自动应答 - - var res amqp.Delivery - var ok bool - for { - res, ok = <-delivery - if ok == true { - //fmt.Println(string(res.Body)) - fmt.Println(">>>>>>>>>>>>>>>>>>EggCanalInviteUserNumsConsume<<<<<<<<<<<<<<<<<<<<<<<<<") - err = handleEggCanalInviteUserNumsConsume(res.Body) - if err != nil { - fmt.Println("EggCanalInviteUserNumsConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggCanalInviteUserNumsConsume_ERR", utils2.SerializeStr(map[string]interface{}{ - "body": res.Body, - "err": err.Error(), - })) - } - //_ = res.Reject(false) - //_ = res.Ack(true) - } else { - panic(errors.New("error getting message")) - } - } -} - -func handleEggCanalInviteUserNumsConsume(msg []byte) error { - //1、解析canal采集至mq中queue的数据结构体 - var canalMsg *md.CanalUserRelateMessage[md.CanalUserRelate] - err := json.Unmarshal(msg, &canalMsg) - if err != nil { - fmt.Println("EggCanalInviteUserNumsConsumeFaliedUnMarshal_ERR:::::", err.Error()) - return nil - } - - year, week := time.Now().ISOWeek() - yearStr := utils2.IntToStr(year) - weekStr := utils2.IntToStr(week) - index := es2.GetAppointIndexFromAlias(yearStr, weekStr) - // 2. 监听插入信息 - if canalMsg.Type == md2.CanalMsgInsertSqlType { - for _, item := range canalMsg.Data { - if item.Level != "1" { - return nil - } - parentUid := item.ParentUid - id := fmt.Sprintf("%d%d_%s", year, week, parentUid) - - // 新增拉新人数 - script := elastic.NewScript("ctx._source.invite_user_nums += params.inc").Param("inc", 1) - service, err := es.EsClient.Update(). - Index(index). - Id(id). - Script(script). - Do(context.Background()) - if err != nil { - if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { - // 蛋蛋分数据还不存在,创建蛋蛋分数据 - now := time.Now().Format("2006-01-02 15:04:05") - err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, id, utils2.StrToInt64(parentUid), enum.InviteUserNums, "1", now) - if err1 != nil { - return err1 - } - return nil - } - fmt.Println("EggCanalInviteUserNumsConsumeFailedUpdateInviteUserNums_ERR:::::", err.Error()) - return err - } - fmt.Println(service) - } - } - fmt.Println("EggCanalInviteUserNumsConsume_Succeed::::") - return nil -} diff --git a/consume/egg_canal_person_add_activity_value_consume.go b/consume/egg_canal_person_add_activity_value_consume.go deleted file mode 100644 index a5ca767..0000000 --- a/consume/egg_canal_person_add_activity_value_consume.go +++ /dev/null @@ -1,118 +0,0 @@ -package consume - -import ( - "applet/app/db" - utils2 "applet/app/utils" - "applet/app/utils/logx" - "applet/consume/md" - md2 "applet/es/md" - "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" - es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "context" - "encoding/json" - "errors" - "fmt" - "github.com/olivere/elastic/v7" - "github.com/streadway/amqp" - "strings" - "time" -) - -// EggCanalPersonAddActivityValueConsume 用户获得活跃积分时更新到 es -func EggCanalPersonAddActivityValueConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>EggCanalPersonAddActivityValueConsume>>>>>>>>>>>>>") - 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(1000) - delivery := ch.Consume(queue.Name, true) //设置自动应答 - - var res amqp.Delivery - var ok bool - for { - res, ok = <-delivery - if ok == true { - //fmt.Println(string(res.Body)) - fmt.Println(">>>>>>>>>>>>>>>>>>EggCanalPersonAddActivityValueConsume<<<<<<<<<<<<<<<<<<<<<<<<<") - err = handleEggCanalPersonAddActivityValueConsume(res.Body) - if err != nil { - fmt.Println("EggCanalPersonAddActivityValueConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggCanalPersonAddActivityValueConsume_ERR", utils2.SerializeStr(map[string]interface{}{ - "body": res.Body, - "err": err.Error(), - })) - } - //_ = res.Reject(false) - //_ = res.Ack(true) - } else { - panic(errors.New("error getting message")) - } - } -} - -func handleEggCanalPersonAddActivityValueConsume(msg []byte) error { - //1.解析canal采集至mq中queue的数据结构体 - var canalMsg *md.CanalUserVirtualCoinFlowMessage[md.CanalUserVirtualCoinFlow] - err := json.Unmarshal(msg, &canalMsg) - if err != nil { - return nil - } - - year, week := time.Now().ISOWeek() - yearStr := utils2.IntToStr(year) - weekStr := utils2.IntToStr(week) - index := es2.GetAppointIndexFromAlias(yearStr, weekStr) - - settingDb := implement.NewEggEnergyBasicSettingDb(db.Db) - setting, err := settingDb.EggEnergyBasicSettingGetOne() - if err != nil { - return err - } - personEggPointsCoinId := setting.PersonEggPointsCoinId - // 2. 监听插入信息 - if canalMsg.Type == md2.CanalMsgInsertSqlType { - for _, item := range canalMsg.Data { - uid := item.Uid - id := fmt.Sprintf("%d%d_%s", year, week, uid) - - if item.CoinId != utils2.IntToStr(personEggPointsCoinId) && item.Direction != "1" { - continue - } - - // 3. 增加个人活跃积分 - amount := utils2.StrToFloat64(item.Amount) - script := elastic.NewScript("ctx._source.person_add_activity_value += params.inc").Param("inc", amount) - updateDoc, err := es.EsClient.Update(). - Index(index). - Id(id). - Script(script). - Do(context.Background()) - if err != nil { - if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { - // 蛋蛋分数据还不存在,创建蛋蛋分数据 - now := time.Now().Format("2006-01-02 15:04:05") - err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, id, utils2.StrToInt64(uid), enum.PersonAddActivityValue, utils2.Float64ToStr(amount), now) - if err1 != nil { - return err1 - } - return nil - } - fmt.Println("EggCanalPersonAddActivityValueConsumeUpdateDoc_ERR::::", err.Error()) - return err - } - fmt.Println("updateDoc==========>", updateDoc) - } - } - fmt.Println("EggCanalPersonAddActivityValueConsume_End::::::") - return nil -} diff --git a/consume/egg_canal_person_add_activity_value_consume_test.go b/consume/egg_canal_person_add_activity_value_consume_test.go deleted file mode 100644 index 01f6e28..0000000 --- a/consume/egg_canal_person_add_activity_value_consume_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package consume - -import ( - "applet/consume/md" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "testing" - "time" -) - -func TestHandleEggCanalPersonAddActivityValueConsume(t *testing.T) { - data := md.CanalUserVirtualCoinFlow{ - Id: "1", - Uid: "16", - CoinId: "3", - Direction: "1", - Title: "测试", - Amount: "40", - BeforeAmount: "0", - AfterAmount: "80", - SysFee: "0", - TransferType: "6", - } - - message := md.CanalUserVirtualCoinFlowMessage[md.CanalUserVirtualCoinFlow]{ - Data: []md.CanalUserVirtualCoinFlow{data}, - Database: "test_db", - ES: time.Now().UnixNano(), - ID: 1, - IsDdl: false, - Old: nil, - PkNames: []string{"id"}, - Table: "user_virtual_coin_flow", - TS: time.Now().Unix(), - Type: "INSERT", - } - - err := rabbit.Init("120.77.153.180", "5672", "guest", "guest") - if err != nil { - return - } - ch, err := rabbit.Cfg.Pool.GetChannel() - if err != nil { - return - } - defer ch.Release() - ch.Publish(md2.EggCanalExchange, message, "egg_canal_user_virtual_coin_flow") - -} diff --git a/consume/egg_canal_user_consume.go b/consume/egg_canal_user_consume.go deleted file mode 100644 index da88db6..0000000 --- a/consume/egg_canal_user_consume.go +++ /dev/null @@ -1,79 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - "applet/app/db" - "applet/app/utils" - "applet/app/utils/logx" - "applet/consume/md" - md2 "applet/es/md" - "code.fnuoos.com/EggPlanet/egg_system_rules.git" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/streadway/amqp" - "time" -) - -func EggCanalUserConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggCanalUserConsume>>>>>>>>>>>>") - 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 = handleEggCanalUserConsume(res.Body, ch) - err = res.Ack(true) - fmt.Println("err ::: ", err) - } else { - panic(errors.New("error getting message")) - } - } - fmt.Println("get msg done") -} - -func handleEggCanalUserConsume(msg []byte, ch *rabbit.Channel) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - var canalMsg *md.CanalUserMessage[md.CanalUser] - err := json.Unmarshal(msg, &canalMsg) - if err != nil { - fmt.Println("EggCanalInviteUserNumsConsumeFaliedUnMarshal_ERR:::::", err.Error()) - return nil - } - if canalMsg.Type == md2.CanalMsgInsertSqlType || canalMsg.Type == md2.CanalMsgUpdateSqlType { - oldUser := make(map[string]md.CanalUser) - for _, item := range canalMsg.Old { - oldUser[item.Id] = item - } - for _, item := range canalMsg.Data { - if utils.StrToInt(item.ParentUid) == 0 { - continue - } - count := rule.ExtendUserCount(db.Db, utils.StrToInt(item.ParentUid)) - if count > 1000 { - msg1 := md.CommUserId{ - Uid: item.ParentUid, - } - ch.Publish("egg.app", msg1, "egg_slow_auto_up_lv") - continue - } - rule.UserUpgradeInsert(db.Db, utils.StrToInt(item.ParentUid)) - } - } - return nil -} diff --git a/consume/egg_canal_violate_nums_consume.go b/consume/egg_canal_violate_nums_consume.go deleted file mode 100644 index 141025e..0000000 --- a/consume/egg_canal_violate_nums_consume.go +++ /dev/null @@ -1,124 +0,0 @@ -package consume - -import ( - "applet/app/db" - utils2 "applet/app/utils" - "applet/app/utils/logx" - "applet/consume/md" - md2 "applet/es/md" - "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" - es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/streadway/amqp" - "strings" - "time" -) - -// EggCanalViolateNumsConsume 更新违规次数 -func EggCanalViolateNumsConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>EggCanalViolateNumsConsume>>>>>>>>>>>>>") - 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(1000) - delivery := ch.Consume(queue.Name, true) //设置自动应答 - - var res amqp.Delivery - var ok bool - for { - res, ok = <-delivery - if ok == true { - //fmt.Println(string(res.Body)) - fmt.Println(">>>>>>>>>>>>>>>>>>EggCanalViolateNumsConsume<<<<<<<<<<<<<<<<<<<<<<<<<") - err = handleEggCanalViolateNumsConsume(res.Body) - if err != nil { - fmt.Println("EggCanalViolateNumsConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggCanalViolateNumsConsume_ERR", utils2.SerializeStr(map[string]interface{}{ - "body": res.Body, - "err": err.Error(), - })) - } - //_ = res.Reject(false) - //_ = res.Ack(true) - } else { - panic(errors.New("error getting message")) - } - } -} - -func handleEggCanalViolateNumsConsume(msg []byte) error { - //1、解析canal采集至mq中queue的数据结构体 - var canalMsg *md.CanalTagRecordsMessage[md.CanalTagRecords] - err := json.Unmarshal(msg, &canalMsg) - if err != nil { - return nil - } - - year, week := time.Now().ISOWeek() - yearStr := utils2.IntToStr(year) - weekStr := utils2.IntToStr(week) - index := es2.GetAppointIndexFromAlias(yearStr, weekStr) - // 2. 监听插入和删除信息 - if canalMsg.Type == md2.CanalMsgInsertSqlType || canalMsg.Type == md2.CanalMsgDeleteSqlType { - tagDb := implement.NewUserTagDb(db.Db) - for _, item := range canalMsg.Data { - tag, err1 := tagDb.UserTagGetOneByParams(map[string]interface{}{ - "key": "id", - "value": item.TagId, - }) - if err1 != nil { - return err1 - } - // 2.1. 判断是否为处罚标签 - if tag.IsPunish == 0 { - continue - } - uid := item.Uid - id := fmt.Sprintf("%d%d_%s", year, week, uid) - - // 2.2 计算违规次数 - sql := "SELECT COUNT(*) AS total " + - "From user_tag_records " + - "left join user_tag on user_tag_records.tag_id = user_tag.id " + - "WHERE user_tag_records.uid = %s " + - "AND user_tag.is_punish = 1" - sql = fmt.Sprintf(sql, uid) - res, err1 := db.QueryNativeString(db.Db, sql) - if err1 != nil { - return err1 - } - - // 2.3 更新违规记录 - updateMap := make(map[string]interface{}) - updateMap["violate_nums"] = utils2.StrToInt(res[0]["total"]) - updateDocRet, err := es.UpdateDoc(index, id, updateMap) - if err != nil { - if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { - // 蛋蛋分数据还不存在,创建蛋蛋分数据 - now := time.Now().Format("2006-01-02 15:04:05") - err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, id, utils2.StrToInt64(uid), enum.ViolateNums, "1", now) - if err1 != nil { - return err1 - } - return nil - } - return err - } - fmt.Println("updateDocRet ========>", updateDocRet) - } - } - - return nil -} diff --git a/consume/egg_cannal_user_virtual_ coin_flow_aggregation_consume.go b/consume/egg_cannal_user_virtual_ coin_flow_aggregation_consume.go deleted file mode 100644 index c95bd37..0000000 --- a/consume/egg_cannal_user_virtual_ coin_flow_aggregation_consume.go +++ /dev/null @@ -1,116 +0,0 @@ -package consume - -import ( - "applet/app/db" - utils2 "applet/app/utils" - "applet/app/utils/logx" - "applet/consume/md" - md2 "applet/es/md" - "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" - "code.fnuoos.com/EggPlanet/egg_models.git/src/model" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/shopspring/decimal" - "github.com/streadway/amqp" - "time" -) - -func EggCanalUserVirtualCoinFlowAggregationConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>EggCanalUserVirtualCoinFlowAggregationConsume>>>>>>>>>>>>>") - 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(50) - delivery := ch.Consume(queue.Name, true) //设置自动应答 - - var res amqp.Delivery - var ok bool - for { - res, ok = <-delivery - if ok == true { - fmt.Println(">>>>>>>>>>>>>>>>>>EggCanalUserVirtualCoinFlowAggregationConsume<<<<<<<<<<<<<<<<<<<<<<<<<") - err = handleEggCanalUserVirtualCoinFlowAggregationConsume(res.Body) - if err != nil { - fmt.Println("EggCanalUserVirtualCoinFlowAggregationConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggCanalUserVirtualCoinFlowAggregationConsume_ERR", utils2.SerializeStr(map[string]interface{}{ - "body": res.Body, - "err": err.Error(), - })) - } - //_ = res.Reject(false) - //_ = res.Ack(true) - } else { - panic(errors.New("error getting message")) - } - } -} - -func handleEggCanalUserVirtualCoinFlowAggregationConsume(msg []byte) error { - //1、解析canal采集至mq中queue的数据结构体 - var canalMsg *md.CanalUserVirtualCoinFlowAggregationMessage[md.CanalUserVirtualCoinFlowAggregation] - err := json.Unmarshal(msg, &canalMsg) - if err != nil { - return nil - } - - // 2. 监听插入信息 - if canalMsg.Type == md2.CanalMsgInsertSqlType && canalMsg.Data[0].Direction == utils2.IntToStr(1) { - //2、查找基础设置 - settingDb := implement.NewEggEnergyBasicSettingDb(db.Db) - basicSetting, err := settingDb.EggEnergyBasicSettingGetOne() - if err != nil { - return err - } - aggregationDb := implement.NewUserVirtualCoinFlowAggregationDb(db.Db) - now := time.Now() - - if canalMsg.Data[0].CoinId == utils2.IntToStr(basicSetting.PersonEggEnergyCoinId) { - userVirtualCoinFlowAggregation, err1 := aggregationDb.UserVirtualCoinFlowAggregationGetOneByParams(map[string]interface{}{ - "key": "uid", - "value": canalMsg.Data[0].Uid, - }) - if err1 != nil { - return err1 - } - if userVirtualCoinFlowAggregation == nil { - //新增记录 - _, err3 := aggregationDb.UserVirtualCoinFlowAggregationInsert(&model.UserVirtualCoinFlowAggregation{ - Uid: utils2.StrToInt(canalMsg.Data[0].Uid), - CoinId: utils2.StrToInt(canalMsg.Data[0].CoinId), - TodayData: canalMsg.Data[0].Amount, - ThisWeekData: canalMsg.Data[0].Amount, - ThisMonthData: canalMsg.Data[0].Amount, - NowData: canalMsg.Data[0].Amount, - CreateAt: now.Format("2006-01-02 15:04:05"), - UpdateAt: now.Format("2006-01-02 15:04:05"), - }) - if err3 != nil { - return err3 - } - } else { - //更新记录 - amount, _ := decimal.NewFromString(canalMsg.Data[0].Amount) - todayData, _ := decimal.NewFromString(userVirtualCoinFlowAggregation.TodayData) - thisWeekData, _ := decimal.NewFromString(userVirtualCoinFlowAggregation.ThisWeekData) - thisMonthData, _ := decimal.NewFromString(userVirtualCoinFlowAggregation.ThisWeekData) - userVirtualCoinFlowAggregation.TodayData = todayData.Add(amount).String() - userVirtualCoinFlowAggregation.ThisWeekData = thisWeekData.Add(amount).String() - userVirtualCoinFlowAggregation.ThisMonthData = thisMonthData.Add(amount).String() - userVirtualCoinFlowAggregation.NowData = canalMsg.Data[0].AfterAmount - _, err2 := aggregationDb.UserVirtualCoinFlowAggregationUpdate(userVirtualCoinFlowAggregation.Id, userVirtualCoinFlowAggregation, "today_data", "this_week_data", "this_month_data", "now_data") - if err2 != nil { - return err2 - } - } - } - } - return nil -} diff --git a/consume/egg_cannal_user_virtual_ coin_flow_aggregation_consume_test.go b/consume/egg_cannal_user_virtual_ coin_flow_aggregation_consume_test.go deleted file mode 100644 index aa9c28f..0000000 --- a/consume/egg_cannal_user_virtual_ coin_flow_aggregation_consume_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package consume - -import ( - "applet/consume/md" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "testing" - "time" -) - -func TestSendMessageToUserVirtualCoinFlowAggregationConsume(t *testing.T) { - data := md.CanalUserVirtualCoinFlowAggregation{ - Id: "1", - Uid: "19", - CoinId: "1", - Direction: "1", - Title: "兑换到个人蛋蛋能量", - Amount: "40", - BeforeAmount: "0", - AfterAmount: "80", - SysFee: "0", - TransferType: "6", - } - - message := md.CanalUserVirtualCoinFlowAggregationMessage[md.CanalUserVirtualCoinFlowAggregation]{ - Data: []md.CanalUserVirtualCoinFlowAggregation{data}, - Database: "test_db", - ES: time.Now().UnixNano(), - ID: 1, - IsDdl: false, - Old: nil, - PkNames: []string{"id"}, - Table: "user_virtual_coin_flow", - TS: time.Now().Unix(), - Type: "INSERT", - } - - err := rabbit.Init("120.77.153.180", "5672", "guest", "guest") - if err != nil { - return - } - ch, err := rabbit.Cfg.Pool.GetChannel() - if err != nil { - return - } - defer ch.Release() - ch.Publish(md2.EggCanalExchange, message, "egg_canal_user_virtual_coin_flow") - -} diff --git a/consume/egg_comment_consume.go b/consume/egg_comment_consume.go deleted file mode 100644 index 945a2bb..0000000 --- a/consume/egg_comment_consume.go +++ /dev/null @@ -1,97 +0,0 @@ -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" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "context" - "encoding/json" - "errors" - "fmt" - "github.com/olivere/elastic/v7" - "github.com/streadway/amqp" - "strings" - "time" -) - -func EggCommentDataConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggCommentDataConsume>>>>>>>>>>>>") - 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 = handleEggCommentDataConsume(res.Body) - if err != nil { - fmt.Println("EggCommentDataConsume:::::", err.Error()) - utils2.FilePutContents("EggCommentDataConsume_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 handleEggCommentDataConsume(msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md2.EggSendFriendCircleData - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - - year, week := time.Now().ISOWeek() - yearStr := utils2.IntToStr(year) - weekStr := utils2.IntToStr(week) - index := es2.GetAppointIndexFromAlias(yearStr, weekStr) - id := fmt.Sprintf("%d%d_%d", year, week, msg.Uid) - script := elastic.NewScript("ctx._source.forum_comments_nums += params.inc").Param("inc", 1) - updateDoc, err := es.EsClient.Update(). - Index(index). - Id(id). - Script(script). - Do(context.Background()) - if err != nil { - if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { - // 蛋蛋分数据还不存在,创建蛋蛋分数据 - now := time.Now().Format("2006-01-02 15:04:05") - err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, id, msg.Uid, enum.ForumCommentsNums, "1", now) - if err1 != nil { - return err1 - } - return nil - } - fmt.Println("EggCommentDataConsumeUpdateDoc_ERR::::", err.Error()) - return err - } - fmt.Println("updateDoc==========>", updateDoc) - return nil -} diff --git a/consume/egg_energy_auto_exchange_green_energy.go b/consume/egg_energy_auto_exchange_green_energy.go deleted file mode 100644 index ba3bac6..0000000 --- a/consume/egg_energy_auto_exchange_green_energy.go +++ /dev/null @@ -1,70 +0,0 @@ -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_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" -) - -func EggEnergyAutoExchangeGreenEnergyConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggEnergyAutoExchangeGreenEnergyConsume>>>>>>>>>>>>") - 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 = handleEggEnergyAutoExchangeGreenEnergyConsume(res.Body) - if err != nil { - fmt.Println("EggEnergyAutoExchangeGreenEnergyConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggEnergyAutoExchangeGreenEnergyConsume_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 handleEggEnergyAutoExchangeGreenEnergyConsume(msgData []byte) error { - //1、解析mq中queue的数据结构体 - var msg *md2.EggEnergyStructForAutoExchangeGreenEnergy - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - engine := db.Db - - //2、调用制度方法 - err = egg_energy.ActivityCoinAutoExchangeEggPersonEnergy(engine, *msg) - return err -} diff --git a/consume/egg_energy_auto_score_consume.go b/consume/egg_energy_auto_score_consume.go deleted file mode 100644 index c2173b1..0000000 --- a/consume/egg_energy_auto_score_consume.go +++ /dev/null @@ -1,140 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - utils2 "applet/app/utils" - "applet/app/utils/logx" - "applet/consume/md" - "bytes" - "code.fnuoos.com/EggPlanet/egg_system_rules.git" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/streadway/amqp" - "io/ioutil" - "net/http" - "time" -) - -func EggEnergyAutoScoreConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggEnergyAutoScoreConsume>>>>>>>>>>>>") - 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 = handleEggEnergyAutoScoreDataConsume(res.Body) - if err != nil { - fmt.Println("EggEnergyAutoScoreConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggEnergyAutoScoreConsume_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 handleEggEnergyAutoScoreDataConsume(msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md2.EggStructForAutoScoreData - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - - // 2. 请求获取预测分数 - req := md.GetPredictReq{ - Ecpm: msg.Ecpm, - InviteUserNums: msg.InviteUserNums, - TeamActivityNums: msg.TeamActivityNums, - SignInNums: msg.SignInNums, - ImActivityNums: msg.ImActivityNums, - SendRedPackageNums: msg.SendRedPackageNums, - EggEnergyExchangeAccountBalance: msg.EggEnergyExchangeAccountBalance, - AccountBalanceExchangeEggEnergyNums: msg.AccountBalanceExchangeEggEnergyNums, - SendCircleOfFriendNums: msg.SendCircleOfFriendNums, - ForumCommentsNums: msg.ForumCommentsNums, - CollegeLearningNums: msg.CollegeLearningNums, - ViolateNums: msg.ViolateNums, - BrowseInterfaceNums: msg.BrowseInterfaceNums, - PersonAddActivityValue: msg.PersonAddActivityValue, - } - - reqBytes, err := json.Marshal(req) - if err != nil { - fmt.Println("EggEnergyAutoScoreConsumeFailedMarshal_ERR:::::", err.Error()) - return err - } - - url := "http://ddf.ddstaros.cn/predict" - - request, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(reqBytes)) - if err != nil { - fmt.Println("EggEnergyAutoScoreConsumeFailedNewRequest_ERR:::::", err.Error()) - return err - } - request.Header.Set("Content-Type", "application/json") - client := &http.Client{Timeout: 5 * time.Second} // 设置请求超时时长5s - resp, err := client.Do(request) - if err != nil { - fmt.Println("EggEnergyAutoScoreConsumeFailedPostRequest_ERR:::::", err.Error()) - return err - } - defer resp.Body.Close() - - respBody, err := ioutil.ReadAll(resp.Body) - if err != nil { - fmt.Println("EggEnergyAutoScoreConsumeFailedIOReadAll_ERR:::::", err.Error()) - return err - } - - var score md.GetPredictResp - err = json.Unmarshal(respBody, &score) - if err != nil { - fmt.Println("EggEnergyAutoScoreConsumeFailedUnmarshal_ERR:::::", err.Error()) - return err - } - - // 3. 更新上周得分 - updateMap := make(map[string]interface{}) - updateMap["score_value"] = score.PredictedScore - updateMap["score_value_kind"] = 2 - now := time.Now() - lastWeek := now.AddDate(0, 0, -7) - year, week := lastWeek.ISOWeek() - yearString := utils2.IntToStr(year) - weekString := utils2.IntToStr(week) - LastWeekIndex := es2.GetAppointIndexFromAlias(yearString, weekString) - updateDocRet, err := es.UpdateDoc(LastWeekIndex, msg.DocId, updateMap) - if err != nil { - fmt.Println("EggEnergyAutoScoreConsumeFailedUpdateEs_ERR:::::", err.Error()) - return err - } - fmt.Printf("updateDoc ==> %+v \n\n", updateDocRet) - - return nil -} diff --git a/consume/egg_energy_deal_user_ecpm.go b/consume/egg_energy_deal_user_ecpm.go deleted file mode 100644 index b76041a..0000000 --- a/consume/egg_energy_deal_user_ecpm.go +++ /dev/null @@ -1,97 +0,0 @@ -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" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" - es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "context" - "encoding/json" - "errors" - "fmt" - "github.com/olivere/elastic/v7" - "github.com/streadway/amqp" - "strings" - "time" -) - -func EggEnergyDealUserECPMConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggEnergyDealUserECPMConsume>>>>>>>>>>>>") - 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 = handleEggEnergyDealUserECPMConsume(res.Body) - if err != nil { - fmt.Println("EggEnergyDealUserECPMConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggEnergyDealUserECPMConsume_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 handleEggEnergyDealUserECPMConsume(msgData []byte) error { - //1、解析mq中queue的数据结构体 - var msg *md2.DealUserEcpmReq - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - - //2、更新用户信息 - year, week := time.Now().ISOWeek() - yearStr := utils2.IntToStr(year) - weekStr := utils2.IntToStr(week) - index := es2.GetAppointIndexFromAlias(yearStr, weekStr) - id := fmt.Sprintf("%d%d_%d", year, week, msg.Uid) - - script := elastic.NewScript("ctx._source.ecpm += params.inc").Param("inc", utils2.StrToFloat64(msg.Ecpm)) - updateDocRet, err := es.EsClient.Update(). - Index(index). - Id(id). - Script(script). - Do(context.Background()) - if err != nil { - if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { - // 蛋蛋分数据还不存在,创建蛋蛋分数据 - now := time.Now().Format("2006-01-02 15:04:05") - err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, id, msg.Uid, enum.Ecpm, msg.Ecpm, now) - if err1 != nil { - return err1 - } - return nil - } - return err - } - fmt.Printf("UpdateDoc ==> %+v \n\n", updateDocRet) - return err -} diff --git a/consume/egg_energy_deal_user_ecpm_test.go b/consume/egg_energy_deal_user_ecpm_test.go deleted file mode 100644 index 3bc1e86..0000000 --- a/consume/egg_energy_deal_user_ecpm_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package consume - -import ( - "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" - "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" - "encoding/json" - "fmt" - "testing" -) - -func TestHandleEggEnergyDealUserECPMConsume(t *testing.T) { - - es.Init("http://123.57.140.192:9200", "elastic", "fnuo123") - m := md.DealUserEcpmReq{ - Uid: 16, - Ecpm: "694.704000", - } - bytes, err := json.Marshal(m) - err = handleEggEnergyDealUserECPMConsume(bytes) - if err != nil { - fmt.Println(err) - return - } -} diff --git a/consume/egg_energy_deal_user_virtual_coin_consume.go b/consume/egg_energy_deal_user_virtual_coin_consume.go deleted file mode 100644 index e787251..0000000 --- a/consume/egg_energy_deal_user_virtual_coin_consume.go +++ /dev/null @@ -1,82 +0,0 @@ -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_system_rules.git" - 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" - "time" -) - -func EggEnergyDealUserVirtualCoinDataConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggEnergyDealUserVirtualCoinDataConsume>>>>>>>>>>>>") - 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 = handleEggEnergyDealUserVirtualCoinDataConsume(res.Body) - if err != nil { - fmt.Println("EggEnergyDealUserVirtualCoinDataConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggEnergyDealUserVirtualCoinDataConsume_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 handleEggEnergyDealUserVirtualCoinDataConsume(msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md2.EggEnergyStructForDealUserVirtualCoinData - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - - engine := db.Db - session := engine.NewSession() - err = rule.DealUserVirtualCoin(session, md3.DealUserVirtualCoinReq{ - Kind: msg.Kind, - Title: msg.Title, - TransferType: msg.TransferType, - CoinId: msg.CoinId, - Uid: msg.Uid, - Amount: msg.Amount, - }) - if err != nil { - return err - } - - return session.Commit() -} diff --git a/consume/egg_energy_fund_data_consume.go b/consume/egg_energy_fund_data_consume.go deleted file mode 100644 index b1d8980..0000000 --- a/consume/egg_energy_fund_data_consume.go +++ /dev/null @@ -1,176 +0,0 @@ -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" - "code.fnuoos.com/EggPlanet/egg_system_rules.git" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/svc" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/shopspring/decimal" - "github.com/streadway/amqp" - "time" -) - -func EggEnergyDealFundDataConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggEnergyDealFundDataConsume>>>>>>>>>>>>") - 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 = handleEggEnergyDealFundDataConsume(res.Body) - if err != nil { - fmt.Println("EggEnergyDealFundDataConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggEnergyDealFundDataConsume_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 handleEggEnergyDealFundDataConsume(msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msgStr string - err := json.Unmarshal(msgData, &msgStr) - if err != nil { - return err - } - var msg *md2.EggEnergyStructForEggEnergyFundData - err = json.Unmarshal([]byte(msgStr), &msg) - if err != nil { - return err - } - now := time.Now() - - engine := db.Db - session := engine.NewSession() - session.Begin() - - // 2. 获取 fund_data 数据 - fundDataDb := implement.NewEggEnergyFundDataDb(engine) - fundDataRecordsDb := implement.NewEggEnergyFundDataRecordsDb(engine) - data, err := fundDataDb.EggEnergyFundDataGetOneByParams(map[string]interface{}{ - "key": "id", - "value": msg.ID, - }) - if err != nil { - return err - } - - // 3. 获取核心数据 - eggEnergyCoreData, cb, err2 := svc.GetEggEnergyCoreData(engine) - if err2 != nil { - return err2 - } - if cb != nil { - defer cb() // 释放锁 - } - // 4. 计算涨价公式 - err3, calcPriceIncreaseFormulaResp := egg_energy.CalcPriceIncreaseFormula(utils2.AnyToString(msg.Amount), eggEnergyCoreData) - if err3 != nil { - _ = session.Rollback() - session.Close() - return err3 - } - - // 5. 处理可用能量 - dealAvailableEggEnergyCoinReq := md2.DealAvailableEggEnergyCoinReq{ - Amount: calcPriceIncreaseFormulaResp.GetEggEnergyNums, - AmountFee: "", - BeforePrice: calcPriceIncreaseFormulaResp.BeforePrice, - AfterPrice: calcPriceIncreaseFormulaResp.AfterPrice, - BeforePlanetTotalValue: calcPriceIncreaseFormulaResp.BeforePlanetTotalValue, - AfterPlanetTotalValue: calcPriceIncreaseFormulaResp.AfterPlanetTotalValue, - BeforeEnergyTotalNums: calcPriceIncreaseFormulaResp.BeforeEnergyTotalNums, - AfterEnergyTotalNums: calcPriceIncreaseFormulaResp.AfterEnergyTotalNums, - } - err4 := egg_energy.DealAvailableEggEnergyCoin(session, int(enum.CapitalInjection), eggEnergyCoreData, dealAvailableEggEnergyCoinReq) - if err4 != nil { - fmt.Println("ActivityCoinAutoExchangeEggPersonEnergy:::::err111:::", err4) - _ = session.Rollback() - session.Close() - return err4 - } - - // 6. 计算余额 - balanceAmount := decimal.NewFromFloat(utils2.AnyToFloat64(data.BalanceAmount)). - Sub(decimal.NewFromFloat(utils2.AnyToFloat64(data.BalanceAmount))). - String() - - // 7. 插入资金数据详细数据 - record := model.EggEnergyFundDataRecords{ - RecordsId: data.Id, - TotalAmount: data.TotalAmount, - BalanceAmount: balanceAmount, - BalanceTimes: data.BalanceTimes - 1, - BeforePrice: calcPriceIncreaseFormulaResp.BeforePrice, - AfterPrice: calcPriceIncreaseFormulaResp.AfterPrice, - BeforePlanetTotalValue: calcPriceIncreaseFormulaResp.BeforePlanetTotalValue, - AfterPlanetTotalValue: calcPriceIncreaseFormulaResp.AfterPlanetTotalValue, - CreateAt: now.Format("2006-01-02 15:04:05"), - UpdateAt: now.Format("2006-01-02 15:04:05"), - } - _, err5 := fundDataRecordsDb.EggEnergyFundDataRecordsInsertBySession(session, record) - if err5 != nil { - _ = session.Rollback() - return err5 - } - - // 8. 更新当前数据 - fundData := model.EggEnergyFundData{ - Id: data.Id, - Kind: data.Kind, - TotalAmount: data.TotalAmount, - BalanceAmount: balanceAmount, - Hours: data.Hours, - BalanceTimes: data.BalanceTimes - 1, - Frequency: data.Frequency, - Memo: data.Memo, - CreateAt: data.CreateAt, - UpdateAt: now.Format("2006-01-02 15:04:05"), - } - - forceColumns := []string{ - "balance_times", - "balance_amount", - } - _, err6 := fundDataDb.EggEnergyFundDataUpdateBySession(session, fundData, forceColumns...) - if err6 != nil { - _ = session.Rollback() - return err6 - } - return session.Commit() -} diff --git a/consume/egg_energy_platform_revenue_data_consume.go b/consume/egg_energy_platform_revenue_data_consume.go deleted file mode 100644 index 6b382ea..0000000 --- a/consume/egg_energy_platform_revenue_data_consume.go +++ /dev/null @@ -1,184 +0,0 @@ -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" - "code.fnuoos.com/EggPlanet/egg_system_rules.git" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/svc" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/shopspring/decimal" - "github.com/streadway/amqp" - "time" -) - -func EggEnergyDealPlatformRevenueDataConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggEnergyDealPlatformRevenueDataConsume>>>>>>>>>>>>") - 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 = handleEggEnergyDealPlatformRevenueDataConsume(res.Body) - if err != nil { - fmt.Println("EggEnergyDealFundDataConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggEnergyDealFundDataConsume_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 handleEggEnergyDealPlatformRevenueDataConsume(msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - var msgStr string - err := json.Unmarshal(msgData, &msgStr) - if err != nil { - return err - } - - // 1.解析mq中queue的数据结构体 - var msg *md2.EggEnergyStructForPlatformRevenueData - err = json.Unmarshal([]byte(msgStr), &msg) - if err != nil { - return err - } - now := time.Now() - - engine := db.Db - session := engine.NewSession() - session.Begin() - - // 2. 获取 platform_revenue_data 数据 - revenueDataDb := implement.NewPlatformRevenueDataDb(engine) - dataRecordsDb := implement.NewPlatformRevenueDataRecordsDb(engine) - data, err := revenueDataDb.PlatformRevenueDataGetOneByParams(map[string]interface{}{ - "key": "id", - "value": msg.ID, - }) - if err != nil { - return err - } - - // 3. 获取核心数据 - eggEnergyCoreData, cb, err2 := svc.GetEggEnergyCoreData(engine) - if err2 != nil { - return err2 - } - if cb != nil { - defer cb() // 释放锁 - } - - // 4. 计算涨价 - amountValue, _ := decimal.NewFromString(msg.Amount) - planetTotalValue, _ := decimal.NewFromString(eggEnergyCoreData.PlanetTotalValue) - energyTotalNumsValue, _ := decimal.NewFromString(eggEnergyCoreData.NowEnergyTotalNums) - afterPlanetTotalValue := planetTotalValue.Add(amountValue).Truncate(8).String() - afterPrice := (planetTotalValue.Add(amountValue)).Div(energyTotalNumsValue).Truncate(16).String() //涨价后的价格 - - // 4. 计算涨价公式 - //err3, calcPriceIncreaseFormulaResp := egg_energy.CalcPriceIncreaseFormula(utils2.AnyToString(msg.Amount), eggEnergyCoreData) - //if err3 != nil { - // _ = session.Rollback() - // session.Close() - // return err3 - //} - - // 5. 处理可用能量 - dealAvailableEggEnergyCoinReq := md2.DealAvailableEggEnergyCoinReq{ - Amount: msg.Amount, - AmountFee: "", - BeforePrice: eggEnergyCoreData.NowPrice, - AfterPrice: afterPrice, - BeforePlanetTotalValue: eggEnergyCoreData.PlanetTotalValue, - AfterPlanetTotalValue: afterPlanetTotalValue, - BeforeEnergyTotalNums: eggEnergyCoreData.NowEnergyTotalNums, - AfterEnergyTotalNums: eggEnergyCoreData.NowEnergyTotalNums, - } - err4 := egg_energy.DealAvailableEggEnergyCoin(session, int(enum.PlatformProfitability), eggEnergyCoreData, dealAvailableEggEnergyCoinReq) - if err4 != nil { - fmt.Println("ActivityCoinAutoExchangeEggPersonEnergy:::::err111:::", err4) - _ = session.Rollback() - session.Close() - return err4 - } - - // 6. 计算余额 - balanceAmount := decimal.NewFromFloat(utils2.AnyToFloat64(data.BalanceAmount)). - Sub(decimal.NewFromFloat(utils2.AnyToFloat64(data.BalanceAmount))). - String() - - // 7. 插入资金数据详细数据 - record := model.PlatformRevenueDataRecords{ - RecordsId: data.Id, - TotalAmount: data.TotalAmount, - BalanceAmount: balanceAmount, - BalanceTimes: data.BalanceTimes - 1, - BeforePrice: eggEnergyCoreData.NowPrice, - AfterPrice: afterPrice, - BeforePlanetTotalValue: eggEnergyCoreData.PlanetTotalValue, - AfterPlanetTotalValue: afterPlanetTotalValue, - CreateAt: now.Format("2006-01-02 15:04:05"), - UpdateAt: now.Format("2006-01-02 15:04:05"), - } - _, err5 := dataRecordsDb.PlatformRevenueDataRecordsInsertBySession(session, record) - if err5 != nil { - _ = session.Rollback() - return err5 - } - - // 8. 更新当前数据 - PlatformRevenueData := model.PlatformRevenueData{ - Id: data.Id, - Kind: data.Kind, - TotalAmount: data.TotalAmount, - BalanceAmount: balanceAmount, - Hours: data.Hours, - BalanceTimes: data.BalanceTimes - 1, - Frequency: data.Frequency, - Memo: data.Memo, - CreateAt: data.CreateAt, - UpdateAt: now.Format("2006-01-02 15:04:05"), - } - - forceColumns := []string{ - "balance_times", - "balance_amount", - } - _, err6 := revenueDataDb.PlatformRevenueDataUpdateBySession(session, PlatformRevenueData, forceColumns...) - if err6 != nil { - _ = session.Rollback() - return err6 - } - return session.Commit() -} diff --git a/consume/egg_energy_settlement_public_give_activity_coin_consume.go b/consume/egg_energy_settlement_public_give_activity_coin_consume.go deleted file mode 100644 index b004d2b..0000000 --- a/consume/egg_energy_settlement_public_give_activity_coin_consume.go +++ /dev/null @@ -1,83 +0,0 @@ -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_system_rules.git" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/streadway/amqp" -) - -func EggEnergySettlementPublicGiveActivityCoinConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggEnergySettlementPublicGiveActivityCoinConsume>>>>>>>>>>>>") - 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 = handleEggEnergySettlementPublicGiveActivityCoinConsume(res.Body) - if err != nil { - fmt.Println("EggEnergySettlementPublicGiveActivityCoinConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggEnergySettlementPublicGiveActivityCoinConsume_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 handleEggEnergySettlementPublicGiveActivityCoinConsume(msgData []byte) error { - //1、解析mq中queue的数据结构体 - var msg *md2.DealUserVirtualCoinReq - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - engine := db.Db - session := engine.NewSession() - defer func() { - session.Close() - if err := recover(); err != nil { - _ = logx.Error(err) - } - }() - session.Begin() - - //2、给相应的用户加上个人的团队活跃积分 - err = rule.DealUserVirtualCoin(session, *msg) - if err != nil { - session.Rollback() - return err - } - - //3、判断是否今天已 - return session.Commit() -} diff --git a/consume/egg_energy_start_exchange_green_energy.go b/consume/egg_energy_start_exchange_green_energy.go deleted file mode 100644 index ce54b1a..0000000 --- a/consume/egg_energy_start_exchange_green_energy.go +++ /dev/null @@ -1,73 +0,0 @@ -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_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" -) - -func EggEnergyStartExchangeGreenEnergyConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggEnergyStartExchangeGreenEnergyConsume>>>>>>>>>>>>") - 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 = handleEggEnergyStartExchangeGreenEnergyConsume(res.Body, ch) - if err != nil { - fmt.Println("EggEnergyStartExchangeGreenEnergyConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggEnergyStartExchangeGreenEnergyConsume_ERR", utils2.SerializeStr(map[string]interface{}{ - "body": res.Body, - "err": err.Error(), - })) - _ = res.Reject(false) //TODO::拒绝 true - var msg *md2.EggEnergyStructForStartExchangeGreenEnergy - json.Unmarshal(res.Body, &msg) - ch.Publish(queue.ExchangeName, msg, queue.RoutKey) - } else { - err = res.Ack(true) - fmt.Println("err ::: ", err) - } - } else { - panic(errors.New("error getting message")) - } - } - fmt.Println("get msg done") -} - -func handleEggEnergyStartExchangeGreenEnergyConsume(msgData []byte, ch *rabbit.Channel) error { - //1、解析mq中queue的数据结构体 - var msg *md2.EggEnergyStructForStartExchangeGreenEnergy - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - engine := db.Db - - //2、调用制度方法 - err = egg_energy.ActivityCoinStartExchangeEggEnergy(engine, *msg, ch) - return err -} diff --git a/consume/egg_energy_start_level_dividend_consume.go b/consume/egg_energy_start_level_dividend_consume.go deleted file mode 100644 index c0bdb41..0000000 --- a/consume/egg_energy_start_level_dividend_consume.go +++ /dev/null @@ -1,106 +0,0 @@ -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_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" - "time" -) - -func EggEnergyStartLevelDividendConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggEnergyStartLevelDividendConsume>>>>>>>>>>>>") - 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 = handleEggEnergyStartLevelDividendConsume(res.Body) - if err != nil { - fmt.Println("EggEnergyStartLevelDividendConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggEnergyStartLevelDividendConsume_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 handleEggEnergyStartLevelDividendConsume(msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - //1、解析mq中queue的数据结构体 - var msg *md2.EggEnergyStructForStarLevelDividends - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - engine := db.Db - //2、查找 `egg_energy_basic_setting` 基础设置 - eggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(engine) - eggEnergyBasicSetting, err := eggEnergyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ - "key": "is_open", - "value": 1, - }) - if err != nil { - return err - } - if eggEnergyBasicSetting == nil { - return errors.New("蛋蛋能量设置未开启!") - } - - //3、给相应的用户加上个人的团队绿色能量 - session := engine.NewSession() - defer func() { - session.Close() - if err := recover(); err != nil { - _ = logx.Error(err) - } - }() - session.Begin() - - err = rule.DealUserVirtualCoin(session, md3.DealUserVirtualCoinReq{ - Kind: "add", - Title: enum.UserVirtualAmountFlowTransferType.String(enum.SettlementStarLevelDividends), - TransferType: int(enum.SettlementStarLevelDividends), - CoinId: eggEnergyBasicSetting.TeamEggEnergyCoinId, - Uid: msg.Uid, - Amount: msg.SignDividend, - }) - if err != nil { - session.Rollback() - return err - } - return session.Commit() -} diff --git a/consume/egg_energy_team_assistance_consume.go b/consume/egg_energy_team_assistance_consume.go deleted file mode 100644 index 78dc3b2..0000000 --- a/consume/egg_energy_team_assistance_consume.go +++ /dev/null @@ -1,129 +0,0 @@ -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" - "code.fnuoos.com/EggPlanet/egg_system_rules.git" - 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 EggEnergyTeamAssistanceConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggEnergyTeamAssistanceConsume>>>>>>>>>>>>") - 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(50) - 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 = handleEggEnergyTeamAssistanceDataConsume(res.Body) - if err != nil { - fmt.Println("EggEnergyTeamAssistanceConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggEnergyTeamAssistance_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 handleEggEnergyTeamAssistanceDataConsume(msgData []byte) error { - time.Sleep(time.Duration(10) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md2.EggEnergyTeamAssistanceReq - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - - // 2.查询数据库数据用户是否已经助力过 - detailDb := implement.NewEggEnergyAssistanceDetailDb(db.Db) - exist, err := detailDb.AssistanceDetailExist(msg.Uid, msg.AssistanceUid, msg.SignId) - if err != nil { - return err - } - now := time.Now() - if !exist { - //插入助力数据 - detail := model.EggEnergyAssistanceDetail{ - Uid: msg.Uid, - AssistedUid: msg.AssistanceUid, - SignId: msg.SignId, - CreatedAt: now.Format("2006-01-02 15:04:05"), - UpdatedAt: now.Format("2006-01-02 15:04:05"), - } - _, err = detailDb.AssistanceDetailInsert(&detail) - if err != nil { - return err - } - } - - // 3. 变更数据 - assistanceDb := implement.NewEggEnergyTeamAssistanceDb(db.Db) - date := now.Format("2006-01-02") - session := db.Db.Where("") - teamAssistance, err := assistanceDb.EggEnergyTeamAssistanceGetOneByParamsBySession(session, map[string]interface{}{ - "key": "sign_id", - "value": msg.SignId, - }) - if err != nil { - return err - } - if teamAssistance == nil { - m := model.EggEnergyTeamAssistance{ - Uid: msg.Uid, - AssistedNum: 1, - AssistedTimes: 1, - RewardScore: utils2.Float64ToStr(msg.AssistanceValue), - Date: date, - SignId: msg.SignId, - CreateAt: now.Format("2006-01-02 15:04:05"), - UpdateAt: now.Format("2006-01-02 15:04:05"), - } - _, err = assistanceDb.EggEnergyTeamAssistanceInsert(&m) - if err != nil { - return err - } - } else { - teamAssistance.RewardScore = utils2.Float64ToStr(msg.AssistanceValue + utils2.StrToFloat64(teamAssistance.RewardScore)) - // 如果未助力过, 助力人数 + 1 添加助力信息 - if !exist { - teamAssistance.AssistedNum++ - } - teamAssistance.AssistedTimes++ - _, err = assistanceDb.EggEnergyTeamAssistanceUpdate(teamAssistance.Id, teamAssistance, "assisted_num", "reward_score", "assisted_times") - if err != nil { - return err - } - } - - return nil -} diff --git a/consume/egg_energy_team_assistance_consume_test.go b/consume/egg_energy_team_assistance_consume_test.go deleted file mode 100644 index 3b1ef6e..0000000 --- a/consume/egg_energy_team_assistance_consume_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - "applet/app/db" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "fmt" - "testing" -) - -func TestEggEnergyTeamAssistanceConsume(t *testing.T) { - dbcfg := cfg.DBCfg{ - Host: "119.23.182.117:3306", - Name: "egg", - User: "root", - Psw: "Fnuo123com@", - ShowLog: true, - MaxLifetime: 30, - MaxOpenConns: 100, - MaxIdleConns: 100, - Path: "tmp/%s.log", - } - db.InitDB(&dbcfg) - err := rabbit.Init("120.77.153.180", "5672", "guest", "guest") - if err != nil { - return - } - ch, err := rabbit.Cfg.Pool.GetChannel() - if err != nil { - fmt.Println("DealFundDataGetRabbitChannel_ERR:::::", err.Error()) - return - } - defer ch.Release() - ch.Publish(md2.EggEnergyExchange, md2.EggEnergyTeamAssistanceReq{ - AssistanceUid: 19, - Uid: 2, - AssistanceValue: 100, - SignStart: "2024-12-20 08:00:00", - SignEnd: "2024-12-21 08:00:00", - SignId: 13, - }, md2.EggEnergyTeamAssistance) -} diff --git a/consume/egg_energy_user_activity_consume.go b/consume/egg_energy_user_activity_consume.go deleted file mode 100644 index 2eb4439..0000000 --- a/consume/egg_energy_user_activity_consume.go +++ /dev/null @@ -1,83 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - "applet/app/db" - "applet/app/utils" - md2 "applet/es/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/rule" - - "applet/app/utils/logx" - "applet/consume/md" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/streadway/amqp" - "time" -) - -func EggEnergyUserActivityConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggEnergyUserActivityConsume>>>>>>>>>>>>") - 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 = handleEggEnergyUserActivityConsume(res.Body, ch) - err = res.Ack(true) - fmt.Println("err ::: ", err) - } else { - panic(errors.New("error getting message")) - } - } - fmt.Println("get msg done") -} - -func handleEggEnergyUserActivityConsume(msg []byte, ch *rabbit.Channel) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - var canalMsg *md.CanalEggEnergyUserActivityMessage[md.CanalEggEnergyUserActivity] - err := json.Unmarshal(msg, &canalMsg) - if err != nil { - fmt.Println("EggCanalInviteUserNumsConsumeFaliedUnMarshal_ERR:::::", err.Error()) - return nil - } - if canalMsg.Type == md2.CanalMsgInsertSqlType { - for _, item := range canalMsg.Data { - userDb := implement.NewUserDb(db.Db) - user, _ := userDb.GetUser(utils.StrToInt64(item.Uid)) - if user == nil { - continue - } - if user.ParentUid == 0 { - continue - } - count := rule.ExtendUserCount(db.Db, int(user.ParentUid)) - if count > 1000 { - msg1 := md.CommUserId{ - Uid: utils.Int64ToStr(user.ParentUid), - } - ch.Publish("egg.app", msg1, "egg_slow_auto_up_lv") - continue - } - rule.UserUpgradeInsert(db.Db, int(user.ParentUid)) - } - } - - return nil -} diff --git a/consume/egg_fin_withdraw_apply_consume.go b/consume/egg_fin_withdraw_apply_consume.go deleted file mode 100644 index f291388..0000000 --- a/consume/egg_fin_withdraw_apply_consume.go +++ /dev/null @@ -1,256 +0,0 @@ -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" - "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/sys_cfg" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "context" - "encoding/json" - "errors" - "fmt" - "github.com/go-pay/gopay" - "github.com/go-pay/gopay/alipay" - "github.com/go-pay/xlog" - "github.com/streadway/amqp" - "time" -) - -func EggFinWithdrawApplyDataConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggFinWithdrawApplyDataConsume>>>>>>>>>>>>") - 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 alipayStruct *InitAlipayStruct - client, err := InitAlipay(alipayStruct) - if err != nil { - fmt.Println("EggFinWithdrawApplyDataConsume:::::", err.Error()) - utils2.FilePutContents("EggFinWithdrawApplyDataConsume", utils2.SerializeStr(map[string]interface{}{ - "err": err.Error(), - })) - return - } - var res amqp.Delivery - var ok bool - for { - res, ok = <-delivery - if ok == true { - err = handleEggFinWithdrawApplyDataConsume(res.Body, client, ch) - if err != nil { - fmt.Println("EggFinWithdrawApplyDataConsume:::::", err.Error()) - utils2.FilePutContents("EggFinWithdrawApplyDataConsume", utils2.SerializeStr(map[string]interface{}{ - "body": res.Body, - "err": err.Error(), - })) - //// 如果需要重试 推回队尾 - //if err.Error() == "Lock wait timeout exceeded; try restarting transaction" { - // var msg *md.CommUserId - // json.Unmarshal(res.Body, &msg) - // ch.Publish(queue.ExchangeName, msg, queue.RoutKey) - //} - - var data md2.EggFinWithdrawApplyErrorData - data.ErrorInfo = err.Error() - // 尝试解析数据结构体 - var msg *md2.EggFinWithdrawApplyData - err1 := json.Unmarshal(res.Body, &msg) - if err1 != nil { - // 无法解析 直接将[]byte推进队列 - data.Ext = res.Body - } else { - // 解析成功 - data.EggFinWithdrawApplyData = *msg - } - ch.Publish(md2.EggAppExchange, data, md2.EggFinWithdrawApplyError) - } - //_ = res.Reject(false) - err = res.Ack(true) - fmt.Println("err ::: ", err) - } else { - panic(errors.New("error getting message")) - } - } -} - -func handleEggFinWithdrawApplyDataConsume(msgData []byte, client *alipay.Client, ch *rabbit.Channel) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md2.EggFinWithdrawApplyData - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - - applyDb := implement.NewFinWithdrawApplyDb(db.Db) - apply, err := applyDb.FinWithdrawApplyGet(msg.Id) - if err != nil { - return err - } - if apply == nil { - return errors.New("提现记录不存在~") - } - - // 如果不在队列处理阶段或不是自动处理订单,直接返回 - if apply.State != 4 && apply.Type != 2 { - return errors.New("提现记录无需处理~") - } - - // 2.3 更新 apply 信息 - apply.State = 2 - affected, err2 := applyDb.UpdateFinWithdrawApply(apply, "state") - if err2 != nil { - return err2 - } - if affected == 0 { - return errors.New("更新 apply 状态失败") - } - - if msg.WithdrawKind == 1 { - // 3.支付宝提现 - alipayUserInfoDb := implement.NewAlipayUserInfoDb(db.Db) - userInfo, err1 := alipayUserInfoDb.GetAlipayUserInfo(msg.Uid) - if err != nil { - return err1 - } - bm := make(gopay.BodyMap) - bm.Set("out_biz_no", msg.Id). - Set("trans_amount", msg.Amount). - Set("biz_scene", "DIRECT_TRANSFER"). - Set("product_code", "TRANS_ACCOUNT_NO_PWD"). - Set("product_code", "TRANS_ACCOUNT_NO_PWD"). - Set("business_params", "{\"payer_show_name_use_alias\":\"true\"}"). - SetBodyMap("payee_info", func(bm gopay.BodyMap) { - bm.Set("identity", userInfo.OpenId) - bm.Set("identity_type", "ALIPAY_OPEN_ID") - }) - _, err = client.FundTransUniTransfer(context.Background(), bm) - if err != nil { - //TODO::处理提现失败 - err11 := dealFinWithdrawApplyStateForBad(apply) - if err11 != nil { - return errors.New("处理提现失败:" + err11.Error()) - } - return err - } - } else if msg.WithdrawKind == 2 { - - } - - return nil -} - -func dealFinWithdrawApplyStateForBad(finWithdrawApply *model.FinWithdrawApply) error { - session := db.Db.NewSession() - defer session.Close() - session.Begin() - - finWithdrawApplyDb := implement.NewFinWithdrawApplyDb(db.Db) - finWithdrawApply.State = int(enum.FinWithdrawApplyStateForBad) - updateAffected, err1 := finWithdrawApplyDb.UpdateFinWithdrawApplyBySession(session, finWithdrawApply, "state") - if err1 != nil { - return err1 - } - if updateAffected <= 0 { - return errors.New("更新提现单状态失败") - } - dealUserWalletReq := md3.DealUserWalletReq{ - Direction: "add", - Kind: int(enum.UserWithdrawBad), - Title: enum.UserWithdrawBad.String(), - Uid: finWithdrawApply.Uid, - Amount: utils2.StrToFloat64(finWithdrawApply.Amount), - } - - err := rule.DealUserWallet(session, dealUserWalletReq) - if err != nil { - session.Rollback() - return err - } - - err = session.Commit() - if err != nil { - _ = session.Rollback() - } - return err -} - -type InitAlipayStruct struct { - IsProd bool `json:"is_prod" label:"是否生产环境"` - AlipayAppId string `json:"alipay_app_id" label:"支付宝商家应用appid"` - AlipayPrivateKey string `json:"alipay_private_key" label:"支付宝商家应用私钥"` - AlipayPublicKey string `json:"alipay_public_key" label:"支付宝商家应用公钥"` - AlipayPublicContentRSA2 []byte `json:"alipay_public_content_rsa_2" label:"支付宝公钥证书"` - AlipayRootContent []byte `json:"alipay_root_content" label:"支付宝根证书"` - AppPublicContent []byte `json:"app_public_content" label:"应用公钥证书"` -} - -// InitAlipay 初始化支付宝客户端 -// appid:应用ID -// privateKey:应用私钥,支持PKCS1和PKCS8 -// isProd:是否是正式环境,沙箱环境请选择新版沙箱应用。 -func InitAlipay(initData *InitAlipayStruct) (client *alipay.Client, err error) { - if initData == nil { - sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) - sysCfgMap := sysCfgDb.SysCfgFindWithDb(enum.AlipayAppId, enum.AlipayPrivateKey, enum.AlipayPublicKey, enum.AlipayPublicContentRSA2, enum.AlipayRootContent, enum.AppPublicContent) - initData = &InitAlipayStruct{ - IsProd: true, - AlipayAppId: sysCfgMap[enum.AlipayAppId], - AlipayPrivateKey: sysCfgMap[enum.AlipayPrivateKey], - AlipayPublicKey: sysCfgMap[enum.AlipayPublicKey], - AlipayPublicContentRSA2: []byte(sysCfgMap[enum.AlipayPublicContentRSA2]), - AlipayRootContent: []byte(sysCfgMap[enum.AlipayRootContent]), - AppPublicContent: []byte(sysCfgMap[enum.AppPublicContent]), - } - } - client, err = alipay.NewClient(initData.AlipayAppId, initData.AlipayPrivateKey, initData.IsProd) - if err != nil { - xlog.Error(err) - return - } - - // 自定义配置http请求接收返回结果body大小,默认 10MB - client.SetBodySize(10) // 没有特殊需求,可忽略此配置 - - // 打开Debug开关,输出日志,默认关闭 - client.DebugSwitch = gopay.DebugOn - - client.SetLocation(alipay.LocationShanghai). // 设置时区,不设置或出错均为默认服务器时间 - SetCharset(alipay.UTF8). // 设置字符编码,不设置默认 utf-8 - SetSignType(alipay.RSA2) // 设置签名类型,不设置默认 RSA2 - - // SetAppAuthToken("") //授权token - - //SetReturnUrl("https://www.fmm.ink"). // 设置返回URL - // SetNotifyUrl("https://www.fmm.ink"). // 设置异步通知URL - - // 传入 支付宝公钥证书 alipayPublicCert.crt 内容 - client.AutoVerifySign(initData.AlipayPublicContentRSA2) - - // 传入证书内容 - err = client.SetCertSnByContent(initData.AppPublicContent, initData.AlipayRootContent, initData.AlipayPublicContentRSA2) - if err != nil { - xlog.Debug("SetCertSn:", err) - return - } - - return -} diff --git a/consume/egg_fin_withdraw_apply_consume_test.go b/consume/egg_fin_withdraw_apply_consume_test.go deleted file mode 100644 index 0bce56a..0000000 --- a/consume/egg_fin_withdraw_apply_consume_test.go +++ /dev/null @@ -1,54 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - "applet/app/db" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "fmt" - "testing" -) - -func TestHandleEggFinWithdrawApplyDataConsume(t *testing.T) { - dbcfg := cfg.DBCfg{ - Host: "119.23.182.117:3306", - Name: "egg", - User: "root", - Psw: "Fnuo123com@", - ShowLog: true, - MaxLifetime: 30, - MaxOpenConns: 100, - MaxIdleConns: 100, - Path: "tmp/%s.log", - } - db.InitDB(&dbcfg) - err := rabbit.Init("120.77.153.180", "5672", "guest", "guest") - if err != nil { - return - } - ch, err := rabbit.Cfg.Pool.GetChannel() - if err != nil { - fmt.Println("DealFundDataGetRabbitChannel_ERR:::::", err.Error()) - return - } - defer ch.Release() - ch.Publish(md2.EggAppExchange, md2.EggFinWithdrawApplyData{ - Id: 1, - Uid: 2, - AdmId: 3, - Amount: "10", - RealAmount: "10", - Fee: "4", - Type: 1, - WithdrawAccount: "3", - WithdrawName: "2", - Reason: 2, - PaymentDate: "2", - State: 2, - WithdrawKind: 2, - IsFirst: 2, - Memo: "测试报错例子2", - UpdateAt: "", - CreateAt: "", - }, md2.EggFinWithdrawApply) -} diff --git a/consume/egg_new_user_register_consume.go b/consume/egg_new_user_register_consume.go deleted file mode 100644 index 2c767bb..0000000 --- a/consume/egg_new_user_register_consume.go +++ /dev/null @@ -1,102 +0,0 @@ -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" - "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 - } - - // 3. 更新新增人数 - now := time.Now().Format("2006-01-02") - growDataDb := implement.NewPlatformGrowDataDb(db.Db) - growData, err := growDataDb.PlatformGrowDataGetOneByParams(map[string]interface{}{ - "key": "date", - "value": now, - }) - if err != nil { - return err - } - if growData != nil { - growData.UserGrowCount++ - _, err = growDataDb.PlatformGrowDataUpdate(growData, "user_grow_count") - if err != nil { - return err - } - } else { - m := model.PlatformGrowData{ - UserGrowCount: 1, - Date: now, - } - _, err = growDataDb.PlatformGrowDataInsert(&m) - if err != nil { - return err - } - } - - return nil -} diff --git a/consume/egg_record_active_consume.go b/consume/egg_record_active_consume.go deleted file mode 100644 index 5f233cd..0000000 --- a/consume/egg_record_active_consume.go +++ /dev/null @@ -1,135 +0,0 @@ -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_system_rules.git" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "context" - "encoding/json" - "errors" - "fmt" - "github.com/olivere/elastic/v7" - "github.com/streadway/amqp" - "strings" - "time" -) - -// EggRecordActiveDataConsume 更新团队活跃次数和签到次数 -func EggRecordActiveDataConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggRecordActiveDataConsume>>>>>>>>>>>>") - 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 = handleEggRecordActiveDataConsume(res.Body) - if err != nil { - fmt.Println("EggRecordActiveDataConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggRecordActiveDataConsume_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 handleEggRecordActiveDataConsume(msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md2.EggStructForRecordActiveData - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - - year, week := time.Now().ISOWeek() - yearStr := utils2.IntToStr(year) - weekStr := utils2.IntToStr(week) - index := es2.GetAppointIndexFromAlias(yearStr, weekStr) - - // 2.获取用户直推上级 - userRelateDb := implement.NewUserRelateDb(db.Db) - userRelate, err := userRelateDb.GetUserParentUserRelate(msg.Uid) - if err != nil { - return err - } - - // 3.添加团队活跃次数 - if userRelate != nil { - parentUid := userRelate.ParentUid - parentEsId := fmt.Sprintf("%d%d_%d", year, week, parentUid) - // 增加团队活跃次数记录 - script := elastic.NewScript("ctx._source.team_activity_nums += params.inc").Param("inc", 1) - _, err = es.EsClient.Update(). - Index(index). - Id(parentEsId). - Script(script). - Do(context.Background()) - if err != nil { - if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { - // 蛋蛋分数据还不存在,创建蛋蛋分数据 - now := time.Now().Format("2006-01-02 15:04:05") - err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, parentEsId, parentUid, enum.TeamActivityNums, "1", now) - if err1 != nil { - return err1 - } - } else { - return err - } - } - } - - // 4.更新签到次数 - esId := fmt.Sprintf("%d%d_%d", year, week, msg.Uid) - script := elastic.NewScript(` - ctx._source.sign_in_nums += params.signInInc; - `).Param("signInInc", 1) - - _, err = es.EsClient.Update(). - Index(index). - Id(esId). - Script(script). - Do(context.Background()) - if err != nil { - if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { - // 蛋蛋分数据还不存在,创建蛋蛋分数据 - now := time.Now().Format("2006-01-02 15:04:05") - err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, esId, msg.Uid, enum.SignInNums, "1", now) - if err1 != nil { - return err1 - } - return nil - } - return err - } - return nil -} diff --git a/consume/egg_send_friend_circle_consume.go b/consume/egg_send_friend_circle_consume.go deleted file mode 100644 index e1c7eab..0000000 --- a/consume/egg_send_friend_circle_consume.go +++ /dev/null @@ -1,97 +0,0 @@ -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" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "context" - "encoding/json" - "errors" - "fmt" - "github.com/olivere/elastic/v7" - "github.com/streadway/amqp" - "strings" - "time" -) - -func EggSendFriendCircleDataConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggSendFriendCircleDataConsume>>>>>>>>>>>>") - 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 = handleEggSendFriendCircleDataConsume(res.Body) - if err != nil { - fmt.Println("EggSendFriendCircleDataConsume_ERR:::::", err.Error()) - utils2.FilePutContents("EggSendFriendCircleDataConsume_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 handleEggSendFriendCircleDataConsume(msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md2.EggSendFriendCircleData - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - - year, week := time.Now().ISOWeek() - yearStr := utils2.IntToStr(year) - weekStr := utils2.IntToStr(week) - index := es2.GetAppointIndexFromAlias(yearStr, weekStr) - id := fmt.Sprintf("%d%d_%d", year, week, msg.Uid) - script := elastic.NewScript("ctx._source.send_circle_of_friend_nums += params.inc").Param("inc", 1) - updateDoc, err := es.EsClient.Update(). - Index(index). - Id(id). - Script(script). - Do(context.Background()) - if err != nil { - if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { - // 蛋蛋分数据还不存在,创建蛋蛋分数据 - now := time.Now().Format("2006-01-02 15:04:05") - err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, id, msg.Uid, enum.SendCircleOfFriendNums, "1", now) - if err1 != nil { - return err1 - } - return nil - } - fmt.Println("EggSendFriendCircleDataConsumeUpdateDoc_ERR::::", err.Error()) - return err - } - fmt.Println("updateDoc==========>", updateDoc) - return nil -} diff --git a/consume/egg_slow_auto_up_lv_consume.go b/consume/egg_slow_auto_up_lv_consume.go deleted file mode 100644 index df8ed48..0000000 --- a/consume/egg_slow_auto_up_lv_consume.go +++ /dev/null @@ -1,60 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - "applet/app/db" - "applet/app/utils" - "code.fnuoos.com/EggPlanet/egg_system_rules.git" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule" - - "applet/app/utils/logx" - "applet/consume/md" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/streadway/amqp" - "time" -) - -func EggSlowAutoUpLvConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggSlowAutoUpLvConsume>>>>>>>>>>>>") - 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 = handleEggSlowAutoUpLvConsume(res.Body) - err = res.Ack(true) - fmt.Println("err ::: ", err) - } else { - panic(errors.New("error getting message")) - } - } - fmt.Println("get msg done") -} - -func handleEggSlowAutoUpLvConsume(msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md.CommUserId - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - rule.UserUpgradeInsert(db.Db, utils.StrToInt(msg.Uid)) - return nil -} diff --git a/consume/im_egg_energy_batch_send_message_consume.go b/consume/im_egg_energy_batch_send_message_consume.go deleted file mode 100644 index 8127f5b..0000000 --- a/consume/im_egg_energy_batch_send_message_consume.go +++ /dev/null @@ -1,86 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - utils2 "applet/app/utils" - "applet/app/utils/logx" - "applet/consume/md" - "applet/pkg/pb" - "code.fnuoos.com/EggPlanet/egg_system_rules.git" - 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" - "google.golang.org/protobuf/proto" - "time" -) - -func IMEggEnergyBatchSendMessageDataConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>IMEggEnergyBatchSendMessageDataConsume>>>>>>>>>>>>") - 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 = handleIMEggEnergyBatchSendMessageDataConsume(res.Body) - if err != nil { - fmt.Println("IMEggEnergyBatchSendMessageDataConsume_ERR:::::", err.Error()) - utils2.FilePutContents("IMEggEnergyBatchSendMessageDataConsume_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 handleIMEggEnergyBatchSendMessageDataConsume(msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md2.IMEggEnergyStructForBatchSendMessageData - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - - //TODO::调用im GRPC 接口 - buf, err := proto.Marshal(&pb.Text{ - Text: msg.Content, - }) - - _, err = utils2.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).SendMessage(utils2.GetCtx("", utils2.Int64ToStr(msg.SendId), "", ""), &pb.SendMessageReq{ - ReceiverType: pb.ReceiverType(msg.ReceiverType), - ReceiverId: msg.ReceiveIMId, - ToUserIds: nil, - MessageType: pb.MessageType(msg.MessageType), - MessageContent: buf, - SendTime: utils2.UnixMilliTime(time.Now()), - IsPersist: true, - MessageContentBack: "", - }) - if err != nil { - return err - } - - return nil -} diff --git a/consume/im_egg_energy_del_friend_circle_comment_consume.go b/consume/im_egg_energy_del_friend_circle_comment_consume.go deleted file mode 100644 index fa16e42..0000000 --- a/consume/im_egg_energy_del_friend_circle_comment_consume.go +++ /dev/null @@ -1,77 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - utils2 "applet/app/utils" - "applet/app/utils/cache" - "applet/app/utils/logx" - "applet/consume/md" - "code.fnuoos.com/EggPlanet/egg_system_rules.git" - md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/streadway/amqp" - "time" -) - -func IMEggEnergyDelFriendCircleDataConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>IMEggEnergyDelFriendCircleDataConsume>>>>>>>>>>>>") - 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 = handleIMEggEnergyDelFriendCircleCommentDataConsume(res.Body) - if err != nil { - fmt.Println("IMEggEnergyDelFriendCircleDataConsume_ERR:::::", err.Error()) - utils2.FilePutContents("IMEggEnergyDelFriendCircleDataConsume_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 handleIMEggEnergyDelFriendCircleCommentDataConsume(msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md2.IMEggEnergyStructForDelFriendCircleCommentData - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - - //1、删除es数据 - _, err = es.DeleteDoc(md3.EggFriendCircleCommentEsAlias, msg.CommentIndexId) - if err != nil { - return err - } - - //2、删除redis数据 - key := fmt.Sprintf(md3.CommentLikeCacheKey, msg.CommentIndexId) - cache.Del(key) - return nil -} diff --git a/consume/im_egg_energy_send_red_package_consume.go b/consume/im_egg_energy_send_red_package_consume.go deleted file mode 100644 index 5d72789..0000000 --- a/consume/im_egg_energy_send_red_package_consume.go +++ /dev/null @@ -1,96 +0,0 @@ -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" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" - md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "context" - "encoding/json" - "errors" - "fmt" - "github.com/olivere/elastic/v7" - "github.com/streadway/amqp" - "strings" - "time" -) - -func IMEggEnergySendRedPackageConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>IMEggEnergySendRedPackageConsume>>>>>>>>>>>>") - 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 = handleIMEggEnergySendRedPackageConsume(res.Body) - if err != nil { - fmt.Println("IMEggEnergySendRedPackageConsume_ERR:::::", err.Error()) - utils2.FilePutContents("IMEggEnergySendRedPackageConsume_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 handleIMEggEnergySendRedPackageConsume(msgData []byte) error { - //1、解析mq中queue的数据结构体 - var msg *md3.IMEggEnergyStructForSendRedPackageData - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - - //2、更新用户信息 - year, week := time.Now().ISOWeek() - yearStr := utils2.IntToStr(year) - weekStr := utils2.IntToStr(week) - index := es2.GetAppointIndexFromAlias(yearStr, weekStr) - id := fmt.Sprintf("%d%d_%d", year, week, msg.Uid) - // 3.新增发红包次数 - script := elastic.NewScript("ctx._source.send_red_package_nums += params.inc").Param("inc", 1) - _, err = es.EsClient.Update(). - Index(index). - Id(id). - Script(script). - Do(context.Background()) - if err != nil { - if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { - // 蛋蛋分数据还不存在,创建蛋蛋分数据 - now := time.Now().Format("2006-01-02 15:04:05") - err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, id, msg.Uid, enum.SendRedPackageNums, "1", now) - if err1 != nil { - return err1 - } - return nil - } - return err - } - return err -} diff --git a/consume/init.go b/consume/init.go index 5a1bdbb..92ae745 100644 --- a/consume/init.go +++ b/consume/init.go @@ -17,44 +17,9 @@ func Init() { // 增加消费任务队列 func initConsumes() { - jobs[consumeMd.EggSlowAutoUpLvConsume] = EggSlowAutoUpLvConsume //缓慢 自动升级 - jobs[consumeMd.EggEnergyUserActivityConsume] = EggEnergyUserActivityConsume //监听 自动升级 - jobs[consumeMd.EggCanalUserConsume] = EggCanalUserConsume //监听 自动升级 - - jobs[consumeMd.AliyunSmsRecordFunName] = AliyunSmsRecordConsume //阿里云短信 - jobs[consumeMd.JpushRecordFunName] = JpushRecordConsume //极光推送 - jobs[consumeMd.UserDeleteFunName] = UserDeleteConsume // 用户注销处理 - - jobs[consumeMd.EggEnergyNewUserRegisterDataFunName] = EggEnergyNewUserRegisterDataConsume // 新用户注册 - jobs[consumeMd.IMEggEnergyBatchSendMessageDataFunName] = IMEggEnergyBatchSendMessageDataConsume // 批量发送信息 - jobs[consumeMd.IMEggEnergyDelFriendCircleDataFunName] = IMEggEnergyDelFriendCircleDataConsume // 删除朋友圈 - jobs[consumeMd.EggFinWithdrawApplyDataConsumeFunName] = EggFinWithdrawApplyDataConsume // 提现 - - jobs[consumeMd.EggEnergyDealUserECPMFunName] = EggEnergyDealUserECPMConsume // 处理给用户Ecpm值 - jobs[consumeMd.EggCanalInviteUserNumsFunName] = EggCanalInviteUserNumsConsume // 处理拉新人数 - jobs[consumeMd.EggCanalViolateNumsFunName] = EggCanalViolateNumsConsume // 处理违规次数 - jobs[consumeMd.IMEggEnergySendRedPackageFunName] = IMEggEnergySendRedPackageConsume // 处理用户发送红包次数 - jobs[consumeMd.EggCanalPersonAddActivityValueFunName] = EggCanalPersonAddActivityValueConsume // 用户活跃积分变更时更新es - jobs[consumeMd.EggRecordActiveDataFunName] = EggRecordActiveDataConsume // 用户签到后更新活跃数据 - jobs[consumeMd.EggEnergyAutoScoreDataFunName] = EggEnergyAutoScoreConsume // 自动打分 - jobs[consumeMd.EggSendFriendCircleDataFunName] = EggSendFriendCircleDataConsume // 用户发送朋友圈后更新es - jobs[consumeMd.EggCommentDataFunName] = EggCommentDataConsume // 用户评论后更新es - jobs[consumeMd.EggCanalEnergyExchangeAccountFunName] = EggCanalEnergyExchangeAccountConsume // 蛋蛋能量兑换为余额的时候更新es - - jobs[consumeMd.VideoRewardFunName] = VideoRewardConsume // 短视频奖励 - jobs[consumeMd.PlayletRewardFunName] = PlayletRewardConsume // 短剧奖励 - - jobs[consumeMd.EggEnergyDealPlatformRevenueDataFunName] = EggEnergyDealPlatformRevenueDataConsume // 平台营收 - jobs[consumeMd.EggEnergyDealFundDataFunName] = EggEnergyDealFundDataConsume // 资金数据 - jobs[consumeMd.EggEnergyDealUserVirtualCoinDataFunName] = EggEnergyDealUserVirtualCoinDataConsume // 视频奖励给相应团队发放积分 - - jobs[consumeMd.PublicPlatoonUserRelationCommissionConsumeFunName] = AddPublicPlatoonUserRelationCommissionConsume - jobs[consumeMd.EggEnergyStartLevelDividendFunName] = EggEnergyStartLevelDividendConsume - jobs[consumeMd.EggEnergySettlementPublicGiveActivityCoinFunName] = EggEnergySettlementPublicGiveActivityCoinConsume - jobs[consumeMd.EggEnergyStartExchangeGreenEnergyFunName] = EggEnergyStartExchangeGreenEnergyConsume - jobs[consumeMd.EggEnergyAutoExchangeGreenEnergyFunName] = EggEnergyAutoExchangeGreenEnergyConsume - jobs[consumeMd.EggEnergyTeamAssistanceConsumeFunName] = EggEnergyTeamAssistanceConsume // 更新团队助力数据 - jobs[consumeMd.EggCanalUserVirtualCoinFlowAggregationConsumeFunName] = EggCanalUserVirtualCoinFlowAggregationConsume // 聚合流水数据 + jobs[consumeMd.UserRegisterConsumeForMyFansFunName] = UserRegisterConsumeForMyFans + jobs[consumeMd.UserRegisterConsumeForMyRecommenderFunName] = UserRegisterConsumeForMyRecommender + jobs[consumeMd.UserRegisterConsumeForOfficialFunName] = UserRegisterConsumeForOfficial } func Run() { diff --git a/consume/jpush_record_consume.go b/consume/jpush_record_consume.go deleted file mode 100644 index b1ed0b8..0000000 --- a/consume/jpush_record_consume.go +++ /dev/null @@ -1,95 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - "applet/app/db" - "applet/app/svc/sys_cfg" - utils2 "applet/app/utils" - "applet/app/utils/logx" - "applet/consume/md" - "code.fnuoos.com/EggPlanet/egg_models.git/src/model" - "code.fnuoos.com/EggPlanet/egg_system_rules.git" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/jPush" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/streadway/amqp" - "strings" - "time" -) - -func JpushRecordConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>JpushRecordConsume>>>>>>>>>>>>") - 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 = handleJpushRecordConsume(res.Body) - if err != nil { - fmt.Println("JpushRecordConsume_ERR:::::", err.Error()) - utils2.FilePutContents("JpushRecordConsume_ERR", utils2.SerializeStr(map[string]interface{}{ - "body": res.Body, - "err": err.Error(), - })) - _ = res.Reject(false) - //TODO::重新推回队列末尾,避免造成队列堵塞 - var msg *md.JpushRecordFundData - json.Unmarshal(res.Body, &msg) - msg.Num = "1" - ch.Publish(queue.ExchangeName, msg, queue.RoutKey) - } else { - //_ = res.Reject(false) - err = res.Ack(true) - } - - fmt.Println("err ::: ", err) - } else { - panic(errors.New("error getting message")) - } - } - fmt.Println("get msg done") -} - -func handleJpushRecordConsume(msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md.JpushRecordFundData - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - engine := db.Db - sysCfgDb := sys_cfg.NewSysCfgDb(engine) - jpushKey := sysCfgDb.SysCfgGetWithDb("jpush_key") - jpushSecret := sysCfgDb.SysCfgGetWithDb("jpush_secret") - if msg.Target == "0" { //广播全部 - _, err := jPush.PushAllUser(jpushKey, jpushSecret, msg.Title, msg.Content, msg.Platform, nil) - if err != nil && msg.Num != "1" { - return err - } - } else { - _, err = jPush.PushMoreUser(jpushKey, jpushSecret, msg.Title, msg.Content, msg.Platform, strings.Split(msg.UserId, ","), nil) - if err != nil && msg.Num != "1" { - return err - } - } - if msg.Id != "" { - engine.Where("id=?", msg.Id).Cols("state").Update(&model.JpushRecord{State: 1}) - } - return nil -} diff --git a/consume/md/consume_key.go b/consume/md/consume_key.go index ce97056..d72d5b1 100644 --- a/consume/md/consume_key.go +++ b/consume/md/consume_key.go @@ -12,344 +12,36 @@ type MqQueue struct { var RabbitMqQueueKeyList = []*MqQueue{ { - ExchangeName: "egg.energy", - Name: "egg_energy_star_level_dividend_queue", - Type: TopicQueueType, - IsPersistent: false, - RoutKey: "star_level_dividend", - BindKey: "", - ConsumeFunName: "EggEnergyStartLevelDividendConsume", - }, - { - ExchangeName: "egg.energy", - Name: "egg_energy_fund_data_queue", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "fund_data", - BindKey: "", - ConsumeFunName: "EggEnergyDealFundDataConsume", - }, - { - ExchangeName: "egg.energy", - Name: "egg_energy_platform_revenue_data_queue", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "platform_revenue_data", - BindKey: "", - ConsumeFunName: "EggEnergyDealPlatformRevenueDataConsume", - }, - { - ExchangeName: "egg.energy", - Name: "egg_deal_user_virtual_coin_queue", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "deal_user_virtual_coin", - BindKey: "", - ConsumeFunName: "EggEnergyDealUserVirtualCoinDataConsume", - }, - { - ExchangeName: "im.egg.energy", - Name: "im_egg_energy_batch_send_message_queue", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "batch_send_message_data", - BindKey: "", - ConsumeFunName: "IMEggEnergyBatchSendMessageDataConsume", - }, - { - ExchangeName: "im.egg.energy", - Name: "im_egg_energy_del_friend_comment_circle_queue", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "del_friend_circle_comment_data", - BindKey: "", - ConsumeFunName: "IMEggEnergyDelFriendCircleDataConsume", - }, - { - ExchangeName: "egg.app", - Name: "egg_fin_withdraw_apply", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "egg_fin_withdraw_apply", - BindKey: "", - ConsumeFunName: "EggFinWithdrawApplyDataConsume", - }, - { - ExchangeName: "egg.energy", - Name: "egg_energy_settlement_public_give_activity_coin", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "settlement_public_give_activity_coin", - BindKey: "", - ConsumeFunName: "EggEnergySettlementPublicGiveActivityCoinConsume", - }, - { - ExchangeName: "egg.energy", - Name: "egg_energy_start_exchange_egg_energy", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "start_exchange_egg_energy", - BindKey: "", - ConsumeFunName: "EggEnergyStartExchangeGreenEnergyConsume", - }, - { - ExchangeName: "egg.energy", - Name: "egg_energy_auto_exchange_egg_energy", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "auto_exchange_egg_energy", - BindKey: "", - ConsumeFunName: "EggEnergyAutoExchangeGreenEnergyConsume", - }, - { - ExchangeName: "egg.app", - Name: "add_public_platoon_user_relation_commission", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "add_public_platoon_user_relation_commission", - BindKey: "", - ConsumeFunName: "AddPublicPlatoonUserRelationCommissionConsume", - }, - { - ExchangeName: "egg.jpush", - Name: "egg_jpush_record_queue", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "jpush_record", - BindKey: "", - ConsumeFunName: "JpushRecordConsume", - }, - { - ExchangeName: "egg.aliyun_sms", - Name: "egg_aliyun_sms_record_queue_new", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "aliyun_sms_record", - BindKey: "", - ConsumeFunName: "AliyunSmsRecordConsume", - }, - { - ExchangeName: "egg.advertising", - Name: "egg_advertising_smash", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "advertising_smash", - BindKey: "", - ConsumeFunName: "AdvertisingSmashConsume", - }, - { - ExchangeName: "egg.advertising", - Name: "egg_advertising_sign", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "advertising_sign", - BindKey: "", - ConsumeFunName: "AdvertisingSignConsume", - }, - { - ExchangeName: "egg.app", - Name: "egg_new_user_register_queue", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "egg_new_user_register", - BindKey: "", - ConsumeFunName: "EggEnergyNewUserRegisterDataConsume", - }, - { - ExchangeName: "egg.energy", - Name: "egg_energy_user_ecpm", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "user_ecpm", - BindKey: "", - ConsumeFunName: "EggEnergyDealUserECPMConsume", - }, - { - ExchangeName: "egg.canal.topic", - Name: "egg_canal_invite_user_nums_queue", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "user_relate", - BindKey: "", - ConsumeFunName: "EggCanalInviteUserNumsConsume", - }, - { - ExchangeName: "egg.canal.topic", - Name: "egg_canal_violate_nums_queue", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "user_tag_records", - BindKey: "", - ConsumeFunName: "EggCanalViolateNumsConsume", - }, - { - ExchangeName: "im.egg.energy", - Name: "im_egg_energy_send_red_package_queue", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "send_red_package", - BindKey: "", - ConsumeFunName: "IMEggEnergySendRedPackageConsume", - }, - { - ExchangeName: "egg.app", - Name: "egg_record_active_queue", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "egg_record_active", - BindKey: "", - ConsumeFunName: "EggRecordActiveDataConsume", - }, - { - ExchangeName: "egg.canal.topic", - Name: "egg_canal_person_add_activity_value_queue", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "egg_canal_user_virtual_coin_flow", - BindKey: "", - ConsumeFunName: "EggCanalPersonAddActivityValueConsume", - }, - { - ExchangeName: "egg.video_playlet", - Name: "egg_video_reward", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "video", - BindKey: "", - ConsumeFunName: "VideoRewardFunName", - }, - { - ExchangeName: "egg.video_playlet", - Name: "egg_playlet_reward", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "playlet", - BindKey: "", - ConsumeFunName: "PlayletRewardFunName", - }, - { - ExchangeName: "egg.user", - Name: "egg_user_delete", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "user_delete", - BindKey: "", - ConsumeFunName: "UserDeleteConsume", - }, - { - ExchangeName: "egg.app", - Name: "egg_auto_score_queue", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "egg_auto_score", - BindKey: "", - ConsumeFunName: "EggEnergyAutoScoreConsume", - }, - { - ExchangeName: "egg.app", - Name: "egg_slow_auto_up_lv", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "egg_slow_auto_up_lv", - BindKey: "", - ConsumeFunName: "EggSlowAutoUpLvConsume", - }, - { - ExchangeName: "egg.canal.topic", - Name: "egg_energy_user_activity", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "egg_energy_user_activity", - BindKey: "", - ConsumeFunName: "EggEnergyUserActivityConsume", - }, - { - ExchangeName: "egg.canal.topic", - Name: "egg_canal_user", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "egg_canal_user", - BindKey: "", - ConsumeFunName: "EggCanalUserConsume", - }, - { - ExchangeName: "egg.energy", - Name: "egg_energy_team_assistance_back", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "egg_energy_team_assistance", - BindKey: "", - ConsumeFunName: "EggEnergyTeamAssistanceConsume", - }, - { - ExchangeName: "egg.canal.topic", - Name: "egg_user_virtual_coin_flow_aggregation", - Type: DirectQueueType, - IsPersistent: false, - RoutKey: "egg_canal_user_virtual_coin_flow", - BindKey: "", - ConsumeFunName: "EggCanalUserVirtualCoinFlowAggregationConsume", - }, - { - ExchangeName: "egg.app", - Name: "egg_send_friend_circle_queue", + ExchangeName: "egg.im", + Name: "egg_user_register_my_fans", Type: DirectQueueType, IsPersistent: false, - RoutKey: "egg_send_friend_circle", - BindKey: "", - ConsumeFunName: "EggSendFriendCircleDataConsume", + RoutKey: "my_fans", + BindKey: "my_fans", + ConsumeFunName: "UserRegisterConsumeForMyFans", }, { - ExchangeName: "egg.app", - Name: "egg_comment_queue", + ExchangeName: "egg.im", + Name: "egg_user_register_my_recommender", Type: DirectQueueType, IsPersistent: false, - RoutKey: "egg_comment", - BindKey: "", - ConsumeFunName: "EggCommentDataConsume", + RoutKey: "my_recommender", + BindKey: "my_recommender", + ConsumeFunName: "UserRegisterConsumeForMyRecommender", }, { - ExchangeName: "egg.canal.topic", - Name: "egg_canal_energy_exchange_account_queue", + ExchangeName: "egg.im", + Name: "egg_user_register_official", Type: DirectQueueType, IsPersistent: false, - RoutKey: "egg_canal_user_wallet_flow", - BindKey: "", - ConsumeFunName: "EggCanalEnergyExchangeAccountConsume", + RoutKey: "official", + BindKey: "official", + ConsumeFunName: "UserRegisterConsumeForOfficial", }, } const ( - EggSlowAutoUpLvConsume = "EggSlowAutoUpLvConsume" - EggEnergyUserActivityConsume = "EggEnergyUserActivityConsume" - EggCanalUserConsume = "EggCanalUserConsume" - JpushRecordFunName = "JpushRecordConsume" - AliyunSmsRecordFunName = "AliyunSmsRecordConsume" - EggEnergyStartLevelDividendFunName = "EggEnergyStartLevelDividendConsume" - EggEnergyDealFundDataFunName = "EggEnergyDealFundDataConsume" - EggEnergyDealPlatformRevenueDataFunName = "EggEnergyDealPlatformRevenueDataConsume" - EggEnergyDealUserVirtualCoinDataFunName = "EggEnergyDealUserVirtualCoinDataConsume" - IMEggEnergyBatchSendMessageDataFunName = "IMEggEnergyBatchSendMessageDataConsume" - IMEggEnergyDelFriendCircleDataFunName = "IMEggEnergyDelFriendCircleDataConsume" - EggFinWithdrawApplyDataConsumeFunName = "EggFinWithdrawApplyDataConsume" - EggEnergySettlementPublicGiveActivityCoinFunName = "EggEnergySettlementPublicGiveActivityCoinConsume" - EggEnergyStartExchangeGreenEnergyFunName = "EggEnergyStartExchangeGreenEnergyConsume" - EggEnergyAutoExchangeGreenEnergyFunName = "EggEnergyAutoExchangeGreenEnergyConsume" - EggEnergyNewUserRegisterDataFunName = "EggEnergyNewUserRegisterDataConsume" - EggEnergyDealUserECPMFunName = "EggEnergyDealUserECPMConsume" - EggCanalInviteUserNumsFunName = "EggCanalInviteUserNumsConsume" - EggCanalViolateNumsFunName = "EggCanalViolateNumsConsume" - IMEggEnergySendRedPackageFunName = "IMEggEnergySendRedPackageConsume" - EggRecordActiveDataFunName = "EggRecordActiveDataConsume" - EggCanalPersonAddActivityValueFunName = "EggCanalPersonAddActivityValueConsume" - VideoRewardFunName = "VideoRewardFunName" - PlayletRewardFunName = "PlayletRewardFunName" - UserDeleteFunName = "UserDeleteConsume" - EggEnergyAutoScoreDataFunName = "EggEnergyAutoScoreConsume" - PublicPlatoonUserRelationCommissionConsumeFunName = "AddPublicPlatoonUserRelationCommissionConsume" - EggEnergyTeamAssistanceConsumeFunName = "EggEnergyTeamAssistanceConsume" - EggCanalUserVirtualCoinFlowAggregationConsumeFunName = "EggCanalUserVirtualCoinFlowAggregationConsume" - EggSendFriendCircleDataFunName = "EggSendFriendCircleDataConsume" - EggCanalEnergyExchangeAccountFunName = "EggCanalEnergyExchangeAccountConsume" - EggCommentDataFunName = "EggCommentDataConsume" + UserRegisterConsumeForMyFansFunName = "UserRegisterConsumeForMyFans" + UserRegisterConsumeForMyRecommenderFunName = "UserRegisterConsumeForMyRecommender" + UserRegisterConsumeForOfficialFunName = "UserRegisterConsumeForOfficial" ) diff --git a/consume/playlet_reward_consume.go b/consume/playlet_reward_consume.go deleted file mode 100644 index 7bd60fc..0000000 --- a/consume/playlet_reward_consume.go +++ /dev/null @@ -1,147 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - "applet/app/db" - "applet/app/e" - "applet/app/svc/sys_cfg" - utils2 "applet/app/utils" - "code.fnuoos.com/EggPlanet/egg_system_rules.git" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/svc" - - "applet/app/utils/cache" - "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" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/streadway/amqp" - "github.com/tidwall/gjson" - "time" -) - -func PlayletRewardConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>PlayletRewardConsume>>>>>>>>>>>>") - 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(100) - 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 = handlePlayletRewardConsume(ch, res.Body) - if err != nil { - fmt.Println("PlayletRewardConsume_ERR:::::", err.Error()) - utils2.FilePutContents("PlayletRewardConsume_ERR", utils2.SerializeStr(map[string]interface{}{ - "body": res.Body, - "err": err.Error(), - })) - _ = res.Reject(false) - //TODO::重新推回队列末尾,避免造成队列堵塞 - var msg *md.PlayletReward - json.Unmarshal(res.Body, &msg) - ch.Publish(queue.ExchangeName, msg, queue.RoutKey) - } else { - //_ = res.Reject(false) - err = res.Ack(true) - } - - fmt.Println("err ::: ", err) - } else { - panic(errors.New("error getting message")) - } - } - fmt.Println("get msg done") -} - -func handlePlayletRewardConsume(ch *rabbit.Channel, msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md.PlayletReward - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - //1、分布式锁阻拦 - requestIdPrefix := fmt.Sprintf("playlet.reward.lock:%s", msg.Uid) - cb, err := svc.HandleDistributedLockForComm(msg.Uid, "playlet.reward.lock.update:%s", requestIdPrefix) - if err != nil { - return err - } - if cb != nil { - defer cb() // 释放锁 - } - eg := db.Db - sysCfgDb := sys_cfg.NewSysCfgDb(eg) - playletBase := sysCfgDb.SysCfgGetWithDb("playlet_base") - sess := eg.NewSession() - defer sess.Close() - sess.Begin() - NewPlayletTotalDb := implement.NewPlayletTotalDb(db.Db) - total, _ := NewPlayletTotalDb.GetPlayletTotalSess(sess, msg.Uid, time.Now().Format("20060102")) - if total == nil { - total = &model.PlayletTotal{ - Uid: utils2.StrToInt(msg.Uid), - Date: utils2.StrToInt(time.Now().Format("20060102")), - Time: time.Now(), - } - insert, err := sess.Insert(total) - if insert == 0 || err != nil { - sess.Rollback() - return e.NewErr(400, "获取奖励失败") - } - } - Leave := utils2.StrToInt(gjson.Get(playletBase, "total").String()) - total.Total - if Leave-1 < 0 { - sess.Rollback() - return nil - } - total.Total++ - - update, err2 := sess.Where("id=?", total.Id).Cols("total").Update(total) - if update == 0 || err2 != nil { - sess.Rollback() - return e.NewErr(400, "获取奖励失败") - } - sess.Commit() - numKey := "playlet.num:" + time.Now().Format("20060102") + "." + msg.Uid - todayRange := utils2.GetTimeRange("today") - cache.SetEx(numKey, utils2.IntToStr(total.Total), int(todayRange["end"]-time.Now().Unix())) - NewEggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) - eggData, _ := NewEggEnergyBasicSettingDb.EggEnergyBasicSettingGetOne() - err = ch.PublishV2(md2.EggEnergyExchange, md2.EggEnergyStructForDealUserVirtualCoinData{ - Kind: "add", - Title: enum.EggEnergyPlayletRewardPersonalActiveCoin.String(), - TransferType: int(enum.EggEnergyPlayletRewardPersonalActiveCoin), - CoinId: eggData.PersonEggPointsCoinId, - Uid: utils2.StrToInt64(msg.Uid), - Amount: utils2.StrToFloat64(gjson.Get(playletBase, "reward").String()), - }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData) - if err != nil { - ch.PublishV2(md2.EggEnergyExchange, md2.EggEnergyStructForDealUserVirtualCoinData{ - Kind: "add", - Title: enum.EggEnergyPlayletRewardPersonalActiveCoin.String(), - TransferType: int(enum.EggEnergyPlayletRewardPersonalActiveCoin), - CoinId: eggData.PersonEggPointsCoinId, - Uid: utils2.StrToInt64(msg.Uid), - Amount: utils2.StrToFloat64(gjson.Get(playletBase, "reward").String()), - }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData) - } - return nil -} diff --git a/consume/user_delete_consume.go b/consume/user_delete_consume.go deleted file mode 100644 index 2d779a1..0000000 --- a/consume/user_delete_consume.go +++ /dev/null @@ -1,168 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - "applet/app/db" - model2 "applet/app/db/model" - utils2 "applet/app/utils" - "applet/app/utils/logx" - "applet/consume/md" - db2 "code.fnuoos.com/EggPlanet/egg_models.git/src" - "code.fnuoos.com/EggPlanet/egg_models.git/src/model" - "code.fnuoos.com/EggPlanet/egg_system_rules.git" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/jinzhu/copier" - "github.com/streadway/amqp" - "time" - "xorm.io/xorm" -) - -func UserDeleteConsume(queue md.MqQueue) { - var backCfg db2.BackUpDBCfg - copier.Copy(&backCfg, &cfg.BackUpDb) - backUpDb, err := db2.InitBackUpDB(&backCfg) - if err != nil { - logx.Error(err) - return - } - fmt.Println(">>>>>>>>>>>>UserDeleteConsume>>>>>>>>>>>>") - 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(100) - 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 = handleUserDeleteConsume(backUpDb, ch, res.Body) - if err != nil { - fmt.Println("UserDeleteConsume_ERR:::::", err.Error()) - utils2.FilePutContents("UserDeleteConsume_ERR", utils2.SerializeStr(map[string]interface{}{ - "body": res.Body, - "err": err.Error(), - })) - _ = res.Reject(false) - //TODO::重新推回队列末尾,避免造成队列堵塞 - var msg *md.CommUserId - json.Unmarshal(res.Body, &msg) - ch.Publish(queue.ExchangeName, msg, queue.RoutKey) - } else { - //_ = res.Reject(false) - err = res.Ack(true) - } - - fmt.Println("err ::: ", err) - } else { - panic(errors.New("error getting message")) - } - } - fmt.Println("get msg done") -} - -func handleUserDeleteConsume(backEg *xorm.Engine, ch *rabbit.Channel, msgData []byte) error { - if backEg == nil { - return nil - } - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md.CommUserId - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - eg := db.Db - //1.用户信息 - var user model2.User - exist, err := eg.Where("id=?", msg.Uid).Get(&user) - if exist { - backEg.Insert(&user) - user.Phone = "" - user.State = 2 - user.Nickname = "注销用户" - db.Db.Where("id=?", user.Id).Cols("state,phone,nickname").Update(&user) - } - //2.用户关系链 - //查出所有下级 - var relate []model.UserRelate - err = eg.Where("parent_uid=?", msg.Uid).Find(&relate) - if len(relate) > 0 { - backEg.Insert(&relate) - } - var relateParent []model.UserRelate - err = eg.Where("uid=?", msg.Uid).Find(&relateParent) - var relateParent1 []model.UserRelate - err = eg.Where("uid=?", msg.ParentUid).Find(&relateParent1) - var parentIds = make([]int64, 0) - - if len(relateParent) > 0 { - backEg.Insert(&relateParent) - for _, v := range relateParent { - parentIds = append(parentIds, v.ParentUid) - } - } - var ids = make([]int64, 0) - for _, v := range relate { - ids = append(ids, v.Uid) - } - //读出所有下级重新处理 - var allRelate []model.UserRelate - err = eg.In("uid", ids).Desc("level").Find(&allRelate) - for _, v := range allRelate { - if utils2.InArrInt64(v.ParentUid, parentIds) { - eg.Where("id=?", v.Id).Delete(&model.UserRelate{}) - continue - } - if v.ParentUid == utils2.StrToInt64(msg.Uid) && utils2.StrToInt64(msg.ParentUid) > 0 { //如果相等 - level := v.Level - var tmp = model.UserRelate{ - ParentUid: utils2.StrToInt64(msg.ParentUid), - Uid: v.Uid, - Level: level, - InviteTime: v.InviteTime, - } - eg.Insert(&tmp) - for _, v1 := range relateParent1 { - level++ - var tmp1 = model.UserRelate{ - ParentUid: v1.ParentUid, - Uid: v.Uid, - Level: level, - InviteTime: v.InviteTime, - } - eg.Insert(&tmp1) - } - } - } - eg.Where("parent_uid=?", msg.Uid).Cols("parent_uid").Update(&model2.User{ParentUid: utils2.StrToInt64(msg.ParentUid)}) - _, err = eg.Where("parent_uid=?", msg.Uid).Delete(&model.UserRelate{}) - _, err = eg.Where("uid=?", msg.Uid).Delete(&model.UserRelate{}) - - var UserRealNameAuth model.UserRealNameAuth - exist, err = eg.Where("uid=?", msg.Uid).Get(&UserRealNameAuth) - if exist { - backEg.Insert(&UserRealNameAuth) - } - eg.Where("uid=?", msg.Uid).Delete(&model.UserRealNameAuth{}) - var publicPlatoonUserRelation model.PublicPlatoonUserRelation - exist, err = eg.Where("uid=?", msg.Uid).Get(&publicPlatoonUserRelation) - if exist { - publicPlatoonUserRelation.Id = 0 - backEg.Insert(&publicPlatoonUserRelation) - } - rule.DealPublicPlatoon(eg, utils2.StrToInt64(msg.Uid), "注销") - return nil -} diff --git a/consume/user_register_for_my_my_fans.go b/consume/user_register_for_my_my_fans.go new file mode 100644 index 0000000..7f284a8 --- /dev/null +++ b/consume/user_register_for_my_my_fans.go @@ -0,0 +1,138 @@ +package consume + +import ( + "applet/app/cfg" + "applet/app/db" + db2 "applet/app/db/gim" + model2 "applet/app/db/gim/model" + "applet/app/db/model" + md2 "applet/app/md" + utils2 "applet/app/utils" + "applet/app/utils/logx" + utils "applet/app/utils/rpc" + "applet/consume/md" + "applet/pkg/pb" + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" + "encoding/json" + "errors" + "fmt" + "github.com/streadway/amqp" + "strconv" + "time" +) + +func UserRegisterConsumeForMyFans(queue md.MqQueue) { + fmt.Println(">>>>>>>>>>>>UserRegisterConsumeForMyFans>>>>>>>>>>>>") + 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) + + var res amqp.Delivery + var ok bool + for { + res, ok = <-delivery + if ok == true { + fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") + err = handleUserRegisterConsumeForMyFans(res.Body) + if err != nil { + fmt.Println("!!!!!!!err!!!!!!!", err) + _ = res.Reject(false) + + utils2.FilePutContents("UserRegisterConsumeForMyFans_err", "[err]:"+err.Error()) + if err.Error() == "用户暂未注册im系统" { + //TODO::重新推回队列末尾,避免造成队列堵塞 + var msg *md2.UserRegisterMessageStructForMyFans + json.Unmarshal(res.Body, &msg) + ch.Publish(queue.ExchangeName, msg, queue.RoutKey) + } + } else { + _ = res.Ack(true) + } + } else { + panic(errors.New("error getting message")) + } + } + fmt.Println("get msg done") +} + +func handleUserRegisterConsumeForMyFans(msgData []byte) error { + //time.Sleep(time.Duration(15) * time.Second) + //1、解析mq中queue的数据结构体 + var msg *md2.UserRegisterMessageStructForMyFans + err := json.Unmarshal(msgData, &msg) + if err != nil { + return err + } + //2、查找用户对应im系统中的数据 + gimUser, err := db2.UserGetOneByParams(db.DbIm, map[string]interface{}{ + "key": "phone_number", + "value": msg.Phone, + }) + if err != nil { + return err + } + if gimUser == nil { + user, err := db.UserFindByMobile(db.Db, strconv.FormatInt(msg.Phone, 10)) + if err != nil { + return err + } + + gimUserId, err := db2.UserInsert(db.DbIm, &model2.User{ + PhoneNumber: strconv.FormatInt(msg.Phone, 10), + Nickname: user.Nickname, + AvatarUrl: user.Avatar, + Sex: user.Sex, + CreateTime: time.Now().Format("2006-01-02 15:04:05"), + UpdateTime: time.Now().Format("2006-01-02 15:04:05"), + IsAutoAddedFriends: 0, + }) + if err != nil { + return errors.New("用户暂未注册im系统") + } + gimUser, err = db2.UserGetOneByParams(db.DbIm, map[string]interface{}{ + "key": "id", + "value": gimUserId, + }) + if gimUser == nil { + return errors.New("用户暂未注册im系统") + } + } + + groupName := "我的粉丝【1】群" + //3、创建群 + resp, err := utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).CreateGroup(utils.GetCtx("", utils2.Int64ToStr(gimUser.Id), ""), &pb.CreateGroupReq{ + Name: groupName, + AvatarUrl: "", + Introduction: "", + Extra: "", + MemberIds: nil, + }) + if err != nil { + return err + } + //插入 im_group 记录 + now := time.Now() + _, err = db.ImGroupInsert(db.Db, &model.ImGroup{ + Kind: 3, + Uid: int(msg.Uid), + GroupId: int(resp.GroupId), + IsFull: 0, + Name: groupName, + CreateTime: now, + UpdateTime: now, + }) + if err != nil { + return err + } + + return nil +} diff --git a/consume/user_register_for_my_my_recommender.go b/consume/user_register_for_my_my_recommender.go new file mode 100644 index 0000000..d46ae65 --- /dev/null +++ b/consume/user_register_for_my_my_recommender.go @@ -0,0 +1,202 @@ +package consume + +import ( + "applet/app/cfg" + "applet/app/db" + db2 "applet/app/db/gim" + "applet/app/db/gim/model" + model2 "applet/app/db/model" + md2 "applet/app/md" + utils2 "applet/app/utils" + "applet/app/utils/logx" + utils "applet/app/utils/rpc" + "applet/consume/md" + "applet/pkg/pb" + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" + "encoding/json" + "errors" + "fmt" + "github.com/streadway/amqp" + "strconv" + "time" +) + +func UserRegisterConsumeForMyRecommender(queue md.MqQueue) { + fmt.Println(">>>>>>>>>>>>UserRegisterConsumeForMyRecommender>>>>>>>>>>>>") + 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) + + var res amqp.Delivery + var ok bool + for { + res, ok = <-delivery + if ok == true { + fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") + err = handleUserRegisterConsumeForMyRecommender(res.Body) + if err != nil { + fmt.Println("!!!!!!!err!!!!!!!", err) + _ = res.Reject(false) + + utils2.FilePutContents("UserRegisterConsumeForMyRecommender_err", "[err]:"+err.Error()) + if err.Error() == "用户暂未注册im系统" { + //TODO::重新推回队列末尾,避免造成队列堵塞 + var msg *md2.UserRegisterMessageStructForMyRecommender + json.Unmarshal(res.Body, &msg) + ch.Publish(queue.ExchangeName, msg, queue.RoutKey) + } + } else { + _ = res.Ack(true) + } + } else { + panic(errors.New("error getting message")) + } + } + fmt.Println("get msg done") +} + +func handleUserRegisterConsumeForMyRecommender(msgData []byte) error { + //time.Sleep(time.Duration(20) * time.Second) + //1、解析mq中queue的数据结构体 + var msg *md2.UserRegisterMessageStructForMyRecommender + err := json.Unmarshal(msgData, &msg) + if err != nil { + return err + } + //2、查找用户对应im系统中的数据 + gimUser, err := db2.UserGetOneByParams(db.DbIm, map[string]interface{}{ + "key": "phone_number", + "value": msg.Phone, + }) + if err != nil { + return err + } + + if gimUser == nil { + user, err := db.UserFindByMobile(db.Db, strconv.FormatInt(msg.Phone, 10)) + if err != nil { + return err + } + + gimUserId, err := db2.UserInsert(db.DbIm, &model.User{ + PhoneNumber: strconv.FormatInt(msg.Phone, 10), + Nickname: user.Nickname, + AvatarUrl: user.Avatar, + Sex: user.Sex, + CreateTime: time.Now().Format("2006-01-02 15:04:05"), + UpdateTime: time.Now().Format("2006-01-02 15:04:05"), + IsAutoAddedFriends: 0, + }) + if err != nil { + return errors.New("用户暂未注册im系统") + } + gimUser, err = db2.UserGetOneByParams(db.DbIm, map[string]interface{}{ + "key": "id", + "value": gimUserId, + }) + if gimUser == nil { + return errors.New("用户暂未注册im系统") + } + } + + //2、查找是否有群 + var fansGroup model2.ImGroup + fansGroups, err := db.ImGroupFindByParamsByKind(db.Db, 3, map[string]interface{}{ + "key": "uid", + "value": msg.RecommenderUid, + }) + if err != nil { + return err + } + for _, group := range *fansGroups { + //统计当前群有多少人 + userGroups, err := db2.GroupUserFindByParams(db.DbIm, map[string]interface{}{ + "key": "group_id", + "value": group.GroupId, + }) + if err != nil { + return err + } + if len(*userGroups) < 1000 { + fansGroup = group + } + } + + if fansGroup.GroupId == 0 { + recommenderUser, err := db.UserFindByID(db.Db, msg.RecommenderUid) + if err != nil { + return err + } + recommenderGimUser, err := db2.UserGetOneByParams(db.DbIm, map[string]interface{}{ + "key": "phone_number", + "value": recommenderUser.Phone, + }) + if recommenderGimUser == nil { + return errors.New("当前推荐人信息有误,请联系管理员!!!") + } + + groupName := "我的粉丝【" + utils2.AnyToString(len(*fansGroups)+1) + "】群" + //3、创建群 + resp, err := utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).CreateGroup(utils.GetCtx("", strconv.FormatInt(recommenderGimUser.Id, 10), "0"), &pb.CreateGroupReq{ + Name: groupName, + AvatarUrl: "", + //Introduction: "官方群", + Introduction: "", + Extra: "", + MemberIds: []int64{}, + }) + if err != nil { + return err + } + + //插入 im_group 记录 + now := time.Now() + _, err = db.ImGroupInsert(db.Db, &model2.ImGroup{ + Kind: 3, + Uid: int(msg.RecommenderUid), + GroupId: int(resp.GroupId), + IsFull: 0, + Name: groupName, + CreateTime: now, + UpdateTime: now, + }) + if err != nil { + return err + } + tempFansGroup, err := db.ImGroupGetOneByParams(db.Db, 2, map[string]interface{}{ + "group_id": resp.GroupId, + }) + if err != nil { + return err + } + fansGroup = *tempFansGroup + } + + userGroup, err2 := db2.GroupUserGetOneByParams(db.DbIm, 1, map[string]interface{}{ + "key": "group_id", + "value": fansGroup.GroupId, + }) + if err2 != nil { + return err2 + } + if userGroup == nil { + return errors.New("当前推荐人群暂未设置群主,请联系管理员!!!") + } + + //加入群 + _, err = utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).AddGroupMembers( + utils.GetCtx("", strconv.FormatInt(userGroup.UserId, 10), ""), + &pb.AddGroupMembersReq{ + GroupId: int64(fansGroup.GroupId), + UserIds: []int64{gimUser.Id}, + }) + return nil +} diff --git a/consume/user_register_for_official_consume.go b/consume/user_register_for_official_consume.go index 8bd852b..0ee6835 100644 --- a/consume/user_register_for_official_consume.go +++ b/consume/user_register_for_official_consume.go @@ -64,7 +64,7 @@ func UserRegisterConsumeForOfficial(queue md.MqQueue) { } func handleUserRegisterConsumeForOfficial(msgData []byte) error { - time.Sleep(time.Duration(5) * time.Second) + //time.Sleep(time.Duration(1) * time.Second) //1、解析mq中queue的数据结构体 var msg *md2.UserRegisterMessageStructForOfficial err := json.Unmarshal(msgData, &msg) @@ -127,7 +127,7 @@ func handleUserRegisterConsumeForOfficial(msgData []byte) error { "key": "group_id", "value": group.GroupId, }) - if len(*userGroups) < 500 { + if len(*userGroups) < 1000 { officialGroup = group } } @@ -135,13 +135,13 @@ func handleUserRegisterConsumeForOfficial(msgData []byte) error { if officialGroup.GroupId == 0 { groupName := "官方【" + utils2.AnyToString(len(*officialGroups)+1) + "】群" //3、创建群 - resp, err := utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).CreateGroup(utils.GetCtx("", strconv.FormatInt(gimUser.Id, 10), "0"), &pb.CreateGroupReq{ + resp, err := utils.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).CreateGroup(utils.GetCtx("", "1", "0"), &pb.CreateGroupReq{ Name: groupName, AvatarUrl: "", //Introduction: "官方群", Introduction: "", Extra: "", - MemberIds: []int64{}, + MemberIds: []int64{gimUser.Id}, }) if err != nil { return err diff --git a/consume/video_reward_consume.go b/consume/video_reward_consume.go deleted file mode 100644 index fa82e00..0000000 --- a/consume/video_reward_consume.go +++ /dev/null @@ -1,144 +0,0 @@ -package consume - -import ( - "applet/app/cfg" - "applet/app/db" - "applet/app/e" - utils2 "applet/app/utils" - "applet/app/utils/cache" - "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" - "code.fnuoos.com/EggPlanet/egg_system_rules.git" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" - 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/EggPlanet/egg_system_rules.git/svc/sys_cfg" - "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "encoding/json" - "errors" - "fmt" - "github.com/streadway/amqp" - "github.com/tidwall/gjson" - "time" -) - -func VideoRewardConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>VideoRewardConsume>>>>>>>>>>>>") - 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(100) - 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 = handleVideoRewardConsume(ch, res.Body) - if err != nil { - fmt.Println("VideoRewardConsume_ERR:::::", err.Error()) - utils2.FilePutContents("VideoRewardConsume_ERR", utils2.SerializeStr(map[string]interface{}{ - "body": res.Body, - "err": err.Error(), - })) - _ = res.Reject(false) - //TODO::重新推回队列末尾,避免造成队列堵塞 - var msg *md.VideoReward - json.Unmarshal(res.Body, &msg) - ch.Publish(queue.ExchangeName, msg, queue.RoutKey) - } else { - //_ = res.Reject(false) - err = res.Ack(true) - } - - fmt.Println("err ::: ", err) - } else { - panic(errors.New("error getting message")) - } - } - fmt.Println("get msg done") -} - -func handleVideoRewardConsume(ch *rabbit.Channel, msgData []byte) error { - time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 - // 1.解析mq中queue的数据结构体 - var msg *md.VideoReward - err := json.Unmarshal(msgData, &msg) - if err != nil { - return err - } - //1、分布式锁阻拦 - requestIdPrefix := fmt.Sprintf("video.reward.lock:%s", msg.Uid) - cb, err := svc.HandleDistributedLockForComm(msg.Uid, "video.reward.lock.update:%s", requestIdPrefix) - if err != nil { - return err - } - if cb != nil { - defer cb() // 释放锁 - } - eg := db.Db - sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) - videoBase := sysCfgDb.SysCfgGetWithDb("video_base") - sess := eg.NewSession() - defer sess.Close() - sess.Begin() - NewVideoTotalDb := implement.NewVideoTotalDb(db.Db) - total, _ := NewVideoTotalDb.GetVideoTotalSess(sess, msg.Uid, time.Now().Format("20060102")) - if total == nil { - total = &model.VideoTotal{ - Uid: utils2.StrToInt(msg.Uid), - Date: utils2.StrToInt(time.Now().Format("20060102")), - Time: time.Now(), - } - insert, err := sess.Insert(total) - if insert == 0 || err != nil { - sess.Rollback() - return e.NewErr(400, "获取奖励失败") - } - } - Leave := utils2.StrToInt(gjson.Get(videoBase, "total").String()) - total.Total - if Leave-1 < 0 { - return nil - } - total.Total++ - update, err2 := sess.Where("id=?", total.Id).Cols("total").Update(total) - if update == 0 || err2 != nil { - sess.Rollback() - return e.NewErr(400, "获取奖励失败") - } - sess.Commit() - numKey := "video.num:" + time.Now().Format("20060102") + "." + msg.Uid - todayRange := utils2.GetTimeRange("today") - cache.SetEx(numKey, utils2.IntToStr(total.Total), int(todayRange["end"]-time.Now().Unix())) - NewEggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) - eggData, _ := NewEggEnergyBasicSettingDb.EggEnergyBasicSettingGetOne() - err = ch.PublishV2(md2.EggEnergyExchange, md2.EggEnergyStructForDealUserVirtualCoinData{ - Kind: "add", - Title: enum.EggEnergyVideoRewardPersonalActiveCoin.String(), - TransferType: int(enum.EggEnergyVideoRewardPersonalActiveCoin), - CoinId: eggData.PersonEggPointsCoinId, - Uid: utils2.StrToInt64(msg.Uid), - Amount: utils2.StrToFloat64(gjson.Get(videoBase, "reward").String()), - }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData) - if err != nil { - ch.PublishV2(md2.EggEnergyExchange, md2.EggEnergyStructForDealUserVirtualCoinData{ - Kind: "add", - Title: enum.EggEnergyVideoRewardPersonalActiveCoin.String(), - TransferType: int(enum.EggEnergyVideoRewardPersonalActiveCoin), - CoinId: eggData.PersonEggPointsCoinId, - Uid: utils2.StrToInt64(msg.Uid), - Amount: utils2.StrToFloat64(gjson.Get(videoBase, "reward").String()), - }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData) - } - return nil -}