Commit 9d77177e authored by hujiebin's avatar hujiebin

insert or update

parent 7ae23437
...@@ -83,6 +83,7 @@ func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp mysql.N ...@@ -83,6 +83,7 @@ func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp mysql.N
} }
// 增加家族经验-总 // 增加家族经验-总
gpg := new(GroupPowerGrade) gpg := new(GroupPowerGrade)
// insert
if err := txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId).First(gpg).Error; err != nil { if err := txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId).First(gpg).Error; err != nil {
if err != gorm.ErrRecordNotFound { if err != gorm.ErrRecordNotFound {
return err return err
...@@ -97,10 +98,12 @@ func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp mysql.N ...@@ -97,10 +98,12 @@ func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp mysql.N
if err = txModel.DB().Create(gpg).Error; err != nil { if err = txModel.DB().Create(gpg).Error; err != nil {
return err return err
} }
} } else {
if err := txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId). // or update
UpdateColumn("exp", gorm.Expr("exp + ?", exp)).Error; err != nil { if err := txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId).
return err 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"}}, //if err = txModel.DB().Model(GroupPowerGrade{}).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "group_power_id"}},
// DoUpdates: clause.Assignments(map[string]interface{}{ // DoUpdates: clause.Assignments(map[string]interface{}{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment