feat(订单): 实现推荐奖励系统支持佣金和赠送天数两种模式
Build docker and publish / build (20.15.1) (push) Failing after 9m13s
Build docker and publish / build (20.15.1) (push) Failing after 9m13s
重构推荐奖励处理逻辑,新增支持根据配置选择佣金奖励或赠送天数奖励 修改Discount相关字段类型为float64以支持小数折扣 添加GiftDays配置项控制赠送天数 新增FindActiveSubscribe方法查询用户有效订阅
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user