feat: 实现多商户管理模块与前端服务
refactor: 优化服务层代码并修复类型问题 docs: 更新开发进度文档 feat(merchant): 新增商户监控与数据统计服务 feat(dashboard): 添加商户管理前端页面与服务 fix: 修复类型转换与可选参数处理 feat: 实现商户订单、店铺与结算管理功能 refactor: 重构审计日志格式与服务调用 feat: 新增商户入驻与身份注册功能 fix(controller): 修复路由参数类型问题 feat: 添加商户排名与统计报告功能 chore: 更新模拟数据与服务配置
This commit is contained in:
137
dashboard/src/services/merchantService.ts
Normal file
137
dashboard/src/services/merchantService.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
// 商户管理服务
|
||||
|
||||
interface Merchant {
|
||||
id: string;
|
||||
tenantId: string;
|
||||
companyName: string;
|
||||
businessLicense: string;
|
||||
contactEmail: string;
|
||||
contactPhone: string;
|
||||
status: 'PENDING' | 'ACTIVE' | 'SUSPENDED' | 'TERMINATED';
|
||||
tier: 'BASIC' | 'PRO' | 'ENTERPRISE';
|
||||
traceId: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
interface MerchantResponse {
|
||||
data: Merchant[];
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
}
|
||||
|
||||
// 模拟数据
|
||||
const mockMerchants: Merchant[] = [
|
||||
{
|
||||
id: '1',
|
||||
tenantId: 'tenant1',
|
||||
companyName: '商户A',
|
||||
businessLicense: '1234567890',
|
||||
contactEmail: 'merchantA@example.com',
|
||||
contactPhone: '13800138001',
|
||||
status: 'ACTIVE',
|
||||
tier: 'PRO',
|
||||
traceId: 'trace1',
|
||||
createdAt: '2026-03-01T10:00:00Z',
|
||||
updatedAt: '2026-03-01T10:00:00Z',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
tenantId: 'tenant2',
|
||||
companyName: '商户B',
|
||||
businessLicense: '0987654321',
|
||||
contactEmail: 'merchantB@example.com',
|
||||
contactPhone: '13900139001',
|
||||
status: 'PENDING',
|
||||
tier: 'BASIC',
|
||||
traceId: 'trace2',
|
||||
createdAt: '2026-03-02T10:00:00Z',
|
||||
updatedAt: '2026-03-02T10:00:00Z',
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
tenantId: 'tenant3',
|
||||
companyName: '商户C',
|
||||
businessLicense: '1122334455',
|
||||
contactEmail: 'merchantC@example.com',
|
||||
contactPhone: '13700137001',
|
||||
status: 'SUSPENDED',
|
||||
tier: 'ENTERPRISE',
|
||||
traceId: 'trace3',
|
||||
createdAt: '2026-03-03T10:00:00Z',
|
||||
updatedAt: '2026-03-03T10:00:00Z',
|
||||
},
|
||||
];
|
||||
|
||||
// 获取商户列表
|
||||
export const getMerchants = async (): Promise<MerchantResponse> => {
|
||||
// 模拟API请求延迟
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
return {
|
||||
data: mockMerchants,
|
||||
total: mockMerchants.length,
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
};
|
||||
};
|
||||
|
||||
// 创建商户
|
||||
export const createMerchant = async (merchantData: Partial<Merchant>): Promise<Merchant> => {
|
||||
// 模拟API请求延迟
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
const newMerchant: Merchant = {
|
||||
id: `new-${Date.now()}`,
|
||||
tenantId: merchantData.tenantId || 'default-tenant',
|
||||
companyName: merchantData.companyName || '',
|
||||
businessLicense: merchantData.businessLicense || '',
|
||||
contactEmail: merchantData.contactEmail || '',
|
||||
contactPhone: merchantData.contactPhone || '',
|
||||
status: merchantData.status || 'PENDING',
|
||||
tier: merchantData.tier || 'BASIC',
|
||||
traceId: `trace-${Date.now()}`,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
mockMerchants.push(newMerchant);
|
||||
return newMerchant;
|
||||
};
|
||||
|
||||
// 更新商户
|
||||
export const updateMerchant = async (merchantId: string, merchantData: Partial<Merchant>): Promise<Merchant> => {
|
||||
// 模拟API请求延迟
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
const index = mockMerchants.findIndex(m => m.id === merchantId);
|
||||
if (index === -1) {
|
||||
throw new Error('商户不存在');
|
||||
}
|
||||
mockMerchants[index] = {
|
||||
...mockMerchants[index],
|
||||
...merchantData,
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
return mockMerchants[index];
|
||||
};
|
||||
|
||||
// 删除商户
|
||||
export const deleteMerchant = async (merchantId: string): Promise<boolean> => {
|
||||
// 模拟API请求延迟
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
const index = mockMerchants.findIndex(m => m.id === merchantId);
|
||||
if (index === -1) {
|
||||
throw new Error('商户不存在');
|
||||
}
|
||||
mockMerchants.splice(index, 1);
|
||||
return true;
|
||||
};
|
||||
|
||||
// 获取商户详情
|
||||
export const getMerchantById = async (merchantId: string): Promise<Merchant> => {
|
||||
// 模拟API请求延迟
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
const merchant = mockMerchants.find(m => m.id === merchantId);
|
||||
if (!merchant) {
|
||||
throw new Error('商户不存在');
|
||||
}
|
||||
return merchant;
|
||||
};
|
||||
Reference in New Issue
Block a user