listlogic.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "jyBXBase/rpc/bxcollection/bxcol"
  6. "jyBXBase/rpc/bxcollection/internal/svc"
  7. "jyBXBase/rpc/bxcollection/model"
  8. "jyBXBase/rpc/bxcollection/util"
  9. "log"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type ListLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
  18. return &ListLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. // 获取收藏列表
  25. func (l *ListLogic) List(in *bxcol.ListReq) (*bxcol.ListRes, error) {
  26. var ldata bxcol.ColList
  27. pagesize_max := 50
  28. isPay, _ := util.Power(in.UserId)
  29. if !isPay {
  30. pagesize_max = 100
  31. }
  32. if in.Pagesize != 0 {
  33. pagesize_max = int(in.Pagesize)
  34. }
  35. sql := util.CollListSql(in, isPay, in.UserId)
  36. log.Println(sql)
  37. data := model.Mysql.SelectBySql(sql)
  38. count := 0
  39. result := []map[string]interface{}{}
  40. if data != nil && len(*data) > 0 {
  41. if in.Pagenum <= 0 {
  42. in.Pagenum = 1
  43. }
  44. start := (int(in.Pagenum) - 1) * pagesize_max
  45. end := int(in.Pagenum) * pagesize_max
  46. if end > len(*data) {
  47. end = len(*data)
  48. }
  49. if start < len(*data) {
  50. result = (*data)[start:end]
  51. }
  52. count = len(*data)
  53. }
  54. haveNextPage := len(result) >= pagesize_max
  55. ldata.Count = int64(count)
  56. ldata.HaveNextPage = haveNextPage
  57. ldata.Pagesize = int64(pagesize_max)
  58. var res []*bxcol.ColData
  59. mres := util.GetInfoById(model.Mgo_Bidding, "collection", "bidding_back", result)
  60. for _, v := range mres {
  61. var r bxcol.ColData
  62. r.Id = v.Id
  63. r.Title = v.Title
  64. r.Buyerclass = v.Buyerclass
  65. r.Buyer = v.Buyer
  66. r.Type = v.Type
  67. r.Budget = common.InterfaceToStr(v.Budget)
  68. r.Area = v.Area
  69. r.Bidamount = common.InterfaceToStr(v.Bidamount)
  70. r.Bidopentime = v.Bidopentime
  71. r.Publishtime = v.Publishtime
  72. r.SSubscopeclass = v.S_subscopeclass
  73. r.SWinner = v.S_winner
  74. res = append(res, &r)
  75. }
  76. ldata.Res = res
  77. return &bxcol.ListRes{
  78. Ldata: &ldata,
  79. }, nil
  80. }