item

package
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2022 License: GPL-2.0 Imports: 5 Imported by: 0

README

商品

用goods item 来表示商品,便于区分。在外部系统直接用item

一个产品(product)对应多个商品(item), 其中商品包括规格(sku) 商品交易时, 为最新的快照(item snapshot).商品交易结束后生成交易快照(trade snapshot)

Documentation

Overview

*

  • Copyright 2014 @ 56x.net.
  • name :
  • author : jarryliu
  • date : 2014-02-04 20:39
  • description :
  • history :

*

  • Copyright 2015 @ 56x.net.
  • name : goods
  • author : jarryliu
  • date : 2016-06-28 23:54
  • description :
  • history :

*

  • Copyright 2015 @ 56x.net.
  • name : label_manager
  • author : jarryliu
  • date : 2016-06-06 21:37
  • description :
  • history :

*

  • Copyright 2015 @ 56x.net.
  • name : snapshot
  • author : jarryliu
  • date : 2016-06-28 21:41
  • description :
  • history :

Index

Constants

View Source
const (
	// 普通商品
	ItemNormal int32 = 1
	// 批发商品
	ItemWholesale int32 = 2
)
View Source
const (
	// 仓库中的商品
	ShelvesInWarehouse int32 = 0
	// 已下架
	ShelvesDown int32 = 1
	// 已上架
	ShelvesOn int32 = 2
	// 已拒绝上架 (不允许上架)
	ShelvesIncorrect int32 = 3
)

Variables

View Source
var (
	ErrNoSuchSku = domain.NewError(
		"err_item_no_such_item_sku", "商品SKU不存在")

	ErrNotBindShop = domain.NewError(
		"err_item_not_bind_shop", "请选择商品上架的店铺")

	ErrIncorrectShopOfItem = domain.NewError(
		"err_item_not_bind_shop", "商品绑定的店铺非法")

	ErrEmptyReviewRemark = domain.NewError(
		"err_sale_empty_remark", "原因不能为空")

	ErrGoodsNum = domain.NewError(
		"err_goods_num", "商品数量错误")

	ErrOutOfSalePrice = domain.NewError(
		"out_of_sale_price", "超出商品售价")

	ErrOutOfStock = domain.NewError(
		"err_out_of_stock", "库存不足")

	ErrFullOfStock = domain.NewError(
		"err_full_of_stock", "商品已经售完")

	ErrInternalDisallow = domain.NewError(
		"err_sale_tag_internal_disallow", "不允许删除内置销售标签!")

	ErrCanNotDeleteItem = domain.NewError(
		"err_goods_can_not_delete_item", "已售出货品只允许下架。")

	ErrNotSetWholesalePrice = domain.NewError(
		"err_not_set_wholesale_price", "请先设置批发价格!")
)
View Source
var (
	ErrNoSuchItem = domain.NewError(
		"no_such_goods", "商品不存在")

	ErrIncorrectProductCategory = domain.NewError(
		"err_item_incorrect_product_category", "非法的商品分类")

	ErrItemWholesaleOff = domain.NewError(
		"err_item_wholesale_off", "商品已下架或待审核!")

	ErrLatestSnapshot = domain.NewError(
		"latest_snapshot", "已经是最新的快照")

	ErrNoSuchSnapshot = domain.NewError(
		"no_such_snapshot", "商品快照不存在")

	ErrNotOnShelves = domain.NewError(
		"not_on_shelves", "商品已下架")

	ErrGoodsMinProfitRate = domain.NewError(
		"err_goods_min_profit_rate", "商品利润率不能低于%s")
)

Functions

This section is empty.

Types

type GoodsItem

