fix(trade): v3.5.14 提交订单/支付成功日志使用真实 clientApp
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -26,7 +26,7 @@ export class TradeController {
|
||||
|
||||
@Post()
|
||||
create(@CurrentUser() user: AuthUser, @Body() body: Record<string, unknown>, @Req() req: Request) {
|
||||
return this.tradeService.createOrder(user.actorId, body as never, req);
|
||||
return this.tradeService.createOrder(user.actorId, body as never, req, user.clientApp);
|
||||
}
|
||||
|
||||
@Get()
|
||||
|
||||
@@ -210,6 +210,31 @@ export class TradeService {
|
||||
};
|
||||
}
|
||||
|
||||
private resolveTrackedUserClientApp(
|
||||
clientApp?: ClientApp | string | null,
|
||||
fallback: ClientApp = ClientApp.USER_H5,
|
||||
): ClientApp {
|
||||
if (clientApp === ClientApp.USER_MINI || clientApp === ClientApp.USER_H5) {
|
||||
return clientApp;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/** 支付回调无 JWT:沿用该订单已有埋点;没有则默认小程序(当前生产 C 端) */
|
||||
private async clientAppForPaidOrder(userId: bigint, orderId: bigint): Promise<ClientApp> {
|
||||
const row = await this.prisma.logUserAnalytics.findFirst({
|
||||
where: {
|
||||
userId,
|
||||
refType: 'ORDER',
|
||||
refId: orderId,
|
||||
eventName: { in: ['order_submit', 'pay_fail'] },
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
select: { clientApp: true },
|
||||
});
|
||||
return this.resolveTrackedUserClientApp(row?.clientApp, ClientApp.USER_MINI);
|
||||
}
|
||||
|
||||
async createOrder(
|
||||
userId: bigint,
|
||||
body: {
|
||||
@@ -221,6 +246,7 @@ export class TradeService {
|
||||
skuId?: string;
|
||||
},
|
||||
req: Request,
|
||||
clientApp?: ClientApp,
|
||||
) {
|
||||
const preview = await this.preview(userId, body);
|
||||
if (preview.quantityOk === false) {
|
||||
@@ -351,7 +377,7 @@ export class TradeService {
|
||||
);
|
||||
}
|
||||
|
||||
this.analyticsService.trackOneSafe(userId, 'USER_H5', {
|
||||
this.analyticsService.trackOneSafe(userId, this.resolveTrackedUserClientApp(clientApp), {
|
||||
eventName: 'order_submit',
|
||||
refType: 'ORDER',
|
||||
refId: order.id,
|
||||
@@ -480,7 +506,7 @@ export class TradeService {
|
||||
userId,
|
||||
});
|
||||
|
||||
this.analyticsService.trackOneSafe(userId, 'USER_H5', {
|
||||
this.analyticsService.trackOneSafe(userId, this.resolveTrackedUserClientApp(clientApp), {
|
||||
eventName: 'pay_success',
|
||||
refType: 'ORDER',
|
||||
refId: order.id,
|
||||
@@ -653,12 +679,16 @@ export class TradeService {
|
||||
orderNo: order.orderNo,
|
||||
userId: order.userId,
|
||||
});
|
||||
this.analyticsService.trackOneSafe(order.userId, 'USER_H5', {
|
||||
eventName: 'pay_success',
|
||||
refType: 'ORDER',
|
||||
refId: order.id,
|
||||
extraJson: { orderId: order.id.toString(), mode: 'wechat_callback' },
|
||||
});
|
||||
this.analyticsService.trackOneSafe(
|
||||
order.userId,
|
||||
await this.clientAppForPaidOrder(order.userId, order.id),
|
||||
{
|
||||
eventName: 'pay_success',
|
||||
refType: 'ORDER',
|
||||
refId: order.id,
|
||||
extraJson: { orderId: order.id.toString(), mode: 'wechat_callback' },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return { orderId: order.id.toString(), alreadyPaid: false };
|
||||
|
||||
Reference in New Issue
Block a user