feat: 添加在线设备统计功能并优化订阅相关逻辑
- 在DeviceManager中添加GetOnlineDeviceCount方法用于获取在线设备数 - 在统计接口中增加在线设备数返回 - 优化订阅查询逻辑,增加服务组关联节点数量计算 - 添加AnyTLS协议支持及相关URI生成功能 - 重构邀请佣金计算逻辑,支持首购/年付/非首购不同比例 - 修复用户基本信息更新中IsAdmin和Enable字段类型不匹配问题 - 更新数据库迁移脚本和配置文件中邀请相关配置项
This commit is contained in:
@@ -366,7 +366,7 @@ func (l *ActivateOrderLogic) handleCommission(ctx context.Context, userInfo *use
|
||||
return
|
||||
}
|
||||
|
||||
amount := l.calculateCommission(orderInfo.Price)
|
||||
amount := l.calculateCommission(orderInfo.Amount, isNewPurchase && orderInfo.IsNew, orderInfo.Quantity)
|
||||
|
||||
// Use transaction for commission updates
|
||||
err = l.svc.DB.Transaction(func(tx *gorm.DB) error {
|
||||
@@ -401,13 +401,25 @@ func (l *ActivateOrderLogic) handleCommission(ctx context.Context, userInfo *use
|
||||
// referrer existence, commission settings, and order type
|
||||
func (l *ActivateOrderLogic) shouldProcessCommission(userInfo *user.User, orderInfo *order.Order, isNewPurchase bool) bool {
|
||||
return userInfo.RefererId != 0 &&
|
||||
l.svc.Config.Invite.ReferralPercentage != 0 &&
|
||||
(!l.svc.Config.Invite.OnlyFirstPurchase || (isNewPurchase && orderInfo.IsNew))
|
||||
(l.svc.Config.Invite.FirstPurchasePercentage != 0 ||
|
||||
l.svc.Config.Invite.FirstYearlyPurchasePercentage != 0 ||
|
||||
l.svc.Config.Invite.NonFirstPurchasePercentage != 0)
|
||||
}
|
||||
|
||||
// calculateCommission computes the commission amount based on order price and referral percentage
|
||||
func (l *ActivateOrderLogic) calculateCommission(price int64) int64 {
|
||||
return int64(float64(price) * (float64(l.svc.Config.Invite.ReferralPercentage) / 100))
|
||||
// calculateCommission computes the commission amount based on order price and purchase type
|
||||
func (l *ActivateOrderLogic) calculateCommission(price int64, isFirstPurchase bool, quantity int64) int64 {
|
||||
var percentage int64
|
||||
if isFirstPurchase {
|
||||
// 判断是否为年付(12个月)
|
||||
if quantity == 12 {
|
||||
percentage = l.svc.Config.Invite.FirstYearlyPurchasePercentage
|
||||
} else {
|
||||
percentage = l.svc.Config.Invite.FirstPurchasePercentage
|
||||
}
|
||||
} else {
|
||||
percentage = l.svc.Config.Invite.NonFirstPurchasePercentage
|
||||
}
|
||||
return int64(float64(price) * (float64(percentage) / 100))
|
||||
}
|
||||
|
||||
// clearServerCache clears user list cache for all servers associated with the subscription
|
||||
|
||||
Reference in New Issue
Block a user