type GoodsItem struct {
	// 商品编号
	Id int64 `db:"id" pk:"yes" auto:"yes"`
	// 产品编号
	ProductId int64 `db:"product_id"`
	// 促销标志
	PromFlag int32 `db:"prom_flag"`
	// 分类编号
	CategoryId int32 `db:"cat_id"`
	// 供货商编号
	VendorId int64 `db:"vendor_id"`
	// 品牌编号(冗余)
	BrandId int32 `db:"brand_id"`
	// 店铺编号
	ShopId int64 `db:"shop_id"`
	// 店铺分类编号
	ShopCatId int32 `db:"shop_cat_id"`
	// 快递模板编号
	ExpressTid int32 `db:"express_tid"`
	// 商品标题
	Title string `db:"title"`
	// 短标题
	ShortTitle string `db:"short_title"`
	// 供货商编码
	Code string `db:"code"`
	// 主图
	Image string `db:"image"`
	// 是否为赠品
	IsPresent int32 `db:"is_present"`
	// 销售价格区间
	PriceRange string `db:"price_range"`
	// 总库存
	StockNum int32 `db:"stock_num"`
	// 销售数量
	SaleNum int32 `db:"sale_num"`
	// SKU数量
	SkuNum int32 `db:"sku_num"`
	// 默认SKU编号
	SkuId int64 `db:"sku_id"`
	// 成本价
	Cost int64 `db:"cost"`
	// 销售价
	Price int64 `db:"price"`
	// 零售价
	RetailPrice int64 `db:"retail_price"`
	// 重量:克(g)
	Weight int32 `db:"weight"`
	// 体积:毫升(ml)
	Bulk int32 `db:"bulk"`
	// 是否上架
	ShelveState int32 `db:"shelve_state"`
	// 审核状态
	ReviewState int32 `db:"review_state"`
	// 审核备注
	ReviewRemark string `db:"review_remark"`
	// 排序序号
	SortNum int32 `db:"sort_num"`
	// 创建时间
	CreateTime int64 `db:"create_time"`
	// 更新时间
	UpdateTime int64 `db:"update_time"`
	// 促销价
	PromPrice int64 `db:"-"`

	SkuArray []*Sku `db:"-"`
}

商品,临时改方便辨别

type IGoodsItem

type IGoodsItem interface {
	// 获取聚合根编号
	GetAggregateRootId() int64
	// 设置值
	GetValue() *GoodsItem
	// 获取包装过的商品信息
	GetPackedValue() *valueobject.Goods
	// 设置值
	SetValue(*GoodsItem) error
	// 设置SKU
	SetSku(arr []*Sku) error
	// 保存
	Save() (int64, error)
	// 获取产品
	Product() product.IProduct
	// 商品快照
	Snapshot() *Snapshot
	// 批发
	Wholesale() IWholesaleItem
	// 获取SKU数组
	SkuArray() []*Sku
	// 获取商品的规格
	SpecArray() promodel.SpecList
	// 获取SKU
	GetSku(skuId int64) *Sku
	// 获取促销信息
	GetPromotions() []promotion.IPromotion
	// 获取促销价
	GetPromotionPrice(level int) int64
	// 获取会员价销价,返回是否有会原价及价格
	GetLevelPrice(level int) (bool, int64)
	// 获取促销描述
	GetPromotionDescribe() map[string]string
	// 获取会员价
	GetLevelPrices() []*MemberPrice
	// 保存会员价
	SaveLevelPrice(*MemberPrice) (int32, error)
	// 是否上架
	IsOnShelves() bool
	// 设置上架
	SetShelve(state int32, remark string) error
	// 审核
	Review(pass bool, remark string) error
	// 标记为违规
	Incorrect(remark string) error
	// 更新销售数量,扣减库存
	AddSalesNum(skuId int64, quantity int32) error
	// 取消销售
	CancelSale(skuId int64, quantity int32, orderNo string) error
	// 占用库存
	TakeStock(skuId int64, quantity int32) error
	// 释放库存
	FreeStock(skuId int64, quantity int32) error

	// 删除商品
	Destroy() error
}

商品

type IGoodsItemRepo

