refactor(catalog): 废弃 LEWAN_ 镜像,统一英文 SKU 与积分价,商品图按 SKU 缓存
对外目录只保留英文主 sku;迁移硬删镜像并校准 1元=100积分;发货页/凭证优先使用 local {sku}.webp。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -83,11 +83,45 @@ func (s *MerchantService) CreateMerchantProduct(merchantID uint, in CreateMercha
|
||||
return merchantProduct, nil
|
||||
}
|
||||
|
||||
type ListMerchantProductsOptions struct {
|
||||
ActiveOnly bool
|
||||
ExcludeLegacyLewanSKU bool
|
||||
Status string // active / inactive;空表示不限(ActiveOnly 优先)
|
||||
Keyword string
|
||||
}
|
||||
|
||||
func (s *MerchantService) ListMerchantProducts(merchantID uint, page, size int, activeOnly bool) ([]model.MerchantProduct, int64, error) {
|
||||
return s.ListMerchantProductsWithOptions(merchantID, page, size, ListMerchantProductsOptions{
|
||||
ActiveOnly: activeOnly,
|
||||
})
|
||||
}
|
||||
|
||||
// ListMerchantProductsForClient 商户开放 API / 手工下单选品:排除 LEWAN_* 镜像,只返回英文主 sku。
|
||||
func (s *MerchantService) ListMerchantProductsForClient(merchantID uint, page, size int) ([]model.MerchantProduct, int64, error) {
|
||||
return s.ListMerchantProductsWithOptions(merchantID, page, size, ListMerchantProductsOptions{
|
||||
ActiveOnly: true,
|
||||
ExcludeLegacyLewanSKU: true,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *MerchantService) ListMerchantProductsWithOptions(merchantID uint, page, size int, opts ListMerchantProductsOptions) ([]model.MerchantProduct, int64, error) {
|
||||
page, size = normalizePage(page, size)
|
||||
tx := s.db.Model(&model.MerchantProduct{}).Where("merchant_id = ?", merchantID)
|
||||
if activeOnly {
|
||||
status := strings.TrimSpace(opts.Status)
|
||||
if opts.ActiveOnly {
|
||||
tx = tx.Where("status = ?", model.ProductStatusActive)
|
||||
} else if status != "" {
|
||||
if status != model.ProductStatusActive && status != model.ProductStatusInactive {
|
||||
return nil, 0, errors.New("无效的商品状态")
|
||||
}
|
||||
tx = tx.Where("status = ?", status)
|
||||
}
|
||||
if opts.ExcludeLegacyLewanSKU {
|
||||
tx = tx.Where("sku NOT ILIKE ?", "lewan_%")
|
||||
}
|
||||
if keyword := strings.TrimSpace(opts.Keyword); keyword != "" {
|
||||
like := "%" + keyword + "%"
|
||||
tx = tx.Where("(sku ILIKE ? OR display_name ILIKE ?)", like, like)
|
||||
}
|
||||
var total int64
|
||||
if err := tx.Count(&total).Error; err != nil {
|
||||
@@ -98,6 +132,28 @@ func (s *MerchantService) ListMerchantProducts(merchantID uint, page, size int,
|
||||
return products, total, err
|
||||
}
|
||||
|
||||
// DeleteMerchantProduct 软删除商户商品;仅允许删除已下架商品,避免误删在售品。
|
||||
func (s *MerchantService) DeleteMerchantProduct(merchantID, id uint, actorUserID uint) error {
|
||||
return s.db.Transaction(func(tx *gorm.DB) error {
|
||||
var item model.MerchantProduct
|
||||
if err := tx.Where("id = ? AND merchant_id = ?", id, merchantID).First(&item).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errors.New("商品不存在")
|
||||
}
|
||||
return err
|
||||
}
|
||||
if item.Status != model.ProductStatusInactive {
|
||||
return errors.New("请先下架后再删除")
|
||||
}
|
||||
if err := tx.Delete(&item).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return writeAudit(tx, &merchantID, &actorUserID, nil, "merchant_product.delete", "merchant_product", fmt.Sprint(id), map[string]string{
|
||||
"sku": item.SKU,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
type UpdateMerchantProductInput struct {
|
||||
DisplayName *string
|
||||
PriceAmount *int64
|
||||
|
||||
Reference in New Issue
Block a user