subscribe.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // @Description 订阅设置相关
  2. package service
  3. import (
  4. "errors"
  5. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/entity"
  6. IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/init"
  7. "strconv"
  8. "strings"
  9. "app.yhyue.com/moapp/jybase/common"
  10. "app.yhyue.com/moapp/jybase/mongodb"
  11. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type SubseribeService struct {
  15. Mgo mongodb.MongodbSim
  16. UserId string //mongodb 的用户id
  17. Types string //订阅信息产品类型 超级订阅、大会员、商机管理、免费订阅...
  18. PositionType int64
  19. *entity.SubscribeUpdate
  20. PositionId int64
  21. BaseUserId int64
  22. MgoLog mongodb.MongodbSim
  23. }
  24. // @description 订阅设置相关修改
  25. // @param SubseribeService 用户信息相关
  26. // @return int64 是否成功 1成功 -1失败
  27. // @return error 错误信息
  28. // TODO 后期需要实现 查询各个身份的订阅设置修改[目前只实现了超级订阅]
  29. func (this *SubseribeService) Update() (int64, error) {
  30. if this.UserId == "" {
  31. return -1, errors.New(entity.UPDATE_ERROR_MSG)
  32. }
  33. //查询条件
  34. //查询字段
  35. fields := `{"i_vip_status":1,"o_vipjy":1}`
  36. //查询用户信息
  37. r := IC.Compatible.Select(this.UserId, fields)
  38. if r == nil || len(*r) == 0 {
  39. logx.Error("未找到用户")
  40. return -1, errors.New(entity.UPDATE_ERROR_MSG)
  41. }
  42. //判断用户权益
  43. vip_status := common.Int64All((*r)["i_vip_status"])
  44. if vip_status <= 0 {
  45. logx.Error("用户暂无权益")
  46. return -1, errors.New(entity.UPDATE_ERROR_MSG)
  47. }
  48. o_vipjy := common.ObjToMap((*r)["o_vipjy"])
  49. //权益通过,获取要修改的参数
  50. setMap := map[string]interface{}{}
  51. if this.Area != nil {
  52. setMap["o_vipjy.o_area"] = this.Area
  53. }
  54. //区县
  55. if this.District != nil {
  56. setMap["o_vipjy.o_district"] = this.District
  57. }
  58. if this.Buyerclass != nil {
  59. setMap["o_vipjy.a_buyerclass"] = this.Buyerclass
  60. }
  61. if this.Amount != "" {
  62. setMap["o_vipjy.amount"] = this.Amount
  63. }
  64. setMap["o_vipjy.i_switch"] = this.ISwitch
  65. if this.Items != nil {
  66. setMap["o_vipjy.a_items"] = this.Items
  67. //判断是否新增
  68. keyLen := 0
  69. if (*o_vipjy)["a_items"] != nil {
  70. aitems, _ := (*o_vipjy)["a_items"].([]interface{})
  71. a_items := common.ObjArrToMapArr(aitems)
  72. keyLen = GetKeyWordLen(a_items)
  73. }
  74. newKeyLen := GetKeyWordLen(this.Items)
  75. if newKeyLen > keyLen {
  76. jy.Publish(this.MgoLog, IC.C.Nsq, IC.C.NsqTopic, "task", this.UserId, jy.Jyweb_node2, map[string]interface{}{
  77. "code": 1015, //首次订阅
  78. "types": "subscribeKeyWords",
  79. "num": 50,
  80. "baseUserId": this.BaseUserId,
  81. "positionId": this.PositionId,
  82. })
  83. }
  84. }
  85. if this.Infotype != nil {
  86. setMap["o_vipjy.a_infotype"] = this.Infotype
  87. }
  88. if this.Matchmode != "" {
  89. setMap["o_vipjy.i_matchmode"] = strings.Split(this.Matchmode, ",")
  90. }
  91. if this.Matchway != "" {
  92. i_matchway, _ := strconv.Atoi(this.Matchway)
  93. setMap["o_vipjy.i_matchway"] = i_matchway
  94. }
  95. if this.Projectmatch != "" {
  96. i_projectmatch, _ := strconv.Atoi(this.Projectmatch)
  97. setMap["o_vipjy.i_projectmatch"] = i_projectmatch
  98. }
  99. if this.Ratemode != "" {
  100. i_ratemode, _ := strconv.Atoi(this.Ratemode)
  101. setMap["o_vipjy.i_ratemode"] = i_ratemode
  102. }
  103. if this.Apppush != "" {
  104. i_apppush, _ := strconv.Atoi(this.Apppush)
  105. setMap["o_vipjy.i_apppush"] = i_apppush
  106. }
  107. if this.Mailpush != "" {
  108. i_mailpush, _ := strconv.Atoi(this.Mailpush)
  109. setMap["o_vipjy.i_mailpush"] = i_mailpush
  110. }
  111. if this.Mail != "" {
  112. setMap["o_vipjy.s_email"] = this.Mail
  113. }
  114. if this.Otherbuyerclass != "" {
  115. i_otherbuyerclass, _ := strconv.Atoi(this.Otherbuyerclass)
  116. setMap["o_vipjy.i_matchbuyerclass_other"] = i_otherbuyerclass
  117. }
  118. if ok := IC.Compatible.Update(this.UserId, map[string]interface{}{
  119. "$set": setMap,
  120. }); ok {
  121. return 1, nil
  122. }
  123. return -1, errors.New(entity.UPDATE_ERROR_MSG)
  124. }
  125. func GetKeyWordLen(a_items []map[string]interface{}) (count int) {
  126. if len(a_items) == 0 {
  127. return
  128. }
  129. for _, v := range a_items {
  130. a_key, _ := v["a_key"].([]interface{})
  131. count += len(a_key)
  132. }
  133. return
  134. }