Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-user
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
chenweijian
hilo-user
Commits
94e970a0
Commit
94e970a0
authored
Feb 23, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:调整路由
parent
681bf0f0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
4 deletions
+65
-4
user_bag.go
domain/model/bag_m/user_bag.go
+61
-1
router.go
route/router.go
+2
-1
inner.go
route/user_r/inner.go
+2
-2
No files found.
domain/model/bag_m/user_bag.go
View file @
94e970a0
...
...
@@ -3,6 +3,7 @@ package bag_m
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm/clause"
"hilo-user/_const/enum/res_e"
"time"
)
...
...
@@ -10,12 +11,25 @@ import (
type
UserBag
struct
{
mysql
.
Entity
UserId
mysql
.
ID
ResType
mysql
.
Type
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
}
// 获取用户有效的背包
// param userId 用户id
// param resType 背包类型 1:礼物
...
...
@@ -44,3 +58,49 @@ func GetUserBag(model *domain.Model, bagId mysql.ID) (*UserBag, error) {
}
return
res
,
nil
}
// 增加用户背包
// param userId 用户id
// param resType 道具类型
// param resId 道具id
// param count 增加数量
// param day 增加天数
// condition:
// 0.事务操作
// 1.背包表
// 2.明细表
func
AddUserBag
(
model
*
domain
.
Model
,
userId
mysql
.
ID
,
resType
mysql
.
Type
,
resId
mysql
.
ID
,
count
mysql
.
Num
,
day
int
,
reason
string
)
error
{
return
model
.
Transaction
(
func
(
model
*
domain
.
Model
)
error
{
// 1.背包表
endTime
:=
time
.
Now
()
.
AddDate
(
0
,
0
,
day
)
userBag
:=
&
UserBag
{
UserId
:
userId
,
ResType
:
resType
,
ResId
:
resId
,
Count
:
count
,
EndTime
:
endTime
,
}
if
err
:=
model
.
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
err
}
// 2.明细表
userBagDetail
:=
&
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
:=
model
.
DB
()
.
Create
(
userBagDetail
)
.
Error
;
err
!=
nil
{
return
err
}
return
nil
})
}
route/router.go
View file @
94e970a0
...
...
@@ -26,7 +26,8 @@ func InitRouter() *gin.Engine {
innerUser
:=
inner
.
Group
(
"/user"
)
{
innerUser
.
GET
(
"/levels"
,
wrapper
(
user_r
.
MGetUserLevels
))
innerUser
.
GET
(
"/bag"
,
wrapper
(
user_r
.
GetUserBag
))
innerUser
.
GET
(
"/bag/id"
,
wrapper
(
user_r
.
GetUserBagId
))
//innerUser.POST("/bag/send", wrapper(user_r.SendUserBag))
}
return
r
}
route/user_r/inner.go
View file @
94e970a0
...
...
@@ -55,8 +55,8 @@ type GetUserBagReq struct {
// @Summary 获取单个背包
// @Param bagId query int true "背包id"
// @Success 200 {object} user_cv.UserBag
// @Router /inner/user/bag [get]
func
GetUserBag
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
// @Router /inner/user/bag
/id
[get]
func
GetUserBag
Id
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myCtx
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
var
model
=
domain
.
CreateModelContext
(
myCtx
)
var
req
GetUserBagReq
...
...
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