diff --git a/internal/dao/bundleExtend.go b/internal/dao/bundleExtend.go index d4ed906..e72171d 100644 --- a/internal/dao/bundleExtend.go +++ b/internal/dao/bundleExtend.go @@ -93,7 +93,6 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.Bun Joins("LEFT JOIN bundle_activate bc on bc.user_id = u.id"). Where("rn.name IS NOT NULL"). Where("u.deleted_at = 0"). - Where("bb.month = ?", req.Month). Where("bor.deleted_at IS NULL"). Order("bor.expiration_time desc") if req.UserName != "" { @@ -121,6 +120,12 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.Bun if req.Bought == 1 { session = session.Where("bor.uuid IS NULL") } + if req.Month == "" { + newestMonthQuery := app.ModuleClients.BundleDB.Model(&model.BundleBalance{}).Select("max(month) as month,user_id").Group("user_id") + session.Joins("LEFT JOIN (?) as newest_month on newest_month.user_id = bb.user_id", newestMonthQuery).Where("") + } else { + session = session.Where("bb.month = ?", req.Month) + } err = session.Count(&total).Error if err != nil { return @@ -521,6 +526,8 @@ inner join ( user_id from bundle_balance bb + where + bb.deleted_at is null group by bb.user_id ) newest on diff --git a/internal/logic/bundleExtendLogic.go b/internal/logic/bundleExtendLogic.go index c1d26a4..473ed1c 100644 --- a/internal/logic/bundleExtendLogic.go +++ b/internal/logic/bundleExtendLogic.go @@ -66,7 +66,7 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (*bundle.GetBundl resp.Total = total date, err := time.Parse("2006-01", req.Month) if err != nil { - return nil, errors.New("请求时间有误") + date = time.Now() } resp.Data = lo.Map(data, func(m model.BundleBalancePo, _ int) *bundle.BundleBalanceItem { result := &bundle.BundleBalanceItem{