addsearchlogic.go 1.9 KB

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