52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package luckygift
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"strconv"
|
|
|
|
"chatapp3-golang/internal/service/highwin"
|
|
)
|
|
|
|
func (s *LuckyGiftService) publishHighWinRegionBroadcasts(ctx context.Context, req LuckyGiftDrawRequest, results []LuckyGiftDrawResult, balanceAfter int64) {
|
|
if s == nil || s.highWinBroadcaster == nil || req.GiftPrice <= 0 {
|
|
return
|
|
}
|
|
for _, result := range results {
|
|
if result.RewardNum <= 0 {
|
|
continue
|
|
}
|
|
multiple := highwin.IntegralMultiple(result.RewardNum, req.GiftPrice)
|
|
if !highwin.ShouldBroadcast(float64(multiple), result.RewardNum) {
|
|
continue
|
|
}
|
|
data := map[string]any{
|
|
"businessId": req.BusinessID,
|
|
"orderId": result.ID,
|
|
"providerOrderId": result.OrderID,
|
|
"acceptUserId": strconv.FormatInt(result.AcceptUserID, 10),
|
|
"giftId": strconv.FormatInt(req.GiftID, 10),
|
|
"giftCandy": req.GiftPrice,
|
|
"giftQuantity": req.GiftNum,
|
|
"multipleType": luckyGiftMultipleType(multiple),
|
|
"balance": balanceAfter,
|
|
"globalNews": true,
|
|
}
|
|
if err := highwin.SendRegionBroadcast(ctx, s.highWinBroadcaster, highwin.BroadcastEvent{
|
|
SysOrigin: req.SysOrigin,
|
|
Type: highwin.MessageTypeLuckyGift,
|
|
UserID: req.SendUserID,
|
|
RoomID: strconv.FormatInt(req.RoomID, 10),
|
|
Multiple: float64(multiple),
|
|
Amount: result.RewardNum,
|
|
Data: data,
|
|
}); err != nil {
|
|
log.Printf("send lucky gift high win region broadcast failed businessId=%s orderId=%s: %v", req.BusinessID, result.ID, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func luckyGiftMultipleType(_ int64) string {
|
|
return "WIN"
|
|
}
|