用户端和服务端增加地址功能(三个地址共存)
This commit is contained in:
@@ -16,12 +16,17 @@ import { BenefitService } from '../benefit/benefit.service';
|
||||
import { PAY_PROVIDER, DELIVERY_PROVIDER } from '../../integrations/integrations.constants';
|
||||
import { IPayProvider } from '../../integrations/pay/pay.interface';
|
||||
import { IDeliveryProvider } from '../../integrations/delivery/delivery.interface';
|
||||
import { IpGeoService } from '../../common/geo/ip-geo.service';
|
||||
import { buildOrderClientLocationSnapshot } from '../../common/geo/client-location.util';
|
||||
import { extractClientIp } from '../../common/geo/client-ip.util';
|
||||
import type { Request } from 'express';
|
||||
|
||||
@Injectable()
|
||||
export class TradeService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly benefitService: BenefitService,
|
||||
private readonly ipGeoService: IpGeoService,
|
||||
@Inject(PAY_PROVIDER) private readonly payProvider: IPayProvider,
|
||||
@Inject(DELIVERY_PROVIDER) private readonly deliveryProvider: IDeliveryProvider,
|
||||
) {}
|
||||
@@ -80,7 +85,9 @@ export class TradeService {
|
||||
productId: string;
|
||||
quantity: number;
|
||||
addressId: string;
|
||||
clientLocation?: unknown;
|
||||
},
|
||||
req: Request,
|
||||
) {
|
||||
const preview = await this.preview(userId, body);
|
||||
const address = await this.prisma.userAddress.findFirst({
|
||||
@@ -95,6 +102,12 @@ export class TradeService {
|
||||
const orderNo = generateOrderNo();
|
||||
const payExpireAt = new Date(Date.now() + 30 * 60 * 1000);
|
||||
|
||||
const location = buildOrderClientLocationSnapshot(
|
||||
req,
|
||||
this.ipGeoService.resolve(extractClientIp(req)),
|
||||
body.clientLocation,
|
||||
);
|
||||
|
||||
const order = await this.prisma.order.create({
|
||||
data: {
|
||||
orderNo,
|
||||
@@ -108,6 +121,16 @@ export class TradeService {
|
||||
receiverProvince: address.province,
|
||||
receiverCity: address.city,
|
||||
receiverDistrict: address.district,
|
||||
clientIp: location.clientIp,
|
||||
ipProvince: location.ipProvince,
|
||||
ipCity: location.ipCity,
|
||||
ipDistrict: location.ipDistrict,
|
||||
gpsProvince: location.gpsProvince,
|
||||
gpsCity: location.gpsCity,
|
||||
gpsDistrict: location.gpsDistrict,
|
||||
gpsLatitude: location.gpsLatitude,
|
||||
gpsLongitude: location.gpsLongitude,
|
||||
gpsAddress: location.gpsAddress,
|
||||
productAmount: preview.productAmount,
|
||||
freightAmount: preview.freightAmount,
|
||||
freightPayType: preview.freightPayType,
|
||||
|
||||
Reference in New Issue
Block a user