Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(crm): admin product list with search options #274

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion api/admin/crm/product/product.api
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,13 @@ type (
type (
ListProductsPageRequest struct {
LikeName string `form:"likeName,optional"`
ProductTypeIds []int `form:"productTypeIds,optional"`
ProductTypeIds []int `form:"typeIds,optional"`
ProductStatusIds []int `form:"productStatusIds,optional"`
SalesStartAt string `form:"salesStartAt,optional,omitempty"`
SalesEndAt string `form:"salesEndAt,optional,omitempty"`
Keys []string `form:"keys,optional"`
ProductCategoryId int `form:"productCategoryId,optional"`
ProductCategoryIds []int `form:"productCategoryIds,optional"`
OrderBy string `form:"orderBy,optional"`
PageIndex int `form:"pageIndex,optional"`
PageSize int `form:"pageSize,optional"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (l *PutCustomerLogic) PutCustomer(req *types.PutCustomerRequest) (resp *typ
// 如果当前数据库的用户已经有了UUID
if cCustomer.Uuid == "" {
mdlCustomer.Uuid = securityx.GenerateUUID()
mdlCustomer.InviteCode = securityx.GenerateInviteCode(mdlCustomer.Uuid)
}

// 更新产品对象
Expand Down
18 changes: 16 additions & 2 deletions internal/logic/admin/crm/product/listproductspagelogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"PowerX/internal/svc"
"PowerX/internal/types"
productUC "PowerX/internal/uc/powerx/crm/product"
"PowerX/pkg/datetime/carbonx"
"context"
"github.com/golang-module/carbon/v2"

"github.com/zeromicro/go-zero/core/logx"
)
Expand All @@ -26,12 +28,24 @@ func NewListProductsPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *

func (l *ListProductsLogic) ListProductsPage(req *types.ListProductsPageRequest) (resp *types.ListProductsPageReply, err error) {

startAt := carbon.ParseByFormat(req.SalesStartAt, carbonx.DateFormat)
endAt := carbon.ParseByFormat(req.SalesEndAt, carbonx.DateFormat)
if !startAt.IsZero() && endAt.IsZero() {
endAt = startAt.AddDays(30)
} else if startAt.IsZero() && !endAt.IsZero() {
startAt = endAt.AddDays(-30)
}

// 去掉代币的产品
notInTypeId := l.svcCtx.PowerX.DataDictionary.GetCachedDDId(l.ctx, product.TypeProductType, product.ProductTypeToken)

page, err := l.svcCtx.PowerX.Product.FindManyProducts(l.ctx, &productUC.FindManyProductsOption{
LikeName: req.LikeName,
NotInTypes: []int{notInTypeId},
StartAt: startAt.ToStdTime(),
EndAt: endAt.ToStdTime(),
LikeName: req.LikeName,
NotInTypes: []int{notInTypeId},
Types: req.ProductTypeIds,
CategoryIds: req.ProductCategoryIds,
PageEmbedOption: types.PageEmbedOption{
PageIndex: req.PageIndex,
PageSize: req.PageSize,
Expand Down
19 changes: 11 additions & 8 deletions internal/types/types.go

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

25 changes: 20 additions & 5 deletions internal/uc/powerx/crm/product/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"PowerX/internal/model/powermodel"
"PowerX/internal/types"
"PowerX/internal/types/errorx"
"PowerX/pkg/datetime/carbonx"
"PowerX/pkg/slicex"
"context"
"encoding/json"
"github.com/pkg/errors"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"strings"
"time"
)

type ProductUseCase struct {
Expand All @@ -34,8 +36,11 @@ type FindManyProductsOption struct {
Ids []int64
NeedActivated bool
CategoryId int
CategoryIds []int
LikeName string
OrderBy string
StartAt time.Time
EndAt time.Time
types.PageEmbedOption
}

Expand All @@ -47,9 +52,7 @@ func (uc *ProductUseCase) buildFindQueryNoPage(db *gorm.DB, opt *FindManyProduct

if len(opt.Types) > 0 {
db = db.Where("type IN ?", opt.Types)
}

if len(opt.NotInTypes) > 0 {
} else if len(opt.NotInTypes) > 0 {
db = db.Where("type NOT IN ?", opt.NotInTypes)
}

Expand All @@ -61,15 +64,27 @@ func (uc *ProductUseCase) buildFindQueryNoPage(db *gorm.DB, opt *FindManyProduct
db = db.Where("plan IN ?", opt.Plans)
}

if !opt.StartAt.IsZero() && !opt.EndAt.IsZero() {
opt.EndAt = opt.EndAt.Add(time.Hour*24 - time.Second)
db = db.
Where("sale_start_date >= ? ", opt.StartAt.Format(carbonx.GoDatetimeFormat)).
Where("sale_end_date <= ? ", opt.EndAt.Format(carbonx.GoDatetimeFormat))
}

if opt.NeedActivated {
db = db.Where("is_activated = ?", true)
}

if opt.CategoryId > 0 {
// 先考虑单个品类检索,在考虑多个品类检索
if opt.CategoryId > 0 || len(opt.CategoryIds) > 0 {
categoryIds := opt.CategoryIds
if opt.CategoryId > 0 {
categoryIds = []int{opt.CategoryId}
}
db = db.
Joins("LEFT JOIN pivot_product_to_product_category ON pivot_product_to_product_category.product_id = products.id").
Joins("LEFT JOIN product_categories ON product_categories.id = pivot_product_to_product_category.product_category_id").
Where("product_categories.id = ?", opt.CategoryId).
Where("product_categories.id IN ?", categoryIds).
Where("pivot_product_to_product_category.deleted_at IS NULL")
}

Expand Down
Loading