cp_level.go 1.02 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8
package event_s

import (
	"git.hilo.cn/hilo-common/domain"
	"hilo-user/domain/event/gift_ev"
	"hilo-user/domain/model/cp_m"
)

hujiebin's avatar
hujiebin committed
9 10 11
// 送礼增加cp等级
// 送礼增加cp排行榜
func CpGiftEvent() {
hujiebin's avatar
hujiebin committed
12 13 14 15 16 17 18 19 20
	gift_ev.AddSendGiftEventAsync(func(model *domain.Model, event interface{}) error {
		sendGiftEvent, ok := event.(*gift_ev.SendGiftEvent)
		if !ok {
			model.Log.Errorf("AddSendGiftEventAsync event type err")
			return nil
		}
		for _, receiverUid := range sendGiftEvent.ReceiveUserIds {
			diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum
			// 有cp关系
hujiebin's avatar
hujiebin committed
21
			if cpRelation, exits := cp_m.GetCpRelationPair(model, sendGiftEvent.SendUserId, receiverUid); exits {
hujiebin's avatar
hujiebin committed
22 23 24 25 26 27 28
				if err := cp_m.AddCpLevelPoints(model, cpRelation, diamonds); 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)
				}
				return nil // 业务场景允许提前break(cp是唯一的)
hujiebin's avatar
hujiebin committed
29 30 31 32 33
			}
		}
		return nil
	})
}