-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mgm): add mgm rules with migrate and seed
- Loading branch information
Showing
14 changed files
with
352 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 客户转介绍的类型", | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.