Skip to content

Commit

Permalink
Merge pull request #266 from ArtisanCloud/dev/michaelhu
Browse files Browse the repository at this point in the history
update(readme): add related recommendation
  • Loading branch information
Matrix-X committed Oct 11, 2023
2 parents 2e05f6c + c63d546 commit 9b85ace
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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社区交流群

Expand Down
12 changes: 12 additions & 0 deletions api/admin/crm/product/product.api
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -186,6 +189,15 @@ type (


type (

DisableProductRequest struct {
ProductId int64 `path:"id"`
}

DisableProductReply struct{
ProductId int64 `json:"id"`
}

DeleteProductRequest struct {
ProductId int64 `path:"id"`
}
Expand Down
28 changes: 28 additions & 0 deletions internal/handler/admin/crm/product/disableproducthandler.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
5 changes: 5 additions & 0 deletions internal/handler/routes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions internal/logic/admin/crm/product/disableproductlogic.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions internal/types/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion internal/uc/powerx/crm/product/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 9b85ace

Please sign in to comment.