@pisell/pisellos 0.0.438 → 0.0.440

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -444,7 +444,7 @@ export interface CheckoutModuleAPI extends Module {
444
444
  /**
445
445
  * 为当前订单添加支付项
446
446
  */
447
- addPaymentItemAsync(paymentItem: PaymentItemInput): Promise<void>;
447
+ addPaymentItemAsync(paymentItem: PaymentItemInput, orderUuid?: string): Promise<void>;
448
448
  /**
449
449
  * 删除当前订单的支付项
450
450
  */
@@ -755,7 +755,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
755
755
  action: 'create',
756
756
  with_good_pass: 1,
757
757
  with_discount_card: 1,
758
- with_wallet_pass_holder: 1
758
+ with_wallet_pass_holder: 1,
759
+ request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
759
760
  });
760
761
  case 4:
761
762
  goodPassList = _context9.sent;
@@ -22,6 +22,7 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
22
22
  with_discount_card: 0 | 1;
23
23
  customer_id: number;
24
24
  with_wallet_pass_holder: 0 | 1;
25
+ request_timezone: string;
25
26
  }): Promise<Discount[]>;
26
27
  batchSearch(code: string, customerId?: number): Promise<Discount[]>;
27
28
  filterEnabledDiscountList(discountList: Discount[]): Discount[];
@@ -111,7 +111,8 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
111
111
  relation_product: 1,
112
112
  with: ["extensionData", "customScheduleSnapshot", "holder.detail"],
113
113
  order_behavior_count: 1,
114
- order_behavior_count_customer_id: customerId || 1
114
+ order_behavior_count_customer_id: customerId || 1,
115
+ request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
115
116
  });
116
117
  const resultDiscountList = this.filterEnabledDiscountList((result == null ? void 0 : result.data) || []) || [];
117
118
  return resultDiscountList;
@@ -20,7 +20,9 @@ export declare enum PaymentStatus {
20
20
  /** 部分支付 - 支付金额不足订单总金额 */
21
21
  PartiallyPaid = "partially_paid",
22
22
  /** 已完成 - 本地支付完成,后台自动同步到服务器 */
23
- Finished = "finish"
23
+ Finished = "finish",
24
+ /** 已撤销 - 本地订单取消 */
25
+ Voided = "voided"
24
26
  }
25
27
  /**
26
28
  * 任务状态枚举
@@ -39,6 +39,7 @@ var PaymentStatus = /* @__PURE__ */ ((PaymentStatus2) => {
39
39
  PaymentStatus2["Sync"] = "sync";
40
40
  PaymentStatus2["PartiallyPaid"] = "partially_paid";
41
41
  PaymentStatus2["Finished"] = "finish";
42
+ PaymentStatus2["Voided"] = "voided";
42
43
  return PaymentStatus2;
43
44
  })(PaymentStatus || {});
