send_gift_redis.go 3.49 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
package gift_cron

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
	"hilo-group/_const/enum/groupPower_e"
	"hilo-group/domain/cache/gift_c"
	"hilo-group/domain/event/gift_ev"
	"hilo-group/domain/model/groupPower_m"
)

// 送礼事件
func SendGiftEvent() {
	//if !config.IsMaster() {
	//	return
	//}
	go func() {
		for true {
			model := domain.CreateModelNil()
			if sendGiftEvent := gift_c.BLPopQueueSendGift(model); sendGiftEvent != nil {
				groupPowerGrade(model, sendGiftEvent) // 家族经验
				groupPowerStar(model, sendGiftEvent)  // 家族之星
			}
		}
	}()
}

// 群组势力经验
func groupPowerGrade(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
	model.Log.Infof("AddSendGiftEventAsync %+v", sendGiftEvent)
	if sendGiftEvent.ResGift.GiftType != mysql.DiamondYellow {
		return
	}
	exist, groupPowerId, err := groupPower_m.CheckGroupPowerUser(model, sendGiftEvent.SendUserId)
	if err != nil {
		model.Log.Infof("CheckGroupPowerUser fail %+v", err)
		return
	}
	if exist {
		exp := sendGiftEvent.GiftN * mysql.Num(len(sendGiftEvent.ReceiveUserIds)) * sendGiftEvent.ResGift.DiamondNum
		//return model.Transaction(func(model *domain.Model) error {
		//	return groupPower_m.IncrGroupPowerExp(model, groupPowerId, exp, sendGiftEvent.SendUserId, "送礼")
		//})
		//return groupPower_c.QueueGroupPowerGradeExp(model, groupPowerId, exp, sendGiftEvent.SendUserId, "送礼")
		if err := model.Transaction(func(model *domain.Model) error {
			return groupPower_m.IncrGroupPowerExp(model, groupPowerId, exp, sendGiftEvent.SendUserId, "送礼")
		}); err != nil {
			model.Log.Errorf("IncrGroupPowerExp fail,data:%v-err:%v", *sendGiftEvent, err)
		} else {
			model.Log.Infof("IncrGroupPowerExp success,data:%v", *sendGiftEvent)
		}
	}
}

// 家族之星
func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
	if sendGiftEvent.ResGift.GiftType != mysql.DiamondYellow {
		return
	}
	var userIds = []mysql.ID{sendGiftEvent.SendUserId}
	userIds = append(userIds, sendGiftEvent.ReceiveUserIds...)
	groupPowers, err := groupPower_m.BatchGetGroupPowerUser(model, userIds)
	if err != nil {
		model.Log.Errorf("AddSendGiftEventAsync fail:%v", err)
		return
	}
	// 送礼加分
	if data, ok := groupPowers[sendGiftEvent.SendUserId]; ok {
		diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum * mysql.Num(len(sendGiftEvent.ReceiveUserIds))
		if err := groupPower_m.IncrGroupPowerMonthStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeFamous, diamonds, 0); err != nil {
			model.Log.Errorf("IncrGroupPowerMonthStarScore famous fail:%v", err)
		}
		if err := groupPower_m.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeFamous, diamonds, 0); err != nil {
			model.Log.Errorf("IncrGroupPowerDayStarScore famous fail:%v", err)
		}
	}
	// 收礼加分
	for _, userId := range sendGiftEvent.ReceiveUserIds {
		if data, ok := groupPowers[userId]; ok {
			diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum
			if err := groupPower_m.IncrGroupPowerMonthStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeCharm, diamonds, 0); err != nil {
				model.Log.Errorf("IncrGroupPowerMonthStarScore charm fail:%v", err)
			}
			if err := groupPower_m.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeCharm, diamonds, 0); err != nil {
				model.Log.Errorf("IncrGroupPowerDayStarScore charm fail:%v", err)
			}
		}
	}
	return
}