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
718e349d
Commit
718e349d
authored
May 26, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:cp特权开关
parent
c05927f8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
131 additions
and
55 deletions
+131
-55
level.go
_const/enum/cp_e/level.go
+9
-9
space.go
cv/cp_cv/space.go
+22
-44
privilege.go
domain/model/cp_m/privilege.go
+55
-0
space.go
route/cp_r/space.go
+44
-2
router.go
route/router.go
+1
-0
No files found.
_const/enum/cp_e/level.go
View file @
718e349d
...
...
@@ -29,6 +29,15 @@ var (
CpLevel4
:
3000000
,
CpLevel5
:
10000000
,
}
// cp等级icon // todo ui
CpLevelIcon
=
map
[
CpLevel
]
string
{
CpLevel0
:
"icon0.png"
,
CpLevel1
:
"icon1.png"
,
CpLevel2
:
"icon2.png"
,
CpLevel3
:
"icon3.png"
,
CpLevel4
:
"icon4.png"
,
CpLevel5
:
"icon5.png"
,
}
// cp特权名称 // todo 翻译
CpPrivilegeNameMsgId
=
map
[
CpPrivilege
]
uint
{
CpPrivilegeSpace
:
0
,
...
...
@@ -40,15 +49,6 @@ var (
CpPrivilegeActiveProfile
:
0
,
CpPrivilegeMicEffect
:
0
,
}
// cp等级icon // todo ui
CpLevelIcon
=
map
[
CpLevel
]
string
{
CpLevel0
:
"icon0.png"
,
CpLevel1
:
"icon1.png"
,
CpLevel2
:
"icon2.png"
,
CpLevel3
:
"icon3.png"
,
CpLevel4
:
"icon4.png"
,
CpLevel5
:
"icon5.png"
,
}
// cp特权icon // todo ui
CpPrivilegeIcon
=
map
[
CpPrivilege
]
string
{
CpPrivilegeSpace
:
"icon_p_1.png"
,
...
...
cv/cp_cv/space.go
View file @
718e349d
...
...
@@ -35,10 +35,12 @@ type CvResLevel struct {
// 特权信息
type
CvPrivilege
struct
{
Type
cp_e
.
CpPrivilege
`json:"type"`
// 特权id 1:空间 2:横幅 3:等级勋章 4:证书 5:进场特效 6:头像头饰 7:动态资料卡 8:麦位特效
NameMsgId
uint
`json:"-"`
// 名称-翻译id
Name
string
`json:"name"`
// 名称
Icon
string
`json:"icon"`
// 图标
Type
cp_e
.
CpPrivilege
`json:"type"`
// 特权id 1:空间 2:横幅 3:等级勋章 4:证书 5:进场特效 6:头像头饰 7:动态资料卡 8:麦位特效
NameMsgId
uint
`json:"-"`
// 名称-翻译id
Name
string
`json:"name"`
// 名称
Icon
string
`json:"icon"`
// 图标
CanSwitch
bool
`json:"canSwitch"`
// 能否开关
UserSwitch
bool
`json:"userSwitch"`
// 用户开关
}
// cp空间页
...
...
@@ -58,48 +60,24 @@ var CvResLevelList = []CvResLevel{
{
cp_e
.
CpLevel5
,
cp_e
.
CpLevelIcon
[
cp_e
.
CpLevel5
]},
}
var
(
CvPrivilege1
=
CvPrivilege
{
cp_e
.
CpPrivilegeSpace
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeSpace
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeSpace
],
false
,
false
}
CvPrivilege2
=
CvPrivilege
{
cp_e
.
CpPrivilegeBanner
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeBanner
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeBanner
],
false
,
false
}
CvPrivilege3
=
CvPrivilege
{
cp_e
.
CpPrivilegeMedal
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeMedal
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeMedal
],
false
,
false
}
CvPrivilege4
=
CvPrivilege
{
cp_e
.
CpPrivilegeCert
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeCert
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeCert
],
false
,
false
}
CvPrivilege5
=
CvPrivilege
{
cp_e
.
CpPrivilegeRoomEffect
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeRoomEffect
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeRoomEffect
],
true
,
false
}
CvPrivilege6
=
CvPrivilege
{
cp_e
.
CpPrivilegeHeadwear
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeHeadwear
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeHeadwear
],
false
,
false
}
CvPrivilege7
=
CvPrivilege
{
cp_e
.
CpPrivilegeActiveProfile
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeActiveProfile
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeActiveProfile
],
true
,
false
}
CvPrivilege8
=
CvPrivilege
{
cp_e
.
CpPrivilegeMicEffect
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeMicEffect
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeMicEffect
],
false
,
false
}
)
var
CpLevelPrivilegeList
=
map
[
cp_e
.
CpLevel
][]
CvPrivilege
{
cp_e
.
CpLevel0
:
{},
cp_e
.
CpLevel1
:
{
{
cp_e
.
CpPrivilegeSpace
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeSpace
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeSpace
]},
{
cp_e
.
CpPrivilegeBanner
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeBanner
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeBanner
]},
{
cp_e
.
CpPrivilegeMedal
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeMedal
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeMedal
]},
{
cp_e
.
CpPrivilegeCert
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeCert
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeCert
]},
},
cp_e
.
CpLevel2
:
{
{
cp_e
.
CpPrivilegeSpace
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeSpace
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeSpace
]},
{
cp_e
.
CpPrivilegeBanner
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeBanner
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeBanner
]},
{
cp_e
.
CpPrivilegeMedal
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeMedal
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeMedal
]},
{
cp_e
.
CpPrivilegeCert
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeCert
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeCert
]},
{
cp_e
.
CpPrivilegeRoomEffect
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeRoomEffect
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeRoomEffect
]},
},
cp_e
.
CpLevel3
:
{
{
cp_e
.
CpPrivilegeSpace
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeSpace
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeSpace
]},
{
cp_e
.
CpPrivilegeBanner
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeBanner
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeBanner
]},
{
cp_e
.
CpPrivilegeMedal
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeMedal
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeMedal
]},
{
cp_e
.
CpPrivilegeCert
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeCert
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeCert
]},
{
cp_e
.
CpPrivilegeRoomEffect
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeRoomEffect
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeRoomEffect
]},
{
cp_e
.
CpPrivilegeHeadwear
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeHeadwear
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeHeadwear
]},
},
cp_e
.
CpLevel4
:
{
{
cp_e
.
CpPrivilegeSpace
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeSpace
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeSpace
]},
{
cp_e
.
CpPrivilegeBanner
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeBanner
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeBanner
]},
{
cp_e
.
CpPrivilegeMedal
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeMedal
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeMedal
]},
{
cp_e
.
CpPrivilegeCert
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeCert
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeCert
]},
{
cp_e
.
CpPrivilegeRoomEffect
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeRoomEffect
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeRoomEffect
]},
{
cp_e
.
CpPrivilegeHeadwear
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeHeadwear
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeHeadwear
]},
{
cp_e
.
CpPrivilegeActiveProfile
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeActiveProfile
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeActiveProfile
]},
},
cp_e
.
CpLevel5
:
{
{
cp_e
.
CpPrivilegeSpace
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeSpace
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeSpace
]},
{
cp_e
.
CpPrivilegeBanner
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeBanner
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeBanner
]},
{
cp_e
.
CpPrivilegeMedal
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeMedal
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeMedal
]},
{
cp_e
.
CpPrivilegeCert
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeCert
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeCert
]},
{
cp_e
.
CpPrivilegeRoomEffect
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeRoomEffect
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeRoomEffect
]},
{
cp_e
.
CpPrivilegeHeadwear
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeHeadwear
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeHeadwear
]},
{
cp_e
.
CpPrivilegeActiveProfile
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeActiveProfile
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeActiveProfile
]},
{
cp_e
.
CpPrivilegeMicEffect
,
cp_e
.
CpPrivilegeNameMsgId
[
cp_e
.
CpPrivilegeMicEffect
],
""
,
cp_e
.
CpPrivilegeIcon
[
cp_e
.
CpPrivilegeMicEffect
]},
},
cp_e
.
CpLevel1
:
{
CvPrivilege1
,
CvPrivilege2
,
CvPrivilege3
,
CvPrivilege4
},
cp_e
.
CpLevel2
:
{
CvPrivilege1
,
CvPrivilege2
,
CvPrivilege3
,
CvPrivilege4
,
CvPrivilege5
},
cp_e
.
CpLevel3
:
{
CvPrivilege1
,
CvPrivilege2
,
CvPrivilege3
,
CvPrivilege4
,
CvPrivilege5
,
CvPrivilege6
},
cp_e
.
CpLevel4
:
{
CvPrivilege1
,
CvPrivilege2
,
CvPrivilege3
,
CvPrivilege4
,
CvPrivilege5
,
CvPrivilege6
,
CvPrivilege7
},
cp_e
.
CpLevel5
:
{
CvPrivilege1
,
CvPrivilege2
,
CvPrivilege3
,
CvPrivilege4
,
CvPrivilege5
,
CvPrivilege6
,
CvPrivilege7
,
CvPrivilege8
},
}
func
CopyCpLevelPrivilegeList
(
Level
cp_e
.
CpLevel
,
lang
string
)
[]
CvPrivilege
{
...
...
domain/model/cp_m/privilege.go
0 → 100644
View file @
718e349d
package
cp_m
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"hilo-user/_const/enum/cp_e"
)
// svip特权
type
CpPrivilege
struct
{
mysql
.
Entity
UserId
mysql
.
ID
Type
cp_e
.
CpPrivilege
OpenClose
mysql
.
OpenClose
}
// 开关用于svip特权
func
OpenCLoseUserSvipPrivilege
(
model
*
domain
.
Model
,
userId
mysql
.
ID
,
Type
cp_e
.
CpPrivilege
,
openClose
mysql
.
OpenClose
)
error
{
var
pri
CpPrivilege
if
err
:=
model
.
DB
()
.
Model
(
CpPrivilege
{})
.
Where
(
"user_id = ? AND `type` = ?"
,
userId
,
Type
)
.
First
(
&
pri
)
.
Error
;
err
!=
nil
{
if
err
!=
gorm
.
ErrRecordNotFound
{
return
err
}
// record not found
return
model
.
DB
()
.
Create
(
&
CpPrivilege
{
UserId
:
userId
,
Type
:
Type
,
OpenClose
:
openClose
,
})
.
Error
}
// update
return
model
.
DB
()
.
Model
(
CpPrivilege
{})
.
Where
(
"user_id = ? AND `type` = ?"
,
userId
,
Type
)
.
UpdateColumn
(
"open_close"
,
openClose
)
.
Error
}
// 批量获取用户svip特权开关
// map userId->type->open
func
MGetUserSvipPrivilege
(
model
*
domain
.
Model
,
userIds
[]
mysql
.
ID
)
(
map
[
mysql
.
ID
]
map
[
cp_e
.
CpPrivilege
]
bool
,
error
)
{
res
:=
make
(
map
[
mysql
.
ID
]
map
[
cp_e
.
CpPrivilege
]
bool
)
var
privileges
[]
CpPrivilege
if
err
:=
model
.
DB
()
.
Model
(
CpPrivilege
{})
.
Where
(
"user_id in ? AND open_close = ?"
,
userIds
,
mysql
.
OPEN
)
.
Find
(
&
privileges
)
.
Error
;
err
!=
nil
{
return
res
,
err
}
for
_
,
v
:=
range
privileges
{
if
data
,
ok
:=
res
[
v
.
UserId
];
ok
{
data
[
v
.
Type
]
=
true
}
else
{
res
[
v
.
UserId
]
=
make
(
map
[
cp_e
.
CpPrivilege
]
bool
)
res
[
v
.
UserId
][
v
.
Type
]
=
true
}
}
return
res
,
nil
}
route/cp_r/space.go
View file @
718e349d
...
...
@@ -8,6 +8,7 @@ import (
"hilo-user/_const/enum/cp_e"
"hilo-user/cv/cp_cv"
"hilo-user/cv/user_cv"
"hilo-user/domain/model/cp_m"
"hilo-user/domain/model/user_m"
"hilo-user/myerr/bizerr"
"hilo-user/req"
...
...
@@ -41,13 +42,23 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) {
return
myContext
,
err
}
expireAt
:=
""
// todo
cpLevel
:=
cp_e
.
CpLevel
3
// todo get from db
cpLevel
:=
cp_e
.
CpLevel
5
// todo get from db
nextPoints
:=
cp_e
.
CpLevelPoints
[
cp_e
.
CpLevelMax
]
remainPoints
:=
mysql
.
Num
(
0
)
if
cpLevel
!=
cp_e
.
CpLevelMax
{
nextPoints
=
cp_e
.
CpLevelPoints
[
cpLevel
+
1
]
remainPoints
=
nextPoints
-
cp_e
.
CpLevelPoints
[
cpLevel
]
// todo get from db
}
privilegeList
:=
cp_cv
.
CopyCpLevelPrivilegeList
(
cpLevel
,
lang
)
userPrivileges
,
err
:=
cp_m
.
MGetUserSvipPrivilege
(
model
,
[]
uint64
{
userId
})
if
err
!=
nil
{
return
myContext
,
err
}
for
i
,
v
:=
range
privilegeList
{
if
v
.
CanSwitch
{
privilegeList
[
i
]
.
UserSwitch
=
userPrivileges
[
userId
][
v
.
Type
]
}
}
response
:=
cp_cv
.
CvSpace
{
CpInfo
:
cp_cv
.
CvCpInfo
{
UserInfo
:
user_cv
.
UserToTiny
(
*
userInfo
),
...
...
@@ -61,8 +72,39 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) {
ExpireAt
:
expireAt
,
},
ResLevelList
:
cp_cv
.
CvResLevelList
,
PrivilegeList
:
cp_cv
.
CopyCpLevelPrivilegeList
(
cpLevel
,
lang
)
,
PrivilegeList
:
privilegeList
,
}
resp
.
ResponseOk
(
c
,
response
)
return
myContext
,
nil
}
type
CpPrivilegeOpenCloseReq
struct
{
Type
cp_e
.
CpPrivilege
`form:"type" binding:"required"`
OpenClose
mysql
.
OpenClose
`form:"openClose" binding:"required"`
}
// @Tags CP v2
// @Summary cp特权开关
// @Param token header string true "token"
// @Param nonce header string true "随机数字"
// @Param type formData int true "1.空间 2.横幅 3.等级勋章 4.证书 5.进场特效 6.头像头饰 7.动态资料卡 8.麦位特效"
// @Param openClose formData int true "1:open 2:close"
// @Success 200
// @Router /v2/cp/privilege/openClose [put]
func
CpPrivilegeOpenClose
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myCtx
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
var
request
CpPrivilegeOpenCloseReq
if
err
:=
c
.
ShouldBind
(
&
request
);
err
!=
nil
{
return
myCtx
,
err
}
userId
,
err
:=
req
.
GetUserId
(
c
)
if
err
!=
nil
{
return
myCtx
,
err
}
var
model
=
domain
.
CreateModelContext
(
myCtx
)
if
err
:=
cp_m
.
OpenCLoseUserSvipPrivilege
(
model
,
userId
,
request
.
Type
,
request
.
OpenClose
);
err
!=
nil
{
return
myCtx
,
err
}
resp
.
ResponseOk
(
c
,
""
)
return
myCtx
,
nil
}
route/router.go
View file @
718e349d
...
...
@@ -32,6 +32,7 @@ func InitRouter() *gin.Engine {
cp
:=
v2
.
Group
(
"/cp"
)
{
cp
.
GET
(
"/space"
,
wrapper
(
cp_r
.
CpSpace
))
cp
.
PUT
(
"/privilege/openClose"
,
wrapper
(
cp_r
.
CpPrivilegeOpenClose
))
}
inner
:=
r
.
Group
(
"/inner"
)
inner
.
Use
(
ExceptionHandle
,
LoggerHandle
)
...
...
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