Skip to content

Commit

Permalink
Merge pull request #260 from ArtisanCloud/dev/michaelhu
Browse files Browse the repository at this point in the history
Dev/michaelhu
  • Loading branch information
Matrix-X committed Oct 5, 2023
2 parents b3c8954 + 87883f2 commit adfeda5
Show file tree
Hide file tree
Showing 18 changed files with 375 additions and 21 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 api/admin/wechat/officialaccount/menu.api
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ type (
type (

QueryMenusReply struct {
Menu *OAMenu `json:"menu,optional"`
Button interface{} `json:"button"`
MatchRule interface{} `json:"matchrule"`
}
)

Expand Down
8 changes: 5 additions & 3 deletions cmd/ctl/database/migrate/powerx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"PowerX/internal/model"
"PowerX/internal/model/crm/customerdomain"
"PowerX/internal/model/crm/market"
"PowerX/internal/model/crm/membership"
"PowerX/internal/model/crm/product"
"PowerX/internal/model/crm/trade"
infoorganizatoin "PowerX/internal/model/infoorganization"
"PowerX/internal/model/media"
"PowerX/internal/model/membership"
"PowerX/internal/model/origanzation"
"PowerX/internal/model/permission"
"PowerX/internal/model/scene"
Expand All @@ -19,6 +19,7 @@ import (
"PowerX/internal/model/scrm/organization"
"PowerX/internal/model/scrm/resource"
"PowerX/internal/model/scrm/tag"
"PowerX/internal/model/wechat"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/gorm"
Expand Down Expand Up @@ -58,7 +59,7 @@ func (m *PowerMigrator) AutoMigrate() {

// customer domain
_ = m.db.AutoMigrate(&customerdomain.Lead{}, &customerdomain.Contact{}, &customerdomain.Customer{}, &membership.Membership{})
_ = m.db.AutoMigrate(&model.WechatOACustomer{}, &model.WechatMPCustomer{}, &model.WeWorkExternalContact{})
_ = m.db.AutoMigrate(&wechat.WechatOACustomer{}, &wechat.WechatMPCustomer{}, &wechat.WeWorkExternalContact{})
_ = m.db.AutoMigrate(
&product.PivotProductToProductCategory{},
)
Expand All @@ -71,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 @@ -82,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
Loading

0 comments on commit adfeda5

Please sign in to comment.