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
c05927f8
Commit
c05927f8
authored
May 26, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:搬运了svip的计算逻辑
parent
31f49f15
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
333 additions
and
64 deletions
+333
-64
level.go
_const/enum/cp_e/level.go
+27
-23
space.go
cv/cp_cv/space.go
+27
-27
grade.go
domain/model/cp_m/grade.go
+255
-0
repo.go
domain/model/cp_m/repo.go
+10
-0
space.go
route/cp_r/space.go
+14
-14
No files found.
_const/enum/cp_e/
grade
.go
→
_const/enum/cp_e/
level
.go
View file @
c05927f8
...
...
@@ -2,28 +2,32 @@ package cp_e
import
"git.hilo.cn/hilo-common/resource/mysql"
type
CpGrade
int
const
(
EffectDays
=
30
// 30天有效期
)
type
CpLevel
int
const
(
Cp
Grade0
CpGrade
=
0
// 无称号
Cp
Grade1
CpGrade
=
1
// 恋爱CP
Cp
Grade2
CpGrade
=
2
// 甜蜜CP
Cp
Grade3
CpGrade
=
3
// 忠诚CP
Cp
Grade4
CpGrade
=
4
// 炽热CP
Cp
Grade5
CpGrade
=
5
// 荣耀CP
Cp
Level0
CpLevel
=
0
// 无称号
Cp
Level1
CpLevel
=
1
// 恋爱CP
Cp
Level2
CpLevel
=
2
// 甜蜜CP
Cp
Level3
CpLevel
=
3
// 忠诚CP
Cp
Level4
CpLevel
=
4
// 炽热CP
Cp
Level5
CpLevel
=
5
// 荣耀CP
Cp
GradeMax
=
CpGrade
5
Cp
LevelMax
=
CpLevel
5
)
var
(
// cp等级
Cp
GradeExp
=
map
[
CpGrade
]
mysql
.
Num
{
Cp
Grade
0
:
0
,
Cp
Grade
1
:
200000
,
Cp
Grade
2
:
800000
,
Cp
Grade
3
:
1000000
,
Cp
Grade
4
:
3000000
,
Cp
Grade
5
:
10000000
,
// cp等级
积分
Cp
LevelPoints
=
map
[
CpLevel
]
mysql
.
Num
{
Cp
Level
0
:
0
,
Cp
Level
1
:
200000
,
Cp
Level
2
:
800000
,
Cp
Level
3
:
1000000
,
Cp
Level
4
:
3000000
,
Cp
Level
5
:
10000000
,
}
// cp特权名称 // todo 翻译
CpPrivilegeNameMsgId
=
map
[
CpPrivilege
]
uint
{
...
...
@@ -37,13 +41,13 @@ var (
CpPrivilegeMicEffect
:
0
,
}
// cp等级icon // todo ui
Cp
GradeIcon
=
map
[
CpGrade
]
string
{
Cp
Grade
0
:
"icon0.png"
,
Cp
Grade
1
:
"icon1.png"
,
Cp
Grade
2
:
"icon2.png"
,
Cp
Grade
3
:
"icon3.png"
,
Cp
Grade
4
:
"icon4.png"
,
Cp
Grade
5
:
"icon5.png"
,
Cp
LevelIcon
=
map
[
CpLevel
]
string
{
Cp
Level
0
:
"icon0.png"
,
Cp
Level
1
:
"icon1.png"
,
Cp
Level
2
:
"icon2.png"
,
Cp
Level
3
:
"icon3.png"
,
Cp
Level
4
:
"icon4.png"
,
Cp
Level
5
:
"icon5.png"
,
}
// cp特权icon // todo ui
CpPrivilegeIcon
=
map
[
CpPrivilege
]
string
{
...
...
cv/cp_cv/space.go
View file @
c05927f8
...
...
@@ -19,17 +19,17 @@ type CvCpInfo struct {
}
// cp等级
type
CvCp
Grade
struct
{
Grade
cp_e
.
CpGrade
`json:"grade"`
// 等级 0:无称号 1:恋爱CP 2:甜蜜CP 3:忠诚CP 4:炽热CP 5:荣耀CP
Exp
uint32
`json:"exp"`
// 经验
值
Next
Exp
uint32
`json:"nextExp,omitempty"`
// 下个等级所需经验
值
Remain
Exp
uint32
`json:"remainExp,omitempty"`
// 还需要多少经验
值到下一个级别
ExpireAt
string
`json:"expireAt,omitempty"`
// 有效期
type
CvCp
Level
struct
{
Level
cp_e
.
CpLevel
`json:"level"`
// 等级 0:无称号 1:恋爱CP 2:甜蜜CP 3:忠诚CP 4:炽热CP 5:荣耀CP
Points
uint32
`json:"points"`
// CP
值
Next
Points
uint32
`json:"nextPoints,omitempty"`
// 下个等级所需CP
值
Remain
Points
uint32
`json:"remainPoints,omitempty"`
// 还需要多少CP
值到下一个级别
ExpireAt
string
`json:"expireAt,omitempty"`
// 有效期
}
// 资源等级
type
CvRes
Grade
struct
{
Grade
cp_e
.
CpGrade
`json:"grade
"`
// 等级
type
CvRes
Level
struct
{
Level
cp_e
.
CpLevel
`json:"level
"`
// 等级
Icon
string
`json:"icon"`
// 等级icon图
}
...
...
@@ -44,36 +44,36 @@ type CvPrivilege struct {
// cp空间页
type
CvSpace
struct
{
CpInfo
CvCpInfo
`json:"cpInfo"`
// cp信息
Cp
Grade
CvCpGrade
`json:"cpGrade
"`
// cp等级
Res
GradeList
[]
CvResGrade
`json:"resGrade
List"`
// 资源等级列表,无称号/恋爱CP/甜蜜CP/忠诚CP/炽热CP/荣耀CP
Cp
Level
CvCpLevel
`json:"cpLevel
"`
// cp等级
Res
LevelList
[]
CvResLevel
`json:"resLevel
List"`
// 资源等级列表,无称号/恋爱CP/甜蜜CP/忠诚CP/炽热CP/荣耀CP
PrivilegeList
[]
CvPrivilege
`json:"privilegeList"`
// 等级特权
}
var
CvRes
GradeList
=
[]
CvResGrade
{
{
cp_e
.
Cp
Grade0
,
cp_e
.
CpGradeIcon
[
cp_e
.
CpGrade
0
]},
{
cp_e
.
Cp
Grade1
,
cp_e
.
CpGradeIcon
[
cp_e
.
CpGrade
1
]},
{
cp_e
.
Cp
Grade2
,
cp_e
.
CpGradeIcon
[
cp_e
.
CpGrade
2
]},
{
cp_e
.
Cp
Grade3
,
cp_e
.
CpGradeIcon
[
cp_e
.
CpGrade
3
]},
{
cp_e
.
Cp
Grade4
,
cp_e
.
CpGradeIcon
[
cp_e
.
CpGrade
4
]},
{
cp_e
.
Cp
Grade5
,
cp_e
.
CpGradeIcon
[
cp_e
.
CpGrade
5
]},
var
CvRes
LevelList
=
[]
CvResLevel
{
{
cp_e
.
Cp
Level0
,
cp_e
.
CpLevelIcon
[
cp_e
.
CpLevel
0
]},
{
cp_e
.
Cp
Level1
,
cp_e
.
CpLevelIcon
[
cp_e
.
CpLevel
1
]},
{
cp_e
.
Cp
Level2
,
cp_e
.
CpLevelIcon
[
cp_e
.
CpLevel
2
]},
{
cp_e
.
Cp
Level3
,
cp_e
.
CpLevelIcon
[
cp_e
.
CpLevel
3
]},
{
cp_e
.
Cp
Level4
,
cp_e
.
CpLevelIcon
[
cp_e
.
CpLevel
4
]},
{
cp_e
.
Cp
Level5
,
cp_e
.
CpLevelIcon
[
cp_e
.
CpLevel
5
]},
}
var
Cp
GradePrivilegeList
=
map
[
cp_e
.
CpGrade
][]
CvPrivilege
{
cp_e
.
Cp
Grade
0
:
{},
cp_e
.
Cp
Grade
1
:
{
var
Cp
LevelPrivilegeList
=
map
[
cp_e
.
CpLevel
][]
CvPrivilege
{
cp_e
.
Cp
Level
0
:
{},
cp_e
.
Cp
Level
1
:
{
{
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
.
Cp
Grade
2
:
{
cp_e
.
Cp
Level
2
:
{
{
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
.
Cp
Grade
3
:
{
cp_e
.
Cp
Level
3
:
{
{
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
]},
...
...
@@ -81,7 +81,7 @@ var CpGradePrivilegeList = map[cp_e.CpGrade][]CvPrivilege{
{
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
.
Cp
Grade
4
:
{
cp_e
.
Cp
Level
4
:
{
{
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
]},
...
...
@@ -90,7 +90,7 @@ var CpGradePrivilegeList = map[cp_e.CpGrade][]CvPrivilege{
{
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
.
Cp
Grade
5
:
{
cp_e
.
Cp
Level
5
:
{
{
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
]},
...
...
@@ -102,9 +102,9 @@ var CpGradePrivilegeList = map[cp_e.CpGrade][]CvPrivilege{
},
}
func
CopyCp
GradePrivilegeList
(
grade
cp_e
.
CpGrade
,
lang
string
)
[]
CvPrivilege
{
privileges
:=
make
([]
CvPrivilege
,
len
(
Cp
GradePrivilegeList
[
grade
]))
copy
(
privileges
,
Cp
GradePrivilegeList
[
grade
])
func
CopyCp
LevelPrivilegeList
(
Level
cp_e
.
CpLevel
,
lang
string
)
[]
CvPrivilege
{
privileges
:=
make
([]
CvPrivilege
,
len
(
Cp
LevelPrivilegeList
[
Level
]))
copy
(
privileges
,
Cp
LevelPrivilegeList
[
Level
])
for
i
,
v
:=
range
privileges
{
privileges
[
i
]
.
Name
=
GetTranslate
(
v
.
NameMsgId
,
lang
)
}
...
...
domain/model/cp_m/grade.go
0 → 100644
View file @
c05927f8
package
cp_m
import
(
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"hilo-user/_const/enum/cp_e"
"hilo-user/myerr"
"time"
)
// cp等级
type
CpLevel
struct
{
mysql
.
Entity
CpId
mysql
.
ID
SmallUserId
mysql
.
ID
LargeUserId
mysql
.
ID
Points
mysql
.
Num
Level
cp_e
.
CpLevel
ExpireAt
time
.
Time
}
// cp等级积分明细
type
CpLevelDetail
struct
{
mysql
.
Entity
CpId
mysql
.
ID
SmallUserId
mysql
.
ID
LargeUserId
mysql
.
ID
AddReduce
mysql
.
AddReduce
Num
mysql
.
Num
BefNum
mysql
.
Num
AftNum
mysql
.
Num
Remark
string
}
// 添加cp等级积分增减明细
func
AddCpLevelDetail
(
model
*
domain
.
Model
,
detail
CpLevelDetail
)
error
{
return
model
.
DB
()
.
Create
(
&
detail
)
.
Error
}
// 增加cp等级积分
// 送礼1钻石=1点数
// condition
// 1.记录不存在,首充加points计算level增加90天有效期
// 2.记录存在
// 2.1 在有效期内,直接加points后判断新level,升级需要更新有效期
// 2.2 不有效期内,算首充,重置points后判断新level,升级需要更新有效期
func
AddCpLevelPoints
(
model
*
domain
.
Model
,
userId
mysql
.
ID
,
points
mysql
.
Num
)
(
err
error
)
{
start
:=
time
.
Now
()
defer
func
()
{
model
.
Log
.
Infof
(
"AddCpLevelPoints cost:%v,err:%v"
,
time
.
Now
()
.
Sub
(
start
),
err
)
}()
cpId
:=
mysql
.
ID
(
1
)
// todo get from weijian
small
,
large
:=
mysql
.
ID
(
4552
),
mysql
.
ID
(
7642
)
// todo get from weijian
var
cpLevel
CpLevel
var
cpLevelDetails
[]
CpLevelDetail
if
err
:=
model
.
DB
()
.
Model
(
CpLevel
{})
.
Where
(
"cp_id = ?"
,
cpId
)
.
First
(
&
cpLevel
)
.
Error
;
err
!=
nil
{
if
err
!=
gorm
.
ErrRecordNotFound
{
return
myerr
.
WrapErr
(
err
)
}
// 明细
cpLevelDetails
=
append
(
cpLevelDetails
,
CpLevelDetail
{
CpId
:
cpId
,
SmallUserId
:
small
,
LargeUserId
:
large
,
AddReduce
:
mysql
.
ADD
,
Num
:
points
,
BefNum
:
0
,
AftNum
:
points
,
Remark
:
fmt
.
Sprintf
(
"send %d gift diamonds"
,
points
),
})
// 1.记录不存在,首充加points计算level增加90天有效期
var
level
cp_e
.
CpLevel
for
l
:=
cp_e
.
CpLevelMax
;
l
>=
cp_e
.
CpLevel0
;
l
--
{
if
cp_e
.
CpLevelPoints
[
l
]
<=
points
{
level
=
l
break
}
}
if
level
>
0
{
points
=
points
-
cp_e
.
CpLevelPoints
[
level
]
// 减去用于已用于升级的积分
// 明细
cpLevelDetails
=
append
(
cpLevelDetails
,
CpLevelDetail
{
CpId
:
cpId
,
SmallUserId
:
small
,
LargeUserId
:
large
,
AddReduce
:
mysql
.
REDUCE
,
Num
:
cp_e
.
CpLevelPoints
[
level
],
BefNum
:
cp_e
.
CpLevelPoints
[
level
]
+
points
,
AftNum
:
points
,
Remark
:
fmt
.
Sprintf
(
"Become LEVEL%d"
,
level
),
})
}
cpLevel
=
CpLevel
{
CpId
:
cpId
,
SmallUserId
:
small
,
LargeUserId
:
large
,
Points
:
points
,
Level
:
level
,
ExpireAt
:
time
.
Now
()
.
AddDate
(
0
,
0
,
cp_e
.
EffectDays
),
}
}
else
{
// 2.记录存在
// 2.1 在有效期内,直接加points后判断新level,升级需要更新有效期
if
cpLevel
.
ExpireAt
.
After
(
time
.
Now
())
{
cpLevel
.
Points
+=
points
// 明细
cpLevelDetails
=
append
(
cpLevelDetails
,
CpLevelDetail
{
CpId
:
cpId
,
SmallUserId
:
small
,
LargeUserId
:
large
,
AddReduce
:
mysql
.
ADD
,
Num
:
points
,
BefNum
:
cpLevel
.
Points
-
points
,
AftNum
:
cpLevel
.
Points
,
Remark
:
fmt
.
Sprintf
(
"send %d gift diamonds"
,
points
),
})
oldLevel
:=
cpLevel
.
Level
levelPoint
:=
cp_e
.
CpLevelPoints
[
oldLevel
]
// 已经用于升级的积分
for
level
:=
cp_e
.
CpLevelMax
;
level
>
oldLevel
;
level
--
{
if
cp_e
.
CpLevelPoints
[
level
]
<=
cpLevel
.
Points
+
levelPoint
{
cpLevel
.
Level
=
level
break
}
}
// 升级
if
oldLevel
!=
cpLevel
.
Level
{
// 减去已用于升级的积分
cpLevel
.
Points
=
cpLevel
.
Points
-
(
cp_e
.
CpLevelPoints
[
cpLevel
.
Level
]
-
cp_e
.
CpLevelPoints
[
oldLevel
])
cpLevel
.
ExpireAt
=
time
.
Now
()
.
AddDate
(
0
,
0
,
cp_e
.
EffectDays
)
// 明细
cpLevelDetails
=
append
(
cpLevelDetails
,
CpLevelDetail
{
CpId
:
cpId
,
SmallUserId
:
small
,
LargeUserId
:
large
,
AddReduce
:
mysql
.
REDUCE
,
Num
:
cp_e
.
CpLevelPoints
[
cpLevel
.
Level
]
-
cp_e
.
CpLevelPoints
[
oldLevel
],
BefNum
:
cpLevel
.
Points
+
cp_e
.
CpLevelPoints
[
cpLevel
.
Level
]
-
cp_e
.
CpLevelPoints
[
oldLevel
],
AftNum
:
cpLevel
.
Points
,
Remark
:
fmt
.
Sprintf
(
"Become LEVEL%d"
,
cpLevel
.
Level
),
})
}
}
else
{
// 2.2 不有效期内,算首充,重置points后判断新level,更新有效期30天
oldPoints
:=
cpLevel
.
Points
cpLevel
.
Points
=
points
// 明细
cpLevelDetails
=
append
(
cpLevelDetails
,
CpLevelDetail
{
CpId
:
cpId
,
SmallUserId
:
small
,
LargeUserId
:
large
,
AddReduce
:
mysql
.
ADD
,
Num
:
points
,
BefNum
:
oldPoints
,
AftNum
:
cpLevel
.
Points
,
Remark
:
fmt
.
Sprintf
(
"send %d gift diamonds"
,
points
),
})
for
level
:=
cp_e
.
CpLevelMax
;
level
>=
cp_e
.
CpLevel0
;
level
--
{
if
cp_e
.
CpLevelPoints
[
level
]
<=
cpLevel
.
Points
{
cpLevel
.
Level
=
level
break
}
}
if
cpLevel
.
Level
>
0
{
cpLevel
.
Points
-=
cp_e
.
CpLevelPoints
[
cpLevel
.
Level
]
// 减去已用于升级的积分
// 明细
cpLevelDetails
=
append
(
cpLevelDetails
,
CpLevelDetail
{
CpId
:
cpId
,
SmallUserId
:
small
,
LargeUserId
:
large
,
AddReduce
:
mysql
.
REDUCE
,
Num
:
cp_e
.
CpLevelPoints
[
cpLevel
.
Level
],
BefNum
:
cpLevel
.
Points
+
cp_e
.
CpLevelPoints
[
cpLevel
.
Level
],
AftNum
:
cpLevel
.
Points
,
Remark
:
fmt
.
Sprintf
(
"Become SVIP%d"
,
cpLevel
.
Level
),
})
}
cpLevel
.
ExpireAt
=
time
.
Now
()
.
AddDate
(
0
,
0
,
cp_e
.
EffectDays
)
}
}
// 顺序增加明细
for
_
,
detail
:=
range
cpLevelDetails
{
if
err
:=
AddCpLevelDetail
(
model
,
detail
);
err
!=
nil
{
return
myerr
.
WrapErr
(
err
)
}
}
return
cpLevel
.
Persistence
(
model
)
}
// 清理过期svip积分
// 降级保级: 积分清零,svip去到大于0的等级,有效期90天
// svip0:积分清零,有效期保持过期
func
ClearExpireUserSvipPoints
(
model
*
domain
.
Model
)
error
{
var
cpLevels
[]
*
CpLevel
// 过期 + (积分 or level) 大于0
if
err
:=
model
.
DB
()
.
Model
(
CpLevel
{})
.
Where
(
"expire_at < ? AND (points > 0 or level > 0) "
,
time
.
Now
())
.
Find
(
&
cpLevels
)
.
Error
;
err
!=
nil
{
return
myerr
.
WrapErr
(
err
)
}
for
_
,
cpLevel
:=
range
cpLevels
{
var
doubleCheck
CpLevel
if
err
:=
model
.
DB
()
.
Model
(
CpLevel
{})
.
Where
(
"id = ?"
,
cpLevel
.
ID
)
.
First
(
&
doubleCheck
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"double check fail:%v"
,
err
)
continue
}
if
doubleCheck
.
ExpireAt
.
After
(
time
.
Now
())
{
continue
}
oldPoints
:=
cpLevel
.
Points
cpLevel
.
Level
,
cpLevel
.
Points
=
cp_e
.
CpLevel0
,
0
// 清零
var
newLevel
cp_e
.
CpLevel
// 0级不刷新30天有效期
for
level
:=
cp_e
.
CpLevelMax
;
level
>
cp_e
.
CpLevel0
;
level
--
{
if
cp_e
.
CpLevelPoints
[
level
]
<=
oldPoints
{
newLevel
=
level
break
}
}
// 降级/保级刷新30天有效期
if
newLevel
>
0
{
cpLevel
.
Level
=
newLevel
cpLevel
.
ExpireAt
=
time
.
Now
()
.
AddDate
(
0
,
0
,
cp_e
.
EffectDays
)
// 明细
if
err
:=
AddCpLevelDetail
(
model
,
CpLevelDetail
{
CpId
:
cpLevel
.
CpId
,
SmallUserId
:
cpLevel
.
SmallUserId
,
LargeUserId
:
cpLevel
.
LargeUserId
,
AddReduce
:
mysql
.
REDUCE
,
Num
:
cp_e
.
CpLevelPoints
[
newLevel
],
BefNum
:
oldPoints
,
AftNum
:
0
,
Remark
:
fmt
.
Sprintf
(
"Become LEVEL%d"
,
newLevel
),
});
err
!=
nil
{
model
.
Log
.
Errorf
(
"AddCpLevelDetail fail:%v"
,
err
)
}
}
if
err
:=
cpLevel
.
Persistence
(
model
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"cpLevel persistence fail:%v"
,
err
)
}
// 明细
if
err
:=
AddCpLevelDetail
(
model
,
CpLevelDetail
{
CpId
:
cpLevel
.
CpId
,
SmallUserId
:
cpLevel
.
SmallUserId
,
LargeUserId
:
cpLevel
.
LargeUserId
,
AddReduce
:
mysql
.
SET
,
Num
:
oldPoints
-
cp_e
.
CpLevelPoints
[
newLevel
],
BefNum
:
oldPoints
-
cp_e
.
CpLevelPoints
[
newLevel
],
AftNum
:
0
,
Remark
:
fmt
.
Sprintf
(
"Expired clear"
),
});
err
!=
nil
{
model
.
Log
.
Errorf
(
"AddCpLevelDetail fail:%v"
,
err
)
}
}
return
nil
}
domain/model/cp_m/repo.go
0 → 100644
View file @
c05927f8
package
cp_m
import
(
"git.hilo.cn/hilo-common/domain"
"hilo-user/domain/model"
)
func
(
p
*
CpLevel
)
Persistence
(
m
*
domain
.
Model
)
error
{
return
model
.
Persistent
(
m
.
DB
(),
p
)
}
route/cp_r/space.go
View file @
c05927f8
...
...
@@ -41,27 +41,27 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) {
return
myContext
,
err
}
expireAt
:=
""
// todo
cp
Grade
:=
cp_e
.
CpGrade
3
// todo get from db
next
Exp
:=
cp_e
.
CpGradeExp
[
cp_e
.
CpGrade
Max
]
remain
Exp
:=
mysql
.
Num
(
0
)
if
cp
Grade
!=
cp_e
.
CpGrade
Max
{
next
Exp
=
cp_e
.
CpGradeExp
[
cpGrade
+
1
]
remain
Exp
=
nextExp
-
cp_e
.
CpGradeExp
[
cpGrade
]
// todo get from db
cp
Level
:=
cp_e
.
CpLevel
3
// todo get from db
next
Points
:=
cp_e
.
CpLevelPoints
[
cp_e
.
CpLevel
Max
]
remain
Points
:=
mysql
.
Num
(
0
)
if
cp
Level
!=
cp_e
.
CpLevel
Max
{
next
Points
=
cp_e
.
CpLevelPoints
[
cpLevel
+
1
]
remain
Points
=
nextPoints
-
cp_e
.
CpLevelPoints
[
cpLevel
]
// todo get from db
}
response
:=
cp_cv
.
CvSpace
{
CpInfo
:
cp_cv
.
CvCpInfo
{
UserInfo
:
user_cv
.
UserToTiny
(
*
userInfo
),
CpUserInfo
:
user_cv
.
UserToTiny
(
*
cpUserInfo
),
},
Cp
Grade
:
cp_cv
.
CvCpGrade
{
Grade
:
cpGrade
,
Exp
:
cp_e
.
CpGradeExp
[
cpGrade
],
// todo get from db
Next
Exp
:
nextExp
,
Remain
Exp
:
remainExp
,
ExpireAt
:
expireAt
,
Cp
Level
:
cp_cv
.
CvCpLevel
{
Level
:
cpLevel
,
Points
:
cp_e
.
CpLevelPoints
[
cpLevel
],
// todo get from db
Next
Points
:
nextPoints
,
Remain
Points
:
remainPoints
,
ExpireAt
:
expireAt
,
},
Res
GradeList
:
cp_cv
.
CvResGrade
List
,
PrivilegeList
:
cp_cv
.
CopyCp
GradePrivilegeList
(
cpGrade
,
lang
),
Res
LevelList
:
cp_cv
.
CvResLevel
List
,
PrivilegeList
:
cp_cv
.
CopyCp
LevelPrivilegeList
(
cpLevel
,
lang
),
}
resp
.
ResponseOk
(
c
,
response
)
return
myContext
,
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