subscribeupdatelogic.go 3.0 KB

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