@pisell/pisellos 2.2.187 → 2.2.189

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 (43) hide show
  1. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +11 -4
  2. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +11 -4
  3. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  4. package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
  5. package/dist/modules/Order/index.d.ts +5 -0
  6. package/dist/modules/Order/index.js +174 -70
  7. package/dist/modules/Order/types.d.ts +1 -0
  8. package/dist/modules/Order/utils.js +3 -1
  9. package/dist/modules/Rules/index.js +32 -21
  10. package/dist/solution/BaseSales/utils/cartPromotion.js +31 -11
  11. package/dist/solution/BookingByStep/index.d.ts +1 -1
  12. package/dist/solution/BookingTicket/index.d.ts +15 -0
  13. package/dist/solution/BookingTicket/index.js +135 -10
  14. package/dist/solution/BookingTicket/types.d.ts +48 -0
  15. package/dist/solution/BookingTicket/types.js +5 -1
  16. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  17. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +394 -0
  18. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  19. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
  20. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  21. package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
  22. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  23. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -1
  24. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +4 -0
  25. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  26. package/lib/modules/BookingContext/utils/orderLineDisplay.js +56 -0
  27. package/lib/modules/Order/index.d.ts +5 -0
  28. package/lib/modules/Order/index.js +99 -14
  29. package/lib/modules/Order/types.d.ts +1 -0
  30. package/lib/modules/Order/utils.js +1 -0
  31. package/lib/modules/Rules/index.js +88 -78
  32. package/lib/solution/BaseSales/utils/cartPromotion.js +22 -1
  33. package/lib/solution/BookingByStep/index.d.ts +1 -1
  34. package/lib/solution/BookingTicket/index.d.ts +15 -0
  35. package/lib/solution/BookingTicket/index.js +75 -2
  36. package/lib/solution/BookingTicket/types.d.ts +48 -0
  37. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  38. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +166 -0
  39. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  40. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +51 -0
  41. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  42. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +127 -0
  43. package/package.json +1 -1
@@ -41,12 +41,29 @@ var import_scan = __toESM(require("./utils/scan"));
41
41
  var import_orderCustomer = require("./utils/orderCustomer");
42
42
  var import_handleScan = require("./utils/scan/handleScan");
43
43
  var import_scanCache = __toESM(require("./utils/scan/scanCache"));
44
+ var import_formatGlobalScan = require("./utils/scan/formatGlobalScan");
45
+ var import_applyGlobalScan = require("./utils/scan/applyGlobalScan");
44
46
  var import_cartView = require("./utils/cartView");
45
47
  var import_addProductDecision = require("./utils/addProductDecision");
46
48
  var import_buildCacheItemFromOrderLine = require("../../modules/BookingContext/utils/buildCacheItemFromOrderLine");
47
49
  var import_buildNormalProductCacheItemFromOrderLine = require("../../modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine");
50
+ var import_orderLineDisplay = require("../../modules/BookingContext/utils/orderLineDisplay");
48
51
  var import_bookingStatus = require("./utils/bookingStatus");
49
52
  __reExport(BookingTicket_exports, require("./types"), module.exports);
53
+ function withProductOptionString(cacheItem) {
54
+ var _a;
55
+ const productOptionString = (0, import_orderLineDisplay.buildProductOptionStringFromOrderLine)(cacheItem);
56
+ if (!productOptionString)
57
+ return cacheItem;
58
+ return {
59
+ ...cacheItem,
60
+ product_option_string: (cacheItem == null ? void 0 : cacheItem.product_option_string) || productOptionString,
61
+ _extend: {
62
+ ...(cacheItem == null ? void 0 : cacheItem._extend) || {},
63
+ product_option_string: ((_a = cacheItem == null ? void 0 : cacheItem._extend) == null ? void 0 : _a.product_option_string) || productOptionString
64
+ }
65
+ };
66
+ }
50
67
  var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
