diff --git a/call/mail.go b/call/mail.go index bf6a58c..2249a97 100644 --- a/call/mail.go +++ b/call/mail.go @@ -6,9 +6,6 @@ import ( "server/db" "server/util" "time" - - "github.com/liangdas/mqant/log" - "gorm.io/gorm" ) var ( @@ -21,7 +18,7 @@ var ( EmailShareRank = "Congratulations on achieving Rank %v in the million giveaway event. You have received a bonus of ₹%v. Thank you for participating!" ) -func checkMail(uid int, red *common.PlayerRed) { +func checkMail(uid int, red *common.PlayerRed) (unReadCount int) { data := &common.PlayerData{UID: uid} db.Mysql().Get(data) user := &common.PlayerDBInfo{Id: uid} @@ -54,11 +51,11 @@ func checkMail(uid int, red *common.PlayerRed) { db.Mysql().QueryAll(sql, "", &common.Mail{}, &all) if len(all) > 0 { now := time.Now().Unix() - u, err := db.Mysql().UpdateRes(&common.PlayerData{UID: uid, LastSysEmailDraw: data.LastSysEmailDraw}, &common.PlayerData{LastSysEmailDraw: now}) - if err != nil || u == 0 { - log.Error("err:%v", err) - return - } + //u, err := db.Mysql().UpdateRes(&common.PlayerData{UID: uid, LastSysEmailDraw: data.LastSysEmailDraw}, &common.PlayerData{LastSysEmailDraw: now}) + //if err != nil || u == 0 { + // log.Error("err:%v", err) + // return + //} for _, v := range all { one := v one.ID = 0 @@ -67,14 +64,16 @@ func checkMail(uid int, red *common.PlayerRed) { db.Mysql().Create(&one) mailCount++ } - if red.ID == 0 { - red.Mail = mailCount - db.Mysql().Create(red) - } else { - db.Mysql().Update(red, map[string]interface{}{"mail": gorm.Expr("mail + ?", mailCount)}) - } + //if red.ID == 0 { + // red.Mail = mailCount + // db.Mysql().Create(red) + //} else { + // db.Mysql().Update(red, map[string]interface{}{"mail": gorm.Expr("mail + ?", mailCount)}) + //} } - red.Mail += mailCount + unReadCount = int(db.Mysql().Count(&common.Mail{}, fmt.Sprintf("receiver = %d and `status` = %d", uid, common.MailStatusNew))) + //red.Mail += mailCount + return } const ( diff --git a/call/redpoint.go b/call/redpoint.go index 8b65695..f482a93 100644 --- a/call/redpoint.go +++ b/call/redpoint.go @@ -45,18 +45,33 @@ func UpsertRedPointAndNotify(uid, num int, module string) { } func PushMailRed(uid int) { - redPoints := &common.PlayerRed{UID: uid} - db.Mysql().Get(redPoints) - checkMail(uid, redPoints) - one := &pb.RedPoint{ - List: []*pb.RedInfo{ - { - ModuleName: pb.RedPointModule_RedPointMail, - Num: uint32(redPoints.Mail), + //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") } - SendNR(uid, int(pb.ServerCommonCmd_CMD_BS_RedPointResp), 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)}) diff --git a/db/mysql/mysql_mail.go b/db/mysql/mysql_mail.go index 7978160..8d4db06 100644 --- a/db/mysql/mysql_mail.go +++ b/db/mysql/mysql_mail.go @@ -8,7 +8,7 @@ import ( ) // QueryMailList 查询玩家邮件列表 -func (c *MysqlClient) QueryMailList(uid, page, num int, birth, channelId, rechargeAmount int64, tag int, list *[]common.Mail) (count int64, err error) { +func (c *MysqlClient) QueryMailList(uid, page, num int, birth, channelId, rechargeAmount int64, tag int, unRead bool, list *[]common.Mail) (count int64, err error) { now := time.Now().Unix() start := now - common.MailExpireTime today := util.GetZeroTime(time.Now()) @@ -30,8 +30,17 @@ func (c *MysqlClient) QueryMailList(uid, page, num int, birth, channelId, rechar rechargeAmount, channelId, ) - sql += fmt.Sprintf(" and `tag` = %d ", tag) - count, err = c.QueryList(page, num, sql, "status,time desc", &common.Mail{}, &list) + if tag != -1 { + sql += fmt.Sprintf(" and `tag` = %d ", tag) + } + if unRead { + sql += fmt.Sprintf(" and `status` = %d ", common.MailStatusNew) + } + if page > 0 || num > 0 { + count, err = c.QueryList(page, num, sql, "status,time desc", &common.Mail{}, &list) + } else { + count, err = c.QueryList(0, 0, sql, "status,time desc", &common.Mail{}, &list) + } if count > common.MailMaxCount { count = common.MailMaxCount } diff --git a/modules/hall/player.go b/modules/hall/player.go index ad6f885..a8ca150 100644 --- a/modules/hall/player.go +++ b/modules/hall/player.go @@ -20,6 +20,7 @@ type player struct { } func (p *player) PushRedPoint() { + call.PushRed(p.db.Id, pb.RedPointModule_RedPointFreeCash, uint32(1)) call.PushMailRed(p.db.Id) } diff --git a/modules/web/handler/activity.go b/modules/web/handler/activity.go index 7b97e54..54dc045 100644 --- a/modules/web/handler/activity.go +++ b/modules/web/handler/activity.go @@ -9,7 +9,6 @@ import ( "server/db" "server/modules/web/app" "server/modules/web/values" - "server/pb" "server/util" "sort" "strconv" @@ -112,7 +111,7 @@ func GetPromotions(c *gin.Context) { } } if num > 0 { - call.PushRed(a.UID, pb.RedPointModule_RedPointTask, uint32(num)) + //call.PushRed(a.UID, pb.RedPointModule_RedPointTask, uint32(num)) } } @@ -673,7 +672,7 @@ func ActivityFirstRechargeBackInfo(c *gin.Context) { } resp.Back = data.Reward if !resp.Draw { - call.PushRed(a.UID, pb.RedPointModule_RedPointFirstRecharge, 1) + //call.PushRed(a.UID, pb.RedPointModule_RedPointFirstRecharge, 1) } } @@ -722,7 +721,7 @@ func ActivityFirstRechargeBackDraw(c *gin.Context) { } resp.Reward = val call.UploadActivityData(a.UID, common.ActivityIDFirstRechargeBack, common.ActivityDataJoin, val) - call.PushRed(a.UID, pb.RedPointModule_RedPointFirstRecharge, 0) + //call.PushRed(a.UID, pb.RedPointModule_RedPointFirstRecharge, 0) } // 幸运码活动 @@ -1195,7 +1194,7 @@ func ActivitySignNewInfo(c *gin.Context) { num = 1 } if num > 0 { - call.PushRed(a.UID, pb.RedPointModule_RedPointSign, uint32(num)) + //call.PushRed(a.UID, pb.RedPointModule_RedPointSign, uint32(num)) } a.Data = resp } @@ -1279,7 +1278,7 @@ func ActivitySignNewDraw(c *gin.Context) { } a.Data = values.ActivitySignDrawResp{Reward: reward, Day: day, Sign: newSign} call.UploadActivityData(a.UID, common.ActivityIDSign, common.ActivityDataJoin, reward) - call.PushRed(a.UID, pb.RedPointModule_RedPointSign, uint32(0)) + //call.PushRed(a.UID, pb.RedPointModule_RedPointSign, uint32(0)) } // 破产礼包活动 @@ -1803,7 +1802,7 @@ func ActivityBetDrawInfo(c *gin.Context) { if resp.Lucky >= item.Cost && vipInfo.Level >= item.VipUnlock && drawInfo.SpinInfo.SpinNum < drawInfo.SpinInfo.SpinCount && now.Unix() >= drawInfo.SpinInfo.NextSpinTIme { - call.PushRed(a.UID, pb.RedPointModule_RedPointFreeSpin, uint32(1)) + //call.PushRed(a.UID, pb.RedPointModule_RedPointFreeSpin, uint32(1)) break } } @@ -1895,7 +1894,7 @@ func ActivityBetDrawDraw(c *gin.Context) { drawInfo = common.ActivityBetDrawData{UID: a.UID} db.Mysql().Get(&drawInfo) - call.PushRed(a.UID, pb.RedPointModule_RedPointFreeSpin, uint32(0)) + //call.PushRed(a.UID, pb.RedPointModule_RedPointFreeSpin, uint32(0)) } func ActivityBetDrawHistory(c *gin.Context) { diff --git a/modules/web/handler/mail.go b/modules/web/handler/mail.go index 440429b..5ca582e 100644 --- a/modules/web/handler/mail.go +++ b/modules/web/handler/mail.go @@ -33,7 +33,7 @@ func MailList(c *gin.Context) { return } rechargeInfo := call.GetRechargeInfo(a.UID) - count, err := db.Mysql().QueryMailList(a.UID, req.Page, req.Num, user.Birth, int64(user.ChannelID), rechargeInfo.TotalRecharge, req.Tag, &list) + count, err := db.Mysql().QueryMailList(a.UID, req.Page, req.Num, user.Birth, int64(user.ChannelID), rechargeInfo.TotalRecharge, req.Tag, false, &list) if err != nil { a.Code = values.CodeRetry return @@ -60,28 +60,35 @@ func ReadMail(c *gin.Context) { if !a.S(req) { return } - // id, err := strconv.Atoi(req.ID) - // if err != nil { - // log.Error("err:%v", err) - // a.Code = values.CodeRetry - // return - // } - id := req.ID - one := &common.Mail{ID: id} - err := db.Mysql().Get(one) - if err != nil { + if req.ID == 0 && req.All { a.Code = values.CodeRetry return } - count, err := db.Mysql().UpdateRes(&common.Mail{ID: id, Status: common.MailStatusNew}, map[string]interface{}{"status": common.MailStatusRead}) - if count == 0 || err != nil { - log.Error("err:%v", err) - a.Code = values.CodeRetry - return + if req.ID > 0 { + id := req.ID + one := &common.Mail{ID: id} + err := db.Mysql().Get(one) + if err != nil { + a.Code = values.CodeRetry + return + } + count, err := db.Mysql().UpdateRes(&common.Mail{ID: id, Status: common.MailStatusNew}, map[string]interface{}{"status": common.MailStatusRead}) + if count == 0 || err != nil { + log.Error("err:%v", err) + a.Code = values.CodeRetry + return + } + a.Data = values.ReadMailResp{Mail: *one} + } else if req.All { + count, err := db.Mysql().UpdateRes(&common.Mail{Receiver: a.UID, Status: common.MailStatusNew}, map[string]interface{}{"status": common.MailStatusRead}) + if count == 0 || err != nil { + log.Error("err:%v", err) + a.Code = values.CodeRetry + return + } } - // call.UpsertRedPointAndNotify(a.UID, -1, call.ModuleMail) - a.Data = values.ReadMailResp{Mail: *one} - + //call.UpsertRedPointAndNotify(a.UID, -1, call.ModuleMail) + return } func DrawMail(c *gin.Context) { diff --git a/modules/web/handler/task.go b/modules/web/handler/task.go index a0e107c..9452106 100644 --- a/modules/web/handler/task.go +++ b/modules/web/handler/task.go @@ -1,15 +1,13 @@ package handler import ( + "github.com/gin-gonic/gin" + "github.com/liangdas/mqant/log" "server/call" "server/common" "server/db" "server/modules/web/app" "server/modules/web/values" - "server/pb" - - "github.com/gin-gonic/gin" - "github.com/liangdas/mqant/log" ) // Record 领奖进度,key为taskid,value为任务进度,小与0时表示已领取 @@ -32,7 +30,7 @@ func GetTaskInfo(c *gin.Context) { } } if num > 0 { - call.PushRed(a.UID, pb.RedPointModule_RedPointTask, uint32(num)) + //call.PushRed(a.UID, pb.RedPointModule_RedPointTask, uint32(num)) } } @@ -104,5 +102,5 @@ func DrawTask(c *gin.Context) { num++ } } - call.PushRed(a.UID, pb.RedPointModule_RedPointTask, uint32(num)) + //call.PushRed(a.UID, pb.RedPointModule_RedPointTask, uint32(num)) } diff --git a/modules/web/handler/vip.go b/modules/web/handler/vip.go index 360c490..02eeb3a 100644 --- a/modules/web/handler/vip.go +++ b/modules/web/handler/vip.go @@ -168,7 +168,7 @@ func GetVipInfo(c *gin.Context) { db.ES().QueryList(common.ESIndexBalance, req.Page, req.Num, q, &resp.CashbackList, "time", false) reset = !util.IsSameDayTimeStamp(now.Unix(), resp.Info.ProfitTime) if reset && resp.Info.Cashback > 0 { - call.PushRed(a.UID, pb.RedPointModule_RedPointVipCashback, uint32(1)) + call.PushRed(a.UID, pb.RedPointModule_RedPointVipReward, uint32(1)) } if hasVipBonus(resp.Info) { call.PushRed(a.UID, pb.RedPointModule_RedPointVipReward, uint32(1)) @@ -490,5 +490,5 @@ func DrawVipCashback(c *gin.Context) { resp.NextCashback = util.GetNext5MinUnix() - now.Unix() } a.Data = resp - call.PushRed(a.UID, pb.RedPointModule_RedPointVipCashback, uint32(0)) + call.PushRed(a.UID, pb.RedPointModule_RedPointVipReward, uint32(0)) } diff --git a/modules/web/values/protocol.go b/modules/web/values/protocol.go index 5dcf7b5..11fa5cb 100644 --- a/modules/web/values/protocol.go +++ b/modules/web/values/protocol.go @@ -125,7 +125,8 @@ type MailListResp struct { // ReadMailReq 读取一封邮件 // ID 邮件id type ReadMailReq struct { - ID int `json:"id" binding:"required"` + ID int `json:"id"` + All bool `json:"all"` } // ReadMailResp 读取一封邮件 diff --git a/pb/proto/platform.proto b/pb/proto/platform.proto index 02ad04f..1db73b9 100644 --- a/pb/proto/platform.proto +++ b/pb/proto/platform.proto @@ -46,19 +46,31 @@ message LoginResponse{ uint32 user_id = 2; // UID:这个地方必定和请求中的uid一致,但是为了方便客户端异步处理,把UID返回了 } +//enum RedPointModule{ +// RedPointInvalid = 0; +// RedPointTask = 1; +// RedPointSign = 2; +// RedPointShare = 3; // * +// RedPointVipCashback = 4; //* +// RedPointMail = 5;// * +// RedPointFreeSpin = 6; // 免费转盘 +// RedPointVipReward = 7; // vip升级奖励 +// RedPointLoginAgain = 8; // 第二次登录游戏 +// RedPointWeekCard = 9; // 周卡 * +// RedPointFirstRecharge = 10 ; // 首充 +// RedPointPdd = 11 ; // 拼多多活动 +//} + enum RedPointModule{ RedPointInvalid = 0; - RedPointTask = 1; - RedPointSign = 2; - RedPointShare = 3; // * - RedPointVipCashback = 4; //* - RedPointMail = 5;// * - RedPointFreeSpin = 6; // 免费转盘 - RedPointVipReward = 7; // vip升级奖励 - RedPointLoginAgain = 8; // 第二次登录游戏 - RedPointWeekCard = 9; // 周卡 * - RedPointFirstRecharge = 10 ; // 首充 - RedPointPdd = 11 ; // 拼多多活动 + RedPointMail = 1; // 邮件 + RedPointVipReward = 2; // vip奖励 + RedPointWithdraw = 3; // 提现 + RedPointFreeCash = 4; // 免费现金 + RedPointShare = 5; // 分享 + RedPointWeekCard = 6; // 周卡 + RedPointCashBack = 7; // 返现 + RedPointPdd = 8; // pdd次数 } message RedInfo {