diff --git a/structs/storage/provider.go b/structs/storage/provider.go index 9f30182..b2f662d 100644 --- a/structs/storage/provider.go +++ b/structs/storage/provider.go @@ -16,6 +16,7 @@ type providerApi struct { // ProviderArticleApi 管理供应商商品的接口 type ProviderArticleApi interface { Get(query GetProviderArticleQuery) (article v2.ProviderArticle, err error) + Upsert(article v2.ProviderArticle) error } type providerArticleApi struct { diff --git a/structs/storage/seller.go b/structs/storage/seller.go index d18288c..d45d64b 100644 --- a/structs/storage/seller.go +++ b/structs/storage/seller.go @@ -16,6 +16,7 @@ type sellerApi struct { // SellerArticleApi 管理供应商商品的接口 type SellerArticleApi interface { Get(query GetProviderArticleQuery) (article v2.ProviderArticle, err error) + Upsert(article v2.SellerArticle) error } type sellerArticleApi struct { diff --git a/structs/v2/calculate-process.go b/structs/v2/calculate-process.go new file mode 100644 index 0000000..82820aa --- /dev/null +++ b/structs/v2/calculate-process.go @@ -0,0 +1,24 @@ +package v2 + +import ( + "time" + + "gorm.io/gorm" +) + +type CalculateProcess struct { + ID uint `gorm:"primary_key" json:"id"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + DeletedAt gorm.DeletedAt `gorm:"index"` + //所有人ID + OwnerID uint `gorm:"index" json:"ownerID"` + // 所有者类型,是provider还是providerArticle还是Seller还是sellerArticle + Kind string `gorm:"index" json:"kind"` + // 条件 + Condition string `json:"condition"` + // 计算过程 + Process string `json:"process"` + // 名称 + Name string `json:"name"` +} diff --git a/structs/v2/provider.go b/structs/v2/provider.go index 0f206c5..b85ea45 100644 --- a/structs/v2/provider.go +++ b/structs/v2/provider.go @@ -1,14 +1,33 @@ package v2 -import "time" +import ( + "time" + + "gorm.io/gorm" +) type ProviderId string -const ( - ProviderId_CoachOutlet_US ProviderId = "coachOutlet_us" - ProviderId_CoachOutlet_CN ProviderId = "coachOutlet_cn" - ProviderId_Coach_CN ProviderId = "coach_cn" -) +type Provider struct { + ID uint `gorm:"primary_key" json:"-"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + DeletedAt gorm.DeletedAt `gorm:"index"` + + ProviderId ProviderId `gorm:"unique" json:"providerId"` + // 供应商的名称 + Name string `json:"name"` + // 供应商配置 + Config ProviderOption `gorm:"type:json;serializer:json" json:"config"` + //计算过程 + CalculateProcess []CalculateProcess `json:"calculateProcess" gorm:"polymorphicType:Kind;polymorphicId:OwnerID;polymorphicValue:provider"` +} + +type ProviderOption struct { + Interval time.Duration `yaml:"interval" json:"interval"` //抓取间隔 + ExchangeRate float64 `yaml:"exchangeRate" json:"exchangeRate"` //汇率 + Freight float64 `yaml:"freight" json:"freight"` //运费 +} // ProviderArticle 供应商商品信息 type ProviderArticle struct { @@ -31,6 +50,8 @@ type ProviderArticle struct { Cost ProviderPrice `json:"cost" gorm:"type:json;serializer:json"` // 历史成本价格 HistoryPrice []ProviderPrice `json:"historyPrice"` + // 计算过程 + CalculateProcess []CalculateProcess `json:"calculateProcess" gorm:"polymorphicType:Kind;polymorphicId:OwnerID;polymorphicValue:providerArticle"` } // ProviderPrice 供应商成本价格 diff --git a/structs/v2/seller.go b/structs/v2/seller.go index 149fa64..d5a4cb0 100644 --- a/structs/v2/seller.go +++ b/structs/v2/seller.go @@ -1,12 +1,32 @@ package v2 -import "time" +import ( + "time" + + "gorm.io/gorm" +) type SellerId string -const ( - SellerId_DW SellerId = "dewu" -) +// Seller 出货商 +type Seller struct { + ID uint `gorm:"primary_key" json:"-"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + DeletedAt gorm.DeletedAt `gorm:"index"` + + SellerId SellerId `gorm:"unique" json:"sellerId"` + // 出货商的名称 + Name string `json:"name"` + // 出货商配置 + Config SellerOption `gorm:"type:json;serializer:json" json:"config"` + //计算过程 + CalculateProcess []CalculateProcess `json:"calculateProcess" gorm:"polymorphicType:Kind;polymorphicId:OwnerID;polymorphicValue:seller"` +} + +type SellerOption struct { + Interval time.Duration `yaml:"interval" json:"interval"` //抓取间隔 +} // SellerArticle 销售商商品信息 type SellerArticle struct { @@ -28,6 +48,8 @@ type SellerArticle struct { Sell SellerPrice `json:"sell" gorm:"type:json;serializer:json"` // 历史出售价格 HistoryPrice []SellerPrice `json:"historyPrice"` + // 计算过程 + CalculateProcess []CalculateProcess `json:"calculateProcess" gorm:"polymorphicType:Kind;polymorphicId:OwnerID;polymorphicValue:sellerArticle"` } // SellerPrice 供应商成本价格