type IGoodsItemRepo interface {
	// 获取SKU服务
	SkuService() ISkuService
	// 获取快照服务
	SnapshotService() ISnapshotService

	// 创建商品
	CreateItem(v *GoodsItem) IGoodsItem

	// 获取商品
	GetItem(itemId int64) IGoodsItem

	// 获取商品
	GetValueGoods(itemId, skuId int64) *GoodsItem

	// 根据SKU-ID获取商品,SKU-ID为商品ID
	//todo: 循环引有,故为interface{}
	GetItemBySkuId(skuId int64) interface{}

	// 获取商品
	GetValueGoodsById(goodsId int64) *GoodsItem

	// 根据产品编号和SKU获取商品
	GetValueGoodsBySku(productId, skuId int64) *GoodsItem

	// 保存商品
	SaveValueGoods(*GoodsItem) (int64, error)

	// 获取在货架上的商品
	GetOnShelvesGoods(mchId int64, start, end int,
		sortBy string) []*valueobject.Goods

	// 获取在货架上的商品
	GetPagedOnShelvesGoods(mchId int64, catIds []int, start, end int,
		where, orderBy string) (total int, goods []*valueobject.Goods)

	// 根据编号获取商品
	GetGoodsByIds(ids ...int64) ([]*valueobject.Goods, error)

	// 获取会员价
	GetGoodSMemberLevelPrice(goodsId int64) []*MemberPrice

	// 保存会员价
	SaveGoodSMemberLevelPrice(*MemberPrice) (int32, error)

	// 移除会员价
	RemoveGoodSMemberLevelPrice(id int) error

	// 保存快照
	SaveSnapshot(*Snapshot) (int64, error)

	// 根据指定商品快照
	GetSnapshots(skuIdArr []int64) []Snapshot

	// 获取最新的商品快照
	GetLatestSnapshot(itemId int64) *Snapshot

	// 获取指定的商品快照
	GetSalesSnapshot(id int64) *TradeSnapshot

	// 根据Key获取商品快照
	GetSaleSnapshotByKey(key string) *TradeSnapshot

	// 获取最新的商品销售快照
	GetLatestSalesSnapshot(skuId int64) *TradeSnapshot

	// 保存商品销售快照
	SaveSalesSnapshot(*TradeSnapshot) (int64, error)

	// Get ItemSku
	GetItemSku(primary interface{}) *Sku
	// Select ItemSku
	SelectItemSku(where string, v ...interface{}) []*Sku
	// Save ItemSku
	SaveItemSku(v *Sku) (int, error)
	// Delete ItemSku
	DeleteItemSku(primary interface{}) error
	// Batch Delete ItemSku
	BatchDeleteItemSku(where string, v ...interface{}) (int64, error)
}

商品仓储

type IItemWholesaleRepo

type IItemWholesaleRepo interface {
	// Get WsItem
	GetWsItem(primary interface{}) *WsItem
	// Select WsItem
	SelectWsItem(where string, v ...interface{}) []*WsItem
	// Save WsItem
	SaveWsItem(v *WsItem, create bool) (int, error)
	// Delete WsItem
	DeleteWsItem(primary interface{}) error
	// Batch Delete WsItem
	BatchDeleteWsItem(where string, v ...interface{}) (int64, error)

	// Get WsSkuPrice
	GetWsSkuPrice(primary interface{}) *WsSkuPrice
	// Select WsSkuPrice
	SelectWsSkuPrice(where string, v ...interface{}) []*WsSkuPrice
	// Save WsSkuPrice
	SaveWsSkuPrice(v *WsSkuPrice) (int, error)
	// Delete WsSkuPrice
	DeleteWsSkuPrice(primary interface{}) error
	// Batch Delete WsSkuPrice
	BatchDeleteWsSkuPrice(where string, v ...interface{}) (int64, error)

	// Get WsItemDiscount
	GetWsItemDiscount(primary interface{}) *WsItemDiscount
	// Select WsItemDiscount
	SelectWsItemDiscount(where string, v ...interface{}) []*WsItemDiscount
	// Save WsItemDiscount
	SaveWsItemDiscount(v *WsItemDiscount) (int, error)
	// Delete WsItemDiscount
	DeleteWsItemDiscount(primary interface{}) error
	// Batch Delete WsItemDiscount
	BatchDeleteWsItemDiscount(where string, v ...interface{}) (int64, error)
}

type ILabelService

type ILabelService interface {
	// 获取所有的销售标签
	GetAllSaleLabels() []ISaleLabel

	// 初始化销售标签
	InitSaleLabels() error

	// 获取销售标签
	GetSaleLabel(id int32) ISaleLabel

	// 根据Code获取销售标签
	GetSaleLabelByCode(code string) ISaleLabel

	// 创建销售标签
	CreateSaleLabel(v *Label) ISaleLabel

	// 删除销售标签
	DeleteSaleLabel(id int32) error
}

