...
 
Commits (20)
...@@ -12,8 +12,9 @@ func Init() { ...@@ -12,8 +12,9 @@ func Init() {
if !config.IsMaster() { if !config.IsMaster() {
return return
} }
gift_cron.SendGiftEventInit() // 礼物消息 //gift_cron.SendGiftEventInit() // 礼物消息
gift_cron.GiftRemark() // 礼物消息补偿 //gift_cron.GiftRemark() // 礼物消息补偿
gift_cron.SendGiftEvent() // 送礼事件
cp_cron.ClearCpExpire() // 清理过期cp cp_cron.ClearCpExpire() // 清理过期cp
cp_cron.CpAnniversaryNotice() // cp纪念日 cp_cron.CpAnniversaryNotice() // cp纪念日
cp_cron.CpInviteCancelInit() // cp邀请、解除到期结算 cp_cron.CpInviteCancelInit() // cp邀请、解除到期结算
......
package gift_cron
import (
"git.hilo.cn/hilo-common/domain"
"github.com/jinzhu/now"
"hilo-user/_const/enum/cp_e"
"hilo-user/domain/cache/gift_c"
"hilo-user/domain/event/gift_ev"
"hilo-user/domain/model/cp_m"
"time"
)
// 送礼事件
func SendGiftEvent() {
//if !config.IsMaster() {
// return
//}
go func() {
for true {
model := domain.CreateModelNil()
if sendGiftEvent := gift_c.BLPopQueueSendGift(model); sendGiftEvent != nil {
cpGiftEvent(model, sendGiftEvent) // cp送礼
}
}
}()
}
// 送礼增加cp等级
// 送礼增加cp排行榜
func cpGiftEvent(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
// 只处理cp礼物
if !sendGiftEvent.ResGift.Cp {
return
}
for _, receiverUid := range sendGiftEvent.ReceiveUserIds {
diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum
// 有cp关系
if cpRelation, exits := cp_m.GetCpRelationPair(model, sendGiftEvent.SendUserId, receiverUid); exits {
if err := cp_m.AddCpLevelPoints(model, cpRelation, diamonds, sendGiftEvent.SceneType, sendGiftEvent.SceneUid); err != nil {
model.Log.Errorf("AddCpLevelPoints fail:%v", err)
}
if err := cp_m.AddCpDayRank(model, cpRelation, diamonds); err != nil {
model.Log.Errorf("AddCpDayRank fail:%v", err)
}
// 检查最新的等级
if cpLevel := cp_m.GetCpLevel(model, cpRelation.Id); cpLevel.CpId >= 0 {
points := cpLevel.Points + cp_e.CpLevelPoints[cpLevel.Level]
if err := cp_m.UpdateCpAchievement(model, cpLevel.CpId, cpRelation.UserId1, cpRelation.UserId2, cp_e.CpAchievementLevel, points); err != nil {
model.Log.Errorf("UpdateCpAchievement fail:%v", err)
}
}
// 检查最高的分数
for _, queryType := range []string{"day", "week", "month"} {
var beginDate, endDate string
var cpAchievementType cp_e.CpAchievement
switch queryType {
case "day":
beginDate, endDate = time.Now().Format("2006-01-02"), time.Now().Format("2006-01-02")
cpAchievementType = cp_e.CpAchievementDayRank
case "week":
beginDate = now.BeginningOfWeek().Format("2006-01-02")
endDate = now.EndOfWeek().Format("2006-01-02")
cpAchievementType = cp_e.CpAchievementWeekRank
case "month":
beginDate = now.BeginningOfMonth().Format("2006-01-02")
endDate = now.EndOfMonth().Format("2006-01-02")
cpAchievementType = cp_e.CpAchievementMonthRank
}
if data := cp_m.GetCpDayRank(model, beginDate, endDate, cpRelation.Id); data.Score > 0 {
if err := cp_m.UpdateCpAchievement(model, cpRelation.Id, cpRelation.UserId1, cpRelation.UserId2, cpAchievementType, data.Score); err != nil {
model.Log.Errorf("UpdateCpAchievement fail:%v", err)
}
}
}
// 检查最新日周月榜单
return // 业务场景允许提前break(cp是唯一的)
}
}
}
...@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code ...@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code
[REDIS] [REDIS]
REDIS_HOST=47.244.34.27:6379 REDIS_HOST=47.244.34.27:6379
REDIS_PASSWORD=8QZ9JD1zLvPR3yHf REDIS_PASSWORD=8QZ9JD1zLvPR3yHf
REDIS_CLUSTER_HOST=47.244.34.27:6379
REDIS_CLUSTER_PASSWORD=8QZ9JD1zLvPR3yHf
[JWT] [JWT]
SECRET=hilo1632 SECRET=hilo1632
ISSUER_API=hiloApi ISSUER_API=hiloApi
......
package gift_c
import (
"encoding/json"
"git.hilo.cn/hilo-common/domain"
"github.com/go-redis/redis/v8"
"hilo-user/domain/event/gift_ev"
"time"
)
const EventSendGiftHiloUserQueue = "send:gift:queue:hilo_user"
// redis pop event sendGift
func BLPopQueueSendGift(model *domain.Model) *gift_ev.SendGiftEvent {
var res *gift_ev.SendGiftEvent
queue := EventSendGiftHiloUserQueue
strs, err := model.RedisCluster.BLPop(model, time.Second, queue).Result()
if err != nil {
if err != redis.Nil {
model.Log.Errorf("BLPopQueueSendGift fail:%v", err)
}
return nil
}
if len(strs) >= 2 {
content := strs[1]
res = new(gift_ev.SendGiftEvent)
if err := json.Unmarshal([]byte(content), res); err != nil {
model.Log.Errorf("BLPopQueueSendGift json fail:%v", err)
return nil
}
return res
}
return nil
}
...@@ -27,7 +27,7 @@ func SetJSON(model *domain.Model, key string, obj interface{}) (err error) { ...@@ -27,7 +27,7 @@ func SetJSON(model *domain.Model, key string, obj interface{}) (err error) {
if err != nil { if err != nil {
return err return err
} }
return model.Redis.Set(model.Context, key, value, DEFAULT_TTL).Err() return model.RedisCluster.Set(model.Context, key, value, DEFAULT_TTL).Err()
} }
// 获取redis中json结构体 // 获取redis中json结构体
...@@ -37,7 +37,7 @@ func GetJSON(model *domain.Model, key string, obj interface{}) (err error) { ...@@ -37,7 +37,7 @@ func GetJSON(model *domain.Model, key string, obj interface{}) (err error) {
defer func() { defer func() {
model.Log.Infof("GetJson key:%v,value:%s,obj:%v,err:%v", key, value, obj, err) model.Log.Infof("GetJson key:%v,value:%s,obj:%v,err:%v", key, value, obj, err)
}() }()
value, err = model.Redis.Get(model.Context, key).Bytes() value, err = model.RedisCluster.Get(model.Context, key).Bytes()
if err != nil { if err != nil {
// may redisV2.Nil // may redisV2.Nil
return return
...@@ -59,7 +59,7 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time ...@@ -59,7 +59,7 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time
if time.Now().After(deadline) { if time.Now().After(deadline) {
return false return false
} }
flag, err := model.Redis.SetNX(model, key, "1", expireTimeout).Result() flag, err := model.RedisCluster.SetNX(model, key, "1", expireTimeout).Result()
if err != nil || !flag { if err != nil || !flag {
time.Sleep(time.Millisecond * 10) time.Sleep(time.Millisecond * 10)
} else { } else {
...@@ -70,5 +70,5 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time ...@@ -70,5 +70,5 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time
// 解锁 // 解锁
func UnLock(model *domain.Model, key string) { func UnLock(model *domain.Model, key string) {
model.Redis.Del(model, key) model.RedisCluster.Del(model, key)
} }
...@@ -53,7 +53,7 @@ func ToUserId(model *domain.Model, externalId mysql.Str) (mysql.ID, error) { ...@@ -53,7 +53,7 @@ func ToUserId(model *domain.Model, externalId mysql.Str) (mysql.ID, error) {
if externalId == "" { if externalId == "" {
return 0, myerr.NewSysError("externalId 不能为空") return 0, myerr.NewSysError("externalId 不能为空")
} }
userId, err := model.Redis.Get(model.Context, user_k.GetExternalIdToUidKey(externalId)).Int64() userId, err := model.RedisCluster.Get(model.Context, user_k.GetExternalIdToUidKey(externalId)).Int64()
if err != nil && err != redisV8.Nil { if err != nil && err != redisV8.Nil {
return 0, err return 0, err
} }
...@@ -76,7 +76,7 @@ func ToUserIdByCode(model *domain.Model, code mysql.Str) (mysql.ID, error) { ...@@ -76,7 +76,7 @@ func ToUserIdByCode(model *domain.Model, code mysql.Str) (mysql.ID, error) {
if code == "" { if code == "" {
return 0, myerr.NewSysError("code 不能为空") return 0, myerr.NewSysError("code 不能为空")
} }
userId, err := model.Redis.Get(model.Context, user_k.GetCodeToUidKey(code)).Int64() userId, err := model.RedisCluster.Get(model.Context, user_k.GetCodeToUidKey(code)).Int64()
if err != nil && err != redisV8.Nil { if err != nil && err != redisV8.Nil {
return 0, err return 0, err
} }
...@@ -105,11 +105,11 @@ func cacheUserTiny(model *domain.Model, user *user_m.User) error { ...@@ -105,11 +105,11 @@ func cacheUserTiny(model *domain.Model, user *user_m.User) error {
// return err // return err
//} //}
// cache externalId->userId // cache externalId->userId
if err := model.Redis.SetEX(model.Context, user_k.GetExternalIdToUidKey(user.ExternalId), user.ID, cache.GetDefaultTTL()).Err(); err != nil { if err := model.RedisCluster.SetEX(model.Context, user_k.GetExternalIdToUidKey(user.ExternalId), user.ID, cache.GetDefaultTTL()).Err(); err != nil {
return err return err
} }
// cache code->userId // cache code->userId
if err := model.Redis.SetEX(model.Context, user_k.GetCodeToUidKey(user.Code), user.ID, cache.GetDefaultTTL()).Err(); err != nil { if err := model.RedisCluster.SetEX(model.Context, user_k.GetCodeToUidKey(user.Code), user.ID, cache.GetDefaultTTL()).Err(); err != nil {
return err return err
} }
if err := cache.SetJSON(model, user_k.GetUserTinyKey(user.ID), userTiny); err != nil { if err := cache.SetJSON(model, user_k.GetUserTinyKey(user.ID), userTiny); err != nil {
......
package common package common
import ( import (
"context"
"encoding/json"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/redisCli" "github.com/bluele/gcache"
"hilo-user/_const/redis_key"
"hilo-user/myerr"
"time" "time"
) )
func GetUserMedalMergeCache(userId mysql.ID) ([]uint32, error) { // 改成lru
bData, err := GetCache(redis_key.GetUserMedalMerge(userId)) var userMedalMergeLru = gcache.New(10000).LRU().Build()
if err != nil {
return nil, myerr.WrapErr(err)
}
res := make([]uint32, 0)
err = json.Unmarshal(bData, &res)
if err != nil {
return nil, myerr.WrapErr(err)
}
return res, nil
}
func GetCache(key string) ([]byte, error) { func GetUserMedalMergeCache(userId mysql.ID) ([]uint32, error) {
data, err := redisCli.GetRedis().Get(context.Background(), key).Bytes() if data, err := userMedalMergeLru.Get(userId); err == nil {
if err != nil { return data.([]uint32), nil
return nil, err
}
return data, nil
}
func SetCache(key string, data interface{}, expire time.Duration) error {
jData, err := json.Marshal(data)
if err != nil {
return err
}
err = redisCli.GetRedis().Set(context.Background(), key, jData, expire).Err()
if err != nil {
mylogrus.MyLog.Errorf("SetCache key:%s, data:%v, err:%s", key, data, err)
return err
} }
return nil return nil, nil
} }
func SetUserMedalMergeCache(userId mysql.ID, data []uint32) error { func SetUserMedalMergeCache(userId mysql.ID, data []uint32) {
err := SetCache(redis_key.GetUserMedalMerge(userId), data, time.Hour*2) _ = userMedalMergeLru.SetWithExpire(userId, data, time.Minute*15)
if err != nil {
mylogrus.MyLog.Errorf("SetUserMedalMerge err:%s", err)
return myerr.WrapErr(err)
}
return nil
} }
...@@ -41,7 +41,9 @@ func AddCpDayRank(model *domain.Model, cpRelation CpRelation, score mysql.Num) ( ...@@ -41,7 +41,9 @@ func AddCpDayRank(model *domain.Model, cpRelation CpRelation, score mysql.Num) (
func PageCpDayRank(model *domain.Model, beginDate, endDate string, offset, limit int) []CpDayRank { func PageCpDayRank(model *domain.Model, beginDate, endDate string, offset, limit int) []CpDayRank {
var ranks []CpDayRank var ranks []CpDayRank
if err := model.DB().Table("cp_day_rank r").Joins("INNER JOIN cp_relation c ON c.id = r.cp_id"). if err := model.DB().Table("cp_day_rank r").Joins("INNER JOIN cp_relation c ON c.id = r.cp_id").
Where("r.date BETWEEN ? AND ?", beginDate, endDate).Group("cp_id").Select("cp_id,r.user_id1,r.user_id2,SUM(r.score) score"). Where("r.date BETWEEN ? AND ?", beginDate, endDate).
Where("cp_id not in (1581, 12651, 5171, 9191, 39131, 28801, 181, 35221)").
Group("cp_id").Select("cp_id,r.user_id1,r.user_id2,SUM(r.score) score").
Order("score DESC").Offset(offset).Limit(limit).Find(&ranks).Error; err != nil { Order("score DESC").Offset(offset).Limit(limit).Find(&ranks).Error; err != nil {
model.Log.Errorf("PageCpDayRank fail:%v", err) model.Log.Errorf("PageCpDayRank fail:%v", err)
} }
......
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mylogrus" "git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/redisCli"
"hilo-user/_const/redis_key/group_k" "hilo-user/_const/redis_key/group_k"
"hilo-user/myerr" "hilo-user/myerr"
"strconv" "strconv"
...@@ -26,7 +25,7 @@ func RoomLivingUserIdFilter(model *domain.Model, userIds []mysql.ID) (map[mysql. ...@@ -26,7 +25,7 @@ func RoomLivingUserIdFilter(model *domain.Model, userIds []mysql.ID) (map[mysql.
return nil, myerr.WrapErr(err) return nil, myerr.WrapErr(err)
} }
groupUserIdstrs, err := redisCli.GetRedis().ZRange(model, key, 0, -1).Result() groupUserIdstrs, err := model.RedisCluster.ZRange(model, key, 0, -1).Result()
if err != nil { if err != nil {
return nil, myerr.WrapErr(err) return nil, myerr.WrapErr(err)
} }
...@@ -34,7 +33,6 @@ func RoomLivingUserIdFilter(model *domain.Model, userIds []mysql.ID) (map[mysql. ...@@ -34,7 +33,6 @@ func RoomLivingUserIdFilter(model *domain.Model, userIds []mysql.ID) (map[mysql.
resultUserSet := map[mysql.ID]string{} resultUserSet := map[mysql.ID]string{}
for i, _ := range groupUserIdstrs { for i, _ := range groupUserIdstrs {
tempGroupUid, userId := analysisMemberStr(groupUserIdstrs[i]) tempGroupUid, userId := analysisMemberStr(groupUserIdstrs[i])
mylogrus.MyLog.Debugf("RoomLivingUserIdFilter, analysisMemberStr %s, %d", tempGroupUid, userId)
if _, flag := userIdSet[userId]; flag { if _, flag := userIdSet[userId]; flag {
resultUserSet[userId] = tempGroupUid resultUserSet[userId] = tempGroupUid
...@@ -44,7 +42,7 @@ func RoomLivingUserIdFilter(model *domain.Model, userIds []mysql.ID) (map[mysql. ...@@ -44,7 +42,7 @@ func RoomLivingUserIdFilter(model *domain.Model, userIds []mysql.ID) (map[mysql.
} }
func ClearExpired(model *domain.Model, key string, expireSec int64) error { func ClearExpired(model *domain.Model, key string, expireSec int64) error {
return model.Redis.ZRemRangeByScore(model, key, return model.RedisCluster.ZRemRangeByScore(model, key,
"0", strconv.FormatInt(time.Now().Unix()-expireSec, 10)).Err() "0", strconv.FormatInt(time.Now().Unix()-expireSec, 10)).Err()
} }
......
...@@ -3,6 +3,7 @@ package invite_m ...@@ -3,6 +3,7 @@ package invite_m
import ( import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/utils"
"gorm.io/gorm" "gorm.io/gorm"
"time" "time"
) )
...@@ -84,3 +85,17 @@ func GetInviteApplyNumByType(model *domain.Model, gType int, beginTime, endTime ...@@ -84,3 +85,17 @@ func GetInviteApplyNumByType(model *domain.Model, gType int, beginTime, endTime
} }
return int(count), nil return int(count), nil
} }
// 今日已提交次数
func TodayInviteApplyCount(model *domain.Model, userId mysql.ID) (int64, error) {
start, end := utils.DayStartEnd(time.Now())
var count int64
if err := model.Db.Model(InviteApply{}).
Where("user_id = ?", userId).
Where("created_time >= ? and created_time <= ?", start.Format(utils.DATETIME_FORMAT), end.Format(utils.DATETIME_FORMAT)).
Count(&count).Error; err != nil {
return 0, err
}
// err == nil, record exists
return count, nil
}
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
// 获取推广员平台 // 获取推广员平台
func GetPromotionPlatforms(model *domain.Model) []string { func GetPromotionPlatforms(model *domain.Model) []string {
return []string{"Falla", "Yalla", "Whisper", "Ahlan", "Mashi", "YoYo", "Yoho", "Echo", "Hawa", "Yalla Ludo", "Hafla", return []string{"Falla", "Yalla", "Whisper", "Ahlan", "Mashi", "YoYo", "Yoho", "Echo", "Hawa", "Yalla Ludo", "Hafla",
"Imo", "Ola Party", "ShareChat", "Viya", "Hello Yo", "Bigo Live", "Hago"} "Imo", "Ola Party", "ShareChat", "Viya", "Hello Yo", "Bigo Live", "Hago", "Oye Talk", "Tiktok", "Bigo", "Mr7ba"}
} }
// 检查是否推广员 // 检查是否推广员
......
...@@ -61,8 +61,8 @@ func GetUserMedalMerge(logger *logrus.Entry, db *gorm.DB, userId mysql.ID) ([]ui ...@@ -61,8 +61,8 @@ func GetUserMedalMerge(logger *logrus.Entry, db *gorm.DB, userId mysql.ID) ([]ui
} }
} }
} }
logger.Infof("maxGrade %+v", maxGrades) //logger.Infof("maxGrade %+v", maxGrades)
logger.Infof("maxMedalIds %+v", maxMedalIds) //logger.Infof("maxMedalIds %+v", maxMedalIds)
mIds := result mIds := result
result = make([]uint32, 0) result = make([]uint32, 0)
......
package event_s package event_s
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/redisCli"
"github.com/jinzhu/now"
"hilo-user/_const/enum/cp_e"
"hilo-user/_const/enum/gift_e"
"hilo-user/domain/event/gift_ev"
"hilo-user/domain/model/cp_m"
"time"
)
// 送礼增加cp等级 // 送礼增加cp等级
// 送礼增加cp排行榜 // 送礼增加cp排行榜
func CpGiftEvent() { //func CpGiftEvent() {
gift_ev.AddSendGiftEventSync(func(model *domain.Model, event interface{}) error { // gift_ev.AddSendGiftEventSync(func(model *domain.Model, event interface{}) error {
sendGiftEvent, ok := event.(*gift_ev.SendGiftEvent) // sendGiftEvent, ok := event.(*gift_ev.SendGiftEvent)
if !ok { // if !ok {
model.Log.Errorf("AddSendGiftEventAsync event type err") // model.Log.Errorf("AddSendGiftEventAsync event type err")
return nil // return nil
} // }
// 只处理cp礼物 // // 只处理cp礼物
if !sendGiftEvent.ResGift.Cp { // if !sendGiftEvent.ResGift.Cp {
return nil // return nil
} // }
for _, receiverUid := range sendGiftEvent.ReceiveUserIds { // for _, receiverUid := range sendGiftEvent.ReceiveUserIds {
diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum // diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum
// 有cp关系 // // 有cp关系
if cpRelation, exits := cp_m.GetCpRelationPair(model, sendGiftEvent.SendUserId, receiverUid); exits { // if cpRelation, exits := cp_m.GetCpRelationPair(model, sendGiftEvent.SendUserId, receiverUid); exits {
if err := cp_m.AddCpLevelPoints(model, cpRelation, diamonds, sendGiftEvent.SceneType, sendGiftEvent.SceneUid); err != nil { // if err := cp_m.AddCpLevelPoints(model, cpRelation, diamonds, sendGiftEvent.SceneType, sendGiftEvent.SceneUid); err != nil {
model.Log.Errorf("AddCpLevelPoints fail:%v", err) // model.Log.Errorf("AddCpLevelPoints fail:%v", err)
} // }
if err := cp_m.AddCpDayRank(model, cpRelation, diamonds); err != nil { // if err := cp_m.AddCpDayRank(model, cpRelation, diamonds); err != nil {
model.Log.Errorf("AddCpDayRank fail:%v", err) // model.Log.Errorf("AddCpDayRank fail:%v", err)
} // }
// 检查最新的等级 // // 检查最新的等级
if cpLevel := cp_m.GetCpLevel(model, cpRelation.Id); cpLevel.CpId >= 0 { // if cpLevel := cp_m.GetCpLevel(model, cpRelation.Id); cpLevel.CpId >= 0 {
points := cpLevel.Points + cp_e.CpLevelPoints[cpLevel.Level] // points := cpLevel.Points + cp_e.CpLevelPoints[cpLevel.Level]
if err := cp_m.UpdateCpAchievement(model, cpLevel.CpId, cpRelation.UserId1, cpRelation.UserId2, cp_e.CpAchievementLevel, points); err != nil { // if err := cp_m.UpdateCpAchievement(model, cpLevel.CpId, cpRelation.UserId1, cpRelation.UserId2, cp_e.CpAchievementLevel, points); err != nil {
model.Log.Errorf("UpdateCpAchievement fail:%v", err) // model.Log.Errorf("UpdateCpAchievement fail:%v", err)
} // }
} // }
// 检查最高的分数 // // 检查最高的分数
for _, queryType := range []string{"day", "week", "month"} { // for _, queryType := range []string{"day", "week", "month"} {
var beginDate, endDate string // var beginDate, endDate string
var cpAchievementType cp_e.CpAchievement // var cpAchievementType cp_e.CpAchievement
switch queryType { // switch queryType {
case "day": // case "day":
beginDate, endDate = time.Now().Format("2006-01-02"), time.Now().Format("2006-01-02") // beginDate, endDate = time.Now().Format("2006-01-02"), time.Now().Format("2006-01-02")
cpAchievementType = cp_e.CpAchievementDayRank // cpAchievementType = cp_e.CpAchievementDayRank
case "week": // case "week":
beginDate = now.BeginningOfWeek().Format("2006-01-02") // beginDate = now.BeginningOfWeek().Format("2006-01-02")
endDate = now.EndOfWeek().Format("2006-01-02") // endDate = now.EndOfWeek().Format("2006-01-02")
cpAchievementType = cp_e.CpAchievementWeekRank // cpAchievementType = cp_e.CpAchievementWeekRank
case "month": // case "month":
beginDate = now.BeginningOfMonth().Format("2006-01-02") // beginDate = now.BeginningOfMonth().Format("2006-01-02")
endDate = now.EndOfMonth().Format("2006-01-02") // endDate = now.EndOfMonth().Format("2006-01-02")
cpAchievementType = cp_e.CpAchievementMonthRank // cpAchievementType = cp_e.CpAchievementMonthRank
} // }
if data := cp_m.GetCpDayRank(model, beginDate, endDate, cpRelation.Id); data.Score > 0 { // if data := cp_m.GetCpDayRank(model, beginDate, endDate, cpRelation.Id); data.Score > 0 {
if err := cp_m.UpdateCpAchievement(model, cpRelation.Id, cpRelation.UserId1, cpRelation.UserId2, cpAchievementType, data.Score); err != nil { // if err := cp_m.UpdateCpAchievement(model, cpRelation.Id, cpRelation.UserId1, cpRelation.UserId2, cpAchievementType, data.Score); err != nil {
model.Log.Errorf("UpdateCpAchievement fail:%v", err) // model.Log.Errorf("UpdateCpAchievement fail:%v", err)
} // }
} // }
} // }
// 检查最新日周月榜单 // // 检查最新日周月榜单
return nil // 业务场景允许提前break(cp是唯一的) // return nil // 业务场景允许提前break(cp是唯一的)
} // }
} // }
return nil // return nil
}) // })
} //}
// 漏掉加分数的送礼记录,补上cp增加分数 // 漏掉加分数的送礼记录,补上cp增加分数
// 送礼增加cp等级 // 送礼增加cp等级
// 送礼增加cp排行榜 // 送礼增加cp排行榜
func CompensateCpScore() { //func CompensateCpScore() {
if !config.IsMaster() { // if !config.IsMaster() {
return // return
} // }
model := domain.CreateModelNil() // model := domain.CreateModelNil()
num, err := redisCli.IncrNumExpire("scirpt:compensateCpScore", 1, time.Hour*999) // num, err := redisCli.IncrNumExpire("scirpt:compensateCpScore", 1, time.Hour*999)
if err != nil { // if err != nil {
model.Log.Errorf("CompensateCpScore err:%v", err) // model.Log.Errorf("CompensateCpScore err:%v", err)
} // }
if num > 1 { // if num > 1 {
model.Log.Errorf("CompensateCpScore 执行过了,退出") // model.Log.Errorf("CompensateCpScore 执行过了,退出")
return // return
} // }
// 查找需要补分的送礼记录 // // 查找需要补分的送礼记录
type GiftOperate struct { // type GiftOperate struct {
Id uint64 `json:"id"` // Id uint64 `json:"id"`
ResGiftId uint64 `json:"res_gift_id"` // ResGiftId uint64 `json:"res_gift_id"`
GiftN int32 `json:"gift_n"` // GiftN int32 `json:"gift_n"`
SendUserId uint64 `json:"send_user_id"` // SendUserId uint64 `json:"send_user_id"`
ReceiveUserId uint64 `json:"receive_user_id"` // ReceiveUserId uint64 `json:"receive_user_id"`
SendUserDiamond uint32 `json:"send_user_diamond"` // SendUserDiamond uint32 `json:"send_user_diamond"`
SceneType int8 `json:"scene_type"` // SceneType int8 `json:"scene_type"`
SceneUid string `json:"scene_uid"` // SceneUid string `json:"scene_uid"`
CreatedTime time.Time `json:"created_time"` // CreatedTime time.Time `json:"created_time"`
} // }
rows := make([]*GiftOperate, 0) // rows := make([]*GiftOperate, 0)
err = model.DB().Model(GiftOperate{}). // err = model.DB().Model(GiftOperate{}).
Where("created_time < ?", "2023-06-22 11:20:15"). // Where("created_time < ?", "2023-06-22 11:20:15").
Where("res_gift_id in (?)", // Where("res_gift_id in (?)",
[]int{3561, 3571, 3581, 3591, 3601, 3611, 3621, 3631, 3641, 3651, 3661, 3671, 3681, 3691, 3701, 3711}). // []int{3561, 3571, 3581, 3591, 3601, 3611, 3621, 3631, 3641, 3651, 3661, 3671, 3681, 3691, 3701, 3711}).
Find(&rows).Error // Find(&rows).Error
if err != nil { // if err != nil {
model.Log.Errorf("CompensateCpScore err:%v", err) // model.Log.Errorf("CompensateCpScore err:%v", err)
return // return
} // }
model.Log.Infof("CompensateCpScore len(rows):%v", len(rows)) // model.Log.Infof("CompensateCpScore len(rows):%v", len(rows))
//
for idx, r := range rows { // for idx, r := range rows {
diamonds := r.SendUserDiamond // diamonds := r.SendUserDiamond
// 有cp关系 // // 有cp关系
if cpRelation, exits := cp_m.GetCpRelationPair(model, r.SendUserId, r.ReceiveUserId); exits { // if cpRelation, exits := cp_m.GetCpRelationPair(model, r.SendUserId, r.ReceiveUserId); exits {
if err := cp_m.AddCpLevelPoints(model, cpRelation, diamonds, gift_e.GiftOperateSceneType(r.SceneType), r.SceneUid); err != nil { // if err := cp_m.AddCpLevelPoints(model, cpRelation, diamonds, gift_e.GiftOperateSceneType(r.SceneType), r.SceneUid); err != nil {
model.Log.Errorf("CompensateCpScore AddCpLevelPoints fail:%v", err) // model.Log.Errorf("CompensateCpScore AddCpLevelPoints fail:%v", err)
return // return
} // }
if err := cp_m.AddCpDayRank(model, cpRelation, diamonds); err != nil { // if err := cp_m.AddCpDayRank(model, cpRelation, diamonds); err != nil {
model.Log.Errorf("CompensateCpScore AddCpDayRank fail:%v", err) // model.Log.Errorf("CompensateCpScore AddCpDayRank fail:%v", err)
return // return
} // }
// 检查最新的等级 // // 检查最新的等级
if cpLevel := cp_m.GetCpLevel(model, cpRelation.Id); cpLevel.CpId >= 0 { // if cpLevel := cp_m.GetCpLevel(model, cpRelation.Id); cpLevel.CpId >= 0 {
points := cpLevel.Points + cp_e.CpLevelPoints[cpLevel.Level] // points := cpLevel.Points + cp_e.CpLevelPoints[cpLevel.Level]
if err := cp_m.UpdateCpAchievement(model, cpLevel.CpId, cpRelation.UserId1, cpRelation.UserId2, cp_e.CpAchievementLevel, points); err != nil { // if err := cp_m.UpdateCpAchievement(model, cpLevel.CpId, cpRelation.UserId1, cpRelation.UserId2, cp_e.CpAchievementLevel, points); err != nil {
model.Log.Errorf("CompensateCpScore UpdateCpAchievement fail:%v", err) // model.Log.Errorf("CompensateCpScore UpdateCpAchievement fail:%v", err)
} // }
} // }
// 检查最高的分数 // // 检查最高的分数
for _, queryType := range []string{"day", "week", "month"} { // for _, queryType := range []string{"day", "week", "month"} {
var beginDate, endDate string // var beginDate, endDate string
var cpAchievementType cp_e.CpAchievement // var cpAchievementType cp_e.CpAchievement
switch queryType { // switch queryType {
case "day": // case "day":
beginDate, endDate = r.CreatedTime.Format("2006-01-02"), r.CreatedTime.Format("2006-01-02") // beginDate, endDate = r.CreatedTime.Format("2006-01-02"), r.CreatedTime.Format("2006-01-02")
cpAchievementType = cp_e.CpAchievementDayRank // cpAchievementType = cp_e.CpAchievementDayRank
case "week": // case "week":
beginDate = now.With(r.CreatedTime).BeginningOfWeek().Format("2006-01-02") // beginDate = now.With(r.CreatedTime).BeginningOfWeek().Format("2006-01-02")
endDate = now.With(r.CreatedTime).EndOfWeek().Format("2006-01-02") // endDate = now.With(r.CreatedTime).EndOfWeek().Format("2006-01-02")
cpAchievementType = cp_e.CpAchievementWeekRank // cpAchievementType = cp_e.CpAchievementWeekRank
case "month": // case "month":
beginDate = now.BeginningOfMonth().Format("2006-01-02") // beginDate = now.BeginningOfMonth().Format("2006-01-02")
endDate = now.EndOfMonth().Format("2006-01-02") // endDate = now.EndOfMonth().Format("2006-01-02")
cpAchievementType = cp_e.CpAchievementMonthRank // cpAchievementType = cp_e.CpAchievementMonthRank
} // }
if data := cp_m.GetCpDayRank(model, beginDate, endDate, cpRelation.Id); data.Score > 0 { // if data := cp_m.GetCpDayRank(model, beginDate, endDate, cpRelation.Id); data.Score > 0 {
if err := cp_m.UpdateCpAchievement(model, cpRelation.Id, cpRelation.UserId1, cpRelation.UserId2, cpAchievementType, data.Score); err != nil { // if err := cp_m.UpdateCpAchievement(model, cpRelation.Id, cpRelation.UserId1, cpRelation.UserId2, cpAchievementType, data.Score); err != nil {
model.Log.Errorf("CompensateCpScore UpdateCpAchievement fail:%v", err) // model.Log.Errorf("CompensateCpScore UpdateCpAchievement fail:%v", err)
} // }
} // }
} // }
} // }
model.Log.Infof("CompensateCpScore idx:%v", idx) // model.Log.Infof("CompensateCpScore idx:%v", idx)
if idx%1000 == 0 { // if idx%1000 == 0 {
time.Sleep(time.Millisecond * 100) // time.Sleep(time.Millisecond * 100)
} // }
} // }
//
model.Log.Infof("CompensateCpScore 补偿完毕") // model.Log.Infof("CompensateCpScore 补偿完毕")
} //}
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
func EventInit() { func EventInit() {
UserBagSendEvent() UserBagSendEvent()
CpGiftEvent() //CpGiftEvent()
CpSpaceVisitEvent() CpSpaceVisitEvent()
} }
......
...@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code ...@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code
[REDIS] [REDIS]
REDIS_HOST=47.244.34.27:6379 REDIS_HOST=47.244.34.27:6379
REDIS_PASSWORD=8QZ9JD1zLvPR3yHf REDIS_PASSWORD=8QZ9JD1zLvPR3yHf
REDIS_CLUSTER_HOST=47.244.34.27:6379
REDIS_CLUSTER_PASSWORD=8QZ9JD1zLvPR3yHf
[JWT] [JWT]
SECRET=hilo1632 SECRET=hilo1632
ISSUER_API=hiloApi ISSUER_API=hiloApi
......
...@@ -3,6 +3,7 @@ package main ...@@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"git.hilo.cn/hilo-common/resource/consul" "git.hilo.cn/hilo-common/resource/consul"
"git.hilo.cn/hilo-common/resource/redisCli"
"hilo-user/cron" "hilo-user/cron"
"hilo-user/domain/service/event_s" "hilo-user/domain/service/event_s"
"hilo-user/route" "hilo-user/route"
...@@ -17,6 +18,7 @@ const ( ...@@ -17,6 +18,7 @@ const (
func main() { func main() {
cron.Init() // 开启定时任务 cron.Init() // 开启定时任务
event_s.EventInit() // 注册事件(内部事件+mysql拟kafka) event_s.EventInit() // 注册事件(内部事件+mysql拟kafka)
redisCli.InitCluster() // redis集群
r := route.InitRouter() // 注册路由 r := route.InitRouter() // 注册路由
consul.RegisterToConsul(PORT, RegisterName, RegisterTag) // 服务注册 consul.RegisterToConsul(PORT, RegisterName, RegisterTag) // 服务注册
r.Run(fmt.Sprintf(":%d", PORT)) // 启动服务 r.Run(fmt.Sprintf(":%d", PORT)) // 启动服务
......
...@@ -27,10 +27,11 @@ var ( ...@@ -27,10 +27,11 @@ var (
// 群组 // 群组
GroupNotFound = myerr.NewBusinessCode(14001, "Group not found", myerr.BusinessData{}) // 找不到该群 GroupNotFound = myerr.NewBusinessCode(14001, "Group not found", myerr.BusinessData{}) // 找不到该群
CpAlreadyInvite = myerr.NewBusinessCode(50120, "Already invited", myerr.BusinessData{}) // 已经发送过邀请了 CpAlreadyInvite = myerr.NewBusinessCode(50120, "Already invited", myerr.BusinessData{}) // 已经发送过邀请了
CpHaveCancelNoDeal = myerr.NewBusinessCode(50121, "You have a cancel apply", myerr.BusinessData{}) // 有接触申请需要处理 CpHaveCancelNoDeal = myerr.NewBusinessCode(50121, "You have a cancel apply", myerr.BusinessData{}) // 有接触申请需要处理
InviteApplyNoPermission = myerr.NewBusinessCode(50122, "This user does not have invitation permission", myerr.BusinessData{}) // 该用户没有邀请权限 InviteApplyNoPermission = myerr.NewBusinessCode(50122, "This user does not have invitation permission", myerr.BusinessData{}) // 该用户没有邀请权限
InviteApplyAlreadyInvited = myerr.NewBusinessCode(50123, "Already invited by someone else", myerr.BusinessData{}) // 已经被别人邀请了 InviteApplyAlreadyInvited = myerr.NewBusinessCode(50123, "Already invited by someone else", myerr.BusinessData{}) // 已经被别人邀请了
InviteApplyCodeInvalid = myerr.NewBusinessCode(50124, "user id invalid", myerr.BusinessData{}) // 邀请人用户id错误 InviteApplyCodeInvalid = myerr.NewBusinessCode(50124, "user id invalid", myerr.BusinessData{}) // 邀请人用户id错误
InviteApplyNewCodeInvalid = myerr.NewBusinessCode(50125, "user id invalid", myerr.BusinessData{}) // 被邀请人用户id错误 InviteApplyNewCodeInvalid = myerr.NewBusinessCode(50125, "user id invalid", myerr.BusinessData{}) // 被邀请人用户id错误
InviteApplyTimes = myerr.NewBusinessCode(50126, "Your application today has reached the upper limit, please wait for tomorrow to continue the application", myerr.BusinessData{}) // 今日邀请次数太多
) )
...@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code ...@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code
[REDIS] [REDIS]
REDIS_HOST=r-eb3btxn8vfdsuwdbuf.redis.dubai.rds.aliyuncs.com:6379 REDIS_HOST=r-eb3btxn8vfdsuwdbuf.redis.dubai.rds.aliyuncs.com:6379
REDIS_PASSWORD= REDIS_PASSWORD=
REDIS_CLUSTER_HOST=r-eb3yt6k8zgxs62kjjs.redis.dubai.rds.aliyuncs.com:6379
REDIS_CLUSTER_PASSWORD=
[JWT] [JWT]
SECRET=hilo1504 SECRET=hilo1504
ISSUER_API=hiloApi ISSUER_API=hiloApi
......
...@@ -43,12 +43,25 @@ func InviteApply(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -43,12 +43,25 @@ func InviteApply(c *gin.Context) (*mycontext.MyContext, error) {
if err != nil { if err != nil {
return myCtx, err return myCtx, err
} }
model := domain.CreateModelContext(myCtx)
// 每日最多提交10次
noLimitTimesMap := map[uint64]struct{}{1770691: {}, 2264431: {}, 7283111: {}}
if _, ok := noLimitTimesMap[myUserId]; !ok {
// 今日提交次数
times, err := invite_m.TodayInviteApplyCount(model, myUserId)
if err != nil {
model.Log.Errorf("InviteApply myUserId:%v, err:%v", myUserId, err)
return myCtx, err
}
if times >= 15 {
return myCtx, bizerr.InviteApplyTimes
}
}
var param paramStr var param paramStr
if err := c.ShouldBind(&param); err != nil { if err := c.ShouldBind(&param); err != nil {
return myCtx, err return myCtx, err
} }
model := domain.CreateModelContext(myCtx)
// 平台是否填写正确 // 平台是否填写正确
platforms := promotion_m.GetPromotionPlatforms(model) platforms := promotion_m.GetPromotionPlatforms(model)
var existsPlatform bool var existsPlatform bool
...@@ -72,6 +85,9 @@ func InviteApply(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -72,6 +85,9 @@ func InviteApply(c *gin.Context) (*mycontext.MyContext, error) {
model.Log.Errorf("InviteApply param:%v", param) model.Log.Errorf("InviteApply param:%v", param)
return myCtx, bizerr.InviteApplyCodeInvalid return myCtx, bizerr.InviteApplyCodeInvalid
} }
//if user.ID != myUserId { //只能自己提交
// return myCtx, bizerr.InvalidParameter
//}
if newUser.ID == 0 || user.ID == 0 { if newUser.ID == 0 || user.ID == 0 {
model.Log.Errorf("InviteApply param:%v", param) model.Log.Errorf("InviteApply param:%v", param)
return myCtx, bizerr.InvalidParameter return myCtx, bizerr.InvalidParameter
...@@ -231,7 +247,7 @@ func InviteApplyList(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -231,7 +247,7 @@ func InviteApplyList(c *gin.Context) (*mycontext.MyContext, error) {
func PromotionPlatform(c *gin.Context) (*mycontext.MyContext, error) { func PromotionPlatform(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys) myCtx := mycontext.CreateMyContext(c.Keys)
resp.ResponseOk(c, []string{"Falla", "Yalla", "Whisper", "Ahlan", "Mashi", "YoYo", "Yoho", "Echo", "Hawa", resp.ResponseOk(c, []string{"Falla", "Yalla", "Whisper", "Ahlan", "Mashi", "YoYo", "Yoho", "Echo", "Hawa",
"Yalla Ludo", "Hafla", "Imo", "Ola Party", "ShareChat", "Viya", "Hello Yo", "Bigo Live", "Hago"}) "Yalla Ludo", "Hafla", "Imo", "Ola Party", "ShareChat", "Viya", "Hello Yo", "Bigo Live", "Hago", "Oye Talk", "Tiktok", "Bigo", "Mr7ba"})
return myCtx, nil return myCtx, nil
} }
......