checksearchlogic.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "jyBXBase/rpc/bxcollection/model"
  6. "strings"
  7. "jyBXBase/rpc/bxcollection/bxcol"
  8. "jyBXBase/rpc/bxcollection/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 *bxcol.AddSearchReq) (res *bxcol.CommonRes, err error) {
  25. // todo: add your logic here and delete this line
  26. res = new(bxcol.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. in.NotKey = strings.Replace(in.NotKey, " ", ",", -1)
  38. in.Keywords = strings.Replace(in.Keywords, " ", ",", -1)
  39. query := map[string]interface{}{
  40. "user_id": in.UserId,
  41. }
  42. allData, b := model.Mgo.Find("search_condition", query, "", "", false, -1, -1)
  43. if !b {
  44. res.ErrCode = 1
  45. res.ErrMsg = "查询失败"
  46. return
  47. }
  48. if allData != nil {
  49. if len(*allData) >= 10 {
  50. res.ErrCode = 1
  51. res.ErrMsg = "对不起,最多可保存10个筛选条件。"
  52. return
  53. }
  54. //判重
  55. for _, vlu := range *allData {
  56. if in.Keywords == common.InterfaceToStr(vlu["keywords"]) &&
  57. in.Type == common.InterfaceToStr(vlu["type"]) &&
  58. in.PublishTime == common.InterfaceToStr(vlu["publish_time"]) &&
  59. in.Area == common.InterfaceToStr(vlu["area"]) &&
  60. in.City == common.InterfaceToStr(vlu["city"]) &&
  61. in.Subtype == common.InterfaceToStr(vlu["subtype"]) &&
  62. in.MinPrice == common.InterfaceToStr(vlu["min_price"]) &&
  63. in.MaxPrice == common.InterfaceToStr(vlu["max_price"]) &&
  64. in.Industry == common.InterfaceToStr(vlu["industry"]) &&
  65. in.SelectType == common.InterfaceToStr(vlu["select_type"]) &&
  66. in.BuyerClass == common.InterfaceToStr(vlu["buyer_class"]) &&
  67. in.HasBuyerTel == common.InterfaceToStr(vlu["buyer_tel"]) &&
  68. in.HasWinnerTel == common.InterfaceToStr(vlu["winner_tel"]) &&
  69. in.FileExists == common.InterfaceToStr(vlu["file_exists"]) &&
  70. in.NotKey == common.InterfaceToStr(vlu["not_key"]) &&
  71. in.TabularFlag == common.InterfaceToStr(vlu["tabular_flag"]) {
  72. res.ErrCode = 1
  73. res.ErrMsg = "该条件已保存,无需重复添加。"
  74. return
  75. }
  76. }
  77. }
  78. return
  79. }