标签服务

type ISaleLabel

type ISaleLabel interface {
	GetDomainId() int32

	// 获取值
	GetValue() *Label

	// 设置值
	SetValue(v *Label) error

	// 保存
	Save() (int32, error)

	// 是否为系统内置
	System() bool

	// 获取标签下的商品
	GetValueGoods(sortBy string, begin, end int) []*valueobject.Goods

	// 获取标签下的分页商品
	GetPagedValueGoods(sortBy string, begin, end int) (total int,
		goods []*valueobject.Goods)
}

销售标签接口

type ISaleLabelRepo

type ISaleLabelRepo interface {
	// 获取商品标签服务
	LabelService() ILabelService

	// 创建销售标签
	CreateSaleLabel(v *Label) ISaleLabel

	// 获取所有的销售标签
	GetAllValueSaleLabels(mchId int64) []*Label

	// 获取销售标签值
	GetValueSaleLabel(mchId int64, tagId int32) *Label

	// 根据Code获取销售标签
	GetSaleLabelByCode(mchId int64, code string) *Label

	// 删除销售标签
	DeleteSaleLabel(mchId int64, id int32) error

	// 获取销售标签
	GetSaleLabel(mchId int64, tagId int32) ISaleLabel

	// 保存销售标签
	SaveSaleLabel(mchId int64, v *Label) (int32, error)

	// 获取商品
	GetValueGoodsBySaleLabel(mchId int64, tagId int32, sortBy string,
		begin, end int) []*valueobject.Goods

	// 获取分页商品
	GetPagedValueGoodsBySaleLabel(mchId int64, tagId int32, sortBy string,
		begin, end int) (int, []*valueobject.Goods)

	// 获取商品的销售标签
	GetItemSaleLabels(itemId int32) []*Label

	// 清理商品的销售标签
	CleanItemSaleLabels(itemId int32) error

	// 保存商品的销售标签
	SaveItemSaleLabels(itemId int32, tagIds []int) error
}

type ISkuService

type ISkuService interface {
	// SpecDataToMap 将SKU字符串转为字典,如: 1:2;2:3
	SpecDataToMap(specData string) map[int]int
	// GetSpecItemArray 获取规格和项的数组
	GetSpecItemArray(sku []*Sku) ([]int, []int)
	// Merge 合并SKU数组;主要是SKU编号的复制
	Merge(from []*Sku, to *[]*Sku)
	// RebuildSkuArray 重建SKU数组,将信息附加
	RebuildSkuArray(sku *[]*Sku, it *GoodsItem) error
	// UpgradeBySku 根据SKU更新商品的信息
	UpgradeBySku(it *GoodsItem, arr []*Sku) error
	// GetItemSkuJson 获取商品SKU的JSON字符串
	GetItemSkuJson(skuArr []*Sku) []byte
	// GetItemSpecArray 获取商品的规格(从SKU中读取)
	GetItemSpecArray(skuArr []*Sku) promodel.SpecList
	// GetSpecHtml 获取规格选择HTML
	GetSpecHtml(spec promodel.SpecList) string
	// GetSpecJson 获取规格JSON数据
	GetSpecJson(spec promodel.SpecList) []byte
}

type ISnapshotService

type ISnapshotService interface {
	// 生成商品快照
	GenerateSnapshot(it *GoodsItem) (int64, error)

	// 获取最新的快照
	GetLatestSnapshot(itemId int64) *Snapshot

	// 获取最新的商品销售快照,如果商品有更新,则更新销售快照
	GetLatestSalesSnapshot(itemId, skuId int64) *TradeSnapshot

	// 根据KEY获取已销售商品的快照
	GetSaleSnapshotByKey(key string) *TradeSnapshot

	// 根据ID获取已销售商品的快照
	GetSalesSnapshot(id int64) *TradeSnapshot
}

快照服务

type IWholesaleItem

