feat 添加exclude属性
This commit is contained in:
parent
cba02db8e8
commit
27bd1558d4
@ -27,18 +27,44 @@ func NewArticleApi(db *gorm.DB) ArticleApi {
|
|||||||
func (a *articleApi) Upsert(article v2.Article) error {
|
func (a *articleApi) Upsert(article v2.Article) error {
|
||||||
return a.db.Clauses(clause.OnConflict{
|
return a.db.Clauses(clause.OnConflict{
|
||||||
Columns: []clause.Column{{Name: "pid"}, {Name: "brand"}},
|
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
|
}).Create(&article).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ******************Find和List
|
||||||
|
|
||||||
type FindArticleQuery struct {
|
type FindArticleQuery struct {
|
||||||
ID uint `query:"id"`
|
ID uint `query:"id"`
|
||||||
Keyword string `query:"keyword"`
|
Keyword string `query:"keyword"`
|
||||||
Brand string `query:"brand"`
|
Brand v2.Brand `query:"brand"`
|
||||||
Pid string `query:"pid"`
|
Pid string `query:"pid"`
|
||||||
Available *bool `query:"available"`
|
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 {
|
func (l *FindArticleQuery) Scope(db *gorm.DB) *gorm.DB {
|
||||||
if l.ID != 0 {
|
if l.ID != 0 {
|
||||||
db = db.Where("`id` = ?", l.ID)
|
db = db.Where("`id` = ?", l.ID)
|
||||||
@ -72,13 +98,37 @@ func (a *articleApi) List(query PageListQuery) (articles []v2.Article, total int
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//**************GET
|
||||||
|
|
||||||
type GetArticleQuery struct {
|
type GetArticleQuery struct {
|
||||||
ID uint `query:"id"`
|
ID uint `query:"id"`
|
||||||
Brand string `query:"brand"`
|
Brand v2.Brand `query:"brand"`
|
||||||
Pid string `query:"pid"`
|
Pid string `query:"pid"`
|
||||||
History bool `query:"history"`
|
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 {
|
func (g *GetArticleQuery) Scope(db *gorm.DB) *gorm.DB {
|
||||||
db = db.Preload("Providers").Preload("Sellers")
|
db = db.Preload("Providers").Preload("Sellers")
|
||||||
if g.ID != 0 {
|
if g.ID != 0 {
|
||||||
|
@ -21,14 +21,43 @@ func NewProviderArticleApi(db *gorm.DB) ProviderArticleApi {
|
|||||||
return &providerArticleApi{db: db}
|
return &providerArticleApi{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ******************GET
|
||||||
|
|
||||||
type GetProviderArticleQuery struct {
|
type GetProviderArticleQuery struct {
|
||||||
ID uint `query:"id"`
|
ID uint `query:"id"`
|
||||||
Brand string `query:"brand"`
|
Brand v2.Brand `query:"brand"`
|
||||||
Pid string `query:"pid"`
|
Pid string `query:"pid"`
|
||||||
ProviderId string `query:"providerId"`
|
ProviderId string `query:"providerId"`
|
||||||
SkuId string `query:"skuId"`
|
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 {
|
func (g *GetProviderArticleQuery) Scope(db *gorm.DB) *gorm.DB {
|
||||||
if g.ID > 0 {
|
if g.ID > 0 {
|
||||||
db = db.Where("id=?", g.ID)
|
db = db.Where("id=?", g.ID)
|
||||||
|
@ -19,12 +19,38 @@ type sellerArticleApi struct {
|
|||||||
|
|
||||||
type GetSellerArticleQuery struct {
|
type GetSellerArticleQuery struct {
|
||||||
ID uint `query:"id"`
|
ID uint `query:"id"`
|
||||||
Brand string `query:"brand"`
|
Brand v2.Brand `query:"brand"`
|
||||||
Pid string `query:"pid"`
|
Pid string `query:"pid"`
|
||||||
SellerId string `query:"sellerId"`
|
SellerId string `query:"sellerId"`
|
||||||
SkuId string `query:"skuId"`
|
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 {
|
func (g *GetSellerArticleQuery) Scope(db *gorm.DB) *gorm.DB {
|
||||||
if g.ID > 0 {
|
if g.ID > 0 {
|
||||||
db = db.Where("id=?", g.ID)
|
db = db.Where("id=?", g.ID)
|
||||||
@ -52,7 +78,7 @@ func (p *sellerArticleApi) Get(query GetSellerArticleQuery) (article v2.SellerAr
|
|||||||
func (p *sellerArticleApi) Upsert(article v2.SellerArticle) error {
|
func (p *sellerArticleApi) Upsert(article v2.SellerArticle) error {
|
||||||
return p.db.Clauses(clause.OnConflict{
|
return p.db.Clauses(clause.OnConflict{
|
||||||
Columns: []clause.Column{{Name: "seller_id"}, {Name: "sku_id"}},
|
Columns: []clause.Column{{Name: "seller_id"}, {Name: "sku_id"}},
|
||||||
DoUpdates: clause.AssignmentColumns([]string{"sell"}),
|
DoUpdates: clause.AssignmentColumns([]string{"sell", "exclude"}),
|
||||||
}).Create(&article).Error
|
}).Create(&article).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ type Article struct {
|
|||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
// 可以购买的
|
// 可以购买的
|
||||||
Available bool `json:"available"`
|
Available bool `json:"available"`
|
||||||
|
// 排除
|
||||||
|
Exclude bool `json:"exclude"`
|
||||||
// 最低成本价(单位为分)
|
// 最低成本价(单位为分)
|
||||||
CostPrice int `json:"costPrice"`
|
CostPrice int `json:"costPrice"`
|
||||||
// 供应商报价列表
|
// 供应商报价列表
|
||||||
|
@ -63,6 +63,8 @@ type ProviderArticle struct {
|
|||||||
SkuID string `gorm:"index:providerId_sku,unique" json:"skuID"`
|
SkuID string `gorm:"index:providerId_sku,unique" json:"skuID"`
|
||||||
// 当前成本价
|
// 当前成本价
|
||||||
Cost ProviderPrice `json:"cost" gorm:"type:json;serializer:json"`
|
Cost ProviderPrice `json:"cost" gorm:"type:json;serializer:json"`
|
||||||
|
// 是否排除,如果排除,就不用拉取价格
|
||||||
|
Exclude bool `json:"exclude"`
|
||||||
// 历史成本价格
|
// 历史成本价格
|
||||||
HistoryPrice []ProviderPrice `json:"historyPrice"`
|
HistoryPrice []ProviderPrice `json:"historyPrice"`
|
||||||
// 计算过程
|
// 计算过程
|
||||||
|
@ -59,6 +59,8 @@ type SellerArticle struct {
|
|||||||
SellerId SellerId `gorm:"index:sellerId_sku,unique" json:"sellerId"`
|
SellerId SellerId `gorm:"index:sellerId_sku,unique" json:"sellerId"`
|
||||||
// 销售商的sku
|
// 销售商的sku
|
||||||
SkuID string `gorm:"index:sellerId_sku,unique" json:"skuID"`
|
SkuID string `gorm:"index:sellerId_sku,unique" json:"skuID"`
|
||||||
|
// 是否排除
|
||||||
|
Exclude bool `json:"exclude"`
|
||||||
// 当前成本价
|
// 当前成本价
|
||||||
Sell SellerPrice `json:"sell" gorm:"type:json;serializer:json"`
|
Sell SellerPrice `json:"sell" gorm:"type:json;serializer:json"`
|
||||||
// 历史出售价格
|
// 历史出售价格
|
||||||
|
Loading…
Reference in New Issue
Block a user