showsearchlogic.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. // todo 待测试
  27. var (
  28. data []*bxbase.ListSearchRes
  29. isOld bool
  30. )
  31. log.Println("获取搜索列表:", in)
  32. res = new(bxbase.ShowSearchRes)
  33. if in.UserId == "" {
  34. res.ErrCode = 1
  35. res.ErrMsg = "用户未登录"
  36. return res, nil
  37. }
  38. query := map[string]interface{}{
  39. "user_id": in.UserId,
  40. "type": in.Type,
  41. }
  42. allSearch, b := IC.Mgo.Find("search_condition", query, `{"creation_time":-1}`, "", false, -1, -1)
  43. if !b {
  44. res.ErrCode = 1
  45. res.ErrMsg = "用户搜索信息查询失败"
  46. return res, nil
  47. }
  48. //需判断新老用户
  49. user, _b := IC.Mgo.FindById("user", in.UserId, `"i_member_status":1,"i_vip_status":1,"s_m_phone":1,"s_phone":1,"o_vipjy":1,"l_registedate":1`)
  50. if !_b {
  51. res.ErrCode = 1
  52. res.ErrMsg = "用户信息查询失败"
  53. return res, nil
  54. }
  55. registedate, _ := (*user)["l_registedate"].(int64)
  56. isOld = registedate != 0 && registedate < IC.C.BidSearchOldUserLimit
  57. if allSearch != nil {
  58. for _, vlu := range *allSearch {
  59. var listSearch bxbase.ListSearchRes
  60. listSearch.Id = common.InterfaceToStr(vlu["_id"])
  61. listSearch.Searchvalue = common.InterfaceToStr(vlu["keywords"])
  62. listSearch.Publishtime = common.InterfaceToStr(vlu["publish_time"])
  63. listSearch.Area = common.InterfaceToStr(vlu["area"])
  64. listSearch.City = common.InterfaceToStr(vlu["city"])
  65. listSearch.Subtype = common.InterfaceToStr(vlu["subtype"])
  66. listSearch.Minprice = common.InterfaceToStr(vlu["min_price"])
  67. listSearch.Maxprice = common.InterfaceToStr(vlu["max_price"])
  68. listSearch.Industry = common.InterfaceToStr(vlu["industry"])
  69. listSearch.SelectType = common.InterfaceToStr(vlu["select_type"])
  70. listSearch.Buyerclass = common.InterfaceToStr(vlu["buyer_class"])
  71. listSearch.Buyertel = common.InterfaceToStr(vlu["buyer_tel"])
  72. listSearch.Winnertel = common.InterfaceToStr(vlu["winner_tel"])
  73. listSearch.FileExists = common.InterfaceToStr(vlu["file_exists"])
  74. listSearch.Notkey = common.InterfaceToStr(vlu["not_key"])
  75. listSearch.Tabularflag = common.InterfaceToStr(vlu["tabular_flag"])
  76. listSearch.SearchGroup = common.Int64All(vlu["searchGroup"])
  77. listSearch.SearchMode = common.Int64All(vlu["searchMode"])
  78. listSearch.WordsMode = common.Int64All(vlu["wordsMode"])
  79. listSearch.AdditionalWords = common.InterfaceToStr(vlu["additionalWords"])
  80. //ppa,buyer,winner,agency
  81. if SelectCheck(listSearch.SelectType, isOld) || listSearch.City != "" || listSearch.Notkey != "" ||
  82. (listSearch.Publishtime != "lately-7" && listSearch.Publishtime != "lately-30" && listSearch.Publishtime != "thisyear") ||
  83. listSearch.Winnertel != "" || listSearch.Buyertel != "" || listSearch.Buyerclass != "" {
  84. listSearch.IsPay = true
  85. }
  86. data = append(data, &listSearch)
  87. }
  88. }
  89. res.Data = data
  90. return res, nil
  91. }
  92. func SelectCheck(v string, isOld bool) bool {
  93. vs := strings.Split(v, ",")
  94. for _, v1 := range vs {
  95. if v1 != "content" && v1 != "file" && v1 != "title" {
  96. //老用户可以选用中标企业
  97. if isOld && v1 == "winner" {
  98. continue
  99. } else {
  100. return true
  101. }
  102. }
  103. }
  104. return false
  105. }