subscribeupdatelogic.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/api/init"
  9. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/api/internal/svc"
  10. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/api/internal/types"
  11. . "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/entity"
  12. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/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. District: req.District,
  51. Amount: req.Amount,
  52. ISwitch: req.ISwitch,
  53. Matchmode: req.Matchmode,
  54. }
  55. fmt.Println("###")
  56. b, _ := json.Marshal(su)
  57. rp, err := l.svcCtx.Suscribe.UpdateSubScribeInfo(l.ctx, &bxsubscribe.UpdateSubScribeInfoReq{
  58. UserId: req.UserId,
  59. PositionType: req.PositionType,
  60. SubSet: b,
  61. BaseUserId: req.NewUserId,
  62. PositionId: req.PositionId,
  63. })
  64. if err != nil {
  65. resp.Err_code, resp.Err_msg = -1, "修改失败"
  66. l.Error(fmt.Sprintf("%+v", req), resp.Err_msg)
  67. } else {
  68. saveData := map[string]interface{}{
  69. "userid": req.UserId,
  70. "o_vipjy": req,
  71. "createtime": time.Now().Unix(),
  72. "type": "o_vipjy",
  73. }
  74. go it.SubscribeUpdateLog.SendLogs(saveData)
  75. resp.Data = map[string]interface{}{
  76. "status": rp.Status,
  77. }
  78. }
  79. return
  80. }
  81. // 判断关键词是否异常,
  82. func KeyWordsRepeat(aitems []map[string]interface{}) bool {
  83. m := map[string]bool{} //去重的数组
  84. // 录入的关键词
  85. i := 0
  86. for _, items := range aitems {
  87. for kk, vv := range items {
  88. if kk == "a_key" {
  89. for _, n := range common.ObjArrToMapArr(vv.([]interface{})) {
  90. db_not := []string{}
  91. db_key := []string{}
  92. db_append := []string{}
  93. matchway := 0
  94. if n["key"] != nil {
  95. db_key = common.ObjArrToStringArr(n["key"].([]interface{}))
  96. }
  97. if n["notkey"] != nil {
  98. db_not = common.ObjArrToStringArr(n["notkey"].([]interface{}))
  99. }
  100. if n["appendkey"] != nil {
  101. db_append = common.ObjArrToStringArr(n["appendkey"].([]interface{}))
  102. }
  103. if n["matchway"] != nil {
  104. matchway = common.IntAll(n["matchway"])
  105. }
  106. key := fmt.Sprintf("%v%v%v%s", db_key, db_append, db_not, matchway)
  107. if m[key] {
  108. return true //有重复 不可以提交
  109. }
  110. i++
  111. m[key] = true
  112. }
  113. }
  114. }
  115. }
  116. if i > 300 {
  117. //关键词大于300异常
  118. return true
  119. }
  120. return false
  121. }