type IWholesaleItem interface {
	// 获取领域编号
	GetDomainId() int64
	// 是否允许批发
	CanWholesale() bool
	// 保存
	Save() (int32, error)

	// 获取详细信息
	GetJsonDetailData() []byte

	// 是否上架
	IsOnShelves() bool
	// 设置上架
	SetShelve(state int32, remark string) error
	// 审核
	Review(pass bool, remark string) error
	// 标记为违规
	Incorrect(remark string) error

	// 根据商品金额获取折扣
	GetWholesaleDiscount(groupId int32, amount int32) float64
	// 获取全部批发折扣
	GetItemDiscount(groupId int32) []*WsItemDiscount
	// 保存批发折扣
	SaveItemDiscount(groupId int32, arr []*WsItemDiscount) error

	// 获取批发价格
	GetWholesalePrice(skuId int64, quantity int32) int64
	// 根据SKU获取价格设置
	GetSkuPrice(skuId int64) []*WsSkuPrice
	// 保存批发SKU价格设置
	SaveSkuPrice(skuId int64, arr []*WsSkuPrice) error
}

商品批发

type Label

type Label struct {
	Id int32 `db:"id" auto:"yes" pk:"yes"`

	// 商户编号
	MerchantId int64 `db:"mch_id"`

	// 标签代码
	TagCode string `db:"tag_code"`

	// 标签名
	TagName string `db:"tag_name"`

	// 商品的遮盖图
	LabelImage string `db:"label_image"`

	// 是否启用
	Enabled int `db:"enabled"`
}

销售标签

type MemberPrice

type MemberPrice struct {
	Id      int   `db:"id" pk:"yes" auto:"yes"`
	GoodsId int64 `db:"goods_id"`
	Level   int   `db:"level"`
	Price   int64 `db:"price"`
	// 限购数量
	MaxQuota int `db:"max_quota"`
	Enabled  int `db:"enabled"`
}

会员价

type Sku

type Sku struct {
	// 编号
	Id int64 `db:"id" pk:"yes" auto:"yes"`
	// 产品编号
	ProductId int64 `db:"product_id"`
	// 商品编号
	ItemId int64 `db:"item_id"`
	// 标题
	Title string `db:"title"`
	// 图片
	Image string `db:"image"`
	// 规格数据
	SpecData string `db:"spec_data"`
	// 规格字符
	SpecWord string `db:"spec_word"`
	// 产品编码
	Code string `db:"code"`
	// 参考价
	RetailPrice int64 `db:"retail_price"`
	// 价格(分)
	Price int64 `db:"price"`
	// 成本(分)
	Cost int64 `db:"cost"`
	// 重量(克)
	Weight int32 `db:"weight"`
	// 体积(毫升)
	Bulk int32 `db:"bulk"`
	// 库存
	Stock int32 `db:"stock"`
	// 已销售数量
	SaleNum int32 `db:"sale_num"`
}

商品SKU

type SkuMedia

type SkuMedia struct {
	// SKU编号
	SkuId int32 `db:"sku_id"`
	// 商品标题
	Title string `db:"title"`
	// 产品编号
	ProductId int32 `db:"product_id"`
	// 商品编号
	ItemId int32 `db:"item_id"`
	// 分类编号
	CatId int32 `db:"cat_id"`
	// 供货商编号
	VendorId int32 `db:"vendor_id"`
	// 品牌编号(冗余)
	BrandId int32 `db:"brand_id"`
	// 店铺编号
	ShopId int32 `db:"shop_id"`
	// 店铺分类编号
	ShopCatId int32 `db:"shop_cat_id"`
	// 快递模板编号
	ExpressTid int32 `db:"express_tid"`
	// 图片
	Image string `db:"image"`
	// 规格数据
	SpecData string `db:"spec_data"`
	// 规格字符
	SpecWord string `db:"spec_word"`
	// 产品编码
	ItemCode string `db:"code"`
	// 参考价
	RetailPrice int64 `db:"retail_price"`
	// 价格(分)
	Price int64 `db:"price"`
	// 重量(克)
	Weight int32 `db:"weight"`
	// 体积(毫升)
	Bulk int32 `db:"bulk"`
	// 库存
	Stock int32 `db:"stock"`
	// 已销售数量
	SaleNum int32 `db:"sale_num"`
}

SKU媒介信息,用于与订单数据交换

func ParseSkuMedia

func ParseSkuMedia(it *GoodsItem, sku *Sku) *SkuMedia

转换为SKU媒体

type Snapshot

