|
|
|
|
package call
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"reflect"
|
|
|
|
|
"server/common"
|
|
|
|
|
"server/db"
|
|
|
|
|
"server/pb"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/liangdas/mqant/log"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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{}
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if unReadCount > 0 {
|
|
|
|
|
one := &pb.RedPoint{
|
|
|
|
|
List: []*pb.RedInfo{
|
|
|
|
|
{
|
|
|
|
|
ModuleName: pb.RedPointModule_RedPointMail,
|
|
|
|
|
Num: uint32(unReadCount),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
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 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")
|
|
|
|
|
}
|