@pisell/pisellos 2.2.152 → 2.2.154

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 (92) hide show
  1. package/dist/core/index.js +1 -0
  2. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  3. package/dist/modules/Cart/utils/cartProduct.js +1 -1
  4. package/dist/modules/Discount/index.d.ts +6 -2
  5. package/dist/modules/Discount/index.js +14 -8
  6. package/dist/modules/Order/index.d.ts +2 -0
  7. package/dist/modules/Order/index.js +234 -161
  8. package/dist/modules/Order/types.d.ts +19 -0
  9. package/dist/modules/Order/utils.js +7 -6
  10. package/dist/modules/Payment/index.d.ts +4 -0
  11. package/dist/modules/Payment/index.js +567 -505
  12. package/dist/modules/Payment/types.d.ts +29 -9
  13. package/dist/modules/SalesSummary/index.d.ts +7 -5
  14. package/dist/modules/SalesSummary/index.js +35 -11
  15. package/dist/plugins/app.d.ts +2 -0
  16. package/dist/server/index.d.ts +2 -5
  17. package/dist/server/index.js +58 -66
  18. package/dist/server/modules/index.d.ts +1 -1
  19. package/dist/server/modules/products/index.d.ts +12 -1
  20. package/dist/server/modules/products/index.js +169 -78
  21. package/dist/server/modules/products/types.d.ts +11 -0
  22. package/dist/server/modules/products/types.js +4 -0
  23. package/dist/server/utils/product.js +2 -2
  24. package/dist/solution/BaseSales/index.d.ts +26 -2
  25. package/dist/solution/BaseSales/index.js +342 -112
  26. package/dist/solution/BaseSales/types.d.ts +4 -4
  27. package/dist/solution/BaseSales/types.js +4 -4
  28. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +62 -0
  29. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +116 -0
  30. package/dist/solution/BaseSales/utils.js +3 -3
  31. package/dist/solution/BookingByStep/index.d.ts +1 -1
  32. package/dist/solution/BookingTicket/index.d.ts +11 -13
  33. package/dist/solution/BookingTicket/index.js +23 -37
  34. package/dist/solution/BookingTicket/types.d.ts +9 -6
  35. package/dist/solution/BookingTicket/types.js +6 -3
  36. package/dist/solution/BookingTicket/utils/cartView.d.ts +7 -12
  37. package/dist/solution/BookingTicket/utils/cartView.js +52 -14
  38. package/dist/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  39. package/dist/solution/BookingTicket/utils/orderCustomer.js +31 -0
  40. package/dist/solution/Sales/index.d.ts +3 -0
  41. package/dist/solution/Sales/index.js +85 -43
  42. package/dist/solution/Sales/types.d.ts +3 -0
  43. package/dist/solution/ScanOrder/types.d.ts +4 -4
  44. package/dist/solution/ScanOrder/types.js +4 -4
  45. package/dist/solution/ScanOrder/utils.js +3 -3
  46. package/dist/solution/ShopDiscount/index.d.ts +2 -1
  47. package/dist/solution/ShopDiscount/index.js +32 -20
  48. package/dist/solution/ShopDiscount/types.d.ts +1 -0
  49. package/lib/core/index.js +1 -0
  50. package/lib/modules/Cart/utils/cartProduct.js +1 -1
  51. package/lib/modules/Discount/index.d.ts +6 -2
  52. package/lib/modules/Discount/index.js +3 -1
  53. package/lib/modules/Order/index.d.ts +2 -0
  54. package/lib/modules/Order/index.js +40 -8
  55. package/lib/modules/Order/types.d.ts +19 -0
  56. package/lib/modules/Order/utils.js +4 -2
  57. package/lib/modules/Payment/index.d.ts +4 -0
  58. package/lib/modules/Payment/index.js +26 -2
  59. package/lib/modules/Payment/types.d.ts +29 -9
  60. package/lib/modules/SalesSummary/index.d.ts +7 -5
  61. package/lib/modules/SalesSummary/index.js +29 -9
  62. package/lib/plugins/app.d.ts +2 -0
  63. package/lib/server/index.d.ts +2 -5
  64. package/lib/server/index.js +38 -58
  65. package/lib/server/modules/index.d.ts +1 -1
  66. package/lib/server/modules/products/index.d.ts +12 -1
  67. package/lib/server/modules/products/index.js +69 -9
  68. package/lib/server/modules/products/types.d.ts +11 -0
  69. package/lib/server/utils/product.js +2 -2
  70. package/lib/solution/BaseSales/index.d.ts +26 -2
  71. package/lib/solution/BaseSales/index.js +169 -3
  72. package/lib/solution/BaseSales/types.d.ts +4 -4
  73. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +62 -0
  74. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +155 -0
  75. package/lib/solution/BaseSales/utils.js +3 -3
  76. package/lib/solution/BookingByStep/index.d.ts +1 -1
  77. package/lib/solution/BookingTicket/index.d.ts +11 -13
  78. package/lib/solution/BookingTicket/index.js +17 -27
  79. package/lib/solution/BookingTicket/types.d.ts +9 -6
  80. package/lib/solution/BookingTicket/utils/cartView.d.ts +7 -12
  81. package/lib/solution/BookingTicket/utils/cartView.js +44 -18
  82. package/lib/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  83. package/lib/solution/BookingTicket/utils/orderCustomer.js +58 -0
  84. package/lib/solution/Sales/index.d.ts +3 -0
  85. package/lib/solution/Sales/index.js +50 -15
  86. package/lib/solution/Sales/types.d.ts +3 -0
  87. package/lib/solution/ScanOrder/types.d.ts +4 -4
  88. package/lib/solution/ScanOrder/utils.js +3 -3
  89. package/lib/solution/ShopDiscount/index.d.ts +2 -1
  90. package/lib/solution/ShopDiscount/index.js +10 -4
  91. package/lib/solution/ShopDiscount/types.d.ts +1 -0
  92. package/package.json +1 -1
