addsearchlogic.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package logic
  2. import (
  3. "context"
  4. "jyBXBase/rpc/bxbase"
  5. IC "jyBXBase/rpc/init"
  6. "jyBXBase/rpc/util"
  7. "log"
  8. "strings"
  9. "time"
  10. "jyBXBase/rpc/internal/svc"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type AddSearchLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewAddSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddSearchLogic {
  19. return &AddSearchLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // 添加搜索列表
  26. func (l *AddSearchLogic) AddSearch(in *bxbase.AddSearchReq) (res *bxbase.CommonRes, err error) {
  27. res = new(bxbase.CommonRes)
  28. newData := make(map[string]interface{})
  29. if in.UserId == "" {
  30. res.ErrCode = 1
  31. res.ErrMsg = "用户未登录"
  32. return
  33. }
  34. if in.InKey == "" {
  35. res.ErrCode = 1
  36. res.ErrMsg = "保存失败"
  37. return
  38. }
  39. log.Println("添加搜索列表:", in)
  40. in.Keywords = strings.Replace(in.Keywords, " ", ",", -1)
  41. switch in.SearchGroup {
  42. case util.SearchGroupBidding:
  43. if ValueSort(util.TopTypesBidding) == in.Subtype {
  44. in.Subtype = ""
  45. }
  46. case util.SearchGroupLeadingProject:
  47. if ValueSort(util.TopTypesLeadingProject) == in.Subtype {
  48. in.Subtype = ""
  49. }
  50. }
  51. newData["keywords"] = in.Keywords
  52. newData["type"] = in.Type
  53. newData["publish_time"] = in.PublishTime
  54. newData["area"] = in.Area
  55. newData["city"] = in.City
  56. newData["subtype"] = in.Subtype
  57. newData["min_price"] = in.MinPrice
  58. newData["max_price"] = in.MaxPrice
  59. newData["industry"] = in.Industry
  60. newData["select_type"] = in.SelectType
  61. newData["buyer_class"] = in.BuyerClass
  62. newData["buyer_tel"] = in.HasBuyerTel
  63. newData["winner_tel"] = in.HasWinnerTel
  64. newData["file_exists"] = in.FileExists
  65. newData["not_key"] = in.NotKey
  66. newData["creation_time"] = time.Now().Unix()
  67. newData["user_id"] = in.UserId
  68. newData["in_key"] = in.InKey
  69. newData["searchGroup"] = in.SearchGroup
  70. newData["searchMode"] = in.SearchMode
  71. newData["wordsMode"] = in.WordsMode
  72. newData["additionalWords"] = in.AdditionalWords
  73. region := map[string]map[string][]string{}
  74. if in.RegionMap != nil {
  75. for k, v := range in.RegionMap {
  76. areaMap := map[string][]string{}
  77. for k1, v1 := range v.Area {
  78. areaMap[k1] = v1.District
  79. }
  80. region[k] = areaMap
  81. }
  82. }
  83. newData["regionMap"] = region
  84. IC.Mgo.Save("search_condition", newData)
  85. return
  86. }