showsearchlogic.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "github.com/zeromicro/go-zero/core/logx"
  6. "jyBXBase/rpc/bxbase"
  7. IC "jyBXBase/rpc/init"
  8. "jyBXBase/rpc/internal/svc"
  9. "log"
  10. "strings"
  11. )
  12. type ShowSearchLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewShowSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowSearchLogic {
  18. return &ShowSearchLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. // 获取收藏列表
  25. func (l *ShowSearchLogic) ShowSearch(in *bxbase.ShowSearchReq) (res *bxbase.ShowSearchRes, err error) {
  26. var (
  27. data []*bxbase.ListSearchRes
  28. isOld bool
  29. )
  30. log.Println("获取搜索列表:", in)
  31. res = new(bxbase.ShowSearchRes)
  32. if in.UserId == "" {
  33. res.ErrCode = -1
  34. res.ErrMsg = "用户未登录"
  35. return res, nil
  36. }
  37. query := map[string]interface{}{
  38. "user_id": in.UserId,
  39. "type": in.Type,
  40. }
  41. allSearch, b := IC.Mgo.Find("search_condition", query, `{"creation_time":-1}`, "", false, -1, -1)
  42. if !b {
  43. res.ErrCode = -1
  44. res.ErrMsg = "用户搜索信息查询失败"
  45. return res, nil
  46. }
  47. //需判断新老用户
  48. user := IC.Compatible.Select(in.UserId, `{"i_member_status":1,"i_vip_status":1,"s_m_phone":1,"s_phone":1,"o_vipjy":1,"l_registedate":1}`)
  49. if user == nil || len(*user) == 0 {
  50. res.ErrCode = -1
  51. res.ErrMsg = "用户信息查询失败"
  52. return res, nil
  53. }
  54. registedate, _ := (*user)["l_registedate"].(int64)
  55. isOld = registedate != 0 && registedate < IC.C.BidSearchOldUserLimit
  56. if allSearch != nil {
  57. for _, vlu := range *allSearch {
  58. var listSearch bxbase.ListSearchRes
  59. listSearch.Id = common.InterfaceToStr(vlu["_id"])
  60. listSearch.Searchvalue = common.InterfaceToStr(vlu["keywords"])
  61. listSearch.Publishtime = common.InterfaceToStr(vlu["publish_time"])
  62. listSearch.Area = common.InterfaceToStr(vlu["area"])
  63. listSearch.City = common.InterfaceToStr(vlu["city"])
  64. listSearch.Subtype = common.InterfaceToStr(vlu["subtype"])
  65. listSearch.Minprice = common.InterfaceToStr(vlu["min_price"])
  66. listSearch.Maxprice = common.InterfaceToStr(vlu["max_price"])
  67. listSearch.Industry = common.InterfaceToStr(vlu["industry"])
  68. listSearch.SelectType = common.InterfaceToStr(vlu["select_type"])
  69. listSearch.Buyerclass = common.InterfaceToStr(vlu["buyer_class"])
  70. listSearch.Buyertel = common.InterfaceToStr(vlu["buyer_tel"])
  71. listSearch.Winnertel = common.InterfaceToStr(vlu["winner_tel"])
  72. listSearch.FileExists = common.InterfaceToStr(vlu["file_exists"])
  73. listSearch.Notkey = common.InterfaceToStr(vlu["not_key"])
  74. listSearch.Tabularflag = common.InterfaceToStr(vlu["tabular_flag"])
  75. listSearch.SearchGroup = common.Int64All(vlu["searchGroup"])
  76. listSearch.SearchMode = common.Int64All(vlu["searchMode"])
  77. listSearch.WordsMode = common.Int64All(vlu["wordsMode"])
  78. listSearch.AdditionalWords = common.InterfaceToStr(vlu["additionalWords"])
  79. //ppa,buyer,winner,agency
  80. if SelectCheck(listSearch.SelectType, isOld) || listSearch.City != "" || listSearch.Notkey != "" ||
  81. (listSearch.Publishtime != "lately-7" && listSearch.Publishtime != "lately-30" && listSearch.Publishtime != "thisyear") ||
  82. listSearch.Winnertel != "" || listSearch.Buyertel != "" || listSearch.Buyerclass != "" {
  83. listSearch.IsPay = true
  84. }
  85. data = append(data, &listSearch)
  86. }
  87. }
  88. res.Data = data
  89. return res, nil
  90. }
  91. func SelectCheck(v string, isOld bool) bool {
  92. vs := strings.Split(v, ",")
  93. for _, v1 := range vs {
  94. if v1 != "content" && v1 != "file" && v1 != "title" {
  95. //老用户可以选用中标企业
  96. if isOld && v1 == "winner" {
  97. continue
  98. } else {
  99. return true
  100. }
  101. }
  102. }
  103. return false
  104. }