Commit 3dc771e0 authored by hujiebin's avatar hujiebin

feat:去掉bft/aft,少了一次读操作。

parent 55cc1f2a
......@@ -123,34 +123,34 @@ func TxAddReduceDiamondAccount(model *domain.Model, userId mysql.ID, operateType
return myerr.NewWaring("gorm condition update.RowsAffected = 0")
}
// 写后读(写后缓存都会丢失,多读一次不影响)
newAccount := new(diamond_m.DiamondAccount)
if err := model.DB().Model(diamond_m.DiamondAccount{}).Where("id = ?", diamondAccount.ID).First(newAccount).Error; err != nil {
model.Log.Errorf("newAccount err:%v", err)
return err
}
if newAccount.DiamondNum < 0 {
model.Log.Errorf("newAccount 0")
return myerr.NewSysError("newAccount 0")
}
// 更新明细
befNum := mysql.Num(0)
if diamondOperateSet.AddReduce == mysql.ADD {
befNum = newAccount.DiamondNum - diamondNum
}
if diamondOperateSet.AddReduce == mysql.REDUCE {
befNum = newAccount.DiamondNum + diamondNum
}
//newAccount := new(diamond_m.DiamondAccount)
//if err := model.DB().Model(diamond_m.DiamondAccount{}).Where("id = ?", diamondAccount.ID).First(newAccount).Error; err != nil {
// model.Log.Errorf("newAccount err:%v", err)
// return err
//}
//if newAccount.DiamondNum < 0 {
// model.Log.Errorf("newAccount 0")
// return myerr.NewSysError("newAccount 0")
//}
//// 更新明细
//befNum := mysql.Num(0)
//if diamondOperateSet.AddReduce == mysql.ADD {
// befNum = newAccount.DiamondNum - diamondNum
//}
//if diamondOperateSet.AddReduce == mysql.REDUCE {
// befNum = newAccount.DiamondNum + diamondNum
//}
if err := model.DB().Table(diamond_m.DiamondAccountDetail{}.TableName()).Create(&diamond_m.DiamondAccountDetail{
UserId: userId,
DiamondAccountId: newAccount.ID,
DiamondAccountId: diamondAccount.ID,
OperateId: diamondOperateSet.ID,
OperateType: operateType,
OriginId: originId,
AddReduce: diamondOperateSet.AddReduce,
Num: diamondNum,
Remark: diamondOperateSet.Name,
BefNum: befNum,
AftNum: newAccount.DiamondNum,
BefNum: 0,
AftNum: 0,
}).Error; err != nil {
model.Log.Errorf("add detail fail:%v", err)
return err
......
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