update readme
This commit is contained in:
parent
844d3ce2be
commit
edd2470102
@ -23,13 +23,13 @@ DTM是首款golang的分布式事务管理器,优雅的解决了幂等、空
|
|||||||
+ XA
|
+ XA
|
||||||
|
|
||||||
### 文档与介绍(更新中)
|
### 文档与介绍(更新中)
|
||||||
* [DTM简介](https://zhuanlan.zhihu.com/p/386770520)
|
* [分布式事务简介](https://zhuanlan.zhihu.com/p/387487859)
|
||||||
* 分布式事务模式
|
* 分布式事务模式
|
||||||
- [XA事务模式](https://zhuanlan.zhihu.com/p/384756957)
|
- [XA事务模式](https://zhuanlan.zhihu.com/p/384756957)
|
||||||
- [SAGA事务模式](https://zhuanlan.zhihu.com/p/385594256)
|
- [SAGA事务模式](https://zhuanlan.zhihu.com/p/385594256)
|
||||||
- TCC事务模式
|
- [TCC事务模式](https://zhuanlan.zhihu.com/p/388357329)
|
||||||
- 可靠消息事务模式
|
- 可靠消息事务模式
|
||||||
* 子事务屏障
|
* [子事务屏障](https://zhuanlan.zhihu.com/p/388444465)
|
||||||
* FAQ
|
* FAQ
|
||||||
* 部署指南
|
* 部署指南
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/yedf/dtm/common"
|
"github.com/yedf/dtm/common"
|
||||||
"github.com/yedf/dtm/dtmcli"
|
"github.com/yedf/dtm/dtmcli"
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 事务参与者的服务地址
|
// 事务参与者的服务地址
|
||||||
@ -70,7 +69,7 @@ const transOutUid = 2
|
|||||||
|
|
||||||
func adjustTrading(sdb *sql.DB, uid int, amount int) (interface{}, error) {
|
func adjustTrading(sdb *sql.DB, uid int, amount int) (interface{}, error) {
|
||||||
db := common.SqlDB2DB(sdb)
|
db := common.SqlDB2DB(sdb)
|
||||||
dbr := db.Exec("update dtm_busi.user_account_trading t join dtm_busi.user_account a on t.user_id=a.user_id and t.user_id=? set t.trading_balance=t.trading_balance + ? where a.balance + t.trading_balance + ? > 0", uid, amount, amount)
|
dbr := db.Exec("update dtm_busi.user_account_trading t join dtm_busi.user_account a on t.user_id=a.user_id and t.user_id=? set t.trading_balance=t.trading_balance + ? where a.balance + t.trading_balance + ? >= 0", uid, amount, amount)
|
||||||
if dbr.Error == nil && dbr.RowsAffected == 0 {
|
if dbr.Error == nil && dbr.RowsAffected == 0 {
|
||||||
return nil, fmt.Errorf("update error, maybe balance not enough")
|
return nil, fmt.Errorf("update error, maybe balance not enough")
|
||||||
}
|
}
|
||||||
@ -79,15 +78,10 @@ func adjustTrading(sdb *sql.DB, uid int, amount int) (interface{}, error) {
|
|||||||
|
|
||||||
func adjustBalance(sdb *sql.DB, uid int, amount int) (interface{}, error) {
|
func adjustBalance(sdb *sql.DB, uid int, amount int) (interface{}, error) {
|
||||||
db := common.SqlDB2DB(sdb)
|
db := common.SqlDB2DB(sdb)
|
||||||
dbr := db.Exec("update dtm_busi.user_account_trading t join dtm_busi.user_account a on t.user_id=a.user_id and t.user_id=? set t.trading_balance=t.trading_balance + ? where a.balance + t.trading_balance + ? > 0", uid, -amount, -amount)
|
dbr := db.Exec("update dtm_busi.user_account_trading t join dtm_busi.user_account a on t.user_id=a.user_id and t.user_id=? set t.trading_balance=t.trading_balance + ?", uid, -amount, -amount)
|
||||||
if dbr.Error != nil {
|
if dbr.Error == nil && dbr.RowsAffected == 1 {
|
||||||
return nil, dbr.Error
|
dbr = db.Exec("update dtm_busi.user_account set balance=balance+? where user_id=?", amount, uid)
|
||||||
}
|
}
|
||||||
if dbr.RowsAffected == 0 {
|
|
||||||
return nil, fmt.Errorf("update trading error")
|
|
||||||
}
|
|
||||||
dbr = db.Model(&UserAccount{}).Where("user_id = ?", uid).
|
|
||||||
Update("balance", gorm.Expr("balance + ?", amount))
|
|
||||||
if dbr.Error != nil {
|
if dbr.Error != nil {
|
||||||
return nil, dbr.Error
|
return nil, dbr.Error
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user