Commit 823c1edd authored by hujiebin's avatar hujiebin

feature/ondup

parent 11907ce1
...@@ -82,17 +82,28 @@ func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp mysql.N ...@@ -82,17 +82,28 @@ func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp mysql.N
return err return err
} }
// 增加家族经验-总 // 增加家族经验-总
gpg := &GroupPowerGrade{ gpg := new(GroupPowerGrade)
if err := txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId).First(gpg).Error; err != nil {
if err != gorm.ErrRecordNotFound {
return err
}
// gorm.ErrRecordNotFound
gpg = &GroupPowerGrade{
GroupPowerId: groupPowerId, GroupPowerId: groupPowerId,
Exp: exp, Exp: exp,
Grade: 0, Grade: 0,
ExpireAt: time.Time{}, ExpireAt: time.Time{},
} }
if err = txModel.DB().Model(GroupPowerGrade{}).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "group_power_id"}}, }
DoUpdates: clause.Assignments(map[string]interface{}{ if err := txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId).
"exp": gorm.Expr("exp + ?", gpg.Exp)})}).Create(gpg).Error; err != nil { UpdateColumn("exp", gorm.Expr("exp + ?", exp)).Error; err != nil {
return err return err
} }
//if err = txModel.DB().Model(GroupPowerGrade{}).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "group_power_id"}},
// DoUpdates: clause.Assignments(map[string]interface{}{
// "exp": gorm.Expr("exp + ?", gpg.Exp)})}).Create(gpg).Error; err != nil {
// return err
//}
// 当前写后读 // 当前写后读
latestGrade := new(GroupPowerGrade) latestGrade := new(GroupPowerGrade)
if err = txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId).First(latestGrade).Error; err != nil { if err = txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId).First(latestGrade).Error; err != nil {
......
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