@pisell/pisellos 2.3.37 → 2.3.39

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.
Files changed (169) hide show
  1. package/dist/modules/Discount/index.d.ts +1 -0
  2. package/dist/modules/Discount/index.js +40 -11
  3. package/dist/modules/Discount/types.d.ts +1 -0
  4. package/dist/modules/Holder/index.d.ts +48 -0
  5. package/dist/modules/Holder/index.js +640 -0
  6. package/dist/modules/Holder/types.d.ts +123 -0
  7. package/dist/modules/Holder/types.js +1 -0
  8. package/dist/modules/Holder/utils.d.ts +13 -0
  9. package/dist/modules/Holder/utils.js +34 -0
  10. package/dist/modules/OpenData/index.js +2 -2
  11. package/dist/modules/Order/index.d.ts +11 -28
  12. package/dist/modules/Order/index.js +513 -747
  13. package/dist/modules/Order/types.d.ts +10 -33
  14. package/dist/modules/Order/utils/orderCollectionIdentity.js +2 -7
  15. package/dist/modules/Order/utils.d.ts +10 -0
  16. package/dist/modules/Order/utils.js +40 -11
  17. package/dist/modules/Payment/index.d.ts +0 -2
  18. package/dist/modules/Payment/index.js +49 -78
  19. package/dist/modules/Payment/types.d.ts +24 -26
  20. package/dist/modules/Payment/types.js +0 -2
  21. package/dist/modules/Product/types.d.ts +1 -0
  22. package/dist/modules/ProductList/index.js +33 -14
  23. package/dist/modules/Quotation/index.d.ts +1 -1
  24. package/dist/modules/Quotation/index.js +2 -2
  25. package/dist/modules/ResourcePlanner/index.d.ts +24 -0
  26. package/dist/modules/ResourcePlanner/index.js +181 -0
  27. package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
  28. package/dist/modules/ResourcePlanner/planner.js +1069 -0
  29. package/dist/modules/ResourcePlanner/types.d.ts +227 -0
  30. package/dist/modules/ResourcePlanner/types.js +1 -0
  31. package/dist/modules/Rules/index.js +48 -15
  32. package/dist/modules/SalesSummary/index.js +12 -13
  33. package/dist/modules/ScanOrderLogger/index.d.ts +2 -0
  34. package/dist/modules/ScanOrderLogger/index.js +15 -2
  35. package/dist/modules/ScanOrderLogger/providers/feishu.js +45 -27
  36. package/dist/modules/ScanOrderLogger/types.d.ts +1 -0
  37. package/dist/modules/Schedule/index.d.ts +3 -1
  38. package/dist/modules/Schedule/index.js +21 -16
  39. package/dist/modules/Summary/utils.js +38 -13
  40. package/dist/modules/index.d.ts +2 -0
  41. package/dist/modules/index.js +3 -1
  42. package/dist/plugins/window.d.ts +1 -0
  43. package/dist/server/index.d.ts +14 -16
  44. package/dist/server/index.js +1162 -1943
  45. package/dist/server/modules/order/index.d.ts +4 -49
  46. package/dist/server/modules/order/index.js +695 -1574
  47. package/dist/server/modules/order/types.d.ts +3 -11
  48. package/dist/server/modules/order/types.js +1 -1
  49. package/dist/solution/BaseSales/index.d.ts +10 -33
  50. package/dist/solution/BaseSales/index.js +385 -676
  51. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  52. package/dist/solution/BookingByStep/index.d.ts +17 -2
  53. package/dist/solution/BookingByStep/index.js +294 -215
  54. package/dist/solution/BookingByStep/types.d.ts +2 -1
  55. package/dist/solution/BookingByStep/types.js +3 -1
  56. package/dist/solution/BookingByStep/utils/capacity.js +17 -1
  57. package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  58. package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
  59. package/dist/solution/BookingTicket/index.js +1 -2
  60. package/dist/solution/Sales/index.d.ts +0 -1
  61. package/dist/solution/Sales/index.js +2 -10
  62. package/dist/solution/ScanOrder/index.d.ts +26 -14
  63. package/dist/solution/ScanOrder/index.js +1140 -737
  64. package/dist/solution/ScanOrder/types.d.ts +21 -1
  65. package/dist/solution/ScanOrder/utils.d.ts +8 -0
  66. package/dist/solution/ScanOrder/utils.js +66 -25
  67. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  68. package/dist/solution/ShopDiscount/index.js +125 -87
  69. package/dist/solution/UnifiedBookingSales/index.d.ts +183 -0
  70. package/dist/solution/UnifiedBookingSales/index.js +1871 -0
  71. package/dist/solution/UnifiedBookingSales/types.d.ts +143 -0
  72. package/dist/solution/UnifiedBookingSales/types.js +11 -0
  73. package/dist/solution/VenueBooking/index.d.ts +39 -11
  74. package/dist/solution/VenueBooking/index.js +1177 -850
  75. package/dist/solution/VenueBooking/types.d.ts +3 -0
  76. package/dist/solution/VenueBooking/utils/resource.js +1 -0
  77. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  78. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -5
  79. package/dist/solution/index.d.ts +1 -0
  80. package/dist/solution/index.js +2 -1
  81. package/dist/types/index.d.ts +1 -0
  82. package/lib/modules/Discount/index.d.ts +1 -0
  83. package/lib/modules/Discount/index.js +9 -0
  84. package/lib/modules/Discount/types.d.ts +1 -0
  85. package/lib/modules/Holder/index.d.ts +48 -0
  86. package/lib/modules/Holder/index.js +402 -0
  87. package/lib/modules/Holder/types.d.ts +123 -0
  88. package/lib/modules/Holder/types.js +17 -0
  89. package/lib/modules/Holder/utils.d.ts +13 -0
  90. package/lib/modules/Holder/utils.js +71 -0
  91. package/lib/modules/OpenData/index.js +1 -1
  92. package/lib/modules/Order/index.d.ts +11 -28
  93. package/lib/modules/Order/index.js +83 -187
  94. package/lib/modules/Order/types.d.ts +10 -33
  95. package/lib/modules/Order/utils/orderCollectionIdentity.js +0 -3
  96. package/lib/modules/Order/utils.d.ts +10 -0
  97. package/lib/modules/Order/utils.js +39 -10
  98. package/lib/modules/Payment/index.d.ts +0 -2
  99. package/lib/modules/Payment/index.js +12 -33
  100. package/lib/modules/Payment/types.d.ts +24 -26
  101. package/lib/modules/Product/types.d.ts +1 -0
  102. package/lib/modules/ProductList/index.js +40 -31
  103. package/lib/modules/Quotation/index.d.ts +1 -1
  104. package/lib/modules/Quotation/index.js +2 -2
  105. package/lib/modules/ResourcePlanner/index.d.ts +24 -0
  106. package/lib/modules/ResourcePlanner/index.js +148 -0
  107. package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
  108. package/lib/modules/ResourcePlanner/planner.js +933 -0
  109. package/lib/modules/ResourcePlanner/types.d.ts +227 -0
  110. package/lib/modules/ResourcePlanner/types.js +17 -0
  111. package/lib/modules/Rules/index.js +34 -18
  112. package/lib/modules/SalesSummary/index.js +6 -7
  113. package/lib/modules/ScanOrderLogger/index.d.ts +2 -0
  114. package/lib/modules/ScanOrderLogger/index.js +13 -1
  115. package/lib/modules/ScanOrderLogger/providers/feishu.js +15 -6
  116. package/lib/modules/ScanOrderLogger/types.d.ts +1 -0
  117. package/lib/modules/Schedule/index.d.ts +3 -1
  118. package/lib/modules/Schedule/index.js +10 -8
  119. package/lib/modules/Summary/utils.js +21 -1
  120. package/lib/modules/index.d.ts +2 -0
  121. package/lib/modules/index.js +5 -1
  122. package/lib/plugins/window.d.ts +1 -0
  123. package/lib/server/index.d.ts +14 -16
  124. package/lib/server/index.js +88 -678
  125. package/lib/server/modules/order/index.d.ts +4 -49
  126. package/lib/server/modules/order/index.js +66 -657
  127. package/lib/server/modules/order/types.d.ts +3 -11
  128. package/lib/solution/BaseSales/index.d.ts +10 -33
  129. package/lib/solution/BaseSales/index.js +33 -201
  130. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  131. package/lib/solution/BookingByStep/index.d.ts +17 -2
  132. package/lib/solution/BookingByStep/index.js +60 -18
  133. package/lib/solution/BookingByStep/types.d.ts +2 -1
  134. package/lib/solution/BookingByStep/types.js +5 -0
  135. package/lib/solution/BookingByStep/utils/capacity.js +20 -1
  136. package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  137. package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
  138. package/lib/solution/BookingTicket/index.js +1 -2
  139. package/lib/solution/Sales/index.d.ts +0 -1
  140. package/lib/solution/Sales/index.js +3 -5
  141. package/lib/solution/ScanOrder/index.d.ts +26 -14
  142. package/lib/solution/ScanOrder/index.js +449 -182
  143. package/lib/solution/ScanOrder/types.d.ts +21 -1
  144. package/lib/solution/ScanOrder/utils.d.ts +8 -0
  145. package/lib/solution/ScanOrder/utils.js +31 -0
  146. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  147. package/lib/solution/ShopDiscount/index.js +14 -0
  148. package/lib/solution/UnifiedBookingSales/index.d.ts +183 -0
  149. package/lib/solution/UnifiedBookingSales/index.js +1076 -0
  150. package/lib/solution/UnifiedBookingSales/types.d.ts +143 -0
  151. package/lib/solution/UnifiedBookingSales/types.js +33 -0
  152. package/lib/solution/VenueBooking/index.d.ts +39 -11
  153. package/lib/solution/VenueBooking/index.js +328 -115
  154. package/lib/solution/VenueBooking/types.d.ts +3 -0
  155. package/lib/solution/VenueBooking/utils/resource.js +1 -0
  156. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  157. package/lib/solution/VenueBooking/utils/slotMerge.js +6 -4
  158. package/lib/solution/index.d.ts +1 -0
  159. package/lib/solution/index.js +3 -1
  160. package/lib/types/index.d.ts +1 -0
  161. package/package.json +2 -2
  162. package/dist/modules/Order/payment-utils.d.ts +0 -26
  163. package/dist/modules/Order/payment-utils.js +0 -225
  164. package/dist/utils/payment-number.d.ts +0 -9
  165. package/dist/utils/payment-number.js +0 -69
  166. package/lib/modules/Order/payment-utils.d.ts +0 -26
  167. package/lib/modules/Order/payment-utils.js +0 -224
  168. package/lib/utils/payment-number.d.ts +0 -9
  169. package/lib/utils/payment-number.js +0 -64
