addsearchlogic.go 1.7 KB

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