checksearchlogic.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package logic
  2. import (
  3. "context"
  4. "jyBXBase/rpc/bxcollection/model"
  5. "strings"
  6. "jyBXBase/rpc/bxcollection/bxcol"
  7. "jyBXBase/rpc/bxcollection/internal/svc"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type CheckSearchLogic struct {
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. logx.Logger
  14. }
  15. func NewCheckSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckSearchLogic {
  16. return &CheckSearchLogic{
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. Logger: logx.WithContext(ctx),
  20. }
  21. }
  22. // 修改筛选列表
  23. func (l *CheckSearchLogic) CheckSearch(in *bxcol.AddSearchReq) (res *bxcol.CommonRes, err error) {
  24. // todo: add your logic here and delete this line
  25. res = new(bxcol.CommonRes)
  26. if in.UserId == "" {
  27. res.ErrCode = 1
  28. res.ErrMsg = "用户未登录"
  29. return
  30. }
  31. if in.Keywords == "" {
  32. res.ErrCode = 1
  33. res.ErrMsg = "请先输入关键词"
  34. return
  35. }
  36. in.NotKey = strings.Replace(in.NotKey, " ", ",", -1)
  37. in.Keywords = strings.Replace(in.Keywords, " ", ",", -1)
  38. query := map[string]interface{}{
  39. "user_id": in.UserId,
  40. }
  41. if model.Mgo.Count("search_condition", query) >= 10 {
  42. res.ErrCode = 1
  43. res.ErrMsg = "对不起,最多可保存10个筛选条件。"
  44. return
  45. }
  46. query["keywords"] = in.Keywords
  47. query["type"] = in.Type
  48. query["publish_time"] = in.PublishTime
  49. query["area"] = in.Area
  50. query["city"] = in.City
  51. query["subtype"] = in.Subtype
  52. query["min_price"] = in.MinPrice
  53. query["max_price"] = in.MaxPrice
  54. query["industry"] = in.Industry
  55. query["select_type"] = in.SelectType
  56. query["buyer_class"] = in.BuyerClass
  57. query["buyer_tel"] = in.HasBuyerTel
  58. query["winner_tel"] = in.HasWinnerTel
  59. query["file_exists"] = in.FileExists
  60. query["not_key"] = in.NotKey
  61. query["tabular_flag"] = in.TabularFlag
  62. if model.Mgo.Count("search_condition", query) > 0 {
  63. res.ErrCode = 1
  64. res.ErrMsg = "该条件已保存,无需重复添加。"
  65. }
  66. return
  67. }