From a13205ca224f8fb505480c237e707e24274d994e Mon Sep 17 00:00:00 2001 From: Matrix-X Date: Thu, 5 Oct 2023 23:21:52 +0800 Subject: [PATCH] feat(mgm): api create rule --- api/admin.crm.api | 1 + api/admin/crm/market/mgm.api | 94 +++++----- .../admin/crm/market/mgm/createmgmhandler.go | 28 +++ .../crm/market/mgm/createmgmrulehandler.go | 28 +++ .../admin/crm/market/mgm/deletemgmhandler.go | 28 +++ .../crm/market/mgm/deletemgmrulehandler.go | 28 +++ .../admin/crm/market/mgm/getmgmhandler.go | 28 +++ .../admin/crm/market/mgm/getmgmrulehandler.go | 28 +++ .../crm/market/mgm/listmgmrulespagehandler.go | 28 +++ .../crm/market/mgm/listmgmspagehandler.go | 28 +++ .../admin/crm/market/mgm/updatemgmhandler.go | 28 +++ .../crm/market/mgm/updatemgmrulehandler.go | 28 +++ internal/handler/routes.go | 35 ++++ .../crm/market/mgm/createmgmrulelogic.go | 47 +++++ .../crm/market/mgm/deletemgmrulelogic.go | 30 ++++ .../admin/crm/market/mgm/getmgmrulelogic.go | 30 ++++ .../crm/market/mgm/listmgmrulespagelogic.go | 30 ++++ .../crm/market/mgm/updatemgmrulelogic.go | 30 ++++ internal/model/crm/market/mgm.go | 2 + internal/types/types.go | 56 ++++++ internal/uc/powerx.go | 2 + internal/uc/powerx/crm/market/mgm.go | 166 ++++++++++++++++++ 22 files changed, 755 insertions(+), 48 deletions(-) create mode 100644 internal/handler/admin/crm/market/mgm/createmgmhandler.go create mode 100644 internal/handler/admin/crm/market/mgm/createmgmrulehandler.go create mode 100644 internal/handler/admin/crm/market/mgm/deletemgmhandler.go create mode 100644 internal/handler/admin/crm/market/mgm/deletemgmrulehandler.go create mode 100644 internal/handler/admin/crm/market/mgm/getmgmhandler.go create mode 100644 internal/handler/admin/crm/market/mgm/getmgmrulehandler.go create mode 100644 internal/handler/admin/crm/market/mgm/listmgmrulespagehandler.go create mode 100644 internal/handler/admin/crm/market/mgm/listmgmspagehandler.go create mode 100644 internal/handler/admin/crm/market/mgm/updatemgmhandler.go create mode 100644 internal/handler/admin/crm/market/mgm/updatemgmrulehandler.go create mode 100644 internal/logic/admin/crm/market/mgm/createmgmrulelogic.go create mode 100644 internal/logic/admin/crm/market/mgm/deletemgmrulelogic.go create mode 100644 internal/logic/admin/crm/market/mgm/getmgmrulelogic.go create mode 100644 internal/logic/admin/crm/market/mgm/listmgmrulespagelogic.go create mode 100644 internal/logic/admin/crm/market/mgm/updatemgmrulelogic.go create mode 100644 internal/uc/powerx/crm/market/mgm.go diff --git a/api/admin.crm.api b/api/admin.crm.api index c72e2633..65aae374 100644 --- a/api/admin.crm.api +++ b/api/admin.crm.api @@ -2,6 +2,7 @@ import "admin/crm/customerdomain/lead.api" import "admin/crm/customerdomain/customer.api" import "admin/crm/market/media.api" import "admin/crm/market/store.api" +import "admin/crm/market/mgm.api" import "admin/crm/business/opportunity.api" import "admin/crm/product/pricebook.api" import "admin/crm/product/product.api" diff --git a/api/admin/crm/market/mgm.api b/api/admin/crm/market/mgm.api index c8a24e82..3e97a3dc 100644 --- a/api/admin/crm/market/mgm.api +++ b/api/admin/crm/market/mgm.api @@ -1,8 +1,8 @@ syntax = "v1" info( - title: "MGM管理" - desc: "MGM管理" + title: "MGMRule管理" + desc: "MGMRule管理" author: "MichaelHu" email: "matrix-x@artisan-cloud.com" version: "v1" @@ -15,49 +15,47 @@ info( ) 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) + @doc "查询MGMRule列表" + @handler ListMGMRulesPage + get /mgms/page-list (ListMGMRulesPageRequest) returns (ListMGMRulesPageReply) + @doc "请求MGMRule上传链接" + @handler CreateMGMRule + post /mgms (CreateMGMRuleRequest) returns (CreateMGMRuleReply) + + @doc "创建或更新MGMRule" + @handler UpdateMGMRule + put /mgms/:id (UpdateMGMRuleRequest) returns (UpdateMGMRuleReply) + + @doc "根据获取MGMRule" + @handler GetMGMRule + get /mgms/:id (GetMGMRuleRequest) returns (GetMGMRuleReply) + + @doc "删除MGMRule" + @handler DeleteMGMRule + delete /mgms/:id (DeleteMGMRuleRequest) returns (DeleteMGMRuleReply) } type ( - ListMGMsPageRequest struct { - MGMTypes []int8 `form:"mgmTypes,optional"` + ListMGMRulesPageRequest struct { + MGMRuleTypes []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 { + MGMRule 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"` + CommissionRate1 float32 `json:"commissionRate1,optional"` + CommissionRate2 float32 `json:"commissionRate2,optional"` + Scene int `json:"scene,optional"` Description string `json:"description,optional"` - MGMType int `json:"mgmType,optional"` - ViewedCount int `json:"viewedCount,optional"` + } - ListMGMsPageReply struct { - List []*MGM `json:"list"` + ListMGMRulesPageReply struct { + List []*MGMRule `json:"list"` PageIndex int `json:"pageIndex"` PageSize int `json:"pageSize"` Total int64 `json:"total"` @@ -65,42 +63,42 @@ type ( ) type ( - CreateMGMRequest struct { - MGM + CreateMGMRuleRequest struct { + MGMRule } - CreateMGMReply struct { - MGMId int64 `json:"id"` + CreateMGMRuleReply struct { + MGMRuleId int64 `json:"id"` } ) type ( - UpdateMGMRequest struct { - MGMId int64 `path:"id"` - MGM + UpdateMGMRuleRequest struct { + MGMRuleId int64 `path:"id"` + MGMRule } - UpdateMGMReply struct { - MGMId int64 `json:"id"` + UpdateMGMRuleReply struct { + MGMRuleId int64 `json:"id"` } ) type ( - GetMGMRequest struct { - MGMId int64 `path:"id"` + GetMGMRuleRequest struct { + MGMRuleId int64 `path:"id"` } - GetMGMReply struct { - *MGM + GetMGMRuleReply struct { + *MGMRule } ) type ( - DeleteMGMRequest struct { - MGMId int64 `path:"id"` + DeleteMGMRuleRequest struct { + MGMRuleId int64 `path:"id"` } - DeleteMGMReply struct { - MGMId int64 `json:"id"` + DeleteMGMRuleReply struct { + MGMRuleId int64 `json:"id"` } ) diff --git a/internal/handler/admin/crm/market/mgm/createmgmhandler.go b/internal/handler/admin/crm/market/mgm/createmgmhandler.go new file mode 100644 index 00000000..c6b34a62 --- /dev/null +++ b/internal/handler/admin/crm/market/mgm/createmgmhandler.go @@ -0,0 +1,28 @@ +package mgm + +import ( + "net/http" + + "PowerX/internal/logic/admin/crm/market/mgm" + "PowerX/internal/svc" + "PowerX/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func CreateMGMHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.CreateMGMRuleRequest + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := mgm.NewCreateMGMRuleLogic(r.Context(), svcCtx) + resp, err := l.CreateMGMRule(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/admin/crm/market/mgm/createmgmrulehandler.go b/internal/handler/admin/crm/market/mgm/createmgmrulehandler.go new file mode 100644 index 00000000..32adcc0c --- /dev/null +++ b/internal/handler/admin/crm/market/mgm/createmgmrulehandler.go @@ -0,0 +1,28 @@ +package mgm + +import ( + "net/http" + + "PowerX/internal/logic/admin/crm/market/mgm" + "PowerX/internal/svc" + "PowerX/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func CreateMGMRuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.CreateMGMRuleRequest + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := mgm.NewCreateMGMRuleLogic(r.Context(), svcCtx) + resp, err := l.CreateMGMRule(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/admin/crm/market/mgm/deletemgmhandler.go b/internal/handler/admin/crm/market/mgm/deletemgmhandler.go new file mode 100644 index 00000000..c8263ce6 --- /dev/null +++ b/internal/handler/admin/crm/market/mgm/deletemgmhandler.go @@ -0,0 +1,28 @@ +package mgm + +import ( + "net/http" + + "PowerX/internal/logic/admin/crm/market/mgm" + "PowerX/internal/svc" + "PowerX/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func DeleteMGMHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.DeleteMGMRuleRequest + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := mgm.NewDeleteMGMRuleLogic(r.Context(), svcCtx) + resp, err := l.DeleteMGMRule(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/admin/crm/market/mgm/deletemgmrulehandler.go b/internal/handler/admin/crm/market/mgm/deletemgmrulehandler.go new file mode 100644 index 00000000..57280b23 --- /dev/null +++ b/internal/handler/admin/crm/market/mgm/deletemgmrulehandler.go @@ -0,0 +1,28 @@ +package mgm + +import ( + "net/http" + + "PowerX/internal/logic/admin/crm/market/mgm" + "PowerX/internal/svc" + "PowerX/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func DeleteMGMRuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.DeleteMGMRuleRequest + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := mgm.NewDeleteMGMRuleLogic(r.Context(), svcCtx) + resp, err := l.DeleteMGMRule(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/admin/crm/market/mgm/getmgmhandler.go b/internal/handler/admin/crm/market/mgm/getmgmhandler.go new file mode 100644 index 00000000..fde3d460 --- /dev/null +++ b/internal/handler/admin/crm/market/mgm/getmgmhandler.go @@ -0,0 +1,28 @@ +package mgm + +import ( + "net/http" + + "PowerX/internal/logic/admin/crm/market/mgm" + "PowerX/internal/svc" + "PowerX/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func GetMGMHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.GetMGMRuleRequest + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := mgm.NewGetMGMRuleLogic(r.Context(), svcCtx) + resp, err := l.GetMGMRule(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/admin/crm/market/mgm/getmgmrulehandler.go b/internal/handler/admin/crm/market/mgm/getmgmrulehandler.go new file mode 100644 index 00000000..701756d2 --- /dev/null +++ b/internal/handler/admin/crm/market/mgm/getmgmrulehandler.go @@ -0,0 +1,28 @@ +package mgm + +import ( + "net/http" + + "PowerX/internal/logic/admin/crm/market/mgm" + "PowerX/internal/svc" + "PowerX/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func GetMGMRuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.GetMGMRuleRequest + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := mgm.NewGetMGMRuleLogic(r.Context(), svcCtx) + resp, err := l.GetMGMRule(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/admin/crm/market/mgm/listmgmrulespagehandler.go b/internal/handler/admin/crm/market/mgm/listmgmrulespagehandler.go new file mode 100644 index 00000000..7acf1411 --- /dev/null +++ b/internal/handler/admin/crm/market/mgm/listmgmrulespagehandler.go @@ -0,0 +1,28 @@ +package mgm + +import ( + "net/http" + + "PowerX/internal/logic/admin/crm/market/mgm" + "PowerX/internal/svc" + "PowerX/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func ListMGMRulesPageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.ListMGMRulesPageRequest + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := mgm.NewListMGMRulesPageLogic(r.Context(), svcCtx) + resp, err := l.ListMGMRulesPage(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/admin/crm/market/mgm/listmgmspagehandler.go b/internal/handler/admin/crm/market/mgm/listmgmspagehandler.go new file mode 100644 index 00000000..81b99526 --- /dev/null +++ b/internal/handler/admin/crm/market/mgm/listmgmspagehandler.go @@ -0,0 +1,28 @@ +package mgm + +import ( + "net/http" + + "PowerX/internal/logic/admin/crm/market/mgm" + "PowerX/internal/svc" + "PowerX/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func ListMGMsPageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.ListMGMRulesPageRequest + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := mgm.NewListMGMRulesPageLogic(r.Context(), svcCtx) + resp, err := l.ListMGMRulesPage(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/admin/crm/market/mgm/updatemgmhandler.go b/internal/handler/admin/crm/market/mgm/updatemgmhandler.go new file mode 100644 index 00000000..3ec7d064 --- /dev/null +++ b/internal/handler/admin/crm/market/mgm/updatemgmhandler.go @@ -0,0 +1,28 @@ +package mgm + +import ( + "net/http" + + "PowerX/internal/logic/admin/crm/market/mgm" + "PowerX/internal/svc" + "PowerX/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func UpdateMGMHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.UpdateMGMRuleRequest + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := mgm.NewUpdateMGMRuleLogic(r.Context(), svcCtx) + resp, err := l.UpdateMGMRule(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/admin/crm/market/mgm/updatemgmrulehandler.go b/internal/handler/admin/crm/market/mgm/updatemgmrulehandler.go new file mode 100644 index 00000000..72caacef --- /dev/null +++ b/internal/handler/admin/crm/market/mgm/updatemgmrulehandler.go @@ -0,0 +1,28 @@ +package mgm + +import ( + "net/http" + + "PowerX/internal/logic/admin/crm/market/mgm" + "PowerX/internal/svc" + "PowerX/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func UpdateMGMRuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.UpdateMGMRuleRequest + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := mgm.NewUpdateMGMRuleLogic(r.Context(), svcCtx) + resp, err := l.UpdateMGMRule(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/internal/handler/routes.go b/internal/handler/routes.go index 35b4b76e..48c1c718 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -10,6 +10,7 @@ import ( admincrmcustomerdomaincustomer "PowerX/internal/handler/admin/crm/customerdomain/customer" admincrmcustomerdomainleader "PowerX/internal/handler/admin/crm/customerdomain/leader" admincrmmarketmedia "PowerX/internal/handler/admin/crm/market/media" + admincrmmarketmgm "PowerX/internal/handler/admin/crm/market/mgm" admincrmmarketstore "PowerX/internal/handler/admin/crm/market/store" admincrmproduct "PowerX/internal/handler/admin/crm/product" admincrmproductartisan "PowerX/internal/handler/admin/crm/product/artisan" @@ -613,6 +614,40 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { rest.WithPrefix("/api/v1/admin/market"), ) + server.AddRoutes( + rest.WithMiddlewares( + []rest.Middleware{serverCtx.EmployeeJWTAuth}, + []rest.Route{ + { + Method: http.MethodGet, + Path: "/mgms/page-list", + Handler: admincrmmarketmgm.ListMGMRulesPageHandler(serverCtx), + }, + { + Method: http.MethodPost, + Path: "/mgms", + Handler: admincrmmarketmgm.CreateMGMRuleHandler(serverCtx), + }, + { + Method: http.MethodPut, + Path: "/mgms/:id", + Handler: admincrmmarketmgm.UpdateMGMRuleHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/mgms/:id", + Handler: admincrmmarketmgm.GetMGMRuleHandler(serverCtx), + }, + { + Method: http.MethodDelete, + Path: "/mgms/:id", + Handler: admincrmmarketmgm.DeleteMGMRuleHandler(serverCtx), + }, + }..., + ), + rest.WithPrefix("/api/v1/admin/market"), + ) + server.AddRoutes( rest.WithMiddlewares( []rest.Middleware{serverCtx.EmployeeJWTAuth}, diff --git a/internal/logic/admin/crm/market/mgm/createmgmrulelogic.go b/internal/logic/admin/crm/market/mgm/createmgmrulelogic.go new file mode 100644 index 00000000..b0eeaba0 --- /dev/null +++ b/internal/logic/admin/crm/market/mgm/createmgmrulelogic.go @@ -0,0 +1,47 @@ +package mgm + +import ( + "PowerX/internal/model/crm/market" + "context" + + "PowerX/internal/svc" + "PowerX/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type CreateMGMRuleLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewCreateMGMRuleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateMGMRuleLogic { + return &CreateMGMRuleLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *CreateMGMRuleLogic) CreateMGMRule(req *types.CreateMGMRuleRequest) (resp *types.CreateMGMRuleReply, err error) { + mdlMGMRule := TransformRequestToMGMRule(&req.MGMRule) + + l.svcCtx.PowerX.MGM.CreateMGMRule(l.ctx, mdlMGMRule) + + return &types.CreateMGMRuleReply{ + MGMRuleId: mdlMGMRule.Id, + }, nil + +} + +func TransformRequestToMGMRule(mediaRequest *types.MGMRule) (mdlMGMRule *market.MGMRule) { + + return &market.MGMRule{ + + CommissionRate1: mediaRequest.CommissionRate1, + CommissionRate2: mediaRequest.CommissionRate2, + Scene: mediaRequest.Scene, + Description: mediaRequest.Description, + } +} diff --git a/internal/logic/admin/crm/market/mgm/deletemgmrulelogic.go b/internal/logic/admin/crm/market/mgm/deletemgmrulelogic.go new file mode 100644 index 00000000..0d382386 --- /dev/null +++ b/internal/logic/admin/crm/market/mgm/deletemgmrulelogic.go @@ -0,0 +1,30 @@ +package mgm + +import ( + "context" + + "PowerX/internal/svc" + "PowerX/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type DeleteMGMRuleLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewDeleteMGMRuleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteMGMRuleLogic { + return &DeleteMGMRuleLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DeleteMGMRuleLogic) DeleteMGMRule(req *types.DeleteMGMRuleRequest) (resp *types.DeleteMGMRuleReply, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/internal/logic/admin/crm/market/mgm/getmgmrulelogic.go b/internal/logic/admin/crm/market/mgm/getmgmrulelogic.go new file mode 100644 index 00000000..dd0df718 --- /dev/null +++ b/internal/logic/admin/crm/market/mgm/getmgmrulelogic.go @@ -0,0 +1,30 @@ +package mgm + +import ( + "context" + + "PowerX/internal/svc" + "PowerX/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetMGMRuleLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetMGMRuleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMGMRuleLogic { + return &GetMGMRuleLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetMGMRuleLogic) GetMGMRule(req *types.GetMGMRuleRequest) (resp *types.GetMGMRuleReply, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/internal/logic/admin/crm/market/mgm/listmgmrulespagelogic.go b/internal/logic/admin/crm/market/mgm/listmgmrulespagelogic.go new file mode 100644 index 00000000..e1f0c986 --- /dev/null +++ b/internal/logic/admin/crm/market/mgm/listmgmrulespagelogic.go @@ -0,0 +1,30 @@ +package mgm + +import ( + "context" + + "PowerX/internal/svc" + "PowerX/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ListMGMsPageLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewListMGMRulesPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListMGMsPageLogic { + return &ListMGMsPageLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *ListMGMsPageLogic) ListMGMRulesPage(req *types.ListMGMRulesPageRequest) (resp *types.ListMGMRulesPageReply, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/internal/logic/admin/crm/market/mgm/updatemgmrulelogic.go b/internal/logic/admin/crm/market/mgm/updatemgmrulelogic.go new file mode 100644 index 00000000..99e110f0 --- /dev/null +++ b/internal/logic/admin/crm/market/mgm/updatemgmrulelogic.go @@ -0,0 +1,30 @@ +package mgm + +import ( + "context" + + "PowerX/internal/svc" + "PowerX/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type UpdateMGMRuleLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewUpdateMGMRuleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateMGMRuleLogic { + return &UpdateMGMRuleLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *UpdateMGMRuleLogic) UpdateMGMRule(req *types.UpdateMGMRuleRequest) (resp *types.UpdateMGMRuleReply, err error) { + // todo: add your logic here and delete this line + + return +} diff --git a/internal/model/crm/market/mgm.go b/internal/model/crm/market/mgm.go index e67c8464..76532494 100644 --- a/internal/model/crm/market/mgm.go +++ b/internal/model/crm/market/mgm.go @@ -13,6 +13,8 @@ type MGMRule struct { Description string `gorm:"comment:场景描述" json:"description"` } +const MGMRuleUniqueId = powermodel.UniqueId + const ( TypeMGMScene = "_mgm_scene" diff --git a/internal/types/types.go b/internal/types/types.go index 71736bdb..172978db 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1121,6 +1121,62 @@ type AssignStoreManagerReply struct { Store } +type ListMGMRulesPageRequest struct { + MGMRuleTypes []int8 `form:"mgmTypes,optional"` + Keys []string `form:"keys,optional"` + OrderBy string `form:"orderBy,optional"` + PageIndex int `form:"pageIndex,optional"` + PageSize int `form:"pageSize,optional"` +} + +type MGMRule struct { + Id int64 `json:"id,optional"` + CommissionRate1 float32 `json:"commissionRate1,optional"` + CommissionRate2 float32 `json:"commissionRate2,optional"` + Scene int `json:"scene,optional"` + Description string `json:"description,optional"` +} + +type ListMGMRulesPageReply struct { + List []*MGMRule `json:"list"` + PageIndex int `json:"pageIndex"` + PageSize int `json:"pageSize"` + Total int64 `json:"total"` +} + +type CreateMGMRuleRequest struct { + MGMRule +} + +type CreateMGMRuleReply struct { + MGMRuleId int64 `json:"id"` +} + +type UpdateMGMRuleRequest struct { + MGMRuleId int64 `path:"id"` + MGMRule +} + +type UpdateMGMRuleReply struct { + MGMRuleId int64 `json:"id"` +} + +type GetMGMRuleRequest struct { + MGMRuleId int64 `path:"id"` +} + +type GetMGMRuleReply struct { + *MGMRule +} + +type DeleteMGMRuleRequest struct { + MGMRuleId int64 `path:"id"` +} + +type DeleteMGMRuleReply struct { + MGMRuleId int64 `json:"id"` +} + type GetOpportunityListRequest struct { Name string `form:"name,optional"` Source string `form:"source,optional"` diff --git a/internal/uc/powerx.go b/internal/uc/powerx.go index 71ba279a..d1653cc7 100644 --- a/internal/uc/powerx.go +++ b/internal/uc/powerx.go @@ -40,6 +40,7 @@ type PowerXUseCase struct { PriceBook *productUC.PriceBookUseCase PriceBookEntry *productUC.PriceBookEntryUseCase Store *market.StoreUseCase + MGM *market.MGMRuleUseCase Artisan *productUC.ArtisanUseCase ShippingAddress *tradeUC.ShippingAddressUseCase Cart *tradeUC.CartUseCase @@ -129,6 +130,7 @@ func NewPowerXUseCase(conf *config.Config) (uc *PowerXUseCase, clean func()) { // 加载市场UseCase uc.Media = market.NewMediaUseCase(db) + uc.MGM = market.NewMGMRuleUseCase(db) // 加载Media Resource UseCase uc.MediaResource = powerx.NewMediaResourceUseCase(db, conf) diff --git a/internal/uc/powerx/crm/market/mgm.go b/internal/uc/powerx/crm/market/mgm.go new file mode 100644 index 00000000..62052da6 --- /dev/null +++ b/internal/uc/powerx/crm/market/mgm.go @@ -0,0 +1,166 @@ +package market + +import ( + model "PowerX/internal/model/crm/market" + "PowerX/internal/model/powermodel" + "PowerX/internal/types" + "PowerX/internal/types/errorx" + "context" + "github.com/pkg/errors" + "gorm.io/gorm" +) + +type MGMRuleUseCase struct { + db *gorm.DB +} + +func NewMGMRuleUseCase(db *gorm.DB) *MGMRuleUseCase { + return &MGMRuleUseCase{ + db: db, + } +} + +type FindManyMGMRulesOption struct { + Types []int8 + Ids []int64 + LikeName string + OrderBy string + types.PageEmbedOption +} + +func (uc *MGMRuleUseCase) buildFindQueryNoPage(db *gorm.DB, opt *FindManyMGMRulesOption) *gorm.DB { + if len(opt.Types) > 0 { + db = db.Where("media_type IN ?", opt.Types) + } + + if len(opt.Ids) > 0 { + db = db.Where("id IN ?", opt.Ids) + } + + if opt.LikeName != "" { + db = db.Where("title LIKE ?", "%"+opt.LikeName+"%") + } + orderBy := "id desc" + if opt.OrderBy != "" { + orderBy = opt.OrderBy + "," + orderBy + } + db.Order(orderBy) + return db +} + +func (uc *MGMRuleUseCase) PreloadItems(db *gorm.DB) *gorm.DB { + //db = db. + // Preload("CoverImage") + + return db +} + +func (uc *MGMRuleUseCase) FindManyMGMRules(ctx context.Context, opt *FindManyMGMRulesOption) (pageList types.Page[*model.MGMRule], err error) { + var medias []*model.MGMRule + db := uc.db.WithContext(ctx).Model(&model.MGMRule{}) + + db = uc.buildFindQueryNoPage(db, opt) + + var count int64 + if err := db.Count(&count).Error; err != nil { + panic(err) + } + + opt.DefaultPageIfNotSet() + if opt.PageIndex != 0 && opt.PageSize != 0 { + db.Offset((opt.PageIndex - 1) * opt.PageSize).Limit(opt.PageSize) + } + + db = uc.PreloadItems(db) + if err := db. + //Debug(). + Find(&medias).Error; err != nil { + panic(err) + } + + return types.Page[*model.MGMRule]{ + List: medias, + PageIndex: opt.PageIndex, + PageSize: opt.PageSize, + Total: count, + }, nil +} + +func (uc *MGMRuleUseCase) CreateMGMRule(ctx context.Context, m *model.MGMRule) { + err := uc.db.WithContext(ctx). + //Debug(). + Create(m).Error + + if err != nil { + panic(err) + } +} + +func (uc *MGMRuleUseCase) UpsertMGMRule(ctx context.Context, m *model.MGMRule) (*model.MGMRule, error) { + + medias := []*model.MGMRule{m} + + err := uc.db.Transaction(func(tx *gorm.DB) error { + // 删除媒体的相关联对象 + _, err := uc.ClearAssociations(tx, m) + if err != nil { + return err + } + + // 更新媒体对象主体 + _, err = uc.UpsertMGMRules(ctx, medias) + if err != nil { + return errors.Wrap(err, "upsert media failed") + } + + return err + }) + + return m, err +} + +func (uc *MGMRuleUseCase) UpsertMGMRules(ctx context.Context, medias []*model.MGMRule) ([]*model.MGMRule, error) { + + err := powermodel.UpsertModelsOnUniqueID(uc.db.WithContext(ctx), &model.MGMRule{}, model.MGMRuleUniqueId, medias, nil, false) + + if err != nil { + panic(errors.Wrap(err, "batch upsert medias failed")) + } + + return medias, err +} + +func (uc *MGMRuleUseCase) PatchMGMRule(ctx context.Context, id int64, m *model.MGMRule) { + if err := uc.db.WithContext(ctx).Model(&model.MGMRule{}).Where(id).Updates(m).Error; err != nil { + panic(err) + } +} + +func (uc *MGMRuleUseCase) GetMGMRule(ctx context.Context, id int64) (*model.MGMRule, error) { + var m model.MGMRule + if err := uc.db.WithContext(ctx).First(&m, id).Error; err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, errorx.WithCause(errorx.ErrBadRequest, "未找到媒体") + } + panic(err) + } + return &m, nil +} + +func (uc *MGMRuleUseCase) DeleteMGMRule(ctx context.Context, id int64) error { + result := uc.db.WithContext(ctx).Delete(&model.MGMRule{}, id) + if err := result.Error; err != nil { + panic(err) + } + if result.RowsAffected == 0 { + return errorx.WithCause(errorx.ErrBadRequest, "未找到媒体") + } + return nil +} + +func (uc *MGMRuleUseCase) ClearAssociations(db *gorm.DB, media *model.MGMRule) (*model.MGMRule, error) { + var err error + + return media, err + +}