subscribeupdatelogic.go 3.1 KB

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