showsearchlogic.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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: add your logic here and delete this line
  27. var (
  28. data []*bxbase.ListSearchRes
  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. if allSearch != nil {
  48. for _, vlu := range *allSearch {
  49. var listSearch bxbase.ListSearchRes
  50. listSearch.Id = common.InterfaceToStr(vlu["_id"])
  51. listSearch.Searchvalue = common.InterfaceToStr(vlu["keywords"])
  52. listSearch.Publishtime = common.InterfaceToStr(vlu["publish_time"])
  53. listSearch.Area = common.InterfaceToStr(vlu["area"])
  54. listSearch.City = common.InterfaceToStr(vlu["city"])
  55. listSearch.Subtype = common.InterfaceToStr(vlu["subtype"])
  56. listSearch.Minprice = common.InterfaceToStr(vlu["min_price"])
  57. listSearch.Maxprice = common.InterfaceToStr(vlu["max_price"])
  58. listSearch.Industry = common.InterfaceToStr(vlu["industry"])
  59. listSearch.SelectType = common.InterfaceToStr(vlu["select_type"])
  60. listSearch.Buyerclass = common.InterfaceToStr(vlu["buyer_class"])
  61. listSearch.Buyertel = common.InterfaceToStr(vlu["buyer_tel"])
  62. listSearch.Winnertel = common.InterfaceToStr(vlu["winner_tel"])
  63. listSearch.FileExists = common.InterfaceToStr(vlu["file_exists"])
  64. listSearch.Notkey = common.InterfaceToStr(vlu["not_key"])
  65. listSearch.Tabularflag = common.InterfaceToStr(vlu["tabular_flag"])
  66. //ppa,buyer,winner,agency
  67. if SelectCheck(listSearch.SelectType) || listSearch.City != "" || listSearch.Notkey != "" ||
  68. (listSearch.Publishtime != "lately-7" && listSearch.Publishtime != "lately-30" && listSearch.Publishtime != "thisyear") ||
  69. listSearch.Winnertel != "" || listSearch.Buyertel != "" || listSearch.Buyerclass != "" {
  70. listSearch.IsPay = true
  71. }
  72. data = append(data, &listSearch)
  73. }
  74. }
  75. res.Data = data
  76. return res, nil
  77. }
  78. func SelectCheck(v string) bool {
  79. vs := strings.Split(v, ",")
  80. for _, v1 := range vs {
  81. if v1 != "content" && v1 != "file" && v1 != "title" {
  82. return true
  83. }
  84. }
  85. return false
  86. }