蛋蛋星球RabbitMq消费项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

add_public_platoon_user_relation_commission.go 3.8 KiB

4 weeks ago
3 weeks ago
3 days ago
4 weeks ago
3 weeks ago
4 weeks ago
2 weeks ago
4 weeks ago
2 weeks ago
3 weeks ago
3 days ago
1 week ago
3 weeks ago
4 weeks ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package consume
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/db"
  5. "applet/app/utils"
  6. "applet/app/utils/logx"
  7. "applet/consume/md"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  10. "code.fnuoos.com/EggPlanet/egg_system_rules.git"
  11. "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  12. md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
  13. "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule"
  14. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  15. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  16. "encoding/json"
  17. "errors"
  18. "fmt"
  19. "github.com/streadway/amqp"
  20. )
  21. func AddPublicPlatoonUserRelationCommissionConsume(queue md.MqQueue) {
  22. fmt.Println(">>>>>>>>>>>>AddPublicPlatoonUserRelationCommissionConsume>>>>>>>>>>>>")
  23. ch, err := rabbit.Cfg.Pool.GetChannel()
  24. if err != nil {
  25. logx.Error(err)
  26. return
  27. }
  28. defer ch.Release()
  29. //1、将自己绑定到交换机上
  30. ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
  31. //2、取出数据进行消费
  32. ch.Qos(1)
  33. delivery := ch.Consume(queue.Name, false)
  34. egg_system_rules.Init(cfg.RedisAddr)
  35. var res amqp.Delivery
  36. var ok bool
  37. for {
  38. res, ok = <-delivery
  39. if ok == true {
  40. err = handleAddPublicPlatoonUserRelationCommissionConsume(res.Body)
  41. if err != nil {
  42. fmt.Println("err ::: ", err)
  43. utils.FilePutContents("AddPublicPlatoonUserRelationCommissionConsume_ERR", "[err]:"+err.Error())
  44. _ = res.Reject(false)
  45. //TODO::重新推回队列末尾,避免造成队列堵塞
  46. //var msg *md2.AddPublicPlatoonUserRelationCommissionReq
  47. //json.Unmarshal(res.Body, &msg)
  48. //ch.Publish(queue.ExchangeName, msg, queue.RoutKey)
  49. } else {
  50. _ = res.Ack(true)
  51. }
  52. } else {
  53. panic(errors.New("error getting message"))
  54. }
  55. }
  56. fmt.Println("get msg done")
  57. }
  58. func handleAddPublicPlatoonUserRelationCommissionConsume(msgData []byte) error {
  59. //1、解析mq中queue的数据结构体
  60. var msg *md2.AddPublicPlatoonUserRelationCommissionReq
  61. err := json.Unmarshal(msgData, &msg)
  62. if err != nil {
  63. return err
  64. }
  65. //3、加入公排
  66. var req []*md2.AddPublicPlatoonUserRelationCommissionReq
  67. req = append(req, msg)
  68. _, err = rule.AddPublicPlatoonUserRelationCommission(db.Db, req)
  69. fmt.Println("err::::", err)
  70. if err != nil {
  71. return err
  72. }
  73. //2、给到直推奖励
  74. //TODO::判断是否签到过
  75. var eggSignIn model.EggSignIn
  76. has, _ := db.Db.Where("uid =?", msg.Uid).Get(&eggSignIn)
  77. if has {
  78. eggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  79. eggEnergyBasicSetting, err := eggEnergyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{
  80. "key": "is_open",
  81. "value": 1,
  82. })
  83. if err != nil {
  84. return err
  85. }
  86. if eggEnergyBasicSetting != nil {
  87. userDeleteInfoDb := implement.NewUserDeleteInfoDb(db.Db)
  88. fmt.Println("userDelete>>>>>>>>>>>>>>>", msg.Phone)
  89. userDelete := userDeleteInfoDb.GetUserDeleteInfo(msg.Phone)
  90. fmt.Println("userDelete>>>>>>>>>>>>>>>", userDelete)
  91. if userDelete == nil {
  92. var newUserRewardRules *md2.NewUserRewardRules
  93. err = json.Unmarshal([]byte(eggEnergyBasicSetting.NewUserIncentiveRules), &newUserRewardRules)
  94. if err != nil {
  95. fmt.Println("handleAddPublicPlatoonUserRelationCommissionConsume___ERR>>>>", err.Error())
  96. }
  97. rewardValue := newUserRewardRules.InviteUserRewardValue
  98. session := db.Db.NewSession()
  99. err = rule.DealUserVirtualCoin(session, md3.DealUserVirtualCoinReq{
  100. Kind: "add",
  101. Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggEnergyRecruitNewUsersReward),
  102. TransferType: int(enum.EggEnergyRecruitNewUsersReward),
  103. CoinId: eggEnergyBasicSetting.PersonEggPointsCoinId,
  104. Uid: utils.StrToInt64(msg.RecommendUid),
  105. Amount: float64(rewardValue),
  106. })
  107. if err != nil {
  108. return err
  109. }
  110. session.Commit()
  111. }
  112. }
  113. }
  114. return nil
  115. }