refactor(service): 统一将wPService重命名为wpService以符合命名规范
This commit is contained in:
parent
dc070fadde
commit
e94ea5ed58
|
|
@ -38,7 +38,7 @@ export class OrderService {
|
||||||
sites: WpSite[];
|
sites: WpSite[];
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
wPService: WPService;
|
wpService: WPService;
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
stockService: StockService;
|
stockService: StockService;
|
||||||
|
|
@ -101,14 +101,14 @@ export class OrderService {
|
||||||
customerModel: Repository<Customer>;
|
customerModel: Repository<Customer>;
|
||||||
|
|
||||||
async syncOrders(siteId: string) {
|
async syncOrders(siteId: string) {
|
||||||
const orders = await this.wPService.getOrders(siteId); // 调用 WooCommerce API 获取订单
|
const orders = await this.wpService.getOrders(siteId); // 调用 WooCommerce API 获取订单
|
||||||
for (const order of orders) {
|
for (const order of orders) {
|
||||||
await this.syncSingleOrder(siteId, order);
|
await this.syncSingleOrder(siteId, order);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async syncOrderById(siteId: string, orderId: string) {
|
async syncOrderById(siteId: string, orderId: string) {
|
||||||
const order = await this.wPService.getOrder(siteId, orderId);
|
const order = await this.wpService.getOrder(siteId, orderId);
|
||||||
await this.syncSingleOrder(siteId, order, true);
|
await this.syncSingleOrder(siteId, order, true);
|
||||||
}
|
}
|
||||||
// 订单状态切换表
|
// 订单状态切换表
|
||||||
|
|
@ -131,7 +131,7 @@ export class OrderService {
|
||||||
throw new Error(`更新订单信息,但失败,原因为 ${siteId} 的站点信息不存在`)
|
throw new Error(`更新订单信息,但失败,原因为 ${siteId} 的站点信息不存在`)
|
||||||
}
|
}
|
||||||
// 同步更新回 wordpress 的 order 状态
|
// 同步更新回 wordpress 的 order 状态
|
||||||
await this.wPService.updateOrder(site, order.id, { status: order.status });
|
await this.wpService.updateOrder(site, order.id, { status: order.status });
|
||||||
order.status = this.orderAutoNextStatusMap[originStatus];
|
order.status = this.orderAutoNextStatusMap[originStatus];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('更新订单状态失败,原因为:', error)
|
console.error('更新订单状态失败,原因为:', error)
|
||||||
|
|
@ -442,7 +442,7 @@ export class OrderService {
|
||||||
refunds: Record<string, any>[];
|
refunds: Record<string, any>[];
|
||||||
}) {
|
}) {
|
||||||
for (const item of refunds) {
|
for (const item of refunds) {
|
||||||
const refund = await this.wPService.getOrderRefund(
|
const refund = await this.wpService.getOrderRefund(
|
||||||
siteId,
|
siteId,
|
||||||
externalOrderId,
|
externalOrderId,
|
||||||
item.id
|
item.id
|
||||||
|
|
@ -1261,9 +1261,9 @@ export class OrderService {
|
||||||
async cancelOrder(id: number) {
|
async cancelOrder(id: number) {
|
||||||
const order = await this.orderModel.findOne({ where: { id } });
|
const order = await this.orderModel.findOne({ where: { id } });
|
||||||
if (!order) throw new Error(`订单 ${id}不存在`);
|
if (!order) throw new Error(`订单 ${id}不存在`);
|
||||||
const site = this.wPService.geSite(order.siteId);
|
const site = this.wpService.geSite(order.siteId);
|
||||||
if (order.status !== OrderStatus.CANCEL) {
|
if (order.status !== OrderStatus.CANCEL) {
|
||||||
await this.wPService.updateOrder(site, order.externalOrderId, {
|
await this.wpService.updateOrder(site, order.externalOrderId, {
|
||||||
status: OrderStatus.CANCEL,
|
status: OrderStatus.CANCEL,
|
||||||
});
|
});
|
||||||
order.status = OrderStatus.CANCEL;
|
order.status = OrderStatus.CANCEL;
|
||||||
|
|
@ -1275,9 +1275,9 @@ export class OrderService {
|
||||||
async refundOrder(id: number) {
|
async refundOrder(id: number) {
|
||||||
const order = await this.orderModel.findOne({ where: { id } });
|
const order = await this.orderModel.findOne({ where: { id } });
|
||||||
if (!order) throw new Error(`订单 ${id}不存在`);
|
if (!order) throw new Error(`订单 ${id}不存在`);
|
||||||
const site = this.wPService.geSite(order.siteId);
|
const site = this.wpService.geSite(order.siteId);
|
||||||
if (order.status !== OrderStatus.REFUNDED) {
|
if (order.status !== OrderStatus.REFUNDED) {
|
||||||
await this.wPService.updateOrder(site, order.externalOrderId, {
|
await this.wpService.updateOrder(site, order.externalOrderId, {
|
||||||
status: OrderStatus.REFUNDED,
|
status: OrderStatus.REFUNDED,
|
||||||
});
|
});
|
||||||
order.status = OrderStatus.REFUNDED;
|
order.status = OrderStatus.REFUNDED;
|
||||||
|
|
@ -1289,9 +1289,9 @@ export class OrderService {
|
||||||
async completedOrder(id: number) {
|
async completedOrder(id: number) {
|
||||||
const order = await this.orderModel.findOne({ where: { id } });
|
const order = await this.orderModel.findOne({ where: { id } });
|
||||||
if (!order) throw new Error(`订单 ${id}不存在`);
|
if (!order) throw new Error(`订单 ${id}不存在`);
|
||||||
const site = this.wPService.geSite(order.siteId);
|
const site = this.wpService.geSite(order.siteId);
|
||||||
if (order.status !== OrderStatus.COMPLETED) {
|
if (order.status !== OrderStatus.COMPLETED) {
|
||||||
await this.wPService.updateOrder(site, order.externalOrderId, {
|
await this.wpService.updateOrder(site, order.externalOrderId, {
|
||||||
status: OrderStatus.COMPLETED,
|
status: OrderStatus.COMPLETED,
|
||||||
});
|
});
|
||||||
order.status = OrderStatus.COMPLETED;
|
order.status = OrderStatus.COMPLETED;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import { QuerySubscriptionDTO } from '../dto/subscription.dto';
|
||||||
@Provide()
|
@Provide()
|
||||||
export class SubscriptionService {
|
export class SubscriptionService {
|
||||||
@Inject()
|
@Inject()
|
||||||
wPService: WPService;
|
wpService: WPService;
|
||||||
|
|
||||||
@InjectEntityModel(Subscription)
|
@InjectEntityModel(Subscription)
|
||||||
subscriptionModel: Repository<Subscription>;
|
subscriptionModel: Repository<Subscription>;
|
||||||
|
|
@ -20,7 +20,7 @@ export class SubscriptionService {
|
||||||
* - 从 WooCommerce 拉取订阅并逐条入库/更新
|
* - 从 WooCommerce 拉取订阅并逐条入库/更新
|
||||||
*/
|
*/
|
||||||
async syncSubscriptions(siteId: string) {
|
async syncSubscriptions(siteId: string) {
|
||||||
const subs = await this.wPService.getSubscriptions(siteId);
|
const subs = await this.wpService.getSubscriptions(siteId);
|
||||||
for (const sub of subs) {
|
for (const sub of subs) {
|
||||||
await this.syncSingleSubscription(siteId, sub);
|
await this.syncSingleSubscription(siteId, sub);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue