Commit 3702a0f9 authored by hujiebin's avatar hujiebin

Merge branch 'fix/group_support' into 'master'

Fix/group support

See merge request !67
parents 8aed32d6 202b83a7
...@@ -21,5 +21,5 @@ func Init() { ...@@ -21,5 +21,5 @@ func Init() {
//group_cron.GroupInEventInit() // 进房事件 //group_cron.GroupInEventInit() // 进房事件
group_cron.CreateGroup() // group_cron.CreateGroup() //
group_cron.CalcGroupSupport() // 群组扶持计算 group_cron.CalcGroupSupport() // 群组扶持计算
group_cron.CalcGroupSupport_OldData() //group_cron.CalcGroupSupport_OldData()
} }
package group_cron package group_cron
import ( import (
"context"
"encoding/json" "encoding/json"
"git.hilo.cn/hilo-common/_const/rediskey"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/config" "git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/sdk/tencentyun" "git.hilo.cn/hilo-common/sdk/tencentyun"
"git.hilo.cn/hilo-common/utils" "git.hilo.cn/hilo-common/utils"
"github.com/robfig/cron" "github.com/robfig/cron"
"hilo-group/_const/enum/gift_e"
"hilo-group/_const/enum/group_e" "hilo-group/_const/enum/group_e"
"hilo-group/domain/model/gift_m"
"hilo-group/domain/model/group_m" "hilo-group/domain/model/group_m"
"hilo-group/domain/service/group_s" "hilo-group/domain/service/group_s"
"time" "time"
...@@ -92,76 +87,76 @@ func sendGroupSupportH5(model *domain.Model) error { ...@@ -92,76 +87,76 @@ func sendGroupSupportH5(model *domain.Model) error {
} }
// 群组扶持计算-旧数据 // 群组扶持计算-旧数据
func CalcGroupSupport_OldData() { //func CalcGroupSupport_OldData() {
if !config.IsMaster() { // if !config.IsMaster() {
return // return
} // }
c := cron.New() // c := cron.New()
spec := "0 20 11 25 8 ?" // spec := "0 20 11 25 8 ?"
_ = c.AddFunc(spec, func() { // _ = c.AddFunc(spec, func() {
defer utils.CheckGoPanic() // defer utils.CheckGoPanic()
var model = domain.CreateModelNil() // var model = domain.CreateModelNil()
//开始 // //开始
model.Log.Infof("CalcGroupSupport_OldData start") // model.Log.Infof("CalcGroupSupport_OldData start")
//
beginTime, endTime, period := group_m.GetSupportLevelTime(time.Now().AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY)) // beginTime, endTime, period := group_m.GetSupportLevelTime(time.Now().AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY))
//beginTime, _, period := group_m.GetSupportLevelTime(time.Now()) // //beginTime, _, period := group_m.GetSupportLevelTime(time.Now())
//endTime := time.Unix(1692843600, 0) // //endTime := time.Unix(1692843600, 0)
//
g := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, Model: model} // g := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, Model: model}
records, err := g.BatchGetConsumeByRange(beginTime, endTime) // records, err := g.BatchGetConsumeByRange(beginTime, endTime)
if err != nil { // if err != nil {
model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, err:%v", beginTime, endTime, err) // model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, err:%v", beginTime, endTime, err)
return // return
} // }
// 流水写入redis // // 流水写入redis
keyDiamond := rediskey.GetGroupSupportConsumeSummary(period) // keyDiamond := rediskey.GetGroupSupportConsumeSummary(period)
for _, r := range records { // for _, r := range records {
if r.SceneUid == "" || r.Consume <= 0 { // if r.SceneUid == "" || r.Consume <= 0 {
continue // continue
} // }
_, err = model.RedisCluster.ZIncrBy(context.Background(), keyDiamond, float64(r.Consume), r.SceneUid).Result() // _, err = model.RedisCluster.ZIncrBy(context.Background(), keyDiamond, float64(r.Consume), r.SceneUid).Result()
if err != nil { // if err != nil {
model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, val:%d, member:%s, err:%v", // model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, val:%d, member:%s, err:%v",
keyDiamond, r.Consume, r.SceneUid, err) // keyDiamond, r.Consume, r.SceneUid, err)
} // }
} // }
err = redisCli.SetExpire(model.RedisCluster, keyDiamond, time.Hour*24*14) // 保留两周 // err = redisCli.SetExpire(model.RedisCluster, keyDiamond, time.Hour*24*14) // 保留两周
if err != nil { // if err != nil {
model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, err:%v", keyDiamond, err) // model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, err:%v", keyDiamond, err)
return // return
} // }
// 支持者写入redis // // 支持者写入redis
for _, r := range records { // for _, r := range records {
if r.SceneUid == "" || r.C <= 0 { // if r.SceneUid == "" || r.C <= 0 {
continue // continue
} // }
// 支持者列表 // // 支持者列表
support := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, SceneUid: r.SceneUid, Model: model} // support := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, SceneUid: r.SceneUid, Model: model}
uids, err := support.BatchGetSupportList(beginTime, endTime) // uids, err := support.BatchGetSupportList(beginTime, endTime)
if err != nil { // if err != nil {
model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, imGroupId:%v, err:%v", beginTime, endTime, r.SceneUid, err) // model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, imGroupId:%v, err:%v", beginTime, endTime, r.SceneUid, err)
continue // continue
} // }
if len(uids) <= 0 { // if len(uids) <= 0 {
continue // continue
} // }
// 支持者数量 // // 支持者数量
keySupportNum := rediskey.GetGroupSupportCountSupporter(period, r.SceneUid) // keySupportNum := rediskey.GetGroupSupportCountSupporter(period, r.SceneUid)
for _, uid := range uids { // for _, uid := range uids {
err = model.RedisCluster.SAdd(context.Background(), keySupportNum, uid).Err() // err = model.RedisCluster.SAdd(context.Background(), keySupportNum, uid).Err()
if err != nil { // if err != nil {
model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, UserId:%d, err:%v", keySupportNum, uid, err) // model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, UserId:%d, err:%v", keySupportNum, uid, err)
} // }
} // }
err = redisCli.SetExpire(model.RedisCluster, keySupportNum, time.Hour*24*14) // 保留两周 // err = redisCli.SetExpire(model.RedisCluster, keySupportNum, time.Hour*24*14) // 保留两周
if err != nil { // if err != nil {
model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, err:%v", keySupportNum, err) // model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, err:%v", keySupportNum, err)
} // }
} // }
//
model.Log.Infof("CalcGroupSupport_OldData end") // model.Log.Infof("CalcGroupSupport_OldData end")
}) // })
//
c.Start() // c.Start()
} //}
...@@ -128,39 +128,39 @@ func (g *GiftOperate) GetConsumeByRange(beginTime, endTime time.Time) (uint32, u ...@@ -128,39 +128,39 @@ func (g *GiftOperate) GetConsumeByRange(beginTime, endTime time.Time) (uint32, u
return 0, 0, nil return 0, 0, nil
} }
if beginTime.Unix() >= 1691337600 && beginTime.Unix() < 1691942400 { // 因为这周水果机被部分人刷币,所以这里做了特殊的处理 //if beginTime.Unix() >= 1691337600 && beginTime.Unix() < 1691942400 { // 因为这周水果机被部分人刷币,所以这里做了特殊的处理
reduceMap := map[string]uint64{ // reduceMap := map[string]uint64{
"HTGS#a63226380": 20000000, // "HTGS#a63226380": 20000000,
//"HTGS#a42641278": 10000000, // //"HTGS#a42641278": 10000000,
"@TGS#3ZZ5GZLHA": 27141539, // "@TGS#3ZZ5GZLHA": 27141539,
"HTGS#a81630128": 8955410, // "HTGS#a81630128": 8955410,
"HTGS#a42300598": 50211301, // "HTGS#a42300598": 50211301,
"HTGS#a40088696": 10000000, // "HTGS#a40088696": 10000000,
"HTGS#a21700997": 14352310, // "HTGS#a21700997": 14352310,
"HTGS#a83608384": 49644203, // "HTGS#a83608384": 49644203,
"@TGS#33GDXTSIH": 50000000, // "@TGS#33GDXTSIH": 50000000,
"HTGS#a50538513": 15000000, // "HTGS#a50538513": 15000000,
"HTGS#a77282385": 15000000, // "HTGS#a77282385": 15000000,
"HTGS#a59437326": 10000000, // "HTGS#a59437326": 10000000,
"HTGS#a16909405": 10000000, // "HTGS#a16909405": 10000000,
"HTGS#a44104431": 16861206, // "HTGS#a44104431": 16861206,
"HTGS#a56794634": 59591313, // "HTGS#a56794634": 59591313,
"HTGS#a11286025": 31232311, // "HTGS#a11286025": 31232311,
"HTGS#a17238550": 52309338, // "HTGS#a17238550": 52309338,
"HTGS#a83592361": 79545067, // "HTGS#a83592361": 79545067,
"HTGS#a39882521": 10255093, // "HTGS#a39882521": 10255093,
} // }
if reduceNum, ok := reduceMap[g.SceneUid]; ok { // if reduceNum, ok := reduceMap[g.SceneUid]; ok {
if g.Log != nil { // if g.Log != nil {
g.Log.Infof("fruit diamond reduceMap,groupId:%v,reduceNum:%v", g.SceneUid, reduceNum) // g.Log.Infof("fruit diamond reduceMap,groupId:%v,reduceNum:%v", g.SceneUid, reduceNum)
} // }
if rows[0].Consume >= reduceNum { // if rows[0].Consume >= reduceNum {
rows[0].Consume -= reduceNum // rows[0].Consume -= reduceNum
} else { // } else {
rows[0].Consume = 0 // rows[0].Consume = 0
} // }
} // }
} //}
return rows[0].C, rows[0].Consume, nil return rows[0].C, rows[0].Consume, nil
} }
......
...@@ -102,14 +102,14 @@ func (gsa *GroupSupportAwardMgr) Get(db *gorm.DB) ([]GroupSupportAwardMgr, error ...@@ -102,14 +102,14 @@ func (gsa *GroupSupportAwardMgr) Get(db *gorm.DB) ([]GroupSupportAwardMgr, error
} }
//添加记录 //添加记录
func AddGroupSupportAward(model *domain.Model, groupUid string, issuerUserId mysql.ID, resGroupSupportId mysql.ID, userIds []mysql.ID, period string) (*GroupSupportAwardAdmin, []GroupSupportAwardMgr, error) { func AddGroupSupportAward(model *domain.Model, groupUid string, issuerUserId mysql.ID, resSupport *res_m.ResGroupSupport, userIds []mysql.ID, period string) (*GroupSupportAwardAdmin, []GroupSupportAwardMgr, error) {
//资源获取 ////资源获取
resGroupSupport, err := res_m.GetResGroupSupportById(model, resGroupSupportId) //resGroupSupport, err := res_m.GetResGroupSupportById(model, resGroupSupportId)
if err != nil { //if err != nil {
return nil, nil, err // return nil, nil, err
} //}
if int(resGroupSupport.MgrNum) < len(userIds) { if int(resSupport.MgrNum) < len(userIds) {
return nil, nil, myerr.NewSysErrorF("AddGroupSupportAward mgrNum:%v 同 len(userIds)=%v 不一致", resGroupSupport.MgrNum, len(userIds)) return nil, nil, myerr.NewSysErrorF("AddGroupSupportAward mgrNum:%v 同 len(userIds)=%v 不一致", resSupport.MgrNum, len(userIds))
} }
//增加群主奖励 //增加群主奖励
...@@ -118,9 +118,9 @@ func AddGroupSupportAward(model *domain.Model, groupUid string, issuerUserId mys ...@@ -118,9 +118,9 @@ func AddGroupSupportAward(model *domain.Model, groupUid string, issuerUserId mys
GroupUid: groupUid, GroupUid: groupUid,
IssuerUserId: issuerUserId, IssuerUserId: issuerUserId,
UserId: issuerUserId, UserId: issuerUserId,
DiamondNum: resGroupSupport.AdminAward, DiamondNum: resSupport.AdminAward,
Grade: resGroupSupport.Grade, Grade: resSupport.Grade,
ResGroupSupportId: resGroupSupport.ID, ResGroupSupportId: resSupport.ID,
Period: period, Period: period,
} }
...@@ -133,9 +133,9 @@ func AddGroupSupportAward(model *domain.Model, groupUid string, issuerUserId mys ...@@ -133,9 +133,9 @@ func AddGroupSupportAward(model *domain.Model, groupUid string, issuerUserId mys
GroupUid: groupUid, GroupUid: groupUid,
IssuerUserId: issuerUserId, IssuerUserId: issuerUserId,
UserId: userIds[i], UserId: userIds[i],
DiamondNum: resGroupSupport.MgrAward, DiamondNum: resSupport.MgrAward,
Grade: resGroupSupport.Grade, Grade: resSupport.Grade,
ResGroupSupportId: resGroupSupport.ID, ResGroupSupportId: resSupport.ID,
Period: period, Period: period,
}) })
} }
......
...@@ -15,13 +15,12 @@ import ( ...@@ -15,13 +15,12 @@ import (
"hilo-group/domain/model/msg_m" "hilo-group/domain/model/msg_m"
"hilo-group/domain/model/res_m" "hilo-group/domain/model/res_m"
"hilo-group/domain/model/user_m" "hilo-group/domain/model/user_m"
"hilo-group/myerr/bizerr"
"strconv" "strconv"
"time" "time"
) )
// 群组支持名单过滤 // 群组支持名单过滤
func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64, []uint64, error) { func (s *GroupService) GroupSupportList(groupId string, uids []uint64, supportLevel uint32) ([]uint64, []uint64, error) {
if len(uids) <= 0 { if len(uids) <= 0 {
return uids, nil, nil return uids, nil, nil
} }
...@@ -29,13 +28,13 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64 ...@@ -29,13 +28,13 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64
result := make([]uint64, 0) result := make([]uint64, 0)
out := make([]uint64, 0) out := make([]uint64, 0)
err := s.svc.Transactional(func() error {
model := domain.CreateModel(s.svc.CtxAndDb) model := domain.CreateModel(s.svc.CtxAndDb)
// 1. 去掉非群管理者 // 1. 去掉非群管理者
roles, _, err := group_m.GetRolesInGroup(model, groupId) roles, _, err := group_m.GetRolesInGroup(model, groupId)
if err != nil { if err != nil {
return err model.Log.Errorf("GroupSupportList groupId:%v, uids:%v, err:%v", groupId, uids, err)
return nil, nil, err
} }
userIds := make([]uint64, 0) userIds := make([]uint64, 0)
for _, i := range uids { for _, i := range uids {
...@@ -48,13 +47,13 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64 ...@@ -48,13 +47,13 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64
} }
// TODO: 去掉非群成员 // TODO: 去掉非群成员
//(4)1个账户只能做1个群组的管理员(5)1个设备下只允许领取1个管理奖励 //(4)1个账户只能做1个群组的管理员(5)1个设备下只允许领取1个管理奖励
_, _, period := group_m.GetLastSupportPeriod(time.Now()) _, _, period := group_m.GetLastSupportPeriod(time.Now())
gsa := group_m.GroupSupportAwardMgr{Period: period} gsa := group_m.GroupSupportAwardMgr{Period: period}
rows, err := gsa.Get(model.Db) rows, err := gsa.Get(model.Db)
if err != nil { if err != nil {
return err model.Log.Errorf("GroupSupportList groupId:%v, uids:%v, err:%v", groupId, uids, err)
return nil, nil, err
} }
awards := make(map[uint64]struct{}, 0) awards := make(map[uint64]struct{}, 0)
for _, i := range rows { for _, i := range rows {
...@@ -67,7 +66,8 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64 ...@@ -67,7 +66,8 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64
for _, u := range uids { for _, u := range uids {
m, err := user_m.GetSameImeiMap(model, u) m, err := user_m.GetSameImeiMap(model, u)
if err != nil { if err != nil {
return err model.Log.Errorf("GroupSupportList groupId:%v, uids:%v, err:%v", groupId, uids, err)
return nil, nil, err
} }
passed := true passed := true
...@@ -90,25 +90,95 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64 ...@@ -90,25 +90,95 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64
} }
model.Log.Infof("GroupSupportList: uids %v, map %v", uids, m) model.Log.Infof("GroupSupportList: uids %v, map %v", uids, m)
_, supportLevel, err := s.GetSupportLevel(groupId)
if err != nil {
return err
}
if uint32(len(userIds)) > supportLevel { if uint32(len(userIds)) > supportLevel {
model.Log.Infof("GroupSupportList: rule out %v, limit exeeded", userIds[supportLevel:]) model.Log.Infof("GroupSupportList: rule out %v, limit exeeded", userIds[supportLevel:])
out = append(out, userIds[supportLevel:]...) out = append(out, userIds[supportLevel:]...)
userIds = userIds[0:supportLevel] userIds = userIds[0:supportLevel]
} }
result = userIds result = userIds
return nil
})
if err == nil {
return result, out, nil return result, out, nil
} else {
return nil, nil, err //err := s.svc.Transactional(func() error {
} // model := domain.CreateModel(s.svc.CtxAndDb)
//
// // 1. 去掉非群管理者
// roles, _, err := group_m.GetRolesInGroup(model, groupId)
// if err != nil {
// return err
// }
// userIds := make([]uint64, 0)
// for _, i := range uids {
// if _, ok := roles[i]; ok {
// userIds = append(userIds, i)
// } else {
// out = append(out, i)
// model.Log.Infof("GroupSupportList: rule out %d, no role", i)
// }
// }
//
// // TODO: 去掉非群成员
//
// //(4)1个账户只能做1个群组的管理员(5)1个设备下只允许领取1个管理奖励
// _, _, period := group_m.GetLastSupportPeriod(time.Now())
// gsa := group_m.GroupSupportAwardMgr{Period: period}
// rows, err := gsa.Get(model.Db)
// if err != nil {
// return err
// }
// awards := make(map[uint64]struct{}, 0)
// for _, i := range rows {
// awards[i.UserId] = struct{}{}
// }
//
// uids = userIds
// userIds = make([]uint64, 0)
// m := make(map[uint64]uint64)
// for _, u := range uids {
// m, err := user_m.GetSameImeiMap(model, u)
// if err != nil {
// return err
// }
//
// passed := true
// for _, i := range m {
// if _, ok := awards[i]; ok {
// if i == u {
// passed = false
// model.Log.Infof("GroupSupportList: rule out %d, already awarded", i)
// } else {
// passed = false
// model.Log.Infof("GroupSupportList: rule out %d, imei awarded", i)
// }
// }
// }
// if passed == true {
// userIds = append(userIds, u)
// } else {
// out = append(out, u)
// }
// }
// model.Log.Infof("GroupSupportList: uids %v, map %v", uids, m)
//
// _, supportLevel, err := s.GetSupportLevel(groupId)
// if err != nil {
// return err
// }
//
// if uint32(len(userIds)) > supportLevel {
// model.Log.Infof("GroupSupportList: rule out %v, limit exeeded", userIds[supportLevel:])
// out = append(out, userIds[supportLevel:]...)
// userIds = userIds[0:supportLevel]
// }
// result = userIds
// return nil
//})
//
//if err == nil {
// return result, out, nil
//} else {
// return nil, nil, err
//}
} }
func (s *GroupService) GetSupportLevel(groupId string) (uint64, uint32, error) { func (s *GroupService) GetSupportLevel(groupId string) (uint64, uint32, error) {
...@@ -132,17 +202,50 @@ func (s *GroupService) GetSupportLevel(groupId string) (uint64, uint32, error) { ...@@ -132,17 +202,50 @@ func (s *GroupService) GetSupportLevel(groupId string) (uint64, uint32, error) {
return 0, 0, nil return 0, 0, nil
} }
func (s *GroupService) GetSupportLevelByRedis(groupId string) (*res_m.ResGroupSupport, uint32, error) {
model := domain.CreateModel(s.svc.CtxAndDb)
_, _, period := group_m.GetLastSupportPeriod(time.Now())
consume, count, err := GetGroupConsumeCount(model, groupId, period)
if err != nil {
return nil, 0, err
}
rec, err := res_m.GetResGroupSupportBy(model, count, consume)
if err != nil {
return nil, 0, err
}
if rec != nil {
return rec, rec.MgrNum, nil
}
return rec, 0, nil
}
func GetGroupConsumeCount(model *domain.Model, imGroupId, period string) (uint64, uint32, error) {
// 流水
keyDiamond := rediskey.GetGroupSupportConsumeSummary(period)
consume, err := model.RedisCluster.ZScore(context.Background(), keyDiamond, imGroupId).Result()
if err != nil {
model.Log.Errorf("GetSupportLevelByRedis key:%v, groupId:%v, err:%v", keyDiamond, imGroupId, err)
return 0, 0, err
}
// 支持者数量
keySupportNum := rediskey.GetGroupSupportCountSupporter(period, imGroupId)
count, err := model.RedisCluster.SCard(context.Background(), keySupportNum).Result()
if err != nil {
model.Log.Errorf("GetSupportLevelByRedis key:%v, groupId:%v, err:%v", keySupportNum, imGroupId, err)
return 0, 0, err
}
return uint64(consume), uint32(count), nil
}
//群组支持奖励 //群组支持奖励
func (s *GroupService) GroupSupportAward(groupId string, profitAllocator uint64, userIds []uint64, resId uint64, period string) error { func (s *GroupService) GroupSupportAward(groupId string, profitAllocator uint64, userIds []uint64, resSupport *res_m.ResGroupSupport,
period string, groupInfo *group_m.GroupInfo) error {
return s.svc.Transactional(func() error { return s.svc.Transactional(func() error {
model := domain.CreateModel(s.svc.CtxAndDb) model := domain.CreateModel(s.svc.CtxAndDb)
//
groupInfo, err := group_m.GetGroupInfo(model, groupId)
if groupInfo == nil {
return bizerr.GroupNotFound
}
//发放奖励 //发放奖励
groupSupportAwardAdmin, groupSupportAwardMgrs, err := group_m.AddGroupSupportAward(model, groupId, profitAllocator, resId, userIds, period) groupSupportAwardAdmin, groupSupportAwardMgrs, err := group_m.AddGroupSupportAward(model, groupId, profitAllocator, resSupport, userIds, period)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -6,13 +6,11 @@ import ( ...@@ -6,13 +6,11 @@ import (
"git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"hilo-group/_const/enum/gift_e"
"hilo-group/_const/enum/group_e" "hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/msg_e" "hilo-group/_const/enum/msg_e"
"hilo-group/cv/group_cv" "hilo-group/cv/group_cv"
"hilo-group/cv/user_cv" "hilo-group/cv/user_cv"
"hilo-group/domain/cache/group_c" "hilo-group/domain/cache/group_c"
"hilo-group/domain/model/gift_m"
"hilo-group/domain/model/group_m" "hilo-group/domain/model/group_m"
"hilo-group/domain/model/res_m" "hilo-group/domain/model/res_m"
"hilo-group/domain/model/user_m" "hilo-group/domain/model/user_m"
...@@ -111,18 +109,28 @@ func GetSupportDetail(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -111,18 +109,28 @@ func GetSupportDetail(c *gin.Context) (*mycontext.MyContext, error) {
result := group_cv.SupportPageDetail{GroupId: txGroupId} result := group_cv.SupportPageDetail{GroupId: txGroupId}
now := time.Now() now := time.Now()
beginTime, endTime, _ := group_m.GetSupportLevelTime(now) _, endTime, period := group_m.GetSupportLevelTime(now)
result.RemainSecond = endTime.Unix() - now.Unix() result.RemainSecond = endTime.Unix() - now.Unix()
g := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, SceneUid: groupId, Model: model} //g := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, SceneUid: groupId, Model: model}
result.CurrentCount, result.CurrentConsume, err = g.GetConsumeByRange(beginTime, endTime) //result.CurrentCount, result.CurrentConsume, err = g.GetConsumeByRange(beginTime, endTime)
//if err != nil {
// return myContext, err
//}
result.CurrentConsume, result.CurrentCount, err = group_s.GetGroupConsumeCount(model, groupId, period)
if err != nil { if err != nil {
model.Log.Errorf("GetSupportDetail groupId:%s, err:%v", groupId, err)
return myContext, err return myContext, err
} }
beginTime, endTime, _ = group_m.GetSupportLevelTime(now.AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY)) _, _, periodLast := group_m.GetSupportLevelTime(now.AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY))
result.LastCount, result.LastConsume, err = g.GetConsumeByRange(beginTime, endTime) //result.LastCount, result.LastConsume, err = g.GetConsumeByRange(beginTimeLast, endTimeLast)
//if err != nil {
// return myContext, err
//}
result.LastConsume, result.LastCount, err = group_s.GetGroupConsumeCount(model, groupId, periodLast)
if err != nil { if err != nil {
model.Log.Errorf("GetSupportDetail groupId:%s, err:%v", groupId, err)
return myContext, err return myContext, err
} }
...@@ -152,7 +160,7 @@ func GetSupportDetail(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -152,7 +160,7 @@ func GetSupportDetail(c *gin.Context) (*mycontext.MyContext, error) {
} }
// 判断这个周期这个群的奖金是否已经发过 // 判断这个周期这个群的奖金是否已经发过
_, _, period := group_m.GetLastSupportPeriod(now) _, _, period = group_m.GetLastSupportPeriod(now)
gsaa := group_m.GroupSupportAwardAdmin{Period: period, GroupUid: groupId} gsaa := group_m.GroupSupportAwardAdmin{Period: period, GroupUid: groupId}
rows, err := gsaa.Get(model.Db) rows, err := gsaa.Get(model.Db)
if err != nil { if err != nil {
...@@ -335,20 +343,24 @@ func TakeSupportAward(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -335,20 +343,24 @@ func TakeSupportAward(c *gin.Context) (*mycontext.MyContext, error) {
return myContext, bizerr.GroupAlreadyAwarded return myContext, bizerr.GroupAlreadyAwarded
} }
userIds, outUserIds, err := group_s.NewGroupService(myContext).GroupSupportList(groupId, userIds)
model.Log.Infof("TakeSupportAward: %v, %v", userIds, outUserIds)
model = domain.CreateModelContext(myContext) model = domain.CreateModelContext(myContext)
resSupportId, _, err := group_s.NewGroupService(myContext).GetSupportLevel(groupId) resSupport, supportLevel, err := group_s.NewGroupService(myContext).GetSupportLevelByRedis(groupId)
if err != nil { if err != nil {
return myContext, err return myContext, err
} }
if resSupportId <= 0 { if resSupport.ID <= 0 {
return myContext, bizerr.NotQualified return myContext, bizerr.NotQualified
} }
userIds, outUserIds, err := group_s.NewGroupService(myContext).GroupSupportList(groupId, userIds, supportLevel)
model.Log.Infof("TakeSupportAward: %v, %v", userIds, outUserIds)
if err != nil {
model.Log.Errorf("TakeSupportAward groupId:%v, userId:%v err:%v", groupId, userId, err)
return myContext, err
}
// 检查userIds的ip限制 // 检查userIds的ip限制
userIp, err := user_m.GetUserIpMap(model.Db, userIds) userIp, err := user_m.GetUserIpMap(model.Db, userIds)
if err != nil { if err != nil {
...@@ -382,8 +394,12 @@ func TakeSupportAward(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -382,8 +394,12 @@ func TakeSupportAward(c *gin.Context) (*mycontext.MyContext, error) {
} }
} }
groupInfo, err := group_m.GetGroupInfo(model, groupId)
if groupInfo == nil || groupInfo.Id <= 0 {
return myContext, bizerr.GroupNotFound
}
// 真正地放奖励 // 真正地放奖励
err = group_s.NewGroupService(myContext).GroupSupportAward(groupId, pa, userIds, resSupportId, period) err = group_s.NewGroupService(myContext).GroupSupportAward(groupId, pa, userIds, resSupport, period, groupInfo)
if err != nil { if err != nil {
return myContext, err return myContext, 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