refactor(services): 重构服务文件结构,将服务按功能分类到不同目录
- 将服务文件按功能分类到core、ai、analytics、security等目录 - 修复logger导入路径问题,统一使用相对路径 - 更新相关文件的导入路径引用 - 添加新的批量操作组件导出文件 - 修复dashboard页面中的类型错误 - 添加dotenv依赖到package.json
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { http } from './http';
|
||||
/**
|
||||
* [MOCK] 商户管理数据<E695B0><EFBFBD>? * AI注意: 这是Mock实现,不是真实业务逻辑
|
||||
* 仅在USE_MOCK=true时启<E697B6><EFBFBD>? */
|
||||
* [MOCK] 商户管理数据<E695B0>? * AI注意: 这是Mock实现,不是真实业务逻辑
|
||||
* 仅在USE_MOCK=true时启<E697B6>? */
|
||||
|
||||
export interface Merchant {
|
||||
id: string;
|
||||
@@ -283,87 +284,67 @@ class ApiMerchantDataSource implements IMerchantDataSource {
|
||||
private baseUrl = '/api/merchants';
|
||||
|
||||
async fetchMerchants(params?: { status?: string; tier?: string; search?: string }): Promise<Merchant[]> {
|
||||
const response = await fetch(`${this.baseUrl}?${new URLSearchParams(params as any)}`);
|
||||
if (!response.ok) throw new Error('Failed to fetch merchants');
|
||||
return response.json();
|
||||
const response = await http.post(`${this.baseUrl}?${new URLSearchParams(params as any)}`);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async createMerchant(data: Partial<Merchant>): Promise<Merchant> {
|
||||
const response = await fetch(this.baseUrl, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to create merchant');
|
||||
return response.json();
|
||||
const response = await http.post(this.baseUrl, data);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async updateMerchant(id: string, data: Partial<Merchant>): Promise<Merchant> {
|
||||
const response = await fetch(`${this.baseUrl}/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to update merchant');
|
||||
return response.json();
|
||||
const response = await http.put(`${this.baseUrl}/${id}`, data);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async deleteMerchant(id: string): Promise<void> {
|
||||
const response = await fetch(`${this.baseUrl}/${id}`, { method: 'DELETE' });
|
||||
if (!response.ok) throw new Error('Failed to delete merchant');
|
||||
const response = await http.post(`${this.baseUrl}/${id}`);
|
||||
|
||||
}
|
||||
|
||||
async fetchShops(params?: { merchantId?: string; platform?: string; status?: string }): Promise<MerchantShop[]> {
|
||||
const response = await fetch(`${this.baseUrl}/shops?${new URLSearchParams(params as any)}`);
|
||||
if (!response.ok) throw new Error('Failed to fetch shops');
|
||||
return response.json();
|
||||
const response = await http.get(`${this.baseUrl}/shops?${new URLSearchParams(params as any)}`);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async createShop(data: Partial<MerchantShop>): Promise<MerchantShop> {
|
||||
const response = await fetch(`${this.baseUrl}/shops`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to create shop');
|
||||
return response.json();
|
||||
const response = await http.post(`${this.baseUrl}/shops`, data);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async updateShop(id: string, data: Partial<MerchantShop>): Promise<MerchantShop> {
|
||||
const response = await fetch(`${this.baseUrl}/shops/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to update shop');
|
||||
return response.json();
|
||||
const response = await http.put(`${this.baseUrl}/shops/${id}`, data);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async deleteShop(id: string): Promise<void> {
|
||||
const response = await fetch(`${this.baseUrl}/shops/${id}`, { method: 'DELETE' });
|
||||
if (!response.ok) throw new Error('Failed to delete shop');
|
||||
const response = await http.delete(`${this.baseUrl}/shops/${id}`);
|
||||
|
||||
}
|
||||
|
||||
async fetchMerchantOrders(merchantId: string, params?: { status?: string }): Promise<MerchantOrder[]> {
|
||||
const response = await fetch(`${this.baseUrl}/${merchantId}/orders?${new URLSearchParams(params as any)}`);
|
||||
if (!response.ok) throw new Error('Failed to fetch merchant orders');
|
||||
return response.json();
|
||||
const response = await http.get(`${this.baseUrl}/${merchantId}/orders?${new URLSearchParams(params as any)}`);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async fetchSettlements(params?: { merchantId?: string; status?: string }): Promise<MerchantSettlement[]> {
|
||||
const response = await fetch(`${this.baseUrl}/settlements?${new URLSearchParams(params as any)}`);
|
||||
if (!response.ok) throw new Error('Failed to fetch settlements');
|
||||
return response.json();
|
||||
const response = await http.get(`${this.baseUrl}/settlements?${new URLSearchParams(params as any)}`);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async processSettlement(id: string, action: 'APPROVE' | 'REJECT'): Promise<MerchantSettlement> {
|
||||
const response = await fetch(`${this.baseUrl}/settlements/${id}/process`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action }),
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to process settlement');
|
||||
return response.json();
|
||||
const response = await http.post(`${this.baseUrl}/settlements/${id}/process`, { action });
|
||||
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user