@@ -81,7 +81,15 @@ func (m *defaultPromoModel) FindRule(ctx context.Context, id int64) (*Rule, erro
|
||||
}
|
||||
|
||||
func (m *defaultPromoModel) UpdateRule(ctx context.Context, data *Rule) error {
|
||||
return m.db.WithContext(ctx).Save(data).Error
|
||||
return m.db.WithContext(ctx).Model(&Rule{}).Where("id = ?", data.Id).Updates(map[string]interface{}{
|
||||
"name": data.Name,
|
||||
"type": data.Type,
|
||||
"params": data.Params,
|
||||
"priority": data.Priority,
|
||||
"enabled": data.Enabled,
|
||||
"start_time": data.StartTime,
|
||||
"end_time": data.EndTime,
|
||||
}).Error
|
||||
}
|
||||
|
||||
func (m *defaultPromoModel) DeleteRule(ctx context.Context, id int64) error {
|
||||
@@ -129,7 +137,10 @@ func (m *defaultPromoModel) UpsertPrices(ctx context.Context, ruleId int64, item
|
||||
return err
|
||||
}
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return tx.Create(item).Error
|
||||
if err := tx.Create(item).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
existing.Quantity = item.Quantity
|
||||
existing.PromoPrice = item.PromoPrice
|
||||
|
||||
@@ -33,7 +33,7 @@ func (Rule) TableName() string {
|
||||
type SubscribePromo struct {
|
||||
Id int64 `gorm:"primaryKey"`
|
||||
SubscribeId int64 `gorm:"type:bigint unsigned;not null;comment:Subscribe ID"`
|
||||
Quantity int64 `gorm:"type:bigint;not null;default:1;comment:Quantity"`
|
||||
Quantity int64 `gorm:"type:int;not null;default:0;comment:购买数量"`
|
||||
PromoRuleId int64 `gorm:"type:bigint unsigned;not null;comment:Promo Rule ID"`
|
||||
PromoPrice int64 `gorm:"type:bigint;not null;default:0;comment:Promo Price"`
|
||||
CreatedAt time.Time `gorm:"<-:create;comment:Create Time"`
|
||||
|
||||
Reference in New Issue
Block a user