feat(订单): 实现推荐奖励系统支持佣金和赠送天数两种模式
Build docker and publish / build (20.15.1) (push) Failing after 9m13s

重构推荐奖励处理逻辑,新增支持根据配置选择佣金奖励或赠送天数奖励
修改Discount相关字段类型为float64以支持小数折扣
添加GiftDays配置项控制赠送天数
新增FindActiveSubscribe方法查询用户有效订阅
This commit is contained in:
2025-10-17 06:01:29 -07:00
parent 7da63ade5c
commit bfbc675e1a
12 changed files with 139 additions and 27 deletions
+1
View File
@@ -203,6 +203,7 @@ type InviteConfig struct {
ForcedInvite bool `yaml:"ForcedInvite" default:"false"`
ReferralPercentage int64 `yaml:"ReferralPercentage" default:"0"`
OnlyFirstPurchase bool `yaml:"OnlyFirstPurchase" default:"false"`
GiftDays int64 `yaml:"GiftDays" default:"3"`
}
type Telegram struct {
+2 -2
View File
@@ -861,10 +861,10 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
serverGroupRouter.GET("/user", server.GetServerUserListHandler(serverCtx))
}
serverV2GroupRouter := router.Group("/v2/server")
serverGroupRouterV2 := router.Group("/v2/server")
{
// Get Server Protocol Config
serverV2GroupRouter.GET("/:server_id", server.QueryServerProtocolConfigHandler(serverCtx))
serverGroupRouterV2.GET("/:server_id", server.QueryServerProtocolConfigHandler(serverCtx))
}
}
+2 -2
View File
@@ -3,7 +3,7 @@ package order
import "github.com/perfect-panel/server/internal/types"
func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64) float64 {
var finalDiscount int64 = 100
var finalDiscount float64 = 1.0
for _, discount := range discounts {
if inputMonths >= discount.Quantity && discount.Discount < finalDiscount {
@@ -11,5 +11,5 @@ func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64) float64
}
}
return float64(finalDiscount) / float64(100)
return finalDiscount
}
+2 -2
View File
@@ -7,14 +7,14 @@ import (
)
func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64) float64 {
var finalDiscount int64 = 100
var finalDiscount float64 = 1.0
for _, discount := range discounts {
if inputMonths >= discount.Quantity && discount.Discount < finalDiscount {
finalDiscount = discount.Discount
}
}
return float64(finalDiscount) / float64(100)
return finalDiscount
}
func calculateCoupon(amount int64, couponInfo *coupon.Coupon) int64 {
+2 -2
View File
@@ -71,8 +71,8 @@ func (s *Subscribe) BeforeUpdate(tx *gorm.DB) error {
}
type Discount struct {
Months int64 `json:"months"`
Discount int64 `json:"discount"`
Months int64 `json:"months"`
Discount float64 `json:"discount"`
}
type Group struct {
+1
View File
@@ -77,6 +77,7 @@ type customUserLogicModel interface {
QueryUserSubscribe(ctx context.Context, userId int64, status ...int64) ([]*SubscribeDetails, error)
FindOneSubscribeDetailsById(ctx context.Context, id int64) (*SubscribeDetails, error)
FindOneUserSubscribe(ctx context.Context, id int64) (*SubscribeDetails, error)
FindActiveSubscribe(ctx context.Context, userId int64) (*Subscribe, error)
FindUsersSubscribeBySubscribeId(ctx context.Context, subscribeId int64) ([]*Subscribe, error)
UpdateUserSubscribeWithTraffic(ctx context.Context, id, download, upload int64, tx ...*gorm.DB) error
QueryResisterUserTotalByDate(ctx context.Context, date time.Time) (int64, error)
+21
View File
@@ -198,3 +198,24 @@ func (m *defaultUserModel) DeleteSubscribeById(ctx context.Context, id int64, tx
func (m *defaultUserModel) ClearSubscribeCache(ctx context.Context, data ...*Subscribe) error {
return m.ClearSubscribeCacheByModels(ctx, data...)
}
// FindActiveSubscribe finds the user's active subscription
func (m *defaultUserModel) FindActiveSubscribe(ctx context.Context, userId int64) (*Subscribe, error) {
var data Subscribe
err := m.QueryNoCacheCtx(ctx, &data, func(conn *gorm.DB, v interface{}) error {
now := time.Now()
return conn.Model(&Subscribe{}).
Where("user_id = ? AND status = ? AND expire_time > ?", userId, 1, now).
Order("expire_time DESC").
First(&data).Error
})
if err != nil {
if err == gorm.ErrRecordNotFound {
return nil, nil
}
return nil, err
}
return &data, nil
}
+3 -2
View File
@@ -1170,6 +1170,7 @@ type InviteConfig struct {
ForcedInvite bool `json:"forced_invite"`
ReferralPercentage int64 `json:"referral_percentage"`
OnlyFirstPurchase bool `json:"only_first_purchase"`
GiftDays int64 `json:"gift_days"`
}
type KickOfflineRequest struct {
@@ -2065,8 +2066,8 @@ type SubscribeConfig struct {
}
type SubscribeDiscount struct {
Quantity int64 `json:"quantity"`
Discount int64 `json:"discount"`
Quantity int64 `json:"quantity"`
Discount float64 `json:"discount"`
}
type SubscribeGroup struct {