@@ -37,8 +37,6 @@ var import_types = require("./types");
37
37
  var import_utils = require("./utils");
38
38
  var import_utils2 = require("../Product/utils");
39
39
  var import_dayjs = __toESM(require("dayjs"));
40
- var import_payment_utils = require("./payment-utils");
41
- var import_payment_number = require("../../utils/payment-number");
42
40
  var import_cartPromotion = require("../../solution/BaseSales/utils/cartPromotion");
43
41
  var import_utils3 = require("../../solution/ScanOrder/utils");
44
42
  var import_manualProductDiscount = require("./utils/manualProductDiscount");
@@ -302,7 +300,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
302
300
  });
303
301
  }
304
302
  async initialize(core, options) {
305
- var _a, _b, _c;
303
+ var _a, _b, _c, _d;
306
304
  this.core = core;
307
305
  this.store = options.store;
308
306
  if (!this.store.tempOrder) {
@@ -315,19 +313,19 @@ var OrderModule = class extends import_BaseModule.BaseModule {
315
313
  this.store.availableWalletIds = [];
316
314
  }
317
315
  this.request = this.core.getPlugin("request");
318
- this.appPlugin = this.core.getPlugin("app");
319
- if (!this.appPlugin) {
320
- throw new Error("Order 模块需要 app 插件支持");
316
+ const appPlugin = this.core.getPlugin("app");
317
+ if (!appPlugin) {
318
+ console.error("Order 模块需要 app 插件支持");
321
319
  }
322
- const app = this.appPlugin.getApp();
323
- this.logger = app.logger;
320
+ const app = (_a = appPlugin == null ? void 0 : appPlugin.getApp) == null ? void 0 : _a.call(appPlugin);
321
+ this.logger = app == null ? void 0 : app.logger;
324
322
  this.window = this.core.getPlugin("window");
325
323
  const otherParams = options.otherParams || {};
326
324
  this.cacheId = otherParams.cacheId;
327
325
  this.salesSummaryModuleName = otherParams.salesSummaryModuleName;
328
- this.rulesHooksOverride = (_a = otherParams.rules) == null ? void 0 : _a.hooks;
326
+ this.rulesHooksOverride = (_b = otherParams.rules) == null ? void 0 : _b.hooks;
329
327
  this.moduleHooksOverride = options.hooks;
330
- this.orderHooks = this.moduleHooksOverride || ((_b = otherParams.order) == null ? void 0 : _b.hooks) || ((_c = otherParams.hooks) == null ? void 0 : _c.order);
328
+ this.orderHooks = this.moduleHooksOverride || ((_c = otherParams.order) == null ? void 0 : _c.hooks) || ((_d = otherParams.hooks) == null ? void 0 : _d.order);
331
329
  this.otherParams = otherParams;
332
330
  this.registerDiscountModules(options);
333
331
  this.logInfo("OrderModule initialized successfully");
@@ -836,6 +834,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
836
834
  /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化;草稿保存请使用 IndexedDB saveDraft。 */
837
835
  persistTempOrder() {
838
836
  }
837
+ notifyTempOrderChanged() {
838
+ if (!this.store.tempOrder)
839
+ return;
840
+ this.store.tempOrder = {
841
+ ...this.store.tempOrder,
842
+ products: [...this.store.tempOrder.products],
843
+ bookings: this.store.tempOrder.bookings ? [...this.store.tempOrder.bookings] : []
844
+ };
845
+ this.persistTempOrder();
846
+ }
839
847
  // ─── TempOrder: 创建 & 获取 ───
840
848
  createDefaultTempOrderInstance() {
841
849
  return (0, import_utils.createDefaultTempOrder)({
@@ -1055,40 +1063,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1055
1063
  const depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1056
1064
  return depositPaidAmount.lt(depositAmount) ? "deposit" : "normal";
1057
1065
  }
1058
- getPaymentNumberAppData(key) {
1059
- var _a, _b, _c, _d, _e;
1060
- const appPlugin = this.appPlugin;
1061
- if (!appPlugin)
1062
- return void 0;
1063
- const getData = (_a = appPlugin.getData) == null ? void 0 : _a.call(appPlugin);
1064
- if (typeof getData === "function")
1065
- return getData(key);
1066
- const app = appPlugin.getApp();
1067
- const coreData = (_e = (_c = (_b = app == null ? void 0 : app.models) == null ? void 0 : _b.getStore) == null ? void 0 : (_d = _c.call(_b)).getDataByModel) == null ? void 0 : _e.call(_d, "core", "core");
1068
- return coreData == null ? void 0 : coreData[key];
1069
- }
1070
- getPaymentNumberDevicePrefixSync() {
1071
- return (0, import_payment_number.resolvePaymentNumberDevicePrefixFromDeviceId)(
1072
- (key) => this.getPaymentNumberAppData(key)
1073
- );
1074
- }
1075
- getPaymentNumberDevicePrefixAsync() {
1076
- return (0, import_payment_number.resolvePaymentNumberDevicePrefix)(
1077
- (key) => this.getPaymentNumberAppData(key)
1078
- );
1079
- }
1080
1066
  normalizePaymentSource(payment, options) {
1081
1067
  const paymentRecord = payment;
1082
1068
  const metadata = paymentRecord.metadata && typeof paymentRecord.metadata === "object" ? { ...paymentRecord.metadata } : {};
1083
- const normalized = (0, import_payment_utils.ensureOrderPaymentNumber)(
1084
- {
1085
- ...paymentRecord,
1086
- metadata,
1087
- origin_amount: paymentRecord.origin_amount ?? paymentRecord.amount ?? "0.00"
1088
- },
1089
- (options == null ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(),
1090
- import_utils.createUuidV4
1091
- );
1069
+ if (!metadata.unique_payment_number) {
1070
+ metadata.unique_payment_number = (0, import_utils.createUuidV4)();
1071
+ }
1072
+ const normalized = {
1073
+ ...paymentRecord,
1074
+ metadata,
1075
+ origin_amount: paymentRecord.origin_amount ?? paymentRecord.amount ?? "0.00"
1076
+ };
1092
1077
  if (paymentRecord.status !== void 0) {
1093
1078
  normalized.status = paymentRecord.status;
1094
1079
  } else if ((options == null ? void 0 : options.defaultPaid) !== false) {
@@ -2509,36 +2494,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2509
2494
  * 用一组支付来源覆盖当前订单支付项。
2510
2495
  *
2511
2496
  * 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
2512
- * 新支付来源的 uuid 会作为 payment_number 的唯一号段,id -> custom_payment_id,
2497
+ * uuid -> metadata.unique_payment_number,id -> custom_payment_id,
2513
2498
  * isSynced 等运行态字段不会进入 tempOrder.payments。
2514
2499
  */
2515
2500
  setOrderPayments(payments) {
2516
2501
  const tempOrder = this.ensureTempOrder();
2517
- tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(
2518
- (payments || []).map((payment) => this.normalizePaymentSource(payment, { defaultPaid: false }))
2519
- );
2502
+ tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(payments);
2520
2503
  this.persistTempOrder();
2521
2504
  return tempOrder.payments;
2522
2505
  }
2523
- /** 同步兼容入口:按调用当下的 device_id 或 LOCAL 生成支付编号。 */
2506
+ /** 追加单个支付项,并立即持久化当前 tempOrder。 */
2524
2507
  addOrderPayment(payment) {
2525
- const hasPaymentNumber = String(
2526
- payment.payment_number || ""
2527
- ).trim() !== "";
2528
- return this.addOrderPaymentWithDevicePrefix(
2529
- payment,
2530
- hasPaymentNumber ? "LOCAL" : this.getPaymentNumberDevicePrefixSync()
2531
- );
2532
- }
2533
- /** 异步入口:创建支付项时读取最新 IoT 设备短号。 */
2534
- async addOrderPaymentAsync(payment) {
2535
- const hasPaymentNumber = String(
2536
- payment.payment_number || ""
2537
- ).trim() !== "";
2538
- const devicePrefix = hasPaymentNumber ? "LOCAL" : await this.getPaymentNumberDevicePrefixAsync();
2539
- return this.addOrderPaymentWithDevicePrefix(payment, devicePrefix);
2540
- }
2541
- addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
2542
2508
  this.logInfo("addOrderPayment", {
2543
2509
  payment
2544
2510
  });
@@ -2551,7 +2517,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2551
2517
  type: orderPaymentType,
2552
2518
  order_payment_type: orderPaymentType
2553
2519
  },
2554
- { defaultPaid: true, devicePrefix }
2520
+ { defaultPaid: true }
2555
2521
  )
2556
2522
  ]);
2557
2523
  tempOrder.payments = [...tempOrder.payments || [], ...mapped];
@@ -2564,55 +2530,57 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2564
2530
  return tempOrder.payments;
2565
2531
  }
2566
2532
  /**
2567
- * 默认按支付唯一号精确更新;仅显式指定 legacy 时兼容历史支付标识。
2568
- * metadata 与 transactions 会分别合并,避免覆盖支付会话号和已有交易记录。
2533
+ * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
2534
+ *
2535
+ * 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
2536
+ * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
2569
2537
  */
2570
- async updateOrderPayment(paymentIdentity, updates, options = {}) {
2538
+ updateOrderPayment(paymentIdentity, updates) {
2571
2539
  const tempOrder = this.ensureTempOrder();
2572
2540
  const identity = String(paymentIdentity);
2573
- const matchMode = options.matchBy === "compat" || options.matchBy === "legacy" ? "compat" : "payment_number";
2574
- const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2575
- tempOrder.payments || [],
2576
- identity,
2577
- matchMode
2578
- );
2579
- if (!matchedPayment) {
2580
- throw new Error(`未找到支付项: ${identity}`);
2581
- }
2582
- let updatedPayment = null;
2583
- tempOrder.payments = (tempOrder.payments || []).map((payment, index) => {
2584
- if (index !== matchedPayment.index)
2541
+ tempOrder.payments = (tempOrder.payments || []).map((payment) => {
2542
+ var _a;
2543
+ const uniquePaymentNumber = (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
2544
+ const orderPaymentId = payment == null ? void 0 : payment.order_payment_id;
2545
+ const customPaymentId = payment == null ? void 0 : payment.custom_payment_id;
2546
+ const uuid = payment == null ? void 0 : payment.uuid;
2547
+ const matched = [
2548
+ uniquePaymentNumber,
2549
+ orderPaymentId,
2550
+ customPaymentId,
2551
+ uuid
2552
+ ].some((value) => value !== void 0 && String(value) === identity);
2553
+ if (!matched)
2585
2554
  return payment;
2586
- const nextPayment = (0, import_payment_utils.mergeOrderPaymentRecord)(payment, {
2555
+ return {
2556
+ ...payment,
2587
2557
  ...updates,
2588
- updated_at: updates.updated_at || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
2589
- });
2590
- updatedPayment = nextPayment;
2591
- return nextPayment;
2558
+ metadata: {
2559
+ ...payment.metadata || {},
2560
+ ...updates.metadata || {}
2561
+ }
2562
+ };
2592
2563
  });
2593
2564
  this.persistTempOrder();
2594
- const summary = await this.recalculateSummary({ createIfMissing: true });
2595
- this.persistTempOrder();
2596
- const payments = tempOrder.payments;
2597
- return {
2598
- updated: true,
2599
- payment: payments[matchedPayment.index] || updatedPayment,
2600
- payments,
2601
- summary
2602
- };
2565
+ return tempOrder.payments;
2603
2566
  }
2604
2567
  /** 从当前订单支付项中移除指定支付项。 */
2605
2568
  deleteOrderPayment(paymentIdentity) {
2606
2569
  const tempOrder = this.ensureTempOrder();
2607
2570
  const identity = String(paymentIdentity);
2608
- const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2609
- tempOrder.payments || [],
2610
- identity,
2611
- "compat"
2612
- );
2613
- if (!matchedPayment)
2614
- return tempOrder.payments;
2615
- tempOrder.payments = (tempOrder.payments || []).filter((_, index) => index !== matchedPayment.index);
2571
+ tempOrder.payments = (tempOrder.payments || []).filter((payment) => {
2572
+ var _a;
2573
+ const uniquePaymentNumber = (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
2574
+ const orderPaymentId = payment == null ? void 0 : payment.order_payment_id;
2575
+ const customPaymentId = payment == null ? void 0 : payment.custom_payment_id;
2576
+ const uuid = payment == null ? void 0 : payment.uuid;
2577
+ return ![
2578
+ uniquePaymentNumber,
2579
+ orderPaymentId,
2580
+ customPaymentId,
2581
+ uuid
2582
+ ].some((value) => value !== void 0 && String(value) === identity);
2583
+ });
2616
2584
  this.persistTempOrder();
2617
2585
  return tempOrder.payments;
2618
2586
  }
@@ -2721,10 +2689,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2721
2689
  payments.map(
2722
2690
  (payment) => this.normalizePaymentSource(
2723
2691
  normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)),
2724
- {
2725
- defaultPaid: false,
2726
- devicePrefix: options == null ? void 0 : options.devicePrefix
2727
- }
2692
+ { defaultPaid: false }
2728
2693
  )
2729
2694
  )
2730
2695
  ).filter((payment) => {
@@ -2775,14 +2740,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2775
2740
  });
2776
2741
  return tempOrder.payments;
2777
2742
  }
2778
- async updateVoucherOrderPaymentsAsync(payments, options) {
2779
- const needsPaymentNumber = (payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
2780
- const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
2781
- return this.updateVoucherOrderPayments(payments, {
2782
- ...options,
2783
- devicePrefix
2784
- });
2785
- }
2786
2743
  async shouldMergeProductToOrder(params) {
2787
2744
  var _a;
2788
2745
  const onBeforeMergeProductToOrder = (_a = this.orderHooks) == null ? void 0 : _a.onBeforeMergeProductToOrder;
@@ -3613,38 +3570,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3613
3570
  await this.saveDraft();
3614
3571
  return tempOrder;
3615
3572
  }
3616
- async saveTempOrderAsDraft(params) {
3617
- var _a, _b, _c, _d, _e;
3618
- const tempOrder = this.ensureTempOrder();
3619
- this.ensureExternalSaleNumber(tempOrder);
3620
- this.persistTempOrder();
3621
- const latestSummary = await this.recalculateSummary({ createIfMissing: true }) || this.store.summary || (0, import_utils.createEmptySummary)();
3622
- const payload = (0, import_utils.buildSubmitPayload)({
3623
- tempOrder,
3624
- cacheId: (params == null ? void 0 : params.cacheId) ?? this.cacheId,
3625
- platform: (params == null ? void 0 : params.platform) || ((_a = this.otherParams) == null ? void 0 : _a.platform),
3626
- businessCode: (params == null ? void 0 : params.businessCode) ?? ((_b = this.otherParams) == null ? void 0 : _b.businessCode) ?? ((_c = this.otherParams) == null ? void 0 : _c.business_code),
3627
- channel: params == null ? void 0 : params.channel,
3628
- type: (params == null ? void 0 : params.type) ?? ((_d = this.otherParams) == null ? void 0 : _d.type),
3629
- summary: latestSummary,
3630
- enhance: params == null ? void 0 : params.enhancePayload
3631
- });
3632
- if (!payload.created_at) {
3633
- payload.created_at = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
3634
- }
3635
- payload.need_sync = 0;
3636
- payload.is_draft_order = 1;
3637
- this.logInfo("saveTempOrderAsDraft calling sales draft", {
3638
- orderId: payload.order_id,
3639
- externalSaleNumber: payload.external_sale_number,
3640
- productsCount: ((_e = payload.products) == null ? void 0 : _e.length) || 0
3641
- });
3642
- return this.request.post("/order/sales/draft", payload, {
3643
- osServer: true,
3644
- customToast: () => {
3645
- }
3646
- });
3647
- }
3648
3573
  /**
3649
3574
  * 提交当前 Sales tempOrder。
3650
3575
  *
@@ -3845,13 +3770,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3845
3770
  }
3846
3771
  async syncPaymentsToOrder(params) {
3847
3772
  const tempOrder = this.ensureTempOrder();
3848
- const needsPaymentNumber = (params.payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
3849
- const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
3850
3773
  const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
3851
- (params.payments || []).map((payment) => this.normalizePaymentSource(payment, {
3852
- defaultPaid: false,
3853
- devicePrefix
3854
- }))
3774
+ params.payments || []
3855
3775
  );
3856
3776
  const shouldConfirmPendingVoucherPayments = params.confirmPendingVoucherPayments ?? params.submitWhenPaid === true;
3857
3777
  const effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
@@ -3873,7 +3793,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3873
3793
  tempOrder,
3874
3794
  effectivePayments
3875
3795
  );
3876
- const submitResult = await this.submitTempOrder({
3796
+ const submitParams = {
3877
3797
  payments: effectivePayments,
3878
3798
  paymentStatus,
3879
3799
  smallTicketDataFlag: params.smallTicketDataFlag,
@@ -3887,7 +3807,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3887
3807
  };
3888
3808
  return nextPayload;
3889
3809
  }
3890
- });
3810
+ };
3811
+ const submitResult = params.checkoutSyncTaskEnabled === false ? await this.submitTempOrderAsync(submitParams) : await this.submitTempOrder(submitParams);
3891
3812
  return { ...completion, submitResult };
3892
3813
  }
3893
3814
  createOrder(params) {
@@ -3904,11 +3825,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3904
3825
  is_deposit: 0,
3905
3826
  relation_products: [],
3906
3827
  relation_forms: [],
3828
+ business_code: params == null ? void 0 : params.business_code,
3907
3829
  ...(params == null ? void 0 : params.extraData) || {}
3908
3830
  };
3909
3831
  let is_deposit = 0;
3910
3832
  if (params.cartItems.length > 0) {
3911
3833
  params.cartItems.forEach((item) => {
3834
+ var _a2;
3912
3835
  if (!item._origin.duration) {
3913
3836
  const { duration, durationType } = (0, import_utils.generateDuration)(item);
3914
3837
  item._origin.duration = duration;
@@ -3917,6 +3840,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3917
3840
  item._origin.sub_type = (0, import_utils.normalizeBookingSubType)(item._origin);
3918
3841
  const discountList = (0, import_utils.getAllDiscountList)(item);
3919
3842
  item._origin.product.discount_list = discountList;
3843
+ if ((_a2 = params == null ? void 0 : params.extraData) == null ? void 0 : _a2.is_add_holder_info) {
3844
+ (0, import_utils.ensureCartItemOriginHolder)(item, this.window);
3845
+ }
3920
3846
  if ((0, import_utils2.isNormalProduct)(item._origin)) {
3921
3847
  order.relation_products.push(item._origin.product);
3922
3848
  const relationForms = item._origin.relation_forms || [];
@@ -4227,12 +4153,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4227
4153
  }
4228
4154
  }
4229
4155
  const nextTempOrder = this.normalizeTempOrderForRuntime(raw, { makeEditMark: true });
4230
- const sourceLastOrderInfo = raw.lastOrderInfo || raw;
4231
- const isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
4232
- const syntheticIdentityOptions = {
4233
- isDraftOrder,
4234
- externalSaleNumber: nextTempOrder.external_sale_number
4235
- };
4236
4156
  const rawSummary = raw.summary && typeof raw.summary === "object" ? raw.summary : {};
4237
4157
  const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map((s) => ({ ...s || {} })) : (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []);
4238
4158
  this.store.tempOrder = nextTempOrder;
@@ -4253,14 +4173,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4253
4173
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
4254
4174
  }
4255
4175
  };
4256
- this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(
4257
- sourceLastOrderInfo,
4258
- syntheticIdentityOptions
4259
- );
4260
- const hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
4261
- if (hadSyntheticDraftOrderId && this.store.syncState !== "submitting") {
4262
- this.store.syncState = "local";
4263
- }
4176
+ this.store.lastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
4264
4177
  const hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
4265
4178
  const currentDiscounts = typeof ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
4266
4179
  const currentScanDiscounts = currentDiscounts.filter((discount) => discount == null ? void 0 : discount.isScan);
@@ -4373,13 +4286,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4373
4286
  }
4374
4287
  normalizeTempOrderForRuntime(raw, options) {
4375
4288
  var _a, _b;
4376
- const runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
4377
4289
  const nextTempOrder = {
4378
4290
  ...this.createDefaultTempOrderInstance(),
4379
- ...runtimeRaw || {}
4291
+ ...raw || {}
4380
4292
  };
4381
- if ((nextTempOrder.order_id === void 0 || nextTempOrder.order_id === null) && (runtimeRaw == null ? void 0 : runtimeRaw.id) !== void 0 && (runtimeRaw == null ? void 0 : runtimeRaw.id) !== null) {
4382
- nextTempOrder.order_id = runtimeRaw.id;
4293
+ if ((nextTempOrder.order_id === void 0 || nextTempOrder.order_id === null) && (raw == null ? void 0 : raw.id) !== void 0 && (raw == null ? void 0 : raw.id) !== null) {
4294
+ nextTempOrder.order_id = raw.id;
4383
4295
  }
4384
4296
  delete nextTempOrder.summary;
4385
4297
  delete nextTempOrder.lastOrderInfo;
@@ -4447,22 +4359,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4447
4359
  nextTempOrder.vouchers = raw.vouchers || [];
4448
4360
  return nextTempOrder;
4449
4361
  }
4450
- isSyntheticDraftOrderIdForRuntime(record, options) {
4451
- const isDraftOrder = (options == null ? void 0 : options.isDraftOrder) ?? Number((record == null ? void 0 : record.is_draft_order) || 0) === 1;
4452
- const externalSaleNumber = (record == null ? void 0 : record.external_sale_number) ?? (options == null ? void 0 : options.externalSaleNumber);
4453
- const orderId = record == null ? void 0 : record.order_id;
4454
- return Boolean(
4455
- isDraftOrder && orderId !== void 0 && orderId !== null && orderId !== "" && externalSaleNumber !== void 0 && externalSaleNumber !== null && externalSaleNumber !== "" && String(orderId) === String(externalSaleNumber)
4456
- );
4457
- }
4458
- withoutSyntheticDraftOrderIdForRuntime(record, options) {
4459
- if (!this.isSyntheticDraftOrderIdForRuntime(record, options))
4460
- return record;
4461
- return {
4462
- ...record,
4463
- order_id: null
4464
- };
4465
- }
4466
4362
  hydrateLinkedBookingIdentity(tempOrder) {
4467
4363
  const bookingUidByProductUid = /* @__PURE__ */ new Map();
4468
4364
  const productByUid = /* @__PURE__ */ new Map();
@@ -394,6 +394,7 @@ export interface CommitOrderParams {
394
394
  type: 'virtual' | 'appointment_booking';
395
395
  platform?: string;
396
396
  extraData?: Record<string, any>;
397
+ business_code?: string;
397
398
  };
398
399
  }
399
400
  export interface OrderSubmitBooking {
@@ -468,8 +469,6 @@ export interface SubmitSalesOrderParams {
468
469
  export interface PaymentItemData {
469
470
  /** 当前支付项的唯一 ID */
470
471
  uuid: string;
471
- /** 支付项稳定唯一号 */
472
- payment_number?: string;
473
472
  /** 当前支付方式付出去多少钱 */
474
473
  amount: string;
475
474
  /** 支付类型代码 */
@@ -492,22 +491,13 @@ export interface PaymentItemData {
492
491
  export interface OrderPaymentMetadata {
493
492
  rounding_rule?: Record<string, any>;
494
493
  unique_payment_number?: string;
495
- /** 刷卡机设备快照;OS 不解析内部字段,仅透传并持久化 */
496
- card_reader_snapshot?: Record<string, unknown>;
497
494
  shop_wallet_pass_id?: number | string;
498
495
  actual_paid_amount?: number | string;
499
496
  change_given_amount?: number | string;
500
- transactions?: OrderPaymentTransaction[];
501
497
  [key: string]: any;
502
498
  }
503
- export interface OrderPaymentTransaction {
504
- number: string;
505
- status: 'success' | 'fail';
506
- }
507
499
  export interface OrderPaymentData {
508
500
  order_payment_id?: number | string;
509
- /** 支付项稳定唯一号;历史支付项允许缺失 */
510
- payment_number?: string;
511
501
  amount: string;
512
502
  code: string;
513
503
  custom_payment_id: number;
@@ -534,15 +524,6 @@ export interface OrderPaymentData {
534
524
  created_at?: string;
535
525
  updated_at?: string;
536
526
  }
537
- export interface OrderPaymentUpdateOptions {
538
- matchBy?: 'payment_number' | 'compat' | 'legacy';
539
- }
540
- export interface OrderPaymentUpdateResult {
541
- updated: boolean;
542
- payment: OrderPaymentData | null;
543
- payments: OrderPaymentData[];
544
- summary: OrderSummary | null;
545
- }
546
527
  export type OrderPaymentSource = PaymentItem | OrderPaymentData | Record<string, any>;
547
528
  export interface MapOrderPaymentsOptions {
548
529
  includeVoided?: boolean;
@@ -569,6 +550,12 @@ export interface SyncPaymentsToOrderParams {
569
550
  payments: OrderPaymentSource[];
570
551
  paymentStatus?: SubmitSalesOrderParams['query']['payment_status'];
571
552
  submitWhenPaid?: boolean;
553
+ /**
554
+ * Whether the checkout should be queued as the local `sync_sales` task.
555
+ * Defaults to true to preserve the WebPOS retry path. Set to false when
556
+ * the caller must wait for the cloud checkout response before proceeding.
557
+ */
558
+ checkoutSyncTaskEnabled?: boolean;
572
559
  smallTicketDataFlag?: number;
573
560
  businessCode?: string;
574
561
  channel?: string;
@@ -693,14 +680,6 @@ export interface OrderModuleAPI {
693
680
  channel?: string;
694
681
  type?: string;
695
682
  }) => OrderSubmitPayload;
696
- saveTempOrderAsDraft: <T = any>(params?: {
697
- cacheId?: string;
698
- platform?: string;
699
- businessCode?: string;
700
- channel?: string;
701
- type?: string;
702
- enhancePayload?: SubmitPayloadEnhancer;
703
- }) => Promise<T>;
704
683
  applyLocalPrintOrderNumbers: (order?: Record<string, any> | null) => Promise<OrderTempOrder>;
705
684
  getTempOrderNote: () => string;
706
685
  updateTempOrderNote: {
@@ -731,6 +710,8 @@ export interface OrderModuleAPI {
731
710
  setEnableTempOrderPersist: (enabled: boolean) => void;
732
711
  /** 是否允许 saveDraft 写入 IndexedDB 草稿。 */
733
712
  isTempOrderPersistEnabled: () => boolean;
713
+ /** 提交 tempOrder 变更并触发 `{moduleName}:changed` 事件 */
714
+ notifyTempOrderChanged: () => void;
734
715
  submitTempOrder: <T = any>(params?: {
735
716
  cacheId?: string;
736
717
  platform?: string;
@@ -758,15 +739,11 @@ export interface OrderModuleAPI {
758
739
  getOrderPayments: () => OrderPaymentData[];
759
740
  setOrderPayments: (payments: OrderPaymentSource[]) => OrderPaymentData[];
760
741
  addOrderPayment: (payment: OrderPaymentSource) => OrderPaymentData[];
761
- addOrderPaymentAsync: (payment: OrderPaymentSource) => Promise<OrderPaymentData[]>;
762
- updateOrderPayment: (paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any>, options?: OrderPaymentUpdateOptions) => Promise<OrderPaymentUpdateResult>;
742
+ updateOrderPayment: (paymentIdentity: string | number, updates: Partial<OrderPaymentData> & Record<string, any>) => OrderPaymentData[];
763
743
  deleteOrderPayment: (paymentIdentity: string | number) => OrderPaymentData[];
764
744
  updateVoucherOrderPayments: (payments: OrderPaymentSource[], options?: {
765
745
  status?: 'paid' | 'payment_pending';
766
746
  }) => OrderPaymentData[];
767
- updateVoucherOrderPaymentsAsync: (payments: OrderPaymentSource[], options?: {
768
- status?: 'paid' | 'payment_pending';
769
- }) => Promise<OrderPaymentData[]>;
770
747
  confirmPendingVoucherPayments: (options?: {
771
748
  persist?: boolean;
772
749
  recalculateSummary?: boolean;
@@ -220,9 +220,6 @@ function normalizeOrderCollection(kind, items, options) {
220
220
  const persistentId = getOrderCollectionPersistentId(kind, item);
221
221
  let uid = getOrderCollectionUid(kind, item);
222
222
  if (!uid) {
223
- if (kind === "payment" && !isBlankOrderCollectionIdentity(item == null ? void 0 : item.payment_number)) {
224
- continue;
225
- }
226
223
  uid = persistentId ? buildOrderCollectionFallbackUid(kind, persistentId) : allocateAnonymousUid(occupiedUids, createAnonymousUid);
227
224
  item = setOrderCollectionUid(kind, item, uid);
228
225
  result[index] = item;
@@ -15,6 +15,7 @@ export interface OrderProductsDepositSummary {
15
15
  deposit_policy_ids: number[];
16
16
  hasDeposit: boolean;
17
17
  }
18
+ import type { WindowPlugin } from '../../plugins';
18
19
  /**
19
20
  * 把"含 option 的主商品单价"与 bundle 合成"单行 composite 单价"。
20
21
  *
@@ -177,6 +178,15 @@ export declare const mergeRelationForms: (relationForms: {
177
178
  form_id: number;
178
179
  form_record_ids: number[];
179
180
  }[];
181
+ export interface CartOrderHolder {
182
+ customer_id?: number;
183
+ form_id: number | string;
184
+ form_record: (number | string)[] | null;
185
+ }
186
+ /**
187
+ * 为购物车行补齐订单所需的 holder 信息(与 cartAccount 结构保持一致)
188
+ */
189
+ export declare function ensureCartItemOriginHolder(cartItem: CartItem, window?: WindowPlugin): void;
180
190
  export declare const getAllDiscountList: (cartItem: CartItem) => any;
181
191
  export { createUuidV4 };
182
192
  export declare function isTempOrder(data: any): data is OrderTempOrder;