You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
4.1 KiB
163 lines
4.1 KiB
package call |
|
|
|
import ( |
|
"github.com/liangdas/mqant/log" |
|
"server/common" |
|
"server/db" |
|
"server/pb" |
|
"server/util" |
|
"time" |
|
) |
|
|
|
const ( |
|
ModuleMail = "Mail" |
|
) |
|
|
|
// UpsertRedPointAndNotify 更新红点并通知客户端 |
|
func UpsertRedPointAndNotify(uid, num int, module string) { |
|
//red := &common.PlayerRed{UID: uid} |
|
//db.Mysql().Get(red) |
|
//val := reflect.ValueOf(red).Elem().FieldByName(module) |
|
//diff := int(val.Int()) + num |
|
//if red.ID == 0 { |
|
// if diff < 0 { |
|
// diff = 0 |
|
// } |
|
// val.SetInt(int64(diff)) |
|
// db.Mysql().Create(red) |
|
//} else { |
|
// update := map[string]interface{}{} |
|
// if num == 0 || diff <= 0 { |
|
// update[module] = 0 |
|
// val.SetInt(0) |
|
// } else { |
|
// update[module] = gorm.Expr(fmt.Sprintf("%v + ?", strings.ToLower(module)), num) |
|
// val.SetInt(int64(diff)) |
|
// } |
|
// db.Mysql().Update(&common.PlayerRed{UID: uid}, update) |
|
//} |
|
//send := &pb.RedPoint{} |
|
switch module { |
|
case ModuleMail: |
|
PushMailRed(uid) |
|
} |
|
//send.List = append(send.List, &pb.RedInfo{ModuleName: pb.RedPointModule_RedPointMail, Num: uint32(diff)}) |
|
//SendNR(uid, int(pb.ServerCommonResp_CommonRedPointResp), send, "common") |
|
} |
|
|
|
func PushMailRed(uid int) { |
|
//redPoints := &common.PlayerRed{UID: uid} |
|
//db.Mysql().Get(redPoints) |
|
var user common.PlayerDBInfo |
|
err := db.Mysql().C().Model(&common.PlayerDBInfo{}).Where("id = ?", uid).Find(&user).Error |
|
if err != nil { |
|
log.Error("get user err, %s", err.Error()) |
|
return |
|
} |
|
rechargeInfo := GetRechargeInfo(uid) |
|
list := []common.Mail{} |
|
unReadCount, err := db.Mysql().QueryMailList(uid, 0, 0, user.Birth, int64(user.ChannelID), rechargeInfo.TotalRecharge, -1, true, &list) |
|
if err != nil { |
|
log.Error("get un read mail count err, %s", err.Error()) |
|
return |
|
} |
|
|
|
var platform, personal bool |
|
one := &pb.RedPoint{ |
|
Mail: 1, |
|
} |
|
for _, v := range list { |
|
if v.Tag == 0 && !platform { |
|
platform = true |
|
one.List = append(one.List, &pb.RedInfo{ModuleName: pb.RedPointModule_RedPointMail, Num: uint32(unReadCount)}) |
|
} else if v.Tag == 1 && !personal { |
|
personal = true |
|
one.List = append(one.List, &pb.RedInfo{ModuleName: pb.RedPointModule_RedPointMailPersonal, Num: uint32(unReadCount)}) |
|
} |
|
if platform && personal { |
|
break |
|
} |
|
} |
|
if unReadCount > 0 { |
|
SendNR(uid, int(pb.ServerCommonResp_CommonRedPointResp), one, "common") |
|
} |
|
//if redPoints.Mail > 0 { |
|
// one := new(pb.RedPoint) |
|
// one.List = append(one.List, &pb.RedInfo{ModuleName: pb.RedPointModule_RedPointMail, Num: uint32(redPoints.Mail)}) |
|
// SendNR(uid, int(pb.ServerCommonResp_CommonRedPointResp), one, "common") |
|
//} |
|
} |
|
|
|
func PushVipRed(uid int) { |
|
vipInfo := GetVIP(uid) |
|
configVip := GetConfigVIPWithout0() |
|
var levelBonus []int |
|
for level := 1; level <= vipInfo.Level; level++ { |
|
flag := int64(1 << level) |
|
if vipInfo.Draws&flag == 0 { |
|
levelBonus = append(levelBonus, level) |
|
} |
|
} |
|
con := GetConfigVIPByLevel(vipInfo.Level) |
|
if con == nil { |
|
return |
|
} |
|
var weekBonus bool |
|
if con.BonusWeek != 0 { // 有周奖励 |
|
if vipInfo.WeekBonusAt == 0 { // 可以领取 |
|
weekBonus = true |
|
} else { |
|
weekBonus = !util.IsSameWeek(time.Now().Unix(), vipInfo.WeekBonusAt) |
|
} |
|
} |
|
|
|
var award bool |
|
for _, v := range configVip { |
|
if util.SliceContain(levelBonus, v.Level) && v.Bonus > 0 { |
|
award = true |
|
break |
|
} |
|
if v.Level == vipInfo.Level { |
|
if weekBonus && v.BonusWeek > 0 { |
|
award = true |
|
break |
|
} |
|
} |
|
} |
|
if award { |
|
PushRed(uid, pb.RedPointModule_RedPointVipReward, 1) |
|
} |
|
} |
|
|
|
func PushWeekCard(uid int) { |
|
cons := GetConfigWeekCard() |
|
if cons == nil { |
|
return |
|
} |
|
weekCardData, err := GetWeekCardData(uid) |
|
if err != nil { |
|
return |
|
} |
|
if weekCardData.ID == 0 { |
|
return |
|
} |
|
now := time.Now() |
|
var award bool |
|
if weekCardData.ID != 0 && weekCardData.BeginAt != 0 { // 已经购买周卡的情况下 |
|
if !util.IsSameDayTimeStamp(now.Unix(), weekCardData.AwardAt) { |
|
award = true |
|
} |
|
} |
|
|
|
if award { |
|
PushRed(uid, pb.RedPointModule_RedPointWeekCard, 1) |
|
} |
|
} |
|
|
|
func PushRed(uid int, module pb.RedPointModule, num uint32) { |
|
one := new(pb.RedPoint) |
|
one.List = append(one.List, &pb.RedInfo{ModuleName: module, Num: num}) |
|
log.Debug("redpoint,uid:%v,module:%v,info:%v", uid, module, one) |
|
SendNR(uid, int(pb.ServerCommonResp_CommonRedPointResp), one, "common") |
|
checkMail(uid, nil) |
|
}
|
|
|