aa
This commit is contained in:
@@ -151,8 +151,8 @@ func GetActStoreSkuVendorList(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs
|
||||
// globals.SugarLogger.Debug(sql)
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(actStoreSkuList, false))
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRows(db, &actStoreSkuList, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCount(db)
|
||||
}
|
||||
@@ -292,20 +292,20 @@ func QueryActs(db *DaoDB, actID int, offset, pageSize int, syncStatus int, keywo
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
var idList []int
|
||||
|
||||
Begin(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
Rollback(db)
|
||||
Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
// globals.SugarLogger.Debug(sql)
|
||||
if err = GetRows(db, &idList, sql, sqlParams...); err != nil || len(idList) == 0 {
|
||||
Rollback(db)
|
||||
Rollback(db, txDB)
|
||||
return pagedInfo, err
|
||||
}
|
||||
pagedInfo.TotalCount = GetLastTotalRowCount(db)
|
||||
Commit(db)
|
||||
Commit(db, txDB)
|
||||
|
||||
sql = `
|
||||
SELECT
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/astaxie/beego/adapter/orm"
|
||||
"github.com/astaxie/beego/client/orm"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -65,15 +65,15 @@ func GetDB() *DaoDB {
|
||||
return &DaoDB{Db: orm.NewOrm()}
|
||||
}
|
||||
|
||||
func Begin(db *DaoDB) (err error) {
|
||||
func Begin(db *DaoDB) (txDB orm.TxOrmer, err error) {
|
||||
if db.transactionLevel == 0 {
|
||||
err = db.Db.Begin()
|
||||
txDB, err = db.Db.Begin()
|
||||
if err == nil {
|
||||
db.startWatchTransaction()
|
||||
}
|
||||
}
|
||||
db.transactionLevel++
|
||||
return err
|
||||
return txDB, err
|
||||
}
|
||||
|
||||
func (db *DaoDB) startWatchTransaction() {
|
||||
@@ -93,11 +93,11 @@ func (db *DaoDB) stopWatchTransaction() {
|
||||
}
|
||||
}
|
||||
|
||||
func Commit(db *DaoDB) (err error) {
|
||||
func Commit(db *DaoDB, txDB orm.TxOrmer) (err error) {
|
||||
if db.transactionLevel == 1 {
|
||||
db.stopWatchTransaction()
|
||||
|
||||
err = db.Db.Commit()
|
||||
err = txDB.Commit()
|
||||
// err = db.Db.Commit()
|
||||
db.transactionLevel = 0
|
||||
} else if db.transactionLevel > 1 {
|
||||
db.transactionLevel--
|
||||
@@ -105,11 +105,11 @@ func Commit(db *DaoDB) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func Rollback(db *DaoDB) (err error) {
|
||||
func Rollback(db *DaoDB, txDB orm.TxOrmer) (err error) {
|
||||
if db.transactionLevel > 0 {
|
||||
db.stopWatchTransaction()
|
||||
|
||||
err = db.Db.Rollback()
|
||||
err = txDB.Rollback()
|
||||
// err = db.Db.Rollback()
|
||||
}
|
||||
db.transactionLevel = 0
|
||||
return err
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/adapter/orm"
|
||||
"github.com/astaxie/beego/client/orm"
|
||||
"github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
|
||||
@@ -969,8 +969,8 @@ func GetOrders(db *DaoDB, ids []int64, isIncludeSku, isIncludeFake bool, fromDat
|
||||
LIMIT ? OFFSET ?`
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRows(db, &orders, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCount(db)
|
||||
}
|
||||
@@ -1154,8 +1154,8 @@ func GetOrdersSupplement(db *DaoDB, storIDs, vendorIDs, statuss []int, vendorOrd
|
||||
sql += " ORDER BY supplement_time DESC"
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRows(db, &orderSupplementFee, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCount(db)
|
||||
}
|
||||
@@ -1347,8 +1347,8 @@ func GetAfsOrdersByPage(db *DaoDB, vendorOrderID, afsOrderID, userID string, fro
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRows(db, &afsOrderList, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCount(db)
|
||||
}
|
||||
|
||||
@@ -94,8 +94,8 @@ func GetUsers(db *DaoDB, userType int, keyword string, userIDs, userID2s, mobile
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRows(db, &userList, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCount(db)
|
||||
}
|
||||
@@ -211,8 +211,8 @@ func QueryUserDeliveryAddress(db *DaoDB, addressID int64, userIDs []string, offs
|
||||
LIMIT ? OFFSET ?`
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRows(db, &addressList, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCount(db)
|
||||
}
|
||||
|
||||
@@ -108,8 +108,8 @@ func GetOperateEvents(db *DaoDB, name string, apiFunctions []string, operateType
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRows(db, &operateEventExt, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCount(db)
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@ func QueryFoodRecipes(db *DaoDB, keyword string, recipeID int, authorID, userID
|
||||
LIMIT ? OFFSET ?`
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRows(db, &recipeList, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCount(db)
|
||||
}
|
||||
|
||||
@@ -81,10 +81,10 @@ func QueryPageStores(db *DaoDB, pageSize, offset int, keyword string, vendorStor
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
var shopList []*PageShopWithPlaceName
|
||||
Begin(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
Rollback(db)
|
||||
Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
@@ -93,9 +93,9 @@ func QueryPageStores(db *DaoDB, pageSize, offset int, keyword string, vendorStor
|
||||
TotalCount: GetLastTotalRowCount(db),
|
||||
Data: shopList,
|
||||
}
|
||||
Commit(db)
|
||||
Commit(db, txDB)
|
||||
} else {
|
||||
Rollback(db)
|
||||
Rollback(db, txDB)
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"github.com/astaxie/beego/adapter/orm"
|
||||
"github.com/astaxie/beego/client/orm"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -317,8 +317,8 @@ func GetPriceReferSnapshot(db *DaoDB, cityCodes, skuIDs []int, skuNameID int, sn
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRows(db, &priceReferSnapshot, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCount(db)
|
||||
}
|
||||
|
||||
@@ -405,10 +405,10 @@ func FormalizeStoreStatus(db *DaoDB, storeID, storeStatus int) (err error) {
|
||||
if err = GetRows(db, &statusList, sql, sqlParams...); err == nil {
|
||||
if len(statusList) == 1 {
|
||||
if statusList[0] != model.StoreStatusOpened {
|
||||
Begin(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
Rollback(db)
|
||||
Rollback(db, txDB)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
@@ -431,7 +431,7 @@ func FormalizeStoreStatus(db *DaoDB, storeID, storeStatus int) (err error) {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
Commit(db)
|
||||
Commit(db, txDB)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -712,8 +712,8 @@ func GetStorePriceScore(db *DaoDB, storeIDs, vendorIDs []int, fromScore, toScore
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRows(db, &StorePriceScore, sql, sqlParams...); err == nil {
|
||||
totalCount = GetLastTotalRowCount(db)
|
||||
}
|
||||
@@ -979,8 +979,8 @@ func GetStoreAuditPage(db *DaoDB, statuss []int, keyword string, applyTimeStart,
|
||||
sql += " ORDER BY a.updated_at LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRows(db, &requestList, sql, sqlParams...); err == nil {
|
||||
return &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCount(db),
|
||||
@@ -1241,8 +1241,8 @@ func GetStoreManageState(db *DaoDB, storeIDs, brandIDs []int, vendorID, sortType
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRows(db, &requestList, sql, sqlParams...); err == nil {
|
||||
return &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCount(db),
|
||||
|
||||
@@ -1707,8 +1707,8 @@ func GetStoreSkuAudit(db *DaoDB, storeIDs, nameIDs, skuIDs, statuss, types []int
|
||||
sql += " ORDER BY a.updated_at LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
Begin(db)
|
||||
defer Commit(db)
|
||||
txDB, _ := Begin(db)
|
||||
defer Commit(db, txDB)
|
||||
if err = GetRows(db, &requestList, sql, sqlParams...); err == nil {
|
||||
return &model.PagedInfo{
|
||||
TotalCount: GetLastTotalRowCount(db),
|
||||
|
||||
Reference in New Issue
Block a user