@pisell/pisellos 2.3.39 → 2.3.41

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 (226) hide show
  1. package/dist/core/index.d.ts +2 -0
  2. package/dist/core/index.js +7 -0
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  4. package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
  8. package/dist/model/strategy/adapter/promotion/examples.js +99 -0
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
  12. package/dist/model/strategy/adapter/promotion/type.js +45 -0
  13. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -3
  14. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -3
  15. package/dist/modules/Discount/index.d.ts +0 -1
  16. package/dist/modules/Discount/index.js +11 -40
  17. package/dist/modules/Discount/types.d.ts +0 -1
  18. package/dist/modules/OpenData/index.d.ts +2 -0
  19. package/dist/modules/OpenData/index.js +10 -2
  20. package/dist/modules/Order/index.d.ts +29 -12
  21. package/dist/modules/Order/index.js +750 -509
  22. package/dist/modules/Order/payment-utils.d.ts +26 -0
  23. package/dist/modules/Order/payment-utils.js +225 -0
  24. package/dist/modules/Order/types.d.ts +33 -10
  25. package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
  26. package/dist/modules/Order/utils.d.ts +0 -10
  27. package/dist/modules/Order/utils.js +13 -41
  28. package/dist/modules/Payment/index.d.ts +2 -0
  29. package/dist/modules/Payment/index.js +79 -50
  30. package/dist/modules/Payment/types.d.ts +99 -28
  31. package/dist/modules/Payment/types.js +20 -3
  32. package/dist/modules/Payment/walletpass.d.ts +25 -1
  33. package/dist/modules/Payment/walletpass.js +707 -157
  34. package/dist/modules/Product/types.d.ts +0 -1
  35. package/dist/modules/ProductList/index.js +14 -33
  36. package/dist/modules/Quotation/index.d.ts +1 -1
  37. package/dist/modules/Quotation/index.js +2 -2
  38. package/dist/modules/Rules/index.d.ts +1 -0
  39. package/dist/modules/Rules/index.js +89 -96
  40. package/dist/modules/SalesSummary/index.js +13 -12
  41. package/dist/modules/ScanOrderLogger/index.d.ts +0 -2
  42. package/dist/modules/ScanOrderLogger/index.js +2 -15
  43. package/dist/modules/ScanOrderLogger/providers/feishu.js +27 -45
  44. package/dist/modules/ScanOrderLogger/types.d.ts +0 -1
  45. package/dist/modules/Schedule/index.d.ts +1 -3
  46. package/dist/modules/Schedule/index.js +16 -21
  47. package/dist/modules/Summary/utils.js +13 -38
  48. package/dist/modules/index.d.ts +0 -2
  49. package/dist/modules/index.js +1 -3
  50. package/dist/plugins/window.d.ts +0 -1
  51. package/dist/server/index.d.ts +16 -14
  52. package/dist/server/index.js +1925 -1143
  53. package/dist/server/modules/order/index.d.ts +54 -4
  54. package/dist/server/modules/order/index.js +1600 -700
  55. package/dist/server/modules/order/types.d.ts +11 -3
  56. package/dist/server/modules/order/types.js +1 -1
  57. package/dist/solution/BaseSales/index.d.ts +109 -20
  58. package/dist/solution/BaseSales/index.js +1800 -480
  59. package/dist/solution/BaseSales/types.d.ts +52 -0
  60. package/dist/solution/BaseSales/types.js +2 -1
  61. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  62. package/dist/solution/BaseSales/utils/cartPromotion.js +90 -31
  63. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  64. package/dist/solution/BookingByStep/index.d.ts +2 -17
  65. package/dist/solution/BookingByStep/index.js +215 -294
  66. package/dist/solution/BookingByStep/types.d.ts +1 -2
  67. package/dist/solution/BookingByStep/types.js +1 -3
  68. package/dist/solution/BookingByStep/utils/capacity.js +1 -17
  69. package/dist/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  70. package/dist/solution/BookingByStep/utils/timeslots.js +12 -19
  71. package/dist/solution/BookingTicket/index.d.ts +7 -3
  72. package/dist/solution/BookingTicket/index.js +132 -49
  73. package/dist/solution/BookingTicket/utils/addProductDecision.js +6 -0
  74. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  75. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +172 -82
  76. package/dist/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  77. package/dist/solution/BookingTicket/utils/weighingProductSku.js +45 -0
  78. package/dist/solution/Sales/index.d.ts +1 -0
  79. package/dist/solution/Sales/index.js +10 -2
  80. package/dist/solution/ScanOrder/index.d.ts +14 -26
  81. package/dist/solution/ScanOrder/index.js +756 -1148
  82. package/dist/solution/ScanOrder/types.d.ts +1 -21
  83. package/dist/solution/ScanOrder/utils.d.ts +0 -8
  84. package/dist/solution/ScanOrder/utils.js +25 -66
  85. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  86. package/dist/solution/ShopDiscount/index.js +87 -125
  87. package/dist/solution/VenueBooking/index.d.ts +11 -39
  88. package/dist/solution/VenueBooking/index.js +860 -1176
  89. package/dist/solution/VenueBooking/types.d.ts +0 -3
  90. package/dist/solution/VenueBooking/utils/resource.js +0 -1
  91. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  92. package/dist/solution/VenueBooking/utils/slotMerge.js +5 -10
  93. package/dist/solution/index.d.ts +0 -1
  94. package/dist/solution/index.js +1 -2
  95. package/dist/types/index.d.ts +1 -1
  96. package/dist/utils/payment-number.d.ts +9 -0
  97. package/dist/utils/payment-number.js +69 -0
  98. package/lib/core/index.d.ts +2 -0
  99. package/lib/core/index.js +4 -0
  100. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  101. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  102. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  103. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  104. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  105. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  106. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  107. package/lib/model/strategy/adapter/promotion/index.js +51 -0
  108. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  109. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  110. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
  111. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  112. package/lib/modules/Discount/index.d.ts +0 -1
  113. package/lib/modules/Discount/index.js +0 -9
  114. package/lib/modules/Discount/types.d.ts +0 -1
  115. package/lib/modules/OpenData/index.d.ts +2 -0
  116. package/lib/modules/OpenData/index.js +6 -1
  117. package/lib/modules/Order/index.d.ts +29 -12
  118. package/lib/modules/Order/index.js +196 -86
  119. package/lib/modules/Order/payment-utils.d.ts +26 -0
  120. package/lib/modules/Order/payment-utils.js +224 -0
  121. package/lib/modules/Order/types.d.ts +33 -10
  122. package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
  123. package/lib/modules/Order/utils.d.ts +0 -10
  124. package/lib/modules/Order/utils.js +16 -40
  125. package/lib/modules/Payment/index.d.ts +2 -0
  126. package/lib/modules/Payment/index.js +34 -13
  127. package/lib/modules/Payment/types.d.ts +99 -28
  128. package/lib/modules/Payment/types.js +4 -3
  129. package/lib/modules/Payment/walletpass.d.ts +25 -1
  130. package/lib/modules/Payment/walletpass.js +470 -21
  131. package/lib/modules/Product/types.d.ts +0 -1
  132. package/lib/modules/ProductList/index.js +31 -40
  133. package/lib/modules/Quotation/index.d.ts +1 -1
  134. package/lib/modules/Quotation/index.js +2 -2
  135. package/lib/modules/Rules/index.d.ts +1 -0
  136. package/lib/modules/Rules/index.js +47 -40
  137. package/lib/modules/SalesSummary/index.js +7 -6
  138. package/lib/modules/ScanOrderLogger/index.d.ts +0 -2
  139. package/lib/modules/ScanOrderLogger/index.js +1 -13
  140. package/lib/modules/ScanOrderLogger/providers/feishu.js +6 -15
  141. package/lib/modules/ScanOrderLogger/types.d.ts +0 -1
  142. package/lib/modules/Schedule/index.d.ts +1 -3
  143. package/lib/modules/Schedule/index.js +8 -10
  144. package/lib/modules/Summary/utils.js +1 -21
  145. package/lib/modules/index.d.ts +0 -2
  146. package/lib/modules/index.js +1 -5
  147. package/lib/plugins/window.d.ts +0 -1
  148. package/lib/server/index.d.ts +16 -14
  149. package/lib/server/index.js +675 -83
  150. package/lib/server/modules/order/index.d.ts +54 -4
  151. package/lib/server/modules/order/index.js +679 -66
  152. package/lib/server/modules/order/types.d.ts +11 -3
  153. package/lib/solution/BaseSales/index.d.ts +109 -20
  154. package/lib/solution/BaseSales/index.js +883 -70
  155. package/lib/solution/BaseSales/types.d.ts +52 -0
  156. package/lib/solution/BaseSales/types.js +2 -1
  157. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  158. package/lib/solution/BaseSales/utils/cartPromotion.js +63 -12
  159. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  160. package/lib/solution/BookingByStep/index.d.ts +2 -17
  161. package/lib/solution/BookingByStep/index.js +18 -60
  162. package/lib/solution/BookingByStep/types.d.ts +1 -2
  163. package/lib/solution/BookingByStep/types.js +0 -5
  164. package/lib/solution/BookingByStep/utils/capacity.js +1 -20
  165. package/lib/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  166. package/lib/solution/BookingByStep/utils/timeslots.js +11 -19
  167. package/lib/solution/BookingTicket/index.d.ts +7 -3
  168. package/lib/solution/BookingTicket/index.js +62 -9
  169. package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -0
  170. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  171. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +36 -4
  172. package/lib/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  173. package/lib/solution/BookingTicket/utils/weighingProductSku.js +63 -0
  174. package/lib/solution/Sales/index.d.ts +1 -0
  175. package/lib/solution/Sales/index.js +5 -3
  176. package/lib/solution/ScanOrder/index.d.ts +14 -26
  177. package/lib/solution/ScanOrder/index.js +190 -449
  178. package/lib/solution/ScanOrder/types.d.ts +1 -21
  179. package/lib/solution/ScanOrder/utils.d.ts +0 -8
  180. package/lib/solution/ScanOrder/utils.js +0 -31
  181. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  182. package/lib/solution/ShopDiscount/index.js +0 -14
  183. package/lib/solution/VenueBooking/index.d.ts +11 -39
  184. package/lib/solution/VenueBooking/index.js +123 -328
  185. package/lib/solution/VenueBooking/types.d.ts +0 -3
  186. package/lib/solution/VenueBooking/utils/resource.js +0 -1
  187. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  188. package/lib/solution/VenueBooking/utils/slotMerge.js +4 -6
  189. package/lib/solution/index.d.ts +0 -1
  190. package/lib/solution/index.js +1 -3
  191. package/lib/types/index.d.ts +1 -1
  192. package/lib/utils/payment-number.d.ts +9 -0
  193. package/lib/utils/payment-number.js +64 -0
  194. package/package.json +1 -1
  195. package/dist/modules/Holder/index.d.ts +0 -48
  196. package/dist/modules/Holder/index.js +0 -640
  197. package/dist/modules/Holder/types.d.ts +0 -123
  198. package/dist/modules/Holder/types.js +0 -1
  199. package/dist/modules/Holder/utils.d.ts +0 -13
  200. package/dist/modules/Holder/utils.js +0 -34
  201. package/dist/modules/ResourcePlanner/index.d.ts +0 -24
  202. package/dist/modules/ResourcePlanner/index.js +0 -181
  203. package/dist/modules/ResourcePlanner/planner.d.ts +0 -14
  204. package/dist/modules/ResourcePlanner/planner.js +0 -1069
  205. package/dist/modules/ResourcePlanner/types.d.ts +0 -227
  206. package/dist/modules/ResourcePlanner/types.js +0 -1
  207. package/dist/solution/UnifiedBookingSales/index.d.ts +0 -183
  208. package/dist/solution/UnifiedBookingSales/index.js +0 -1871
  209. package/dist/solution/UnifiedBookingSales/types.d.ts +0 -143
  210. package/dist/solution/UnifiedBookingSales/types.js +0 -11
  211. package/lib/modules/Holder/index.d.ts +0 -48
  212. package/lib/modules/Holder/index.js +0 -402
  213. package/lib/modules/Holder/types.d.ts +0 -123
  214. package/lib/modules/Holder/types.js +0 -17
  215. package/lib/modules/Holder/utils.d.ts +0 -13
  216. package/lib/modules/Holder/utils.js +0 -71
  217. package/lib/modules/ResourcePlanner/index.d.ts +0 -24
  218. package/lib/modules/ResourcePlanner/index.js +0 -148
  219. package/lib/modules/ResourcePlanner/planner.d.ts +0 -14
  220. package/lib/modules/ResourcePlanner/planner.js +0 -933
  221. package/lib/modules/ResourcePlanner/types.d.ts +0 -227
  222. package/lib/modules/ResourcePlanner/types.js +0 -17
  223. package/lib/solution/UnifiedBookingSales/index.d.ts +0 -183
  224. package/lib/solution/UnifiedBookingSales/index.js +0 -1076
  225. package/lib/solution/UnifiedBookingSales/types.d.ts +0 -143
  226. package/lib/solution/UnifiedBookingSales/types.js +0 -33
