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 }