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
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ElMessage } from 'element-plus'
|
||||
import { showToast } from 'vant'
|
||||
import { apiMonitor } from './monitor'
|
||||
import { debugError, debugLog } from '@/shared/utils/debug'
|
||||
import { getEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
import { resolveEffectiveSiteCode } from '@/stores/distributionSite'
|
||||
|
||||
function showError(message: string) {
|
||||
const isMobile = window.location.pathname.startsWith('/m')
|
||||
@@ -202,7 +202,7 @@ apiClient.interceptors.request.use(
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
|
||||
const siteCode = getEffectiveSiteCode()
|
||||
const siteCode = resolveEffectiveSiteCode()
|
||||
if (siteCode && !config.headers['X-Distribution-Site-Code']) {
|
||||
config.headers['X-Distribution-Site-Code'] = siteCode
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ export function shouldProbeTenantContext(
|
||||
export function getEffectiveSiteCode(): string {
|
||||
if (typeof window === 'undefined') return ''
|
||||
// 经营租户站点不能同时携带旧分销站点编码,否则列表和下单会走旧分销过滤。
|
||||
if (sessionStorage.getItem('hfb_tenant_code')) return ''
|
||||
if (isTenantSiteContext()) return ''
|
||||
const envCode = ((import.meta.env.VITE_DISTRIBUTION_SITE_CODE as string) || '').trim()
|
||||
if (envCode) return envCode
|
||||
|
||||
@@ -193,6 +193,22 @@ export function getEffectiveSiteCode(): string {
|
||||
return ''
|
||||
}
|
||||
|
||||
/** 当前标签页是否已识别为经营租户。 */
|
||||
export function isTenantSiteContext(): boolean {
|
||||
if (typeof window === 'undefined') return false
|
||||
return Boolean((sessionStorage.getItem('hfb_tenant_code') || '').trim())
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一解析业务请求应携带的旧分销站点编码。
|
||||
* 经营租户必须返回空串,调用方也不得把显式传入的历史参数继续透传。
|
||||
*/
|
||||
export function resolveEffectiveSiteCode(explicitCode?: string): string {
|
||||
if (isTenantSiteContext()) return ''
|
||||
const explicit = (explicitCode || '').trim()
|
||||
return explicit || getEffectiveSiteCode()
|
||||
}
|
||||
|
||||
export const useDistributionSiteStore = defineStore('distributionSite', {
|
||||
state: () => {
|
||||
const code = getEffectiveSiteCode()
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
|
||||
import { getEffectiveSiteCode, shouldProbeTenantContext } from './distributionSite'
|
||||
import {
|
||||
getEffectiveSiteCode,
|
||||
isTenantSiteContext,
|
||||
resolveEffectiveSiteCode,
|
||||
shouldProbeTenantContext,
|
||||
} from './distributionSite'
|
||||
|
||||
describe('shouldProbeTenantContext', () => {
|
||||
afterEach(() => sessionStorage.clear())
|
||||
@@ -26,6 +31,15 @@ describe('shouldProbeTenantContext', () => {
|
||||
|
||||
it('经营租户上下文不回退为旧分销站点编码', () => {
|
||||
sessionStorage.setItem('hfb_tenant_code', 'jieyou')
|
||||
expect(isTenantSiteContext()).toBe(true)
|
||||
expect(getEffectiveSiteCode()).toBe('')
|
||||
expect(resolveEffectiveSiteCode('legacy_site')).toBe('')
|
||||
})
|
||||
|
||||
it('旧分销上下文保留显式站点编码', () => {
|
||||
sessionStorage.setItem('hfb_site_code', 'session_site')
|
||||
expect(isTenantSiteContext()).toBe(false)
|
||||
expect(resolveEffectiveSiteCode(' explicit_site ')).toBe('explicit_site')
|
||||
expect(resolveEffectiveSiteCode()).toBe('session_site')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user