subscribeupdatelogic.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  5. it "jyBXSubscribe/api/init"
  6. "jyBXSubscribe/api/internal/svc"
  7. "jyBXSubscribe/api/internal/types"
  8. "jyBXSubscribe/rpc/model/service"
  9. "app.yhyue.com/moapp/jybase/common"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type SubscribeUpdateLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. }
  17. func NewSubscribeUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubscribeUpdateLogic {
  18. return &SubscribeUpdateLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. }
  23. }
  24. //
  25. func (l *SubscribeUpdateLogic) SubscribeUpdate(req *types.SubscribeUpdateReq) (resp *types.CommonResp, err error) {
  26. resp = &types.CommonResp{} //出参
  27. if req.UserId == "" {
  28. return
  29. }
  30. subService := &service.SubseribeService{
  31. UserId: req.UserId,
  32. Mgo: it.Mgo,
  33. }
  34. if req.Area != nil {
  35. subService.Area = req.Area
  36. }
  37. if req.Apppush != "" {
  38. subService.Apppush = req.Apppush
  39. }
  40. if req.Buyerclass != nil {
  41. subService.Buyerclass = req.Buyerclass
  42. }
  43. if req.Infotype != nil {
  44. subService.Infotype = req.Infotype
  45. }
  46. //TODO 判重
  47. if KeyWordsRepeat(req.Items) {
  48. resp.Data = map[string]interface{}{
  49. "status": -1,
  50. }
  51. resp.Err_code, resp.Err_msg = -1, "关键词设置异常"
  52. return
  53. }
  54. if req.Items != nil {
  55. subService.Items = req.Items
  56. }
  57. if req.Mail != "" {
  58. subService.Mail = req.Mail
  59. }
  60. if req.Mailpush != "" {
  61. subService.Mailpush = req.Mailpush
  62. }
  63. if req.Matchway != "" {
  64. subService.Matchway = req.Matchway
  65. }
  66. if req.Otherbuyerclass != "" {
  67. subService.Otherbuyerclass = req.Otherbuyerclass
  68. }
  69. if req.Projectmatch != "" {
  70. subService.Projectmatch = req.Projectmatch
  71. }
  72. if req.Ratemode != "" {
  73. subService.Ratemode = req.Ratemode
  74. }
  75. status, err := subService.Update()
  76. if err != nil {
  77. resp.Err_code, resp.Err_msg = -1, "修改失败"
  78. l.Error(fmt.Sprintf("%+v", req), resp.Err_msg)
  79. } else {
  80. resp.Data = map[string]interface{}{
  81. "status": status,
  82. }
  83. }
  84. return
  85. }
  86. //判断关键词是否异常,
  87. func KeyWordsRepeat(aitems []map[string]interface{}) bool {
  88. m := map[string]bool{} //去重的数组
  89. // 录入的关键词
  90. i := 0
  91. for _, items := range aitems {
  92. for kk, vv := range items {
  93. if kk == "a_key" {
  94. for _, n := range common.ObjArrToMapArr(vv.([]interface{})) {
  95. db_not := []string{}
  96. db_key := []string{}
  97. db_append := []string{}
  98. matchway := 0
  99. if n["key"] != nil {
  100. db_key = common.ObjArrToStringArr(n["key"].([]interface{}))
  101. }
  102. if n["notkey"] != nil {
  103. db_not = common.ObjArrToStringArr(n["notkey"].([]interface{}))
  104. }
  105. if n["appendkey"] != nil {
  106. db_append = common.ObjArrToStringArr(n["appendkey"].([]interface{}))
  107. }
  108. if n["matchway"] != nil {
  109. matchway = common.IntAll(n["matchway"])
  110. }
  111. key := fmt.Sprintf("%v%v%v%s", db_key, db_append, db_not, matchway)
  112. if m[key] {
  113. return true //有重复 不可以提交
  114. }
  115. i++
  116. m[key] = true
  117. }
  118. }
  119. }
  120. }
  121. if i > 300 {
  122. //关键词大于300异常
  123. return true
  124. }
  125. return false
  126. }