fund.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package service
  2. import (
  3. "context"
  4. "gof_ppw_api/api"
  5. "gof_ppw_api/internal/dao"
  6. )
  7. var Fund = new(FundService)
  8. type FundService struct {
  9. Service
  10. }
  11. // List 基金列表
  12. func (p *FundService) List(ctx context.Context, req *api.FundListReq) (ret interface{}, count int, err error) {
  13. orm := dao.FundInformation.Ctx(ctx).As("a")
  14. orm = orm.InnerJoin("dc_fund_last_nav b", "a.is_valid = 1 AND a.fund_id = b.fund_id")
  15. if req.BeginPriceDate != "" {
  16. orm = orm.WhereGTE("b.price_date", req.BeginPriceDate)
  17. }
  18. if req.EndPriceDate != "" {
  19. orm = orm.WhereLTE("b.price_date", req.EndPriceDate)
  20. }
  21. count, _ = orm.Count()
  22. offset, length := (req.Page-1)*req.PageSize, req.PageSize
  23. all, err := orm.Fields("a.fund_id,a.fund_name,a.fund_short_name,b.price_date,b.nav").Limit(offset, length).Order("b.price_date DESC").All()
  24. if err != nil {
  25. return nil, 0, nil
  26. }
  27. return all.List(), count, nil
  28. }
  29. // Detail 特定基金详情
  30. func (p *FundService) Detail(ctx context.Context, fundId string) (ret interface{}, err error) {
  31. // db := g.DB("default")
  32. // one, err := db.GetOne(ctx, "SELECT fund_id,fund_name,fund_short_name FROM dc_fund_information WHERE is_valid = 1 AND fund_id = ?", fundId)
  33. one, err := dao.FundInformation.Ctx(ctx).
  34. Where("is_valid = ? AND fund_id = ?", 1, fundId).
  35. Fields("fund_id,fund_name,fund_short_name").
  36. One()
  37. if err != nil {
  38. return nil, err
  39. }
  40. return one.Map(), nil
  41. }