showsearchlogic.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. allSearch, b := IC.Mgo.Find("search_condition", query, `{"creation_time":-1}`, "", false, -1, -1)
  46. if !b {
  47. res.ErrCode = -1
  48. res.ErrMsg = "用户搜索信息查询失败"
  49. return res, nil
  50. }
  51. //需判断新老用户
  52. 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}`)
  53. if user == nil || len(*user) == 0 {
  54. res.ErrCode = -1
  55. res.ErrMsg = "用户信息查询失败"
  56. return res, nil
  57. }
  58. registedate, _ := (*user)["l_registedate"].(int64)
  59. isOld = registedate != 0 && registedate < IC.C.BidSearchOldUserLimit
  60. if allSearch != nil {
  61. for _, vlu := range *allSearch {
  62. var listSearch bxbase.ListSearchRes
  63. listSearch.Id = common.InterfaceToStr(vlu["_id"])
  64. listSearch.Searchvalue = common.InterfaceToStr(vlu["keywords"])
  65. //PC端保存带时间范围的刷选条件时,到期时间选择18号,时间参数为18号0点,正常应该是18号23点59分59秒
  66. //现对老数据进行处理
  67. publishTime := common.InterfaceToStr(vlu["publish_time"])
  68. if publishTime != "" && strings.Contains(publishTime, "_") {
  69. publishTimeStart := strings.Split(publishTime, "_")[0]
  70. if publishTimeEnd := strings.Split(publishTime, "_")[1]; publishTimeEnd != "" {
  71. if endTimeInt, err := strconv.ParseInt(publishTimeEnd, 10, 64); err == nil {
  72. endTimeUnix := time.Unix(endTimeInt, 0)
  73. endTimeInt = time.Date(endTimeUnix.Year(), endTimeUnix.Month(), endTimeUnix.Day(), 23, 59, 59, 59, time.Local).Unix()
  74. publishTime = fmt.Sprintf("%s_%d", publishTimeStart, endTimeInt)
  75. }
  76. }
  77. }
  78. listSearch.Publishtime = publishTime
  79. listSearch.Area = common.InterfaceToStr(vlu["area"])
  80. listSearch.Buyer = common.InterfaceToStr(vlu["buyer"])
  81. listSearch.Winner = common.InterfaceToStr(vlu["winner"])
  82. listSearch.Agency = common.InterfaceToStr(vlu["agency"])
  83. listSearch.District = common.InterfaceToStr(vlu["district"])
  84. listSearch.City = common.InterfaceToStr(vlu["city"])
  85. listSearch.Subtype = common.InterfaceToStr(vlu["subtype"])
  86. listSearch.Minprice = common.InterfaceToStr(vlu["min_price"])
  87. listSearch.Maxprice = common.InterfaceToStr(vlu["max_price"])
  88. listSearch.Industry = common.InterfaceToStr(vlu["industry"])
  89. listSearch.SelectType = common.InterfaceToStr(vlu["select_type"])
  90. listSearch.Buyerclass = common.InterfaceToStr(vlu["buyer_class"])
  91. listSearch.Buyertel = common.InterfaceToStr(vlu["buyer_tel"])
  92. listSearch.Winnertel = common.InterfaceToStr(vlu["winner_tel"])
  93. listSearch.FileExists = common.InterfaceToStr(vlu["file_exists"])
  94. listSearch.Notkey = common.InterfaceToStr(vlu["not_key"])
  95. listSearch.Tabularflag = common.InterfaceToStr(vlu["tabular_flag"])
  96. listSearch.SearchGroup = common.Int64All(vlu["searchGroup"])
  97. listSearch.SearchMode = common.Int64All(vlu["searchMode"])
  98. listSearch.WordsMode = common.Int64All(vlu["wordsMode"])
  99. listSearch.AdditionalWords = common.InterfaceToStr(vlu["additionalWords"])
  100. listSearch.InKey = common.InterfaceToStr(vlu["in_key"])
  101. listSearch.Type = common.InterfaceToStr(vlu["type"])
  102. regionMap := gconv.Map(vlu["regionMap"])
  103. region := map[string]*bxbase.Area{}
  104. if regionMap != nil {
  105. for k1, v1 := range regionMap {
  106. areaMap := map[string]*bxbase.District{}
  107. for k2, v2 := range gconv.Map(v1) {
  108. log.Println(gconv.Strings(v2))
  109. areaMap[k2] = &bxbase.District{
  110. District: gconv.Strings(v2),
  111. }
  112. }
  113. region[k1] = &bxbase.Area{
  114. Area: areaMap,
  115. }
  116. }
  117. }
  118. listSearch.RegionMap = region
  119. //ppa,buyer,winner,agency
  120. if SelectCheck(listSearch.SelectType, isOld) || listSearch.City != "" || listSearch.Notkey != "" ||
  121. (listSearch.Publishtime != "lately-7" && listSearch.Publishtime != "lately-30" && listSearch.Publishtime != "thisyear") ||
  122. listSearch.Winnertel != "" || listSearch.Buyertel != "" || listSearch.Buyerclass != "" {
  123. listSearch.IsPay = true
  124. }
  125. data = append(data, &listSearch)
  126. }
  127. }
  128. res.Data = data
  129. return res, nil
  130. }
  131. func SelectCheck(v string, isOld bool) bool {
  132. vs := strings.Split(v, ",")
  133. for _, v1 := range vs {
  134. if v1 != "content" && v1 != "file" && v1 != "title" {
  135. //老用户可以选用中标企业
  136. if isOld && v1 == "winner" {
  137. continue
  138. } else {
  139. return true
  140. }
  141. }
  142. }
  143. return false
  144. }