checksearchlogic.go 1.8 KB

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