@@ -0,0 +1,155 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/solution/BaseSales/utils/transformBaseProductToOrderProduct.ts
20
+ var transformBaseProductToOrderProduct_exports = {};
21
+ __export(transformBaseProductToOrderProduct_exports, {
22
+ transformBaseProductToOrderProduct: () => transformBaseProductToOrderProduct
23
+ });
24
+ module.exports = __toCommonJS(transformBaseProductToOrderProduct_exports);
25
+ function toNumber(value, fallback = 0) {
26
+ const parsedValue = Number(value);
27
+ if (!Number.isFinite(parsedValue))
28
+ return fallback;
29
+ return parsedValue;
30
+ }
31
+ function toProductId(value) {
32
+ if (value === null || value === void 0 || value === "")
33
+ return null;
34
+ const parsedValue = Number(value);
35
+ if (!Number.isFinite(parsedValue))
36
+ return null;
37
+ return parsedValue;
38
+ }
39
+ function toSafePositiveInt(value, fallback = 1) {
40
+ const parsedValue = Math.floor(Number(value));
41
+ if (!Number.isFinite(parsedValue) || parsedValue < 1)
42
+ return fallback;
43
+ return parsedValue;
44
+ }
45
+ function toPriceString(value, fallback = "0.00") {
46
+ const parsedValue = Number(value);
47
+ if (!Number.isFinite(parsedValue))
48
+ return fallback;
49
+ return parsedValue.toFixed(2);
50
+ }
51
+ function normalizeOptionItems(optionItems) {
52
+ if (!Array.isArray(optionItems))
53
+ return [];
54
+ return optionItems.map((optionItem) => {
55
+ const optionGroupItemId = toNumber(optionItem == null ? void 0 : optionItem.option_group_item_id);
56
+ const price = (optionItem == null ? void 0 : optionItem.price) ?? (optionItem == null ? void 0 : optionItem.add_price) ?? 0;
57
+ return {
58
+ option_group_item_id: optionGroupItemId,
59
+ option_group_id: toNumber(optionItem == null ? void 0 : optionItem.option_group_id),
60
+ num: toSafePositiveInt((optionItem == null ? void 0 : optionItem.num) ?? (optionItem == null ? void 0 : optionItem.quantity), 1),
61
+ price: toNumber(price, 0)
62
+ };
63
+ });
64
+ }
65
+ function normalizeBundleItems(bundleItems) {
66
+ if (!Array.isArray(bundleItems))
67
+ return [];
68
+ return bundleItems.map((bundleItem) => ({
69
+ ...bundleItem,
70
+ option: normalizeOptionItems(bundleItem == null ? void 0 : bundleItem.option)
71
+ }));
72
+ }
73
+ function findVariantById(origin, variantId) {
74
+ if (!origin || !variantId || variantId <= 0)
75
+ return null;
76
+ const variants = Array.isArray(origin == null ? void 0 : origin.variant) ? origin.variant : [];
77
+ return variants.find((variant) => Number(variant == null ? void 0 : variant.id) === variantId) || null;
78
+ }
79
+ function transformBaseProductToOrderProduct(params) {
80
+ var _a, _b;
81
+ const { payload, fallbackProductId = null } = params;
82
+ if (!payload || typeof payload !== "object")
83
+ return null;
84
+ const sourceProduct = params.sourceProduct || params.sourceItem || {};
85
+ const productId = toProductId(
86
+ payload.product_id ?? payload.id ?? (sourceProduct == null ? void 0 : sourceProduct.product_id) ?? (sourceProduct == null ? void 0 : sourceProduct.id) ?? fallbackProductId
87
+ );
88
+ if (productId === null)
89
+ return null;
90
+ const productVariantId = toNumber(
91
+ payload.product_variant_id ?? payload.variant_id ?? (sourceProduct == null ? void 0 : sourceProduct.product_variant_id) ?? (sourceProduct == null ? void 0 : sourceProduct.variant_id),
92
+ 0
93
+ );
94
+ const callbackOrigin = payload.origin || ((_a = payload._origin) == null ? void 0 : _a.sourceProduct) || ((_b = payload._origin) == null ? void 0 : _b.sourceItem) || payload._origin || {};
95
+ const origin = {
96
+ ...sourceProduct || {},
97
+ ...callbackOrigin || {}
98
+ };
99
+ const matchedVariant = findVariantById(callbackOrigin, productVariantId) ?? findVariantById(sourceProduct, productVariantId) ?? findVariantById(origin, productVariantId);
100
+ const sourceProductPrice = toPriceString(
101
+ payload.price ?? payload.selling_price ?? (matchedVariant == null ? void 0 : matchedVariant.price) ?? (matchedVariant == null ? void 0 : matchedVariant.base_price) ?? (origin == null ? void 0 : origin.price) ?? (origin == null ? void 0 : origin.base_price) ?? (sourceProduct == null ? void 0 : sourceProduct.price) ?? (sourceProduct == null ? void 0 : sourceProduct.selling_price) ?? (sourceProduct == null ? void 0 : sourceProduct.base_price),
102
+ "0.00"
103
+ );
104
+ const productOptionItem = normalizeOptionItems(
105
+ payload.option ?? payload.options ?? payload.product_option_item
106
+ );
107
+ const productBundle = normalizeBundleItems(
108
+ payload.bundle ?? payload.product_bundle
109
+ );
110
+ const uniqueIdentificationNumber = payload.unique_identification_number ?? payload.unique;
111
+ const metadata = {
112
+ unique: payload.unique,
113
+ session: payload.session,
114
+ form: payload.form,
115
+ service_times: payload.service_times,
116
+ machine_code: payload.machine_code,
117
+ schedule_id: payload.schedule_id,
118
+ duration: payload.duration,
119
+ policy_id: payload.policy_id,
120
+ source_shop_id: payload.source_shop_id,
121
+ origin,
122
+ source_product_price: sourceProductPrice
123
+ };
124
+ if (uniqueIdentificationNumber) {
125
+ metadata.unique_identification_number = String(uniqueIdentificationNumber);
126
+ }
127
+ return {
128
+ product_id: productId,
129
+ product_variant_id: productVariantId,
130
+ unique_identification_number: uniqueIdentificationNumber ? String(uniqueIdentificationNumber) : void 0,
131
+ num: toSafePositiveInt(payload.quantity ?? payload.num, 1),
132
+ product_option_item: productOptionItem,
133
+ product_bundle: productBundle,
134
+ selling_price: sourceProductPrice,
135
+ original_price: sourceProductPrice,
136
+ tax_fee: toPriceString(
137
+ payload.tax_fee ?? (matchedVariant == null ? void 0 : matchedVariant.tax_fee) ?? (origin == null ? void 0 : origin.tax_fee) ?? (sourceProduct == null ? void 0 : sourceProduct.tax_fee),
138
+ "0.00"
139
+ ),
140
+ is_charge_tax: toNumber(
141
+ payload.is_charge_tax ?? (matchedVariant == null ? void 0 : matchedVariant.is_charge_tax) ?? (origin == null ? void 0 : origin.is_charge_tax) ?? (sourceProduct == null ? void 0 : sourceProduct.is_charge_tax),
142
+ 0
143
+ ),
144
+ metadata,
145
+ note: payload.note != null ? String(payload.note) : "",
146
+ _origin: {
147
+ ...sourceProduct || {},
148
+ callbackData: payload
149
+ }
150
+ };
151
+ }
152
+ // Annotate the CommonJS export names for ESM import in node:
153
+ 0 && (module.exports = {
154
+ transformBaseProductToOrderProduct
155
+ });
@@ -61,13 +61,13 @@ function createEmptySummary() {
61
61
  function buildProductLineFingerprint(productOptionItem, productBundle) {
62
62
  const optArr = Array.isArray(productOptionItem) ? productOptionItem : [];
63
63
  const normalizedOpts = optArr.map((item) => ({
64
- product_option_item_id: Number(item == null ? void 0 : item.product_option_item_id) || 0,
64
+ option_group_item_id: Number(item == null ? void 0 : item.option_group_item_id) || 0,
65
65
  option_group_id: Number(item == null ? void 0 : item.option_group_id) || 0,
66
66
  num: typeof (item == null ? void 0 : item.num) === "number" && !Number.isNaN(item.num) ? Math.max(1, Math.floor(item.num)) : 1,
67
67
  price: String((item == null ? void 0 : item.price) ?? "")
68
68
  })).sort((p, q) => {
69
- if (p.product_option_item_id !== q.product_option_item_id) {
70
- return p.product_option_item_id - q.product_option_item_id;
69
+ if (p.option_group_item_id !== q.option_group_item_id) {
70
+ return p.option_group_item_id - q.option_group_item_id;
71
71
  }
72
72
  if (p.option_group_id !== q.option_group_id)
73
73
  return p.option_group_id - q.option_group_id;
@@ -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 | 1 | 2 | 3 | 4 | 5 | 6;
314
+ weekNum: 0 | 2 | 1 | 5 | 3 | 4 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -1,7 +1,7 @@
1
1
  import { Module, ModuleOptions, PisellCore } from '../../types';
2
- import { BookingTicketCartView, BookingTicketCustomerView, BookingTicketProductCatalogView, BookingTicketState, IGetCustomerListParams, ICustomer, ILoadProductsParams, ILoadProductDetailParams, IScanResult } from './types';
2
+ import { BookingTicketCartView, BookingTicketProductCatalogView, BookingTicketState, IGetCustomerListParams, ICustomer, ILoadProductsParams, ILoadProductDetailParams, IScanResult } from './types';
3
3
  import type { ProductData } from '../../modules';
4
- import type { OrderCustomerView, OrderCustomerPatch } from '../../modules/Order/types';
4
+ import type { OrderCustomerView } from '../../modules/Order/types';
5
5
  import { BaseSalesImpl } from '../BaseSales';
6
6
  import type { ISalesDetail } from '../BaseSales/utils/parseSalesResponse';
7
7
  import type { LoadSalesDetailParams } from '../../modules/Order/types';
@@ -13,7 +13,6 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
13
13
  * 父类按 `getRegisteredModuleNames` 注入成员到该 store。
14
14
  */
15
15
  protected store: BookingTicketState;
16
- private shopStore;
17
16
  private platform;
18
17
  private scan;
19
18
  private productCatalog;
@@ -102,16 +101,13 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
102
101
  /**
103
102
  * 获取购物车 UI 视图。
104
103
  *
105
- * tempOrder 仍是 checkout 协议对象;本方法只输出 UI 直接消费的数据,
106
- * 商品行展示字段在 Solution 层合并,避免 UI 直接读取 tempOrder 原始结构。
104
+ * tempOrder 仍是 checkout 协议对象;商品行直接透传 products,bookings 附带关联商品。
107
105
  */
108
106
  getCart(): BookingTicketCartView;
109
107
  /**
110
- * 获取客户 UI 视图。
111
- *
112
- * 优先使用 CustomerModule 的 selected customer;缺失时回退到 tempOrder 顶层客户字段。
108
+ * 获取当前下单客户(与 OrderModule.tempOrder snapshot 一致)。
113
109
  */
114
- getCustomer(): BookingTicketCustomerView | null;
110
+ getCustomer(): ICustomer | null;
115
111
  /**
116
112
  * 通过 ids 获取商品列表(不加载到模块中)
117
113
  * @returns 商品列表
@@ -169,13 +165,15 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
169
165
  /**
170
166
  * 设置当前下单客户。
171
167
  *
172
- * @param patch tempOrder 协议字段(customer_id 必填,其余缺省视为清空)
173
- * @param snapshot UI 富字段快照;undefined 不动;null 清空;ICustomer 写入
168
+ * @param customer 完整客户对象;null 表示清空
169
+ *
170
+ * 内部将 customer 格式化为 tempOrder 协议字段后写入 OrderModule,
171
+ * 并以 customer 作为 snapshot 保存富字段。
174
172
  *
175
173
  * 同时透传 OrderModule 内部 emit 的 `order:onOrderCustomerChange` 之外,
176
174
  * 在 BookingTicket 命名空间也 emit 一次,方便上层统一从 Solution 订阅。
177
175
  */
178
- setOrderCustomer(patch: OrderCustomerPatch | null, snapshot?: ICustomer | null): void;
176
+ setOrderCustomer(customer: ICustomer | null): void;
179
177
  /**
180
178
  * 读取 tempOrder 上的下单客户协议字段;customer_id 缺失时返回 null。
181
179
  */
@@ -233,7 +231,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
233
231
  * 获取当前的客户搜索条件
234
232
  * @returns 当前搜索条件
235
233
  */
236
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
234
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
237
235
  /**
238
236
  * 获取客户列表状态(包含滚动加载相关状态)
239
237
  * @returns 客户状态
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(BookingTicket_exports);
37
37
  var import_types = require("./types");
38
38
  var import_BaseSales = require("../BaseSales");
39
39
  var import_scan = __toESM(require("./utils/scan"));
40
+ var import_orderCustomer = require("./utils/orderCustomer");
40
41
  var import_handleScan = require("./utils/scan/handleScan");
41
42
  var import_scanCache = __toESM(require("./utils/scan/scanCache"));
42
43
  var import_cartView = require("./utils/cartView");
@@ -76,10 +77,6 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
76
77
  async initialize(core, options = {}) {
77
78
  var _a;
78
79
  this.scan = new import_scan.default(this, "BOOKING_TICKET_SCAN");
79
- this.shopStore = core.getPlugin("shopStore");
80
- if (!this.shopStore) {
81
- throw new Error("bookingTicket解决方案需要 shopStore 插件支持");
82
- }
83
80
  await super.initialize(core, options);
84
81
  if (!this.request) {
85
82
  throw new Error("bookingTicket解决方案需要 request 插件支持");
@@ -111,7 +108,7 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
111
108
  country_calling_code: detailCustomer == null ? void 0 : detailCustomer.country_calling_code
112
109
  };
113
110
  customerModule.setSelectedCustomer(customer);
114
- this.setOrderCustomer(customer, detailCustomer);
111
+ this.setOrderCustomer(customer);
115
112
  }
116
113
  return sales;
117
114
  }
@@ -259,33 +256,20 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
259
256
  /**
260
257
  * 获取购物车 UI 视图。
261
258
  *
262
- * tempOrder 仍是 checkout 协议对象;本方法只输出 UI 直接消费的数据,
263
- * 商品行展示字段在 Solution 层合并,避免 UI 直接读取 tempOrder 原始结构。
259
+ * tempOrder 仍是 checkout 协议对象;商品行直接透传 products,bookings 附带关联商品。
264
260
  */
265
261
  getCart() {
266
262
  var _a;
267
263
  const tempOrder = ((_a = this.store.order) == null ? void 0 : _a.getTempOrder()) ?? null;
268
264
  const salesDetail = this.getSalesOrder();
269
265
  const bookings = (salesDetail == null ? void 0 : salesDetail.bookings) ?? ((tempOrder == null ? void 0 : tempOrder.bookings) || []);
270
- const salesDetailBookingMap = salesDetail == null ? void 0 : salesDetail.bookingsByProductUid;
271
- const bookingsByProductUid = salesDetailBookingMap && Object.keys(salesDetailBookingMap).length > 0 ? salesDetailBookingMap : (0, import_cartView.indexBookingsByProductUid)(bookings);
272
- return {
273
- items: (0, import_cartView.buildCartItemViews)((tempOrder == null ? void 0 : tempOrder.products) || [], {
274
- bookingDetailMap: bookingsByProductUid,
275
- productsCatalog: this.productCatalog
276
- })
277
- };
266
+ return (0, import_cartView.buildCartView)((tempOrder == null ? void 0 : tempOrder.products) || [], bookings);
278
267
  }
279
268
  /**
280
- * 获取客户 UI 视图。
281
- *
282
- * 优先使用 CustomerModule 的 selected customer;缺失时回退到 tempOrder 顶层客户字段。
269
+ * 获取当前下单客户(与 OrderModule.tempOrder snapshot 一致)。
283
270
  */
284
271
  getCustomer() {
285
- var _a, _b, _c, _d;
286
- const selected = ((_b = (_a = this.store.customer) == null ? void 0 : _a.getSelectedCustomer) == null ? void 0 : _b.call(_a)) ?? null;
287
- const tempOrder = ((_d = (_c = this.store.order) == null ? void 0 : _c.getTempOrder) == null ? void 0 : _d.call(_c)) ?? null;
288
- return (0, import_cartView.buildCustomerView)(selected, tempOrder);
272
+ return this.getOrderCustomerSnapshot();
289
273
  }
290
274
  /**
291
275
  * 通过 ids 获取商品列表(不加载到模块中)
@@ -387,16 +371,22 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
387
371
  /**
388
372
  * 设置当前下单客户。
389
373
  *
390
- * @param patch tempOrder 协议字段(customer_id 必填,其余缺省视为清空)
391
- * @param snapshot UI 富字段快照;undefined 不动;null 清空;ICustomer 写入
374
+ * @param customer 完整客户对象;null 表示清空
375
+ *
376
+ * 内部将 customer 格式化为 tempOrder 协议字段后写入 OrderModule,
377
+ * 并以 customer 作为 snapshot 保存富字段。
392
378
  *
393
379
  * 同时透传 OrderModule 内部 emit 的 `order:onOrderCustomerChange` 之外,
394
380
  * 在 BookingTicket 命名空间也 emit 一次,方便上层统一从 Solution 订阅。
395
381
  */
396
- setOrderCustomer(patch, snapshot) {
397
- this.store.order.setOrderCustomer(patch, snapshot);
382
+ setOrderCustomer(customer) {
383
+ if (!customer) {
384
+ this.clearOrderCustomer();
385
+ return;
386
+ }
387
+ const patch = (0, import_orderCustomer.formatOrderCustomerPatch)(customer);
388
+ this.store.order.setOrderCustomer(patch, customer);
398
389
  const next = this.buildOrderCustomerPayload();
399
- console.log("setOrderCustomer1234", patch, snapshot, next);
400
390
  this.core.effects.emit(`${this.name}:onOrderCustomerChange`, next);
401
391
  }
402
392
  /**
@@ -94,21 +94,24 @@ export interface IScanResult {
94
94
  result: any;
95
95
  }
96
96
  /**
97
- * BookingTicket 面向 UI 的购物车行视图。
97
+ * BookingTicket 面向 UI 的购物车商品行视图。
98
98
  *
99
- * tempOrder.products 仍保持 Sales checkout 协议结构;展示字段在 Solution 层合并后输出,
100
- * 避免 UI 直接读取 booking/detail/catalog 等原始来源。
99
+ * 直接透传 tempOrder.products 协议行,不做 Solution enrichment。
101
100
  */
102
- export interface BookingTicketCartItemView extends BaseSalesOrderProduct {
103
- /** UI 运行态扩展,不进入 tempOrder 提交协议。 */
101
+ export type BookingTicketCartItemView = BaseSalesOrderProduct;
102
+ /**
103
+ * BookingTicket 面向 UI 的 booking 行视图(平铺,附带关联商品)。
104
+ */
105
+ export interface BookingTicketCartBookingView extends ISalesBooking {
104
106
  _extend: {
105
- booking: ISalesBooking | null;
107
+ product: BookingTicketCartItemView | null;
106
108
  };
107
109
  }
108
110
  /**
109
111
  * BookingTicket 面向 UI 的购物车视图。
110
112
  */
111
113
  export interface BookingTicketCartView {
114
+ bookings: BookingTicketCartBookingView[];
112
115
  items: BookingTicketCartItemView[];
113
116
  }
114
117
  /**
@@ -1,24 +1,19 @@
1
1
  import type { BaseSalesOrderProduct } from '../../BaseSales';
2
2
  import type { ISalesBooking } from '../../BaseSales/utils/parseSalesResponse';
3
- import type { ProductData } from '../../../modules/Product/types';
4
- import type { BookingTicketCartItemView, BookingTicketCustomerView, ICustomer } from '../types';
3
+ import type { BookingTicketCartView, BookingTicketCustomerView, ICustomer } from '../types';
5
4
  import type { ScanOrderTempOrder } from '../../ScanOrder/types';
6
5
  /**
7
6
  * 仅按 booking.product_uid 建索引,避免发明 booking 与商品行之间的其它等价关系。
8
7
  */
9
8
  export declare function indexBookingsByProductUid(bookings: ISalesBooking[] | undefined | null): Record<string, ISalesBooking[]>;
10
9
  /**
11
- * 合并购物车行展示字段。协议字段仍来自 tempOrder.products,
12
- * 展示字段按 booking detail/product 优先,商品池 catalog 兜底。
10
+ * 构建购物车 UI 视图:bookings 平铺附带关联商品;items 仅含未关联 booking 的商品行。
11
+ *
12
+ * 商品行直接透传 tempOrder.products,不做 enrichment。
13
+ * 关联规则(1:1):booking.product_uid ↔ line.metadata.unique_identification_number;
14
+ * 同一 uid 已被更早的 booking 占用时,后续 booking 的 product 为 null。
13
15
  */
14
- export declare function buildCartItemView(line: BaseSalesOrderProduct, ctx: {
15
- bookingDetailMap?: Record<string, ISalesBooking[]>;
16
- productsCatalog: ProductData[];
17
- }): BookingTicketCartItemView;
18
- export declare function buildCartItemViews(lines: BaseSalesOrderProduct[] | undefined | null, ctx: {
19
- bookingDetailMap?: Record<string, ISalesBooking[]>;
20
- productsCatalog: ProductData[];
21
- }): BookingTicketCartItemView[];
16
+ export declare function buildCartView(lines: BaseSalesOrderProduct[] | undefined | null, bookings: ISalesBooking[] | undefined | null): BookingTicketCartView;
22
17
  export declare function isWalkInCustomer(customer: Pick<ICustomer, 'id'> | null | undefined): boolean;
23
18
  /**
24
19
  * selected 优先,缺失时回退 tempOrder.customer_*,统一输出 UI 客户视图。
@@ -19,8 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/solution/BookingTicket/utils/cartView.ts
20
20
  var cartView_exports = {};
21
21
  __export(cartView_exports, {
22
- buildCartItemView: () => buildCartItemView,
23
- buildCartItemViews: () => buildCartItemViews,
22
+ buildCartView: () => buildCartView,
24
23
  buildCustomerView: () => buildCustomerView,
25
24
  indexBookingsByProductUid: () => indexBookingsByProductUid,
26
25
  isWalkInCustomer: () => isWalkInCustomer
@@ -40,21 +39,49 @@ function indexBookingsByProductUid(bookings) {
40
39
  return acc;
41
40
  }, {});
42
41
  }
43
- function buildCartItemView(line, ctx) {
44
- var _a, _b, _c;
45
- const productUid = (_a = line.metadata) == null ? void 0 : _a.unique_identification_number;
46
- const matched = productUid ? (_c = (_b = ctx.bookingDetailMap) == null ? void 0 : _b[String(productUid)]) == null ? void 0 : _c[0] : void 0;
47
- return {
48
- ...line,
49
- _extend: {
50
- booking: matched ?? null
51
- }
52
- };
42
+ function indexProductsByUid(lines) {
43
+ return lines.reduce((acc, line) => {
44
+ var _a;
45
+ const uid = (_a = line.metadata) == null ? void 0 : _a.unique_identification_number;
46
+ if (uid === void 0 || uid === null || uid === "")
47
+ return acc;
48
+ const key = String(uid);
49
+ if (!acc[key])
50
+ acc[key] = line;
51
+ return acc;
52
+ }, {});
53
53
  }
54
- function buildCartItemViews(lines, ctx) {
55
- if (!Array.isArray(lines) || lines.length === 0)
56
- return [];
57
- return lines.map((line) => buildCartItemView(line, ctx));
54
+ function buildCartView(lines, bookings) {
55
+ const productLines = Array.isArray(lines) ? lines : [];
56
+ const bookingList = Array.isArray(bookings) ? bookings : [];
57
+ const linesByUid = indexProductsByUid(productLines);
58
+ const claimedUids = /* @__PURE__ */ new Set();
59
+ const cartBookings = bookingList.filter((booking) => booking.parent_id !== 0).map((booking) => {
60
+ const uid = booking == null ? void 0 : booking.product_uid;
61
+ let product = null;
62
+ if (uid !== void 0 && uid !== null && uid !== "") {
63
+ const key = String(uid);
64
+ if (!claimedUids.has(key)) {
65
+ const line = linesByUid[key];
66
+ if (line) {
67
+ claimedUids.add(key);
68
+ product = line;
69
+ }
70
+ }
71
+ }
72
+ return {
73
+ ...booking,
74
+ _extend: { product }
75
+ };
76
+ });
77
+ const items = productLines.filter((line) => {
78
+ var _a;
79
+ const uid = (_a = line.metadata) == null ? void 0 : _a.unique_identification_number;
80
+ if (uid === void 0 || uid === null || uid === "")
81
+ return true;
82
+ return !claimedUids.has(String(uid));
83
+ });
84
+ return { bookings: cartBookings, items };
58
85
  }
59
86
  function isWalkInCustomer(customer) {
60
87
  if (!customer)
@@ -95,8 +122,7 @@ function buildCustomerView(selected, tempOrder) {
95
122
  }
96
123
  // Annotate the CommonJS export names for ESM import in node:
97
124
  0 && (module.exports = {
98
- buildCartItemView,
99
- buildCartItemViews,
125
+ buildCartView,
100
126
  buildCustomerView,
101
127
  indexBookingsByProductUid,
102
128
  isWalkInCustomer
@@ -0,0 +1,4 @@
1
+ import type { ICustomer } from '../types';
2
+ import type { OrderCustomerPatch } from '../../../modules/Order/types';
3
+ /** 将 ICustomer 格式化为写入 tempOrder 的协议字段。 */
4
+ export declare function formatOrderCustomerPatch(customer: ICustomer): OrderCustomerPatch;
@@ -0,0 +1,58 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/solution/BookingTicket/utils/orderCustomer.ts
20
+ var orderCustomer_exports = {};
21
+ __export(orderCustomer_exports, {
22
+ formatOrderCustomerPatch: () => formatOrderCustomerPatch
23
+ });
24
+ module.exports = __toCommonJS(orderCustomer_exports);
25
+ function resolveCustomerDisplayName(customer) {
26
+ const c = customer;
27
+ const displayName = c.display_name;
28
+ if (typeof displayName === "string" && displayName)
29
+ return displayName;
30
+ const nickname = c.nickname;
31
+ if (typeof nickname === "string" && nickname)
32
+ return nickname;
33
+ const firstName = c.first_name;
34
+ const lastName = c.last_name;
35
+ if (typeof firstName === "string" && firstName || typeof lastName === "string" && lastName) {
36
+ return `${typeof firstName === "string" ? firstName : ""} ${typeof lastName === "string" ? lastName : ""}`.trim();
37
+ }
38
+ const customerName = c.customer_name;
39
+ if (typeof customerName === "string" && customerName)
40
+ return customerName;
41
+ return customer.name ?? "";
42
+ }
43
+ function formatOrderCustomerPatch(customer) {
44
+ var _a;
45
+ const rawId = customer.id;
46
+ const numericId = typeof rawId === "number" ? rawId : rawId !== void 0 && rawId !== null && rawId !== "" ? Number(rawId) : null;
47
+ return {
48
+ customer_id: Number.isFinite(numericId) ? numericId : null,
49
+ customer_name: resolveCustomerDisplayName(customer),
50
+ phone: customer.phone ?? "",
51
+ email: customer.email ?? "",
52
+ country_calling_code: ((_a = customer.country_calling_code) == null ? void 0 : _a.toString()) ?? ""
53
+ };
54
+ }
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ formatOrderCustomerPatch
58
+ });
@@ -82,6 +82,9 @@ export declare class SalesImpl extends BaseModule implements Module, SalesModule
82
82
  private getResourceId;
83
83
  private getBookingAppointmentStatus;
84
84
  private getBookingOrderPaymentStatus;
85
+ private countBookingOrders;
86
+ private countCompletedBookings;
87
+ private groupBookingsByResource;
85
88
  private isBookingMatchedResource;
86
89
  private sortMatchedBookings;
87
90
  /**