feat: 修改收益bug

This commit is contained in:
zerosaturation 2026-05-19 19:59:41 +08:00
parent 7dd947ca12
commit 1ee151630d
3 changed files with 18 additions and 7 deletions

View File

@ -631,7 +631,7 @@ func (r *socialRepositoryImpl) GetMyLikedAssets(userID, starID int64, page, page
if err := r.db.Where("asset_id = ? AND deleted_at IS NULL", item.AssetID). if err := r.db.Where("asset_id = ? AND deleted_at IS NULL", item.AssetID).
First(&exhibition).Error; err == nil { First(&exhibition).Error; err == nil {
item.HourlyEarnings = calculateHourlyEarnings(item.LikeCount) item.HourlyEarnings = calculateHourlyEarnings(item.LikeCount)
item.Earnings = calculateRealtimeEarnings(item.LikeCount, exhibition.StartTime, now) item.Earnings = calculateRealtimeEarnings(item.LikeCount, exhibition.StartTime, now, exhibition.ExpireAt)
} }
} }
@ -664,9 +664,16 @@ func calculateHourlyEarnings(likeCount int32) float64 {
// calculateRealtimeEarnings 实时计算展示收益 // calculateRealtimeEarnings 实时计算展示收益
// 公式R1 = R0 × T × [100% + Buff(n)] // 公式R1 = R0 × T × [100% + Buff(n)]
// R0 = 5 水晶/小时T = 上架时长小时Buff(n) 根据点赞数计算 // R0 = 5 水晶/小时T = 上架时长小时Buff(n) 根据点赞数计算
func calculateRealtimeEarnings(likeCount int32, startTime, now int64) int64 { // 注意:使用 min(now, expireAt) 确保过期后收益不再增长
func calculateRealtimeEarnings(likeCount int32, startTime, now, expireAt int64) int64 {
// 计算有效截止时间(展览结束时间 vs 当前时间,取较小值)
endTime := now
if expireAt > 0 && expireAt < now {
endTime = expireAt
}
// 计算上架时长(毫秒转小时) // 计算上架时长(毫秒转小时)
T := (now - startTime) / 3600000 T := (endTime - startTime) / 3600000
if T <= 0 { if T <= 0 {
T = 1 // 最少1小时 T = 1 // 最少1小时
} }
@ -721,7 +728,7 @@ func (r *socialRepositoryImpl) GetMyTodayLikedAssets(userID, starID int64, page,
if err := r.db.Where("asset_id = ? AND deleted_at IS NULL AND expire_at > ?", item.AssetID, now.UnixMilli()). if err := r.db.Where("asset_id = ? AND deleted_at IS NULL AND expire_at > ?", item.AssetID, now.UnixMilli()).
First(&exhibition).Error; err == nil { First(&exhibition).Error; err == nil {
item.HourlyEarnings = calculateHourlyEarnings(item.LikeCount) item.HourlyEarnings = calculateHourlyEarnings(item.LikeCount)
item.Earnings = calculateRealtimeEarnings(item.LikeCount, exhibition.StartTime, now.UnixMilli()) item.Earnings = calculateRealtimeEarnings(item.LikeCount, exhibition.StartTime, now.UnixMilli(), exhibition.ExpireAt)
} }
} }
@ -782,7 +789,7 @@ func (r *socialRepositoryImpl) GetMyWeekLikedAssets(userID, starID int64, page,
if err := r.db.Where("asset_id = ? AND deleted_at IS NULL AND expire_at > ?", item.AssetID, nowMillis). if err := r.db.Where("asset_id = ? AND deleted_at IS NULL AND expire_at > ?", item.AssetID, nowMillis).
First(&exhibition).Error; err == nil { First(&exhibition).Error; err == nil {
item.HourlyEarnings = calculateHourlyEarnings(item.LikeCount) item.HourlyEarnings = calculateHourlyEarnings(item.LikeCount)
item.Earnings = calculateRealtimeEarnings(item.LikeCount, exhibition.StartTime, nowMillis) item.Earnings = calculateRealtimeEarnings(item.LikeCount, exhibition.StartTime, nowMillis, exhibition.ExpireAt)
} }
} }
@ -832,7 +839,7 @@ func (r *socialRepositoryImpl) GetUserLikedAssets(userID, starID int64, page, pa
if err := r.db.Where("asset_id = ? AND deleted_at IS NULL AND expire_at > ?", item.AssetID, now). if err := r.db.Where("asset_id = ? AND deleted_at IS NULL AND expire_at > ?", item.AssetID, now).
First(&exhibition).Error; err == nil { First(&exhibition).Error; err == nil {
item.HourlyEarnings = calculateHourlyEarnings(item.LikeCount) item.HourlyEarnings = calculateHourlyEarnings(item.LikeCount)
item.Earnings = calculateRealtimeEarnings(item.LikeCount, exhibition.StartTime, now) item.Earnings = calculateRealtimeEarnings(item.LikeCount, exhibition.StartTime, now, exhibition.ExpireAt)
} }
} }

View File

@ -289,7 +289,7 @@ onUnload(() => {
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
padding: 200rpx 40rpx 100rpx; padding: 80rpx 40rpx 100rpx;
box-sizing: border-box; box-sizing: border-box;
} }
@ -389,6 +389,8 @@ onUnload(() => {
display: flex; display: flex;
justify-content: center; justify-content: center;
animation: fadeIn 1s ease-out 0.6s both; animation: fadeIn 1s ease-out 0.6s both;
position: fixed;
bottom: 112rpx;
} }
@keyframes fadeIn { @keyframes fadeIn {

View File

@ -381,7 +381,9 @@ const handleExhibitionCardTap = (item, index) => {
// exhibitionWorks.value[index].earnings = data.earnings; // exhibitionWorks.value[index].earnings = data.earnings;
// } else { // } else {
// //
await loadExhibitedAssets();
await loadLikedAssets(); await loadLikedAssets();
// } // }
uni.showToast({ title: '点赞成功', icon: 'success' }); uni.showToast({ title: '点赞成功', icon: 'success' });