Skip to content

Commit

Permalink
feat(mgm): add mgm rules with migrate and seed
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrix-X committed Oct 5, 2023
1 parent 22431a6 commit 87883f2
Show file tree
Hide file tree
Showing 14 changed files with 352 additions and 12 deletions.
106 changes: 106 additions & 0 deletions api/admin/crm/market/mgm.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
syntax = "v1"

info(
title: "MGM管理"
desc: "MGM管理"
author: "MichaelHu"
email: "[email protected]"
version: "v1"
)

@server(
group: admin/crm/market/mgm
prefix: /api/v1/admin/market
middleware: EmployeeJWTAuth
)

service PowerX {
@doc "查询MGM列表"
@handler ListMGMsPage
get /mgms/page-list (ListMGMsPageRequest) returns (ListMGMsPageReply)
@doc "请求MGM上传链接"
@handler CreateMGM
post /mgms (CreateMGMRequest) returns (CreateMGMReply)

@doc "创建或更新MGM"
@handler UpdateMGM
put /mgms/:id (UpdateMGMRequest) returns (UpdateMGMReply)

@doc "根据获取MGM"
@handler GetMGM
get /mgms/:id (GetMGMRequest) returns (GetMGMReply)

@doc "删除MGM"
@handler DeleteMGM
delete /mgms/:id (DeleteMGMRequest) returns (DeleteMGMReply)
}

type (
ListMGMsPageRequest struct {
MGMTypes []int8 `form:"mgmTypes,optional"`
Keys []string `form:"keys,optional"`
OrderBy string `form:"orderBy,optional"`
PageIndex int `form:"pageIndex,optional"`
PageSize int `form:"pageSize,optional"`
}

MGM struct {
Id int64 `json:"id,optional"`

Title string `json:"title,optional"`
SubTitle string `json:"subTitle,optional"`
CoverImageId int64 `json:"coverImageId,optional"`
ResourceUrl string `json:"resourceUrl,optional"`
Description string `json:"description,optional"`
MGMType int `json:"mgmType,optional"`
ViewedCount int `json:"viewedCount,optional"`
}

ListMGMsPageReply struct {
List []*MGM `json:"list"`
PageIndex int `json:"pageIndex"`
PageSize int `json:"pageSize"`
Total int64 `json:"total"`
}
)

type (
CreateMGMRequest struct {
MGM
}

CreateMGMReply struct {
MGMId int64 `json:"id"`
}
)

type (
UpdateMGMRequest struct {
MGMId int64 `path:"id"`
MGM
}

UpdateMGMReply struct {
MGMId int64 `json:"id"`
}
)

type (
GetMGMRequest struct {
MGMId int64 `path:"id"`
}

GetMGMReply struct {
*MGM
}
)

