diff --git a/domain/model/groupPower_m/group_grade.go b/domain/model/groupPower_m/group_grade.go index d65a403e78a832b070c25e34e1d0b17a9e151ffe..2a719327e7739e378d192973bdc70091a85948ff 100644 --- a/domain/model/groupPower_m/group_grade.go +++ b/domain/model/groupPower_m/group_grade.go @@ -83,6 +83,7 @@ func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp mysql.N } // 增加家族经验-总 gpg := new(GroupPowerGrade) + // insert if err := txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId).First(gpg).Error; err != nil { if err != gorm.ErrRecordNotFound { return err @@ -97,10 +98,12 @@ func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp mysql.N if err = txModel.DB().Create(gpg).Error; err != nil { return err } - } - if err := txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId). - UpdateColumn("exp", gorm.Expr("exp + ?", exp)).Error; err != nil { - return err + } else { + // or update + if err := txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId). + UpdateColumn("exp", gorm.Expr("exp + ?", exp)).Error; err != nil { + return err + } } //if err = txModel.DB().Model(GroupPowerGrade{}).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "group_power_id"}}, // DoUpdates: clause.Assignments(map[string]interface{}{