Commit a2b78e4f by Leo Zheng

修改右侧接口的返回格式

parent acd7876c
...@@ -15,10 +15,10 @@ export default class paymentMethodAnalysisStrategy extends abstractDataStrategyL ...@@ -15,10 +15,10 @@ export default class paymentMethodAnalysisStrategy extends abstractDataStrategyL
} }
processData(data: any, timeFrame: string, type: string, ticketCategory: string): any { processData(data: any, timeFrame: string, type: string, ticketCategory: string): any {
return this.processPaymentMethodData(data, timeFrame); return this.processPaymentMethodData(data, timeFrame, type);
} }
private processPaymentMethodData(data: any, timeFrame: string): any { private processPaymentMethodData(data: any, timeFrame: string, type: string): any {
const currentDate = new Date(); const currentDate = new Date();
let startDate = new Date(); let startDate = new Date();
if (timeFrame === '12month') { if (timeFrame === '12month') {
...@@ -70,7 +70,8 @@ export default class paymentMethodAnalysisStrategy extends abstractDataStrategyL ...@@ -70,7 +70,8 @@ export default class paymentMethodAnalysisStrategy extends abstractDataStrategyL
return { return {
paymentMethod: key, paymentMethod: key,
amount: parseFloat(amount.toFixed(2)), amount: parseFloat(amount.toFixed(2)),
percentage: `${percentage}%` percentage: `${percentage}%`,
unit: type === 'amount' ? '元' : '张'
}; };
}); });
......
...@@ -11,9 +11,9 @@ export default class businessStatusStrategy implements dataStrategy{ ...@@ -11,9 +11,9 @@ export default class businessStatusStrategy implements dataStrategy{
const closedStores = totalStores - openStores; const closedStores = totalStores - openStores;
const result = [ const result = [
{ key: '门店数', value: totalStores }, { key: '门店数', value: totalStores, unit: '家' },
{ key: '开店数', value: openStores }, { key: '开店数', value: openStores, unit: '家' },
{ key: '关店数', value: closedStores } { key: '关店数', value: closedStores, unit: '家' }
]; ];
result.sort((a, b) => b.value - a.value); result.sort((a, b) => b.value - a.value);
......
...@@ -8,20 +8,25 @@ export default class merchantBusinessStatisticsStrategy extends abstractMerchant ...@@ -8,20 +8,25 @@ export default class merchantBusinessStatisticsStrategy extends abstractMerchant
processData(): any { processData(): any {
const totalBusinesses = Math.floor(Math.random() * 2000) + 1000; const totalBusinesses = Math.floor(Math.random() * 2000) + 1000;
const totalShops = Math.floor(Math.random() * 2500) + 1500; const totalShops = Math.floor(Math.random() * 2500) + 1500;
const businessActivityRate = Math.floor(Math.random() * 50) + 50; // Random percentage between 50% and 100% const businessActivityRate = Math.floor(Math.random() * 50) + 50;
const result = [ const result = [
{ {
key: '营业商家数', key: '营业商家数',
value: totalBusinesses value: totalBusinesses,
unit: '家'
}, },
{ {
key: '营业店铺数', key: '营业店铺数',
value: totalShops value: totalShops,
unit: '家'
}, },
{ {
key: '商家动销率', key: '商家动销率',
value: businessActivityRate value: businessActivityRate,
unit: '%'
} }
]; ];
......
...@@ -4,8 +4,6 @@ export default class storeTypeDistributionStrategy { ...@@ -4,8 +4,6 @@ export default class storeTypeDistributionStrategy {
} }
private generateStoreTypeData(): any { private generateStoreTypeData(): any {
const totalStores = 1000; // Total number of stores to be randomly distributed
const storeTypes = [ const storeTypes = [
'文化创意', '文化创意',
'特色餐饮', '特色餐饮',
...@@ -16,13 +14,14 @@ export default class storeTypeDistributionStrategy { ...@@ -16,13 +14,14 @@ export default class storeTypeDistributionStrategy {
'体验式商铺' '体验式商铺'
]; ];
const randomValues = Array.from({ length: storeTypes.length - 1 }, () => Math.floor(Math.random() * totalStores * 0.3)); const randomValues = Array.from({ length: storeTypes.length }, () => Math.floor(Math.random() * 300) + 1);
const remainingValue = totalStores - randomValues.reduce((a, b) => a + b, 0);
randomValues.push(remainingValue); const totalStores = randomValues.reduce((sum, value) => sum + value, 0);
const result = randomValues.map((value, index) => ({ const result = randomValues.map((value, index) => ({
key: storeTypes[index], key: storeTypes[index],
value: value value: value,
percent: ((value / totalStores) * 100).toFixed(2) + '%'
})); }));
result.sort((a, b) => b.value - a.value); result.sort((a, b) => b.value - a.value);
......
...@@ -10,7 +10,6 @@ export default class visitorAgeProfileStrategy extends abstractCustomerProfileSt ...@@ -10,7 +10,6 @@ export default class visitorAgeProfileStrategy extends abstractCustomerProfileSt
processData(type: string): any { processData(type: string): any {
const total = type === 'ticket' ? 1000 : 3429; const total = type === 'ticket' ? 1000 : 3429;
// Generate random values for each age group ensuring they sum up to total
const children = Math.floor(Math.random() * (total * 0.2)); const children = Math.floor(Math.random() * (total * 0.2));
const teenagers = Math.floor(Math.random() * (total * 0.2)); const teenagers = Math.floor(Math.random() * (total * 0.2));
const youngAdults = Math.floor(Math.random() * (total * 0.5)); const youngAdults = Math.floor(Math.random() * (total * 0.5));
......
...@@ -36,6 +36,8 @@ export default class visitorGenderProfileStrategy extends abstractCustomerProfil ...@@ -36,6 +36,8 @@ export default class visitorGenderProfileStrategy extends abstractCustomerProfil
unit: '人' unit: '人'
}, },
sexRatio: { sexRatio: {
maleName: type === 'ticket' ? '男性游客' : '男性会员',
femaleName: type === 'ticket' ? '女性游客' : '女性会员',
male: maleCount, male: maleCount,
maleRatio: maleRatio, maleRatio: maleRatio,
female: femaleCount, female: femaleCount,
......
...@@ -23,8 +23,9 @@ export default class visitorHomeProfileStrategy extends abstractCustomerProfileS ...@@ -23,8 +23,9 @@ export default class visitorHomeProfileStrategy extends abstractCustomerProfileS
const totalVisitors = Object.values(cityCounts).reduce((a, b) => a + b, 0); const totalVisitors = Object.values(cityCounts).reduce((a, b) => a + b, 0);
const scaleFactor = total / totalVisitors; const scaleFactor = total / totalVisitors;
let count = 0;
const result = Object.entries(cityCounts).map(([key, count]) => { let result = Object.entries(cityCounts).map(([key, count]) => {
const scaledCount = Math.floor(count * scaleFactor); const scaledCount = Math.floor(count * scaleFactor);
return { return {
key, key,
...@@ -38,6 +39,7 @@ export default class visitorHomeProfileStrategy extends abstractCustomerProfileS ...@@ -38,6 +39,7 @@ export default class visitorHomeProfileStrategy extends abstractCustomerProfileS
result[0].value += difference; result[0].value += difference;
} }
result = result.slice(0, 10);
return result; return result;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment