@@ -51,6 +51,11 @@ export class UserRedeemController {
|
||||
);
|
||||
}
|
||||
|
||||
@Get('records/pending-rating')
|
||||
pendingRating(@CurrentUser() user: AuthUser, @Query('storeId') storeId: string) {
|
||||
return this.redeemService.getPendingRatingRecord(user.actorId, storeId);
|
||||
}
|
||||
|
||||
@Get('records/:id')
|
||||
record(@CurrentUser() user: AuthUser, @Param('id') id: string) {
|
||||
return this.redeemService.getUserRecord(user.actorId, id);
|
||||
|
||||
@@ -3,11 +3,18 @@ import { AnalyticsModule } from '../analytics/analytics.module';
|
||||
import { IamModule } from '../iam/iam.module';
|
||||
import { BenefitModule } from '../benefit/benefit.module';
|
||||
import { SettlementModule } from '../settlement/settlement.module';
|
||||
import { StoreModule } from '../store/store.module';
|
||||
import { RedeemService } from './redeem.service';
|
||||
import { ShopRedeemController, UserRedeemController } from './redeem.controller';
|
||||
|
||||
@Module({
|
||||
imports: [IamModule, AnalyticsModule, BenefitModule, forwardRef(() => SettlementModule)],
|
||||
imports: [
|
||||
IamModule,
|
||||
AnalyticsModule,
|
||||
BenefitModule,
|
||||
forwardRef(() => SettlementModule),
|
||||
forwardRef(() => StoreModule),
|
||||
],
|
||||
controllers: [UserRedeemController, ShopRedeemController],
|
||||
providers: [RedeemService],
|
||||
exports: [RedeemService],
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Inject,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
forwardRef,
|
||||
} from '@nestjs/common';
|
||||
import { randomBytes } from 'crypto';
|
||||
import {
|
||||
@@ -33,6 +35,7 @@ import { BenefitService } from '../benefit/benefit.service';
|
||||
import { AuthService } from '../iam/auth.service';
|
||||
import { PayRedeemAnomalyService } from '../../common/alert/pay-redeem-anomaly.service';
|
||||
import { WecomMessagePushService } from '../../integrations/wecom/wecom-message-push.service';
|
||||
import { StoreService } from '../store/store.service';
|
||||
|
||||
type TokenPayload = {
|
||||
userId: string;
|
||||
@@ -123,6 +126,8 @@ export class RedeemService {
|
||||
private readonly payRedeemAnomaly: PayRedeemAnomalyService,
|
||||
private readonly wecomPush: WecomMessagePushService,
|
||||
private readonly systemConfig: SystemConfigService,
|
||||
@Inject(forwardRef(() => StoreService))
|
||||
private readonly storeService: StoreService,
|
||||
) {}
|
||||
|
||||
private maskPhoneForStore(phone: string) {
|
||||
@@ -1388,6 +1393,22 @@ export class RedeemService {
|
||||
});
|
||||
}
|
||||
|
||||
async getPendingRatingRecord(userId: bigint, storeId: string) {
|
||||
const sid = String(storeId || '').trim();
|
||||
if (!/^\d+$/.test(sid)) return null;
|
||||
const record = await this.prisma.redeemRecord.findFirst({
|
||||
where: {
|
||||
userId,
|
||||
storeId: BigInt(sid),
|
||||
rating: null,
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
select: { id: true },
|
||||
});
|
||||
if (!record) return null;
|
||||
return serializeBigInt({ id: record.id });
|
||||
}
|
||||
|
||||
async submitRating(
|
||||
userId: bigint,
|
||||
body: {
|
||||
@@ -1421,6 +1442,7 @@ export class RedeemService {
|
||||
imageUrls,
|
||||
},
|
||||
});
|
||||
await this.storeService.refreshStoreRatingFromReviews(record.storeId);
|
||||
return serializeBigInt(mapStoreRating(rating));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1668,4 +1668,19 @@ export class StoreService {
|
||||
await this.partnerGetStore(partnerAccountId, storeId);
|
||||
return this.replaceStoreCategories(storeId, categoryIds, priorities);
|
||||
}
|
||||
|
||||
/** 评价提交后回写门店综合评分(服务+环境均值) */
|
||||
async refreshStoreRatingFromReviews(storeId: bigint) {
|
||||
const agg = await this.prisma.storeRating.aggregate({
|
||||
where: { storeId },
|
||||
_avg: { serviceScore: true, envScore: true },
|
||||
});
|
||||
const avgService = Number(agg._avg.serviceScore ?? 0);
|
||||
const avgEnv = Number(agg._avg.envScore ?? 0);
|
||||
const rating = Math.round(((avgService + avgEnv) / 2) * 100) / 100;
|
||||
await this.prisma.store.update({
|
||||
where: { id: storeId },
|
||||
data: { rating },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user