fix(contribution): 认种记录总贡献值显示用户实际有效算力

后端:
- get-planting-ledger.query.ts: 添加effectiveContribution字段
- 从contributionAccount获取用户实际的个人算力(personalContribution)

前端:
- planting_record.dart: PlantingSummary添加effectiveContribution字段
- planting_record_model.dart: 解析effectiveContribution字段
- planting_records_page.dart: 总贡献值显示effectiveContribution而非totalAmount

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-17 08:29:14 -08:00
parent 613fb33ff9
commit e8f3c34723
4 changed files with 21 additions and 4 deletions

View File

@ -1,5 +1,6 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { SyncedDataRepository } from '../../infrastructure/persistence/repositories/synced-data.repository'; import { SyncedDataRepository } from '../../infrastructure/persistence/repositories/synced-data.repository';
import { ContributionAccountRepository } from '../../infrastructure/persistence/repositories/contribution-account.repository';
export interface PlantingRecordDto { export interface PlantingRecordDto {
orderId: string; orderId: string;
@ -18,6 +19,8 @@ export interface PlantingSummaryDto {
totalTreeCount: number; totalTreeCount: number;
totalAmount: string; totalAmount: string;
effectiveTreeCount: number; effectiveTreeCount: number;
/** 用户实际的有效贡献值(个人算力) */
effectiveContribution: string;
firstPlantingAt: string | null; firstPlantingAt: string | null;
lastPlantingAt: string | null; lastPlantingAt: string | null;
} }
@ -33,24 +36,32 @@ export interface PlantingLedgerDto {
@Injectable() @Injectable()
export class GetPlantingLedgerQuery { export class GetPlantingLedgerQuery {
constructor(private readonly syncedDataRepository: SyncedDataRepository) {} constructor(
private readonly syncedDataRepository: SyncedDataRepository,
private readonly contributionAccountRepository: ContributionAccountRepository,
) {}
async execute( async execute(
accountSequence: string, accountSequence: string,
page: number = 1, page: number = 1,
pageSize: number = 20, pageSize: number = 20,
): Promise<PlantingLedgerDto> { ): Promise<PlantingLedgerDto> {
const [summary, ledger] = await Promise.all([ const [summary, ledger, contributionAccount] = await Promise.all([
this.syncedDataRepository.getPlantingSummary(accountSequence), this.syncedDataRepository.getPlantingSummary(accountSequence),
this.syncedDataRepository.getPlantingLedger(accountSequence, page, pageSize), this.syncedDataRepository.getPlantingLedger(accountSequence, page, pageSize),
this.contributionAccountRepository.findByAccountSequence(accountSequence),
]); ]);
// 获取用户实际的有效贡献值(个人算力)
const effectiveContribution = contributionAccount?.personalContribution.toString() || '0';
return { return {
summary: { summary: {
totalOrders: summary.totalOrders, totalOrders: summary.totalOrders,
totalTreeCount: summary.totalTreeCount, totalTreeCount: summary.totalTreeCount,
totalAmount: summary.totalAmount, totalAmount: summary.totalAmount,
effectiveTreeCount: summary.effectiveTreeCount, effectiveTreeCount: summary.effectiveTreeCount,
effectiveContribution,
firstPlantingAt: summary.firstPlantingAt?.toISOString() || null, firstPlantingAt: summary.firstPlantingAt?.toISOString() || null,
lastPlantingAt: summary.lastPlantingAt?.toISOString() || null, lastPlantingAt: summary.lastPlantingAt?.toISOString() || null,
}, },

View File

@ -57,6 +57,7 @@ class PlantingSummaryModel extends PlantingSummary {
required super.totalTreeCount, required super.totalTreeCount,
required super.totalAmount, required super.totalAmount,
required super.effectiveTreeCount, required super.effectiveTreeCount,
required super.effectiveContribution,
super.firstPlantingAt, super.firstPlantingAt,
super.lastPlantingAt, super.lastPlantingAt,
}); });
@ -67,6 +68,7 @@ class PlantingSummaryModel extends PlantingSummary {
totalTreeCount: json['totalTreeCount'] ?? 0, totalTreeCount: json['totalTreeCount'] ?? 0,
totalAmount: json['totalAmount']?.toString() ?? '0', totalAmount: json['totalAmount']?.toString() ?? '0',
effectiveTreeCount: json['effectiveTreeCount'] ?? 0, effectiveTreeCount: json['effectiveTreeCount'] ?? 0,
effectiveContribution: json['effectiveContribution']?.toString() ?? '0',
firstPlantingAt: json['firstPlantingAt'] != null firstPlantingAt: json['firstPlantingAt'] != null
? DateTime.tryParse(json['firstPlantingAt']) ? DateTime.tryParse(json['firstPlantingAt'])
: null, : null,

View File

@ -80,10 +80,12 @@ class PlantingSummary extends Equatable {
final int totalOrders; final int totalOrders;
/// ///
final int totalTreeCount; final int totalTreeCount;
/// ///
final String totalAmount; final String totalAmount;
/// ///
final int effectiveTreeCount; final int effectiveTreeCount;
///
final String effectiveContribution;
/// ///
final DateTime? firstPlantingAt; final DateTime? firstPlantingAt;
/// ///
@ -94,6 +96,7 @@ class PlantingSummary extends Equatable {
required this.totalTreeCount, required this.totalTreeCount,
required this.totalAmount, required this.totalAmount,
required this.effectiveTreeCount, required this.effectiveTreeCount,
required this.effectiveContribution,
this.firstPlantingAt, this.firstPlantingAt,
this.lastPlantingAt, this.lastPlantingAt,
}); });
@ -104,6 +107,7 @@ class PlantingSummary extends Equatable {
totalTreeCount, totalTreeCount,
totalAmount, totalAmount,
effectiveTreeCount, effectiveTreeCount,
effectiveContribution,
firstPlantingAt, firstPlantingAt,
lastPlantingAt, lastPlantingAt,
]; ];

View File

@ -257,7 +257,7 @@ class _PlantingRecordsPageState extends ConsumerState<PlantingRecordsPage> {
children: [ children: [
_buildSummaryItem('总订单数', summary.totalOrders.toString()), _buildSummaryItem('总订单数', summary.totalOrders.toString()),
_buildSummaryItem('总认种量', summary.totalTreeCount.toString(), color: _green), _buildSummaryItem('总认种量', summary.totalTreeCount.toString(), color: _green),
_buildSummaryItem('总贡献值', formatAmount(summary.totalAmount), color: _orange), _buildSummaryItem('总贡献值', formatAmount(summary.effectiveContribution), color: _orange),
], ],
), ),
const SizedBox(height: 16), const SizedBox(height: 16),