type (
DeleteMGMRequest struct {
MGMId int64 `path:"id"`
}

DeleteMGMReply struct {
MGMId int64 `json:"id"`
}
)
3 changes: 2 additions & 1 deletion cmd/ctl/database/migrate/powerx.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (m *PowerMigrator) AutoMigrate() {

// market
_ = m.db.AutoMigrate(&market.Media{})
_ = m.db.AutoMigrate(&market.MGMRule{}, market.InviteRecord{}, market.CommissionRecord{})

// media
_ = m.db.AutoMigrate(&media.MediaResource{}, &media.PivotMediaResourceToObject{})
Expand All @@ -83,7 +84,7 @@ func (m *PowerMigrator) AutoMigrate() {
_ = m.db.AutoMigrate(&trade.OrderStatusTransition{}, &trade.PivotOrderToInventoryLog{})
_ = m.db.AutoMigrate(&trade.Payment{}, &trade.PaymentItem{})
_ = m.db.AutoMigrate(&trade.RefundOrder{}, &trade.RefundOrderItem{})
_ = m.db.AutoMigrate(&trade.TokenBalance{}, &trade.ExchangeRatio{}, &trade.ExchangeRecord{})
_ = m.db.AutoMigrate(&trade.TokenBalance{}, &trade.TokenExchangeRatio{}, &trade.TokenExchangeRecord{})

// custom
migrate.AutoMigrateCustom(m.db)
Expand Down
1 change: 1 addition & 0 deletions cmd/ctl/database/seed/datadictionary/datadictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func DefaultDataDictionary() (data []*model.DataDictionaryType) {
defaultPaymentTypeDataDictionary(),
defaultPaymentStatusDataDictionary(),
defaultTokenCategoryDataDictionary(),
defaultMGMDataDictionary(),
}

return data
Expand Down
66 changes: 66 additions & 0 deletions cmd/ctl/database/seed/datadictionary/mgm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package datadictionary

import (
"PowerX/internal/model"
"PowerX/internal/model/crm/market"
)

func defaultMGMDataDictionary() *model.DataDictionaryType {
return &model.DataDictionaryType{
Items: []*model.DataDictionaryItem{
&model.DataDictionaryItem{
Key: market.MGMSceneDirectRecruitment,
Type: market.TypeMGMScene,
Name: "直接会员招募",
Value: market.MGMSceneDirectRecruitment,
Sort: 0,
},
&model.DataDictionaryItem{
Key: market.MGMSceneIndirectRecruitment,
Type: market.TypeMGMScene,
Name: "间接会员招募",
Value: market.MGMSceneIndirectRecruitment,
Sort: 0,
},
&model.DataDictionaryItem{
Key: market.MGMSceneTeamPerformanceReward,
Type: market.TypeMGMScene,
Name: "团队业绩奖励(仅限两层)",
Value: market.MGMSceneTeamPerformanceReward,
Sort: 0,
},
&model.DataDictionaryItem{
Key: market.MGMSceneLevelUpgradeReward,
Type: market.TypeMGMScene,
Name: "级别升级奖励",
Value: market.MGMSceneLevelUpgradeReward,
Sort: 0,
},
&model.DataDictionaryItem{
Key: market.MGMSceneMonthlyRecruitmentCompetition,
Type: market.TypeMGMScene,
Name: "月度拉新竞赛(仅限两层)",
Value: market.MGMSceneMonthlyRecruitmentCompetition,
Sort: 0,
},
&model.DataDictionaryItem{
Key: market.MGMSceneProductPromotionReward,
Type: market.TypeMGMScene,
Name: "推广特定产品奖励",
Value: market.MGMSceneProductPromotionReward,
Sort: 0,
},
&model.DataDictionaryItem{
Key: market.MGMSceneVIPMemberReward,
Type: market.TypeMGMScene,
Name: "VIP会员奖励",
Value: market.MGMSceneVIPMemberReward,
Sort: 0,
},
},
Type: market.TypeMGMScene,
Name: "MGM场景类型",
Description: "各种MGM 客户转介绍的类型",
}

}
97 changes: 97 additions & 0 deletions cmd/ctl/database/seed/mgm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package seed

import (
"PowerX/internal/model/crm/market"
"PowerX/internal/uc/powerx"
"context"
"github.com/pkg/errors"
"gorm.io/gorm"
)

func CreateMGMRules(db *gorm.DB) (err error) {

var count int64
if err = db.Model(&market.MGMRule{}).Count(&count).Error; err != nil {
panic(errors.Wrap(err, "init mgm rules failed"))
}

data := DefaultMGMRules(db)
if count == 0 {
if err = db.Model(&market.MGMRule{}).Create(data).Error; err != nil {
panic(errors.Wrap(err, "init mgm rules failed"))
}
}

return err
}

func DefaultMGMRules(db *gorm.DB) []*market.MGMRule {

ucDD := powerx.NewDataDictionaryUseCase(db)
arrayRules := []*market.MGMRule{}
item, _ := ucDD.GetDataDictionaryItem(context.Background(), market.TypeMGMScene, market.MGMSceneDirectRecruitment)
rule := &market.MGMRule{
CommissionRate1: 0.05,
CommissionRate2: 0,
Scene: int(item.Id),
Description: "描述:会员A成功招募了新会员B,新会员B在系统内进行了消费。\n\n分佣率:A获得B的总消费额的一定比例,例如5%。",
}
arrayRules = append(arrayRules, rule)

item, _ = ucDD.GetDataDictionaryItem(context.Background(), market.TypeMGMScene, market.MGMSceneIndirectRecruitment)
rule = &market.MGMRule{
CommissionRate1: 0.05,
CommissionRate2: 0.3,
Scene: int(item.Id),
Description: "描述:会员A招募了新会员B,新会员B成功招募了C。C在系统内进行了消费。\n\n分佣率:A获得C的总消费额的一定比例,例如3%。",
}
arrayRules = append(arrayRules, rule)

item, _ = ucDD.GetDataDictionaryItem(context.Background(), market.TypeMGMScene, market.MGMSceneTeamPerformanceReward)
rule = &market.MGMRule{
CommissionRate1: 0.02,
CommissionRate2: 0,
Scene: int(item.Id),
Description: "描述:会员A成功招募了多个会员,并带领团队一起推广,团队的总业绩达到一定水平。\n\n分佣率:A获得团队总业绩的一定比例,例如2%。",
}
arrayRules = append(arrayRules, rule)

item, _ = ucDD.GetDataDictionaryItem(context.Background(), market.TypeMGMScene, market.MGMSceneLevelUpgradeReward)
rule = &market.MGMRule{
CommissionRate1: 0.05,
CommissionRate2: 0,
Scene: int(item.Id),
Description: "描述:会员A的团队中达到一定数量的下级会员,A升级成高级会员。\n\n分佣率:A获得自己及其下级会员的总业绩的一定比例,例如5%。",
}
arrayRules = append(arrayRules, rule)

item, _ = ucDD.GetDataDictionaryItem(context.Background(), market.TypeMGMScene, market.MGMSceneMonthlyRecruitmentCompetition)
rule = &market.MGMRule{
CommissionRate1: 0.05,
CommissionRate2: 0,
Scene: int(item.Id),
Description: "描述:每个月内,会员A成功拉新的会员数量排名前三的获得额外奖励。\n\n分佣率:第一名获得总消费额的5%,第二名获得总消费额的3%,第三名获得总消费额的2%。\n\n",
}
arrayRules = append(arrayRules, rule)

item, _ = ucDD.GetDataDictionaryItem(context.Background(), market.TypeMGMScene, market.MGMSceneProductPromotionReward)
rule = &market.MGMRule{
CommissionRate1: 0.1,
CommissionRate2: 0,
Scene: int(item.Id),
Description: "描述:会员A成功推广了某个特定产品,被推广的产品有额外奖励计划。\n\n分佣率:A获得特定产品销售额的一定比例,例如10%。",
}
arrayRules = append(arrayRules, rule)

item, _ = ucDD.GetDataDictionaryItem(context.Background(), market.TypeMGMScene, market.MGMSceneVIPMemberReward)
rule = &market.MGMRule{
CommissionRate1: 0.15,
CommissionRate2: 0,
Scene: int(item.Id),
Description: "描述:成功招募并维持了高额消费的VIP会员获得额外奖励。\n\n分佣率:VIP会员的消费额度的一定比例,例如15%。",
}
arrayRules = append(arrayRules, rule)

return arrayRules

}
2 changes: 1 addition & 1 deletion cmd/ctl/database/seed/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package seed
import (
"PowerX/internal/model/crm/trade"
"PowerX/internal/uc/powerx"
trade2 "PowerX/internal/uc/powerx/trade"
trade2 "PowerX/internal/uc/powerx/crm/trade"
"context"
"fmt"
"github.com/pkg/errors"
Expand Down
4 changes: 4 additions & 0 deletions cmd/ctl/database/seed/powerx.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ func (s *PowerSeeder) CreatePowerX() (err error) {
_ = CreatePayments(s.db)
}

// Product
_ = CreateTokenProducts(s.db)
_ = CreatePriceBooks(s.db)
_ = CreateTokenExchangeRatios(s.db)

// Marketing
_ = CreateMGMRules(s.db)

// custom
seed.CreateCustomSeeds(s.db)

Expand Down
2 changes: 1 addition & 1 deletion cmd/ctl/database/seed/pricebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"PowerX/internal/model/crm/product"
"PowerX/internal/types"
"PowerX/internal/uc/powerx"
product2 "PowerX/internal/uc/powerx/product"
product2 "PowerX/internal/uc/powerx/crm/product"
"context"
"github.com/pkg/errors"
"gorm.io/gorm"
Expand Down
2 changes: 1 addition & 1 deletion cmd/ctl/database/seed/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"PowerX/internal/model/crm/product"
"PowerX/internal/model/media"
"PowerX/internal/uc/powerx"
product2 "PowerX/internal/uc/powerx/product"
product2 "PowerX/internal/uc/powerx/crm/product"
"PowerX/pkg/mathx"
"context"
"fmt"
Expand Down
8 changes: 4 additions & 4 deletions cmd/ctl/database/seed/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ import (
func CreateTokenExchangeRatios(db *gorm.DB) (err error) {

var count int64
if err = db.Model(&trade.ExchangeRatio{}).Count(&count).Error; err != nil {
if err = db.Model(&trade.TokenExchangeRatio{}).Count(&count).Error; err != nil {
panic(errors.Wrap(err, "init exchange rate failed"))
}

data := DefaultExchangeRecord(db)
if count == 0 {
if err = db.Model(&trade.ExchangeRatio{}).Create(data).Error; err != nil {
if err = db.Model(&trade.TokenExchangeRatio{}).Create(data).Error; err != nil {
panic(errors.Wrap(err, "init price book failed"))
}
}

return err
}

func DefaultExchangeRecord(db *gorm.DB) []*trade.ExchangeRatio {
func DefaultExchangeRecord(db *gorm.DB) []*trade.TokenExchangeRatio {

ucDD := powerx.NewDataDictionaryUseCase(db)
categoryId := ucDD.GetCachedDD(context.Background(), trade.TypeTokenCategory, trade.TokenCategoryPurchase).Id

return []*trade.ExchangeRatio{
return []*trade.TokenExchangeRatio{
{
FromCategory: int(categoryId),
Ratio: 1,
Expand Down
1 change: 1 addition & 0 deletions internal/model/crm/customerdomain/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Customer struct {
Password string `gorm:"comment:客户密码" json:"password"`
Email string `gorm:"comment:邮箱地址" json:"email"`
InviterId int64 `gorm:"comment:邀请方" json:"inviterId"`
MgmId int `gorm:"comment:MGM Id" json:"mgmId"`
Source int `gorm:"comment:注册来源" json:"source"`
Type int `gorm:"comment:类型:个人,企业" json:"type"`
IsActivated bool `gorm:"comment:激活状态" json:"isActivated"`
Expand Down
Loading

0 comments on commit 87883f2

Please sign in to comment.