51
68
  constructor() {
52
69
  super(...arguments);
@@ -909,10 +926,12 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
909
926
  * 拼装 cacheItem 的 _extend / _data(资源 / 容量 / timeObj),与 info2 `getProductExtend` 等价。
910
927
  */
911
928
  getProductExtend(cacheItem, extra) {
912
- return (0, import_BookingContext.getProductExtend)({
913
- cacheItem,
929
+ const preparedCacheItem = withProductOptionString(cacheItem);
930
+ const result = (0, import_BookingContext.getProductExtend)({
931
+ cacheItem: preparedCacheItem,
914
932
  ctx: this.buildBookingCalcContext(extra)
915
933
  });
934
+ return result;
916
935
  }
917
936
  /**
918
937
  * 取资源不可用原因列表(结构化 enum + params,i18n 文案由 UI 渲染)。
@@ -1000,6 +1019,60 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
1000
1019
  async updateProductInOrder(params) {
1001
1020
  return this.updateOrderProduct(params);
1002
1021
  }
1022
+ /**
1023
+ * 全局扫码 pubsub 入口:解析码值 → 搜索 → 业务分发(客户 / 加车 / 开单)。
1024
+ * UI 层在 pubsub 订阅回调里注入 `bridge`(uiHosts / action / cart.confirm*)。
1025
+ *
1026
+ * @example
1027
+ * ```ts
1028
+ * await bookingTicket.handleGlobalScanCode(payload.data, {
1029
+ * openProductDetail: uiHosts.openProductDetail,
1030
+ * confirmDetail: cart.confirmDetail,
1031
+ * openOrder: ({ order_id }) => action({ type: 'pisell1.handleOpenCachedBigSale', data: { order_id } }),
1032
+ * });
1033
+ * ```
1034
+ */
1035
+ async handleGlobalScanCode(code, bridge) {
1036
+ var _a, _b, _c, _d;
1037
+ const trimmed = typeof code === "string" ? code.trim() : "";
1038
+ if (!trimmed) {
1039
+ (_a = bridge == null ? void 0 : bridge.onNotify) == null ? void 0 : _a.call(bridge, "fail", "pisell2.text.scan-global-failed");
1040
+ return { status: "failed", reason: "empty_code" };
1041
+ }
1042
+ try {
1043
+ const localSearch = (v) => this.store.products.findProductsByCodeOrBarcode(v);
1044
+ const scanCallback = (0, import_handleScan.handleGlobalScan)(this.request, localSearch);
1045
+ const raw = await scanCallback({ type: "nativeScanner", value: trimmed });
1046
+ const formatted = (0, import_formatGlobalScan.formatGlobalScanResult)(raw, trimmed);
1047
+ if (!formatted) {
1048
+ (_b = bridge == null ? void 0 : bridge.onNotify) == null ? void 0 : _b.call(bridge, "fail", "pisell2.text.scan-global-failed");
1049
+ return { status: "failed", reason: "not_found" };
1050
+ }
1051
+ const result = await (0, import_applyGlobalScan.applyGlobalScan)(
1052
+ {
1053
+ setOrderCustomer: (customer) => this.setOrderCustomer(customer),
1054
+ getOrderCustomerSnapshot: () => this.getOrderCustomerSnapshot(),
1055
+ getBusinessCode: () => {
1056
+ var _a2;
1057
+ return (_a2 = this.otherParams) == null ? void 0 : _a2.businessCode;
1058
+ },
1059
+ buildAddProductCtx: (extra) => this.buildAddProductCtx(extra),
1060
+ decideAddProduct: (item, options) => this.decideAddProduct(item, options),
1061
+ decideAfterDetail: (cacheItem, options) => this.decideAfterDetail(cacheItem, options),
1062
+ transformDetailToProductAndBooking: (input) => this.transformDetailToProductAndBooking(input),
1063
+ addProductToOrder: (product, booking) => this.addProductToOrder(product, booking)
1064
+ },
1065
+ formatted,
1066
+ bridge
1067
+ );
1068
+ (_c = bridge == null ? void 0 : bridge.refresh) == null ? void 0 : _c.call(bridge);
1069
+ return result;
1070
+ } catch (error) {
1071
+ console.error("[BookingTicket] handleGlobalScanCode failed", error);
1072
+ (_d = bridge == null ? void 0 : bridge.onNotify) == null ? void 0 : _d.call(bridge, "fail", "pisell2.text.scan-global-failed");
1073
+ return { status: "failed", reason: "not_found" };
1074
+ }
1075
+ }
1003
1076
  /**
1004
1077
  * 销毁模块:先调用父类(销毁所有 store 内子模块 + emit destroy + super.destroy()),
1005
1078
  * 再清理 BookingTicket 自有资源(scan 监听 + scan 内存缓存)。
@@ -134,3 +134,51 @@ export interface BookingTicketCustomerView {
134
134
  export interface BookingTicketProductCatalogView {
135
135
  products: ProductData[];
136
136
  }
137
+ /** 扫码宿主桥接:SalesSdk 在 pubsub 订阅回调里注入,OS 需要 UI 时直接调用 */
138
+ export interface GlobalScanHostBridge {
139
+ openProductDetail?: (payload: Record<string, any>) => Promise<any | null>;
140
+ openBookingEdit?: (payload: Record<string, any>) => Promise<any | null>;
141
+ confirmDetail?: (input: {
142
+ item: any;
143
+ detailResult: {
144
+ e: any;
145
+ extension_type?: any;
146
+ detail?: any;
147
+ };
148
+ options?: Record<string, any>;
149
+ }) => Promise<any>;
150
+ confirmBookingEdit?: (input: {
151
+ cacheItem: any;
152
+ options?: Record<string, any>;
153
+ }) => Promise<any>;
154
+ openOrder?: (data: {
155
+ order_id: number;
156
+ business_code?: string;
157
+ }) => void;
158
+ /**
159
+ * walk-in 扫 walletPass:直接核销优惠码(对齐 SaleDetail Voucher.handleApplyCode / cart.scanCode)。
160
+ */
161
+ applyPromotionCode?: (code: string, customerId?: number) => Promise<{
162
+ isAvailable?: boolean;
163
+ type?: string;
164
+ unavailableReason?: string;
165
+ }>;
166
+ onNotify?: (type: 'success' | 'fail' | 'info', messageKey?: string) => void;
167
+ refresh?: () => void;
168
+ }
169
+ /** handleGlobalScanCode 结构化返回 */
170
+ export type GlobalScanHandleResult = {
171
+ status: 'success';
172
+ kind: 'customer' | 'products' | 'promotion';
173
+ meta?: {
174
+ count?: number;
175
+ };
176
+ } | {
177
+ status: 'pending';
178
+ kind: 'openOrder' | 'requiresDetail' | 'requiresBookingEdit';
179
+ } | {
180
+ status: 'cancelled';
181
+ } | {
182
+ status: 'failed';
183
+ reason: 'empty_code' | 'not_found' | 'invalid_data' | 'no_bridge';
184
+ };
@@ -0,0 +1,36 @@
1
+ import type { GlobalScanHandleResult, GlobalScanHostBridge, ICustomer } from '../../types';
2
+ import type { AddProductDecision } from '../addProductDecision';
3
+ import { GlobalScanFormattedResult } from './formatGlobalScan';
4
+ /** applyGlobalScan 所需的 BookingTicket 运行时能力 */
5
+ export interface GlobalScanApplyHost {
6
+ setOrderCustomer(customer: ICustomer | null): void;
7
+ getOrderCustomerSnapshot(): ICustomer | null;
8
+ getBusinessCode(): string | undefined;
9
+ buildAddProductCtx(extra?: Record<string, any>): Record<string, any>;
10
+ decideAddProduct(item: any, options?: Record<string, any>): AddProductDecision;
11
+ decideAfterDetail(cacheItem: any, options?: Record<string, any>): AddProductDecision;
12
+ transformDetailToProductAndBooking(input: {
13
+ item: any;
14
+ cacheItem?: any;
15
+ detailResult?: {
16
+ e: any;
17
+ extension_type?: any;
18
+ detail?: any;
19
+ };
20
+ options?: Record<string, any>;
21
+ }): {
22
+ product: any;
23
+ booking?: any;
24
+ cacheItem: any;
25
+ };
26
+ addProductToOrder(product: any, booking?: any): Promise<any>;
27
+ }
28
+ /**
29
+ * 应用全局扫码格式化结果:设客户 / 加车 / 开单 / 弹窗链。
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const result = await applyGlobalScan(bookingTicket, formatted, bridge);
34
+ * ```
35
+ */
36
+ export declare function applyGlobalScan(host: GlobalScanApplyHost, formatted: GlobalScanFormattedResult, bridge?: GlobalScanHostBridge): Promise<GlobalScanHandleResult>;
@@ -0,0 +1,166 @@
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/scan/applyGlobalScan.ts
20
+ var applyGlobalScan_exports = {};
21
+ __export(applyGlobalScan_exports, {
22
+ applyGlobalScan: () => applyGlobalScan
23
+ });
24
+ module.exports = __toCommonJS(applyGlobalScan_exports);
25
+ var import_addProductDecision = require("../addProductDecision");
26
+ var import_cartView = require("../cartView");
27
+ var import_scanProductValues = require("./scanProductValues");
28
+ async function processScannedProductItem(host, item, code, bridge) {
29
+ const ctx = host.buildAddProductCtx();
30
+ if ((0, import_scanProductValues.isScanProductBundle)(item) || (0, import_scanProductValues.isScanProductOption)(item)) {
31
+ return runRequiresDetailFlow(host, item, ctx, bridge);
32
+ }
33
+ if ((0, import_scanProductValues.countScanVariantMatches)(item, code) >= 2) {
34
+ return runRequiresDetailFlow(host, item, ctx, bridge);
35
+ }
36
+ const values = (0, import_scanProductValues.genScanProductValues)(item, code);
37
+ const itemWithSelection = { ...item, cartDetailValue: values };
38
+ const decision = host.decideAddProduct(itemWithSelection, ctx);
39
+ return runAddProductDecision(host, item, decision, ctx, bridge);
40
+ }
41
+ async function runRequiresDetailFlow(host, item, ctx, bridge) {
42
+ if (!(bridge == null ? void 0 : bridge.openProductDetail)) {
43
+ return "pending";
44
+ }
45
+ const payload = (0, import_addProductDecision.buildRequiresDetailPayload)(item, ctx);
46
+ const detailResult = await bridge.openProductDetail(payload);
47
+ if (!detailResult) {
48
+ return "cancelled";
49
+ }
50
+ if (!bridge.confirmDetail) {
51
+ return "pending";
52
+ }
53
+ await bridge.confirmDetail({
54
+ item: payload.productData ?? payload.item ?? item,
55
+ detailResult
56
+ });
57
+ return "added";
58
+ }
59
+ async function runAddProductDecision(host, catalogItem, decision, ctx, bridge) {
60
+ if (decision.action === "add") {
61
+ const transformed = host.transformDetailToProductAndBooking({
62
+ item: catalogItem,
63
+ cacheItem: decision.cacheItem,
64
+ options: ctx
65
+ });
66
+ await host.addProductToOrder(transformed.product, transformed.booking);
67
+ return "added";
68
+ }
69
+ if (decision.action === "requiresDetail") {
70
+ return runRequiresDetailFlow(host, catalogItem, ctx, bridge);
71
+ }
72
+ if (decision.action === "requiresBookingEdit") {
73
+ if (!(bridge == null ? void 0 : bridge.openBookingEdit)) {
74
+ return "pending";
75
+ }
76
+ const edited = await bridge.openBookingEdit(decision.payload);
77
+ if (!edited) {
78
+ return "cancelled";
79
+ }
80
+ if (!bridge.confirmBookingEdit) {
81
+ return "pending";
82
+ }
83
+ await bridge.confirmBookingEdit({ cacheItem: edited });
84
+ return "added";
85
+ }
86
+ return "pending";
87
+ }
88
+ async function applyGlobalScan(host, formatted, bridge) {
89
+ var _a, _b, _c, _d, _e, _f, _g;
90
+ const { searchType, data, scanCode } = formatted;
91
+ debugger;
92
+ if (searchType === "wallet") {
93
+ if (!data) {
94
+ (_a = bridge == null ? void 0 : bridge.onNotify) == null ? void 0 : _a.call(bridge, "fail", "pisell2.text.scan-global-failed");
95
+ return { status: "failed", reason: "invalid_data" };
96
+ }
97
+ host.setOrderCustomer(data);
98
+ (_b = bridge == null ? void 0 : bridge.onNotify) == null ? void 0 : _b.call(bridge, "success", "pisell2.text.add-client-success");
99
+ return { status: "success", kind: "customer" };
100
+ }
101
+ if (searchType === "walletPass") {
102
+ if (!data) {
103
+ (_c = bridge == null ? void 0 : bridge.onNotify) == null ? void 0 : _c.call(bridge, "fail", "pisell2.text.scan-global-failed");
104
+ return { status: "failed", reason: "invalid_data" };
105
+ }
106
+ const snapshot = host.getOrderCustomerSnapshot();
107
+ if ((0, import_cartView.isWalkInCustomer)(snapshot)) {
108
+ if (!(bridge == null ? void 0 : bridge.applyPromotionCode)) {
109
+ return { status: "failed", reason: "no_bridge" };
110
+ }
111
+ const result = await bridge.applyPromotionCode(scanCode);
112
+ if (result == null ? void 0 : result.isAvailable) {
113
+ return { status: "success", kind: "promotion" };
114
+ }
115
+ return { status: "failed", reason: "invalid_data" };
116
+ }
117
+ host.setOrderCustomer(data);
118
+ (_d = bridge == null ? void 0 : bridge.onNotify) == null ? void 0 : _d.call(bridge, "success", "pisell2.text.add-client-success");
119
+ return { status: "success", kind: "customer" };
120
+ }
121
+ if (searchType === "product" || searchType === "local_product") {
122
+ const list = data == null ? void 0 : data.list;
123
+ if (!Array.isArray(list) || list.length === 0) {
124
+ (_e = bridge == null ? void 0 : bridge.onNotify) == null ? void 0 : _e.call(bridge, "fail", "pisell2.text.scan-global-failed");
125
+ return { status: "failed", reason: "invalid_data" };
126
+ }
127
+ let addedCount = 0;
128
+ for (const item of list) {
129
+ const outcome = await processScannedProductItem(host, item, scanCode, bridge);
130
+ if (outcome === "added") {
131
+ addedCount += 1;
132
+ }
133
+ if (outcome === "cancelled") {
134
+ return { status: "cancelled" };
135
+ }
136
+ if (outcome === "pending") {
137
+ return { status: "pending", kind: "requiresDetail" };
138
+ }
139
+ }
140
+ if (addedCount > 0) {
141
+ (_f = bridge == null ? void 0 : bridge.onNotify) == null ? void 0 : _f.call(bridge, "success");
142
+ return { status: "success", kind: "products", meta: { count: addedCount } };
143
+ }
144
+ return { status: "failed", reason: "no_bridge" };
145
+ }
146
+ if (searchType === "order") {
147
+ const orderId = (data == null ? void 0 : data.order_id) ?? (data == null ? void 0 : data.id);
148
+ if (!orderId) {
149
+ (_g = bridge == null ? void 0 : bridge.onNotify) == null ? void 0 : _g.call(bridge, "fail", "pisell2.text.scan-global-failed");
150
+ return { status: "failed", reason: "invalid_data" };
151
+ }
152
+ if (!(bridge == null ? void 0 : bridge.openOrder)) {
153
+ return { status: "pending", kind: "openOrder" };
154
+ }
155
+ bridge.openOrder({
156
+ order_id: Number(orderId),
157
+ business_code: host.getBusinessCode()
158
+ });
159
+ return { status: "pending", kind: "openOrder" };
160
+ }
161
+ return { status: "failed", reason: "invalid_data" };
162
+ }
163
+ // Annotate the CommonJS export names for ESM import in node:
164
+ 0 && (module.exports = {
165
+ applyGlobalScan
166
+ });
@@ -0,0 +1,32 @@
1
+ /**
2
+ * 全局扫码搜索结果格式化(对齐 ticketBooking `formatScanGlobal`)。
3
+ */
4
+ export type GlobalScanSearchType = 'customer' | 'wallet' | 'walletPass' | 'product' | 'local_product' | 'order';
5
+ export interface GlobalScanFormattedResult {
6
+ searchType: GlobalScanSearchType;
7
+ data: any;
8
+ scanCode: string;
9
+ }
10
+ interface RawScanSearchResult {
11
+ searchType?: GlobalScanSearchType;
12
+ response?: {
13
+ status?: boolean;
14
+ code?: number;
15
+ message?: string;
16
+ data?: any;
17
+ };
18
+ }
19
+ /**
20
+ * 将 handleGlobalScan 返回的原始结构格式化为 UI/OS 统一结构。
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const formatted = formatGlobalScanResult(
25
+ * { searchType: 'wallet', response: { code: 200, data: { customer: {...} } } },
26
+ * 'WL123',
27
+ * );
28
+ * // => { searchType: 'wallet', data: customerObj, scanCode: 'WL123' }
29
+ * ```
30
+ */
31
+ export declare function formatGlobalScanResult(raw: RawScanSearchResult | null | undefined, scanCode: string): GlobalScanFormattedResult | null;
32
+ export {};
@@ -0,0 +1,51 @@
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/scan/formatGlobalScan.ts
20
+ var formatGlobalScan_exports = {};
21
+ __export(formatGlobalScan_exports, {
22
+ formatGlobalScanResult: () => formatGlobalScanResult
23
+ });
24
+ module.exports = __toCommonJS(formatGlobalScan_exports);
25
+ function formatGlobalScanResult(raw, scanCode) {
26
+ var _a;
27
+ if (!(raw == null ? void 0 : raw.searchType))
28
+ return null;
29
+ const { searchType } = raw;
30
+ const { data: resultData, code } = raw.response || {};
31
+ if (code !== 200 && searchType !== "local_product") {
32
+ return null;
33
+ }
34
+ if (searchType === "wallet") {
35
+ return { searchType, data: resultData == null ? void 0 : resultData.customer, scanCode };
36
+ }
37
+ if (searchType === "walletPass") {
38
+ return { searchType, data: (_a = resultData == null ? void 0 : resultData[0]) == null ? void 0 : _a.customer, scanCode };
39
+ }
40
+ if (searchType === "product" || searchType === "local_product") {
41
+ return { searchType, data: resultData, scanCode };
42
+ }
43
+ if (searchType === "order") {
44
+ return { searchType, data: resultData, scanCode };
45
+ }
46
+ return null;
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ formatGlobalScanResult
51
+ });
@@ -0,0 +1,21 @@
1
+ /**
2
+ * 扫码商品条码预选规格纯函数(对齐 ticketBooking addServiceVariant/utils)。
3
+ */
4
+ /** 套餐商品 */
5
+ export declare function isScanProductBundle(item: any): boolean;
6
+ /** 单规格 / 选项组商品 */
7
+ export declare function isScanProductOption(item: any): boolean;
8
+ /**
9
+ * 根据条码匹配 variant,生成 cartDetailValue(对齐 ticketBooking `genValues`)。
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const values = genScanProductValues(catalogItem, '6901234567890');
14
+ * const itemWithSelection = { ...catalogItem, cartDetailValue: values };
15
+ * ```
16
+ */
17
+ export declare function genScanProductValues(item: any, code: string): Record<string, any>;
18
+ /**
19
+ * 统计条码命中的 variant 数量(多命中时需弹窗选择)。
20
+ */
21
+ export declare function countScanVariantMatches(item: any, code: string): number;
@@ -0,0 +1,127 @@
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/scan/scanProductValues.ts
20
+ var scanProductValues_exports = {};
21
+ __export(scanProductValues_exports, {
22
+ countScanVariantMatches: () => countScanVariantMatches,
23
+ genScanProductValues: () => genScanProductValues,
24
+ isScanProductBundle: () => isScanProductBundle,
25
+ isScanProductOption: () => isScanProductOption
26
+ });
27
+ module.exports = __toCommonJS(scanProductValues_exports);
28
+ function isScanProductBundle(item) {
29
+ return ((item == null ? void 0 : item.bundle_group_count) || 0) > 0;
30
+ }
31
+ function isScanProductOption(item) {
32
+ var _a;
33
+ return ((item == null ? void 0 : item.option_group_count) || 0) > 0 || (((_a = item == null ? void 0 : item.option_group) == null ? void 0 : _a.length) || 0) > 0;
34
+ }
35
+ function formatVariantGroupTitle(title, variantGroup = []) {
36
+ try {
37
+ return variantGroup.map((group) => {
38
+ const value = title == null ? void 0 : title[group == null ? void 0 : group.position_id];
39
+ return value ? `${(group == null ? void 0 : group.name) || "-"}: ${value}` : "";
40
+ }).filter(Boolean).join(", ");
41
+ } catch {
42
+ return "";
43
+ }
44
+ }
45
+ function formatDataKey(data) {
46
+ var _a, _b, _c, _d;
47
+ const next = { ...data };
48
+ let key = `${next.product_id}`;
49
+ let rowKey = key;
50
+ if (next.product_variant_id) {
51
+ const str = `_${next.product_variant_id}`;
52
+ key += str;
53
+ rowKey += str;
54
+ }
55
+ if ((_a = next == null ? void 0 : next.option) == null ? void 0 : _a.length) {
56
+ for (const item of next.option) {
57
+ const str = `_${item.option_group_id}_${item.product_option_item_id}`;
58
+ key += str;
59
+ rowKey += `${str}_${item.quantity || item.num}`;
60
+ }
61
+ }
62
+ if ((_b = next == null ? void 0 : next.bundle) == null ? void 0 : _b.length) {
63
+ for (const item of next.bundle) {
64
+ let str = `_${item.group_id}_${item.bundle_product_id}`;
65
+ key += str;
66
+ rowKey += `${str}_${item.quantity || item.num}`;
67
+ if (item == null ? void 0 : item.option) {
68
+ for (const opt of item.option) {
69
+ const optStr = `_${opt.option_group_id}_${opt.product_option_item_id}`;
70
+ key += optStr;
71
+ rowKey += `${optStr}_${opt.quantity || opt.num}`;
72
+ }
73
+ }
74
+ }
75
+ }
76
+ if (next == null ? void 0 : next.session) {
77
+ const str = `_${(_c = next.session) == null ? void 0 : _c.key}`;
78
+ key += str;
79
+ rowKey += str;
80
+ }
81
+ if (next == null ? void 0 : next.schedule) {
82
+ const str = `_${(_d = next.schedule) == null ? void 0 : _d.key}`;
83
+ key += str;
84
+ rowKey += str;
85
+ }
86
+ next.key = key;
87
+ next.rowKey = rowKey;
88
+ return next;
89
+ }
90
+ function genScanProductValues(item, code) {
91
+ var _a, _b;
92
+ const params = {
93
+ bundle: [],
94
+ option: [],
95
+ product_id: item.id,
96
+ product_variant_id: 0,
97
+ quantity: 1,
98
+ rowKey: "",
99
+ session: null
100
+ };
101
+ if (((_a = item == null ? void 0 : item.variant_group) == null ? void 0 : _a.length) || ((_b = item == null ? void 0 : item.option_group) == null ? void 0 : _b.length)) {
102
+ const variantItem = (item.variant || []).find(
103
+ (v) => (v == null ? void 0 : v.code) === code || (v == null ? void 0 : v.barcode) === code
104
+ );
105
+ if (variantItem) {
106
+ params.price = Number((variantItem == null ? void 0 : variantItem.price) || 0);
107
+ params.product_variant_id = variantItem.id;
108
+ params.product_option_string = formatVariantGroupTitle(
109
+ variantItem == null ? void 0 : variantItem.title,
110
+ (item == null ? void 0 : item.variant_group) || []
111
+ );
112
+ }
113
+ }
114
+ return formatDataKey(params);
115
+ }
116
+ function countScanVariantMatches(item, code) {
117
+ return ((item == null ? void 0 : item.variant) || []).filter(
118
+ (v) => (v == null ? void 0 : v.code) === code || (v == null ? void 0 : v.barcode) === code
119
+ ).length;
120
+ }
121
+ // Annotate the CommonJS export names for ESM import in node:
122
+ 0 && (module.exports = {
123
+ countScanVariantMatches,
124
+ genScanProductValues,
125
+ isScanProductBundle,
126
+ isScanProductOption
127
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.187",
4
+ "version": "2.2.189",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",