Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
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-group
Commits
18c512d7
Commit
18c512d7
authored
Apr 19, 2023
by
chenweijian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
家族贡献排行自动发奖
parent
d766308d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
221 additions
and
4 deletions
+221
-4
cron.go
cron/cron.go
+1
-0
group_power_month_act.go
cron/group_cron/group_power_month_act.go
+22
-0
groupPower.go
domain/model/groupPower_m/groupPower.go
+30
-0
group_power.go
domain/service/group_power_s/group_power.go
+150
-3
group_power_month_act.sql
mysql/group_power_month_act.sql
+15
-0
group_rank.go
route/group_power_r/group_rank.go
+3
-1
No files found.
cron/cron.go
View file @
18c512d7
...
...
@@ -15,4 +15,5 @@ func Init() {
gift_cron
.
GiftRemark
()
// 礼物消息补偿
mic_cron
.
OnMicCheck
()
// 检查上麦
group_cron
.
GroupPowerExpClear
()
// 清理家族经验/等级
group_cron
.
GroupPowerMonthRankAct
()
}
cron/group_cron/group_power_month_act.go
0 → 100644
View file @
18c512d7
package
group_cron
import
(
"git.hilo.cn/hilo-common/domain"
"github.com/robfig/cron"
"hilo-group/domain/service/group_power_s"
)
// 家族贡献月度排行榜发奖
func
GroupPowerMonthRankAct
()
{
c
:=
cron
.
New
()
// 每月1号0:02结算发奖
spec
:=
"0 2 0 1 * ?"
_
=
c
.
AddFunc
(
spec
,
func
()
{
var
model
=
domain
.
CreateModelNil
()
if
err
:=
group_power_s
.
CalcGroupPowerMonthRankAct
(
model
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"GroupPowerMonthRankAct fail:%v"
,
err
)
}
})
c
.
Start
()
}
domain/model/groupPower_m/groupPower.go
View file @
18c512d7
...
...
@@ -43,6 +43,16 @@ type GroupPowerUser struct {
Role
groupPower_e
.
GroupPowerUserRole
}
type
ActFamilyMonthRankLog
struct
{
Id
uint64
`json:"id"`
Period
string
`json:"period"`
FamilyId
uint64
`json:"family_id"`
RankFamily
int
`json:"rank_family"`
RankUser
int
`json:"rank_user"`
UserId
uint64
`json:"user_id"`
Award
string
`json:"award"`
}
func
(
gpu
*
GroupPowerUser
)
Get
(
db
*
gorm
.
DB
)
([]
GroupPowerUser
,
error
)
{
rows
:=
make
([]
GroupPowerUser
,
0
)
err
:=
db
.
Where
(
gpu
)
.
Find
(
&
rows
)
.
Error
...
...
@@ -64,6 +74,22 @@ func GetPowerOwner(db *gorm.DB, powerId uint64) (uint64, error) {
return
records
[
0
]
.
UserId
,
nil
}
func
GetPowerOwnerMap
(
model
*
domain
.
Model
,
powerIds
[]
uint64
)
(
map
[
uint64
]
uint64
,
error
)
{
rows
:=
make
([]
GroupPowerUser
,
0
)
if
len
(
powerIds
)
>
0
{
if
err
:=
model
.
DB
()
.
Model
(
&
GroupPowerUser
{})
.
Where
(
"group_power_id IN ? and role = ?"
,
powerIds
,
groupPower_e
.
GroupPowerUserRoleMgr
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
}
result
:=
make
(
map
[
uint64
]
uint64
,
0
)
for
_
,
i
:=
range
rows
{
result
[
i
.
GroupPowerId
]
=
i
.
UserId
}
return
result
,
nil
}
func
GetMyPowerId
(
db
*
gorm
.
DB
,
userId
uint64
)
(
uint64
,
error
)
{
gpu
:=
GroupPowerUser
{
UserId
:
userId
,
Role
:
groupPower_e
.
GroupPowerUserRoleMgr
}
records
,
err
:=
gpu
.
Get
(
db
)
...
...
@@ -707,3 +733,7 @@ func BatchGetGroupPowerUser(model *domain.Model, userIds []mysql.ID) (map[mysql.
}
return
res
,
nil
}
func
CreateActFamilyMonthRankLog
(
model
*
domain
.
Model
,
list
[]
*
ActFamilyMonthRankLog
)
error
{
return
model
.
DB
()
.
CreateInBatches
(
&
list
,
50
)
.
Error
}
domain/service/group_power_s/group_power.go
View file @
18c512d7
package
group_power_s
import
(
"encoding/json"
"git.hilo.cn/hilo-common/_const/enum/diamond_e"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/txop/award_tx"
"git.hilo.cn/hilo-common/utils"
"github.com/jinzhu/now"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/msg_e"
"hilo-group/cv/group_power_cv"
"hilo-group/cv/user_cv"
"hilo-group/domain/event/group_power_ev"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/user_m"
"hilo-group/myerr/bizerr"
"time"
)
type
GroupPowerService
struct
{
...
...
@@ -80,9 +88,12 @@ func GetGroupPowerRankResp(model *domain.Model, beginDate, endDate string, userI
for
_
,
g
:=
range
rank
{
ids
=
append
(
ids
,
g
.
GroupPowerId
)
}
myGroupPower
,
err
:=
groupPower_m
.
GetGroupPowerUserOrNil
(
model
,
userId
)
if
err
!=
nil
{
return
var
myGroupPower
*
groupPower_m
.
GroupPowerUser
if
userId
>
0
{
myGroupPower
,
err
=
groupPower_m
.
GetGroupPowerUserOrNil
(
model
,
userId
)
if
err
!=
nil
{
return
}
}
if
myGroupPower
!=
nil
{
ids
=
append
(
ids
,
myGroupPower
.
GroupPowerId
)
...
...
@@ -172,3 +183,139 @@ func GetGroupPowerStar(model *domain.Model, groupPowerId mysql.ID, _type groupPo
}
return
response
,
nil
}
func
CalcGroupPowerMonthRankAct
(
model
*
domain
.
Model
)
error
{
lastDayTime
:=
time
.
Now
()
.
AddDate
(
0
,
0
,
-
1
)
_now
:=
now
.
New
(
lastDayTime
)
calcMonth
:=
_now
.
BeginningOfMonth
()
.
Format
(
utils
.
MONTH_FORMAT
)
beginDate
,
endDate
:=
_now
.
BeginningOfMonth
()
.
Format
(
"2006-01-02"
),
_now
.
EndOfMonth
()
.
Format
(
"2006-01-02"
)
// 计算获奖
response
,
err
:=
GetGroupPowerRankResp
(
model
,
beginDate
,
endDate
,
0
)
if
err
!=
nil
{
return
err
}
powerIds
:=
make
([]
uint64
,
0
,
len
(
response
.
Items
))
for
i
,
v
:=
range
response
.
Items
{
powerIds
=
append
(
powerIds
,
v
.
Id
)
response
.
Items
[
i
]
.
StarList
,
err
=
GetGroupPowerStar
(
model
,
v
.
Id
,
groupPower_e
.
GroupPowerStarTypeFamous
,
0
,
10
)
if
err
!=
nil
{
return
err
}
}
// 读奖励配置
type
award
struct
{
MedalId
uint64
MedalDay
uint32
Diamond
uint32
Noble
uint32
NobleDay
uint32
HeaddressId
uint64
HeaddressDay
int
}
confMap
:=
map
[
int
]
map
[
int
]
*
award
{
1
:
{
0
:
{
MedalId
:
1
,
MedalDay
:
30
,
Diamond
:
300000
,
Noble
:
5
,
NobleDay
:
15
},
1
:
{
MedalId
:
1
,
MedalDay
:
30
,
Diamond
:
100000
,
Noble
:
5
,
NobleDay
:
7
},
4
:
{
HeaddressId
:
1
,
HeaddressDay
:
30
},
},
2
:
{
0
:
{
MedalId
:
1
,
MedalDay
:
30
,
Diamond
:
200000
,
Noble
:
4
,
NobleDay
:
15
},
1
:
{
MedalId
:
1
,
MedalDay
:
30
,
Diamond
:
80000
,
Noble
:
4
,
NobleDay
:
7
},
4
:
{
HeaddressId
:
1
,
HeaddressDay
:
30
},
},
3
:
{
0
:
{
MedalId
:
1
,
MedalDay
:
30
,
Diamond
:
100000
,
Noble
:
5
,
NobleDay
:
5
},
1
:
{
MedalId
:
1
,
MedalDay
:
30
,
Diamond
:
50000
},
4
:
{
HeaddressId
:
1
,
HeaddressDay
:
30
},
},
4
:
{
0
:
{
MedalId
:
1
,
MedalDay
:
30
},
1
:
{
MedalId
:
1
,
MedalDay
:
30
,
HeaddressId
:
1
,
HeaddressDay
:
30
},
},
}
awardList
:=
make
([]
*
award_tx
.
UserAward
,
0
,
50
)
// 奖励
ownerMap
,
err
:=
groupPower_m
.
GetPowerOwnerMap
(
model
,
powerIds
)
if
err
!=
nil
{
return
err
}
// log list
logList
:=
make
([]
*
groupPower_m
.
ActFamilyMonthRankLog
,
0
,
50
)
for
_
,
v
:=
range
response
.
Items
{
teamRank
:=
0
if
v
.
Rank
>=
1
&&
v
.
Rank
<=
3
{
teamRank
=
v
.
Rank
}
else
if
v
.
Rank
>=
4
&&
v
.
Rank
<=
10
{
teamRank
=
4
}
else
{
break
}
ownerId
,
ok
:=
ownerMap
[
v
.
Id
]
if
!
ok
||
ownerId
<=
0
{
model
.
Log
.
Errorf
(
"CalcGroupPowerMonthRankAct 获取势力主错误 familyId:%d"
,
v
.
Id
)
return
bizerr
.
InvalidParameter
}
uRankConfMap
,
tCOk
:=
confMap
[
teamRank
]
if
!
tCOk
{
break
}
oAward
,
aOk
:=
uRankConfMap
[
0
]
if
!
aOk
{
model
.
Log
.
Errorf
(
"CalcGroupPowerMonthRankAct 配置错误:%v"
,
confMap
)
return
bizerr
.
InvalidParameter
}
oAwardJ
,
_
:=
json
.
Marshal
(
oAward
)
logList
=
append
(
logList
,
&
groupPower_m
.
ActFamilyMonthRankLog
{
Period
:
calcMonth
,
FamilyId
:
v
.
Id
,
RankFamily
:
v
.
Rank
,
RankUser
:
0
,
UserId
:
ownerId
,
Award
:
string
(
oAwardJ
),
})
awardList
=
append
(
awardList
,
&
award_tx
.
UserAward
{
MedalId
:
oAward
.
MedalId
,
MedalDuration
:
oAward
.
MedalDay
,
Diamond
:
oAward
.
Diamond
,
NobleLevel
:
oAward
.
Noble
,
NobleDuration
:
oAward
.
NobleDay
})
for
i
,
u
:=
range
v
.
StarList
{
uRank
:=
i
+
1
confIdx
:=
9
if
uRank
>=
1
&&
uRank
<=
3
{
confIdx
=
1
}
else
if
uRank
>=
4
&&
uRank
<=
10
{
confIdx
=
4
}
award
,
aOk
:=
uRankConfMap
[
confIdx
]
if
!
aOk
{
break
}
awardJ
,
_
:=
json
.
Marshal
(
award
)
logList
=
append
(
logList
,
&
groupPower_m
.
ActFamilyMonthRankLog
{
Period
:
calcMonth
,
FamilyId
:
v
.
Id
,
RankFamily
:
v
.
Rank
,
RankUser
:
uRank
,
UserId
:
u
.
User
.
Id
,
Award
:
string
(
awardJ
),
})
awardList
=
append
(
awardList
,
&
award_tx
.
UserAward
{
MedalId
:
award
.
MedalId
,
MedalDuration
:
award
.
MedalDay
,
Diamond
:
award
.
Diamond
,
NobleLevel
:
award
.
Noble
,
NobleDuration
:
award
.
NobleDay
,
HeaddressId
:
award
.
HeaddressId
,
HeaddressDuration
:
award
.
HeaddressDay
})
}
}
return
model
.
Transaction
(
func
(
model
*
domain
.
Model
)
error
{
// log
err
=
groupPower_m
.
CreateActFamilyMonthRankLog
(
model
,
logList
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CalcGroupPowerMonthRankAct err:%+v"
,
err
)
return
err
}
// award
for
_
,
v
:=
range
awardList
{
err
=
award_tx
.
SendUserAward
(
model
,
v
,
diamond_e
.
GeneralActivity
,
msg_e
.
MgrSendDiamondProperty
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CalcGroupPowerMonthRankAct award:%+v, err:%+v"
,
v
,
err
)
return
err
}
}
return
nil
})
}
mysql/group_power_month_act.sql
0 → 100644
View file @
18c512d7
CREATE
TABLE
`act_family_month_rank_log`
(
`id`
bigint
unsigned
NOT
NULL
AUTO_INCREMENT
COMMENT
'id'
,
`period`
varchar
(
20
)
NOT
NULL
DEFAULT
''
COMMENT
'月份'
,
`family_id`
bigint
unsigned
NOT
NULL
COMMENT
'家族id'
,
`rank_family`
int
unsigned
NOT
NULL
DEFAULT
'0'
COMMENT
'家族排名'
,
`rank_user`
int
unsigned
NOT
NULL
DEFAULT
'0'
COMMENT
'用户在家族中的家族排名'
,
`user_id`
bigint
unsigned
NOT
NULL
COMMENT
'id'
,
`award`
varchar
(
500
)
NOT
NULL
DEFAULT
''
COMMENT
'获得的奖励'
,
`created_time`
timestamp
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_time`
timestamp
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
ON
UPDATE
CURRENT_TIMESTAMP
,
PRIMARY
KEY
(
`id`
),
UNIQUE
KEY
`period`
(
`period`
,
`family_id`
,
`rank_user`
),
KEY
`user_idx`
(
`user_id`
)
USING
BTREE
,
KEY
`created_time`
(
`created_time`
)
USING
BTREE
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_0900_ai_ci
COMMENT
=
'家族月度排行发奖日志'
;
\ No newline at end of file
route/group_power_r/group_rank.go
View file @
18c512d7
...
...
@@ -71,7 +71,9 @@ func GroupPowerMonthRankAct(c *gin.Context) (*mycontext.MyContext, error) {
if
err
!=
nil
{
return
myContext
,
err
}
response
.
MyGroupPower
.
StarList
,
err
=
group_power_s
.
GetGroupPowerStar
(
model
,
response
.
MyGroupPower
.
Id
,
groupPower_e
.
GroupPowerStarTypeFamous
,
0
,
10
)
if
response
.
MyGroupPower
!=
nil
{
response
.
MyGroupPower
.
StarList
,
err
=
group_power_s
.
GetGroupPowerStar
(
model
,
response
.
MyGroupPower
.
Id
,
groupPower_e
.
GroupPowerStarTypeFamous
,
0
,
10
)
}
if
err
!=
nil
{
return
myContext
,
err
}
...
...
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