@pisell/pisellos 2.2.147 → 2.2.149
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.
- package/dist/apis/picoding.d.ts +0 -0
- package/dist/apis/picoding.js +1 -0
- package/dist/model/strategy/adapter/index.d.ts +2 -0
- package/dist/model/strategy/adapter/index.js +3 -1
- package/dist/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
- package/dist/model/strategy/adapter/itemRule/adapter.js +483 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
- package/dist/model/strategy/adapter/itemRule/examples.d.ts +79 -0
- package/dist/model/strategy/adapter/itemRule/examples.js +382 -0
- package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/dist/model/strategy/adapter/itemRule/index.js +5 -0
- package/dist/model/strategy/adapter/itemRule/type.d.ts +225 -0
- package/dist/model/strategy/adapter/itemRule/type.js +101 -0
- package/dist/modules/Cart/types.d.ts +2 -0
- package/dist/modules/Cart/utils/cartProduct.js +22 -1
- package/dist/modules/Cart/utils/changePrice.js +6 -0
- package/dist/modules/Date/index.d.ts +1 -1
- package/dist/modules/Date/index.js +16 -8
- package/dist/modules/Date/types.d.ts +3 -1
- package/dist/modules/OpenData/index.d.ts +24 -0
- package/dist/modules/OpenData/index.js +173 -0
- package/dist/modules/OpenData/types.d.ts +73 -0
- package/dist/modules/OpenData/types.js +1 -0
- package/dist/modules/OpenData/utils.d.ts +2 -0
- package/dist/modules/OpenData/utils.js +75 -0
- package/dist/modules/Order/index.d.ts +171 -1
- package/dist/modules/Order/index.js +2052 -112
- package/dist/modules/Order/types.d.ts +441 -20
- package/dist/modules/Order/types.js +23 -0
- package/dist/modules/Order/utils.d.ts +120 -0
- package/dist/modules/Order/utils.js +653 -2
- package/dist/modules/Product/utils.js +2 -2
- package/dist/modules/ProductList/index.js +2 -1
- package/dist/modules/Quotation/index.d.ts +8 -1
- package/dist/modules/Quotation/index.js +40 -10
- package/dist/modules/Quotation/types.d.ts +5 -0
- package/dist/modules/Rules/index.d.ts +3 -1
- package/dist/modules/Rules/index.js +136 -50
- package/dist/modules/Rules/types.d.ts +6 -0
- package/dist/modules/Rules/types.js +8 -0
- package/dist/modules/SalesSummary/index.d.ts +70 -0
- package/dist/modules/SalesSummary/index.js +175 -0
- package/dist/modules/SalesSummary/types.d.ts +64 -0
- package/dist/modules/SalesSummary/types.js +1 -0
- package/dist/modules/SalesSummary/utils.d.ts +34 -0
- package/dist/modules/SalesSummary/utils.js +488 -0
- package/dist/modules/ScanOrderLogger/index.d.ts +21 -0
- package/dist/modules/ScanOrderLogger/index.js +161 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.js +203 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
- package/dist/modules/ScanOrderLogger/types.d.ts +52 -0
- package/dist/modules/ScanOrderLogger/types.js +1 -0
- package/dist/modules/Schedule/getDateIsInSchedule.js +7 -7
- package/dist/modules/Schedule/index.d.ts +4 -13
- package/dist/modules/Schedule/index.js +6 -23
- package/dist/modules/Schedule/utils.d.ts +1 -1
- package/dist/modules/Summary/index.d.ts +3 -0
- package/dist/modules/Summary/index.js +134 -15
- package/dist/modules/Summary/types.d.ts +7 -0
- package/dist/modules/Summary/utils.d.ts +104 -1
- package/dist/modules/Summary/utils.js +1116 -13
- package/dist/modules/index.d.ts +4 -0
- package/dist/modules/index.js +5 -1
- package/dist/server/index.d.ts +41 -4
- package/dist/server/index.js +900 -405
- package/dist/server/modules/order/index.d.ts +10 -2
- package/dist/server/modules/order/index.js +251 -196
- package/dist/server/modules/products/index.d.ts +26 -0
- package/dist/server/modules/products/index.js +618 -338
- package/dist/server/modules/products/types.d.ts +5 -1
- package/dist/solution/BaseSales/index.d.ts +175 -0
- package/dist/solution/BaseSales/index.js +1293 -0
- package/dist/solution/BaseSales/types.d.ts +305 -0
- package/dist/solution/BaseSales/types.js +38 -0
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +143 -0
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +159 -0
- package/dist/solution/BaseSales/utils.d.ts +40 -0
- package/dist/solution/BaseSales/utils.js +222 -0
- package/dist/solution/BookingByStep/index.d.ts +14 -0
- package/dist/solution/BookingByStep/index.js +699 -212
- package/dist/solution/BookingByStep/types.d.ts +3 -1
- package/dist/solution/BookingByStep/types.js +5 -1
- package/dist/solution/BookingByStep/utils/capacity.js +1 -1
- package/dist/solution/BookingByStep/utils/resources.js +6 -1
- package/dist/solution/BookingTicket/index.d.ts +113 -15
- package/dist/solution/BookingTicket/index.js +534 -196
- package/dist/solution/BookingTicket/types.d.ts +69 -6
- package/dist/solution/BookingTicket/types.js +40 -9
- package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +37 -0
- package/dist/solution/BookingTicket/utils/bookingStatus.js +66 -0
- package/dist/solution/BookingTicket/utils/cartView.d.ts +26 -0
- package/dist/solution/BookingTicket/utils/cartView.js +84 -0
- package/dist/solution/Sales/index.d.ts +1 -0
- package/dist/solution/Sales/index.js +1 -0
- package/dist/solution/ScanOrder/index.d.ts +146 -0
- package/dist/solution/ScanOrder/index.js +3029 -0
- package/dist/solution/ScanOrder/types.d.ts +305 -0
- package/dist/solution/ScanOrder/types.js +35 -0
- package/dist/solution/ScanOrder/utils.d.ts +167 -0
- package/dist/solution/ScanOrder/utils.js +768 -0
- package/dist/solution/ShopDiscount/index.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.js +9 -5
- package/dist/solution/ShopDiscount/types.d.ts +4 -0
- package/dist/solution/VenueBooking/index.d.ts +197 -0
- package/dist/solution/VenueBooking/index.js +3411 -0
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/dist/solution/VenueBooking/types.d.ts +153 -0
- package/dist/solution/VenueBooking/types.js +21 -0
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
- package/dist/solution/VenueBooking/utils/dateSummary.js +104 -0
- package/dist/solution/VenueBooking/utils/resource.d.ts +14 -0
- package/dist/solution/VenueBooking/utils/resource.js +130 -0
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +34 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +224 -0
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/dist/solution/VenueBooking/utils/timeSlot.js +453 -0
- package/dist/solution/VenueBooking/utils.d.ts +1 -0
- package/dist/solution/VenueBooking/utils.js +1 -0
- package/dist/solution/index.d.ts +3 -0
- package/dist/solution/index.js +4 -1
- package/lib/apis/picoding.d.ts +0 -0
- package/lib/apis/picoding.js +0 -0
- package/lib/model/strategy/adapter/index.d.ts +2 -0
- package/lib/model/strategy/adapter/index.js +6 -0
- package/lib/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
- package/lib/model/strategy/adapter/itemRule/adapter.js +377 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
- package/lib/model/strategy/adapter/itemRule/examples.d.ts +79 -0
- package/lib/model/strategy/adapter/itemRule/examples.js +316 -0
- package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/lib/model/strategy/adapter/itemRule/index.js +60 -0
- package/lib/model/strategy/adapter/itemRule/type.d.ts +225 -0
- package/lib/model/strategy/adapter/itemRule/type.js +46 -0
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/modules/Cart/types.d.ts +2 -0
- package/lib/modules/Cart/utils/cartProduct.js +17 -1
- package/lib/modules/Cart/utils/changePrice.js +5 -0
- package/lib/modules/Date/index.d.ts +1 -1
- package/lib/modules/Date/index.js +7 -1
- package/lib/modules/Date/types.d.ts +3 -1
- package/lib/modules/OpenData/index.d.ts +24 -0
- package/lib/modules/OpenData/index.js +119 -0
- package/lib/modules/OpenData/types.d.ts +73 -0
- package/lib/modules/OpenData/types.js +17 -0
- package/lib/modules/OpenData/utils.d.ts +2 -0
- package/lib/modules/OpenData/utils.js +111 -0
- package/lib/modules/Order/index.d.ts +171 -1
- package/lib/modules/Order/index.js +1396 -5
- package/lib/modules/Order/types.d.ts +441 -20
- package/lib/modules/Order/types.js +1 -0
- package/lib/modules/Order/utils.d.ts +120 -0
- package/lib/modules/Order/utils.js +562 -2
- package/lib/modules/Product/utils.js +2 -2
- package/lib/modules/ProductList/index.js +2 -1
- package/lib/modules/Quotation/index.d.ts +8 -1
- package/lib/modules/Quotation/index.js +33 -4
- package/lib/modules/Quotation/types.d.ts +5 -0
- package/lib/modules/Rules/index.d.ts +3 -1
- package/lib/modules/Rules/index.js +46 -6
- package/lib/modules/Rules/types.d.ts +6 -0
- package/lib/modules/Rules/types.js +11 -2
- package/lib/modules/SalesSummary/index.d.ts +70 -0
- package/lib/modules/SalesSummary/index.js +106 -0
- package/lib/modules/SalesSummary/types.d.ts +64 -0
- package/lib/modules/SalesSummary/types.js +17 -0
- package/lib/modules/SalesSummary/utils.d.ts +34 -0
- package/lib/modules/SalesSummary/utils.js +430 -0
- package/lib/modules/ScanOrderLogger/index.d.ts +21 -0
- package/lib/modules/ScanOrderLogger/index.js +135 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.js +148 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
- package/lib/modules/ScanOrderLogger/types.d.ts +52 -0
- package/lib/modules/ScanOrderLogger/types.js +17 -0
- package/lib/modules/Schedule/getDateIsInSchedule.js +5 -5
- package/lib/modules/Schedule/index.d.ts +4 -13
- package/lib/modules/Schedule/index.js +4 -15
- package/lib/modules/Schedule/utils.d.ts +1 -1
- package/lib/modules/Summary/index.d.ts +3 -0
- package/lib/modules/Summary/index.js +61 -2
- package/lib/modules/Summary/types.d.ts +7 -0
- package/lib/modules/Summary/utils.d.ts +104 -1
- package/lib/modules/Summary/utils.js +659 -8
- package/lib/modules/index.d.ts +4 -0
- package/lib/modules/index.js +9 -1
- package/lib/server/index.d.ts +41 -4
- package/lib/server/index.js +272 -10
- package/lib/server/modules/order/index.d.ts +10 -2
- package/lib/server/modules/order/index.js +31 -4
- package/lib/server/modules/products/index.d.ts +26 -0
- package/lib/server/modules/products/index.js +174 -22
- package/lib/server/modules/products/types.d.ts +5 -1
- package/lib/solution/BaseSales/index.d.ts +175 -0
- package/lib/solution/BaseSales/index.js +655 -0
- package/lib/solution/BaseSales/types.d.ts +305 -0
- package/lib/solution/BaseSales/types.js +40 -0
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +143 -0
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +160 -0
- package/lib/solution/BaseSales/utils.d.ts +40 -0
- package/lib/solution/BaseSales/utils.js +200 -0
- package/lib/solution/BookingByStep/index.d.ts +14 -0
- package/lib/solution/BookingByStep/index.js +469 -91
- package/lib/solution/BookingByStep/types.d.ts +3 -1
- package/lib/solution/BookingByStep/types.js +10 -0
- package/lib/solution/BookingByStep/utils/capacity.js +1 -1
- package/lib/solution/BookingByStep/utils/resources.js +5 -2
- package/lib/solution/BookingTicket/index.d.ts +113 -15
- package/lib/solution/BookingTicket/index.js +253 -61
- package/lib/solution/BookingTicket/types.d.ts +69 -6
- package/lib/solution/BookingTicket/types.js +16 -14
- package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +37 -0
- package/lib/solution/BookingTicket/utils/bookingStatus.js +65 -0
- package/lib/solution/BookingTicket/utils/cartView.d.ts +26 -0
- package/lib/solution/BookingTicket/utils/cartView.js +103 -0
- package/lib/solution/Sales/index.d.ts +1 -0
- package/lib/solution/ScanOrder/index.d.ts +146 -0
- package/lib/solution/ScanOrder/index.js +1820 -0
- package/lib/solution/ScanOrder/types.d.ts +305 -0
- package/lib/solution/ScanOrder/types.js +36 -0
- package/lib/solution/ScanOrder/utils.d.ts +167 -0
- package/lib/solution/ScanOrder/utils.js +639 -0
- package/lib/solution/ShopDiscount/index.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.js +9 -4
- package/lib/solution/ShopDiscount/types.d.ts +4 -0
- package/lib/solution/VenueBooking/index.d.ts +197 -0
- package/lib/solution/VenueBooking/index.js +1892 -0
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/lib/solution/VenueBooking/types.d.ts +153 -0
- package/lib/solution/VenueBooking/types.js +44 -0
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
- package/lib/solution/VenueBooking/utils/dateSummary.js +110 -0
- package/lib/solution/VenueBooking/utils/resource.d.ts +14 -0
- package/lib/solution/VenueBooking/utils/resource.js +91 -0
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +34 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +225 -0
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/lib/solution/VenueBooking/utils/timeSlot.js +339 -0
- package/lib/solution/VenueBooking/utils.d.ts +1 -0
- package/lib/solution/VenueBooking/utils.js +69 -0
- package/lib/solution/index.d.ts +3 -0
- package/lib/solution/index.js +7 -1
- package/package.json +1 -1
|
@@ -33,19 +33,58 @@ __export(Order_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(Order_exports);
|
|
35
35
|
var import_BaseModule = require("../BaseModule");
|
|
36
|
+
var import_types = require("./types");
|
|
36
37
|
var import_utils = require("./utils");
|
|
37
38
|
var import_utils2 = require("../Product/utils");
|
|
38
39
|
var import_dayjs = __toESM(require("dayjs"));
|
|
40
|
+
var import_utils3 = require("../../solution/ScanOrder/utils");
|
|
41
|
+
var import_Discount = require("../Discount");
|
|
42
|
+
var import_Rules = require("../Rules");
|
|
43
|
+
var import_types2 = require("../Rules/types");
|
|
44
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
45
|
+
var import_lodash_es = require("lodash-es");
|
|
46
|
+
var LOCAL_ORDER_STORE_NAME = "orders";
|
|
39
47
|
var OrderModule = class extends import_BaseModule.BaseModule {
|
|
40
|
-
// LoggerManager 实例
|
|
41
48
|
constructor(name, version) {
|
|
42
49
|
super(name || "order", version);
|
|
43
50
|
this.defaultName = "order";
|
|
44
51
|
this.defaultVersion = "1.0.0";
|
|
45
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Populate `savedAmount` on each discount based on product-level discount details.
|
|
55
|
+
* Only selected discounts get a non-zero value.
|
|
56
|
+
*/
|
|
57
|
+
static populateSavedAmounts(productList, discountList) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const savedMap = /* @__PURE__ */ new Map();
|
|
60
|
+
for (const product of productList) {
|
|
61
|
+
const qty = product.num || 1;
|
|
62
|
+
for (const pd of product.discount_list || []) {
|
|
63
|
+
const discountKey = ((_a = pd.discount) == null ? void 0 : _a.resource_id) || pd.id;
|
|
64
|
+
if (discountKey == null)
|
|
65
|
+
continue;
|
|
66
|
+
const amount = new import_decimal.default(pd.amount || 0).times(qty).plus(((_b = pd.metadata) == null ? void 0 : _b.product_discount_difference) || 0);
|
|
67
|
+
savedMap.set(
|
|
68
|
+
discountKey,
|
|
69
|
+
(savedMap.get(discountKey) || new import_decimal.default(0)).plus(amount)
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const d of discountList) {
|
|
74
|
+
const key = d.id;
|
|
75
|
+
d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
46
78
|
async initialize(core, options) {
|
|
79
|
+
var _a;
|
|
47
80
|
this.core = core;
|
|
48
81
|
this.store = options.store;
|
|
82
|
+
if (!this.store.tempOrder) {
|
|
83
|
+
this.store.tempOrder = null;
|
|
84
|
+
}
|
|
85
|
+
if (!this.store.summary) {
|
|
86
|
+
this.store.summary = (0, import_utils.createEmptySummary)();
|
|
87
|
+
}
|
|
49
88
|
this.request = this.core.getPlugin("request");
|
|
50
89
|
const appPlugin = this.core.getPlugin("app");
|
|
51
90
|
if (!appPlugin) {
|
|
@@ -53,6 +92,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
53
92
|
}
|
|
54
93
|
const app = appPlugin.getApp();
|
|
55
94
|
this.logger = app.logger;
|
|
95
|
+
this.dbManager = app.sqlite;
|
|
96
|
+
this.window = this.core.getPlugin("window");
|
|
97
|
+
const otherParams = options.otherParams || {};
|
|
98
|
+
this.cacheId = otherParams.cacheId;
|
|
99
|
+
this.salesSummaryModuleName = otherParams.salesSummaryModuleName;
|
|
100
|
+
this.rulesHooksOverride = (_a = otherParams.rules) == null ? void 0 : _a.hooks;
|
|
101
|
+
this.otherParams = otherParams;
|
|
102
|
+
this.registerDiscountModules(options);
|
|
103
|
+
this.restoreTempOrderFromStorage();
|
|
56
104
|
this.logInfo("OrderModule initialized successfully");
|
|
57
105
|
}
|
|
58
106
|
/**
|
|
@@ -91,6 +139,1178 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
91
139
|
});
|
|
92
140
|
}
|
|
93
141
|
}
|
|
142
|
+
// ─── Discount: 子模块注册 ───
|
|
143
|
+
registerDiscountModules(options) {
|
|
144
|
+
let targetCacheData = {};
|
|
145
|
+
if (this.cacheId && this.window) {
|
|
146
|
+
const sessionData = this.window.sessionStorage.getItem(this.name);
|
|
147
|
+
if (sessionData) {
|
|
148
|
+
try {
|
|
149
|
+
const data = JSON.parse(sessionData);
|
|
150
|
+
targetCacheData = (data == null ? void 0 : data[this.cacheId]) || {};
|
|
151
|
+
} catch {
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const discount = new import_Discount.DiscountModule(`${this.name}_discount`);
|
|
156
|
+
this.core.registerModule(discount, {
|
|
157
|
+
initialState: targetCacheData == null ? void 0 : targetCacheData[discount.name],
|
|
158
|
+
otherParams: {
|
|
159
|
+
fatherModule: this.name,
|
|
160
|
+
openCache: !!this.cacheId,
|
|
161
|
+
cacheId: this.cacheId
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
this.store.discount = discount;
|
|
165
|
+
const rules = new import_Rules.RulesModule(`${this.name}_rules`);
|
|
166
|
+
this.core.registerModule(rules, {
|
|
167
|
+
hooks: this.rulesHooksOverride || this.createDefaultRulesHooks()
|
|
168
|
+
});
|
|
169
|
+
this.store.rules = rules;
|
|
170
|
+
}
|
|
171
|
+
createDefaultRulesHooks() {
|
|
172
|
+
return (0, import_utils.createDefaultOrderRulesHooks)();
|
|
173
|
+
}
|
|
174
|
+
// ─── Discount: 公共 API ───
|
|
175
|
+
async loadDiscountConfig(params) {
|
|
176
|
+
var _a, _b, _c, _d;
|
|
177
|
+
const discountList = await ((_a = this.store.discount) == null ? void 0 : _a.loadPrepareConfig({
|
|
178
|
+
customer_id: params.customerId,
|
|
179
|
+
action: params.action || "create",
|
|
180
|
+
with_good_pass: 1,
|
|
181
|
+
with_discount_card: 1,
|
|
182
|
+
with_wallet_pass_holder: 1,
|
|
183
|
+
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
184
|
+
}));
|
|
185
|
+
if (discountList) {
|
|
186
|
+
(_b = this.store.discount) == null ? void 0 : _b.setDiscountList(discountList);
|
|
187
|
+
}
|
|
188
|
+
if ((_d = (_c = this.store.tempOrder) == null ? void 0 : _c.products) == null ? void 0 : _d.length) {
|
|
189
|
+
this.applyDiscount();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
getDiscountList() {
|
|
193
|
+
var _a;
|
|
194
|
+
return ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
|
|
195
|
+
}
|
|
196
|
+
async scanCode(code, customerId) {
|
|
197
|
+
var _a, _b, _c, _d, _e;
|
|
198
|
+
const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, customerId)) || [];
|
|
199
|
+
const rulesModule = this.store.rules;
|
|
200
|
+
if (!rulesModule) {
|
|
201
|
+
return {
|
|
202
|
+
type: "clientCalc",
|
|
203
|
+
isAvailable: false,
|
|
204
|
+
discountList: this.getDiscountList(),
|
|
205
|
+
unavailableReason: import_types2.UnavailableReason.Unknown
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
if (!resultDiscountList.length) {
|
|
209
|
+
return {
|
|
210
|
+
type: "server",
|
|
211
|
+
isAvailable: false,
|
|
212
|
+
discountList: this.getDiscountList()
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const withScanList = resultDiscountList.map((item) => ({
|
|
216
|
+
...item,
|
|
217
|
+
isScan: true
|
|
218
|
+
}));
|
|
219
|
+
const currentSelected = this.getDiscountList().filter((n) => n.isSelected);
|
|
220
|
+
if (currentSelected.length && currentSelected.some((n) => withScanList.some((m) => m.id === n.id))) {
|
|
221
|
+
return {
|
|
222
|
+
type: "clientCalc",
|
|
223
|
+
isAvailable: true,
|
|
224
|
+
discountList: this.getDiscountList()
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
const tempOrder = this.store.tempOrder;
|
|
228
|
+
const holders = ((_b = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _b.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
|
|
229
|
+
const { isAvailable, discountList: newDiscountList, unavailableReason } = rulesModule.isDiscountListAvailable({
|
|
230
|
+
productList: (tempOrder == null ? void 0 : tempOrder.products) || [],
|
|
231
|
+
oldDiscountList: this.getDiscountList(),
|
|
232
|
+
newDiscountList: withScanList,
|
|
233
|
+
orderTotalAmount: Number(((_c = this.store.summary) == null ? void 0 : _c.total_amount) || 0),
|
|
234
|
+
holders,
|
|
235
|
+
isFormSubject: !!((_d = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _d.type) && tempOrder.holder.type === "form"
|
|
236
|
+
}) || { isAvailable: false, discountList: this.getDiscountList() };
|
|
237
|
+
if (isAvailable && newDiscountList) {
|
|
238
|
+
(_e = this.store.discount) == null ? void 0 : _e.setDiscountList(newDiscountList);
|
|
239
|
+
this.applyDiscount();
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
type: "clientCalc",
|
|
243
|
+
isAvailable: isAvailable || false,
|
|
244
|
+
discountList: newDiscountList || this.getDiscountList(),
|
|
245
|
+
unavailableReason
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
applyDiscount() {
|
|
249
|
+
var _a, _b, _c, _d, _e;
|
|
250
|
+
const tempOrder = this.store.tempOrder;
|
|
251
|
+
if (!tempOrder)
|
|
252
|
+
return;
|
|
253
|
+
const rulesModule = this.store.rules;
|
|
254
|
+
if (!rulesModule)
|
|
255
|
+
return;
|
|
256
|
+
const discountList = ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
|
|
257
|
+
const holders = ((_b = tempOrder.holder) == null ? void 0 : _b.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
|
|
258
|
+
const result = rulesModule.calcDiscount({
|
|
259
|
+
productList: tempOrder.products,
|
|
260
|
+
discountList,
|
|
261
|
+
holders,
|
|
262
|
+
isFormSubject: !!((_c = tempOrder.holder) == null ? void 0 : _c.type) && tempOrder.holder.type === "form",
|
|
263
|
+
orderTotalAmount: Number(((_d = this.store.summary) == null ? void 0 : _d.total_amount) || 0)
|
|
264
|
+
});
|
|
265
|
+
if (result == null ? void 0 : result.productList) {
|
|
266
|
+
tempOrder.products = result.productList;
|
|
267
|
+
}
|
|
268
|
+
if (result == null ? void 0 : result.discountList) {
|
|
269
|
+
OrderModule.populateSavedAmounts(
|
|
270
|
+
result.productList || tempOrder.products,
|
|
271
|
+
result.discountList
|
|
272
|
+
);
|
|
273
|
+
(_e = this.store.discount) == null ? void 0 : _e.setDiscountList(result.discountList);
|
|
274
|
+
tempOrder.discount_list = result.discountList.filter(
|
|
275
|
+
(d) => d.isSelected
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// ─── TempOrder: 初始化入口 ───
|
|
280
|
+
initTempOrder(params) {
|
|
281
|
+
if (params.cacheId !== void 0)
|
|
282
|
+
this.cacheId = params.cacheId;
|
|
283
|
+
if (params.salesSummaryModuleName !== void 0)
|
|
284
|
+
this.salesSummaryModuleName = params.salesSummaryModuleName;
|
|
285
|
+
this.restoreTempOrderFromStorage();
|
|
286
|
+
}
|
|
287
|
+
// ─── TempOrder: localStorage 持久化 ───
|
|
288
|
+
getTempOrderStorageKey() {
|
|
289
|
+
if (!this.cacheId)
|
|
290
|
+
return null;
|
|
291
|
+
return `scanOrder:tempOrder:${this.cacheId}`;
|
|
292
|
+
}
|
|
293
|
+
restoreTempOrderFromStorage() {
|
|
294
|
+
var _a, _b;
|
|
295
|
+
const key = this.getTempOrderStorageKey();
|
|
296
|
+
if (!key)
|
|
297
|
+
return;
|
|
298
|
+
if (!this.window)
|
|
299
|
+
return;
|
|
300
|
+
const cachedData = this.window.localStorage.getItem(key);
|
|
301
|
+
if (!cachedData)
|
|
302
|
+
return;
|
|
303
|
+
try {
|
|
304
|
+
const parsedData = JSON.parse(cachedData);
|
|
305
|
+
if (!(0, import_utils.isTempOrder)(parsedData)) {
|
|
306
|
+
this.window.localStorage.removeItem(key);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (Array.isArray(parsedData.products)) {
|
|
310
|
+
for (let i = 0; i < parsedData.products.length; i++) {
|
|
311
|
+
const p = parsedData.products[i];
|
|
312
|
+
if (!p || typeof p !== "object")
|
|
313
|
+
continue;
|
|
314
|
+
if (!Array.isArray(p.product_option_item)) {
|
|
315
|
+
p.product_option_item = [];
|
|
316
|
+
}
|
|
317
|
+
if (!Array.isArray(p.product_bundle)) {
|
|
318
|
+
p.product_bundle = [];
|
|
319
|
+
}
|
|
320
|
+
const row = p;
|
|
321
|
+
parsedData.products[i] = (0, import_utils3.normalizeOrderProduct)(row);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const parsedRecord = parsedData;
|
|
325
|
+
this.store.summary = parsedRecord.summary || (0, import_utils.createEmptySummary)();
|
|
326
|
+
delete parsedData.summary;
|
|
327
|
+
if (parsedRecord.lastOrderInfo) {
|
|
328
|
+
this.store.lastOrderInfo = parsedRecord.lastOrderInfo;
|
|
329
|
+
delete parsedData.lastOrderInfo;
|
|
330
|
+
}
|
|
331
|
+
if (!parsedData._extend || typeof parsedData._extend !== "object") {
|
|
332
|
+
parsedData._extend = { productsByUid: {} };
|
|
333
|
+
} else if (!parsedData._extend.productsByUid) {
|
|
334
|
+
parsedData._extend.productsByUid = {};
|
|
335
|
+
}
|
|
336
|
+
this.store.tempOrder = parsedData;
|
|
337
|
+
} catch {
|
|
338
|
+
(_b = (_a = this.window) == null ? void 0 : _a.localStorage) == null ? void 0 : _b.removeItem(key);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
persistTempOrder() {
|
|
342
|
+
const key = this.getTempOrderStorageKey();
|
|
343
|
+
if (!key || !this.store.tempOrder)
|
|
344
|
+
return;
|
|
345
|
+
if (!this.window)
|
|
346
|
+
return;
|
|
347
|
+
this.window.localStorage.setItem(key, JSON.stringify(this.store.tempOrder));
|
|
348
|
+
}
|
|
349
|
+
// ─── TempOrder: 创建 & 获取 ───
|
|
350
|
+
createDefaultTempOrderInstance() {
|
|
351
|
+
return (0, import_utils.createDefaultTempOrder)({
|
|
352
|
+
now: (0, import_utils.formatDateTime)(/* @__PURE__ */ new Date())
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
createExternalSaleNumber() {
|
|
356
|
+
var _a;
|
|
357
|
+
const timestamp = (0, import_dayjs.default)().format("YYYYMMDDHHmmssSSS");
|
|
358
|
+
const random6 = String(Math.floor(Math.random() * 1e6)).padStart(6, "0");
|
|
359
|
+
const parts = ["LOCAL"];
|
|
360
|
+
const context = (_a = this.core) == null ? void 0 : _a.context;
|
|
361
|
+
const getData = context == null ? void 0 : context.getData;
|
|
362
|
+
if (typeof getData === "function") {
|
|
363
|
+
const shopId = getData.call(context, "shop_id");
|
|
364
|
+
const deviceId = getData.call(context, "device_id");
|
|
365
|
+
if (shopId !== void 0 && shopId !== null && shopId !== "") {
|
|
366
|
+
parts.push(String(shopId));
|
|
367
|
+
}
|
|
368
|
+
if (deviceId !== void 0 && deviceId !== null && deviceId !== "") {
|
|
369
|
+
parts.push(String(deviceId).slice(-8));
|
|
370
|
+
}
|
|
371
|
+
} else {
|
|
372
|
+
this.logWarning("external_sale_number context getData unavailable", { key: "shop_id" });
|
|
373
|
+
this.logWarning("external_sale_number context getData unavailable", { key: "device_id" });
|
|
374
|
+
}
|
|
375
|
+
parts.push(timestamp, random6);
|
|
376
|
+
return parts.join("_");
|
|
377
|
+
}
|
|
378
|
+
ensureExternalSaleNumber(tempOrder) {
|
|
379
|
+
if (!tempOrder.external_sale_number) {
|
|
380
|
+
tempOrder.external_sale_number = this.createExternalSaleNumber();
|
|
381
|
+
}
|
|
382
|
+
this.ensureRequestUniqueIdempotencyToken(tempOrder);
|
|
383
|
+
return tempOrder.external_sale_number;
|
|
384
|
+
}
|
|
385
|
+
ensureRequestUniqueIdempotencyToken(tempOrder) {
|
|
386
|
+
if (!tempOrder.request_unique_idempotency_token) {
|
|
387
|
+
tempOrder.request_unique_idempotency_token = `${tempOrder.external_sale_number}_${Date.now()}`;
|
|
388
|
+
}
|
|
389
|
+
return tempOrder.request_unique_idempotency_token;
|
|
390
|
+
}
|
|
391
|
+
hasLocalDatabase() {
|
|
392
|
+
return !!this.dbManager;
|
|
393
|
+
}
|
|
394
|
+
buildLocalOrderRecord(tempOrder) {
|
|
395
|
+
const externalSaleNumber = this.ensureExternalSaleNumber(tempOrder);
|
|
396
|
+
return {
|
|
397
|
+
...tempOrder,
|
|
398
|
+
id: tempOrder.order_id ?? externalSaleNumber,
|
|
399
|
+
external_sale_number: externalSaleNumber,
|
|
400
|
+
summary: this.store.summary || (0, import_utils.createEmptySummary)(),
|
|
401
|
+
lastOrderInfo: this.store.lastOrderInfo
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
async getLocalOrderByOrderId(orderId) {
|
|
405
|
+
var _a, _b, _c, _d;
|
|
406
|
+
if (!this.dbManager || orderId === void 0 || orderId === null)
|
|
407
|
+
return null;
|
|
408
|
+
try {
|
|
409
|
+
const direct = await ((_b = (_a = this.dbManager).get) == null ? void 0 : _b.call(
|
|
410
|
+
_a,
|
|
411
|
+
LOCAL_ORDER_STORE_NAME,
|
|
412
|
+
orderId
|
|
413
|
+
));
|
|
414
|
+
if (direct)
|
|
415
|
+
return direct;
|
|
416
|
+
const orders = await ((_d = (_c = this.dbManager).getAll) == null ? void 0 : _d.call(_c, LOCAL_ORDER_STORE_NAME));
|
|
417
|
+
return (orders || []).find(
|
|
418
|
+
(order) => String(order == null ? void 0 : order.order_id) === String(orderId)
|
|
419
|
+
) || null;
|
|
420
|
+
} catch (error) {
|
|
421
|
+
this.logWarning("getLocalOrderByOrderId failed", {
|
|
422
|
+
orderId,
|
|
423
|
+
error: error instanceof Error ? error.message : String(error)
|
|
424
|
+
});
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
async getLocalOrderByOrderNumber(orderNumber) {
|
|
429
|
+
var _a, _b, _c, _d;
|
|
430
|
+
if (!this.dbManager || !orderNumber)
|
|
431
|
+
return null;
|
|
432
|
+
try {
|
|
433
|
+
const direct = await ((_b = (_a = this.dbManager).get) == null ? void 0 : _b.call(
|
|
434
|
+
_a,
|
|
435
|
+
LOCAL_ORDER_STORE_NAME,
|
|
436
|
+
orderNumber
|
|
437
|
+
));
|
|
438
|
+
if (direct)
|
|
439
|
+
return direct;
|
|
440
|
+
const orders = await ((_d = (_c = this.dbManager).getAll) == null ? void 0 : _d.call(_c, LOCAL_ORDER_STORE_NAME));
|
|
441
|
+
return (orders || []).find(
|
|
442
|
+
(order) => String(order == null ? void 0 : order.order_number) === String(orderNumber)
|
|
443
|
+
) || null;
|
|
444
|
+
} catch (error) {
|
|
445
|
+
this.logWarning("getLocalOrderByOrderNumber failed", {
|
|
446
|
+
orderNumber,
|
|
447
|
+
error: error instanceof Error ? error.message : String(error)
|
|
448
|
+
});
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
async getLocalOrderByExternalSaleNumber(externalSaleNumber) {
|
|
453
|
+
var _a, _b, _c, _d;
|
|
454
|
+
if (!this.dbManager || !externalSaleNumber)
|
|
455
|
+
return null;
|
|
456
|
+
try {
|
|
457
|
+
const direct = await ((_b = (_a = this.dbManager).get) == null ? void 0 : _b.call(
|
|
458
|
+
_a,
|
|
459
|
+
LOCAL_ORDER_STORE_NAME,
|
|
460
|
+
externalSaleNumber
|
|
461
|
+
));
|
|
462
|
+
if (direct)
|
|
463
|
+
return direct;
|
|
464
|
+
const orders = await ((_d = (_c = this.dbManager).getAll) == null ? void 0 : _d.call(_c, LOCAL_ORDER_STORE_NAME));
|
|
465
|
+
return (orders || []).find(
|
|
466
|
+
(order) => String(order == null ? void 0 : order.external_sale_number) === String(externalSaleNumber)
|
|
467
|
+
) || null;
|
|
468
|
+
} catch (error) {
|
|
469
|
+
this.logWarning("getLocalOrderByExternalSaleNumber failed", {
|
|
470
|
+
externalSaleNumber,
|
|
471
|
+
error: error instanceof Error ? error.message : String(error)
|
|
472
|
+
});
|
|
473
|
+
return null;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
async saveDraft() {
|
|
477
|
+
var _a, _b;
|
|
478
|
+
if (!this.dbManager)
|
|
479
|
+
return;
|
|
480
|
+
const tempOrder = this.ensureTempOrder();
|
|
481
|
+
const record = this.buildLocalOrderRecord(tempOrder);
|
|
482
|
+
try {
|
|
483
|
+
await ((_b = (_a = this.dbManager).update) == null ? void 0 : _b.call(_a, LOCAL_ORDER_STORE_NAME, record));
|
|
484
|
+
} catch (error) {
|
|
485
|
+
this.logWarning("saveDraft failed", {
|
|
486
|
+
externalSaleNumber: tempOrder.external_sale_number,
|
|
487
|
+
orderNumber: tempOrder.order_number,
|
|
488
|
+
orderId: tempOrder.order_id,
|
|
489
|
+
error: error instanceof Error ? error.message : String(error)
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
async hydrateTempOrderFromLocalRecord(record) {
|
|
494
|
+
return this.hydrateTempOrderFromRecord(record);
|
|
495
|
+
}
|
|
496
|
+
extractOrderIdFromSubmitResult(result) {
|
|
497
|
+
var _a, _b;
|
|
498
|
+
return ((_a = result == null ? void 0 : result.data) == null ? void 0 : _a.order_id) ?? (result == null ? void 0 : result.order_id) ?? ((_b = result == null ? void 0 : result.data) == null ? void 0 : _b.id) ?? (result == null ? void 0 : result.id) ?? null;
|
|
499
|
+
}
|
|
500
|
+
calculatePaymentTotal(payments) {
|
|
501
|
+
return (0, import_utils.mapPaymentItemsToOrderPayments)(payments, {
|
|
502
|
+
includeVoided: false
|
|
503
|
+
}).reduce((sum, payment) => {
|
|
504
|
+
const amount = new import_decimal.default(payment.amount || 0);
|
|
505
|
+
const rounding = new import_decimal.default(payment.rounding_amount || 0);
|
|
506
|
+
return sum.plus(amount.minus(rounding));
|
|
507
|
+
}, new import_decimal.default(0));
|
|
508
|
+
}
|
|
509
|
+
calculatePaidPaymentSummary(payments) {
|
|
510
|
+
return (payments || []).reduce(
|
|
511
|
+
(summary, payment) => {
|
|
512
|
+
const paymentRecord = payment;
|
|
513
|
+
if ((paymentRecord == null ? void 0 : paymentRecord.status) !== "paid")
|
|
514
|
+
return summary;
|
|
515
|
+
return {
|
|
516
|
+
customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
|
|
517
|
+
orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
|
|
518
|
+
payServiceChargeAmount: summary.payServiceChargeAmount.plus(this.calculatePaymentServiceFee(paymentRecord))
|
|
519
|
+
};
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
customerPaidAmount: new import_decimal.default(0),
|
|
523
|
+
orderPaidAmount: new import_decimal.default(0),
|
|
524
|
+
payServiceChargeAmount: new import_decimal.default(0)
|
|
525
|
+
}
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
calculatePaymentServiceFee(payment) {
|
|
529
|
+
if (payment.service_fee !== void 0 && payment.service_fee !== null && payment.service_fee !== "") {
|
|
530
|
+
return new import_decimal.default(payment.service_fee || 0);
|
|
531
|
+
}
|
|
532
|
+
const serviceCharge = payment.service_charge && typeof payment.service_charge === "object" ? payment.service_charge : {};
|
|
533
|
+
const percentage = new import_decimal.default(serviceCharge.percentage || 0);
|
|
534
|
+
const fixedAmount = new import_decimal.default(serviceCharge.amount || 0);
|
|
535
|
+
return new import_decimal.default(payment.amount || 0).times(percentage).plus(fixedAmount);
|
|
536
|
+
}
|
|
537
|
+
getPaymentTargetAmount() {
|
|
538
|
+
const tempOrder = this.ensureTempOrder();
|
|
539
|
+
const summary = this.store.summary || (0, import_utils.createEmptySummary)();
|
|
540
|
+
if (tempOrder.is_deposit === 1) {
|
|
541
|
+
return new import_decimal.default(
|
|
542
|
+
tempOrder.deposit_amount || summary.deposit_amount || 0
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
return new import_decimal.default(summary.total_amount || summary.expect_amount || 0);
|
|
546
|
+
}
|
|
547
|
+
ensureTempOrder() {
|
|
548
|
+
if (this.store.tempOrder) {
|
|
549
|
+
this.ensureExternalSaleNumber(this.store.tempOrder);
|
|
550
|
+
return this.store.tempOrder;
|
|
551
|
+
}
|
|
552
|
+
const newOrder = this.createDefaultTempOrderInstance();
|
|
553
|
+
this.ensureExternalSaleNumber(newOrder);
|
|
554
|
+
this.store.tempOrder = newOrder;
|
|
555
|
+
this.persistTempOrder();
|
|
556
|
+
return newOrder;
|
|
557
|
+
}
|
|
558
|
+
restoreOrder() {
|
|
559
|
+
const freshTempOrder = this.createDefaultTempOrderInstance();
|
|
560
|
+
this.ensureExternalSaleNumber(freshTempOrder);
|
|
561
|
+
this.store.tempOrder = freshTempOrder;
|
|
562
|
+
this.store.summary = (0, import_utils.createEmptySummary)();
|
|
563
|
+
this.store.lastOrderInfo = void 0;
|
|
564
|
+
this.persistTempOrder();
|
|
565
|
+
return freshTempOrder;
|
|
566
|
+
}
|
|
567
|
+
getTempOrder() {
|
|
568
|
+
return this.store.tempOrder;
|
|
569
|
+
}
|
|
570
|
+
getOrderIdentity() {
|
|
571
|
+
var _a;
|
|
572
|
+
const tempOrder = this.store.tempOrder;
|
|
573
|
+
if (!tempOrder)
|
|
574
|
+
return null;
|
|
575
|
+
const lastOrderInfo = this.store.lastOrderInfo || {};
|
|
576
|
+
const orderId = tempOrder.order_id ?? lastOrderInfo.order_id ?? lastOrderInfo.id ?? null;
|
|
577
|
+
return {
|
|
578
|
+
localId: this.cacheId || ((_a = tempOrder._extend) == null ? void 0 : _a.localId),
|
|
579
|
+
orderId,
|
|
580
|
+
externalSaleNumber: tempOrder.external_sale_number || lastOrderInfo.external_sale_number || "",
|
|
581
|
+
orderNumber: tempOrder.order_number || lastOrderInfo.order_number || "",
|
|
582
|
+
shopOrderNumber: tempOrder.shop_order_number || lastOrderInfo.shop_order_number || "",
|
|
583
|
+
shopFullOrderNumber: tempOrder.shop_full_order_number || lastOrderInfo.shop_full_order_number || "",
|
|
584
|
+
isSubmitted: orderId !== null && orderId !== void 0
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
getOrderSyncState() {
|
|
588
|
+
const tempOrder = this.store.tempOrder;
|
|
589
|
+
if (!tempOrder)
|
|
590
|
+
return "local";
|
|
591
|
+
if (this.store.syncState)
|
|
592
|
+
return this.store.syncState;
|
|
593
|
+
if (this.store.lastOrderInfo)
|
|
594
|
+
return "remoteLoaded";
|
|
595
|
+
if (tempOrder.order_id)
|
|
596
|
+
return "submitted";
|
|
597
|
+
return "local";
|
|
598
|
+
}
|
|
599
|
+
getOrderAmountSnapshot() {
|
|
600
|
+
const tempOrder = this.store.tempOrder;
|
|
601
|
+
if (!tempOrder)
|
|
602
|
+
return null;
|
|
603
|
+
const summary = this.store.summary || (0, import_utils.createEmptySummary)();
|
|
604
|
+
const depositAmount = tempOrder.deposit_amount || summary.deposit_amount || "0.00";
|
|
605
|
+
const targetAmount = tempOrder.is_deposit === 1 ? new import_decimal.default(depositAmount || 0) : new import_decimal.default(summary.total_amount || summary.expect_amount || 0);
|
|
606
|
+
const paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
|
|
607
|
+
const amountGap = import_decimal.default.max(0, targetAmount.minus(paymentTotal)).toFixed(2);
|
|
608
|
+
return {
|
|
609
|
+
isDeposit: tempOrder.is_deposit === 1 || depositAmount !== "0.00",
|
|
610
|
+
depositAmount,
|
|
611
|
+
expectAmount: summary.expect_amount || "0.00",
|
|
612
|
+
totalAmount: summary.total_amount || "0.00",
|
|
613
|
+
amountGap,
|
|
614
|
+
summary
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
getOrderSnapshot() {
|
|
618
|
+
var _a;
|
|
619
|
+
const tempOrder = this.store.tempOrder;
|
|
620
|
+
if (!tempOrder)
|
|
621
|
+
return null;
|
|
622
|
+
const identity = this.getOrderIdentity();
|
|
623
|
+
const amount = this.getOrderAmountSnapshot();
|
|
624
|
+
if (!identity || !amount)
|
|
625
|
+
return null;
|
|
626
|
+
return {
|
|
627
|
+
identity,
|
|
628
|
+
syncState: this.getOrderSyncState(),
|
|
629
|
+
amount,
|
|
630
|
+
status: tempOrder.status || "",
|
|
631
|
+
paymentStatus: tempOrder.payment_status || "",
|
|
632
|
+
shippingStatus: tempOrder.shipping_status || "",
|
|
633
|
+
note: tempOrder.note || "",
|
|
634
|
+
customer: {
|
|
635
|
+
customerId: tempOrder.customer_id ?? null,
|
|
636
|
+
customerName: tempOrder.customer_name || "",
|
|
637
|
+
phone: tempOrder.phone || "",
|
|
638
|
+
email: tempOrder.email || ""
|
|
639
|
+
},
|
|
640
|
+
productCount: ((_a = tempOrder.products) == null ? void 0 : _a.length) || 0,
|
|
641
|
+
lastOrderInfo: this.store.lastOrderInfo,
|
|
642
|
+
tempOrder
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
async addNewOrder() {
|
|
646
|
+
const tempOrder = this.ensureTempOrder();
|
|
647
|
+
this.ensureExternalSaleNumber(tempOrder);
|
|
648
|
+
await this.recalculateSummary({ createIfMissing: true });
|
|
649
|
+
this.persistTempOrder();
|
|
650
|
+
await this.saveDraft();
|
|
651
|
+
return tempOrder;
|
|
652
|
+
}
|
|
653
|
+
getOrderProducts() {
|
|
654
|
+
const tempOrder = this.ensureTempOrder();
|
|
655
|
+
return tempOrder.products;
|
|
656
|
+
}
|
|
657
|
+
getProductUid(product) {
|
|
658
|
+
const metadata = product.metadata && typeof product.metadata === "object" ? product.metadata : {};
|
|
659
|
+
const uid = metadata.unique_identification_number || product.unique_identification_number || (0, import_utils.createUuidV4)();
|
|
660
|
+
metadata.unique_identification_number = String(uid);
|
|
661
|
+
product.metadata = metadata;
|
|
662
|
+
return String(uid);
|
|
663
|
+
}
|
|
664
|
+
ensureExtend(tempOrder) {
|
|
665
|
+
if (!tempOrder._extend || typeof tempOrder._extend !== "object") {
|
|
666
|
+
tempOrder._extend = { productsByUid: {} };
|
|
667
|
+
}
|
|
668
|
+
if (!tempOrder._extend.productsByUid) {
|
|
669
|
+
tempOrder._extend.productsByUid = {};
|
|
670
|
+
}
|
|
671
|
+
return tempOrder._extend;
|
|
672
|
+
}
|
|
673
|
+
captureProductRuntime(tempOrder, rawProduct, normalizedProduct, existedUid) {
|
|
674
|
+
var _a;
|
|
675
|
+
const uid = existedUid || this.getProductUid(normalizedProduct);
|
|
676
|
+
const extend = this.ensureExtend(tempOrder);
|
|
677
|
+
const existed = ((_a = extend.productsByUid) == null ? void 0 : _a[uid]) || {};
|
|
678
|
+
const origin = rawProduct._origin ?? normalizedProduct._origin ?? existed.origin;
|
|
679
|
+
extend.productsByUid[uid] = {
|
|
680
|
+
...existed,
|
|
681
|
+
...origin !== void 0 ? { origin } : {}
|
|
682
|
+
};
|
|
683
|
+
delete normalizedProduct._origin;
|
|
684
|
+
delete normalizedProduct.unique_identification_number;
|
|
685
|
+
}
|
|
686
|
+
createLinkedProductAndBooking(params) {
|
|
687
|
+
const productMetadata = params.product.metadata && typeof params.product.metadata === "object" ? { ...params.product.metadata } : {};
|
|
688
|
+
const bookingMetadata = params.booking.metadata && typeof params.booking.metadata === "object" ? { ...params.booking.metadata } : {};
|
|
689
|
+
const productUid = String(
|
|
690
|
+
productMetadata.unique_identification_number || params.product.unique_identification_number || (0, import_utils.createUuidV4)()
|
|
691
|
+
);
|
|
692
|
+
const bookingUid = String(
|
|
693
|
+
bookingMetadata.unique_identification_number || (0, import_utils.createUuidV4)()
|
|
694
|
+
);
|
|
695
|
+
productMetadata.unique_identification_number = productUid;
|
|
696
|
+
bookingMetadata.unique_identification_number = bookingUid;
|
|
697
|
+
return {
|
|
698
|
+
productUid,
|
|
699
|
+
bookingUid,
|
|
700
|
+
product: {
|
|
701
|
+
...params.product,
|
|
702
|
+
unique_identification_number: productUid,
|
|
703
|
+
metadata: {
|
|
704
|
+
...productMetadata,
|
|
705
|
+
booking_uid: bookingUid
|
|
706
|
+
},
|
|
707
|
+
booking_uid: bookingUid
|
|
708
|
+
},
|
|
709
|
+
booking: {
|
|
710
|
+
...params.booking,
|
|
711
|
+
is_all: (0, import_utils.normalizeBookingIsAll)(params.booking),
|
|
712
|
+
product_uid: productUid,
|
|
713
|
+
sub_type: (0, import_utils.normalizeBookingSubType)(params.booking),
|
|
714
|
+
metadata: bookingMetadata
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
// ─── TempOrder: 金额汇总 ───
|
|
719
|
+
getSalesSummary() {
|
|
720
|
+
if (!this.salesSummaryModuleName)
|
|
721
|
+
return null;
|
|
722
|
+
return this.core.getModule(this.salesSummaryModuleName);
|
|
723
|
+
}
|
|
724
|
+
async recalculateSummary(options) {
|
|
725
|
+
const tempOrder = (options == null ? void 0 : options.createIfMissing) ? this.ensureTempOrder() : this.store.tempOrder;
|
|
726
|
+
if (!tempOrder)
|
|
727
|
+
return null;
|
|
728
|
+
const salesSummary = this.getSalesSummary();
|
|
729
|
+
const existedSummary = this.store.summary || (0, import_utils.createEmptySummary)();
|
|
730
|
+
const paidPaymentSummary = this.calculatePaidPaymentSummary(
|
|
731
|
+
tempOrder.payments || []
|
|
732
|
+
);
|
|
733
|
+
if (!salesSummary) {
|
|
734
|
+
const emptySummary = {
|
|
735
|
+
...(0, import_utils.createEmptySummary)(),
|
|
736
|
+
total_refund_amount: existedSummary.total_refund_amount || "0.00",
|
|
737
|
+
customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
|
|
738
|
+
order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
|
|
739
|
+
pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
|
|
740
|
+
};
|
|
741
|
+
this.store.summary = emptySummary;
|
|
742
|
+
tempOrder.surcharge_fee = emptySummary.surcharge_fee;
|
|
743
|
+
return this.store.summary;
|
|
744
|
+
}
|
|
745
|
+
const salesSummaryResult = await salesSummary.getSummary({
|
|
746
|
+
products: tempOrder.products,
|
|
747
|
+
isPriceIncludeTax: tempOrder.is_price_include_tax,
|
|
748
|
+
shopDiscount: tempOrder.shop_discount
|
|
749
|
+
});
|
|
750
|
+
const summary = {
|
|
751
|
+
...salesSummaryResult,
|
|
752
|
+
total_refund_amount: existedSummary.total_refund_amount || "0.00",
|
|
753
|
+
customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
|
|
754
|
+
order_paid_amount: paidPaymentSummary.orderPaidAmount.toFixed(2),
|
|
755
|
+
pay_service_charge_amount: paidPaymentSummary.payServiceChargeAmount.toFixed(2)
|
|
756
|
+
};
|
|
757
|
+
this.store.summary = summary;
|
|
758
|
+
if (summary.is_price_include_tax !== void 0) {
|
|
759
|
+
tempOrder.is_price_include_tax = summary.is_price_include_tax;
|
|
760
|
+
}
|
|
761
|
+
if (typeof summary.tax_title === "string" && summary.tax_title) {
|
|
762
|
+
tempOrder.tax_title = summary.tax_title;
|
|
763
|
+
}
|
|
764
|
+
tempOrder.surcharge_fee = summary.surcharge_fee;
|
|
765
|
+
tempOrder.surcharges = summary.surcharges || [];
|
|
766
|
+
tempOrder.deposit_amount = summary.deposit_amount || "0.00";
|
|
767
|
+
tempOrder.is_deposit = summary.deposit_amount !== "0.00" ? 1 : 0;
|
|
768
|
+
return this.store.summary;
|
|
769
|
+
}
|
|
770
|
+
async getOrderSummary() {
|
|
771
|
+
const summary = await this.recalculateSummary({ createIfMissing: true });
|
|
772
|
+
if (!summary)
|
|
773
|
+
return (0, import_utils.createEmptySummary)();
|
|
774
|
+
this.persistTempOrder();
|
|
775
|
+
return summary;
|
|
776
|
+
}
|
|
777
|
+
// ─── TempOrder: 备注 ───
|
|
778
|
+
updateTempOrderNote(note) {
|
|
779
|
+
const tempOrder = this.ensureTempOrder();
|
|
780
|
+
tempOrder.note = String(note || "");
|
|
781
|
+
this.persistTempOrder();
|
|
782
|
+
return tempOrder.note;
|
|
783
|
+
}
|
|
784
|
+
getTempOrderNote() {
|
|
785
|
+
var _a;
|
|
786
|
+
return ((_a = this.store.tempOrder) == null ? void 0 : _a.note) || "";
|
|
787
|
+
}
|
|
788
|
+
updateTempOrderShopDiscount(amount) {
|
|
789
|
+
const tempOrder = this.ensureTempOrder();
|
|
790
|
+
const discount = import_decimal.default.max(new import_decimal.default(Number(amount) || 0), 0).toDecimalPlaces(2).toFixed(2);
|
|
791
|
+
tempOrder.shop_discount = discount;
|
|
792
|
+
this.persistTempOrder();
|
|
793
|
+
return tempOrder.shop_discount;
|
|
794
|
+
}
|
|
795
|
+
updateTempOrderBuzzer(buzzer) {
|
|
796
|
+
const tempOrder = this.ensureTempOrder();
|
|
797
|
+
tempOrder.buzzer = String(buzzer || "");
|
|
798
|
+
this.persistTempOrder();
|
|
799
|
+
return tempOrder.buzzer;
|
|
800
|
+
}
|
|
801
|
+
updateTempOrderContactsInfo(contactsInfo) {
|
|
802
|
+
const tempOrder = this.ensureTempOrder();
|
|
803
|
+
tempOrder.contacts_info = contactsInfo && typeof contactsInfo === "object" && !Array.isArray(contactsInfo) ? contactsInfo : null;
|
|
804
|
+
this.persistTempOrder();
|
|
805
|
+
return tempOrder.contacts_info;
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* 更新当前 tempOrder 的客户协议字段。
|
|
809
|
+
*
|
|
810
|
+
* PaymentModal 只需要修改订单里的客户字段;如果外部还有客户模块需要同步,
|
|
811
|
+
* 应由调用方通过回调处理,不能把外部 UI 状态写进 tempOrder。
|
|
812
|
+
*/
|
|
813
|
+
updateTempOrderCustomer(customer) {
|
|
814
|
+
const tempOrder = this.ensureTempOrder();
|
|
815
|
+
const customerId = customer.customer_id ?? customer.customerId ?? customer.id ?? null;
|
|
816
|
+
const customerName = customer.customer_name ?? customer.customerName ?? customer.display_name ?? customer.name ?? "";
|
|
817
|
+
tempOrder.customer_id = customerId === null || customerId === void 0 || customerId === "" ? null : Number(customerId);
|
|
818
|
+
tempOrder.customer_name = String(customerName || "");
|
|
819
|
+
tempOrder.country_calling_code = String(
|
|
820
|
+
customer.country_calling_code ?? customer.countryCallingCode ?? ""
|
|
821
|
+
);
|
|
822
|
+
tempOrder.phone = String(customer.phone || "");
|
|
823
|
+
tempOrder.email = String(customer.email || "");
|
|
824
|
+
this.persistTempOrder();
|
|
825
|
+
return {
|
|
826
|
+
customerId: tempOrder.customer_id,
|
|
827
|
+
customerName: tempOrder.customer_name,
|
|
828
|
+
phone: tempOrder.phone,
|
|
829
|
+
email: tempOrder.email
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
setOrderCustomer(patch, snapshot) {
|
|
833
|
+
if (!patch) {
|
|
834
|
+
this.clearOrderCustomer();
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
const tempOrder = this.ensureTempOrder();
|
|
838
|
+
tempOrder.customer_id = patch.customer_id || patch.id || null;
|
|
839
|
+
tempOrder.customer_name = String(patch.customer_name || "");
|
|
840
|
+
tempOrder.country_calling_code = String(patch.country_calling_code || "");
|
|
841
|
+
tempOrder.phone = String(patch.phone || "");
|
|
842
|
+
tempOrder.email = String(patch.email || "");
|
|
843
|
+
if (snapshot !== void 0) {
|
|
844
|
+
const extend = this.ensureExtend(tempOrder);
|
|
845
|
+
if (snapshot === null)
|
|
846
|
+
delete extend.customerSnapshot;
|
|
847
|
+
else
|
|
848
|
+
extend.customerSnapshot = (0, import_lodash_es.cloneDeep)(snapshot);
|
|
849
|
+
}
|
|
850
|
+
this.persistTempOrder();
|
|
851
|
+
this.emitOrderCustomerChange();
|
|
852
|
+
}
|
|
853
|
+
getOrderCustomer() {
|
|
854
|
+
const tempOrder = this.store.tempOrder;
|
|
855
|
+
if (!tempOrder || tempOrder.customer_id === null || tempOrder.customer_id === void 0) {
|
|
856
|
+
return null;
|
|
857
|
+
}
|
|
858
|
+
return {
|
|
859
|
+
customer_id: tempOrder.customer_id,
|
|
860
|
+
customer_name: tempOrder.customer_name || "",
|
|
861
|
+
country_calling_code: tempOrder.country_calling_code || "",
|
|
862
|
+
phone: tempOrder.phone || "",
|
|
863
|
+
email: tempOrder.email || ""
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
getOrderCustomerSnapshot() {
|
|
867
|
+
var _a, _b;
|
|
868
|
+
const snapshot = (_b = (_a = this.store.tempOrder) == null ? void 0 : _a._extend) == null ? void 0 : _b.customerSnapshot;
|
|
869
|
+
return snapshot ? (0, import_lodash_es.cloneDeep)(snapshot) : null;
|
|
870
|
+
}
|
|
871
|
+
clearOrderCustomer() {
|
|
872
|
+
const tempOrder = this.ensureTempOrder();
|
|
873
|
+
tempOrder.customer_id = null;
|
|
874
|
+
tempOrder.customer_name = "";
|
|
875
|
+
tempOrder.country_calling_code = "";
|
|
876
|
+
tempOrder.phone = "";
|
|
877
|
+
tempOrder.email = "";
|
|
878
|
+
if (tempOrder._extend)
|
|
879
|
+
delete tempOrder._extend.customerSnapshot;
|
|
880
|
+
this.persistTempOrder();
|
|
881
|
+
this.core.effects.emit(import_types.OrderHooks.OnOrderCustomerChange, null);
|
|
882
|
+
}
|
|
883
|
+
emitOrderCustomerChange() {
|
|
884
|
+
const patch = this.getOrderCustomer();
|
|
885
|
+
if (!patch) {
|
|
886
|
+
this.core.effects.emit(import_types.OrderHooks.OnOrderCustomerChange, null);
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
const payload = {
|
|
890
|
+
patch,
|
|
891
|
+
snapshot: this.getOrderCustomerSnapshot()
|
|
892
|
+
};
|
|
893
|
+
this.core.effects.emit(import_types.OrderHooks.OnOrderCustomerChange, payload);
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* 读取当前订单的 Sales 协议支付项。
|
|
897
|
+
*
|
|
898
|
+
* 这里返回的是 tempOrder.payments,而不是旧 PaymentModule 的本地
|
|
899
|
+
* payment order / tender session。Sales checkout 以该数组为提交事实来源。
|
|
900
|
+
*/
|
|
901
|
+
getOrderPayments() {
|
|
902
|
+
const tempOrder = this.ensureTempOrder();
|
|
903
|
+
return tempOrder.payments || [];
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* 用一组支付来源覆盖当前订单支付项。
|
|
907
|
+
*
|
|
908
|
+
* 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
|
|
909
|
+
* uuid -> metadata.unique_payment_number,id -> custom_payment_id,
|
|
910
|
+
* isSynced 等运行态字段不会进入 tempOrder.payments。
|
|
911
|
+
*/
|
|
912
|
+
setOrderPayments(payments) {
|
|
913
|
+
const tempOrder = this.ensureTempOrder();
|
|
914
|
+
tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(payments);
|
|
915
|
+
this.persistTempOrder();
|
|
916
|
+
return tempOrder.payments;
|
|
917
|
+
}
|
|
918
|
+
/** 追加单个支付项,并立即持久化当前 tempOrder。 */
|
|
919
|
+
addOrderPayment(payment) {
|
|
920
|
+
const tempOrder = this.ensureTempOrder();
|
|
921
|
+
const mapped = (0, import_utils.mapPaymentItemsToOrderPayments)([payment]);
|
|
922
|
+
tempOrder.payments = [...tempOrder.payments || [], ...mapped];
|
|
923
|
+
this.persistTempOrder();
|
|
924
|
+
return tempOrder.payments;
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
|
|
928
|
+
*
|
|
929
|
+
* 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
|
|
930
|
+
* 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
|
|
931
|
+
*/
|
|
932
|
+
updateOrderPayment(paymentIdentity, updates) {
|
|
933
|
+
const tempOrder = this.ensureTempOrder();
|
|
934
|
+
const identity = String(paymentIdentity);
|
|
935
|
+
tempOrder.payments = (tempOrder.payments || []).map((payment) => {
|
|
936
|
+
var _a;
|
|
937
|
+
const uniquePaymentNumber = (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
|
|
938
|
+
const orderPaymentId = payment == null ? void 0 : payment.order_payment_id;
|
|
939
|
+
const customPaymentId = payment == null ? void 0 : payment.custom_payment_id;
|
|
940
|
+
const uuid = payment == null ? void 0 : payment.uuid;
|
|
941
|
+
const matched = [
|
|
942
|
+
uniquePaymentNumber,
|
|
943
|
+
orderPaymentId,
|
|
944
|
+
customPaymentId,
|
|
945
|
+
uuid
|
|
946
|
+
].some((value) => value !== void 0 && String(value) === identity);
|
|
947
|
+
if (!matched)
|
|
948
|
+
return payment;
|
|
949
|
+
return {
|
|
950
|
+
...payment,
|
|
951
|
+
...updates,
|
|
952
|
+
metadata: {
|
|
953
|
+
...payment.metadata || {},
|
|
954
|
+
...updates.metadata || {}
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
});
|
|
958
|
+
this.persistTempOrder();
|
|
959
|
+
return tempOrder.payments;
|
|
960
|
+
}
|
|
961
|
+
/** 从当前订单支付项中移除指定支付项。 */
|
|
962
|
+
deleteOrderPayment(paymentIdentity) {
|
|
963
|
+
const tempOrder = this.ensureTempOrder();
|
|
964
|
+
const identity = String(paymentIdentity);
|
|
965
|
+
tempOrder.payments = (tempOrder.payments || []).filter((payment) => {
|
|
966
|
+
var _a;
|
|
967
|
+
const uniquePaymentNumber = (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
|
|
968
|
+
const orderPaymentId = payment == null ? void 0 : payment.order_payment_id;
|
|
969
|
+
const customPaymentId = payment == null ? void 0 : payment.custom_payment_id;
|
|
970
|
+
const uuid = payment == null ? void 0 : payment.uuid;
|
|
971
|
+
return ![
|
|
972
|
+
uniquePaymentNumber,
|
|
973
|
+
orderPaymentId,
|
|
974
|
+
customPaymentId,
|
|
975
|
+
uuid
|
|
976
|
+
].some((value) => value !== void 0 && String(value) === identity);
|
|
977
|
+
});
|
|
978
|
+
this.persistTempOrder();
|
|
979
|
+
return tempOrder.payments;
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* 覆盖当前订单中的 wallet pass 支付项。
|
|
983
|
+
*
|
|
984
|
+
* 判断口径与 PaymentModal 保持一致:voucher_id 存在且不为 0 的支付项
|
|
985
|
+
* 视为 wallet pass;其它支付项保持不变。
|
|
986
|
+
*/
|
|
987
|
+
updateVoucherOrderPayments(payments) {
|
|
988
|
+
const tempOrder = this.ensureTempOrder();
|
|
989
|
+
const mappedVouchers = (0, import_utils.mapPaymentItemsToOrderPayments)(payments).filter(
|
|
990
|
+
(payment) => payment.voucher_id !== void 0 && Number(payment.voucher_id) !== 0
|
|
991
|
+
);
|
|
992
|
+
const nonVoucherPayments = (tempOrder.payments || []).filter((payment) => {
|
|
993
|
+
return payment.voucher_id === void 0 || Number(payment.voucher_id) === 0;
|
|
994
|
+
});
|
|
995
|
+
tempOrder.payments = [...nonVoucherPayments, ...mappedVouchers];
|
|
996
|
+
this.persistTempOrder();
|
|
997
|
+
return tempOrder.payments;
|
|
998
|
+
}
|
|
999
|
+
// ─── TempOrder: 商品 CRUD ───
|
|
1000
|
+
async addProductToOrder(product, booking) {
|
|
1001
|
+
var _a;
|
|
1002
|
+
const tempOrder = this.ensureTempOrder();
|
|
1003
|
+
const linked = booking ? this.createLinkedProductAndBooking({ product, booking }) : null;
|
|
1004
|
+
const productToAdd = (linked == null ? void 0 : linked.product) || product;
|
|
1005
|
+
const incomingFingerprint = (0, import_utils3.buildProductLineFingerprint)(
|
|
1006
|
+
productToAdd.product_option_item,
|
|
1007
|
+
productToAdd.product_bundle
|
|
1008
|
+
);
|
|
1009
|
+
const normalizedIncoming = (0, import_utils3.normalizeOrderProduct)(productToAdd);
|
|
1010
|
+
const hasIncomingGoodPass = this.hasGoodPassDiscount(
|
|
1011
|
+
normalizedIncoming
|
|
1012
|
+
);
|
|
1013
|
+
const shouldForceNewLine = !!booking;
|
|
1014
|
+
const matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex((item) => {
|
|
1015
|
+
if (this.hasGoodPassDiscount(item))
|
|
1016
|
+
return false;
|
|
1017
|
+
if (item.product_id !== productToAdd.product_id)
|
|
1018
|
+
return false;
|
|
1019
|
+
if (item.product_variant_id !== productToAdd.product_variant_id)
|
|
1020
|
+
return false;
|
|
1021
|
+
const existedFingerprint = (0, import_utils3.buildProductLineFingerprint)(
|
|
1022
|
+
item.product_option_item,
|
|
1023
|
+
item.product_bundle
|
|
1024
|
+
);
|
|
1025
|
+
return existedFingerprint === incomingFingerprint;
|
|
1026
|
+
});
|
|
1027
|
+
if (matchedIndex === -1) {
|
|
1028
|
+
this.captureProductRuntime(
|
|
1029
|
+
tempOrder,
|
|
1030
|
+
productToAdd,
|
|
1031
|
+
normalizedIncoming
|
|
1032
|
+
);
|
|
1033
|
+
if (linked) {
|
|
1034
|
+
normalizedIncoming.booking_uid = linked.bookingUid;
|
|
1035
|
+
normalizedIncoming.metadata = {
|
|
1036
|
+
...normalizedIncoming.metadata || {},
|
|
1037
|
+
booking_uid: linked.bookingUid
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
tempOrder.products.push(normalizedIncoming);
|
|
1041
|
+
} else {
|
|
1042
|
+
const targetProduct = tempOrder.products[matchedIndex];
|
|
1043
|
+
const targetUid = (_a = targetProduct.metadata) == null ? void 0 : _a.unique_identification_number;
|
|
1044
|
+
const normalizedProduct = (0, import_utils3.normalizeOrderProduct)({
|
|
1045
|
+
...productToAdd,
|
|
1046
|
+
metadata: {
|
|
1047
|
+
...productToAdd.metadata || {},
|
|
1048
|
+
unique_identification_number: targetUid
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
tempOrder.products[matchedIndex] = {
|
|
1052
|
+
...targetProduct,
|
|
1053
|
+
...normalizedProduct,
|
|
1054
|
+
metadata: {
|
|
1055
|
+
...targetProduct.metadata || {},
|
|
1056
|
+
...normalizedProduct.metadata || {},
|
|
1057
|
+
unique_identification_number: targetUid
|
|
1058
|
+
},
|
|
1059
|
+
note: targetProduct.note,
|
|
1060
|
+
order_detail_id: targetProduct.order_detail_id,
|
|
1061
|
+
num: (0, import_utils3.getSafeProductNum)(targetProduct.num + normalizedProduct.num)
|
|
1062
|
+
};
|
|
1063
|
+
this.captureProductRuntime(
|
|
1064
|
+
tempOrder,
|
|
1065
|
+
productToAdd,
|
|
1066
|
+
tempOrder.products[matchedIndex],
|
|
1067
|
+
targetUid
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
if (linked) {
|
|
1071
|
+
tempOrder.bookings = [...tempOrder.bookings || [], linked.booking];
|
|
1072
|
+
}
|
|
1073
|
+
this.applyDiscount();
|
|
1074
|
+
await this.recalculateSummary({ createIfMissing: true });
|
|
1075
|
+
this.persistTempOrder();
|
|
1076
|
+
return tempOrder.products;
|
|
1077
|
+
}
|
|
1078
|
+
hasGoodPassDiscount(product) {
|
|
1079
|
+
var _a, _b;
|
|
1080
|
+
const hasMainGoodPass = (product.discount_list || []).some(
|
|
1081
|
+
(item) => (item == null ? void 0 : item.type) === "good_pass" || (item == null ? void 0 : item.tag) === "good_pass"
|
|
1082
|
+
);
|
|
1083
|
+
if (hasMainGoodPass)
|
|
1084
|
+
return true;
|
|
1085
|
+
const bundleDiscountList = [];
|
|
1086
|
+
(product.product_bundle || []).forEach((item) => {
|
|
1087
|
+
bundleDiscountList.push(...(item == null ? void 0 : item.discount_list) || []);
|
|
1088
|
+
});
|
|
1089
|
+
(((_b = (_a = product == null ? void 0 : product._extend) == null ? void 0 : _a.other) == null ? void 0 : _b.bundle) || []).forEach((item) => {
|
|
1090
|
+
bundleDiscountList.push(...(item == null ? void 0 : item.discount_list) || []);
|
|
1091
|
+
});
|
|
1092
|
+
return bundleDiscountList.some(
|
|
1093
|
+
(item) => (item == null ? void 0 : item.type) === "good_pass" || (item == null ? void 0 : item.tag) === "good_pass"
|
|
1094
|
+
);
|
|
1095
|
+
}
|
|
1096
|
+
async updateProductInOrder(params) {
|
|
1097
|
+
var _a, _b, _c, _d, _e;
|
|
1098
|
+
const {
|
|
1099
|
+
product_id,
|
|
1100
|
+
product_variant_id,
|
|
1101
|
+
updates,
|
|
1102
|
+
unique_identification_number,
|
|
1103
|
+
product_option_item,
|
|
1104
|
+
product_bundle
|
|
1105
|
+
} = params;
|
|
1106
|
+
const tempOrder = this.ensureTempOrder();
|
|
1107
|
+
const identityLookup = {
|
|
1108
|
+
product_id,
|
|
1109
|
+
product_variant_id
|
|
1110
|
+
};
|
|
1111
|
+
if (unique_identification_number !== void 0) {
|
|
1112
|
+
identityLookup.unique_identification_number = unique_identification_number;
|
|
1113
|
+
}
|
|
1114
|
+
if (product_option_item !== void 0)
|
|
1115
|
+
identityLookup.product_option_item = product_option_item;
|
|
1116
|
+
if (product_bundle !== void 0)
|
|
1117
|
+
identityLookup.product_bundle = product_bundle;
|
|
1118
|
+
const productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
|
|
1119
|
+
if (productIndex === -1) {
|
|
1120
|
+
throw new Error("[Order] 目标商品不存在,无法更新");
|
|
1121
|
+
}
|
|
1122
|
+
const targetProduct = tempOrder.products[productIndex];
|
|
1123
|
+
const nextProduct = {
|
|
1124
|
+
...targetProduct,
|
|
1125
|
+
...updates,
|
|
1126
|
+
product_id,
|
|
1127
|
+
product_variant_id,
|
|
1128
|
+
metadata: {
|
|
1129
|
+
...targetProduct.metadata || {},
|
|
1130
|
+
...(updates == null ? void 0 : updates.metadata) || {},
|
|
1131
|
+
unique_identification_number: ((_a = targetProduct.metadata) == null ? void 0 : _a.unique_identification_number) || unique_identification_number
|
|
1132
|
+
}
|
|
1133
|
+
};
|
|
1134
|
+
nextProduct.num = (0, import_utils3.getSafeProductNum)(nextProduct.num);
|
|
1135
|
+
const callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, "selling_price") || Object.prototype.hasOwnProperty.call(updates || {}, "original_price");
|
|
1136
|
+
const callerUpdatesMainMeta = ((_b = updates == null ? void 0 : updates.metadata) == null ? void 0 : _b.main_product_selling_price) !== void 0 || ((_c = updates == null ? void 0 : updates.metadata) == null ? void 0 : _c.main_product_original_price) !== void 0 || ((_d = updates == null ? void 0 : updates.metadata) == null ? void 0 : _d.source_product_price) !== void 0;
|
|
1137
|
+
if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
1138
|
+
const existedMeta = nextProduct.metadata || {};
|
|
1139
|
+
nextProduct.metadata = { ...existedMeta };
|
|
1140
|
+
delete nextProduct.metadata.source_product_price;
|
|
1141
|
+
delete nextProduct.metadata.main_product_selling_price;
|
|
1142
|
+
delete nextProduct.metadata.main_product_original_price;
|
|
1143
|
+
delete nextProduct.metadata.price_schema_version;
|
|
1144
|
+
}
|
|
1145
|
+
tempOrder.products[productIndex] = (0, import_utils3.normalizeOrderProduct)(nextProduct);
|
|
1146
|
+
this.captureProductRuntime(
|
|
1147
|
+
tempOrder,
|
|
1148
|
+
updates,
|
|
1149
|
+
tempOrder.products[productIndex],
|
|
1150
|
+
(_e = tempOrder.products[productIndex].metadata) == null ? void 0 : _e.unique_identification_number
|
|
1151
|
+
);
|
|
1152
|
+
this.applyDiscount();
|
|
1153
|
+
await this.recalculateSummary({ createIfMissing: true });
|
|
1154
|
+
this.persistTempOrder();
|
|
1155
|
+
return tempOrder.products;
|
|
1156
|
+
}
|
|
1157
|
+
async removeProductFromOrder(identity) {
|
|
1158
|
+
const tempOrder = this.ensureTempOrder();
|
|
1159
|
+
tempOrder.products = tempOrder.products.filter(
|
|
1160
|
+
(item) => !(0, import_utils3.isIdentityMatch)(item, identity)
|
|
1161
|
+
);
|
|
1162
|
+
this.applyDiscount();
|
|
1163
|
+
await this.recalculateSummary({ createIfMissing: true });
|
|
1164
|
+
this.persistTempOrder();
|
|
1165
|
+
return tempOrder.products;
|
|
1166
|
+
}
|
|
1167
|
+
// ─── TempOrder: 提交 ───
|
|
1168
|
+
/**
|
|
1169
|
+
* 提交当前 Sales tempOrder。
|
|
1170
|
+
*
|
|
1171
|
+
* smallTicketDataFlag 用于 B 端 checkout 小票数据返回。PaymentModal 在支付提交时
|
|
1172
|
+
* 应传 1,确保 /order/sales/checkout 返回打印所需数据。
|
|
1173
|
+
*/
|
|
1174
|
+
async submitTempOrder(params) {
|
|
1175
|
+
var _a, _b, _c;
|
|
1176
|
+
const tempOrder = this.ensureTempOrder();
|
|
1177
|
+
this.persistTempOrder();
|
|
1178
|
+
const effectiveCacheId = (params == null ? void 0 : params.cacheId) ?? this.cacheId;
|
|
1179
|
+
const hasPaymentOverride = (params == null ? void 0 : params.payments) !== void 0;
|
|
1180
|
+
const hasPaymentStatusOverride = (params == null ? void 0 : params.paymentStatus) !== void 0;
|
|
1181
|
+
const hasSmallTicketDataFlagOverride = (params == null ? void 0 : params.smallTicketDataFlag) !== void 0;
|
|
1182
|
+
const enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || (params == null ? void 0 : params.enhancePayload) ? (payload2, ctx) => {
|
|
1183
|
+
const nextPayload = {
|
|
1184
|
+
...payload2,
|
|
1185
|
+
...hasPaymentOverride ? {
|
|
1186
|
+
payments: (0, import_utils.mapPaymentItemsToOrderPayments)(
|
|
1187
|
+
(params == null ? void 0 : params.payments) || []
|
|
1188
|
+
)
|
|
1189
|
+
} : {},
|
|
1190
|
+
...hasPaymentStatusOverride ? { payment_status: params == null ? void 0 : params.paymentStatus } : {},
|
|
1191
|
+
...hasSmallTicketDataFlagOverride ? { small_ticket_data_flag: params == null ? void 0 : params.smallTicketDataFlag } : {}
|
|
1192
|
+
};
|
|
1193
|
+
return (params == null ? void 0 : params.enhancePayload) ? params.enhancePayload(nextPayload, ctx) : nextPayload;
|
|
1194
|
+
} : void 0;
|
|
1195
|
+
const payload = (0, import_utils.buildSubmitPayload)({
|
|
1196
|
+
tempOrder,
|
|
1197
|
+
cacheId: effectiveCacheId,
|
|
1198
|
+
platform: (params == null ? void 0 : params.platform) || ((_a = this.otherParams) == null ? void 0 : _a.platform),
|
|
1199
|
+
businessCode: params == null ? void 0 : params.businessCode,
|
|
1200
|
+
channel: params == null ? void 0 : params.channel,
|
|
1201
|
+
type: params == null ? void 0 : params.type,
|
|
1202
|
+
enhance: enhancePayload
|
|
1203
|
+
});
|
|
1204
|
+
await this.saveDraft();
|
|
1205
|
+
let result;
|
|
1206
|
+
try {
|
|
1207
|
+
this.logInfo("submitTempOrder calling sales checkout", {
|
|
1208
|
+
orderId: payload.order_id,
|
|
1209
|
+
externalSaleNumber: payload.external_sale_number,
|
|
1210
|
+
paymentStatus: payload.payment_status,
|
|
1211
|
+
paymentsCount: ((_b = payload.payments) == null ? void 0 : _b.length) || 0,
|
|
1212
|
+
smallTicketDataFlag: payload.small_ticket_data_flag
|
|
1213
|
+
});
|
|
1214
|
+
result = await this.submitSalesOrder({
|
|
1215
|
+
query: payload
|
|
1216
|
+
});
|
|
1217
|
+
} catch (error) {
|
|
1218
|
+
const backendErrorResponse = this.extractSubmitErrorResponse(error);
|
|
1219
|
+
if (backendErrorResponse) {
|
|
1220
|
+
this.store.syncState = "failed";
|
|
1221
|
+
this.logSubmitBackendRejected(backendErrorResponse, payload);
|
|
1222
|
+
return backendErrorResponse;
|
|
1223
|
+
}
|
|
1224
|
+
this.store.syncState = "failed";
|
|
1225
|
+
this.logError("submitTempOrder failed", {
|
|
1226
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1227
|
+
orderId: payload.order_id,
|
|
1228
|
+
externalSaleNumber: payload.external_sale_number,
|
|
1229
|
+
paymentStatus: payload.payment_status,
|
|
1230
|
+
paymentsCount: ((_c = payload.payments) == null ? void 0 : _c.length) || 0
|
|
1231
|
+
});
|
|
1232
|
+
throw error;
|
|
1233
|
+
}
|
|
1234
|
+
if (this.isSubmitResponseRejected(result)) {
|
|
1235
|
+
this.store.syncState = "failed";
|
|
1236
|
+
this.logSubmitBackendRejected(result, payload);
|
|
1237
|
+
return result;
|
|
1238
|
+
}
|
|
1239
|
+
const submittedOrderId = this.extractOrderIdFromSubmitResult(result);
|
|
1240
|
+
if (submittedOrderId !== null && submittedOrderId !== void 0) {
|
|
1241
|
+
tempOrder.order_id = submittedOrderId;
|
|
1242
|
+
const resultRecord = result;
|
|
1243
|
+
await this.markLocalOrderSynced(
|
|
1244
|
+
submittedOrderId,
|
|
1245
|
+
(resultRecord == null ? void 0 : resultRecord.data) || resultRecord || {}
|
|
1246
|
+
);
|
|
1247
|
+
}
|
|
1248
|
+
return result;
|
|
1249
|
+
}
|
|
1250
|
+
async markLocalOrderSynced(orderId, remoteOrder) {
|
|
1251
|
+
const tempOrder = this.ensureTempOrder();
|
|
1252
|
+
tempOrder.order_id = orderId;
|
|
1253
|
+
this.store.lastOrderInfo = remoteOrder;
|
|
1254
|
+
this.store.syncState = "submitted";
|
|
1255
|
+
this.persistTempOrder();
|
|
1256
|
+
await this.saveDraft();
|
|
1257
|
+
}
|
|
1258
|
+
isSubmitResponseRejected(response) {
|
|
1259
|
+
const isErrorCode = (response == null ? void 0 : response.code) !== void 0 && response.code !== 200 && response.code !== "200";
|
|
1260
|
+
const isErrorStatus = (response == null ? void 0 : response.status) === false || typeof (response == null ? void 0 : response.status) === "number" && response.status >= 400;
|
|
1261
|
+
const isErrorSuccess = (response == null ? void 0 : response.success) === false;
|
|
1262
|
+
return isErrorCode || isErrorStatus || isErrorSuccess;
|
|
1263
|
+
}
|
|
1264
|
+
isSubmitErrorResponse(response) {
|
|
1265
|
+
if (!response || typeof response !== "object")
|
|
1266
|
+
return false;
|
|
1267
|
+
return this.isSubmitResponseRejected(response) || response.message !== void 0 || response.msg !== void 0 || response.error !== void 0;
|
|
1268
|
+
}
|
|
1269
|
+
extractSubmitErrorResponse(error) {
|
|
1270
|
+
var _a, _b;
|
|
1271
|
+
const candidates = [
|
|
1272
|
+
(_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data,
|
|
1273
|
+
error == null ? void 0 : error.data,
|
|
1274
|
+
(_b = error == null ? void 0 : error.response) == null ? void 0 : _b.body,
|
|
1275
|
+
error == null ? void 0 : error.body
|
|
1276
|
+
];
|
|
1277
|
+
return candidates.find((candidate) => this.isSubmitErrorResponse(candidate)) || null;
|
|
1278
|
+
}
|
|
1279
|
+
logSubmitBackendRejected(response, payload) {
|
|
1280
|
+
var _a;
|
|
1281
|
+
this.logError("submitTempOrder backend rejected", {
|
|
1282
|
+
response,
|
|
1283
|
+
payload: {
|
|
1284
|
+
order_id: payload.order_id,
|
|
1285
|
+
external_sale_number: payload.external_sale_number,
|
|
1286
|
+
payment_status: payload.payment_status,
|
|
1287
|
+
paymentsCount: ((_a = payload.payments) == null ? void 0 : _a.length) || 0
|
|
1288
|
+
}
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
async syncPaymentsToOrder(params) {
|
|
1292
|
+
const tempOrder = this.ensureTempOrder();
|
|
1293
|
+
const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
|
|
1294
|
+
params.payments || []
|
|
1295
|
+
);
|
|
1296
|
+
tempOrder.payments = mappedPayments;
|
|
1297
|
+
if (params.paymentStatus)
|
|
1298
|
+
tempOrder.payment_status = params.paymentStatus;
|
|
1299
|
+
this.persistTempOrder();
|
|
1300
|
+
await this.saveDraft();
|
|
1301
|
+
const paymentTotal = this.calculatePaymentTotal(mappedPayments);
|
|
1302
|
+
const targetAmount = this.getPaymentTargetAmount();
|
|
1303
|
+
const isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
|
|
1304
|
+
if (!isFullyPaid || !params.submitWhenPaid) {
|
|
1305
|
+
return { isFullyPaid };
|
|
1306
|
+
}
|
|
1307
|
+
const submitResult = await this.submitTempOrder({
|
|
1308
|
+
payments: mappedPayments,
|
|
1309
|
+
paymentStatus: params.paymentStatus || "paid",
|
|
1310
|
+
smallTicketDataFlag: params.smallTicketDataFlag
|
|
1311
|
+
});
|
|
1312
|
+
return { isFullyPaid, submitResult };
|
|
1313
|
+
}
|
|
94
1314
|
createOrder(params) {
|
|
95
1315
|
var _a;
|
|
96
1316
|
const order = {
|
|
@@ -115,6 +1335,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
115
1335
|
item._origin.duration = duration;
|
|
116
1336
|
item._origin.sub_type = durationType;
|
|
117
1337
|
}
|
|
1338
|
+
item._origin.sub_type = (0, import_utils.normalizeBookingSubType)(item._origin);
|
|
118
1339
|
const discountList = (0, import_utils.getAllDiscountList)(item);
|
|
119
1340
|
item._origin.product.discount_list = discountList;
|
|
120
1341
|
if ((0, import_utils2.isNormalProduct)(item._origin)) {
|
|
@@ -220,18 +1441,30 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
220
1441
|
}
|
|
221
1442
|
/**
|
|
222
1443
|
* Checkout 专用:创建订单到后端
|
|
223
|
-
*
|
|
1444
|
+
*
|
|
224
1445
|
* 专门为 Checkout 模块设计的订单创建方法,
|
|
225
1446
|
* 直接调用 /order/checkout 接口创建订单
|
|
226
1447
|
* 接收已经处理好的订单数据,无需再处理购物车
|
|
227
|
-
*
|
|
1448
|
+
*
|
|
228
1449
|
* @param params Checkout 订单参数(已处理的订单数据)
|
|
229
1450
|
* @returns 后端返回的订单数据(包含订单ID等)
|
|
230
1451
|
*/
|
|
231
1452
|
async createOrderByCheckout(params) {
|
|
232
1453
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
233
|
-
const onlineStorePaymentCodeList = [
|
|
234
|
-
|
|
1454
|
+
const onlineStorePaymentCodeList = [
|
|
1455
|
+
"WXPAY",
|
|
1456
|
+
"WECHAT",
|
|
1457
|
+
"ALIPAY",
|
|
1458
|
+
"APPLE_PAY",
|
|
1459
|
+
"CREDIT_CARD_3DS",
|
|
1460
|
+
"CREDIT_CARD_TOKEN",
|
|
1461
|
+
"GOOGLE_PAY",
|
|
1462
|
+
"GOOGLE_PAY_3DS",
|
|
1463
|
+
"CREDIT_CARD"
|
|
1464
|
+
];
|
|
1465
|
+
params.payments = (_a = params.payments) == null ? void 0 : _a.filter(
|
|
1466
|
+
(p) => !onlineStorePaymentCodeList.includes(p.code)
|
|
1467
|
+
);
|
|
235
1468
|
this.logInfo("createOrderByCheckout called", {
|
|
236
1469
|
type: params.type,
|
|
237
1470
|
platform: params.platform,
|
|
@@ -329,6 +1562,164 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
329
1562
|
throw error;
|
|
330
1563
|
}
|
|
331
1564
|
}
|
|
1565
|
+
async submitSalesOrder(params) {
|
|
1566
|
+
const { url, query } = params;
|
|
1567
|
+
const fetchUrl = url || "/order/sales/checkout";
|
|
1568
|
+
return this.request.post(fetchUrl, query, { customToast: () => {
|
|
1569
|
+
} });
|
|
1570
|
+
}
|
|
1571
|
+
/**
|
|
1572
|
+
* 发送支付链接邮件。
|
|
1573
|
+
*
|
|
1574
|
+
* 调用前必须已经有远端 order_id。BaseSales 会在需要时先提交本地订单,
|
|
1575
|
+
* OrderModule 只负责校验 order_ids 并调用 /order/batch-email。
|
|
1576
|
+
*/
|
|
1577
|
+
async sendCustomerPayLink(params) {
|
|
1578
|
+
var _a;
|
|
1579
|
+
const orderIds = params.order_ids || params.orderIds || [];
|
|
1580
|
+
if (!orderIds.length) {
|
|
1581
|
+
throw new Error("发送支付链接前必须先提交本地订单并取得订单 ID");
|
|
1582
|
+
}
|
|
1583
|
+
if (!((_a = params.emails) == null ? void 0 : _a.length)) {
|
|
1584
|
+
throw new Error("发送支付链接需要至少一个邮箱");
|
|
1585
|
+
}
|
|
1586
|
+
return this.request.post("/order/batch-email", {
|
|
1587
|
+
order_ids: orderIds,
|
|
1588
|
+
notify_action: params.notify_action || "order_payment_reminder",
|
|
1589
|
+
emails: params.emails
|
|
1590
|
+
});
|
|
1591
|
+
}
|
|
1592
|
+
// TODO 获取详情的接口
|
|
1593
|
+
async getOrderInfoByRemote(order_id) {
|
|
1594
|
+
const res = await this.request.get(`/order/sales/${order_id}`, {
|
|
1595
|
+
with: ["products", "scheduleEvents", "payments", "customer", "summary", "contacts_info"]
|
|
1596
|
+
});
|
|
1597
|
+
if (res.code === 200) {
|
|
1598
|
+
this.store.lastOrderInfo = res.data;
|
|
1599
|
+
}
|
|
1600
|
+
return res;
|
|
1601
|
+
}
|
|
1602
|
+
/**
|
|
1603
|
+
* 把 sqlite / 后端返回的订单记录直接恢复为 tempOrder。
|
|
1604
|
+
*
|
|
1605
|
+
* 数据源应尽量返回 tempOrder 所需结构;这里仅做 SDK 运行必须字段兜底,
|
|
1606
|
+
* 例如数组字段、商品行唯一值、价格 metadata、summary 派生状态和 _extend。
|
|
1607
|
+
*/
|
|
1608
|
+
async hydrateTempOrderFromRecord(record, options) {
|
|
1609
|
+
const raw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
|
|
1610
|
+
const defaults = this.createDefaultTempOrderInstance();
|
|
1611
|
+
const nextTempOrder = {
|
|
1612
|
+
...defaults
|
|
1613
|
+
};
|
|
1614
|
+
const TEMP_ORDER_KEYS = [
|
|
1615
|
+
"order_id",
|
|
1616
|
+
"external_sale_number",
|
|
1617
|
+
"order_number",
|
|
1618
|
+
"shop_order_number",
|
|
1619
|
+
"shop_full_order_number",
|
|
1620
|
+
"type",
|
|
1621
|
+
"business_code",
|
|
1622
|
+
"platform",
|
|
1623
|
+
"sales_channel",
|
|
1624
|
+
"order_sales_channel",
|
|
1625
|
+
"status",
|
|
1626
|
+
"payment_status",
|
|
1627
|
+
"shipping_status",
|
|
1628
|
+
"customer_id",
|
|
1629
|
+
"customer_name",
|
|
1630
|
+
"country_calling_code",
|
|
1631
|
+
"phone",
|
|
1632
|
+
"email",
|
|
1633
|
+
"customer",
|
|
1634
|
+
"is_price_include_tax",
|
|
1635
|
+
"tax_title",
|
|
1636
|
+
"tax_country_code",
|
|
1637
|
+
"currency_code",
|
|
1638
|
+
"currency_symbol",
|
|
1639
|
+
"currency_format",
|
|
1640
|
+
"is_deposit",
|
|
1641
|
+
"deposit_amount",
|
|
1642
|
+
"shop_discount",
|
|
1643
|
+
"surcharge_fee",
|
|
1644
|
+
"note",
|
|
1645
|
+
"buzzer",
|
|
1646
|
+
"delivery_type",
|
|
1647
|
+
"table_number",
|
|
1648
|
+
"schedule_date",
|
|
1649
|
+
"created_at",
|
|
1650
|
+
"request_unique_idempotency_token"
|
|
1651
|
+
];
|
|
1652
|
+
TEMP_ORDER_KEYS.forEach((key) => {
|
|
1653
|
+
if (raw[key] !== void 0) {
|
|
1654
|
+
nextTempOrder[key] = raw[key];
|
|
1655
|
+
}
|
|
1656
|
+
});
|
|
1657
|
+
nextTempOrder.metadata = raw.metadata && typeof raw.metadata === "object" ? { ...raw.metadata } : {};
|
|
1658
|
+
nextTempOrder.holder = raw.holder && typeof raw.holder === "object" ? { ...raw.holder } : null;
|
|
1659
|
+
nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map((p) => this.normalizeHydratedOrderProduct(p)) : [];
|
|
1660
|
+
nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map((b) => ({
|
|
1661
|
+
...b || {},
|
|
1662
|
+
is_all: (0, import_utils.normalizeBookingIsAll)(b || {}),
|
|
1663
|
+
sub_type: (0, import_utils.normalizeBookingSubType)(b || {})
|
|
1664
|
+
})) : [];
|
|
1665
|
+
nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map((p) => ({ ...p || {} })) : [];
|
|
1666
|
+
nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map((s) => ({ ...s || {} })) : [];
|
|
1667
|
+
nextTempOrder.discount_list = Array.isArray(raw.discount_list) ? raw.discount_list.map((d) => ({ ...d || {} })) : [];
|
|
1668
|
+
nextTempOrder.relation_forms = Array.isArray(raw.relation_forms) ? raw.relation_forms.map((f) => ({ ...f || {} })) : [];
|
|
1669
|
+
nextTempOrder.contacts = Array.isArray(raw.contacts) ? raw.contacts.map((c) => ({ ...c || {} })) : [];
|
|
1670
|
+
nextTempOrder.contacts_info = raw.contacts_info && typeof raw.contacts_info === "object" && !Array.isArray(raw.contacts_info) ? { ...raw.contacts_info } : null;
|
|
1671
|
+
nextTempOrder._extend = raw._extend && typeof raw._extend === "object" ? {
|
|
1672
|
+
...raw._extend,
|
|
1673
|
+
productsByUid: raw._extend.productsByUid || {}
|
|
1674
|
+
} : { productsByUid: {} };
|
|
1675
|
+
this.ensureExternalSaleNumber(nextTempOrder);
|
|
1676
|
+
this.store.tempOrder = nextTempOrder;
|
|
1677
|
+
this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
|
|
1678
|
+
this.store.lastOrderInfo = raw.lastOrderInfo || raw;
|
|
1679
|
+
if (options == null ? void 0 : options.recalcOnHydrate) {
|
|
1680
|
+
await this.recalculateSummary({ createIfMissing: false });
|
|
1681
|
+
}
|
|
1682
|
+
this.persistTempOrder();
|
|
1683
|
+
return nextTempOrder;
|
|
1684
|
+
}
|
|
1685
|
+
normalizeHydratedOrderProduct(product) {
|
|
1686
|
+
const row = { ...product || {} };
|
|
1687
|
+
if (row.num === void 0 && row.product_quantity !== void 0) {
|
|
1688
|
+
row.num = row.product_quantity;
|
|
1689
|
+
}
|
|
1690
|
+
if (!Array.isArray(row.product_option_item))
|
|
1691
|
+
row.product_option_item = [];
|
|
1692
|
+
if (!Array.isArray(row.product_bundle))
|
|
1693
|
+
row.product_bundle = [];
|
|
1694
|
+
if (!row.metadata || typeof row.metadata !== "object")
|
|
1695
|
+
row.metadata = {};
|
|
1696
|
+
const existingIdentity = row.metadata.unique_identification_number || row.unique_identification_number;
|
|
1697
|
+
if (!existingIdentity) {
|
|
1698
|
+
row.metadata.unique_identification_number = (0, import_utils.createUuidV4)();
|
|
1699
|
+
}
|
|
1700
|
+
const normalized = (0, import_utils3.normalizeOrderProduct)(row);
|
|
1701
|
+
const result = {
|
|
1702
|
+
...row,
|
|
1703
|
+
...normalized,
|
|
1704
|
+
metadata: {
|
|
1705
|
+
...row.metadata,
|
|
1706
|
+
...normalized.metadata
|
|
1707
|
+
}
|
|
1708
|
+
};
|
|
1709
|
+
if (result.metadata)
|
|
1710
|
+
delete result.metadata.price_schema_version;
|
|
1711
|
+
return result;
|
|
1712
|
+
}
|
|
1713
|
+
getLastOrderInfo() {
|
|
1714
|
+
var _a;
|
|
1715
|
+
return (_a = this.store) == null ? void 0 : _a.lastOrderInfo;
|
|
1716
|
+
}
|
|
1717
|
+
async getOrderInfo(order_id) {
|
|
1718
|
+
const res = await this.request.get(`/order/sales/${order_id}`, {
|
|
1719
|
+
with: ["products", "scheduleEvents"]
|
|
1720
|
+
});
|
|
1721
|
+
return res;
|
|
1722
|
+
}
|
|
332
1723
|
};
|
|
333
1724
|
// Annotate the CommonJS export names for ESM import in node:
|
|
334
1725
|
0 && (module.exports = {
|