44
45
  var TaskRunStatus = /* @__PURE__ */ ((TaskRunStatus2) => {
@@ -74,10 +74,9 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
74
74
  this.store.surchargeList = (surchargeList == null ? void 0 : surchargeList.data) || [];
75
75
  }
76
76
  async getSummary(cartItems) {
77
- var _a, _b;
77
+ var _a, _b, _c;
78
78
  const shopInfo = ((_b = (_a = this.shopStore.get("core")) == null ? void 0 : _a.core) == null ? void 0 : _b.shop) || {};
79
- const scheduleModule = this.core.getModule("appointmentBooking_schedule");
80
- const summary = (0, import_utils.calculatePriceDetails)(shopInfo, cartItems, scheduleModule == null ? void 0 : scheduleModule.isInScheduleByDate, this.store.surchargeList);
79
+ const summary = (0, import_utils.calculatePriceDetails)(shopInfo, cartItems, (_c = import_Schedule.ScheduleModule) == null ? void 0 : _c.isInScheduleByDate, this.store.surchargeList);
81
80
  this.store.summary = summary;
82
81
  return this.store.summary;
83
82
  }
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 6;
314
+ weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
123
123
  * 获取当前的客户搜索条件
124
124
  * @returns 当前搜索条件
125
125
  */
126
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
126
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
127
127
  /**
128
128
  * 获取客户列表状态(包含滚动加载相关状态)
129
129
  * @returns 客户状态
@@ -169,7 +169,7 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
169
169
  * @param paymentItem 支付项数据
170
170
  * @throws 当前没有活跃订单时抛出错误
171
171
  */
172
- addPaymentItemAsync(paymentItem: PaymentItemInput): Promise<void>;
172
+ addPaymentItemAsync(paymentItem: PaymentItemInput, orderUuid?: string): Promise<void>;
173
173
  /**
174
174
  * 删除当前订单的支付项
175
175
  *
@@ -373,6 +373,8 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
373
373
  * 在 updateStateAmountToRemaining 中会使用优化版本。
374
374
  */
375
375
  private checkOrderPaymentCompletion;
376
+ private repairEftposPaymentFromIndexDbAsync;
377
+ private syncOrderToBackendFromIndexDbAsync;
376
378
  /**
377
379
  * 同步订单到后端并返回真实订单ID
378
380
  *
@@ -1009,9 +1009,31 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1009
1009
  * @param paymentItem 支付项数据
1010
1010
  * @throws 当前没有活跃订单时抛出错误
1011
1011
  */
1012
- async addPaymentItemAsync(paymentItem) {
1013
- var _a, _b;
1014
- this.logInfo("addPaymentItemAsync called", paymentItem);
1012
+ async addPaymentItemAsync(paymentItem, orderUuid) {
1013
+ var _a, _b, _c, _d, _e;
1014
+ this.logInfo("addPaymentItemAsync called", { paymentItem, orderUuid });
1015
+ const isEftposPayment = ((_a = paymentItem.type) == null ? void 0 : _a.toLowerCase()) === "eftpos" || ((_b = paymentItem.code) == null ? void 0 : _b.toUpperCase().includes("EFTPOS"));
1016
+ const shouldRepairFromIndexDb = !!orderUuid && isEftposPayment && (!this.store.currentOrder || this.store.currentOrder.uuid !== orderUuid);
1017
+ if (shouldRepairFromIndexDb) {
1018
+ this.logError("EFTPOS push payment repair triggered", {
1019
+ orderUuid,
1020
+ currentOrderUuid: (_c = this.store.currentOrder) == null ? void 0 : _c.uuid,
1021
+ paymentCode: paymentItem.code,
1022
+ paymentType: paymentItem.type
1023
+ });
1024
+ try {
1025
+ await this.repairEftposPaymentFromIndexDbAsync({
1026
+ orderUuid,
1027
+ paymentItem
1028
+ });
1029
+ } catch (error) {
1030
+ this.logError("EFTPOS push payment repair failed", {
1031
+ orderUuid,
1032
+ error: error instanceof Error ? error.message : String(error)
1033
+ });
1034
+ }
1035
+ return;
1036
+ }
1015
1037
  try {
1016
1038
  if (!this.store.currentOrder) {
1017
1039
  throw (0, import_utils.createCheckoutError)(
@@ -1041,16 +1063,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1041
1063
  const remainingAmount = await this.calculateRemainingAmountAsync();
1042
1064
  if (Number(remainingAmount) > 0) {
1043
1065
  this.logInfo("订单金额还有待付的,同步 EFTPOS 支付");
1044
- const isEftposPayment = ((_a = paymentItem.type) == null ? void 0 : _a.toLowerCase()) === "eftpos" || ((_b = paymentItem.code) == null ? void 0 : _b.toUpperCase().includes("EFTPOS"));
1066
+ const isEftposPayment2 = ((_d = paymentItem.type) == null ? void 0 : _d.toLowerCase()) === "eftpos" || ((_e = paymentItem.code) == null ? void 0 : _e.toUpperCase().includes("EFTPOS"));
1045
1067
  const isCashPayment2 = paymentItem.code === "CASHMANUAL";
1046
1068
  const isCustomePayment = paymentItem.type === "custom";
1047
1069
  this.logInfo("EFTPOS 支付检查:", {
1048
1070
  paymentCode: paymentItem.code,
1049
1071
  paymentType: paymentItem.type,
1050
- isEftposPayment,
1072
+ isEftposPayment: isEftposPayment2,
1051
1073
  currentOrderSynced: this.store.isOrderSynced
1052
1074
  });
1053
- if (isEftposPayment || isCashPayment2 || isCustomePayment) {
1075
+ if (isEftposPayment2 || isCashPayment2 || isCustomePayment) {
1054
1076
  this.logInfo("检测到 EFTPOS 支付,立即同步订单到后端...");
1055
1077
  try {
1056
1078
  const syncResult = await this.syncOrderToBackendWithReturn(true);
@@ -1568,11 +1590,13 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1568
1590
  };
1569
1591
  }
1570
1592
  try {
1571
- this.logInfo("删除本地订单数据");
1572
- await this.payment.deletePaymentOrderAsync(currentOrderUuid);
1573
- this.logInfo("本地订单数据删除成功");
1593
+ this.logInfo("标记本地订单为已删除");
1594
+ await this.payment.updateOrderAsync(currentOrderUuid, {
1595
+ payment_status: import_types2.PaymentStatus.Voided
1596
+ });
1597
+ this.logInfo("本地订单删除标记成功");
1574
1598
  } catch (error) {
1575
- this.logWarning("删除本地订单数据失败,但继续执行:", error);
1599
+ this.logWarning("标记本地订单删除失败,但继续执行:", error);
1576
1600
  }
1577
1601
  this.logInfo("清理订单相关状态");
1578
1602
  this.store.currentOrder = void 0;
@@ -2363,6 +2387,221 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2363
2387
  this.logError("检查订单支付完成状态失败:", error);
2364
2388
  }
2365
2389
  }
2390
+ async repairEftposPaymentFromIndexDbAsync(params) {
2391
+ const { orderUuid, paymentItem } = params;
2392
+ const order = await this.payment.getPaymentOrderByUuidAsync(orderUuid);
2393
+ if (!order) {
2394
+ this.logError("EFTPOS repair failed: order not found in IndexDB", {
2395
+ orderUuid,
2396
+ paymentItem
2397
+ });
2398
+ return;
2399
+ }
2400
+ const orderPaymentType = order.is_deposit === 1 ? "deposit" : "normal";
2401
+ const processedPaymentItem = await this.processCashPaymentItem(paymentItem);
2402
+ const metadata = {
2403
+ ...processedPaymentItem.metadata,
2404
+ rounding_rule: this.otherParams.order_rounding_setting,
2405
+ shop_wallet_pass_id: this.otherParams.shop_wallet_pass_id
2406
+ };
2407
+ const paymentItemWithType = {
2408
+ ...processedPaymentItem,
2409
+ order_payment_type: orderPaymentType,
2410
+ metadata
2411
+ };
2412
+ await this.payment.addPaymentItemAsync(orderUuid, paymentItemWithType);
2413
+ await this.syncOrderToBackendFromIndexDbAsync({ orderUuid });
2414
+ }
2415
+ async syncOrderToBackendFromIndexDbAsync(params) {
2416
+ var _a, _b, _c, _d, _e, _f, _g;
2417
+ const { orderUuid } = params;
2418
+ const paymentOrder = await this.payment.getPaymentOrderByUuidAsync(orderUuid);
2419
+ if (!paymentOrder) {
2420
+ this.logError("EFTPOS repair sync failed: missing payment order", {
2421
+ orderUuid
2422
+ });
2423
+ return { success: false };
2424
+ }
2425
+ const localOrderData = ((_a = paymentOrder.order_info) == null ? void 0 : _a.original_order_data) || ((_b = paymentOrder.order_info) == null ? void 0 : _b.order_data);
2426
+ if (!localOrderData) {
2427
+ this.logError("EFTPOS repair sync failed: missing local order data", {
2428
+ orderUuid,
2429
+ orderInfoKeys: Object.keys(paymentOrder.order_info || {})
2430
+ });
2431
+ return { success: false };
2432
+ }
2433
+ const paymentItems = await this.payment.getPaymentItemsAsync(orderUuid);
2434
+ const processedPaymentItems = paymentItems.map((item) => {
2435
+ var _a2, _b2;
2436
+ return {
2437
+ ...item,
2438
+ metadata: {
2439
+ ...item.metadata,
2440
+ rounding_rule: ((_a2 = item.metadata) == null ? void 0 : _a2.rounding_rule) || this.otherParams.order_rounding_setting,
2441
+ shop_wallet_pass_id: ((_b2 = item.metadata) == null ? void 0 : _b2.shop_wallet_pass_id) || this.otherParams.shop_wallet_pass_id
2442
+ }
2443
+ };
2444
+ });
2445
+ let finalDepositAmount;
2446
+ const manualDepositAmount = paymentOrder.deposit_amount || "0.00";
2447
+ const manualDepositValue = new import_decimal.default(manualDepositAmount);
2448
+ if (manualDepositValue.gt(0)) {
2449
+ finalDepositAmount = manualDepositAmount;
2450
+ } else {
2451
+ finalDepositAmount = "0.00";
2452
+ }
2453
+ if (paymentOrder.is_deposit === 0 && processedPaymentItems.every((item) => item.order_payment_type !== "deposit")) {
2454
+ finalDepositAmount = "0.00";
2455
+ }
2456
+ if (paymentOrder.is_deposit === 0 && processedPaymentItems.some((item) => item.order_payment_type === "deposit")) {
2457
+ finalDepositAmount = processedPaymentItems.filter(
2458
+ (item) => item.status !== "voided" && item.order_payment_type === "deposit"
2459
+ ).reduce((sum, item) => {
2460
+ const amountValue = new import_decimal.default(item.amount || "0");
2461
+ const roundingValue = new import_decimal.default(item.rounding_amount || "0");
2462
+ return sum.plus(amountValue).sub(roundingValue);
2463
+ }, new import_decimal.default(0)).toFixed(2);
2464
+ }
2465
+ if (paymentOrder.is_deposit === 1 && new import_decimal.default(finalDepositAmount).gte(
2466
+ new import_decimal.default(paymentOrder.total_amount)
2467
+ )) {
2468
+ finalDepositAmount = processedPaymentItems.filter(
2469
+ (item) => item.status !== "voided" && item.order_payment_type === "deposit"
2470
+ ).reduce((sum, item) => {
2471
+ const amountValue = new import_decimal.default(item.amount || "0");
2472
+ const roundingValue = new import_decimal.default(item.rounding_amount || "0");
2473
+ return sum.plus(amountValue).sub(roundingValue);
2474
+ }, new import_decimal.default(0)).toFixed(2);
2475
+ }
2476
+ let orderPaymentStatus;
2477
+ const totalPaidAmount = processedPaymentItems.filter((item) => item.status !== "voided").reduce((sum, item) => {
2478
+ const amountValue = new import_decimal.default(item.amount || "0");
2479
+ const roundingValue = new import_decimal.default(item.rounding_amount || "0");
2480
+ return sum.plus(amountValue).sub(roundingValue);
2481
+ }, new import_decimal.default(0));
2482
+ if (totalPaidAmount.gte(new import_decimal.default(paymentOrder.total_amount))) {
2483
+ orderPaymentStatus = "paid";
2484
+ } else if (totalPaidAmount.gt(0)) {
2485
+ orderPaymentStatus = "partially_paid";
2486
+ } else {
2487
+ orderPaymentStatus = "unpaid";
2488
+ }
2489
+ const orderParams = {
2490
+ ...localOrderData,
2491
+ payment_status: orderPaymentStatus,
2492
+ type: localOrderData.type,
2493
+ platform: localOrderData.platform,
2494
+ payments: processedPaymentItems,
2495
+ customer_id: localOrderData.customer_id,
2496
+ is_price_include_tax: this.otherParams.is_price_include_tax,
2497
+ tax_title: this.otherParams.tax_title,
2498
+ tax_rate: this.otherParams.tax_rate,
2499
+ tax_country_code: this.otherParams.tax_country_code,
2500
+ currency_code: this.otherParams.currency_code,
2501
+ currency_symbol: this.otherParams.currency_symbol,
2502
+ currency_format: this.otherParams.currency_format,
2503
+ business_code: ((_c = this.otherParams) == null ? void 0 : _c.business_code) || void 0,
2504
+ is_deposit: (paymentOrder.is_deposit || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
2505
+ deposit_amount: finalDepositAmount,
2506
+ product_tax_fee: localOrderData.tax_fee,
2507
+ note: localOrderData.shop_note,
2508
+ bookings: (_d = localOrderData.bookings) == null ? void 0 : _d.map((item) => {
2509
+ return {
2510
+ ...item,
2511
+ product: {
2512
+ ...item.product,
2513
+ custom_deposit_data: void 0
2514
+ },
2515
+ deposit: void 0
2516
+ };
2517
+ }),
2518
+ relation_products: (_e = localOrderData.relation_products) == null ? void 0 : _e.map((item) => {
2519
+ return {
2520
+ ...item,
2521
+ custom_deposit_data: void 0,
2522
+ deposit: void 0
2523
+ };
2524
+ })
2525
+ };
2526
+ const currentOrderId = paymentOrder.order_id;
2527
+ const isUpdateOperation = currentOrderId && !(0, import_utils.isVirtualOrderId)(currentOrderId);
2528
+ if (isUpdateOperation) {
2529
+ orderParams.order_id = currentOrderId;
2530
+ }
2531
+ this.logError("EFTPOS repair sync start", {
2532
+ orderUuid,
2533
+ orderId: currentOrderId,
2534
+ isUpdateOperation,
2535
+ paymentItemCount: processedPaymentItems.length
2536
+ });
2537
+ let checkoutResponse;
2538
+ try {
2539
+ this.logError("EFTPOS repair calling backend checkout API", {
2540
+ url: "/order/checkout",
2541
+ isManual: true,
2542
+ ...orderParams
2543
+ });
2544
+ checkoutResponse = await this.order.createOrderByCheckout(orderParams);
2545
+ } catch (error) {
2546
+ this.logError("EFTPOS repair checkout API failed", {
2547
+ orderUuid,
2548
+ error: error instanceof Error ? error.message : String(error)
2549
+ });
2550
+ throw error;
2551
+ } finally {
2552
+ this.logError("EFTPOS repair sync end", {
2553
+ orderUuid,
2554
+ orderId: currentOrderId,
2555
+ responseStatus: checkoutResponse == null ? void 0 : checkoutResponse.status
2556
+ });
2557
+ }
2558
+ const responseStatus = checkoutResponse == null ? void 0 : checkoutResponse.status;
2559
+ const isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === "success" || responseStatus === 1 && (checkoutResponse == null ? void 0 : checkoutResponse.code) === 200;
2560
+ if (!isSuccessResponse) {
2561
+ const errorMessage = (checkoutResponse == null ? void 0 : checkoutResponse.message) || "订单同步失败,后端返回非成功状态";
2562
+ this.logError("EFTPOS repair sync failed: api error", {
2563
+ orderUuid,
2564
+ errorMessage,
2565
+ response: checkoutResponse
2566
+ });
2567
+ return { success: false, response: checkoutResponse };
2568
+ }
2569
+ let realOrderId = currentOrderId;
2570
+ if (!isUpdateOperation) {
2571
+ let extractedOrderId = (_f = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _f.order_id;
2572
+ if (!extractedOrderId) {
2573
+ extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
2574
+ }
2575
+ if (extractedOrderId !== void 0 && extractedOrderId !== null) {
2576
+ extractedOrderId = String(extractedOrderId);
2577
+ }
2578
+ realOrderId = extractedOrderId;
2579
+ if (realOrderId) {
2580
+ await this.payment.replaceOrderIdByUuidAsync(orderUuid, realOrderId);
2581
+ } else {
2582
+ this.logError("EFTPOS repair missing order_id in response", {
2583
+ orderUuid,
2584
+ response: checkoutResponse
2585
+ });
2586
+ }
2587
+ }
2588
+ const syncedPaymentUuids = processedPaymentItems.filter((item) => item.status !== "voided").map((item) => item.uuid).filter(Boolean);
2589
+ for (const paymentUuid of syncedPaymentUuids) {
2590
+ await this.payment.updatePaymentAsync(orderUuid, paymentUuid, {
2591
+ isSynced: true,
2592
+ syncError: void 0
2593
+ });
2594
+ }
2595
+ const latestPaymentStatus = ((_g = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _g.payment_status) || orderPaymentStatus;
2596
+ await this.payment.updateOrderAsync(orderUuid, {
2597
+ payment_status: latestPaymentStatus
2598
+ });
2599
+ return {
2600
+ success: true,
2601
+ orderId: realOrderId,
2602
+ response: checkoutResponse
2603
+ };
2604
+ }
2366
2605
  /**
2367
2606
  * 同步订单到后端并返回真实订单ID
2368
2607
  *
@@ -444,7 +444,7 @@ export interface CheckoutModuleAPI extends Module {
444
444
  /**
445
445
  * 为当前订单添加支付项
446
446
  */
447
- addPaymentItemAsync(paymentItem: PaymentItemInput): Promise<void>;
447
+ addPaymentItemAsync(paymentItem: PaymentItemInput, orderUuid?: string): Promise<void>;
448
448
  /**
449
449
  * 删除当前订单的支付项
450
450
  */
@@ -501,7 +501,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
501
501
  action: "create",
502
502
  with_good_pass: 1,
503
503
  with_discount_card: 1,
504
- with_wallet_pass_holder: 1
504
+ with_wallet_pass_holder: 1,
505
+ request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
505
506
  }));
506
507
  const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
507
508
  (item) => item.isScan
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.438",
4
+ "version": "0.0.440",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",