fix(site): 清理经营租户请求中的旧分销参数
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
|
||||
import { getEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import { resolveEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
|
||||
export interface NotificationItem {
|
||||
id: number
|
||||
@@ -16,7 +16,7 @@ export interface NotificationItem {
|
||||
}
|
||||
|
||||
export async function fetchNotifications(page = 1, pageSize = 20, distributionSiteCode?: string) {
|
||||
const siteCode = distributionSiteCode || getEffectiveSiteCode() || undefined
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode)
|
||||
const params: Record<string, unknown> = { page, page_size: pageSize }
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
@@ -31,7 +31,7 @@ export async function fetchNotifications(page = 1, pageSize = 20, distributionSi
|
||||
}
|
||||
|
||||
export async function markNotificationRead(id: number, distributionSiteCode?: string) {
|
||||
const siteCode = distributionSiteCode || getEffectiveSiteCode() || undefined
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode)
|
||||
const params: Record<string, unknown> = {}
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
@@ -45,7 +45,7 @@ export async function markNotificationRead(id: number, distributionSiteCode?: st
|
||||
}
|
||||
|
||||
export async function fetchUnreadNotificationCount(distributionSiteCode?: string) {
|
||||
const siteCode = distributionSiteCode || getEffectiveSiteCode() || undefined
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode)
|
||||
const params: Record<string, unknown> = {}
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
@@ -61,7 +61,7 @@ export async function fetchUnreadNotificationCount(distributionSiteCode?: string
|
||||
}
|
||||
|
||||
export async function markAllNotificationsRead(distributionSiteCode?: string) {
|
||||
const siteCode = distributionSiteCode || getEffectiveSiteCode() || undefined
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode)
|
||||
const params: Record<string, unknown> = {}
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
|
||||
import { getEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import { resolveEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
|
||||
export interface ChatParticipant {
|
||||
id: number
|
||||
@@ -95,7 +95,7 @@ export interface ChatMessage {
|
||||
}
|
||||
|
||||
export async function fetchChats(page = 1, pageSize = 20, distributionSiteCode?: string) {
|
||||
const siteCode = distributionSiteCode || getEffectiveSiteCode() || undefined
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode)
|
||||
const params: Record<string, unknown> = { page, page_size: pageSize }
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
@@ -107,7 +107,7 @@ export async function fetchChats(page = 1, pageSize = 20, distributionSiteCode?:
|
||||
}
|
||||
|
||||
export async function fetchUnreadChatCount(distributionSiteCode?: string) {
|
||||
const siteCode = distributionSiteCode || getEffectiveSiteCode() || undefined
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode)
|
||||
const params: Record<string, unknown> = {}
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
@@ -136,7 +136,7 @@ export async function ensureSupportChat(
|
||||
scene: SupportScene | string = 'general',
|
||||
distributionSiteCode?: string
|
||||
) {
|
||||
const siteCode = distributionSiteCode || getEffectiveSiteCode() || undefined
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode)
|
||||
const payload: { scene: string; distribution_site_code?: string } = {
|
||||
scene: scene || 'general',
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const apiClient = vi.hoisted(() => ({
|
||||
get: vi.fn(),
|
||||
@@ -25,6 +25,11 @@ import {
|
||||
import { fetchAdminPayments } from '@/features/admin/api/adminPayments'
|
||||
|
||||
describe('financial API clients', () => {
|
||||
afterEach(() => {
|
||||
sessionStorage.clear()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('fetches wallet balance and paginated ledger with server data', async () => {
|
||||
apiClient.get
|
||||
.mockResolvedValueOnce({ data: { data: { available_balance_cent: 100 } } })
|
||||
@@ -79,6 +84,25 @@ describe('financial API clients', () => {
|
||||
await expect(cancelWithdrawal(9)).resolves.toEqual({ cancelled: true })
|
||||
})
|
||||
|
||||
it('drops explicit legacy site codes from tenant withdrawal payloads', async () => {
|
||||
sessionStorage.setItem('hfb_tenant_code', 'jieyou')
|
||||
apiClient.post.mockResolvedValueOnce({ data: { data: { id: 10 } } })
|
||||
|
||||
await createWithdrawal(
|
||||
{
|
||||
payment_account_id: 7,
|
||||
amount_cent: 1000,
|
||||
distribution_site_code: 'legacy_jieyou',
|
||||
},
|
||||
'legacy_override'
|
||||
)
|
||||
|
||||
expect(apiClient.post).toHaveBeenLastCalledWith('/withdrawals', {
|
||||
payment_account_id: 7,
|
||||
amount_cent: 1000,
|
||||
})
|
||||
})
|
||||
|
||||
it('filters empty admin-payment query values and normalizes pagination', async () => {
|
||||
apiClient.get.mockResolvedValueOnce({ data: { data: undefined } })
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const apiClient = vi.hoisted(() => ({
|
||||
get: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/shared/api/client', () => ({ apiClient }))
|
||||
|
||||
import { fetchListingsPage } from './listings'
|
||||
|
||||
describe('listing API site scope', () => {
|
||||
beforeEach(() => {
|
||||
apiClient.get.mockResolvedValue({
|
||||
data: {
|
||||
data: { items: [], total: 0, page: 1, page_size: 20, zone_counts: {} },
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
sessionStorage.clear()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('经营租户不向列表请求透传显式旧分销站点编码', async () => {
|
||||
sessionStorage.setItem('hfb_tenant_code', 'jieyou')
|
||||
|
||||
await fetchListingsPage({
|
||||
page: 1,
|
||||
distribution_site_code: 'legacy_jieyou',
|
||||
})
|
||||
|
||||
const params = apiClient.get.mock.calls[0][1].params
|
||||
expect(params).not.toHaveProperty('distribution_site_code')
|
||||
})
|
||||
|
||||
it('旧分销站点仍保留显式站点编码', async () => {
|
||||
sessionStorage.setItem('hfb_site_code', 'session_site')
|
||||
|
||||
await fetchListingsPage({
|
||||
page: 1,
|
||||
distribution_site_code: 'explicit_site',
|
||||
})
|
||||
|
||||
expect(apiClient.get.mock.calls[0][1].params).toMatchObject({
|
||||
distribution_site_code: 'explicit_site',
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,6 +1,6 @@
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
import type { ApiResponse } from '@/shared/types/types'
|
||||
import { getEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import { resolveEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import type { ListingReviewStatus, ListingStatus } from '@/shared/types/status'
|
||||
|
||||
export interface Listing {
|
||||
@@ -112,8 +112,11 @@ export async function fetchListings(query: PublicListingQuery = {}) {
|
||||
}
|
||||
|
||||
export async function fetchListingsPage(query: PublicListingQuery = {}) {
|
||||
const siteCode = query.distribution_site_code || getEffectiveSiteCode() || undefined
|
||||
const effectiveQuery = siteCode ? { distribution_site_code: siteCode, ...query } : query
|
||||
const { distribution_site_code: explicitSiteCode, ...queryWithoutSiteCode } = query
|
||||
const siteCode = resolveEffectiveSiteCode(explicitSiteCode)
|
||||
const effectiveQuery = siteCode
|
||||
? { ...queryWithoutSiteCode, distribution_site_code: siteCode }
|
||||
: queryWithoutSiteCode
|
||||
const params = Object.fromEntries(
|
||||
Object.entries(effectiveQuery).filter(
|
||||
([, value]) => value !== '' && value !== undefined && value !== null
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import type { PublicListingItem } from '@/features/listings/api/listings'
|
||||
import { getEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import { resolveEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
|
||||
function getHistoryKey() {
|
||||
const code = getEffectiveSiteCode()
|
||||
const code = resolveEffectiveSiteCode()
|
||||
return code ? `hfb.listing.view.history.${code}` : 'hfb.listing.view.history'
|
||||
}
|
||||
|
||||
function getFavoriteKey() {
|
||||
const code = getEffectiveSiteCode()
|
||||
const code = resolveEffectiveSiteCode()
|
||||
return code ? `hfb.listing.favorites.${code}` : 'hfb.listing.favorites'
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { apiClient } from '@/shared/api/client'
|
||||
import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
|
||||
import type { HandoffStatus, OrderStatus, SettlementStatus } from '@/shared/types/status'
|
||||
import { yuanToCent } from '@/shared/utils/money'
|
||||
import { getEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import { resolveEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import { getTrackCode } from '@/shared/utils/trackCode'
|
||||
|
||||
export interface Order {
|
||||
@@ -354,7 +354,7 @@ export async function fetchPostRentalNotice() {
|
||||
}
|
||||
|
||||
export async function fetchOrders(page = 1, pageSize = 20, distributionSiteCode?: string) {
|
||||
const siteCode = distributionSiteCode || getEffectiveSiteCode() || undefined
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode)
|
||||
const params: Record<string, unknown> = { page, page_size: pageSize }
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
@@ -383,7 +383,7 @@ export async function fetchSellerHandoffs(
|
||||
}
|
||||
|
||||
export async function fetchOrder(id: string | number, distributionSiteCode?: string) {
|
||||
const siteCode = distributionSiteCode || getEffectiveSiteCode() || undefined
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode)
|
||||
const params: Record<string, unknown> = {}
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
@@ -393,7 +393,7 @@ export async function fetchOrder(id: string | number, distributionSiteCode?: str
|
||||
}
|
||||
|
||||
export async function createOrder(listingId: number, distributionSiteCode?: string) {
|
||||
const siteCode = distributionSiteCode || getEffectiveSiteCode() || undefined
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode)
|
||||
const trackCode = getTrackCode()
|
||||
const payload: {
|
||||
listing_id: number
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
|
||||
import { getEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import { resolveEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import type { BalanceType, LedgerDirection, WalletStatus } from '@/shared/types/status'
|
||||
|
||||
export interface WalletAccount {
|
||||
@@ -28,7 +28,7 @@ export interface WalletLedger {
|
||||
}
|
||||
|
||||
export async function fetchWalletBalance(distributionSiteCode?: string) {
|
||||
const siteCode = distributionSiteCode || getEffectiveSiteCode() || undefined
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode)
|
||||
const params: Record<string, unknown> = {}
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
@@ -38,7 +38,7 @@ export async function fetchWalletBalance(distributionSiteCode?: string) {
|
||||
}
|
||||
|
||||
export async function fetchWalletLedger(page = 1, pageSize = 20, distributionSiteCode?: string) {
|
||||
const siteCode = distributionSiteCode || getEffectiveSiteCode() || undefined
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode)
|
||||
const params: Record<string, unknown> = { page, page_size: pageSize }
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { apiClient } from '@/shared/api/client'
|
||||
import type { ApiResponse, PaginatedResult } from '@/shared/types/types'
|
||||
import { getEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import { resolveEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
|
||||
// 收款账号类型
|
||||
export type AccountType = 'alipay' | 'wechat' | 'bank'
|
||||
@@ -116,9 +116,9 @@ export async function createWithdrawal(
|
||||
req: CreateWithdrawalRequest,
|
||||
distributionSiteCode?: string
|
||||
) {
|
||||
const siteCode =
|
||||
distributionSiteCode || req.distribution_site_code || getEffectiveSiteCode() || undefined
|
||||
const payload: CreateWithdrawalRequest = { ...req }
|
||||
delete payload.distribution_site_code
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode || req.distribution_site_code)
|
||||
if (siteCode) {
|
||||
payload.distribution_site_code = siteCode
|
||||
}
|
||||
@@ -127,7 +127,7 @@ export async function createWithdrawal(
|
||||
}
|
||||
|
||||
export async function fetchWithdrawals(page = 1, pageSize = 20, distributionSiteCode?: string) {
|
||||
const siteCode = distributionSiteCode || getEffectiveSiteCode() || undefined
|
||||
const siteCode = resolveEffectiveSiteCode(distributionSiteCode)
|
||||
const params: Record<string, unknown> = { page, page_size: pageSize }
|
||||
if (siteCode) {
|
||||
params.distribution_site_code = siteCode
|
||||
|
||||
Reference in New Issue
Block a user