subscribeupdatelogic.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. if KeyWordsRepeat(req.Items) {
  47. resp.Data = map[string]interface{}{
  48. "status": -1,
  49. }
  50. resp.Err_code, resp.Err_msg = -1, "关键词设置异常"
  51. return
  52. }
  53. if req.Items != nil {
  54. subService.Items = req.Items
  55. }
  56. if req.Mail != "" {
  57. subService.Mail = req.Mail
  58. }
  59. if req.Mailpush != "" {
  60. subService.Mailpush = req.Mailpush
  61. }
  62. if req.Matchway != "" {
  63. subService.Matchway = req.Matchway
  64. }
  65. if req.Otherbuyerclass != "" {
  66. subService.Otherbuyerclass = req.Otherbuyerclass
  67. }
  68. if req.Projectmatch != "" {
  69. subService.Projectmatch = req.Projectmatch
  70. }
  71. if req.Ratemode != "" {
  72. subService.Ratemode = req.Ratemode
  73. }
  74. status, err := subService.Update()
  75. if err != nil {
  76. resp.Err_code, resp.Err_msg = -1, "修改失败"
  77. l.Error(fmt.Sprintf("%+v", req), resp.Err_msg)
  78. } else {
  79. resp.Data = map[string]interface{}{
  80. "status": status,
  81. }
  82. }
  83. return
  84. }
  85. //判断关键词是否异常,
  86. func KeyWordsRepeat(aitems []map[string]interface{}) bool {
  87. m := map[string]bool{} //去重的数组
  88. // 录入的关键词
  89. i := 0
  90. for _, items := range aitems {
  91. for kk, vv := range items {
  92. if kk == "a_key" {
  93. for _, n := range common.ObjArrToMapArr(vv.([]interface{})) {
  94. db_not := []string{}
  95. db_key := []string{}
  96. db_append := []string{}
  97. matchway := 0
  98. if n["key"] != nil {
  99. db_key = common.ObjArrToStringArr(n["key"].([]interface{}))
  100. }
  101. if n["notkey"] != nil {
  102. db_not = common.ObjArrToStringArr(n["notkey"].([]interface{}))
  103. }
  104. if n["appendkey"] != nil {
  105. db_append = common.ObjArrToStringArr(n["appendkey"].([]interface{}))
  106. }
  107. if n["matchway"] != nil {
  108. matchway = common.IntAll(n["matchway"])
  109. }
  110. key := fmt.Sprintf("%v%v%v%s", db_key, db_append, db_not, matchway)
  111. if m[key] {
  112. return true //有重复 不可以提交
  113. }
  114. i++
  115. m[key] = true
  116. }
  117. }
  118. }
  119. }
  120. if i > 300 {
  121. //关键词大于300异常
  122. return true
  123. }
  124. return false
  125. }