Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-common
Commits
653c7e69
Commit
653c7e69
authored
Aug 21, 2023
by
hujiebin
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:明细去掉bef/aft
parent
6b090bbb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
34 deletions
+39
-34
diamond.go
txop/diamond_tx/diamond.go
+39
-34
No files found.
txop/diamond_tx/diamond.go
View file @
653c7e69
...
@@ -96,8 +96,7 @@ func TxAddReduceDiamondAccount(model *domain.Model, userId mysql.ID, operateType
...
@@ -96,8 +96,7 @@ 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"
)
}
}
return
model
.
Transaction
(
func
(
model
*
domain
.
Model
)
error
{
err
=
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
{
...
@@ -123,44 +122,50 @@ func TxAddReduceDiamondAccount(model *domain.Model, userId mysql.ID, operateType
...
@@ -123,44 +122,50 @@ 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
{
model
.
Log
.
Errorf
(
"newAccount 0"
)
return
myerr
.
NewSysError
(
"newAccount 0"
)
}
}
// 更新明细
return
nil
befNum
:=
mysql
.
Num
(
0
)
})
if
diamondOperateSet
.
AddReduce
==
mysql
.
ADD
{
if
err
!=
nil
{
befNum
=
newAccount
.
DiamondNum
-
diamondNum
model
.
Log
.
Errorf
(
"transaction fail:%v"
,
err
)
}
return
err
if
diamondOperateSet
.
AddReduce
==
mysql
.
REDUCE
{
befNum
=
newAccount
.
DiamondNum
+
diamondNum
}
}
// 更新明细
//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
{
if
err
:=
model
.
DB
()
.
Table
(
diamond_m
.
DiamondAccountDetail
{}
.
TableName
())
.
Create
(
&
diamond_m
.
DiamondAccountDetail
{
UserId
:
userId
,
UserId
:
userId
,
DiamondAccountId
:
new
Account
.
ID
,
DiamondAccountId
:
diamond
Account
.
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
:
befNum
,
BefNum
:
0
,
// 去掉
AftNum
:
newAccount
.
DiamondNum
,
AftNum
:
0
,
})
.
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
})
}
}
hujiebin
@hujiebin
mentioned in commit
55cc1f2a
·
Aug 21, 2023
mentioned in commit
55cc1f2a
mentioned in commit 55cc1f2a67e64a581c97542c55812741d4cab561
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment