pushSet.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "fmt"
  5. IC "jyBXSubscribe/rpc/init"
  6. "jyBXSubscribe/rpc/type/bxsubscribe"
  7. "jyBXSubscribe/rpc/util"
  8. )
  9. type PushSetService struct {
  10. UserId string //mongodb 的用户id
  11. PositionType int64
  12. EntId int64
  13. EntUserId int64
  14. }
  15. func (this *PushSetService) Update(item, setType, pushType string, ratemode, pushValue int64, times []string) bool {
  16. set := map[string]interface{}{}
  17. switch setType {
  18. case "pushRoute":
  19. set = map[string]interface{}{
  20. fmt.Sprintf("o_pushset.%s.%s", item, pushType): pushValue,
  21. }
  22. break
  23. default:
  24. switch pushType {
  25. case "":
  26. set = map[string]interface{}{
  27. fmt.Sprintf("o_pushset.%s.a_times", item): times,
  28. }
  29. break
  30. case "ratemode":
  31. set = map[string]interface{}{
  32. fmt.Sprintf("o_pushset.%s.i_ratemode", item): ratemode,
  33. }
  34. break
  35. }
  36. }
  37. update := false
  38. if this.PositionType == 0 {
  39. update = IC.Mgo.UpdateById(util.USER, this.UserId, map[string]interface{}{
  40. "$set": set,
  41. })
  42. } else {
  43. update = IC.Mgo.Update(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId}, map[string]interface{}{
  44. "$set": set,
  45. }, true, false)
  46. }
  47. return update
  48. }
  49. func (this *PushSetService) Find() map[string]*bxsubscribe.PushSet {
  50. pushSetList := &map[string]interface{}{}
  51. if this.PositionType == 0 {
  52. pushSetList, _ = IC.Mgo.FindById(util.USER, this.UserId, `{"o_pushset":":1}`)
  53. } else {
  54. pushSetList, _ = IC.Mgo.FindOne(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId})
  55. }
  56. pushSet := map[string]*bxsubscribe.PushSet{}
  57. if pushSetList != nil && len(*pushSetList) > 0 {
  58. o_pushset, _ := (*pushSetList)["o_pushset"].(map[string]interface{})
  59. fool, o_subset := pushSetMontage(o_pushset["o_subset"])
  60. if fool {
  61. pushSet["o_subset"] = o_subset
  62. }
  63. fool, o_week_report := pushSetMontage(o_pushset["o_week_report"])
  64. if fool {
  65. pushSet["o_week_report"] = o_week_report
  66. }
  67. fool, o_month_report := pushSetMontage(o_pushset["o_month_report"])
  68. if fool {
  69. pushSet["o_month_report"] = o_month_report
  70. }
  71. fool, o_newproject_forecast := pushSetMontage(o_pushset["o_newproject_forecast"])
  72. if fool {
  73. pushSet["o_newproject_forecast"] = o_newproject_forecast
  74. }
  75. fool, o_entinfo := pushSetMontage(o_pushset["o_entinfo"])
  76. if fool {
  77. pushSet["o_entinfo"] = o_entinfo
  78. }
  79. fool, o_follow_project := pushSetMontage(o_pushset["o_follow_project"])
  80. if fool {
  81. pushSet["o_follow_project"] = o_follow_project
  82. }
  83. fool, o_follow_ent := pushSetMontage(o_pushset["o_follow_ent"])
  84. if fool {
  85. pushSet["o_entinfo"] = o_follow_ent
  86. }
  87. }
  88. return pushSet
  89. }
  90. func pushSetMontage(in interface{}) (bool, *bxsubscribe.PushSet) {
  91. data := common.ObjToMap(in)
  92. if data == nil || len(*data) == 0 {
  93. return false, nil
  94. }
  95. a_times := []string{}
  96. if (*data)["a_times"] != nil {
  97. a_times = common.ObjArrToStringArr((*data)["a_times"].([]interface{}))
  98. }
  99. return true, &bxsubscribe.PushSet{
  100. ATimes: a_times,
  101. IApppush: common.Int64All((*data)["i_apppush"]),
  102. IWxpush: common.Int64All((*data)["i_wxpush"]),
  103. IMailpush: common.Int64All((*data)["i_mailpush"]),
  104. IRatemode: common.Int64All((*data)["i_ratemode"]),
  105. }
  106. }
  107. func (this *PushSetService) SetUser(mail string) bool {
  108. set := map[string]interface{}{
  109. "o_pushset.s_email": mail,
  110. }
  111. update := false
  112. if this.PositionType == 0 {
  113. update = IC.Mgo.UpdateById(util.USER, this.UserId, map[string]interface{}{
  114. "$set": set,
  115. })
  116. } else {
  117. update = IC.Mgo.Update(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId}, map[string]interface{}{
  118. "$set": set,
  119. }, true, false)
  120. }
  121. return update
  122. }