feat 添加供应商和销售商状态

This commit is contained in:
timerzz 2024-08-30 13:59:01 +08:00
parent 56c30cfe59
commit cba02db8e8
4 changed files with 48 additions and 0 deletions

View File

@ -16,6 +16,7 @@ type ProviderApi interface {
List(query PageListQuery) (providers []v2.Provider, total int64, err error) List(query PageListQuery) (providers []v2.Provider, total int64, err error)
Create(provider v2.Provider) error Create(provider v2.Provider) error
Update(provider v2.Provider) error Update(provider v2.Provider) error
UpdateStatus(provider v2.Provider) error
Delete(id uint) (provider v2.Provider, err error) Delete(id uint) (provider v2.Provider, err error)
AutoMigrate() error AutoMigrate() error
} }
@ -97,6 +98,13 @@ func (p *providerApi) Update(provider v2.Provider) error {
}) })
} }
func (p *providerApi) UpdateStatus(provider v2.Provider) error {
if provider.ID == 0 {
return fmt.Errorf("id为空")
}
return p.db.Model(&provider).Where("id = ?", provider.ID).Select("status", "msg", "pull_at").Updates(&provider).Error
}
func (p *providerApi) Delete(id uint) (provider v2.Provider, err error) { func (p *providerApi) Delete(id uint) (provider v2.Provider, err error) {
err = p.db.Transaction(func(tx *gorm.DB) error { err = p.db.Transaction(func(tx *gorm.DB) error {
if err = tx.Where("owner_id = ? AND kind = ?", id, "provider").Delete(&v2.CalculateProcess{}).Error; err != nil { if err = tx.Where("owner_id = ? AND kind = ?", id, "provider").Delete(&v2.CalculateProcess{}).Error; err != nil {

View File

@ -16,6 +16,7 @@ type SellerApi interface {
List(query PageListQuery) (sellers []v2.Seller, total int64, err error) List(query PageListQuery) (sellers []v2.Seller, total int64, err error)
Create(seller v2.Seller) error Create(seller v2.Seller) error
Update(seller v2.Seller) error Update(seller v2.Seller) error
UpdateStatus(seller v2.Seller) error
Delete(id uint) (seller v2.Seller, err error) Delete(id uint) (seller v2.Seller, err error)
AutoMigrate() error AutoMigrate() error
} }
@ -97,6 +98,13 @@ func (p *sellerApi) Update(seller v2.Seller) error {
}) })
} }
func (p *sellerApi) UpdateStatus(seller v2.Seller) error {
if seller.ID == 0 {
return fmt.Errorf("id为空")
}
return p.db.Model(&seller).Where("id = ?", seller.ID).Select("status", "msg", "pull_at").Updates(&seller).Error
}
func (p *sellerApi) Delete(id uint) (seller v2.Seller, err error) { func (p *sellerApi) Delete(id uint) (seller v2.Seller, err error) {
err = p.db.Transaction(func(tx *gorm.DB) error { err = p.db.Transaction(func(tx *gorm.DB) error {
if err = tx.Where("owner_id = ? AND kind = ?", id, "seller").Delete(&v2.CalculateProcess{}).Error; err != nil { if err = tx.Where("owner_id = ? AND kind = ?", id, "seller").Delete(&v2.CalculateProcess{}).Error; err != nil {

View File

@ -4,6 +4,16 @@ import (
"time" "time"
) )
type ProviderStatus int
const (
ProviderStatus_Normal = iota
// 正在拉取供应商商品信息
ProviderStatus_Pulling
// 出错
ProviderStatus_Error
)
type ProviderId string type ProviderId string
type Provider struct { type Provider struct {
@ -14,6 +24,12 @@ type Provider struct {
ProviderId ProviderId `gorm:"unique" json:"providerId"` ProviderId ProviderId `gorm:"unique" json:"providerId"`
// 供应商的名称 // 供应商的名称
Name string `json:"name"` Name string `json:"name"`
// 供应商状态
Status ProviderStatus `json:"status"`
// 错误信息
Msg string `json:"msg"`
// 拉取时间
PullAt time.Time `json:"pullAt"`
// 供应商配置 // 供应商配置
Config ProviderOption `gorm:"type:json;serializer:json" json:"config"` Config ProviderOption `gorm:"type:json;serializer:json" json:"config"`
//计算过程 //计算过程

View File

@ -4,6 +4,16 @@ import (
"time" "time"
) )
type SellerStatus int
const (
SellerStatus_Normal = iota
// 正在拉取销售商商品信息
SellerStatus_Pulling
// 出错
SellerStatus_Error
)
type SellerId string type SellerId string
// Seller 出货商 // Seller 出货商
@ -15,6 +25,12 @@ type Seller struct {
SellerId SellerId `gorm:"unique" json:"sellerId"` SellerId SellerId `gorm:"unique" json:"sellerId"`
// 出货商的名称 // 出货商的名称
Name string `json:"name"` Name string `json:"name"`
// 供应商状态
Status SellerStatus `json:"status"`
// 错误信息
Msg string `json:"msg"`
// 拉取时间
PullAt time.Time `json:"pullAt"`
// 出货商配置 // 出货商配置
Config SellerOption `gorm:"type:json;serializer:json" json:"config"` Config SellerOption `gorm:"type:json;serializer:json" json:"config"`
//计算过程 //计算过程