diff --git a/api/admin/crm/product/product.api b/api/admin/crm/product/product.api index e0667813..983c969d 100644 --- a/api/admin/crm/product/product.api +++ b/api/admin/crm/product/product.api @@ -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"` diff --git a/internal/logic/admin/crm/customerdomain/customer/putcustomerlogic.go b/internal/logic/admin/crm/customerdomain/customer/putcustomerlogic.go index 722fb27c..a735a588 100644 --- a/internal/logic/admin/crm/customerdomain/customer/putcustomerlogic.go +++ b/internal/logic/admin/crm/customerdomain/customer/putcustomerlogic.go @@ -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) } // 更新产品对象 diff --git a/internal/logic/admin/crm/product/listproductspagelogic.go b/internal/logic/admin/crm/product/listproductspagelogic.go index a1436e85..5ea1a851 100644 --- a/internal/logic/admin/crm/product/listproductspagelogic.go +++ b/internal/logic/admin/crm/product/listproductspagelogic.go @@ -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" ) @@ -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, diff --git a/internal/types/types.go b/internal/types/types.go index 6d07217d..54616f76 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1369,14 +1369,17 @@ type Product struct { } type ListProductsPageRequest struct { - LikeName string `form:"likeName,optional"` - ProductTypeIds []int `form:"productTypeIds,optional"` - ProductStatusIds []int `form:"productStatusIds,optional"` - Keys []string `form:"keys,optional"` - ProductCategoryId int `form:"productCategoryId,optional"` - OrderBy string `form:"orderBy,optional"` - PageIndex int `form:"pageIndex,optional"` - PageSize int `form:"pageSize,optional"` + LikeName string `form:"likeName,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"` } type ListProductsPageReply struct { diff --git a/internal/uc/powerx/crm/product/product.go b/internal/uc/powerx/crm/product/product.go index 73966857..89ea9c02 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" + "PowerX/pkg/datetime/carbonx" "PowerX/pkg/slicex" "context" "encoding/json" @@ -14,6 +15,7 @@ import ( "gorm.io/gorm" "gorm.io/gorm/clause" "strings" + "time" ) type ProductUseCase struct { @@ -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 } @@ -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) } @@ -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") }