subscribeupdatelogic.go 3.5 KB

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