subscribeupdatelogic.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. fmt.Println("###")
  53. b, _ := json.Marshal(su)
  54. rp, err := l.svcCtx.Suscribe.UpdateSubScribeInfo(l.ctx, &bxsubscribe.UpdateSubScribeInfoReq{
  55. UserId: req.UserId,
  56. PositionType: req.PositionType,
  57. SubSet: b,
  58. BaseUserId: req.NewUserId,
  59. PositionId: req.PositionId,
  60. })
  61. if err != nil {
  62. resp.Err_code, resp.Err_msg = -1, "修改失败"
  63. l.Error(fmt.Sprintf("%+v", req), resp.Err_msg)
  64. } else {
  65. it.MgoLog.Save("ovipjy_log", map[string]interface{}{
  66. "userid": req.UserId,
  67. "o_vipjy": req,
  68. "createtime": time.Now().Unix(),
  69. "type": "o_vipjy",
  70. })
  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. }