type Snapshot struct {
	// 商品编号
	ItemId int64 `db:"item_id" pk:"yes"`
	// 产品编号
	ProductId int64 `db:"product_id"`
	// 快照编码
	Key string `db:"snapshot_key"`
	// 分类编号
	CatId int32 `db:"cat_id"`
	// 供货商编号
	VendorId int64 `db:"vendor_id"`
	// 编号
	BrandId int32 `db:"brand_id"`
	// 店铺编号
	ShopId int64 `db:"shop_id"`
	// 编号分类编号
	ShopCatId int32 `db:"shop_cat_id"`
	// 运费模板
	ExpressTid int32 `db:"express_tid"`
	// 商品标题
	Title string `db:"title"`
	// 短标题
	ShortTitle string `db:"short_title"`
	// 商户编码
	Code string `db:"code"`
	// 商品图片
	Image string `db:"image"`
	// 是否为赠品
	IsPresent int32 `db:"is_present"`
	// 价格区间
	PriceRange string `db:"price_range"`
	// 默认SKU
	SkuId int64 `db:"sku_id"`
	// 成本
	Cost int64 `db:"cost"`
	// 售价
	Price int64 `db:"price"`
	// 零售价
	RetailPrice int64 `db:"retail_price"`
	// 重量(g)
	Weight int32 `db:"weight"`
	// 体积(ml)
	Bulk int32 `db:"bulk"`
	// 会员价
	LevelSales int32 `db:"level_sales"`
	// 上架状态
	ShelveState int32 `db:"shelve_state"`
	// 更新时间
	UpdateTime int64 `db:"update_time"`
}

商品快照(针对商品)

type TradeSnapshot

type TradeSnapshot struct {
	//快照编号
	Id int64 `db:"id" auto:"yes" pk:"yes"`
	//商品编号
	ItemId int64 `db:"item_id"`
	//商品SKU编号
	SkuId int64 `db:"sku_id"`
	//快照编码: 商户编号+g商品编号+快照时间戳
	SnapshotKey string `db:"snap_key"`
	// 卖家编号
	SellerId int64 `db:"seller_id"`
	// 卖家名称
	//SellerName  string `db:"seller_name"`
	//商品标题
	GoodsTitle string `db:"goods_title"`
	//小标题
	//SmallTitle  string `db:"-"`
	//货号
	GoodsNo string `db:"goods_no"`
	//分类编号
	CategoryId int32 `db:"cat_id"`
	//SKU
	Sku string `db:"sku"`
	//图片
	Image string `db:"img"`
	// 供货价
	Cost int64 `db:"cost"`
	//销售价
	Price int64 `db:"price"`
	// 快照时间
	CreateTime int64 `db:"create_time"`
}

已销售(交易)商品快照(针对SKU)

type WsItem

type WsItem struct {
	// 编号
	ID int64 `db:"id" pk:"yes" auto:"yes"`
	// 运营商编号
	VendorId int64 `db:"vendor_id"`
	// 商品编号
	ItemId int64 `db:"item_id"`
	// 价格
	Price int64 `db:"price"`
	// 价格区间
	PriceRange string `db:"price_range"`
	// 上架状态
	ShelveState int32 `db:"shelve_state"`
	// 是否审核通过
	ReviewState int32 `db:"review_state"`
	// 审核备注
	ReviewRemark string `db:"review_remark"`
}

批发商品

type WsItemDiscount

type WsItemDiscount struct {
	// 编号
	ID int32 `db:"id" pk:"yes" auto:"yes"`
	// 商品编号
	ItemId int64 `db:"item_id"`
	// 客户分组
	BuyerGid int32 `db:"buyer_gid"`
	// 要求金额,默认为0
	RequireAmount int32 `db:"require_amount"`
	// 折扣率
	DiscountRate float64 `db:"discount_rate"`
}

批发商品折扣

type WsSkuPrice

type WsSkuPrice struct {
	// 编号
	ID int32 `db:"id" pk:"yes" auto:"yes"`
	// 商品编号
	ItemId int64 `db:"item_id"`
	// SKU编号
	SkuId int64 `db:"sku_id"`
	// 需要数量以上
	RequireQuantity int32 `db:"require_quantity"`
	// 批发价
	WholesalePrice int64 `db:"wholesale_price"`
}

商品批发价

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL