diff --git a/internal/dao/bundleExtend.go b/internal/dao/bundleExtend.go index 10d395b..5a4da27 100644 --- a/internal/dao/bundleExtend.go +++ b/internal/dao/bundleExtend.go @@ -538,38 +538,108 @@ func GetVedioWorkDetail(req *bundle.GetVedioWorkDetailReq) (data model.CastWorkV } func ToBeComfirmedWorks(req *bundle.ToBeComfirmedWorksReq) (data []model.CastWorkLog, total int64, unconfirmed int64, err error) { - unConfirmSubQuery := app.ModuleClients.BundleDB. - Table("cast_work_log"). - Select("work_uuid, MAX(update_time) AS max_update_time"). - Where("cast_work_log.deleted_at = 0"). - Group("work_uuid").Where("work_status = ?", 4) + var bundleTimeInfo model.BundleBalanceTimeInfo + //获取套餐信息 + err = app.ModuleClients.BundleDB.Model(&model.BundleBalance{}). + Select("bundle_balance.user_id,bundle_balance.order_uuid,bundle_balance.month,bundle_balance.expired_at,bundle_balance.start_at"). + Joins("left join micro-account.user u on bundle_balance.user_id = u.id and u.deleted_at = 0"). + Where("bundle_balance.deleted_at is null"). + Where("u.sub_num = ?", req.ArtistUuid). + Where("bundle_balance.month = ?", time.Now().Format("2006-01")). + Order("bundle_balance.start_at desc"). + First(&bundleTimeInfo).Error + if err != nil { + return + } + //查询当前套餐为新购还是续费 + orderReq := &bundle.OrderRecordsDetailRequest{} + orderReq.Uuid = bundleTimeInfo.OrderUUID + orderInfo, err := OrderRecordDetail(orderReq) + if err != nil { + fmt.Println("获取用户订单信息失败:", err) + return nil, 0, 0, errors.New("获取用户订单信息失败") + } - err = 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", unConfirmSubQuery). - Where("artist_uuid = ?", req.ArtistUuid).Where("cwl.deleted_at = 0").Where("confirmed_at = ?", 0).Count(&unconfirmed).Error - if err != nil { + if orderInfo.PurchaseType == 1 { + //新购,只显示当前套餐的待确认作品 + //获取待确认列表 + unConfirmSubQuery := app.ModuleClients.BundleDB. + Table("cast_work_log"). + Select("work_uuid, MAX(update_time) AS max_update_time"). + Joins("left join cast_work_extra cwe on cwe.work_uuid = cast_work_log.work_uuid and cwe.deleted_at = 0"). + Where("cast_work_log.deleted_at = 0"). + Where("cwe.bundle_order_uuid = ?", bundleTimeInfo.OrderUUID). + Group("work_uuid").Where("work_status = ?", 4) + + err = 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", unConfirmSubQuery). + Where("artist_uuid = ?", req.ArtistUuid).Where("cwl.deleted_at = 0").Where("confirmed_at = ?", 0).Count(&unconfirmed).Error + if err != nil { + return + } + subQuery := app.ModuleClients.BundleDB. + Table("cast_work_log"). + Select("work_uuid, MAX(update_time) AS max_update_time"). + Joins("left join cast_work_extra cwe on cwe.work_uuid = cast_work_log.work_uuid and cwe.deleted_at = 0"). + Where("cast_work_log.deleted_at = 0"). + Where("cwe.bundle_order_uuid = ?", bundleTimeInfo.OrderUUID). + Group("work_uuid").Where("work_status in ?", []int{4, 5, 6, 7, 9}) + 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("cwl.deleted_at = 0") + err = session.Count(&total).Error + if err != nil { + return + } + if req.Page != 0 && req.PageSize != 0 { + session.Limit(int(req.PageSize)).Offset(int(req.Page-1) * int(req.PageSize)) + } + err = session.Order("created_at desc").Find(&data).Error + return + } else if orderInfo.PurchaseType == 2 { + //续费,显示当前套餐和旧套餐的待确认作品 + //获取待确认列表 + unConfirmSubQuery := app.ModuleClients.BundleDB. + Table("cast_work_log"). + Select("work_uuid, MAX(update_time) AS max_update_time"). + Joins("left join cast_work_extra cwe on cwe.work_uuid = cast_work_log.work_uuid and cwe.deleted_at = 0"). + Where("cast_work_log.deleted_at = 0"). + Where("cwe.bundle_order_uuid in ?", []string{bundleTimeInfo.OrderUUID, orderInfo.RenewalOrderUUID}). + Group("work_uuid").Where("work_status = ?", 4) + + err = 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", unConfirmSubQuery). + Where("artist_uuid = ?", req.ArtistUuid).Where("cwl.deleted_at = 0").Where("confirmed_at = ?", 0).Count(&unconfirmed).Error + if err != nil { + return + } + subQuery := app.ModuleClients.BundleDB. + Table("cast_work_log"). + Select("work_uuid, MAX(update_time) AS max_update_time"). + Joins("left join cast_work_extra cwe on cwe.work_uuid = cast_work_log.work_uuid and cwe.deleted_at = 0"). + Where("cast_work_log.deleted_at = 0"). + Where("cwe.bundle_order_uuid in ?", []string{bundleTimeInfo.OrderUUID, orderInfo.RenewalOrderUUID}). + Group("work_uuid").Where("work_status in ?", []int{4, 5, 6, 7, 9}) + 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("cwl.deleted_at = 0") + err = session.Count(&total).Error + if err != nil { + return + } + if req.Page != 0 && req.PageSize != 0 { + session.Limit(int(req.PageSize)).Offset(int(req.Page-1) * int(req.PageSize)) + } + err = session.Order("created_at desc").Find(&data).Error return } - subQuery := app.ModuleClients.BundleDB. - Table("cast_work_log"). - Select("work_uuid, MAX(update_time) AS max_update_time"). - Where("cast_work_log.deleted_at = 0"). - Group("work_uuid").Where("work_status in ?", []int{4, 5, 6, 7, 9}) - 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("cwl.deleted_at = 0") - err = session.Count(&total).Error - if err != nil { - return - } - if req.Page != 0 && req.PageSize != 0 { - session.Limit(int(req.PageSize)).Offset(int(req.Page-1) * int(req.PageSize)) - } - err = session.Order("created_at desc").Find(&data).Error - return + return nil, 0, 0, errors.New("订单购买类型错误") } func ConfirmWork(req *bundle.ConfirmWorkReq) error { diff --git a/internal/logic/bundleExtendLogic.go b/internal/logic/bundleExtendLogic.go index d6eba5a..8677a56 100644 --- a/internal/logic/bundleExtendLogic.go +++ b/internal/logic/bundleExtendLogic.go @@ -223,22 +223,12 @@ func GetBundleBalanceByUserId(req *bundle.GetBundleBalanceByUserIdReq) (*bundle. } else { IsExpired = msg.NotExpired //未过期 } - var payTime time.Time - if data.PayTime != "" { - loc, _ := time.LoadLocation("Asia/Shanghai") - // 按实际格式选一种,或两种都支持 - if t, err := time.ParseInLocation("2006-01-02 15:04:05", data.PayTime, loc); err == nil { - payTime = t - } else if t, err := time.ParseInLocation("20060102 15:04:05", data.PayTime, loc); err == nil { - payTime = t - } - // 若解析失败,payTime 为零值 - } + result := &bundle.GetBundleBalanceByUserIdResp{ OrderUUID: data.OrderUUID, BundleName: data.BundleName, BundleStatus: IsExpired, - PayTime: payTime.UnixMilli(), + PayTime: data.PayTime.UnixMilli(), StartTime: data.StartAt.UnixMilli(), ExpiredTime: data.ExpiredAt.UnixMilli(), PaymentAmount: data.PaymentAmount, diff --git a/internal/model/bundle.go b/internal/model/bundle.go index 5264009..f34a2d6 100644 --- a/internal/model/bundle.go +++ b/internal/model/bundle.go @@ -159,17 +159,17 @@ type BundleBalancePo struct { } type UserBundleBalancePo struct { - OrderUUID string `json:"orderUUID" gorm:"column:order_uuid"` - BundleUuid string `json:"bundleUuid" gorm:"column:bundle_uuid"` - BundleName string `json:"bundleName" gorm:"column:bundle_name"` - BundleStatus string `json:"bundleStatus" gorm:"column:bundle_status"` - PayTime string `json:"payTime" gorm:"column:pay_time"` - ExpiredTime string `json:"expiredTime" gorm:"column:expired_time"` - PaymentAmount string `json:"paymentAmount" gorm:"column:payment_amount"` - PaymentType int32 `json:"paymentType" gorm:"column:payment_type"` - Activate int `gorm:"column:activate"` - RenewalOrderUUID string `gorm:"column:renewal_order_uuid;type:varchar(1024);comment:续费订单UUID" json:"renewalOrderUUID"` - PurchaseType uint64 `gorm:"column:purchase_type;type:bigint;comment:购买类型 1:新购 2:续费" json:"purchaseType"` + OrderUUID string `json:"orderUUID" gorm:"column:order_uuid"` + BundleUuid string `json:"bundleUuid" gorm:"column:bundle_uuid"` + BundleName string `json:"bundleName" gorm:"column:bundle_name"` + BundleStatus string `json:"bundleStatus" gorm:"column:bundle_status"` + PayTime time.Time `json:"payTime" gorm:"column:pay_time"` + ExpiredTime string `json:"expiredTime" gorm:"column:expired_time"` + PaymentAmount string `json:"paymentAmount" gorm:"column:payment_amount"` + PaymentType int32 `json:"paymentType" gorm:"column:payment_type"` + Activate int `gorm:"column:activate"` + RenewalOrderUUID string `gorm:"column:renewal_order_uuid;type:varchar(1024);comment:续费订单UUID" json:"renewalOrderUUID"` + PurchaseType uint64 `gorm:"column:purchase_type;type:bigint;comment:购买类型 1:新购 2:续费" json:"purchaseType"` BundleBalance } @@ -441,3 +441,12 @@ type RenewalInfo struct { AccountBundleNumber int AccountIncreaseNumber int } + +// 套餐时间信息 +type BundleBalanceTimeInfo struct { + UserId int `gorm:"column:user_id;not null"` + OrderUUID string `gorm:"column:order_uuid;not null"` + Month string `gorm:"column:month;not null"` + ExpiredAt time.Time `gorm:"column:expired_at;not null"` + StartAt time.Time `gorm:"column:start_at;not null"` +} diff --git a/pb/bundle.proto b/pb/bundle.proto index 70cb3ae..5fc8128 100644 --- a/pb/bundle.proto +++ b/pb/bundle.proto @@ -71,7 +71,7 @@ service Bundle { rpc ToBeComfirmedWorks(ToBeComfirmedWorksReq) returns (ToBeComfirmedWorksResp) {} // 待确认作品列表 rpc ConfirmWork(ConfirmWorkReq) returns (ConfirmWorkResp) {} // 确认作品 - rpc GetWaitConfirmWorkList(GetWaitConfirmWorkListReq) returns (GetWaitConfirmWorkListResp) {} // 获取待确认作品列表 + rpc GetWaitConfirmWorkList(GetWaitConfirmWorkListReq) returns (GetWaitConfirmWorkListResp) {} // 获取待确认作品列表(用于客户端自动确认定时任务) //对账单 rpc GetReconciliationList(GetReconciliationListReq) returns (GetReconciliationListResp) {} // 获取对账单列表