From c63d5460f4e5111818ef3e9b17a3f3f088045f43 Mon Sep 17 00:00:00 2001 From: Matrix-X Date: Wed, 11 Oct 2023 22:16:21 +0800 Subject: [PATCH] update(readme): add related recommendation --- README.md | 4 ++ api/admin/crm/product/product.api | 12 ++++++ .../crm/product/disableproducthandler.go | 28 ++++++++++++++ internal/handler/routes.go | 5 +++ .../admin/crm/product/disableproductlogic.go | 38 +++++++++++++++++++ internal/types/types.go | 8 ++++ internal/uc/powerx/crm/product/product.go | 7 +++- 7 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 internal/handler/admin/crm/product/disableproducthandler.go create mode 100644 internal/logic/admin/crm/product/disableproductlogic.go diff --git a/README.md b/README.md index 1553c759..269d6dc2 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,11 @@ https://powerx.artisan-cloud.com/zh/v1/case/ 暂时用于2C的一些定制开发的场景,需要用到Web UI + +## 相关产品推荐 +[PowerWechat 微信的Golang SDK](https://github.com/ArtisanCloud/PowerWeChat) +[WeyUI 一套微信生态前端组件库,适配PowerX非常友好](https://github.com/yaoyaochil/WeyUI) ## PowerX社区交流群 diff --git a/api/admin/crm/product/product.api b/api/admin/crm/product/product.api index f645a573..e0667813 100644 --- a/api/admin/crm/product/product.api +++ b/api/admin/crm/product/product.api @@ -43,6 +43,9 @@ service PowerX { @handler PatchProduct patch /products/:id (PatchProductRequest) returns (PatchProductReply) + @doc "下架产品" + @handler DisableProduct + put /products/disable/:id (DisableProductRequest)returns (DisableProductReply) @doc "删除产品" @handler DeleteProduct @@ -186,6 +189,15 @@ type ( type ( + + DisableProductRequest struct { + ProductId int64 `path:"id"` + } + + DisableProductReply struct{ + ProductId int64 `json:"id"` + } + DeleteProductRequest struct { ProductId int64 `path:"id"` } diff --git a/internal/handler/admin/crm/product/disableproducthandler.go b/internal/handler/admin/crm/product/disableproducthandler.go new file mode 100644 index 00000000..81a39da7 --- /dev/null +++ b/internal/handler/admin/crm/product/disableproducthandler.go @@ -0,0 +1,28 @@ +package product + +import ( + "net/http" + + "PowerX/internal/logic/admin/crm/product" + "PowerX/internal/svc" + "PowerX/internal/types" + "github.com/zeromicro/go-zero/rest/httpx" +) + +func DisableProductHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.DisableProductRequest + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := product.NewDisableProductLogic(r.Context(), svcCtx) + resp, err := l.DisableProduct(&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 e91d7e31..a667f175 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -742,6 +742,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/products/:id", Handler: admincrmproduct.PatchProductHandler(serverCtx), }, + { + Method: http.MethodPut, + Path: "/products/disable/:id", + Handler: admincrmproduct.DisableProductHandler(serverCtx), + }, { Method: http.MethodDelete, Path: "/products/:id", diff --git a/internal/logic/admin/crm/product/disableproductlogic.go b/internal/logic/admin/crm/product/disableproductlogic.go new file mode 100644 index 00000000..9a3f6f47 --- /dev/null +++ b/internal/logic/admin/crm/product/disableproductlogic.go @@ -0,0 +1,38 @@ +package product + +import ( + product2 "PowerX/internal/model/crm/product" + fmt "PowerX/pkg/printx" + "context" + + "PowerX/internal/svc" + "PowerX/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type DisableProductLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewDisableProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DisableProductLogic { + return &DisableProductLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *DisableProductLogic) DisableProduct(req *types.DisableProductRequest) (resp *types.DisableProductReply, err error) { + p := &product2.Product{ + IsActivated: false, + } + fmt.Dump(p) + l.svcCtx.PowerX.Product.PatchProduct(l.ctx, req.ProductId, p) + + return &types.DisableProductReply{ + ProductId: req.ProductId, + }, nil +} diff --git a/internal/types/types.go b/internal/types/types.go index 3c49ef9e..5e3313c4 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1419,6 +1419,14 @@ type PatchProductReply struct { *Product } +type DisableProductRequest struct { + ProductId int64 `path:"id"` +} + +type DisableProductReply struct { + ProductId int64 `json:"id"` +} + type DeleteProductRequest struct { ProductId int64 `path:"id"` } diff --git a/internal/uc/powerx/crm/product/product.go b/internal/uc/powerx/crm/product/product.go index dbdfd0c1..52834e75 100644 --- a/internal/uc/powerx/crm/product/product.go +++ b/internal/uc/powerx/crm/product/product.go @@ -7,6 +7,7 @@ import ( "PowerX/internal/model/powermodel" "PowerX/internal/types" "PowerX/internal/types/errorx" + fmt "PowerX/pkg/printx" "PowerX/pkg/slicex" "context" "encoding/json" @@ -185,8 +186,12 @@ func (uc *ProductUseCase) UpsertProducts(ctx context.Context, products []*model. } func (uc *ProductUseCase) PatchProduct(ctx context.Context, id int64, product *model.Product) { + fmt.Dump(product) if err := uc.db.WithContext(ctx).Model(&model.Product{}). - Where(id).Updates(&product).Error; err != nil { + Where(id). + Debug(). + Updates(product). + Error; err != nil { panic(err) } }