Commit 1d9d82cd authored by hujiebin's avatar hujiebin

Revert "feat:去掉无用的"

This reverts commit 37383277.
parent 4c2c0e87
......@@ -133,6 +133,7 @@ const (
ActFruitPutRankAward = 47 // 水果机投入排行榜提醒领奖
GroupPowerUpgrade = 48 // 家族升级
GroupPowerExpireNotice = 49 // 家族等级即将过期(每月20日)
GroupPowerWelcomeJoin = 53 // 欢迎加入家族
)
type MsgSysUserType = mysql.Type
......
......@@ -106,6 +106,7 @@ const (
MSG_ID_DEALER_CAN_NOT_SOLE MsgIdType = 166 // 此用户已有家族代理,不能出售钻石
MSG_ID_BUY_FROM_FAMILY MsgIdType = 167 // 请向本家族代理购买钻石
MSG_ID_NEED_JOIN_FAMILY MsgIdType = 168 // 请加入代理的家族后进行购买
MSG_ID_SET_FAMILY_NAMEPL MsgIdType = 169 // 等级不够不能修改家族铭牌
ADD_GROUP_FAILED AddGroupResultType = 0
ADD_GROUP_DONE AddGroupResultType = 1
......
......@@ -2,6 +2,7 @@ package group_cron
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/config"
"github.com/robfig/cron"
"hilo-group/domain/event/group_power_ev"
"hilo-group/domain/model/groupPower_m"
......@@ -29,6 +30,9 @@ func GroupPowerExpClear() {
})
// 每月20号发家族即将过期通知
spec = "0 0 0 20 * ?"
if !config.AppIsRelease() {
spec = "0 0 */1 * * ?"
}
_ = c.AddFunc(spec, func() {
var model = domain.CreateModelNil()
_ = group_power_ev.PublishGroupPowerExpireNotice(model, &group_power_ev.GroupPowerExpireNoticeEvent{})
......
......@@ -481,12 +481,16 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr
model.Log.Infof("BuildPopularGroupInfo, roomEnterTime: %v", roomEnterTime)
// 排序优先级V8.0版本
//sort.Slice(groupIds, func(i, j int) bool {
// gi := groupIds[i]
// gj := groupIds[j]
// return roomEnterTime[gi] > roomEnterTime[gj] ||
// roomEnterTime[gi] == roomEnterTime[gj] && visitCount[gj] > visitCount[gj] ||
// roomEnterTime[gi] == roomEnterTime[gj] && visitCount[gj] == visitCount[gj] && i >= j
//})
sort.Slice(groupIds, func(i, j int) bool {
gi := groupIds[i]
gj := groupIds[j]
return roomEnterTime[gi] > roomEnterTime[gj] ||
roomEnterTime[gi] == roomEnterTime[gj] && visitCount[gj] > visitCount[gj] ||
roomEnterTime[gi] == roomEnterTime[gj] && visitCount[gj] == visitCount[gj] && i >= j
return visitCount[gj] > visitCount[gj]
})
result := make([]*PopularGroupInfo, 0)
......
......@@ -657,20 +657,21 @@ type GroupPowerInfo struct {
}
type GroupPower struct {
Id uint64 `json:"id"`
Name string `json:"name"`
Nameplate string `json:"nameplate"` // 铭牌
Declaration string `json:"declaration"` // 宣言
Icon string `json:"icon"` // 头像
Grade mysql.Num `json:"grade" gorm:"-"` // 等级
Exp mysql.Num `json:"exp" gorm:"-"` // 当前经验值
NextExp mysql.Num `json:"nextExp" gorm:"-"` // 升到下一级需要的经验值
GradeName mysql.Str `json:"gradeName"` // 等级称号
GradeMedal mysql.Str `json:"gradeMedal"` // 等级勋章图片
MemberNum mysql.Num `json:"memberNum" gorm:"-"` // 当前人数
MemberMax mysql.Num `json:"memberMax" gorm:"-"` // 最大人数
Role int `json:"role" gorm:"-"` // 我在此家族中的角色 0.路人 1.成员 2.家族长 3.管理员
IsApply bool `json:"isApply" gorm:"-"` // 最大人数
Id uint64 `json:"id"`
Name string `json:"name"`
Nameplate string `json:"nameplate"` // 铭牌
Declaration string `json:"declaration"` // 宣言
Icon string `json:"icon"` // 头像
Grade groupPower_e.GroupPowerGrade `json:"grade" gorm:"-"` // 等级
Exp mysql.Num `json:"exp" gorm:"-"` // 当前经验值
NextExp mysql.Num `json:"nextExp" gorm:"-"` // 升到下一级需要的经验值
GradeName mysql.Str `json:"gradeName"` // 等级称号
GradeMedal mysql.Str `json:"gradeMedal"` // 等级勋章图片
MemberNum mysql.Num `json:"memberNum" gorm:"-"` // 当前人数
MemberMax mysql.Num `json:"memberMax" gorm:"-"` // 最大人数
Role int `json:"role" gorm:"-"` // 我在此家族中的角色 0.路人 1.成员 2.家族长 3.管理员
IsApply bool `json:"isApply" gorm:"-"` // 最大人数
MonthRank int `json:"monthRank" gorm:"-"` // 家族月排名
}
type GroupPowerUser struct {
......
......@@ -54,15 +54,14 @@ type CvGroupPowerStarData struct {
// 资源等级
type CvResGrade struct {
Grade groupPower_e.GroupPowerGrade `json:"grade"` // 等级
Icon string `json:"icon"` // 等级icon
BigIcon string `json:"bigIcon"` // 等级大图标
Grade groupPower_e.GroupPowerGrade `json:"grade"` // 等级
}
// 特权信息
type CvPrivilege struct {
Type groupPower_e.GroupPowerPrivilege `json:"type"` // 特权id 1:成员数 2:管理员数 3:家族铭牌 4:家族徽章装饰 5:编辑铭牌 6:家族头饰
Num int `json:"num"` // 数目
Icon string `json:"icon"` // 图标
}
// 家族等级页
......@@ -75,40 +74,40 @@ type CvGroupPowerGradeDetail struct {
}
var CvResGradeList = []CvResGrade{
{groupPower_e.GroupPowerGrade0, "青铜icon", "青铜bigIcon"}, // todo
{groupPower_e.GroupPowerGrade1, "白银icon", "白银bigIcon"}, // todo
{groupPower_e.GroupPowerGrade2, "黄金icon", "黄金bigIcon"}, // todo
{groupPower_e.GroupPowerGrade3, "黑金icon", "黑金bigIcon"}, // todo
{groupPower_e.GroupPowerGrade0},
{groupPower_e.GroupPowerGrade1},
{groupPower_e.GroupPowerGrade2},
{groupPower_e.GroupPowerGrade3},
}
var GroupPowerGradePrivilegeNum = map[groupPower_e.GroupPowerGrade][]CvPrivilege{
groupPower_e.GroupPowerGrade0: {
{groupPower_e.GroupPowerPrivilegeMemberNum, 300},
{groupPower_e.GroupPowerPrivilegeMgrNum, 10},
{groupPower_e.GroupPowerPrivilegeNameplate, 1},
{groupPower_e.GroupPowerPrivilegeMedal, 1},
{groupPower_e.GroupPowerPrivilegeMemberNum, 300, "https://image.whoisamy.shop/hilo/resource/family/users.png"},
{groupPower_e.GroupPowerPrivilegeMgrNum, 10, "https://image.whoisamy.shop/hilo/resource/family/gl_user.png"},
{groupPower_e.GroupPowerPrivilegeNameplate, 1, "https://image.whoisamy.shop/hilo/resource/family/nameplate_black.png"},
{groupPower_e.GroupPowerPrivilegeMedal, 1, "https://image.whoisamy.shop/hilo/resource/family/privilege_black.png"},
},
groupPower_e.GroupPowerGrade1: {
{groupPower_e.GroupPowerPrivilegeMemberNum, 500},
{groupPower_e.GroupPowerPrivilegeMgrNum, 15},
{groupPower_e.GroupPowerPrivilegeNameplate, 1},
{groupPower_e.GroupPowerPrivilegeMedal, 1},
{groupPower_e.GroupPowerPrivilegeNameplateEdit, 1},
{groupPower_e.GroupPowerPrivilegeMemberNum, 500, "https://image.whoisamy.shop/hilo/resource/family/users.png"},
{groupPower_e.GroupPowerPrivilegeMgrNum, 15, "https://image.whoisamy.shop/hilo/resource/family/gl_user.png"},
{groupPower_e.GroupPowerPrivilegeNameplate, 1, "https://image.whoisamy.shop/hilo/resource/family/nameplate_cyan.png"},
{groupPower_e.GroupPowerPrivilegeMedal, 1, "https://image.whoisamy.shop/hilo/resource/family/privilege_cyan.png"},
{groupPower_e.GroupPowerPrivilegeNameplateEdit, 1, "https://image.whoisamy.shop/hilo/resource/family/edit_cyan.png"},
},
groupPower_e.GroupPowerGrade2: {
{groupPower_e.GroupPowerPrivilegeMemberNum, 800},
{groupPower_e.GroupPowerPrivilegeMgrNum, 20},
{groupPower_e.GroupPowerPrivilegeNameplate, 1},
{groupPower_e.GroupPowerPrivilegeMedal, 1},
{groupPower_e.GroupPowerPrivilegeNameplateEdit, 1},
{groupPower_e.GroupPowerPrivilegeNameplateHeadwear, 1},
{groupPower_e.GroupPowerPrivilegeMemberNum, 800, "https://image.whoisamy.shop/hilo/resource/family/users.png"},
{groupPower_e.GroupPowerPrivilegeMgrNum, 20, "https://image.whoisamy.shop/hilo/resource/family/gl_user.png"},
{groupPower_e.GroupPowerPrivilegeNameplate, 1, "https://image.whoisamy.shop/hilo/resource/family/nameplate_white.png"},
{groupPower_e.GroupPowerPrivilegeMedal, 1, "https://image.whoisamy.shop/hilo/resource/family/privilege_white.png"},
{groupPower_e.GroupPowerPrivilegeNameplateEdit, 1, "https://image.whoisamy.shop/hilo/resource/family/edit_white.png"},
{groupPower_e.GroupPowerPrivilegeNameplateHeadwear, 1, "https://image.whoisamy.shop/hilo/resource/family/headwear_white.png"},
},
groupPower_e.GroupPowerGrade3: {
{groupPower_e.GroupPowerPrivilegeMemberNum, 1200},
{groupPower_e.GroupPowerPrivilegeMgrNum, 25},
{groupPower_e.GroupPowerPrivilegeNameplate, 1},
{groupPower_e.GroupPowerPrivilegeMedal, 1},
{groupPower_e.GroupPowerPrivilegeNameplateEdit, 1},
{groupPower_e.GroupPowerPrivilegeNameplateHeadwear, 1},
{groupPower_e.GroupPowerPrivilegeMemberNum, 1200, "https://image.whoisamy.shop/hilo/resource/family/users.png"},
{groupPower_e.GroupPowerPrivilegeMgrNum, 25, "https://image.whoisamy.shop/hilo/resource/family/gl_user.png"},
{groupPower_e.GroupPowerPrivilegeNameplate, 1, "https://image.whoisamy.shop/hilo/resource/family/nameplate_yellow.png"},
{groupPower_e.GroupPowerPrivilegeMedal, 1, "https://image.whoisamy.shop/hilo/resource/family/privilege_yellow.png"},
{groupPower_e.GroupPowerPrivilegeNameplateEdit, 1, "https://image.whoisamy.shop/hilo/resource/family/edit_yellow.png"},
{groupPower_e.GroupPowerPrivilegeNameplateHeadwear, 1,"https://image.whoisamy.shop/hilo/resource/family/headwear_yellow.png"},
},
}
......@@ -70,10 +70,13 @@ type CvUserDetail struct {
}
type GroupPower struct {
Id uint64 `json:"id"` // 群主所在的势力ID
Name string `json:"name"` // 群主所在的势力的名称
Nameplate string `json:"nameplate"` // 势力铭牌
Grade groupPower_e.GroupPowerGrade `json:"grade"` // 等级
Id uint64 `json:"id"` // 群主所在的势力ID
Icon string `json:"icon"` // 家族头像
Name string `json:"name"` // 群主所在的势力的名称
Nameplate string `json:"nameplate"` // 势力铭牌
Grade groupPower_e.GroupPowerGrade `json:"grade"` // 等级
MemberNum uint32 `json:"memberNum,omitempty"` // 当前成员数
MemberMax uint32 `json:"memberMax,omitempty"` // 成员上限
}
type CvUserTiny struct {
......@@ -321,13 +324,41 @@ func getUserDetails(model *domain.Model, users []*user_m.User, myUserId mysql.ID
if err != nil {
return nil, err
}
groupPowerUsers, err := groupPower_m.MGetGroupPowerUsers(model, gpIds)
if err != nil {
return nil, err
}
// 成员上限
groupPowerNames := make(map[mysql.ID]string, 0)
groupPowerInfos := make(map[mysql.ID]groupPower_m.GroupPowerInfo)
groupPowerGrades := make(map[mysql.ID]groupPower_m.GroupPowerGrade)
groupPowerMembers := make(map[mysql.ID][2]int) // 0->memberNum 1->memberLimit
for uid, gid := range groupPowers {
groupPowerNames[uid] = powerNames[gid]
groupPowerInfos[uid] = groupPowerInfoMap[gid]
groupPowerGrades[uid] = groupPowerGradeMap[gid]
var memberMax int
grade := groupPowerGradeMap[gid].Grade
if grade >= groupPower_e.GroupPowerGrade0 && grade <= groupPower_e.GroupPowerGradeMax {
if grade == groupPower_e.GroupPowerGrade0 {
memberMax = 300
}
if grade == groupPower_e.GroupPowerGrade1 {
memberMax = 500
}
if grade == groupPower_e.GroupPowerGrade2 {
memberMax = 800
}
if grade == groupPower_e.GroupPowerGrade3 {
memberMax = 1200
}
}
memberNum := len(groupPowerUsers[gid])
if memberNum > memberMax {
memberMax = memberNum
}
groupPowerMembers[uid] = [2]int{memberNum, memberMax}
}
up := user_m.UserProperty{}
......@@ -372,7 +403,7 @@ func getUserDetails(model *domain.Model, users []*user_m.User, myUserId mysql.ID
cvUserDetail, err := userToDetail(users[i], myUserId, userTradeUnion, likeMap, likeMeMap, rels,
vips[users[i].ID] != nil, vips[users[i].ID], svips[users[i].ID], headwear, ride,
wealthGradeMap, charmGradeMap, activeGradeMap, medals, medalInfo, rooms, groupPowers, groupPowerNames, groupPowerInfos, groupPowerGrades, nobles, superManagerMap)
wealthGradeMap, charmGradeMap, activeGradeMap, medals, medalInfo, rooms, groupPowers, groupPowerNames, groupPowerInfos, groupPowerGrades, groupPowerMembers, nobles, superManagerMap)
if err != nil {
return nil, err
}
......@@ -392,7 +423,7 @@ func userToDetail(user *user_m.User, myUserId mysql.ID, userTradeUnion *user_m.U
likeMeMap map[mysql.ID]bool, hvMap map[mysql.ID]Relation, isVip bool, vipExpireTime *int64, svip rpc.CvSvip, headwear *headwear_cv.CvHeadwear, ride property_cv.CvProperty,
wealthGradeMap map[mysql.ID]uint32, charmGradeMap map[mysql.ID]uint32, actityGradeMap map[mysql.ID]uint32,
medals map[uint64][]uint32, medalInfo map[uint64][]medal_cv.CvMedal, rooms map[mysql.ID]string,
powers map[mysql.ID]uint64, powerNames map[mysql.ID]string, groupPowerInfos map[mysql.ID]groupPower_m.GroupPowerInfo, powerGrades map[mysql.ID]groupPower_m.GroupPowerGrade, nobles map[mysql.ID]noble_m.UserNoble, superManagerMap map[uint64]bool) (*CvUserDetail, error) {
powers map[mysql.ID]uint64, powerNames map[mysql.ID]string, groupPowerInfos map[mysql.ID]groupPower_m.GroupPowerInfo, powerGrades map[mysql.ID]groupPower_m.GroupPowerGrade, groupPowerMembers map[mysql.ID][2]int, nobles map[mysql.ID]noble_m.UserNoble, superManagerMap map[uint64]bool) (*CvUserDetail, error) {
cvUserDetail := &CvUserDetail{
CvUserBase: CvUserBase{
Id: &user.ID,
......@@ -534,9 +565,12 @@ func userToDetail(user *user_m.User, myUserId mysql.ID, userTradeUnion *user_m.U
cvUserDetail.MyGroupPowerName = powerNames[user.ID]
cvUserDetail.GroupPower = GroupPower{
Id: groupPowerInfos[user.ID].ID,
Icon: groupPowerInfos[user.ID].Icon,
Name: groupPowerInfos[user.ID].Name,
Nameplate: groupPowerInfos[user.ID].Nameplate,
Grade: powerGrades[user.ID].Grade,
MemberNum: mysql.Num(groupPowerMembers[user.ID][0]),
MemberMax: mysql.Num(groupPowerMembers[user.ID][1]),
}
if n, ok := nobles[user.ID]; ok && n.Level > 0 {
cvUserDetail.Noble = noble_cv.CvNoble{
......@@ -700,6 +734,28 @@ func GetUserDetail(model *domain.Model, userId mysql.ID, myUserId mysql.ID) (*Cv
powerNames := map[mysql.ID]string{userId: groupPowerName}
groupPowerInfos, err := groupPower_m.MGetGroupPowerInfoMap(model, []mysql.ID{groupPowerId})
groupPowerGrades, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{groupPowerId})
groupPowerUsers, err := groupPower_m.MGetGroupPowerUsers(model, []mysql.ID{groupPowerId})
var memberMax int
grade := groupPowerGrades[groupPowerId].Grade
if grade >= groupPower_e.GroupPowerGrade0 && grade <= groupPower_e.GroupPowerGradeMax {
if grade == groupPower_e.GroupPowerGrade0 {
memberMax = 300
}
if grade == groupPower_e.GroupPowerGrade1 {
memberMax = 500
}
if grade == groupPower_e.GroupPowerGrade2 {
memberMax = 800
}
if grade == groupPower_e.GroupPowerGrade3 {
memberMax = 1200
}
}
memberNum := len(groupPowerUsers[groupPowerId])
if memberNum > memberMax {
memberMax = memberNum
}
groupPowerMembers := [2]int{memberNum, memberMax} // 0->memberNum 1->memberLimit
up := user_m.UserProperty{}
rides, err := up.BatchGet(mysql.Db, []uint64{userId})
......@@ -789,14 +845,14 @@ func GetUserDetail(model *domain.Model, userId mysql.ID, myUserId mysql.ID) (*Cv
return userToDetailOne(model, &user, myUserId, userTradeUnion, likeN > 0, likeMe > 0,
rel, isVip, expireTime, svip, headwear, ride, wealthUserScore.Grade, charmUserScore.Grade,
activityUserScore.Grade, medals[userId], medalInfo[userId], rooms[userId], powers[userId], powerNames[userId], groupPowerInfos[groupPowerId].Nameplate, groupPowerGrades[groupPowerId],
activityUserScore.Grade, medals[userId], medalInfo[userId], rooms[userId], powers[userId], powerNames[userId], groupPowerInfos[groupPowerId], groupPowerGrades[groupPowerId], groupPowerMembers,
noble, superManagerMap[userId], myGroups, phoneInfo, thirdList, cvCountryManager)
}
// 单用户版,简化参数
func userToDetailOne(model *domain.Model, user *user_m.User, myUserId mysql.ID, userTradeUnion *user_m.UserTradeUnion, isLike bool, likeMe bool, hvMap map[mysql.ID]Relation,
isVip bool, vipExpireTime *int64, svip rpc.CvSvip, headwear *headwear_cv.CvHeadwear, ride property_cv.CvProperty, wealthGrade uint32, charmGrade uint32, activityGrade uint32,
medals []uint32, medalInfo []medal_cv.CvMedal, room string, power uint64, powerName string, powerNameplate string, grade groupPower_m.GroupPowerGrade, noble *noble_m.UserNoble, isOfficialStaff bool,
medals []uint32, medalInfo []medal_cv.CvMedal, room string, power uint64, powerName string, powerInfo groupPower_m.GroupPowerInfo, grade groupPower_m.GroupPowerGrade, members [2]int, noble *noble_m.UserNoble, isOfficialStaff bool,
myGroups []group_m.GroupInfo, phoneInfo *user_m.UserPhoneInfo, thirdList []int8, countryManager *country_cv.CVCountryManager) (*CvUserDetail, error) {
room, err := group_m.ToTxGroupId(model, room)
......@@ -839,8 +895,11 @@ func userToDetailOne(model *domain.Model, user *user_m.User, myUserId mysql.ID,
GroupPower: GroupPower{
Id: power,
Name: powerName,
Nameplate: powerNameplate,
Icon: powerInfo.Icon,
Nameplate: powerInfo.Nameplate,
Grade: grade.Grade,
MemberNum: mysql.Num(members[0]),
MemberMax: mysql.Num(members[1]),
},
PhoneInfo: phoneInfo,
ThirdList: thirdList,
......
......@@ -2,7 +2,6 @@ package groupPower_m
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/common"
......@@ -42,9 +41,7 @@ func (this *GroupPower) Get(model *domain.Model) (*GroupPower, error) {
return nil, err
}
if grade.GroupPowerId > 0 {
group.Grade = mysql.Num(grade.Grade)
group.Exp = mysql.Num(grade.Exp)
group.NextExp = mysql.Num(grade.Exp)
group.Grade = grade.Grade
}
return group, nil
}
......@@ -119,22 +116,30 @@ func UpdateFamily(model *domain.Model, familyId uint64, name, nameplate, declara
if familyId == 0 || (name == "" && nameplate == "" && declaration == "" && icon == "") {
return nil
}
// 修改铭牌
if nameplate != "" {
sql := "UPDATE `group_power` a left join (SELECT ? `id` FROM group_power WHERE nameplate = ?) b on a.id = b.id SET a.`nameplate`=? where a.id=? and b.id is null;"
result := model.Db.Exec(sql, familyId, nameplate, nameplate, familyId)
if result.Error != nil {
return myerr.WrapErr(result.Error)
}
if result.RowsAffected <= 0 {
return myerr.WrapErr(bizerr.GroupPowerHaveChangeInfo)
}
return nil
}
db := model.Db.Model(GroupPower{})
updateMap := make(map[string]interface{})
if name != "" {
updateMap["name"] = name
}
if nameplate != "" {
updateMap["nameplate"] = nameplate
db = db.Where("not exists (select id from group_power where nameplate = ?)", nameplate)
}
if declaration != "" {
updateMap["declaration"] = declaration
}
if icon != "" {
updateMap["icon"] = icon
}
result := db.Where("id = ?", familyId).Updates(updateMap).Limit(1)
result := db.Where("group_power.id = ?", familyId).Updates(updateMap).Limit(1)
if result.Error != nil {
return myerr.WrapErr(result.Error)
}
......@@ -157,3 +162,12 @@ func IsExistsNameplate(model *domain.Model, nameplate string) bool {
}
return false
}
func GetMemberNum(model *domain.Model, familyId uint64) (int64, error) {
var count int64
err := model.Db.Model(GroupPowerUser{}).Where("group_power_id=?", familyId).Count(&count).Error
if err != nil {
return 0, err
}
return count, nil
}
......@@ -26,14 +26,12 @@ type GroupPower struct {
GroupUid mysql.Str
Name mysql.Str
Status groupPower_e.GroupPowerStatus
Nameplate mysql.Str // 铭牌
Declaration mysql.Str // 宣言
Icon mysql.Str // 头像
Grade mysql.Num `gorm:"-"` // 等级
Exp mysql.Num `gorm:"-"` // 当前经验值
NextExp mysql.Num `gorm:"-"` // 升到下一级需要的经验值
GradeName mysql.Str // 等级称号
GradeMedal mysql.Str // 等级勋章图片
Nameplate mysql.Str // 铭牌
Declaration mysql.Str // 宣言
Icon mysql.Str // 头像
GradeName mysql.Str // 等级称号
GradeMedal mysql.Str // 等级勋章图片
Grade groupPower_e.GroupPowerGrade `gorm:"-"`
}
type GroupPowerUser struct {
......
......@@ -237,7 +237,7 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID,
// 增加势力上麦时长-家族之星
// 事务操作
func IncrGroupPowerStarOnMic(model *domain.Model, groupPowerId, userId mysql.ID, joinMicTimestamp int64) error {
func IncrGroupPowerStarOnMicMonth(model *domain.Model, groupPowerId, userId mysql.ID, joinMicTimestamp int64) error {
return model.Transaction(func(model *domain.Model) error {
// 月统计
star, err := GetGroupPowerMonthStar(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive)
......@@ -255,7 +255,33 @@ func IncrGroupPowerStarOnMic(model *domain.Model, groupPowerId, userId mysql.ID,
curTs = month0Ts
}
score := nowTs - curTs
return IncrGroupPowerMonthStarScore(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), nowTs)
err = IncrGroupPowerMonthStarScore(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), nowTs)
return err
})
}
// 增加势力上麦时长-家族之星
// 事务操作
func IncrGroupPowerStarOnMicDay(model *domain.Model, groupPowerId, userId mysql.ID, joinMicTimestamp int64) error {
return model.Transaction(func(model *domain.Model) error {
// 日统计
star, err := GetGroupPowerDayStar(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive)
curTs := joinMicTimestamp
nowTs := time.Now().Unix()
day0Ts := now.BeginningOfDay().Unix()
if err != nil && err != gorm.ErrRecordNotFound {
return err
}
if star != nil && joinMicTimestamp < star.LastCalTs { // 加入的时间比上次计算时间小
curTs = star.LastCalTs
}
// 跨天
if curTs < day0Ts {
curTs = day0Ts
}
score := nowTs - curTs
err = IncrGroupPowerDayStarScore(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), nowTs)
return err
})
}
......
......@@ -3,7 +3,7 @@ package groupPower_m
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"hilo-group/_const/enum/groupPower_e"
"git.hilo.cn/hilo-common/utils"
)
type GroupPowerInfo struct {
......@@ -29,6 +29,7 @@ func MGetGroupPowerInfoMap(model *domain.Model, groupPowerIds []mysql.ID) (map[m
return res, err
}
for i, v := range rows {
rows[i].Icon = utils.MakeFullUrl(rows[i].Icon) // 拼接url
res[v.ID] = rows[i]
}
return res, nil
......@@ -57,13 +58,19 @@ func GetGroupPowerUser(model *domain.Model, groupPowerId mysql.ID) ([]*GroupPowe
return m[groupPowerId], nil
}
// 获取所有家族的主
func GetAllGroupPowerOwners(model *domain.Model) ([]mysql.ID, error) {
// 分批获取所有家族成员
func BatchGetAllGroupPowerUsers(model *domain.Model, lastId mysql.ID, limit int) ([]mysql.ID, mysql.ID, error) {
var res []GroupPowerUser
var userIds []mysql.ID
if err := model.DB().Model(GroupPowerUser{}).Select("user_id").
Where("role = ?", groupPower_e.GroupPowerUserRoleMgr).Find(&userIds).Error; err != nil {
model.Log.Errorf("GetAllGroupPowerOwners fail:%v", err)
return userIds, err
var nextLastId mysql.ID
if err := model.DB().Model(GroupPowerUser{}).
Where("id > ?", lastId).Order("id asc").Limit(limit).Find(&res).Error; err != nil {
model.Log.Errorf("BatchGetAllGroupPowerUsers fail:%v", err)
return userIds, 0, err
}
return userIds, nil
for _, v := range res {
userIds = append(userIds, v.UserId)
nextLastId = v.ID
}
return userIds, nextLastId, nil
}
......@@ -80,3 +80,11 @@ func OptGroupPowerApplyList(model *domain.Model, familyId uint64, pageSize, page
nextIdx, hasNext := common.PageNext(count, pageIndex, pageSize)
return rows, nextIdx, hasNext, nil
}
func DelGroupPowerApplyJoinNoDeal(model *domain.Model, userId uint64) error {
err := model.Db.Exec("delete from group_power_apply_join where user_id=? and is_accept = 0", userId).Error
if err != nil {
return myerr.WrapErr(err)
}
return nil
}
......@@ -3,6 +3,7 @@ package groupPower_m
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
)
type GroupPowerExpRank struct {
......@@ -25,3 +26,37 @@ func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit
}
return res, nil
}
// 获取我的家族经验排行榜
func GetMyGroupPowerExpRank(model *domain.Model, beginDate, endDate string, groupPowerId uint64) (GroupPowerExpRank, error) {
var res GroupPowerExpRank
if err := model.DB().Table("group_power_day_exp").Select("group_power_id,SUM(exp) as exp").
Where("date BETWEEN ? AND ? AND group_power_id = ?", beginDate, endDate, groupPowerId).Group("group_power_id").First(&res).Error; err != nil {
if err != gorm.ErrRecordNotFound {
model.Log.Errorf("GetMyGroupPowerExpRank fail:%v", err)
return res, err
}
return res, nil
}
return res, nil
}
// 获取我的家族月排名是多少,超过30则返回31
func GetGroupPowerExpRankById(model *domain.Model, beginDate, endDate string, limit int, groupPowerId uint64) (int, error) {
var res []GroupPowerExpRank
if err := model.DB().Table("group_power_day_exp").Select("group_power_id,SUM(exp) as exp").
Where("date BETWEEN ? AND ?", beginDate, endDate).Group("group_power_id").Order("exp DESC").Limit(limit).Find(&res).Error; err != nil {
model.Log.Errorf("GetMyGroupPowerExpRank fail:%v", err)
return 0, err
}
for i := range res {
res[i].Rank = i + 1
}
myRank := 31
for _, v := range res {
if v.GroupPowerId == groupPowerId {
myRank = v.Rank
}
}
return myRank, nil
}
......@@ -3,13 +3,14 @@ package groupPower_m
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/jinzhu/now"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"hilo-group/_const/enum/groupPower_e"
"time"
)
// 家族之星
// 家族之星-月
type GroupPowerMonthStar struct {
Month string
GroupPowerId mysql.ID
......@@ -21,6 +22,18 @@ type GroupPowerMonthStar struct {
UpdatedTime time.Time `gorm:"->"`
}
// 家族之星-日
type GroupPowerDayStar struct {
Date time.Time
GroupPowerId mysql.ID
UserId mysql.ID
Type groupPower_e.GroupPowerStarType
Score mysql.Num
LastCalTs int64
CreatedTime time.Time `gorm:"->"`
UpdatedTime time.Time `gorm:"->"`
}
// 增加家族之星分数
func IncrGroupPowerMonthStarScore(model *domain.Model, groupPowerId, userId mysql.ID, _type groupPower_e.GroupPowerStarType, score mysql.Num, lastCalTs int64) error {
month := time.Now().Format("200601")
......@@ -45,6 +58,40 @@ func IncrGroupPowerMonthStarScore(model *domain.Model, groupPowerId, userId mysq
return nil
}
// 增加家族之星分数
func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql.ID, _type groupPower_e.GroupPowerStarType, score mysql.Num, lastCalTs int64) error {
star := &GroupPowerDayStar{
Date: time.Now(),
GroupPowerId: groupPowerId,
UserId: userId,
Type: _type,
Score: score,
LastCalTs: lastCalTs,
}
if err := model.DB().Model(GroupPowerDayStar{}).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "date"}, {Name: "group_power_id"}, {Name: "user_id"}, {Name: "type"}},
DoUpdates: clause.Assignments(map[string]interface{}{
"score": gorm.Expr("score + ?", star.Score),
"last_cal_ts": lastCalTs,
}),
}).Create(star).Error; err != nil {
model.Log.Errorf("IncrGroupPowerDayStarScore fail:%v", err)
return err
}
return nil
}
// 获取家族之星分数
// 允许返回gorm.ErrRecordNotFound
func GetGroupPowerDayStar(model *domain.Model, groupPowerId, userId mysql.ID, _type groupPower_e.GroupPowerStarType) (*GroupPowerDayStar, error) {
res := new(GroupPowerDayStar)
date := time.Now()
if err := model.DB().Where("date = ? AND group_power_id = ? AND user_id = ? AND `type` = ?", date.Format("2006-01-02"), groupPowerId, userId, _type).First(res).Error; err != nil {
return nil, err
}
return res, nil
}
// 获取家族之星分数
// 允许返回gorm.ErrRecordNotFound
func GetGroupPowerMonthStar(model *domain.Model, groupPowerId, userId mysql.ID, _type groupPower_e.GroupPowerStarType) (*GroupPowerMonthStar, error) {
......@@ -68,18 +115,44 @@ func GetGroupPowerMonthStarRank(model *domain.Model, groupPowerId mysql.ID, _typ
return res, nil
}
// 获取家族之星排行
func GetGroupPowerStarRankPeriod(model *domain.Model, period string, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int) ([]*GroupPowerDayStar, error) {
var res []*GroupPowerDayStar
var startDate, endDate string
switch period {
case "day":
startDate, endDate = time.Now().Format("2006-01-02"), time.Now().Format("2006-01-02")
case "week":
startDate = now.BeginningOfWeek().Format("2006-01-02")
endDate = now.EndOfWeek().Format("2006-01-02")
case "month":
startDate = now.BeginningOfMonth().Format("2006-01-02")
endDate = now.EndOfMonth().Format("2006-01-02")
}
if err := model.DB().Model(GroupPowerDayStar{}).Where("date BETWEEN ? AND ? AND group_power_id = ? AND `type` = ?", startDate, endDate, groupPowerId, _type).
Select("user_id,SUM(score) as score").Group("user_id").
Order("score desc").Offset(offset).Limit(limit).Find(&res).Error; err != nil {
model.Log.Errorf("GetGroupPowerStarRankPeriod fail:%v", err)
return res, err
}
for i := range res {
res[i].Type = _type
}
return res, nil
}
// 获取家族之星三个排行榜的各自第一名
func GetGroupPowerMonthStartTop1(model *domain.Model, groupPowerId mysql.ID) ([]*GroupPowerMonthStar, error) {
var res []*GroupPowerMonthStar
r1, err := GetGroupPowerMonthStarRank(model, groupPowerId, groupPower_e.GroupPowerStarTypeFamous, 0, 1)
func GetGroupPowerMonthStartTop1(model *domain.Model, groupPowerId mysql.ID) ([]*GroupPowerDayStar, error) {
var res []*GroupPowerDayStar
r1, err := GetGroupPowerStarRankPeriod(model, "month", groupPowerId, groupPower_e.GroupPowerStarTypeFamous, 0, 1)
if err != nil {
return res, err
}
r2, err := GetGroupPowerMonthStarRank(model, groupPowerId, groupPower_e.GroupPowerStarTypeActive, 0, 1)
r2, err := GetGroupPowerStarRankPeriod(model, "month", groupPowerId, groupPower_e.GroupPowerStarTypeActive, 0, 1)
if err != nil {
return res, err
}
r3, err := GetGroupPowerMonthStarRank(model, groupPowerId, groupPower_e.GroupPowerStarTypeCharm, 0, 1)
r3, err := GetGroupPowerStarRankPeriod(model, "month", groupPowerId, groupPower_e.GroupPowerStarTypeCharm, 0, 1)
if err != nil {
return res, err
}
......
......@@ -8,10 +8,10 @@ import (
"github.com/bluele/gcache"
"gorm.io/gorm"
"hilo-group/_const/enum/group_e"
"hilo-group/common"
"hilo-group/myerr"
"hilo-group/myerr/bizerr"
"math/rand"
"sort"
"time"
)
......@@ -45,6 +45,7 @@ type GroupInfo struct {
MemberFee uint64 // 加入会员需要黄钻数
CreatedTime time.Time `gorm:"->"`
UpdatedTime time.Time `gorm:"->"`
VisitCount int64 `gorm:"-"` // 热度
}
func GenerateGroupCode(n uint16) string {
......@@ -516,18 +517,52 @@ func GetLatestGroupInfos(model *domain.Model, limit, lastId int, groupIds []stri
return
}
func GetFamilyRooms(model *domain.Model, familyId uint64, pageSize, pageIndex int) ([]*GroupInfo, int, bool, error) {
rows := make([]*GroupInfo, 0)
db := model.Db.Model(GroupInfo{}).Where("owner in (select user_id from group_power_user where group_power_id=? order by field(`role`, 2, 3, 1))", familyId)
func GetFamilyRooms(model *domain.Model, familyId uint64, pageSize, pageIndex int) (res []*GroupInfo, nextIdx int, hasNext bool, err error) {
allImGroupIds := make([]string, 0)
var count int64
err := db.Count(&count).Error
err = model.Db.Model(GroupInfo{}).Select("im_group_id").Where("owner in (select user_id from group_power_user where group_power_id=?)",
familyId).Pluck("im_group_id", &allImGroupIds).Count(&count).Error
if err != nil {
return nil, 0, false, err
}
// 房间热度排序
visitCountMap, visitCountList, err := BatchGetRoomVisitCountList(model.Log, allImGroupIds)
if err != nil {
return nil, 0, false, err
}
err = db.Limit(pageSize).Offset(pageIndex).Find(&rows).Error
roomNum := len(visitCountList)
if roomNum > pageIndex {
endIndex := pageIndex + pageSize
if roomNum >= endIndex {
visitCountList = visitCountList[pageIndex : pageIndex+pageSize]
if roomNum > endIndex {
nextIdx = endIndex
hasNext = true
}
} else {
visitCountList = visitCountList[pageIndex:]
}
} else {
return nil, 0, false, err
}
showImGroupIdList := make([]string, 0, len(visitCountList))
for _, v := range visitCountList {
showImGroupIdList = append(showImGroupIdList, v.ImGroupId)
}
res = make([]*GroupInfo, 0)
err = model.Db.Model(GroupInfo{}).Where("im_group_id in ?", showImGroupIdList).Find(&res).Error
if err != nil {
return nil, 0, false, err
}
nextIdx, hasNext := common.PageNext(count, pageIndex, pageSize)
return rows, nextIdx, hasNext, nil
for i, v := range res {
if c, ok := visitCountMap[v.ImGroupId]; ok {
res[i].VisitCount = c
}
}
sort.Slice(res, func(i, j int) bool {
return res[i].VisitCount > res[j].VisitCount
})
return res, nextIdx, hasNext, nil
}
......@@ -451,6 +451,47 @@ func BatchGetRoomVisitCount(logE *logrus.Entry, groupIds []string) (map[string]i
return visitCount, nil
}
type RoomVisit struct {
ImGroupId string
Count int64
}
// 批量查询房间最近N天的访问人数。使用二级缓存
func BatchGetRoomVisitCountList(logE *logrus.Entry, groupIds []string) (map[string]int64, []*RoomVisit, error) {
//roomVisitCount, err := redis.GetAllRoomVisitCount()
roomVisitCount, err := room_c.MGetRoomVisitCount(groupIds)
if err != nil {
return nil, nil, err
}
logE.Infof("MGetRoomVisitCount:%v", roomVisitCount)
res := make([]*RoomVisit, 0, len(groupIds))
visitCount := make(map[string]int64)
for _, groupId := range groupIds {
// 先从二级缓存中找
if c, ok := roomVisitCount[groupId]; ok {
if vc, err := strconv.ParseInt(c, 10, 64); err == nil && vc > 0 {
logE.Debugf("GetRoomVisitCount, from roomVisitCount %s - %d", groupId, vc)
visitCount[groupId] = vc
res = append(res, &RoomVisit{ImGroupId: groupId, Count: vc})
}
} else {
// 如果没有,就从roomVisit中取
if vc, err := room_c.GetSetRoomVisitCount(groupId); err == nil && vc > 0 {
logE.Infof("GetRoomVisitCount, from roomVisit %s - %d", groupId, vc)
visitCount[groupId] = vc
res = append(res, &RoomVisit{ImGroupId: groupId, Count: vc})
}
}
}
sort.Slice(res, func(i, j int) bool {
return res[i].Count >= res[j].Count
})
return visitCount, res, nil
}
type UserEnterRoom struct {
UserId uint64
GroupId string
......
......@@ -195,23 +195,36 @@ func GroupPowerEvents() {
// 势力等级即将过期
group_power_ev.AddGroupPowerExpireNoticeAsync(func(model *domain.Model, e interface{}) error {
model.Log.Infof("msg AddGroupPowerExpireNoticeAsync")
powerOwners, err := groupPower_m.GetAllGroupPowerOwners(model)
if err != nil {
model.Log.Errorf("AddGroupPowerExpireNoticeAsync fail:%v", err)
return err
}
userMaps, err := user_m.GetUserMapByIds(model, powerOwners)
if err != nil {
return err
}
for uid, u := range userMaps {
if err := msg_m.NewUserRecord(model, uid, msg_e.GroupPowerExpireNotice, "", 0, "", "", "", "", "").Persistent(); err != nil {
model.Log.Errorf("msg AddGroupPowerExpireNoticeAsync NewUserRecord err:%v", err)
return nil
start := time.Now()
model.Log.Infof("msg AddGroupPowerExpireNoticeAsync,start:%v", start)
lastId := mysql.ID(0)
for {
powerUsers, nextLastId, err := groupPower_m.BatchGetAllGroupPowerUsers(model, lastId, 500)
if err != nil {
model.Log.Errorf("AddGroupPowerExpireNoticeAsync fail:%v", err)
return err
}
msg_m.SendEmasMsgAssistant(model, u.ExternalId, u.DeviceType)
if len(powerUsers) <= 0 {
break
}
userMaps, err := user_m.GetUserMapByIds(model, powerUsers)
if err != nil {
return err
}
for uid, u := range userMaps {
if err := msg_m.NewUserRecord(model, uid, msg_e.GroupPowerExpireNotice, "", 0, "", "", "", "", "").Persistent(); err != nil {
model.Log.Errorf("msg AddGroupPowerExpireNoticeAsync NewUserRecord err:%v", err)
return nil
}
_ = msg_m.SendEmasMsgAssistant(model, u.ExternalId, u.DeviceType)
}
if nextLastId <= 0 {
break
}
lastId = nextLastId
time.Sleep(time.Second) // 停顿一秒
}
model.Log.Infof("msg AddGroupPowerExpireNoticeAsync,end:%v", time.Now().Sub(start).Seconds())
return nil
})
}
......@@ -493,6 +506,9 @@ func SendGift() {
if err := groupPower_m.IncrGroupPowerMonthStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeFamous, diamonds, 0); err != nil {
model.Log.Errorf("IncrGroupPowerMonthStarScore famous fail:%v", err)
}
if err := groupPower_m.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeFamous, diamonds, 0); err != nil {
model.Log.Errorf("IncrGroupPowerDayStarScore famous fail:%v", err)
}
}
// 收礼加分
for _, userId := range sendGiftEvent.ReceiveUserIds {
......@@ -501,6 +517,9 @@ func SendGift() {
if err := groupPower_m.IncrGroupPowerMonthStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeCharm, diamonds, 0); err != nil {
model.Log.Errorf("IncrGroupPowerMonthStarScore charm fail:%v", err)
}
if err := groupPower_m.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeCharm, diamonds, 0); err != nil {
model.Log.Errorf("IncrGroupPowerDayStarScore charm fail:%v", err)
}
}
}
return nil
......
......@@ -318,9 +318,13 @@ func (s *GroupMicService) IncrGroupPowerOnMicExpAndTime(groupId string, userId u
if err := groupPower_m.IncrGroupPowerExpOnMic(model, groupPowerId, userId, joinMicTimestamp); err != nil {
model.Log.Errorf("IncrGroupPowerExpOnMic fail:%v", err)
}
// 增加势力上麦时长
if err := groupPower_m.IncrGroupPowerStarOnMic(model, groupPowerId, userId, joinMicTimestamp); err != nil {
model.Log.Errorf("IncrGroupPowerOnMicTime fail:%v", err)
// 增加势力上麦时长-月
if err := groupPower_m.IncrGroupPowerStarOnMicMonth(model, groupPowerId, userId, joinMicTimestamp); err != nil {
model.Log.Errorf("IncrGroupPowerStarOnMicMonth fail:%v", err)
}
// 增加势力上麦时长-天
if err := groupPower_m.IncrGroupPowerStarOnMicDay(model, groupPowerId, userId, joinMicTimestamp); err != nil {
model.Log.Errorf("IncrGroupPowerStarOnMicDay fail:%v", err)
}
return nil
}
......@@ -63,7 +63,7 @@ require (
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.2.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/consul/api v1.7.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
......
......@@ -137,8 +137,9 @@ github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
......
......@@ -91,6 +91,8 @@ var (
GroupPowerCannotRepeated = myerr.NewBusinessCode(15018, "Cannot be repeated", myerr.BusinessData{}) // 不能重复
GroupPowerCannotQuit = myerr.NewBusinessCode(15019, "Cannot quit", myerr.BusinessData{}) // 不能退出
GroupPowerUserHaveNoJoin = myerr.NewBusinessCode(15020, "User have no joined power", myerr.BusinessData{}) // 还未加入国家势力
GroupPowerChangeNameplate = myerr.NewBusinessCode(15021, "Can only be modified at the silver level", myerr.BusinessData{}) // 修改铭牌不够等级
GroupPowerMemberMax = myerr.NewBusinessCode(15022, "The family size has reached the upper limit", myerr.BusinessData{}) // 家族人数达到上限
TaskHasAward = myerr.NewBusinessCode(19001, "task has award", myerr.BusinessData{})
......
ALTER TABLE hilo.group_power ADD nameplate varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' NOT NULL COMMENT '家族铭牌';
ALTER TABLE hilo.group_power ADD declaration varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' NOT NULL COMMENT '家族宣言';
ALTER TABLE hilo.group_power ADD icon varchar(200) DEFAULT '' NOT NULL COMMENT '家族头像';
update hilo.group_power set nameplate = id;
CREATE UNIQUE INDEX nameplate_IDX USING BTREE ON hilo.group_power (nameplate);
ALTER TABLE hilo.group_power ADD icon varchar(200) DEFAULT 'https://image.whoisamy.shop/hilo/resource/family_default.png' NOT NULL COMMENT '家族头像';
CREATE INDEX nameplate_IDX USING BTREE ON hilo.group_power (nameplate);
CREATE TABLE `group_power_invite_join` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
......@@ -42,4 +41,34 @@ CREATE TABLE `group_power_quit_log` (
KEY `user_id` (`user_id`) USING BTREE,
KEY `created_time` (`created_time`) USING BTREE,
KEY `mgr_id` (`mgr_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
\ No newline at end of file
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT INTO hilo.res_multi_text (msg_id, `language`, content)
VALUES (169, 'zh', '白银等级才可以修改'),
(169, 'en', 'Can only be modified at the silver level'),
(169, 'ar', 'لا يمكن تعديله إلا على المستوى الفضي'),
(169, 'tr', 'Yalnızca gümüş seviyesinde değiştirilebilir'),
(169, 'id', 'Hanya dapat dimodifikasi pada level perak'),
(169, 'ru', 'Можно модифицировать только на серебряном уровне'),
(169, 'ko', '실버 등급에서만 수정 가능'),
(169, 'pt', 'Só pode ser modificado no nível prata'),
(169, 'th', 'สามารถแก้ไขได้ที่ระดับซิลเวอร์เท่านั้น'),
(169, 'ca', 'Solo se puede modificar en el nivel plata.'),
(169, 'hi', 'केवल चांदी के स्तर पर संशोधित किया जा सकता है'),
(169, 'vi', 'Chỉ có thể được sửa đổi ở cấp độ bạc'),
(169, 'ur', 'صرف چاندی کی سطح پر نظر ثانی کی جا سکتی ہے');
INSERT INTO hilo.res_msg_translate (`language`, title, content, icon_url, msg_type, `type`, action_type, action_url)
VALUES ('zh', '', '你已加入家族,和朋友们一起快乐玩耍吧!', '', 1, 53, 0, ''),
('en', '', "You have joined the family, let's have fun with your friends!", '', 1, 53, 0, ''),
('ar', '', 'لقد انضممت إلى العائلة ، فلنستمتع مع أصدقائك!', '', 1, 53, 0, ''),
('tr', '', 'Aileye katıldınız, arkadaşlarınızla eğlenelim!', '', 1, 53, 0, ''),
('id', '', 'Anda telah bergabung dengan keluarga, mari bersenang-senang dengan teman-teman Anda!', '', 1, 53, 0,''),
('ru', '', 'Вы присоединились к семье, давайте веселиться с друзьями!', '', 1, 53, 0, ''),
('ko', '', '당신은 가족에 합류했습니다. 친구들과 즐거운 시간을 보내십시오!', '', 1, 53, 0, ''),
('pt', '', 'Você se juntou à família, vamos nos divertir com seus amigos!', '', 1, 53, 0, ''),
('th', '', 'คุณได้เข้าร่วมครอบครัวแล้ว มาสนุกกับเพื่อนๆ กันเถอะ!', '', 1, 53, 0, ''),
('ca', '', 'Te has unido a la familia, ¡diviértete con tus amigos!', '', 1, 53, 0, ''),
('hi', '', 'आप परिवार में शामिल हो गए हैं, आइए अपने दोस्तों के साथ मस्ती करें!', '', 1, 53, 0, ''),
('vi', '', 'Bạn đã tham gia gia đình, hãy vui vẻ với bạn bè của bạn!', '', 1, 53, 0, ''),
('ur', '', 'آپ خاندان میں شامل ہو گئے ہیں، آئیے اپنے دوستوں کے ساتھ مزے کریں!', '', 1, 53, 0, '');
......@@ -5,10 +5,15 @@ import (
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/sdk/aws"
"git.hilo.cn/hilo-common/sdk/tencentyun"
"git.hilo.cn/hilo-common/txop/msg"
"git.hilo.cn/hilo-common/utils"
"github.com/gin-gonic/gin"
"github.com/jinzhu/now"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/msg_e"
......@@ -742,11 +747,19 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) {
for _, v := range members {
resMembers = append(resMembers, &group_power_cv.GroupPowerUser{User: userMap[v.UserId], Role: v.Role})
}
groupPowerGrade, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{gp.ID})
gradeM, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{gp.ID})
if err != nil {
return myContext, err
}
grade := gradeM[gp.ID]
nextExp := groupPower_e.GroupPowerGradeExp[groupPower_e.GroupPowerGradeMax]
if grade.Grade != groupPower_e.GroupPowerGradeMax {
nextExp = groupPower_e.GroupPowerGradeExp[grade.Grade+1]
}
info := &group_power_cv.GroupPower{
Id: gpInfo.ID, Name: gpInfo.Name, Nameplate: gpInfo.Nameplate, Declaration: gpInfo.Declaration, Icon: gpInfo.Icon,
Grade: gpInfo.Grade, Exp: gpInfo.Exp, NextExp: gpInfo.NextExp, GradeName: gpInfo.GradeName, GradeMedal: gpInfo.GradeMedal,
MemberNum: mysql.Num(total), MemberMax: mysql.Num(group_power_cv.GroupPowerGradePrivilegeNum[groupPowerGrade[gp.ID].Grade][0].Num),
Grade: grade.Grade, Exp: grade.Exp, NextExp: nextExp, GradeName: gpInfo.GradeName, GradeMedal: gpInfo.GradeMedal,
MemberNum: mysql.Num(total), MemberMax: mysql.Num(group_power_cv.GroupPowerGradePrivilegeNum[grade.Grade][0].Num),
}
if info.Icon != "" {
info.Icon = common.MakeFullUrl(info.Icon)
......@@ -758,8 +771,17 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) {
}
if groupInfo != nil {
info.Nameplate = groupInfo.Name
if len(info.Nameplate) > 6 {
info.Nameplate = info.Nameplate[:6]
}
}
}
// 家族月排名
beginDate, endDate := now.BeginningOfMonth().Format("2006-01-02"), now.EndOfMonth().Format("2006-01-02")
info.MonthRank, err = groupPower_m.GetGroupPowerExpRankById(model, beginDate, endDate, 30, info.Id)
if err != nil {
return myContext, err
}
// 我在该家族中的角色
myPU := groupPower_m.GroupPowerUser{UserId: myUserId}
myGroupPUser, err := myPU.GetGroupPowerUser(model)
......@@ -770,7 +792,7 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) {
info.Role = int(myGroupPUser.Role)
} else {
// 是否申请了加入
apply, err := groupPower_m.GetGroupPowerApplyJoin(model, myUserId, info.Id, -1)
apply, err := groupPower_m.GetGroupPowerApplyJoin(model, myUserId, info.Id, 0)
if err != nil {
return myContext, err
}
......@@ -956,6 +978,15 @@ func GroupPowerApplyJoin(c *gin.Context) (*mycontext.MyContext, error) {
if len(uList) > 0 {
return myContext, bizerr.GroupPowerHasJoinOther
}
// 判断家族是否满人了
nowNum, err := groupPower_m.GetMemberNum(model, familyId)
if err != nil {
return myContext, myerr.WrapErr(err)
}
maxNum := group_power_cv.GroupPowerGradePrivilegeNum[gpInfo.Grade][0].Num
if nowNum+1 > int64(maxNum) {
return myContext, bizerr.GroupPowerMemberMax
}
// 插入申请表
err = groupPower_m.InsertGroupPowerApplyJoin(model, userId, gpInfo.ID)
......@@ -1027,6 +1058,20 @@ func GroupPowerApplyPass(c *gin.Context) (*mycontext.MyContext, error) {
resp.ResponseOk(c, nil)
return myContext, nil
}
// 判断家族是否满人了
nowNum, err := groupPower_m.GetMemberNum(model, apply.GroupPowerId)
if err != nil {
return myContext, myerr.WrapErr(err)
}
gradeM, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{apply.GroupPowerId})
if err != nil {
return myContext, err
}
grade := gradeM[apply.GroupPowerId]
maxNum := group_power_cv.GroupPowerGradePrivilegeNum[grade.Grade][0].Num
if int(nowNum+1) > maxNum {
return myContext, bizerr.GroupPowerMemberMax
}
err = model.Transaction(func(model *domain.Model) error {
txModel := domain.CreateModel(model.CtxAndDb)
......@@ -1037,16 +1082,36 @@ func GroupPowerApplyPass(c *gin.Context) (*mycontext.MyContext, error) {
txModel.Log.Errorf("GroupPowerApplyPass err:%v, info:%v", err, gpU)
return err
}
newNum, err := groupPower_m.GetMemberNum(txModel, apply.GroupPowerId)
if err != nil {
txModel.Log.Errorf("GroupPowerApplyPass err:%v, info:%v", err, gpU)
return err
}
if int(newNum) > maxNum {
txModel.Log.Errorf("GroupPowerApplyPass err:%v, info:%v", bizerr.GroupPowerMemberMax, gpU)
return bizerr.GroupPowerMemberMax
}
// 更改申请表状态
err = groupPower_m.OptGroupPowerApplyJoinById(model, apply.Id, userId, optType)
if err != nil {
return err
}
// 删除他在其他家族未处理的申请
err = groupPower_m.DelGroupPowerApplyJoinNoDeal(model, apply.UserId)
if err != nil {
return err
}
return nil
})
if err != nil {
return myContext, err
}
// 发小助手通知用户
err = msg.SendLittleAssistantMsg(model, apply.UserId, msg_e.GroupPowerWelcomeJoin, "", "", "", "", "")
if err != nil {
model.Log.Errorf("GroupPowerApplyPass msg err:%v", err)
}
resp.ResponseOk(c, nil)
return myContext, nil
......@@ -1072,6 +1137,9 @@ func GroupPowerApplyList(c *gin.Context) (*mycontext.MyContext, error) {
if err != nil {
return myContext, err
}
if pageIndex == 1 {
pageIndex = 0
}
model := domain.CreateModelContext(myContext)
// 判断是否加入了家族
......@@ -1222,6 +1290,9 @@ func GroupPowerQuitList(c *gin.Context) (*mycontext.MyContext, error) {
if err != nil {
return myContext, err
}
if pageIndex == 1 {
pageIndex = 0
}
model := domain.CreateModelContext(myContext)
// 判断是否加入了家族
......@@ -1318,6 +1389,9 @@ func GroupPowerSetAdmin(c *gin.Context) (*mycontext.MyContext, error) {
if optGroupPUser == nil {
return myContext, bizerr.GroupPowerUserHaveNoJoin
}
if optUser.ID == userId { // 不能操作自己
return myContext, bizerr.GroupPowerHaveNoPower
}
// 目标身份
var targetRole groupPower_e.GroupPowerUserRole
if optType == 1 {
......@@ -1330,7 +1404,7 @@ func GroupPowerSetAdmin(c *gin.Context) (*mycontext.MyContext, error) {
return myContext, bizerr.GroupPowerHaveAlreadyChange
}
// 变更
err = groupPower_m.UpdateFamilyAdmin(model, userId, optGroupPUser.GroupPowerId, targetRole)
err = groupPower_m.UpdateFamilyAdmin(model, optGroupPUser.UserId, optGroupPUser.GroupPowerId, targetRole)
if optGroupPUser == nil {
return myContext, myerr.WrapErr(err)
}
......@@ -1350,7 +1424,7 @@ func GroupPowerSetAdmin(c *gin.Context) (*mycontext.MyContext, error) {
// @Router /v1/groupPower/info/set [post]
func GroupPowerSetInfo(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys)
userId, err := req.GetUserId(c)
userId, lang, err := req.GetUserIdLang(c, myContext)
if err != nil {
return myContext, err
}
......@@ -1386,22 +1460,40 @@ func GroupPowerSetInfo(c *gin.Context) (*mycontext.MyContext, error) {
// 检查铭牌是否能够修改
if para.Nameplate != "" {
// 等级检查
gp := &groupPower_m.GroupPower{Entity: mysql.Entity{ID: myGroupPUser.GroupPowerId}}
groupPInfo, err := gp.Get(model)
gradeM, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{myGroupPUser.GroupPowerId})
if err != nil {
return myContext, err
}
if groupPInfo.Grade < 1 {
return myContext, bizerr.GroupPowerHaveNoPower
grade := gradeM[myGroupPUser.GroupPowerId]
if grade.Grade < 1 {
return myContext, res_m.GetErrByLanguage(model.Db, common.MSG_ID_SET_FAMILY_NAMEPL, lang, bizerr.GroupPowerChangeNameplate)
}
// 检查铭牌长度和唯一性
if len(para.Nameplate) > 10 {
if len(para.Nameplate) > 6 {
return myContext, bizerr.GroupPowerHaveTooLong
}
if groupPower_m.IsExistsNameplate(model, para.Nameplate) {
return myContext, bizerr.GroupPowerCannotRepeated
}
}
if para.Icon != "" {
switch config.GetConfigApp().MODERATE {
case "AWS":
passed, err := aws.ModerateLabels(model.Log, userId, para.Icon)
if err == nil {
if !passed {
return myContext, bizerr.ImagePolicyViolation
}
} else {
model.Log.Warnf("ModerateLabels err:%v", err)
}
case "TENCENT":
label, err := tencentyun.ModerateImage(model, userId, "", utils.StripAwsPrefix(para.Icon), para.Icon)
if err == nil && label != "Pass" {
return myContext, bizerr.ImagePolicyViolation
}
}
}
// 修改家族信息
err = groupPower_m.UpdateFamily(model, para.Id, para.Name, para.Nameplate, para.Declaration, para.Icon)
......@@ -1420,9 +1512,18 @@ func GroupPowerSetInfo(c *gin.Context) (*mycontext.MyContext, error) {
return myContext, myerr.WrapErr(err)
}
groupPowerGrade, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{gp.ID})
gradeM, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{gp.ID})
if err != nil {
return myContext, err
}
grade := gradeM[gp.ID]
nextExp := groupPower_e.GroupPowerGradeExp[groupPower_e.GroupPowerGradeMax]
if grade.Grade != groupPower_e.GroupPowerGradeMax {
nextExp = groupPower_e.GroupPowerGradeExp[grade.Grade+1]
}
info := &group_power_cv.GroupPower{
Id: gpInfo.ID, Name: gpInfo.Name, Nameplate: gpInfo.Nameplate, Declaration: gpInfo.Declaration, Icon: gpInfo.Icon,
Grade: gpInfo.Grade, Exp: gpInfo.Exp, NextExp: gpInfo.NextExp, GradeName: gpInfo.GradeName, GradeMedal: gpInfo.GradeMedal,
Grade: grade.Grade, Exp: grade.Exp, NextExp: nextExp, GradeName: gpInfo.GradeName, GradeMedal: gpInfo.GradeMedal,
MemberNum: mysql.Num(total), MemberMax: mysql.Num(group_power_cv.GroupPowerGradePrivilegeNum[groupPowerGrade[gp.ID].Grade][0].Num),
}
if info.Icon != "" {
......
......@@ -24,7 +24,7 @@ import (
// @Param token header string true "token"
// @Param nonce header string true "随机数字"
// @Param period path string true "榜单周期 day:日 week:周 month:月"
// @Success 200 {object} group_power_cv.CvGroupPowerRank
// @Success 200 {object} []group_power_cv.CvGroupPowerRank
// @Router /v1/groupPower/rank/{period} [get]
func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys)
......@@ -70,21 +70,28 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
if err != nil {
return myContext, err
}
if myGroupPower != nil {
myGroupPowerRank, err := groupPower_m.GetMyGroupPowerExpRank(model, beginDate, endDate, myGroupPower.GroupPowerId)
if err != nil {
return myContext, err
}
response.MyGroupPower = &group_power_cv.CvGroupPowerRankData{
CvGroupPowerBase: group_power_cv.CvGroupPowerBase{
Id: myGroupPower.GroupPowerId,
Icon: groupPowers[myGroupPower.GroupPowerId].Icon,
Name: groupPowers[myGroupPower.GroupPowerId].Name,
Nameplate: groupPowers[myGroupPower.GroupPowerId].Nameplate,
},
CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{
Grade: grades[myGroupPower.GroupPowerId].Grade,
Exp: myGroupPowerRank.Exp,
},
Rank: 0,
}
}
for _, v := range rank {
if myGroupPower != nil && v.GroupPowerId == myGroupPower.GroupPowerId && myGroupPower.Role == groupPower_e.GroupPowerUserRoleMgr {
response.MyGroupPower = &group_power_cv.CvGroupPowerRankData{
CvGroupPowerBase: group_power_cv.CvGroupPowerBase{
Id: myGroupPower.GroupPowerId,
Icon: groupPowers[myGroupPower.GroupPowerId].Icon,
Name: groupPowers[myGroupPower.GroupPowerId].Name,
Nameplate: groupPowers[myGroupPower.GroupPowerId].Nameplate,
},
CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{
Grade: grades[myGroupPower.GroupPowerId].Grade,
Exp: v.Exp,
},
Rank: v.Rank,
}
if response.MyGroupPower != nil && v.GroupPowerId == response.MyGroupPower.Id {
response.MyGroupPower.Rank = v.Rank
}
response.Items = append(response.Items, group_power_cv.CvGroupPowerRankData{
CvGroupPowerBase: group_power_cv.CvGroupPowerBase{
......@@ -107,6 +114,64 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
return myContext, nil
}
// @Tags 国家势力
// @Summary 家族日周月榜单top3
// @Param token header string true "token"
// @Param nonce header string true "随机数字"
// @Success 200 {object} map[string][]group_power_cv.CvGroupPowerRankData
// @Router /v1/groupPower/rankTop [get]
func GroupPowerRankTop(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys)
periods := []string{"day", "week", "month"}
var response = make(map[string][]group_power_cv.CvGroupPowerRankData)
for _, period := range periods {
var beginDate, endDate string
switch period {
case "day":
beginDate, endDate = time.Now().Format("2006-01-02"), time.Now().Format("2006-01-02")
case "week":
beginDate, endDate = utils.GetMonday(time.Now()).Format("2006-01-02"), utils.GetMonday(time.Now()).AddDate(0, 0, 6).Format("2006-01-02")
case "month":
beginDate, endDate = now.BeginningOfMonth().Format("2006-01-02"), now.EndOfMonth().Format("2006-01-02")
}
var model = domain.CreateModelContext(myContext)
rank, err := groupPower_m.GetGroupPowerExpRank(model, beginDate, endDate, 3)
if err != nil {
return myContext, err
}
var ids []mysql.ID
for _, g := range rank {
ids = append(ids, g.GroupPowerId)
}
grades, err := groupPower_m.MGetGroupPowerGrade(model, ids)
if err != nil {
return myContext, err
}
groupPowers, err := groupPower_m.MGetGroupPowerInfoMap(model, ids)
if err != nil {
return myContext, err
}
for _, v := range rank {
response[period] = append(response[period], group_power_cv.CvGroupPowerRankData{
CvGroupPowerBase: group_power_cv.CvGroupPowerBase{
Id: v.GroupPowerId,
Icon: groupPowers[v.GroupPowerId].Icon,
Name: groupPowers[v.GroupPowerId].Name,
Nameplate: groupPowers[v.GroupPowerId].Nameplate,
},
CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{
Grade: grades[v.GroupPowerId].Grade,
Exp: v.Exp,
},
Rank: v.Rank,
})
}
}
resp.ResponseOk(c, response)
return myContext, nil
}
type GroupPowerStarReq struct {
GroupPowerId mysql.ID `form:"groupPowerId" binding:"required"`
Type groupPower_e.GroupPowerStarType `form:"type" binding:"required"`
......@@ -150,6 +215,76 @@ func GroupPowerStar(c *gin.Context) (*mycontext.MyContext, error) {
users, err := user_m.GetUserMapByIds(model, userIds)
for _, row := range rank {
user := users[row.UserId]
score := row.Score
if param.Type == groupPower_e.GroupPowerStarTypeActive {
score = score / 60
}
if score <= 0 {
continue
}
response = append(response, group_power_cv.CvGroupPowerStarData{
User: user_cv.CvUserTiny{
Id: user.ID,
ExternalId: user.ExternalId,
Code: user.Code,
Nick: user.Nick,
Avatar: user.Avatar,
},
Score: score,
})
}
resp.ResponsePageBaseOk(c, response, 0, false)
return myContext, nil
}
// @Tags 国家势力
// @Summary 家族之星
// @Param token header string true "token"
// @Param nonce header string true "随机数字"
// @Param period path string true "周期 day|week|month"
// @Param groupPowerId query int true "家族id"
// @Param type query integer true "类型 1:送礼 2:活跃 3:收礼物"
// @Param pageSize query int false "分页大小 默认:30" default(30)
// @Param pageIndex query int false "第几个分页,从1开始 默认:1" default(1)
// @Success 200 {object} []group_power_cv.CvGroupPowerStarData
// @Router /v1/groupPower/star/{period} [get]
func GroupPowerStarPeriod(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys)
param := new(GroupPowerStarReq)
if err := c.ShouldBindQuery(param); err != nil {
return myContext, err
}
if param.PageIndex <= 0 {
param.PageIndex = 1
}
if param.PageSize <= 0 {
param.PageSize = 30
}
period := c.Param("period")
if period != "day" && period != "week" && period != "month" {
return myContext, bizerr.InvalidParameter
}
var model = domain.CreateModelContext(myContext)
offset, limit := (param.PageIndex-1)*param.PageSize, param.PageSize
rank, err := groupPower_m.GetGroupPowerStarRankPeriod(model, period, param.GroupPowerId, param.Type, offset, limit)
if err != nil {
return myContext, err
}
var response []group_power_cv.CvGroupPowerStarData
var userIds []mysql.ID
for _, row := range rank {
userIds = append(userIds, row.UserId)
}
users, err := user_m.GetUserMapByIds(model, userIds)
for _, row := range rank {
user := users[row.UserId]
score := row.Score
if param.Type == groupPower_e.GroupPowerStarTypeActive {
score = score / 60
}
if score <= 0 {
continue
}
response = append(response, group_power_cv.CvGroupPowerStarData{
User: user_cv.CvUserTiny{
Id: user.ID,
......@@ -158,7 +293,7 @@ func GroupPowerStar(c *gin.Context) (*mycontext.MyContext, error) {
Nick: user.Nick,
Avatar: user.Avatar,
},
Score: row.Score,
Score: score,
})
}
resp.ResponsePageBaseOk(c, response, 0, false)
......@@ -196,18 +331,21 @@ func GroupPowerGradeDetail(c *gin.Context) (*mycontext.MyContext, error) {
return myContext, bizerr.GroupNotFound
}
grade := gradeM[groupPowerId]
nextExp := mysql.Num(0)
nextExp := groupPower_e.GroupPowerGradeExp[groupPower_e.GroupPowerGradeMax]
if grade.Grade != groupPower_e.GroupPowerGradeMax {
nextExp = groupPower_e.GroupPowerGradeExp[grade.Grade+1]
}
expireAt := ""
if grade.ExpireAt.After(time.Now()) {
expireAt = grade.ExpireAt.Format("2006-01-02")
expireAt = grade.ExpireAt.Add(-time.Second).Format("2006-01-02") // 减少一秒格式化天
}
if grade.Grade == groupPower_e.GroupPowerGrade0 {
expireAt = utils.AddDate(now.EndOfMonth(), 0, 1).Add(-time.Second).Format("2006-01-02") // 0级别(黑铁) 没有有效期,给下个月月底
}
isMember := false
if exits, _, err := groupPower_m.CheckGroupPowerUser(model, userId); err != nil {
if exits, id, err := groupPower_m.CheckGroupPowerUser(model, userId); err != nil {
return myContext, err
} else if exits {
} else if exits && id == groupPowerId {
isMember = true
}
response := group_power_cv.CvGroupPowerGradeDetail{
......
......@@ -77,10 +77,10 @@ func MGetGroupPowers(c *gin.Context) (*mycontext.MyContext, error) {
func Test(c *gin.Context) (*mycontext.MyContext, error) {
var model = domain.CreateModelNil()
if err := msg_m.NewUserRecord(model, 4522, msg_e.GroupPowerUserJoin, "frozen", 4522, "", "", "", "", "").Persistent(); err != nil {
if err := msg_m.NewUserRecord(model, 4549, msg_e.GroupPowerExpireNotice, "", 4549, "", "", "", "", "").Persistent(); err != nil {
return nil, err
}
mgrUser, _ := user_m.GetUser(model, 4522)
mgrUser, _ := user_m.GetUser(model, 4549)
err := msg_m.SendEmasMsgAssistant(model, mgrUser.ExternalId, mgrUser.DeviceType)
if err != nil {
return nil, err
......
......@@ -137,7 +137,9 @@ func InitRouter() *gin.Engine {
groupPower.GET("/quit/list", wrapper(group_power_r.GroupPowerQuitList))
groupPower.POST("/admin", wrapper(group_power_r.GroupPowerSetAdmin))
groupPower.GET("/rank/:period", wrapper(group_power_r.GroupPowerRank))
groupPower.GET("/rankTop", wrapper(group_power_r.GroupPowerRankTop))
groupPower.GET("/star", wrapper(group_power_r.GroupPowerStar))
groupPower.GET("/star/:period", wrapper(group_power_r.GroupPowerStarPeriod))
groupPower.POST("/info/set", wrapper(group_power_r.GroupPowerSetInfo))
}
h5GroupPower := v1.Group("/h5/groupPower")
......
......@@ -7,6 +7,11 @@ import (
)
func TestGetAllGroupPowerOwner(t *testing.T) {
owners, err := groupPower_m.GetAllGroupPowerOwners(domain.CreateModelNil())
owners, err := groupPower_m.BatchGetAllGroupPowerUsers(domain.CreateModelNil())
println(owners, err)
}
func TestGetGroupPowerMonthStartTop1(t *testing.T) {
res, err := groupPower_m.GetGroupPowerMonthStartTop1(domain.CreateModelNil(), 250)
println(res,err)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment