subscribe.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // @Description 订阅设置相关
  2. package service
  3. import (
  4. "errors"
  5. "jyBXSubscribe/entity"
  6. "log"
  7. "strconv"
  8. "app.yhyue.com/moapp/jybase/common"
  9. "app.yhyue.com/moapp/jybase/mongodb"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. //
  13. type SubseribeService struct {
  14. Mgo mongodb.MongodbSim
  15. UserId string //mongodb 的用户id
  16. Types string //订阅信息产品类型 超级订阅、大会员、商机管理、免费订阅...
  17. Area map[string]interface{} //地区
  18. Buyerclass []string //采购单位类型
  19. Items []map[string]interface{} //关键词
  20. Infotype []string //信息类型
  21. Matchway string //匹配方式 1标题 2正文
  22. Projectmatch string //项目匹配 1开始 0关闭
  23. Ratemode string // 1:实时推送,2:每天9点推送,3:每周推送,4:每月推送 5:每日推送两次
  24. Apppush string //app推送 1开启 0关闭
  25. Mailpush string //邮箱推送 1开启 0关闭
  26. Mail string //邮箱
  27. Otherbuyerclass string //匹配未分类类型 1匹配 0不匹配
  28. }
  29. // @description 订阅设置相关修改
  30. // @param SubseribeService 用户信息相关
  31. // @return int64 是否成功 1成功 -1失败
  32. // @return error 错误信息
  33. //TODO 后期需要实现 查询各个身份的订阅设置修改[目前只实现了超级订阅]
  34. func (this *SubseribeService) Update() (int64, error) {
  35. if this.UserId == "" {
  36. return -1, errors.New(entity.UPDATE_ERROR_MSG)
  37. }
  38. //查询条件
  39. query := map[string]interface{}{
  40. "_id": mongodb.StringTOBsonId(this.UserId),
  41. }
  42. //查询字段
  43. fields := `{"i_vip_status":1,"o_vipjy":1}`
  44. //查询用户信息
  45. r, ok := this.Mgo.FindOneByField(entity.User, query, fields)
  46. if !ok || r == nil || len(*r) == 0 {
  47. logx.Error("未找到用户")
  48. return -1, errors.New(entity.UPDATE_ERROR_MSG)
  49. }
  50. //判断用户权益
  51. vip_status := common.Int64All((*r)["i_vip_status"])
  52. if vip_status <= 0 {
  53. logx.Error("用户暂无权益")
  54. return -1, errors.New(entity.UPDATE_ERROR_MSG)
  55. }
  56. //权益通过,获取要修改的参数
  57. setMap := map[string]interface{}{}
  58. if this.Area != nil {
  59. setMap["o_vipjy.o_area"] = this.Area
  60. }
  61. if this.Buyerclass != nil {
  62. setMap["o_vipjy.a_buyerclass"] = this.Buyerclass
  63. }
  64. if this.Items != nil {
  65. setMap["o_vipjy.a_items"] = this.Items
  66. }
  67. if this.Infotype != nil {
  68. setMap["o_vipjy.a_infotype"] = this.Infotype
  69. }
  70. if this.Matchway != "" {
  71. i_matchway, _ := strconv.Atoi(this.Matchway)
  72. setMap["o_vipjy.i_matchway"] = i_matchway
  73. }
  74. if this.Projectmatch != "" {
  75. i_projectmatch, _ := strconv.Atoi(this.Projectmatch)
  76. setMap["o_vipjy.i_projectmatch"] = i_projectmatch
  77. }
  78. if this.Ratemode != "" {
  79. i_ratemode, _ := strconv.Atoi(this.Ratemode)
  80. setMap["o_vipjy.i_ratemode"] = i_ratemode
  81. }
  82. if this.Apppush != "" {
  83. i_apppush, _ := strconv.Atoi(this.Apppush)
  84. setMap["o_vipjy.i_apppush"] = i_apppush
  85. }
  86. if this.Mailpush != "" {
  87. i_mailpush, _ := strconv.Atoi(this.Mailpush)
  88. setMap["o_vipjy.i_mailpush"] = i_mailpush
  89. }
  90. if this.Mail != "" {
  91. setMap["o_vipjy.s_email"] = this.Mail
  92. }
  93. if this.Otherbuyerclass != "" {
  94. setMap["o_vipjy.i_matchbuyerclass_other"] = this.Otherbuyerclass
  95. }
  96. log.Println(setMap)
  97. if ok := this.Mgo.UpdateById(entity.User, this.UserId, map[string]interface{}{
  98. "$set": setMap,
  99. }); ok {
  100. return 1, nil
  101. }
  102. return -1, errors.New(entity.UPDATE_ERROR_MSG)
  103. }