package service import ( "context" "gof_ppw_api/api" "gof_ppw_api/internal/dao" ) var Fund = &FundService{} type FundService struct { Service } // List 基金列表 func (p *FundService) List(ctx context.Context, req *api.FundListReq) (ret interface{}, count int, err error) { orm := dao.FundInformation.Ctx(ctx).As("a") orm = orm.InnerJoin("dc_fund_last_nav b", "a.is_valid = 1 AND a.fund_id = b.fund_id") if req.BeginPriceDate != "" { orm = orm.WhereGTE("b.price_date", req.BeginPriceDate) } if req.EndPriceDate != "" { orm = orm.WhereLTE("b.price_date", req.EndPriceDate) } count, _ = orm.Count() offset, length := (req.Page-1)*req.PageSize, req.PageSize 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() if err != nil { return nil, 0, nil } return all.List(), count, nil } // Detail 特定基金详情 func (p *FundService) Detail(ctx context.Context, fundId string) (ret interface{}, err error) { // db := g.DB("default") // 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) one, err := dao.FundInformation.Ctx(ctx). Where("is_valid = ? AND fund_id = ?", 1, fundId). Fields("fund_id,fund_name,fund_short_name"). One() if err != nil { return nil, err } return one.Map(), nil }