@@ -37,6 +37,8 @@ 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");
40
42
  var import_cartPromotion = require("../../solution/BaseSales/utils/cartPromotion");
41
43
  var import_utils3 = require("../../solution/ScanOrder/utils");
42
44
  var import_manualProductDiscount = require("./utils/manualProductDiscount");
@@ -83,6 +85,11 @@ function isPaidPaymentRecord(payment) {
83
85
  function isCommittedVoucherPaymentRecord(payment) {
84
86
  return isVoucherPaymentRecord(payment) && (payment == null ? void 0 : payment.status) !== "voided" && (hasSyncedOrderPaymentRecord(payment) || isPaidPaymentRecord(payment));
85
87
  }
88
+ function getVoucherPaymentLifecycleKey(payment) {
89
+ if (!isVoucherPaymentRecord(payment))
90
+ return null;
91
+ return `${String(payment.voucher_id)}::${String(payment.status || "")}`;
92
+ }
86
93
  var OrderModule = class extends import_BaseModule.BaseModule {
87
94
  constructor(name, version) {
88
95
  super(name || "order", version);
@@ -300,7 +307,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
300
307
  });
301
308
  }
302
309
  async initialize(core, options) {
303
- var _a, _b, _c, _d;
310
+ var _a, _b, _c;
304
311
  this.core = core;
305
312
  this.store = options.store;
306
313
  if (!this.store.tempOrder) {
@@ -313,19 +320,19 @@ var OrderModule = class extends import_BaseModule.BaseModule {
313
320
  this.store.availableWalletIds = [];
314
321
  }
315
322
  this.request = this.core.getPlugin("request");
316
- const appPlugin = this.core.getPlugin("app");
317
- if (!appPlugin) {
318
- console.error("Order 模块需要 app 插件支持");
323
+ this.appPlugin = this.core.getPlugin("app");
324
+ if (!this.appPlugin) {
325
+ throw new Error("Order 模块需要 app 插件支持");
319
326
  }
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;
327
+ const app = this.appPlugin.getApp();
328
+ this.logger = app.logger;
322
329
  this.window = this.core.getPlugin("window");
323
330
  const otherParams = options.otherParams || {};
324
331
  this.cacheId = otherParams.cacheId;
325
332
  this.salesSummaryModuleName = otherParams.salesSummaryModuleName;
326
- this.rulesHooksOverride = (_b = otherParams.rules) == null ? void 0 : _b.hooks;
333
+ this.rulesHooksOverride = (_a = otherParams.rules) == null ? void 0 : _a.hooks;
327
334
  this.moduleHooksOverride = options.hooks;
328
- this.orderHooks = this.moduleHooksOverride || ((_c = otherParams.order) == null ? void 0 : _c.hooks) || ((_d = otherParams.hooks) == null ? void 0 : _d.order);
335
+ this.orderHooks = this.moduleHooksOverride || ((_b = otherParams.order) == null ? void 0 : _b.hooks) || ((_c = otherParams.hooks) == null ? void 0 : _c.order);
329
336
  this.otherParams = otherParams;
330
337
  this.registerDiscountModules(options);
331
338
  this.logInfo("OrderModule initialized successfully");
@@ -834,16 +841,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
834
841
  /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化;草稿保存请使用 IndexedDB saveDraft。 */
835
842
  persistTempOrder() {
836
843
  }
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
- }
847
844
  // ─── TempOrder: 创建 & 获取 ───
848
845
  createDefaultTempOrderInstance() {
849
846
  return (0, import_utils.createDefaultTempOrder)({
@@ -1063,17 +1060,40 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1063
1060
  const depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1064
1061
  return depositPaidAmount.lt(depositAmount) ? "deposit" : "normal";
1065
1062
  }
1063
+ getPaymentNumberAppData(key) {
1064
+ var _a, _b, _c, _d, _e;
1065
+ const appPlugin = this.appPlugin;
1066
+ if (!appPlugin)
1067
+ return void 0;
1068
+ const getData = (_a = appPlugin.getData) == null ? void 0 : _a.call(appPlugin);
1069
+ if (typeof getData === "function")
1070
+ return getData(key);
1071
+ const app = appPlugin.getApp();
1072
+ 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");
1073
+ return coreData == null ? void 0 : coreData[key];
1074
+ }
1075
+ getPaymentNumberDevicePrefixSync() {
1076
+ return (0, import_payment_number.resolvePaymentNumberDevicePrefixFromDeviceId)(
1077
+ (key) => this.getPaymentNumberAppData(key)
1078
+ );
1079
+ }
1080
+ getPaymentNumberDevicePrefixAsync() {
1081
+ return (0, import_payment_number.resolvePaymentNumberDevicePrefix)(
1082
+ (key) => this.getPaymentNumberAppData(key)
1083
+ );
1084
+ }
1066
1085
  normalizePaymentSource(payment, options) {
1067
1086
  const paymentRecord = payment;
1068
1087
  const metadata = paymentRecord.metadata && typeof paymentRecord.metadata === "object" ? { ...paymentRecord.metadata } : {};
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
- };
1088
+ const normalized = (0, import_payment_utils.ensureOrderPaymentNumber)(
1089
+ {
1090
+ ...paymentRecord,
1091
+ metadata,
1092
+ origin_amount: paymentRecord.origin_amount ?? paymentRecord.amount ?? "0.00"
1093
+ },
1094
+ (options == null ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(),
1095
+ import_utils.createUuidV4
1096
+ );
1077
1097
  if (paymentRecord.status !== void 0) {
1078
1098
  normalized.status = paymentRecord.status;
1079
1099
  } else if ((options == null ? void 0 : options.defaultPaid) !== false) {
@@ -2494,17 +2514,36 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2494
2514
  * 用一组支付来源覆盖当前订单支付项。
2495
2515
  *
2496
2516
  * 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
2497
- * uuid -> metadata.unique_payment_number,id -> custom_payment_id,
2517
+ * 新支付来源的 uuid 会作为 payment_number 的唯一号段,id -> custom_payment_id,
2498
2518
  * isSynced 等运行态字段不会进入 tempOrder.payments。
2499
2519
  */
2500
2520
  setOrderPayments(payments) {
2501
2521
  const tempOrder = this.ensureTempOrder();
2502
- tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(payments);
2522
+ tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(
2523
+ (payments || []).map((payment) => this.normalizePaymentSource(payment, { defaultPaid: false }))
2524
+ );
2503
2525
  this.persistTempOrder();
2504
2526
  return tempOrder.payments;
2505
2527
  }
2506
- /** 追加单个支付项,并立即持久化当前 tempOrder。 */
2528
+ /** 同步兼容入口:按调用当下的 device_id 或 LOCAL 生成支付编号。 */
2507
2529
  addOrderPayment(payment) {
2530
+ const hasPaymentNumber = String(
2531
+ payment.payment_number || ""
2532
+ ).trim() !== "";
2533
+ return this.addOrderPaymentWithDevicePrefix(
2534
+ payment,
2535
+ hasPaymentNumber ? "LOCAL" : this.getPaymentNumberDevicePrefixSync()
2536
+ );
2537
+ }
2538
+ /** 异步入口:创建支付项时读取最新 IoT 设备短号。 */
2539
+ async addOrderPaymentAsync(payment) {
2540
+ const hasPaymentNumber = String(
2541
+ payment.payment_number || ""
2542
+ ).trim() !== "";
2543
+ const devicePrefix = hasPaymentNumber ? "LOCAL" : await this.getPaymentNumberDevicePrefixAsync();
2544
+ return this.addOrderPaymentWithDevicePrefix(payment, devicePrefix);
2545
+ }
2546
+ addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
2508
2547
  this.logInfo("addOrderPayment", {
2509
2548
  payment
2510
2549
  });
@@ -2517,7 +2556,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2517
2556
  type: orderPaymentType,
2518
2557
  order_payment_type: orderPaymentType
2519
2558
  },
2520
- { defaultPaid: true }
2559
+ { defaultPaid: true, devicePrefix }
2521
2560
  )
2522
2561
  ]);
2523
2562
  tempOrder.payments = [...tempOrder.payments || [], ...mapped];
@@ -2530,57 +2569,55 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2530
2569
  return tempOrder.payments;
2531
2570
  }
2532
2571
  /**
2533
- * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
2534
- *
2535
- * 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
2536
- * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
2572
+ * 默认按支付唯一号精确更新;仅显式指定 legacy 时兼容历史支付标识。
2573
+ * metadata 与 transactions 会分别合并,避免覆盖支付会话号和已有交易记录。
2537
2574
  */
2538
- updateOrderPayment(paymentIdentity, updates) {
2575
+ async updateOrderPayment(paymentIdentity, updates, options = {}) {
2539
2576
  const tempOrder = this.ensureTempOrder();
2540
2577
  const identity = String(paymentIdentity);
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)
2578
+ const matchMode = options.matchBy === "compat" || options.matchBy === "legacy" ? "compat" : "payment_number";
2579
+ const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2580
+ tempOrder.payments || [],
2581
+ identity,
2582
+ matchMode
2583
+ );
2584
+ if (!matchedPayment) {
2585
+ throw new Error(`未找到支付项: ${identity}`);
2586
+ }
2587
+ let updatedPayment = null;
2588
+ tempOrder.payments = (tempOrder.payments || []).map((payment, index) => {
2589
+ if (index !== matchedPayment.index)
2554
2590
  return payment;
2555
- return {
2556
- ...payment,
2591
+ const nextPayment = (0, import_payment_utils.mergeOrderPaymentRecord)(payment, {
2557
2592
  ...updates,
2558
- metadata: {
2559
- ...payment.metadata || {},
2560
- ...updates.metadata || {}
2561
- }
2562
- };
2593
+ updated_at: updates.updated_at || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
2594
+ });
2595
+ updatedPayment = nextPayment;
2596
+ return nextPayment;
2563
2597
  });
2564
2598
  this.persistTempOrder();
2565
- return tempOrder.payments;
2599
+ const summary = await this.recalculateSummary({ createIfMissing: true });
2600
+ this.persistTempOrder();
2601
+ const payments = tempOrder.payments;
2602
+ return {
2603
+ updated: true,
2604
+ payment: payments[matchedPayment.index] || updatedPayment,
2605
+ payments,
2606
+ summary
2607
+ };
2566
2608
  }
