supplysearchlogic.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jyInfo/rpc/consumer/consumerinfo"
  4. "context"
  5. "app.yhyue.com/moapp/jybase/common"
  6. "app.yhyue.com/moapp/jyInfo/api/internal/svc"
  7. "app.yhyue.com/moapp/jyInfo/api/internal/types"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type SupplySearchLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewSupplySearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SupplySearchLogic {
  16. return &SupplySearchLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. }
  21. }
  22. func (l *SupplySearchLogic) SupplySearch(req *types.PubSupplyInfoReq) (resp *types.CommonRes, err error) {
  23. if req.UserId == "" { //未登录用户每次搜索100条数据
  24. req.PageIndex = common.Int64All(common.If(req.PageIndex == 0, 1, req.PageIndex))
  25. if req.PageIndex*req.PageSize > 100 {
  26. req.PageIndex = 1
  27. req.PageSize = 100
  28. }
  29. }
  30. supplySearch, err0 := l.svcCtx.Consumer.SupplyInfoSearch(l.ctx, &consumerinfo.SupplyInfoSearchReq{
  31. Keywords: req.Keywords,
  32. SearchType: req.SearchType,
  33. Province: req.Province,
  34. City: req.City,
  35. Time: req.Time,
  36. Status: req.Status,
  37. PageSize: req.PageSize,
  38. PageIndex: req.PageIndex,
  39. })
  40. if err0 != nil {
  41. return &types.CommonRes{
  42. Err_code: -1,
  43. Err_msg: "错误",
  44. Data: nil,
  45. }, nil
  46. }
  47. return &types.CommonRes{
  48. Err_code: common.IntAll(supplySearch.ErrCode),
  49. Err_msg: supplySearch.ErrMsg,
  50. Data: supplySearch.Data,
  51. }, nil
  52. }