修复发奖
This commit is contained in:
parent
2c5c247f12
commit
ffd3eeddfd
@ -96,6 +96,11 @@ func (g *Gateways) GivePropsBackpack(ctx context.Context, req GivePropsBackpackR
|
||||
return g.RewardDispatch.GivePropsBackpack(ctx, req)
|
||||
}
|
||||
|
||||
// IncrGiftBackpack 透传到礼物背包发放接口。
|
||||
func (g *Gateways) IncrGiftBackpack(ctx context.Context, userID int64, giftID int64, quantity int) error {
|
||||
return g.RewardDispatch.IncrGiftBackpack(ctx, userID, giftID, quantity)
|
||||
}
|
||||
|
||||
// GetNobleVIPAbility 透传到贵族 VIP 能力配置接口。
|
||||
func (g *Gateways) GetNobleVIPAbility(ctx context.Context, sourceID int64) (PropsNobleVIPAbility, error) {
|
||||
return g.RewardQuery.GetNobleVIPAbility(ctx, sourceID)
|
||||
@ -325,6 +330,11 @@ func (g *RewardDispatchGateway) GivePropsBackpack(ctx context.Context, req GiveP
|
||||
return g.client.GivePropsBackpack(ctx, req)
|
||||
}
|
||||
|
||||
// IncrGiftBackpack 发放礼物到用户礼物背包。
|
||||
func (g *RewardDispatchGateway) IncrGiftBackpack(ctx context.Context, userID int64, giftID int64, quantity int) error {
|
||||
return g.client.IncrGiftBackpack(ctx, userID, giftID, quantity)
|
||||
}
|
||||
|
||||
// SwitchUseProps 切换用户当前使用道具。
|
||||
func (g *RewardDispatchGateway) SwitchUseProps(ctx context.Context, userID int64, propsID int64) error {
|
||||
return g.client.SwitchUseProps(ctx, userID, propsID)
|
||||
|
||||
@ -640,6 +640,14 @@ func (c *Client) GivePropsBackpack(ctx context.Context, req GivePropsBackpackReq
|
||||
return c.postJSON(ctx, c.cfg.Java.OtherBaseURL+"/props/client/giveProps", req, nil, nil)
|
||||
}
|
||||
|
||||
func (c *Client) IncrGiftBackpack(ctx context.Context, userID int64, giftID int64, quantity int) error {
|
||||
endpoint := c.cfg.Java.OtherBaseURL + "/gift-backpack/client/incrGift?userId=" +
|
||||
url.QueryEscape(strconv.FormatInt(userID, 10)) +
|
||||
"&giftId=" + url.QueryEscape(strconv.FormatInt(giftID, 10)) +
|
||||
"&quantity=" + url.QueryEscape(strconv.Itoa(quantity))
|
||||
return c.getJSON(ctx, endpoint, nil, nil)
|
||||
}
|
||||
|
||||
func (c *Client) GetNobleVIPAbility(ctx context.Context, sourceID int64) (PropsNobleVIPAbility, error) {
|
||||
endpoint := c.cfg.Java.OtherBaseURL + "/props/noble-vip/client/getAbilityDTO?sourceId=" +
|
||||
url.QueryEscape(strconv.FormatInt(sourceID, 10))
|
||||
|
||||
@ -254,8 +254,10 @@ func (s *Service) grantResourceReward(ctx context.Context, record *model.SmashEg
|
||||
_ = s.java.RemoveUserProfileCacheAll(ctx, record.UserID)
|
||||
return nil
|
||||
}
|
||||
if resourceType == resourceTypeGift {
|
||||
return s.java.IncrGiftBackpack(ctx, record.UserID, resourceID, 1)
|
||||
}
|
||||
|
||||
useProps := resourceType != resourceTypeGift
|
||||
if err := s.java.GivePropsBackpack(ctx, integration.GivePropsBackpackRequest{
|
||||
AcceptUserID: record.UserID,
|
||||
PropsID: resourceID,
|
||||
@ -263,17 +265,15 @@ func (s *Service) grantResourceReward(ctx context.Context, record *model.SmashEg
|
||||
Origin: walletOrigin,
|
||||
OriginDesc: walletOriginDesc,
|
||||
Days: days,
|
||||
UseProps: useProps,
|
||||
UseProps: true,
|
||||
AllowGive: false,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if useProps {
|
||||
if err := s.java.SwitchUseProps(ctx, record.UserID, resourceID); err != nil {
|
||||
return err
|
||||
}
|
||||
_ = s.java.RemoveUserProfileCacheAll(ctx, record.UserID)
|
||||
if err := s.java.SwitchUseProps(ctx, record.UserID, resourceID); err != nil {
|
||||
return err
|
||||
}
|
||||
_ = s.java.RemoveUserProfileCacheAll(ctx, record.UserID)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
88
internal/service/smashegg/draw_test.go
Normal file
88
internal/service/smashegg/draw_test.go
Normal file
@ -0,0 +1,88 @@
|
||||
package smashegg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"chatapp3-golang/internal/integration"
|
||||
"chatapp3-golang/internal/model"
|
||||
)
|
||||
|
||||
type fakeSmashEggGateway struct {
|
||||
giftCalls []fakeGiftBackpackCall
|
||||
propsCalls []integration.GivePropsBackpackRequest
|
||||
switches int
|
||||
}
|
||||
|
||||
type fakeGiftBackpackCall struct {
|
||||
userID int64
|
||||
giftID int64
|
||||
quantity int
|
||||
}
|
||||
|
||||
func (g *fakeSmashEggGateway) ChangeGoldBalance(context.Context, integration.GoldReceiptCommand) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *fakeSmashEggGateway) GivePropsBackpack(_ context.Context, req integration.GivePropsBackpackRequest) error {
|
||||
g.propsCalls = append(g.propsCalls, req)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *fakeSmashEggGateway) IncrGiftBackpack(_ context.Context, userID int64, giftID int64, quantity int) error {
|
||||
g.giftCalls = append(g.giftCalls, fakeGiftBackpackCall{
|
||||
userID: userID,
|
||||
giftID: giftID,
|
||||
quantity: quantity,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *fakeSmashEggGateway) SwitchUseProps(context.Context, int64, int64) error {
|
||||
g.switches++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *fakeSmashEggGateway) ActivateTemporaryBadge(context.Context, int64, int64, int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *fakeSmashEggGateway) RemoveUserProfileCacheAll(context.Context, int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *fakeSmashEggGateway) MapGoldBalance(context.Context, []int64) (map[int64]int64, error) {
|
||||
return map[int64]int64{}, nil
|
||||
}
|
||||
|
||||
func (g *fakeSmashEggGateway) MapUserTotalRecharge(context.Context, []int64) (map[int64][]integration.UserTotalRecharge, error) {
|
||||
return map[int64][]integration.UserTotalRecharge{}, nil
|
||||
}
|
||||
|
||||
func TestGrantResourceRewardRoutesGiftToGiftBackpack(t *testing.T) {
|
||||
gateway := &fakeSmashEggGateway{}
|
||||
service := &Service{java: gateway}
|
||||
giftID := int64(2044086730826510337)
|
||||
|
||||
if err := service.grantResourceReward(context.Background(), &model.SmashEggDrawRecord{
|
||||
UserID: 2042274349343506434,
|
||||
RewardGroupID: &giftID,
|
||||
ResourceType: resourceTypeGift,
|
||||
DurationDays: 7,
|
||||
}); err != nil {
|
||||
t.Fatalf("grantResourceReward() error = %v", err)
|
||||
}
|
||||
|
||||
if len(gateway.giftCalls) != 1 {
|
||||
t.Fatalf("gift backpack calls = %d, want 1", len(gateway.giftCalls))
|
||||
}
|
||||
if got := gateway.giftCalls[0]; got.userID != 2042274349343506434 || got.giftID != giftID || got.quantity != 1 {
|
||||
t.Fatalf("gift backpack call = %+v", got)
|
||||
}
|
||||
if len(gateway.propsCalls) != 0 {
|
||||
t.Fatalf("props backpack calls = %d, want 0", len(gateway.propsCalls))
|
||||
}
|
||||
if gateway.switches != 0 {
|
||||
t.Fatalf("switch use props calls = %d, want 0", gateway.switches)
|
||||
}
|
||||
}
|
||||
@ -63,6 +63,7 @@ type smashEggDB interface {
|
||||
type gateway interface {
|
||||
ChangeGoldBalance(ctx context.Context, cmd integration.GoldReceiptCommand) error
|
||||
GivePropsBackpack(ctx context.Context, req integration.GivePropsBackpackRequest) error
|
||||
IncrGiftBackpack(ctx context.Context, userID int64, giftID int64, quantity int) error
|
||||
SwitchUseProps(ctx context.Context, userID int64, propsID int64) error
|
||||
ActivateTemporaryBadge(ctx context.Context, userID int64, badgeID int64, days int) error
|
||||
RemoveUserProfileCacheAll(ctx context.Context, userID int64) error
|
||||
|
||||
@ -324,8 +324,10 @@ func (s *Service) grantResourceReward(ctx context.Context, record *model.WheelDr
|
||||
_ = s.java.RemoveUserProfileCacheAll(ctx, record.UserID)
|
||||
return nil
|
||||
}
|
||||
if resourceType == resourceTypeGift {
|
||||
return s.java.IncrGiftBackpack(ctx, record.UserID, resourceID, 1)
|
||||
}
|
||||
|
||||
useProps := resourceType != resourceTypeGift
|
||||
if err := s.java.GivePropsBackpack(ctx, integration.GivePropsBackpackRequest{
|
||||
AcceptUserID: record.UserID,
|
||||
PropsID: resourceID,
|
||||
@ -333,17 +335,15 @@ func (s *Service) grantResourceReward(ctx context.Context, record *model.WheelDr
|
||||
Origin: walletOrigin,
|
||||
OriginDesc: walletOriginDesc,
|
||||
Days: days,
|
||||
UseProps: useProps,
|
||||
UseProps: true,
|
||||
AllowGive: false,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if useProps {
|
||||
if err := s.java.SwitchUseProps(ctx, record.UserID, resourceID); err != nil {
|
||||
return err
|
||||
}
|
||||
_ = s.java.RemoveUserProfileCacheAll(ctx, record.UserID)
|
||||
if err := s.java.SwitchUseProps(ctx, record.UserID, resourceID); err != nil {
|
||||
return err
|
||||
}
|
||||
_ = s.java.RemoveUserProfileCacheAll(ctx, record.UserID)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
88
internal/service/wheel/draw_test.go
Normal file
88
internal/service/wheel/draw_test.go
Normal file
@ -0,0 +1,88 @@
|
||||
package wheel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"chatapp3-golang/internal/integration"
|
||||
"chatapp3-golang/internal/model"
|
||||
)
|
||||
|
||||
type fakeWheelGateway struct {
|
||||
giftCalls []fakeGiftBackpackCall
|
||||
propsCalls []integration.GivePropsBackpackRequest
|
||||
switches int
|
||||
}
|
||||
|
||||
type fakeGiftBackpackCall struct {
|
||||
userID int64
|
||||
giftID int64
|
||||
quantity int
|
||||
}
|
||||
|
||||
func (g *fakeWheelGateway) ChangeGoldBalance(context.Context, integration.GoldReceiptCommand) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *fakeWheelGateway) GivePropsBackpack(_ context.Context, req integration.GivePropsBackpackRequest) error {
|
||||
g.propsCalls = append(g.propsCalls, req)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *fakeWheelGateway) IncrGiftBackpack(_ context.Context, userID int64, giftID int64, quantity int) error {
|
||||
g.giftCalls = append(g.giftCalls, fakeGiftBackpackCall{
|
||||
userID: userID,
|
||||
giftID: giftID,
|
||||
quantity: quantity,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *fakeWheelGateway) SwitchUseProps(context.Context, int64, int64) error {
|
||||
g.switches++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *fakeWheelGateway) ActivateTemporaryBadge(context.Context, int64, int64, int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *fakeWheelGateway) RemoveUserProfileCacheAll(context.Context, int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *fakeWheelGateway) MapGoldBalance(context.Context, []int64) (map[int64]int64, error) {
|
||||
return map[int64]int64{}, nil
|
||||
}
|
||||
|
||||
func (g *fakeWheelGateway) GetRoomProfileByUserID(context.Context, int64) (integration.RoomProfile, error) {
|
||||
return integration.RoomProfile{}, nil
|
||||
}
|
||||
|
||||
func TestGrantResourceRewardRoutesGiftToGiftBackpack(t *testing.T) {
|
||||
gateway := &fakeWheelGateway{}
|
||||
service := &Service{java: gateway}
|
||||
giftID := int64(2044086730826510337)
|
||||
|
||||
if err := service.grantResourceReward(context.Background(), &model.WheelDrawRecord{
|
||||
UserID: 2042274349343506434,
|
||||
ResourceID: &giftID,
|
||||
ResourceType: resourceTypeGift,
|
||||
DurationDays: 7,
|
||||
}); err != nil {
|
||||
t.Fatalf("grantResourceReward() error = %v", err)
|
||||
}
|
||||
|
||||
if len(gateway.giftCalls) != 1 {
|
||||
t.Fatalf("gift backpack calls = %d, want 1", len(gateway.giftCalls))
|
||||
}
|
||||
if got := gateway.giftCalls[0]; got.userID != 2042274349343506434 || got.giftID != giftID || got.quantity != 1 {
|
||||
t.Fatalf("gift backpack call = %+v", got)
|
||||
}
|
||||
if len(gateway.propsCalls) != 0 {
|
||||
t.Fatalf("props backpack calls = %d, want 0", len(gateway.propsCalls))
|
||||
}
|
||||
if gateway.switches != 0 {
|
||||
t.Fatalf("switch use props calls = %d, want 0", gateway.switches)
|
||||
}
|
||||
}
|
||||
@ -100,6 +100,7 @@ type wheelDB interface {
|
||||
type wheelGateway interface {
|
||||
ChangeGoldBalance(ctx context.Context, cmd integration.GoldReceiptCommand) error
|
||||
GivePropsBackpack(ctx context.Context, req integration.GivePropsBackpackRequest) error
|
||||
IncrGiftBackpack(ctx context.Context, userID int64, giftID int64, quantity int) error
|
||||
SwitchUseProps(ctx context.Context, userID int64, propsID int64) error
|
||||
ActivateTemporaryBadge(ctx context.Context, userID int64, badgeID int64, days int) error
|
||||
RemoveUserProfileCacheAll(ctx context.Context, userID int64) error
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user