2567
2609
  /** 从当前订单支付项中移除指定支付项。 */
2568
2610
  deleteOrderPayment(paymentIdentity) {
2569
2611
  const tempOrder = this.ensureTempOrder();
2570
2612
  const identity = String(paymentIdentity);
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
- });
2613
+ const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2614
+ tempOrder.payments || [],
2615
+ identity,
2616
+ "compat"
2617
+ );
2618
+ if (!matchedPayment)
2619
+ return tempOrder.payments;
2620
+ tempOrder.payments = (tempOrder.payments || []).filter((_, index) => index !== matchedPayment.index);
2584
2621
  this.persistTempOrder();
2585
2622
  return tempOrder.payments;
2586
2623
  }
@@ -2689,7 +2726,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2689
2726
  payments.map(
2690
2727
  (payment) => this.normalizePaymentSource(
2691
2728
  normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)),
2692
- { defaultPaid: false }
2729
+ {
2730
+ defaultPaid: false,
2731
+ devicePrefix: options == null ? void 0 : options.devicePrefix
2732
+ }
2693
2733
  )
2694
2734
  )
2695
2735
  ).filter((payment) => {
@@ -2711,14 +2751,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2711
2751
  const committedVoucherPaymentIds = new Set(
2712
2752
  committedVoucherPayments.filter((payment) => hasSyncedOrderPaymentRecord(payment)).map((payment) => String(payment.order_payment_id))
2713
2753
  );
2714
- const committedVoucherIds = new Set(
2715
- committedVoucherPayments.map((payment) => String(payment.voucher_id))
2754
+ const committedVoucherLifecycleKeys = new Set(
2755
+ committedVoucherPayments.map((payment) => getVoucherPaymentLifecycleKey(payment)).filter((key) => key !== null)
2716
2756
  );
2717
2757
  const replaceableVouchers = mappedVouchers.filter((payment) => {
2718
2758
  if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
2719
2759
  return false;
2720
2760
  }
2721
- if (payment.voucher_id !== void 0 && committedVoucherIds.has(String(payment.voucher_id))) {
2761
+ const lifecycleKey = getVoucherPaymentLifecycleKey(payment);
2762
+ if (lifecycleKey && committedVoucherLifecycleKeys.has(lifecycleKey)) {
2722
2763
  return false;
2723
2764
  }
2724
2765
  return true;
@@ -2740,6 +2781,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2740
2781
  });
2741
2782
  return tempOrder.payments;
2742
2783
  }
2784
+ async updateVoucherOrderPaymentsAsync(payments, options) {
2785
+ const needsPaymentNumber = (payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
2786
+ const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
2787
+ return this.updateVoucherOrderPayments(payments, {
2788
+ ...options,
2789
+ devicePrefix
2790
+ });
2791
+ }
2743
2792
  async shouldMergeProductToOrder(params) {
2744
2793
  var _a;
2745
2794
  const onBeforeMergeProductToOrder = (_a = this.orderHooks) == null ? void 0 : _a.onBeforeMergeProductToOrder;
@@ -3570,6 +3619,38 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3570
3619
  await this.saveDraft();
3571
3620
  return tempOrder;
3572
3621
  }
3622
+ async saveTempOrderAsDraft(params) {
3623
+ var _a, _b, _c, _d, _e;
3624
+ const tempOrder = this.ensureTempOrder();
3625
+ this.ensureExternalSaleNumber(tempOrder);
3626
+ this.persistTempOrder();
3627
+ const latestSummary = await this.recalculateSummary({ createIfMissing: true }) || this.store.summary || (0, import_utils.createEmptySummary)();
3628
+ const payload = (0, import_utils.buildSubmitPayload)({
3629
+ tempOrder,
3630
+ cacheId: (params == null ? void 0 : params.cacheId) ?? this.cacheId,
3631
+ platform: (params == null ? void 0 : params.platform) || ((_a = this.otherParams) == null ? void 0 : _a.platform),
3632
+ businessCode: (params == null ? void 0 : params.businessCode) || ((_b = this.otherParams) == null ? void 0 : _b.businessCode) || ((_c = this.otherParams) == null ? void 0 : _c.business_code) || tempOrder.business_code,
3633
+ channel: params == null ? void 0 : params.channel,
3634
+ type: (params == null ? void 0 : params.type) ?? ((_d = this.otherParams) == null ? void 0 : _d.type),
3635
+ summary: latestSummary,
3636
+ enhance: params == null ? void 0 : params.enhancePayload
3637
+ });
3638
+ if (!payload.created_at) {
3639
+ payload.created_at = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
3640
+ }
3641
+ payload.need_sync = 0;
3642
+ payload.is_draft_order = 1;
3643
+ this.logInfo("saveTempOrderAsDraft calling sales draft", {
3644
+ orderId: payload.order_id,
3645
+ externalSaleNumber: payload.external_sale_number,
3646
+ productsCount: ((_e = payload.products) == null ? void 0 : _e.length) || 0
3647
+ });
3648
+ return this.request.post("/order/sales/draft", payload, {
3649
+ osServer: true,
3650
+ customToast: () => {
3651
+ }
3652
+ });
3653
+ }
3573
3654
  /**
3574
3655
  * 提交当前 Sales tempOrder。
3575
3656
  *
@@ -3770,8 +3851,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3770
3851
  }
3771
3852
  async syncPaymentsToOrder(params) {
3772
3853
  const tempOrder = this.ensureTempOrder();
3854
+ const needsPaymentNumber = (params.payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
3855
+ const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
3773
3856
  const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
3774
- params.payments || []
3857
+ (params.payments || []).map((payment) => this.normalizePaymentSource(payment, {
3858
+ defaultPaid: false,
3859
+ devicePrefix
3860
+ }))
3775
3861
  );
3776
3862
  const shouldConfirmPendingVoucherPayments = params.confirmPendingVoucherPayments ?? params.submitWhenPaid === true;
3777
3863
  const effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
@@ -3793,7 +3879,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3793
3879
  tempOrder,
3794
3880
  effectivePayments
3795
3881
  );
3796
- const submitParams = {
3882
+ const submitResult = await this.submitTempOrder({
3797
3883
  payments: effectivePayments,
3798
3884
  paymentStatus,
3799
3885
  smallTicketDataFlag: params.smallTicketDataFlag,
@@ -3807,8 +3893,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3807
3893
  };
3808
3894
  return nextPayload;
3809
3895
  }
3810
- };
3811
- const submitResult = params.checkoutSyncTaskEnabled === false ? await this.submitTempOrderAsync(submitParams) : await this.submitTempOrder(submitParams);
3896
+ });
3812
3897
  return { ...completion, submitResult };
3813
3898
  }
3814
3899
  createOrder(params) {
@@ -3825,13 +3910,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3825
3910
  is_deposit: 0,
3826
3911
  relation_products: [],
3827
3912
  relation_forms: [],
3828
- business_code: params == null ? void 0 : params.business_code,
3829
3913
  ...(params == null ? void 0 : params.extraData) || {}
3830
3914
  };
3831
3915
  let is_deposit = 0;
3832
3916
  if (params.cartItems.length > 0) {
3833
3917
  params.cartItems.forEach((item) => {
3834
- var _a2;
3835
3918
  if (!item._origin.duration) {
3836
3919
  const { duration, durationType } = (0, import_utils.generateDuration)(item);
3837
3920
  item._origin.duration = duration;
@@ -3840,9 +3923,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3840
3923
  item._origin.sub_type = (0, import_utils.normalizeBookingSubType)(item._origin);
3841
3924
  const discountList = (0, import_utils.getAllDiscountList)(item);
3842
3925
  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
- }
3846
3926
  if ((0, import_utils2.isNormalProduct)(item._origin)) {
3847
3927
  order.relation_products.push(item._origin.product);
3848
3928
  const relationForms = item._origin.relation_forms || [];
@@ -4153,6 +4233,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4153
4233
  }
4154
4234
  }
4155
4235
  const nextTempOrder = this.normalizeTempOrderForRuntime(raw, { makeEditMark: true });
4236
+ const sourceLastOrderInfo = raw.lastOrderInfo || raw;
4237
+ const isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
4238
+ const syntheticIdentityOptions = {
4239
+ isDraftOrder,
4240
+ externalSaleNumber: nextTempOrder.external_sale_number
4241
+ };
4156
4242
  const rawSummary = raw.summary && typeof raw.summary === "object" ? raw.summary : {};
4157
4243
  const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map((s) => ({ ...s || {} })) : (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []);
4158
4244
  this.store.tempOrder = nextTempOrder;
@@ -4173,7 +4259,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4173
4259
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
4174
4260
  }
4175
4261
  };
4176
- this.store.lastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
4262
+ this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(
4263
+ sourceLastOrderInfo,
4264
+ syntheticIdentityOptions
4265
+ );
4266
+ const hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
4267
+ if (hadSyntheticDraftOrderId && this.store.syncState !== "submitting") {
4268
+ this.store.syncState = "local";
4269
+ }
4177
4270
  const hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
4178
4271
  const currentDiscounts = typeof ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
4179
4272
  const currentScanDiscounts = currentDiscounts.filter((discount) => discount == null ? void 0 : discount.isScan);
@@ -4286,12 +4379,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4286
4379
  }
4287
4380
  normalizeTempOrderForRuntime(raw, options) {
4288
4381
  var _a, _b;
4382
+ const runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
4289
4383
  const nextTempOrder = {
4290
4384
  ...this.createDefaultTempOrderInstance(),
4291
- ...raw || {}
4385
+ ...runtimeRaw || {}
4292
4386
  };
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;
4387
+ 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) {
4388
+ nextTempOrder.order_id = runtimeRaw.id;
4295
4389
  }
4296
4390
  delete nextTempOrder.summary;
4297
4391
  delete nextTempOrder.lastOrderInfo;
@@ -4359,6 +4453,22 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4359
4453
  nextTempOrder.vouchers = raw.vouchers || [];
4360
4454
  return nextTempOrder;
4361
4455
  }
4456
+ isSyntheticDraftOrderIdForRuntime(record, options) {
4457
+ const isDraftOrder = (options == null ? void 0 : options.isDraftOrder) ?? Number((record == null ? void 0 : record.is_draft_order) || 0) === 1;
4458
+ const externalSaleNumber = (record == null ? void 0 : record.external_sale_number) ?? (options == null ? void 0 : options.externalSaleNumber);
4459
+ const orderId = record == null ? void 0 : record.order_id;
4460
+ return Boolean(
4461
+ isDraftOrder && orderId !== void 0 && orderId !== null && orderId !== "" && externalSaleNumber !== void 0 && externalSaleNumber !== null && externalSaleNumber !== "" && String(orderId) === String(externalSaleNumber)
4462
+ );
4463
+ }
4464
+ withoutSyntheticDraftOrderIdForRuntime(record, options) {
4465
+ if (!this.isSyntheticDraftOrderIdForRuntime(record, options))
4466
+ return record;
4467
+ return {
4468
+ ...record,
4469
+ order_id: null
4470
+ };
4471
+ }
4362
4472
  hydrateLinkedBookingIdentity(tempOrder) {
4363
4473
  const bookingUidByProductUid = /* @__PURE__ */ new Map();
4364
4474
  const productByUid = /* @__PURE__ */ new Map();
@@ -0,0 +1,26 @@
1
+ export type OrderPaymentTransactionStatus = 'success' | 'fail';
2
+ export interface OrderPaymentTransaction {
3
+ number: string;
4
+ status: OrderPaymentTransactionStatus;
5
+ }
6
+ export type OrderPaymentIdentityType = 'order_payment_id' | 'payment_number' | 'unique_payment_number';
7
+ export interface OrderPaymentIdentityMatch<T> {
8
+ index: number;
9
+ payment: T;
10
+ matchedBy: OrderPaymentIdentityType;
11
+ }
12
+ export declare function getOrderPaymentIdentityKeys(payment: unknown): string[];
13
+ export declare function isPendingOrderPayment(payment: unknown): boolean;
14
+ export declare function isIdentifiedPendingOrderPayment(payment: unknown): boolean;
15
+ export declare function hasOrderPaymentIdentityOverlap(left: unknown, right: unknown): boolean;
16
+ export declare function resolveOrderPaymentIdentity<T extends Record<string, any>>(payments: T[] | null | undefined, identity: string | number, mode?: 'payment_number' | 'compat'): OrderPaymentIdentityMatch<T> | null;
17
+ export declare function ensureOrderPaymentNumber<T extends Record<string, any>>(payment: T, devicePrefix: string, createPaymentNumber: () => string): T & {
18
+ payment_number: string;
19
+ };
20
+ export declare function mergeOrderPaymentTransactions(current: unknown, incoming: unknown): OrderPaymentTransaction[];
21
+ export declare function mergeOrderPaymentRecord<T extends Record<string, any>>(payment: T, updates: Record<string, any>): T;
22
+ export declare function mergeOrderPaymentSnapshot<T extends Record<string, any>>(current: T, incoming: T): T;
23
+ export declare function mergeOrderPaymentListsByIdentity<T extends Record<string, any>>(existing: T[] | null | undefined, incoming: T[] | null | undefined, options?: {
24
+ preserveUnmatchedExisting?: boolean;
25
+ preserveUnmatchedExistingWhen?: (payment: T) => boolean;
26
+ }): T[];