修复充值奖励
This commit is contained in:
parent
c09433bf29
commit
e738fbc44a
@ -759,10 +759,36 @@ func (c *Client) FindRewardGroupDetail(ctx context.Context, sysOrigin string, na
|
||||
if groupName == "" {
|
||||
return RewardGroupDetail{}, fmt.Errorf("reward group name is empty")
|
||||
}
|
||||
if detail, err := c.findInnerRewardGroupDetail(ctx, sysOrigin, groupName); err == nil && rewardGroupDetailHasContent(detail) {
|
||||
if detail, err := c.findInnerRewardGroupDetail(ctx, sysOrigin, groupName); err == nil {
|
||||
if hydrated, hydrateErr := c.hydrateRewardGroupDetail(ctx, detail); hydrateErr == nil && rewardGroupDetailHasContent(hydrated) {
|
||||
return hydrated, nil
|
||||
}
|
||||
if rewardGroupDetailHasContent(detail) {
|
||||
return detail, nil
|
||||
}
|
||||
}
|
||||
detail, err := c.findConsoleRewardGroupDetail(ctx, sysOrigin, groupName)
|
||||
if err != nil {
|
||||
return RewardGroupDetail{}, err
|
||||
}
|
||||
if hydrated, hydrateErr := c.hydrateRewardGroupDetail(ctx, detail); hydrateErr == nil && rewardGroupDetailHasContent(hydrated) {
|
||||
return hydrated, nil
|
||||
}
|
||||
return detail, nil
|
||||
}
|
||||
|
||||
func (c *Client) hydrateRewardGroupDetail(ctx context.Context, detail RewardGroupDetail) (RewardGroupDetail, error) {
|
||||
if rewardGroupDetailHasContent(detail) {
|
||||
return detail, nil
|
||||
}
|
||||
return c.findConsoleRewardGroupDetail(ctx, sysOrigin, groupName)
|
||||
groupID := int64(detail.ID)
|
||||
if groupID <= 0 {
|
||||
return detail, fmt.Errorf("empty reward group id")
|
||||
}
|
||||
if hydrated, err := c.getInnerRewardGroupDetail(ctx, groupID); err == nil && rewardGroupDetailHasContent(hydrated) {
|
||||
return hydrated, nil
|
||||
}
|
||||
return c.getConsoleRewardGroupDetail(ctx, groupID)
|
||||
}
|
||||
|
||||
func (c *Client) findInnerRewardGroupDetail(ctx context.Context, sysOrigin string, name string) (RewardGroupDetail, error) {
|
||||
@ -818,7 +844,7 @@ func pickRewardGroupDetailByName(records []RewardGroupDetail, name string) (Rewa
|
||||
}
|
||||
target := strings.TrimSpace(name)
|
||||
for _, record := range records {
|
||||
if strings.TrimSpace(record.Name) == target && rewardGroupDetailHasContent(record) {
|
||||
if strings.TrimSpace(record.Name) == target {
|
||||
return record, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,3 +140,42 @@ func TestGetRewardGroupDetailFallsBackToConsoleEndpoint(t *testing.T) {
|
||||
t.Fatalf("detail = %+v, want fallback reward item", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindRewardGroupDetailHydratesPageRecord(t *testing.T) {
|
||||
groupID := int64(2056980937278816399)
|
||||
var pageCalls, detailCalls int
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/props-activity/reward/group/client/page", func(w http.ResponseWriter, r *http.Request) {
|
||||
pageCalls++
|
||||
if r.Method != http.MethodPost {
|
||||
t.Fatalf("method = %s, want POST", r.Method)
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"body":{"records":[{"id":"2056980937278816399","name":"累充活动$100","rewardConfigList":[]}]}}`))
|
||||
})
|
||||
mux.HandleFunc("/props-activity/reward/group/client/getByGroupId", func(w http.ResponseWriter, r *http.Request) {
|
||||
detailCalls++
|
||||
if r.URL.Query().Get("id") != "2056980937278816399" {
|
||||
t.Fatalf("id query = %q", r.URL.Query().Get("id"))
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"body":{"id":"2056980937278816399","name":"累充活动$100","rewardConfigList":[{"id":"1","type":"BADGE","name":"Badge","quantity":"30","cover":"https://example.com/badge.png"}]}}`))
|
||||
})
|
||||
server := httptest.NewServer(mux)
|
||||
defer server.Close()
|
||||
|
||||
client := New(config.Config{
|
||||
HTTP: config.HTTPConfig{Timeout: time.Second},
|
||||
Java: config.JavaConfig{OtherBaseURL: server.URL},
|
||||
})
|
||||
got, err := client.FindRewardGroupDetail(context.Background(), "LIKEI", "累充活动$100")
|
||||
if err != nil {
|
||||
t.Fatalf("FindRewardGroupDetail() error = %v", err)
|
||||
}
|
||||
if pageCalls != 1 || detailCalls != 1 {
|
||||
t.Fatalf("calls page=%d detail=%d, want 1/1", pageCalls, detailCalls)
|
||||
}
|
||||
if int64(got.ID) != groupID || len(got.RewardConfigList) != 1 {
|
||||
t.Fatalf("detail = %+v, want hydrated reward group", got)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user