addsearchlogic.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. // todo 待测试
  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.NotKey = strings.Replace(in.NotKey, " ", ",", -1)
  41. in.Keywords = strings.Replace(in.Keywords, " ", ",", -1)
  42. in.AdditionalWords = strings.Replace(in.AdditionalWords, " ", ",", -1)
  43. newData["keywords"] = in.Keywords
  44. newData["type"] = in.Type
  45. newData["publish_time"] = in.PublishTime
  46. newData["area"] = in.Area
  47. newData["city"] = in.City
  48. newData["subtype"] = in.Subtype
  49. newData["min_price"] = in.MinPrice
  50. newData["max_price"] = in.MaxPrice
  51. newData["industry"] = in.Industry
  52. newData["select_type"] = in.SelectType
  53. newData["buyer_class"] = in.BuyerClass
  54. newData["buyer_tel"] = in.HasBuyerTel
  55. newData["winner_tel"] = in.HasWinnerTel
  56. newData["file_exists"] = in.FileExists
  57. newData["not_key"] = in.NotKey
  58. newData["creation_time"] = time.Now().Unix()
  59. newData["user_id"] = in.UserId
  60. newData["in_key"] = in.InKey
  61. newData["searchGroup"] = in.SearchGroup
  62. newData["searchMode"] = in.SearchMode
  63. newData["wordsMode"] = in.WordsMode
  64. newData["additionalWords"] = in.AdditionalWords
  65. IC.Mgo.Save("search_condition", newData)
  66. return
  67. }