subscribe.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // @Description 订阅设置相关
  2. package service
  3. import (
  4. "errors"
  5. "jyBXSubscribe/entity"
  6. IC "jyBXSubscribe/rpc/init"
  7. "strconv"
  8. "app.yhyue.com/moapp/jybase/common"
  9. "app.yhyue.com/moapp/jybase/mongodb"
  10. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  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. if this.Buyerclass != nil {
  55. setMap["o_vipjy.a_buyerclass"] = this.Buyerclass
  56. }
  57. if this.Items != nil {
  58. setMap["o_vipjy.a_items"] = this.Items
  59. //判断是否新增
  60. keyLen := 0
  61. if (*o_vipjy)["a_items"] != nil {
  62. aitems, _ := (*o_vipjy)["a_items"].([]interface{})
  63. a_items := common.ObjArrToMapArr(aitems)
  64. keyLen = GetKeyWordLen(a_items)
  65. }
  66. newKeyLen := GetKeyWordLen(this.Items)
  67. if newKeyLen > keyLen {
  68. jy.Publish(this.MgoLog, IC.C.Nsq, IC.C.NsqTopic, "task", this.UserId, jy.Jyweb_node2, map[string]interface{}{
  69. "code": 1015, //首次订阅
  70. "types": "subscribeKeyWords",
  71. "num": 50,
  72. "baseUserId": this.BaseUserId,
  73. "positionId": this.PositionId,
  74. })
  75. }
  76. }
  77. if this.Infotype != nil {
  78. setMap["o_vipjy.a_infotype"] = this.Infotype
  79. }
  80. if this.Matchway != "" {
  81. i_matchway, _ := strconv.Atoi(this.Matchway)
  82. setMap["o_vipjy.i_matchway"] = i_matchway
  83. }
  84. if this.Projectmatch != "" {
  85. i_projectmatch, _ := strconv.Atoi(this.Projectmatch)
  86. setMap["o_vipjy.i_projectmatch"] = i_projectmatch
  87. }
  88. if this.Ratemode != "" {
  89. i_ratemode, _ := strconv.Atoi(this.Ratemode)
  90. setMap["o_vipjy.i_ratemode"] = i_ratemode
  91. }
  92. if this.Apppush != "" {
  93. i_apppush, _ := strconv.Atoi(this.Apppush)
  94. setMap["o_vipjy.i_apppush"] = i_apppush
  95. }
  96. if this.Mailpush != "" {
  97. i_mailpush, _ := strconv.Atoi(this.Mailpush)
  98. setMap["o_vipjy.i_mailpush"] = i_mailpush
  99. }
  100. if this.Mail != "" {
  101. setMap["o_vipjy.s_email"] = this.Mail
  102. }
  103. if this.Otherbuyerclass != "" {
  104. i_otherbuyerclass, _ := strconv.Atoi(this.Otherbuyerclass)
  105. setMap["o_vipjy.i_matchbuyerclass_other"] = i_otherbuyerclass
  106. }
  107. if ok := IC.Compatible.Update(this.UserId, map[string]interface{}{
  108. "$set": setMap,
  109. }); ok {
  110. return 1, nil
  111. }
  112. return -1, errors.New(entity.UPDATE_ERROR_MSG)
  113. }
  114. func GetKeyWordLen(a_items []map[string]interface{}) (count int) {
  115. if len(a_items) == 0 {
  116. return
  117. }
  118. for _, v := range a_items {
  119. a_key, _ := v["a_key"].([]interface{})
  120. count += len(a_key)
  121. }
  122. return
  123. }