From 27bd1558d4dec0bb59e823f9b316beb20314cf79 Mon Sep 17 00:00:00 2001 From: timerzz Date: Sat, 31 Aug 2024 12:39:40 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0exclude=E5=B1=9E?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- structs/storage/article.go | 70 ++++++++++++++++++++++++----- structs/storage/provider-article.go | 39 +++++++++++++--- structs/storage/seller-article.go | 38 +++++++++++++--- structs/v2/article.go | 2 + structs/v2/provider.go | 2 + structs/v2/seller.go | 2 + 6 files changed, 132 insertions(+), 21 deletions(-) diff --git a/structs/storage/article.go b/structs/storage/article.go index 2393ae3..eca524b 100644 --- a/structs/storage/article.go +++ b/structs/storage/article.go @@ -27,16 +27,42 @@ func NewArticleApi(db *gorm.DB) ArticleApi { func (a *articleApi) Upsert(article v2.Article) error { return a.db.Clauses(clause.OnConflict{ Columns: []clause.Column{{Name: "pid"}, {Name: "brand"}}, - DoUpdates: clause.AssignmentColumns([]string{"name", "english_name", "available", "updated_at", "cost_price", "sell_price", "rate", "remark"}), + DoUpdates: clause.AssignmentColumns([]string{"name", "english_name", "available", "updated_at", "cost_price", "sell_price", "rate", "remark", "exclude"}), }).Create(&article).Error } +// ******************Find和List + type FindArticleQuery struct { - ID uint `query:"id"` - Keyword string `query:"keyword"` - Brand string `query:"brand"` - Pid string `query:"pid"` - Available *bool `query:"available"` + ID uint `query:"id"` + Keyword string `query:"keyword"` + Brand v2.Brand `query:"brand"` + Pid string `query:"pid"` + Available *bool `query:"available"` +} + +func NewFindArticleQuery() *FindArticleQuery { + return &FindArticleQuery{} +} +func (f *FindArticleQuery) SetID(id uint) *FindArticleQuery { + f.ID = id + return f +} +func (f *FindArticleQuery) SetKeyword(keyword string) *FindArticleQuery { + f.Keyword = keyword + return f +} +func (f *FindArticleQuery) SetBrand(brand v2.Brand) *FindArticleQuery { + f.Brand = brand + return f +} +func (f *FindArticleQuery) SetPid(pid string) *FindArticleQuery { + f.Pid = pid + return f +} +func (f *FindArticleQuery) SetAvailable(available bool) *FindArticleQuery { + f.Available = &available + return f } func (l *FindArticleQuery) Scope(db *gorm.DB) *gorm.DB { @@ -72,11 +98,35 @@ func (a *articleApi) List(query PageListQuery) (articles []v2.Article, total int return } +//**************GET + type GetArticleQuery struct { - ID uint `query:"id"` - Brand string `query:"brand"` - Pid string `query:"pid"` - History bool `query:"history"` + ID uint `query:"id"` + Brand v2.Brand `query:"brand"` + Pid string `query:"pid"` + History bool `query:"history"` +} + +func (g *GetArticleQuery) SetID(id uint) *GetArticleQuery { + g.ID = id + return g +} + +func (g *GetArticleQuery) SetBrand(brand v2.Brand) *GetArticleQuery { + g.Brand = brand + return g +} +func (g *GetArticleQuery) SetPid(pid string) *GetArticleQuery { + g.Pid = pid + return g +} +func (g *GetArticleQuery) SetHistory(history bool) *GetArticleQuery { + g.History = history + return g +} + +func NewGetArticleQuery() *GetArticleQuery { + return &GetArticleQuery{} } func (g *GetArticleQuery) Scope(db *gorm.DB) *gorm.DB { diff --git a/structs/storage/provider-article.go b/structs/storage/provider-article.go index edd065d..b149229 100644 --- a/structs/storage/provider-article.go +++ b/structs/storage/provider-article.go @@ -21,12 +21,41 @@ func NewProviderArticleApi(db *gorm.DB) ProviderArticleApi { return &providerArticleApi{db: db} } +// ******************GET + type GetProviderArticleQuery struct { - ID uint `query:"id"` - Brand string `query:"brand"` - Pid string `query:"pid"` - ProviderId string `query:"providerId"` - SkuId string `query:"skuId"` + ID uint `query:"id"` + Brand v2.Brand `query:"brand"` + Pid string `query:"pid"` + ProviderId string `query:"providerId"` + SkuId string `query:"skuId"` +} + +func NewGetProviderArticleQuery() *GetProviderArticleQuery { + return &GetProviderArticleQuery{} +} + +func (g *GetProviderArticleQuery) SetID(id uint) *GetProviderArticleQuery { + g.ID = id + return g +} +func (g *GetProviderArticleQuery) SetBrand(brand v2.Brand) *GetProviderArticleQuery { + g.Brand = brand + return g +} +func (g *GetProviderArticleQuery) SetPid(pid string) *GetProviderArticleQuery { + g.Pid = pid + return g +} + +func (g *GetProviderArticleQuery) SetProviderId(providerId string) *GetProviderArticleQuery { + g.ProviderId = providerId + return g +} + +func (g *GetProviderArticleQuery) SetSkuId(skuId string) *GetProviderArticleQuery { + g.SkuId = skuId + return g } func (g *GetProviderArticleQuery) Scope(db *gorm.DB) *gorm.DB { diff --git a/structs/storage/seller-article.go b/structs/storage/seller-article.go index aaf542f..456e785 100644 --- a/structs/storage/seller-article.go +++ b/structs/storage/seller-article.go @@ -18,11 +18,37 @@ type sellerArticleApi struct { } type GetSellerArticleQuery struct { - ID uint `query:"id"` - Brand string `query:"brand"` - Pid string `query:"pid"` - SellerId string `query:"sellerId"` - SkuId string `query:"skuId"` + ID uint `query:"id"` + Brand v2.Brand `query:"brand"` + Pid string `query:"pid"` + SellerId string `query:"sellerId"` + SkuId string `query:"skuId"` +} + +func NewGetSellerArticleQuery() *GetSellerArticleQuery { + return &GetSellerArticleQuery{} +} + +func (g *GetSellerArticleQuery) SetID(id uint) *GetSellerArticleQuery { + g.ID = id + return g +} + +func (g *GetSellerArticleQuery) SetBrand(brand v2.Brand) *GetSellerArticleQuery { + g.Brand = brand + return g +} +func (g *GetSellerArticleQuery) SetPid(pid string) *GetSellerArticleQuery { + g.Pid = pid + return g +} +func (g *GetSellerArticleQuery) SetSellerId(sellerId string) *GetSellerArticleQuery { + g.SellerId = sellerId + return g +} +func (g *GetSellerArticleQuery) SetSkuId(skuId string) *GetSellerArticleQuery { + g.SkuId = skuId + return g } func (g *GetSellerArticleQuery) Scope(db *gorm.DB) *gorm.DB { @@ -52,7 +78,7 @@ func (p *sellerArticleApi) Get(query GetSellerArticleQuery) (article v2.SellerAr func (p *sellerArticleApi) Upsert(article v2.SellerArticle) error { return p.db.Clauses(clause.OnConflict{ Columns: []clause.Column{{Name: "seller_id"}, {Name: "sku_id"}}, - DoUpdates: clause.AssignmentColumns([]string{"sell"}), + DoUpdates: clause.AssignmentColumns([]string{"sell", "exclude"}), }).Create(&article).Error } diff --git a/structs/v2/article.go b/structs/v2/article.go index 6e36986..ad30542 100644 --- a/structs/v2/article.go +++ b/structs/v2/article.go @@ -29,6 +29,8 @@ type Article struct { Image string `json:"image"` // 可以购买的 Available bool `json:"available"` + // 排除 + Exclude bool `json:"exclude"` // 最低成本价(单位为分) CostPrice int `json:"costPrice"` // 供应商报价列表 diff --git a/structs/v2/provider.go b/structs/v2/provider.go index 0ad9410..84986bb 100644 --- a/structs/v2/provider.go +++ b/structs/v2/provider.go @@ -63,6 +63,8 @@ type ProviderArticle struct { SkuID string `gorm:"index:providerId_sku,unique" json:"skuID"` // 当前成本价 Cost ProviderPrice `json:"cost" gorm:"type:json;serializer:json"` + // 是否排除,如果排除,就不用拉取价格 + Exclude bool `json:"exclude"` // 历史成本价格 HistoryPrice []ProviderPrice `json:"historyPrice"` // 计算过程 diff --git a/structs/v2/seller.go b/structs/v2/seller.go index 972e39a..4a85105 100644 --- a/structs/v2/seller.go +++ b/structs/v2/seller.go @@ -59,6 +59,8 @@ type SellerArticle struct { SellerId SellerId `gorm:"index:sellerId_sku,unique" json:"sellerId"` // 销售商的sku SkuID string `gorm:"index:sellerId_sku,unique" json:"skuID"` + // 是否排除 + Exclude bool `json:"exclude"` // 当前成本价 Sell SellerPrice `json:"sell" gorm:"type:json;serializer:json"` // 历史出售价格