2025-03-17 02:08:22 +00:00
|
|
|
package repository
|
|
|
|
|
2025-03-19 06:45:44 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"code.30cm.net/digimon/app-cloudep-product-service/pkg/domain/entity"
|
|
|
|
"code.30cm.net/digimon/app-cloudep-product-service/pkg/domain/product"
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ProductItemRepository 定義商品相關操作的接口
|
|
|
|
type ProductItemRepository interface {
|
|
|
|
ProductItemIndex
|
|
|
|
ProductItemBasic
|
|
|
|
ProductItemStatistics
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProductItemIndex interface {
|
|
|
|
Index20250317001UP(ctx context.Context) (*mongo.Cursor, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProductItemBasic 基礎操作
|
|
|
|
type ProductItemBasic interface {
|
|
|
|
// Insert 一次新增多筆
|
|
|
|
Insert(ctx context.Context, item []entity.ProductItems) error
|
|
|
|
// Delete 刪除商品
|
|
|
|
Delete(ctx context.Context, ids []string) error
|
|
|
|
// Update 更新商品
|
|
|
|
Update(ctx context.Context, id string, param *ProductUpdateItem) error
|
|
|
|
// DeleteByReferenceID 刪除某Project 下所有
|
|
|
|
DeleteByReferenceID(ctx context.Context, id string) error
|
|
|
|
// FindByID 根據 ID 查找商品
|
|
|
|
FindByID(ctx context.Context, id string) (*entity.ProductItems, error)
|
|
|
|
// ListProductItem 查找商品列表
|
|
|
|
ListProductItem(ctx context.Context, param ProductItemQueryParams) ([]entity.ProductItems, int64, error)
|
|
|
|
// UpdateStatus 更新品相狀態
|
|
|
|
UpdateStatus(ctx context.Context, id string, status product.ItemStatus) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProductItemQueryParams struct {
|
|
|
|
PageSize int64 // 每頁顯示的專案數量
|
|
|
|
PageIndex int64 // 要查詢的頁數
|
|
|
|
ItemID []string // Item 的 ID
|
|
|
|
ReferenceID *string // 對應參照的ID
|
|
|
|
IsFree *bool // 是否為免費品項(贈品)
|
|
|
|
Status *product.ItemStatus // 商品狀態
|
|
|
|
}
|
|
|
|
type ProductUpdateItem struct {
|
|
|
|
Name *string // 名稱
|
|
|
|
Description *string // 描述
|
|
|
|
Price *decimal.Decimal // 價格
|
|
|
|
Stock *int64 // 庫存總數
|
|
|
|
ShortDescription *string // 封面簡短描述
|
|
|
|
IsUnLimit *bool // 是否沒有數量上限
|
|
|
|
IsFree *bool // 是否為免費品項(贈品) -> 開啟就是自訂金額
|
|
|
|
SKU *string // 型號:對應顯示 Item 的 FK
|
|
|
|
TimeSeries *product.TimeSeries // 時段種類
|
|
|
|
Media []entity.Media // 專案動態內容(圖片或者影片)
|
|
|
|
Freight []entity.CustomFields // 運費
|
|
|
|
CustomFields []entity.CustomFields // 自定義屬性
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProductItemStatistics interface {
|
|
|
|
// IncSalesCount 更新接單總數 -> 新增
|
|
|
|
IncSalesCount(ctx context.Context, id string, count int64) error
|
|
|
|
// DecSalesCount 減少接單總數 -> 取消
|
|
|
|
DecSalesCount(ctx context.Context, id string, count int64) error
|
|
|
|
// GetSalesCount 取得這item 的接單數
|
|
|
|
GetSalesCount(ctx context.Context, ids []string) ([]ProductItemSalesCount, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProductItemSalesCount struct {
|
|
|
|
ID string
|
|
|
|
Count uint64
|
|
|
|
}
|