diff --git a/internal/dao/bundleExtend.go b/internal/dao/bundleExtend.go index e34abc4..e9cc192 100644 --- a/internal/dao/bundleExtend.go +++ b/internal/dao/bundleExtend.go @@ -97,6 +97,9 @@ func GetBundleExtendRecordList(req *bundle.BundleExtendRecordsListRequest) (data } func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.BundleBalancePo, total int64, err error) { + subQuery := app.ModuleClients.BundleDB.Table("bundle_order_records"). + Select("customer_id, MAX(created_at) AS max_created_time"). + Group("customer_id") session := app.ModuleClients.BundleDB.Table("`micro-account`.`user` AS u"). Select(` bb.*, @@ -111,7 +114,8 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.Bun Joins("LEFT JOIN fiee_bundle.bundle_balance AS bb on u.id = bb.user_id"). Joins("LEFT JOIN `micro-account`.`real_name` rn on u.real_name_id = rn.id"). Joins("LEFT JOIN bundle_order_records bor on bor.uuid = bb.order_uuid"). - Where("bor.deleted_at IS NULL and rn.name IS NOT NULL and u.deleted_at = 0") + Joins("INNER JOIN (?) AS t ON bor.customer_id = t.customer_id AND bor.created_at = t.max_created_time", subQuery). + Where("rn.name IS NOT NULL and u.deleted_at = 0") if req.UserName != "" { if utils.IsPhoneNumber(req.UserName) { session = session.Where("u.tel_num = ?", req.UserName) @@ -286,7 +290,7 @@ func ToBeComfirmedWorks(req *bundle.ToBeComfirmedWorksReq) (data []model.CastWor session := app.ModuleClients.BundleDB. Table("cast_work_log AS cwl"). Joins("INNER JOIN (?) AS t ON cwl.work_uuid = t.work_uuid AND cwl.update_time = t.max_update_time", subQuery). - Where("artist_uuid = ?", req.ArtistUuid) + Where("artist_uuid = ?", req.ArtistUuid).Where("work_status in ?", []int{4, 5, 6, 7}) err = session.Count(&total).Error if err != nil { return