subscribeupdatelogic.go 3.2 KB

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