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
595cf7be
Commit
595cf7be
authored
Mar 21, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:多加bag_tx
parent
16a0be42
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
158 additions
and
0 deletions
+158
-0
user_bag.go
internal/model/bag_m/user_bag.go
+28
-0
gift.go
internal/model/res_m/gift.go
+47
-0
user_bag.go
txop/bag_tx/user_bag.go
+83
-0
No files found.
internal/model/bag_m/user_bag.go
0 → 100644
View file @
595cf7be
package
bag_m
import
(
"git.hilo.cn/hilo-common/resource/mysql"
"time"
)
type
UserBag
struct
{
mysql
.
Entity
UserId
mysql
.
ID
ResType
mysql
.
Type
// 资源类型 1:礼物
ResId
mysql
.
ID
Count
mysql
.
Num
EndTime
time
.
Time
}
type
UserBagDetail
struct
{
mysql
.
Entity
UserId
mysql
.
ID
BagId
mysql
.
ID
ResType
mysql
.
Type
// 资源类型 1:礼物
ResId
mysql
.
ID
Count
mysql
.
Num
AddReduce
mysql
.
AddReduce
BefNum
mysql
.
Num
AftNum
mysql
.
Num
Remark
mysql
.
Str
}
\ No newline at end of file
internal/model/res_m/gift.go
0 → 100644
View file @
595cf7be
package
res_m
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
)
type
ResGift
struct
{
mysql
.
Entity
Name
mysql
.
Str
IconUrl
mysql
.
Str
SvagUrl
mysql
.
Str
MusicUrl
mysql
.
Str
Column
uint16
DiamondNum
mysql
.
Num
BeanNum
mysql
.
Num
ReceiveDiamondNum
mysql
.
Num
Second
mysql
.
Num
// obsolete
N
mysql
.
Num
GroupBroadcast
bool
Cp
bool
Together
bool
Status
mysql
.
UserYesNo
GiftType
mysql
.
Type
}
// 获取所有的礼物
func
FindAllResGiftsMap
(
model
*
domain
.
Model
)
(
map
[
mysql
.
ID
]
ResGift
,
error
)
{
res
:=
make
(
map
[
mysql
.
ID
]
ResGift
,
0
)
rows
:=
make
([]
ResGift
,
0
)
if
err
:=
model
.
DB
()
.
Model
(
ResGift
{})
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
for
i
,
v
:=
range
rows
{
res
[
v
.
ID
]
=
rows
[
i
]
}
return
res
,
nil
}
// 获取礼物
func
FindResGift
(
model
*
domain
.
Model
,
giftId
mysql
.
ID
)
(
*
ResGift
,
error
)
{
res
:=
new
(
ResGift
)
if
err
:=
model
.
DB
()
.
Model
(
ResGift
{})
.
Where
(
"id = ?"
,
giftId
)
.
First
(
res
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
return
res
,
nil
}
txop/bag_tx/user_bag.go
0 → 100644
View file @
595cf7be
package
bag_tx
import
(
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/internal/enum/msg_e"
"git.hilo.cn/hilo-common/internal/model/bag_m"
"git.hilo.cn/hilo-common/internal/model/msg_m"
"git.hilo.cn/hilo-common/internal/model/res_m"
"git.hilo.cn/hilo-common/internal/model/user_m"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm/clause"
"time"
)
// 增加用户背包
// param userId 用户id
// param resType 道具类型
// param resId 道具id
// param count 增加数量
// param day 增加天数
// condition:
// 0.事务操作,依赖外面传进来的model
// 1.背包表
// 2.明细表
// return bagId
func
SendUserBag
(
txModel
*
domain
.
Model
,
userId
mysql
.
ID
,
resType
mysql
.
Type
,
resId
mysql
.
ID
,
count
mysql
.
Num
,
day
int
,
reason
string
)
(
mysql
.
ID
,
error
)
{
var
bagId
mysql
.
ID
// 1.背包表
endTime
:=
time
.
Now
()
.
AddDate
(
0
,
0
,
day
)
userBag
:=
&
bag_m
.
UserBag
{
UserId
:
userId
,
ResType
:
resType
,
ResId
:
resId
,
Count
:
count
,
EndTime
:
endTime
,
}
if
err
:=
txModel
.
DB
()
.
Clauses
(
clause
.
OnConflict
{
Columns
:
[]
clause
.
Column
{{
Name
:
"user_id"
},
{
Name
:
"res_type"
},
{
Name
:
"res_id"
},
{
Name
:
"end_time"
}},
DoUpdates
:
clause
.
AssignmentColumns
([]
string
{
"count"
}),
})
.
Create
(
userBag
)
.
Error
;
err
!=
nil
{
return
0
,
err
}
bagId
=
userBag
.
ID
// 自增id
// 2.明细表
userBagDetail
:=
&
bag_m
.
UserBagDetail
{
UserId
:
userId
,
BagId
:
userBag
.
ID
,
ResType
:
resType
,
ResId
:
resId
,
Count
:
count
,
AddReduce
:
mysql
.
ADD
,
BefNum
:
0
,
// 加背包的统一为0
AftNum
:
count
,
// 加背包统一为count,因为每次加几乎不可能是一样的
Remark
:
reason
,
}
if
err
:=
txModel
.
DB
()
.
Create
(
userBagDetail
)
.
Error
;
err
!=
nil
{
return
0
,
err
}
// 小助手通知
go
func
()
{
model
:=
domain
.
CreateModelContext
(
txModel
.
MyContext
)
user
,
err
:=
user_m
.
GetUser
(
model
,
userId
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"user_m.GetUser fail:%v"
,
err
)
return
}
gift
,
err
:=
res_m
.
FindResGift
(
model
,
resId
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"res_m.FindResGift fail:%v"
,
err
)
}
if
err
:=
msg_m
.
NewUserRecord
(
model
,
userId
,
msg_e
.
AddUserBag
,
gift
.
Name
,
0
,
""
,
fmt
.
Sprintf
(
"%d"
,
day
),
""
,
""
,
""
)
.
Persistent
();
err
!=
nil
{
model
.
Log
.
Errorf
(
"NewUserRecord fail"
)
}
else
{
if
err
:=
msg_m
.
SendEmasMsgAssistant
(
model
,
user
.
ExternalId
,
user
.
DeviceType
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"SendEmasMsgAssistant fail:%v"
,
err
)
}
}
}()
return
bagId
,
nil
}
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