showsearchlogic.go 5.5 KB

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