Commit 55cc1f2a authored by hujiebin's avatar hujiebin

Revert "feat:明细去掉bef/aft"

This reverts commit 653c7e69.
parent 653c7e69
...@@ -96,7 +96,8 @@ func TxAddReduceDiamondAccount(model *domain.Model, userId mysql.ID, operateType ...@@ -96,7 +96,8 @@ func TxAddReduceDiamondAccount(model *domain.Model, userId mysql.ID, operateType
if diamondAccount.Status == diamond_e.Frozen && diamondOperateSet.AddReduce == mysql.REDUCE { if diamondAccount.Status == diamond_e.Frozen && diamondOperateSet.AddReduce == mysql.REDUCE {
return fmt.Errorf("bizerr.DiamondAccountFrozen") return fmt.Errorf("bizerr.DiamondAccountFrozen")
} }
err = model.Transaction(func(model *domain.Model) error { return model.Transaction(func(model *domain.Model) error {
// 更新diamondAccount表 // 更新diamondAccount表
var db *gorm.DB var db *gorm.DB
if diamondOperateSet.AddReduce == mysql.ADD { if diamondOperateSet.AddReduce == mysql.ADD {
...@@ -122,50 +123,44 @@ func TxAddReduceDiamondAccount(model *domain.Model, userId mysql.ID, operateType ...@@ -122,50 +123,44 @@ func TxAddReduceDiamondAccount(model *domain.Model, userId mysql.ID, operateType
return myerr.NewWaring("gorm condition update.RowsAffected = 0") return myerr.NewWaring("gorm condition update.RowsAffected = 0")
} }
// 写后读(写后缓存都会丢失,多读一次不影响) // 写后读(写后缓存都会丢失,多读一次不影响)
//newAccount := new(diamond_m.DiamondAccount) newAccount := new(diamond_m.DiamondAccount)
//if err := model.DB().Model(diamond_m.DiamondAccount{}).Where("id = ?", diamondAccount.ID).First(newAccount).Error; err != nil { if err := model.DB().Model(diamond_m.DiamondAccount{}).Where("id = ?", diamondAccount.ID).First(newAccount).Error; err != nil {
// model.Log.Errorf("newAccount err:%v", err) model.Log.Errorf("newAccount err:%v", err)
// return err
//}
//if newAccount.DiamondNum < 0 {
// model.Log.Errorf("newAccount 0")
// return myerr.NewSysError("newAccount 0")
//}
for i, f := range extraTxFunc {
if err := f(); err != nil {
model.Log.Errorf("extraFunc i:%v fail:%v", i, err)
return err return err
} }
} if newAccount.DiamondNum < 0 {
return nil model.Log.Errorf("newAccount 0")
}) return myerr.NewSysError("newAccount 0")
if err != nil {
model.Log.Errorf("transaction fail:%v", err)
return err
} }
// 更新明细 // 更新明细
//befNum := mysql.Num(0) befNum := mysql.Num(0)
//if diamondOperateSet.AddReduce == mysql.ADD { if diamondOperateSet.AddReduce == mysql.ADD {
// befNum = newAccount.DiamondNum - diamondNum befNum = newAccount.DiamondNum - diamondNum
//} }
//if diamondOperateSet.AddReduce == mysql.REDUCE { if diamondOperateSet.AddReduce == mysql.REDUCE {
// befNum = newAccount.DiamondNum + diamondNum befNum = newAccount.DiamondNum + diamondNum
//} }
if err := model.DB().Table(diamond_m.DiamondAccountDetail{}.TableName()).Create(&diamond_m.DiamondAccountDetail{ if err := model.DB().Table(diamond_m.DiamondAccountDetail{}.TableName()).Create(&diamond_m.DiamondAccountDetail{
UserId: userId, UserId: userId,
DiamondAccountId: diamondAccount.ID, DiamondAccountId: newAccount.ID,
OperateId: diamondOperateSet.ID, OperateId: diamondOperateSet.ID,
OperateType: operateType, OperateType: operateType,
OriginId: originId, OriginId: originId,
AddReduce: diamondOperateSet.AddReduce, AddReduce: diamondOperateSet.AddReduce,
Num: diamondNum, Num: diamondNum,
Remark: diamondOperateSet.Name, Remark: diamondOperateSet.Name,
BefNum: 0, // 去掉 BefNum: befNum,
AftNum: 0, AftNum: newAccount.DiamondNum,
}).Error; err != nil { }).Error; err != nil {
model.Log.Errorf("add detail fail:%v", err) model.Log.Errorf("add detail fail:%v", err)
//return err return err
}
for i, f := range extraTxFunc {
if err := f(); err != nil {
model.Log.Errorf("extraFunc i:%v fail:%v", i, err)
return err
}
} }
return nil return 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