showsearchlogic.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "fmt"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. "jyBXBase/rpc/bxbase"
  8. IC "jyBXBase/rpc/init"
  9. "jyBXBase/rpc/internal/svc"
  10. "log"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. type ShowSearchLogic struct {
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. logx.Logger
  19. }
  20. func NewShowSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowSearchLogic {
  21. return &ShowSearchLogic{
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. Logger: logx.WithContext(ctx),
  25. }
  26. }
  27. // 获取收藏列表
  28. func (l *ShowSearchLogic) ShowSearch(in *bxbase.ShowSearchReq) (res *bxbase.ShowSearchRes, err error) {
  29. var (
  30. data []*bxbase.ListSearchRes
  31. isOld bool
  32. )
  33. log.Println("获取搜索列表:", in)
  34. res = new(bxbase.ShowSearchRes)
  35. if in.UserId == "" {
  36. res.ErrCode = -1
  37. res.ErrMsg = "用户未登录"
  38. return res, nil
  39. }
  40. query := map[string]interface{}{
  41. "user_id": in.UserId,
  42. "type": in.Type,
  43. }
  44. allSearch, b := IC.Mgo.Find("search_condition", query, `{"creation_time":-1}`, "", false, -1, -1)
  45. if !b {
  46. res.ErrCode = -1
  47. res.ErrMsg = "用户搜索信息查询失败"
  48. return res, nil
  49. }
  50. //需判断新老用户
  51. 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}`)
  52. if user == nil || len(*user) == 0 {
  53. res.ErrCode = -1
  54. res.ErrMsg = "用户信息查询失败"
  55. return res, nil
  56. }
  57. registedate, _ := (*user)["l_registedate"].(int64)
  58. isOld = registedate != 0 && registedate < IC.C.BidSearchOldUserLimit
  59. if allSearch != nil {
  60. for _, vlu := range *allSearch {
  61. var listSearch bxbase.ListSearchRes
  62. listSearch.Id = common.InterfaceToStr(vlu["_id"])
  63. listSearch.Searchvalue = common.InterfaceToStr(vlu["keywords"])
  64. //PC端保存带时间范围的刷选条件时,到期时间选择18号,时间参数为18号0点,正常应该是18号23点59分59秒
  65. //现对老数据进行处理
  66. publishTime := common.InterfaceToStr(vlu["publish_time"])
  67. if publishTime != "" && strings.Contains(publishTime, "_") {
  68. publishTimeStart := strings.Split(publishTime, "_")[0]
  69. if publishTimeEnd := strings.Split(publishTime, "_")[1]; publishTimeEnd != "" {
  70. if endTimeInt, err := strconv.ParseInt(publishTimeEnd, 10, 64); err == nil {
  71. endTimeUnix := time.Unix(endTimeInt, 0)
  72. endTimeInt = time.Date(endTimeUnix.Year(), endTimeUnix.Month(), endTimeUnix.Day(), 23, 59, 59, 59, time.Local).Unix()
  73. publishTime = fmt.Sprintf("%s_%d", publishTimeStart, endTimeInt)
  74. }
  75. }
  76. }
  77. listSearch.Publishtime = publishTime
  78. listSearch.Area = common.InterfaceToStr(vlu["area"])
  79. listSearch.District = common.InterfaceToStr(vlu["district"])
  80. listSearch.City = common.InterfaceToStr(vlu["city"])
  81. listSearch.Subtype = common.InterfaceToStr(vlu["subtype"])
  82. listSearch.Minprice = common.InterfaceToStr(vlu["min_price"])
  83. listSearch.Maxprice = common.InterfaceToStr(vlu["max_price"])
  84. listSearch.Industry = common.InterfaceToStr(vlu["industry"])
  85. listSearch.SelectType = common.InterfaceToStr(vlu["select_type"])
  86. listSearch.Buyerclass = common.InterfaceToStr(vlu["buyer_class"])
  87. listSearch.Buyertel = common.InterfaceToStr(vlu["buyer_tel"])
  88. listSearch.Winnertel = common.InterfaceToStr(vlu["winner_tel"])
  89. listSearch.FileExists = common.InterfaceToStr(vlu["file_exists"])
  90. listSearch.Notkey = common.InterfaceToStr(vlu["not_key"])
  91. listSearch.Tabularflag = common.InterfaceToStr(vlu["tabular_flag"])
  92. listSearch.SearchGroup = common.Int64All(vlu["searchGroup"])
  93. listSearch.SearchMode = common.Int64All(vlu["searchMode"])
  94. listSearch.WordsMode = common.Int64All(vlu["wordsMode"])
  95. listSearch.AdditionalWords = common.InterfaceToStr(vlu["additionalWords"])
  96. //ppa,buyer,winner,agency
  97. if SelectCheck(listSearch.SelectType, isOld) || listSearch.City != "" || listSearch.Notkey != "" ||
  98. (listSearch.Publishtime != "lately-7" && listSearch.Publishtime != "lately-30" && listSearch.Publishtime != "thisyear") ||
  99. listSearch.Winnertel != "" || listSearch.Buyertel != "" || listSearch.Buyerclass != "" {
  100. listSearch.IsPay = true
  101. }
  102. data = append(data, &listSearch)
  103. }
  104. }
  105. res.Data = data
  106. return res, nil
  107. }
  108. func SelectCheck(v string, isOld bool) bool {
  109. vs := strings.Split(v, ",")
  110. for _, v1 := range vs {
  111. if v1 != "content" && v1 != "file" && v1 != "title" {
  112. //老用户可以选用中标企业
  113. if isOld && v1 == "winner" {
  114. continue
  115. } else {
  116. return true
  117. }
  118. }
  119. }
  120. return false
  121. }