subscribeupdatelogic.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. }
  35. if req.Area != nil {
  36. subService.Area = req.Area
  37. }
  38. if req.Apppush != "" {
  39. subService.Apppush = req.Apppush
  40. }
  41. if req.Buyerclass != nil {
  42. subService.Buyerclass = req.Buyerclass
  43. }
  44. if req.Infotype != nil {
  45. subService.Infotype = req.Infotype
  46. }
  47. if KeyWordsRepeat(req.Items) {
  48. resp.Data = map[string]interface{}{
  49. "status": -1,
  50. }
  51. resp.Err_code, resp.Err_msg = -1, "关键词设置异常"
  52. return
  53. }
  54. if req.Items != nil {
  55. subService.Items = req.Items
  56. }
  57. if req.Mail != "" {
  58. subService.Mail = req.Mail
  59. }
  60. if req.Mailpush != "" {
  61. subService.Mailpush = req.Mailpush
  62. }
  63. if req.Matchway != "" {
  64. subService.Matchway = req.Matchway
  65. }
  66. if req.Otherbuyerclass != "" {
  67. subService.Otherbuyerclass = req.Otherbuyerclass
  68. }
  69. if req.Projectmatch != "" {
  70. subService.Projectmatch = req.Projectmatch
  71. }
  72. if req.Ratemode != "" {
  73. subService.Ratemode = req.Ratemode
  74. }
  75. status, err := subService.Update()
  76. if err != nil {
  77. resp.Err_code, resp.Err_msg = -1, "修改失败"
  78. l.Error(fmt.Sprintf("%+v", req), resp.Err_msg)
  79. } else {
  80. it.MgoLog.Save("ovipjy_log", map[string]interface{}{
  81. "userid": req.UserId,
  82. "o_vipjy": req,
  83. "createtime": time.Now().Unix(),
  84. "type": "o_vipjy",
  85. })
  86. resp.Data = map[string]interface{}{
  87. "status": status,
  88. }
  89. }
  90. return
  91. }
  92. //判断关键词是否异常,
  93. func KeyWordsRepeat(aitems []map[string]interface{}) bool {
  94. m := map[string]bool{} //去重的数组
  95. // 录入的关键词
  96. i := 0
  97. for _, items := range aitems {
  98. for kk, vv := range items {
  99. if kk == "a_key" {
  100. for _, n := range common.ObjArrToMapArr(vv.([]interface{})) {
  101. db_not := []string{}
  102. db_key := []string{}
  103. db_append := []string{}
  104. matchway := 0
  105. if n["key"] != nil {
  106. db_key = common.ObjArrToStringArr(n["key"].([]interface{}))
  107. }
  108. if n["notkey"] != nil {
  109. db_not = common.ObjArrToStringArr(n["notkey"].([]interface{}))
  110. }
  111. if n["appendkey"] != nil {
  112. db_append = common.ObjArrToStringArr(n["appendkey"].([]interface{}))
  113. }
  114. if n["matchway"] != nil {
  115. matchway = common.IntAll(n["matchway"])
  116. }
  117. key := fmt.Sprintf("%v%v%v%s", db_key, db_append, db_not, matchway)
  118. if m[key] {
  119. return true //有重复 不可以提交
  120. }
  121. i++
  122. m[key] = true
  123. }
  124. }
  125. }
  126. }
  127. if i > 300 {
  128. //关键词大于300异常
  129. return true
  130. }
  131. return false
  132. }