@pisell/pisellos 2.2.188 → 2.2.190

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 (36) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/Order/index.d.ts +1 -0
  3. package/dist/modules/Order/index.js +53 -45
  4. package/dist/modules/Order/types.d.ts +2 -0
  5. package/dist/modules/Order/utils.js +3 -1
  6. package/dist/solution/BaseSales/index.js +61 -53
  7. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -2
  8. package/dist/solution/BookingByStep/index.d.ts +1 -1
  9. package/dist/solution/BookingTicket/index.d.ts +16 -1
  10. package/dist/solution/BookingTicket/index.js +117 -6
  11. package/dist/solution/BookingTicket/types.d.ts +48 -0
  12. package/dist/solution/BookingTicket/types.js +5 -1
  13. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  14. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +394 -0
  15. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  16. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
  17. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  18. package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
  19. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  20. package/lib/modules/Order/index.d.ts +1 -0
  21. package/lib/modules/Order/index.js +15 -10
  22. package/lib/modules/Order/types.d.ts +2 -0
  23. package/lib/modules/Order/utils.js +1 -0
  24. package/lib/solution/BaseSales/index.js +12 -4
  25. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +11 -2
  26. package/lib/solution/BookingByStep/index.d.ts +1 -1
  27. package/lib/solution/BookingTicket/index.d.ts +16 -1
  28. package/lib/solution/BookingTicket/index.js +56 -0
  29. package/lib/solution/BookingTicket/types.d.ts +48 -0
  30. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  31. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +166 -0
  32. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  33. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +51 -0
  34. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  35. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +127 -0
  36. package/package.json +1 -1
@@ -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.188",
4
+ "version": "2.2.190",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",