@pisell/pisellos 2.2.221 → 2.2.223
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/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/Customer/index.d.ts +7 -0
- package/dist/modules/Customer/index.js +27 -0
- package/dist/modules/OpenData/index.js +1 -1
- package/dist/modules/Order/index.js +17 -11
- package/dist/modules/Order/types.d.ts +3 -0
- package/dist/modules/Order/utils.js +6 -5
- package/dist/modules/Payment/types.d.ts +2 -0
- package/dist/modules/SalesSummary/index.js +3 -3
- package/dist/modules/Schedule/index.js +3 -1
- package/dist/modules/Summary/index.js +4 -3
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +48 -18
- package/dist/server/modules/order/index.js +3 -2
- package/dist/server/modules/order/types.d.ts +1 -1
- package/dist/server/modules/order/utils/filterBookings.js +1 -1
- package/dist/server/modules/schedule/index.d.ts +4 -4
- package/dist/server/modules/schedule/index.js +99 -83
- package/dist/server/utils/small-ticket.d.ts +3 -1
- package/dist/server/utils/small-ticket.js +106 -18
- package/dist/solution/BaseSales/index.js +7 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +3 -1
- package/dist/solution/BookingTicket/index.js +12 -8
- package/lib/modules/Customer/index.d.ts +7 -0
- package/lib/modules/Customer/index.js +26 -0
- package/lib/modules/OpenData/index.js +1 -1
- package/lib/modules/Order/index.js +7 -3
- package/lib/modules/Order/types.d.ts +3 -0
- package/lib/modules/Order/utils.js +2 -1
- package/lib/modules/Payment/types.d.ts +2 -0
- package/lib/modules/SalesSummary/index.js +2 -1
- package/lib/modules/Schedule/index.js +3 -1
- package/lib/modules/Summary/index.js +5 -4
- package/lib/server/index.d.ts +2 -0
- package/lib/server/index.js +37 -7
- package/lib/server/modules/order/index.js +1 -0
- package/lib/server/modules/order/types.d.ts +1 -1
- package/lib/server/modules/order/utils/filterBookings.js +7 -3
- package/lib/server/modules/schedule/index.d.ts +4 -4
- package/lib/server/modules/schedule/index.js +45 -39
- package/lib/server/utils/small-ticket.d.ts +3 -1
- package/lib/server/utils/small-ticket.js +85 -11
- package/lib/solution/BaseSales/index.js +6 -2
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +3 -1
- package/lib/solution/BookingTicket/index.js +3 -3
- package/package.json +1 -1
|
@@ -48,6 +48,29 @@ var CustomerModule = class extends import_BaseModule.BaseModule {
|
|
|
48
48
|
this.openCache = false;
|
|
49
49
|
this.otherParams = {};
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* 判断两份选中客户的核心展示字段是否一致,用于避免重复 clone / emit。
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* this.isSameSelectedCustomer(currentCustomer, nextCustomer);
|
|
56
|
+
*/
|
|
57
|
+
isSameSelectedCustomer(current, next) {
|
|
58
|
+
const normalizedNext = !next ? import_constants.DEFAULT_CUSTOMER : next;
|
|
59
|
+
const normalizedCurrent = current || null;
|
|
60
|
+
if (!normalizedCurrent)
|
|
61
|
+
return false;
|
|
62
|
+
if (String((normalizedCurrent == null ? void 0 : normalizedCurrent.id) ?? "") === "1" && String((normalizedNext == null ? void 0 : normalizedNext.id) ?? "") === "1") {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
const keys = [
|
|
66
|
+
"id",
|
|
67
|
+
"name",
|
|
68
|
+
"phone",
|
|
69
|
+
"email",
|
|
70
|
+
"country_calling_code"
|
|
71
|
+
];
|
|
72
|
+
return keys.every((key) => String((normalizedCurrent == null ? void 0 : normalizedCurrent[key]) ?? "") === String((normalizedNext == null ? void 0 : normalizedNext[key]) ?? ""));
|
|
73
|
+
}
|
|
51
74
|
async initialize(core, options) {
|
|
52
75
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
53
76
|
this.core = core;
|
|
@@ -225,6 +248,9 @@ var CustomerModule = class extends import_BaseModule.BaseModule {
|
|
|
225
248
|
* @param customer 选择的客户
|
|
226
249
|
*/
|
|
227
250
|
setSelectedCustomer(customer) {
|
|
251
|
+
if (this.isSameSelectedCustomer(this.store.selectedCustomer, customer)) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
228
254
|
this.store.selectedCustomer = !customer ? import_constants.DEFAULT_CUSTOMER : (0, import_lodash_es.cloneDeep)(customer);
|
|
229
255
|
this.core.effects.emit(
|
|
230
256
|
`${this.name}:onCustomerSelected`,
|
|
@@ -94,7 +94,7 @@ var OpenDataModule = class extends import_BaseModule.BaseModule {
|
|
|
94
94
|
}
|
|
95
95
|
checkAvailability(scheduleModule) {
|
|
96
96
|
var _a;
|
|
97
|
-
const scheduleList = scheduleModule ? scheduleModule.getScheduleListByIds(
|
|
97
|
+
const scheduleList = scheduleModule ? scheduleModule == null ? void 0 : scheduleModule.getScheduleListByIds(
|
|
98
98
|
((_a = this.store.data) == null ? void 0 : _a["availability.operating_hours"]) || []
|
|
99
99
|
) : void 0;
|
|
100
100
|
return (0, import_utils.computeAvailability)({
|
|
@@ -3050,7 +3050,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3050
3050
|
* 例如数组字段、商品行唯一值、价格 metadata、summary 派生状态和 _extend。
|
|
3051
3051
|
*/
|
|
3052
3052
|
async hydrateTempOrderFromRecord(record, options) {
|
|
3053
|
-
var _a, _b;
|
|
3053
|
+
var _a, _b, _c;
|
|
3054
3054
|
const raw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
|
|
3055
3055
|
const nextTempOrder = this.normalizeTempOrderForRuntime(raw);
|
|
3056
3056
|
const rawSummary = raw.summary && typeof raw.summary === "object" ? raw.summary : {};
|
|
@@ -3073,8 +3073,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3073
3073
|
};
|
|
3074
3074
|
this.store.lastOrderInfo = raw.lastOrderInfo || raw;
|
|
3075
3075
|
const hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
|
|
3076
|
-
|
|
3077
|
-
|
|
3076
|
+
const currentDiscounts = typeof ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
|
|
3077
|
+
const shouldSkipEmptyDiscountSync = hydratedEditDiscounts.length === 0 && currentDiscounts.length === 0;
|
|
3078
|
+
if (!shouldSkipEmptyDiscountSync) {
|
|
3079
|
+
await ((_b = this.store.discount) == null ? void 0 : _b.setOriginalDiscountList(hydratedEditDiscounts));
|
|
3080
|
+
await ((_c = this.store.discount) == null ? void 0 : _c.setDiscountList(hydratedEditDiscounts));
|
|
3081
|
+
}
|
|
3078
3082
|
if (options == null ? void 0 : options.recalcOnHydrate) {
|
|
3079
3083
|
await this.recalculateSummary({ createIfMissing: false });
|
|
3080
3084
|
}
|
|
@@ -434,6 +434,8 @@ export interface PaymentItemData {
|
|
|
434
434
|
name: string;
|
|
435
435
|
/** 支付类型 */
|
|
436
436
|
type: string;
|
|
437
|
+
/** 支付时间 (格式: YYYY-MM-DD HH:mm:ss) */
|
|
438
|
+
payment_time?: string;
|
|
437
439
|
/** @deprecated BaseSales/Sales 协议不提交该字段;旧 Checkout/Payment 内部仍可能使用 */
|
|
438
440
|
isSynced?: boolean;
|
|
439
441
|
}
|
|
@@ -456,6 +458,7 @@ export interface OrderPaymentData {
|
|
|
456
458
|
origin_amount?: string;
|
|
457
459
|
service_fee?: string;
|
|
458
460
|
status?: 'active' | 'voided' | string;
|
|
461
|
+
/** 支付时间 (格式: YYYY-MM-DD HH:mm:ss) */
|
|
459
462
|
payment_time?: string;
|
|
460
463
|
wallet_pass_usage_unit?: unknown;
|
|
461
464
|
wallet_pass_use_value?: string | number | null;
|
|
@@ -818,6 +818,7 @@ function mapPaymentItemToOrderPayment(paymentItem) {
|
|
|
818
818
|
metadata[key] = item[key];
|
|
819
819
|
}
|
|
820
820
|
}
|
|
821
|
+
const paymentTime = item.payment_time ?? (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
|
|
821
822
|
return {
|
|
822
823
|
...item.order_payment_id !== void 0 ? { order_payment_id: item.order_payment_id } : {},
|
|
823
824
|
amount: String(item.amount ?? "0.00"),
|
|
@@ -829,7 +830,7 @@ function mapPaymentItemToOrderPayment(paymentItem) {
|
|
|
829
830
|
...item.origin_amount !== void 0 ? { origin_amount: String(item.origin_amount) } : {},
|
|
830
831
|
...item.service_fee !== void 0 ? { service_fee: String(item.service_fee) } : {},
|
|
831
832
|
...item.status !== void 0 ? { status: item.status } : {},
|
|
832
|
-
|
|
833
|
+
payment_time: paymentTime,
|
|
833
834
|
...item.wallet_pass_usage_unit !== void 0 ? { wallet_pass_usage_unit: item.wallet_pass_usage_unit } : {},
|
|
834
835
|
...item.wallet_pass_use_value !== void 0 ? { wallet_pass_use_value: item.wallet_pass_use_value } : {},
|
|
835
836
|
...item.fund_record && typeof item.fund_record === "object" && !Array.isArray(item.fund_record) ? { fund_record: { ...item.fund_record } } : {},
|
|
@@ -135,6 +135,8 @@ export interface PaymentItem {
|
|
|
135
135
|
origin_amount?: string;
|
|
136
136
|
/** 订单支付类型 */
|
|
137
137
|
order_payment_type?: 'normal' | 'deposit';
|
|
138
|
+
/** 支付时间 (格式: YYYY-MM-DD HH:mm:ss) */
|
|
139
|
+
payment_time?: string;
|
|
138
140
|
/** 本支付项是否已成功同步到后端 */
|
|
139
141
|
isSynced?: boolean;
|
|
140
142
|
/** 最近一次同步失败信息(存在则代表同步失败过) */
|
|
@@ -100,12 +100,13 @@ var SalesSummaryModule = class extends import_BaseModule.BaseModule {
|
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
async getSummary(params) {
|
|
103
|
+
var _a, _b;
|
|
103
104
|
const { products = [], isPriceIncludeTax, taxRate, shopDiscount } = params;
|
|
104
105
|
const taxConfig = this.getTaxConfig();
|
|
105
106
|
const summarySchedule = this.core.getModule(
|
|
106
107
|
`${this.name.split("_")[0]}_schedule`
|
|
107
108
|
);
|
|
108
|
-
const needScheduleIds = this.store.surchargeList.map((item) => item.available_schedule_ids).flat();
|
|
109
|
+
const needScheduleIds = (_b = (_a = this.store.surchargeList) == null ? void 0 : _a.map((item) => item.available_schedule_ids)) == null ? void 0 : _b.flat();
|
|
109
110
|
const scheduleList = summarySchedule == null ? void 0 : summarySchedule.getScheduleListByIds(needScheduleIds);
|
|
110
111
|
const scheduleById = {};
|
|
111
112
|
if (Array.isArray(scheduleList)) {
|
|
@@ -135,8 +135,10 @@ var ScheduleModule = class extends import_BaseModule.BaseModule {
|
|
|
135
135
|
return dates;
|
|
136
136
|
}
|
|
137
137
|
getScheduleListByIds(ids) {
|
|
138
|
+
var _a;
|
|
138
139
|
const idSet = new Set(ids.map((id) => String(id)));
|
|
139
|
-
|
|
140
|
+
console.log("getScheduleListByIds", this.store.scheduleList);
|
|
141
|
+
const list = (_a = this.store.scheduleList) == null ? void 0 : _a.filter((n) => idSet.has(String(n.id)));
|
|
140
142
|
return list;
|
|
141
143
|
}
|
|
142
144
|
setAvailabilityScheduleDateList(list) {
|
|
@@ -74,10 +74,10 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
|
|
|
74
74
|
this.store.surchargeList = (surchargeList == null ? void 0 : surchargeList.data) || [];
|
|
75
75
|
}
|
|
76
76
|
async getSummary(cartItems) {
|
|
77
|
-
var _a, _b, _c;
|
|
77
|
+
var _a, _b, _c, _d;
|
|
78
78
|
const shopInfo = ((_b = (_a = this.shopStore.get("core")) == null ? void 0 : _a.core) == null ? void 0 : _b.shop) || {};
|
|
79
79
|
const scheduleModule = this.core.getModule("appointmentBooking_schedule");
|
|
80
|
-
const needScheduleIds = this.store.surchargeList.map((item) => item.available_schedule_ids).flat();
|
|
80
|
+
const needScheduleIds = (_c = this.store.surchargeList) == null ? void 0 : _c.map((item) => item.available_schedule_ids).flat();
|
|
81
81
|
const scheduleList = scheduleModule == null ? void 0 : scheduleModule.getScheduleListByIds(needScheduleIds);
|
|
82
82
|
const scheduleById = {};
|
|
83
83
|
if (Array.isArray(scheduleList)) {
|
|
@@ -85,7 +85,7 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
|
|
|
85
85
|
scheduleById[item.id] = item;
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
const summary = (0, import_utils.calculatePriceDetails)(shopInfo, cartItems, (
|
|
88
|
+
const summary = (0, import_utils.calculatePriceDetails)(shopInfo, cartItems, (_d = import_Schedule.ScheduleModule) == null ? void 0 : _d.isInScheduleByDate, this.store.surchargeList, scheduleById);
|
|
89
89
|
this.store.summary = summary;
|
|
90
90
|
return this.store.summary;
|
|
91
91
|
}
|
|
@@ -119,8 +119,9 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
|
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
getSurchargeforUtils(items) {
|
|
122
|
+
var _a;
|
|
122
123
|
const scheduleModule = this.core.getModule("appointmentBooking_schedule");
|
|
123
|
-
const needScheduleIds = this.store.surchargeList.map((item) => item.available_schedule_ids).flat();
|
|
124
|
+
const needScheduleIds = (_a = this.store.surchargeList) == null ? void 0 : _a.map((item) => item.available_schedule_ids).flat();
|
|
124
125
|
const scheduleList = scheduleModule == null ? void 0 : scheduleModule.getScheduleListByIds(needScheduleIds);
|
|
125
126
|
const scheduleById = {};
|
|
126
127
|
if (Array.isArray(scheduleList)) {
|
package/lib/server/index.d.ts
CHANGED
|
@@ -412,6 +412,8 @@ declare class Server {
|
|
|
412
412
|
private getProductTitleSnapshotCurrentLocale;
|
|
413
413
|
private normalizeProductTitleSnapshotLocale;
|
|
414
414
|
private resolveProductTitleValue;
|
|
415
|
+
private canAssignStringProductTitleToLocale;
|
|
416
|
+
private hasCjkText;
|
|
415
417
|
private resolveFirstProductTitleValue;
|
|
416
418
|
private withLocalSmallTicketData;
|
|
417
419
|
private handleOrderSalesDetail;
|
package/lib/server/index.js
CHANGED
|
@@ -2611,6 +2611,7 @@ var Server = class {
|
|
|
2611
2611
|
total_amount: (_d = pendingOrder == null ? void 0 : pendingOrder.summary) == null ? void 0 : _d.total_amount,
|
|
2612
2612
|
payment_status: pendingOrder == null ? void 0 : pendingOrder.payment_status,
|
|
2613
2613
|
payment_info: {
|
|
2614
|
+
...(pendingOrder == null ? void 0 : pendingOrder.payment_info) || {},
|
|
2614
2615
|
current_change_given_amount: changeGivenAmount
|
|
2615
2616
|
}
|
|
2616
2617
|
}
|
|
@@ -2705,11 +2706,22 @@ var Server = class {
|
|
|
2705
2706
|
async buildSmallTicketProductMap(order) {
|
|
2706
2707
|
var _a;
|
|
2707
2708
|
const products = Array.isArray(order == null ? void 0 : order.products) ? order.products : [];
|
|
2708
|
-
const
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
)
|
|
2712
|
-
|
|
2709
|
+
const productIdSet = /* @__PURE__ */ new Set();
|
|
2710
|
+
products.forEach((product) => {
|
|
2711
|
+
const productId = (product == null ? void 0 : product.product_id) ?? (product == null ? void 0 : product.id);
|
|
2712
|
+
if (productId !== void 0 && productId !== null && productId !== "") {
|
|
2713
|
+
productIdSet.add(productId);
|
|
2714
|
+
}
|
|
2715
|
+
if (Array.isArray(product == null ? void 0 : product.product_bundle)) {
|
|
2716
|
+
product.product_bundle.forEach((bundle) => {
|
|
2717
|
+
const bundleProductId = (bundle == null ? void 0 : bundle.bundle_product_id) ?? (bundle == null ? void 0 : bundle._bundle_product_id) ?? (bundle == null ? void 0 : bundle.product_id);
|
|
2718
|
+
if (bundleProductId !== void 0 && bundleProductId !== null && bundleProductId !== "") {
|
|
2719
|
+
productIdSet.add(bundleProductId);
|
|
2720
|
+
}
|
|
2721
|
+
});
|
|
2722
|
+
}
|
|
2723
|
+
});
|
|
2724
|
+
const productIds = Array.from(productIdSet);
|
|
2713
2725
|
if (!productIds.length || typeof ((_a = this.products) == null ? void 0 : _a.getProductById) !== "function")
|
|
2714
2726
|
return {};
|
|
2715
2727
|
const entries = await Promise.all(
|
|
@@ -2777,8 +2789,11 @@ var Server = class {
|
|
|
2777
2789
|
if (value === void 0 || value === null || value === "")
|
|
2778
2790
|
return null;
|
|
2779
2791
|
if (typeof value !== "object") {
|
|
2780
|
-
|
|
2781
|
-
|
|
2792
|
+
const title = String(value);
|
|
2793
|
+
if (key === "auto" || key === "original")
|
|
2794
|
+
return title;
|
|
2795
|
+
if (key === currentLocale && this.canAssignStringProductTitleToLocale(title, currentLocale))
|
|
2796
|
+
return title;
|
|
2782
2797
|
return null;
|
|
2783
2798
|
}
|
|
2784
2799
|
const normalizedKey = key.replace("-", "_");
|
|
@@ -2790,6 +2805,21 @@ var Server = class {
|
|
|
2790
2805
|
return this.resolveFirstProductTitleValue(rawValue);
|
|
2791
2806
|
return String(rawValue);
|
|
2792
2807
|
}
|
|
2808
|
+
canAssignStringProductTitleToLocale(title, locale) {
|
|
2809
|
+
if (!locale)
|
|
2810
|
+
return false;
|
|
2811
|
+
if (locale === "zh-CN" || locale === "zh-HK" || locale === "kitchen") {
|
|
2812
|
+
return this.hasCjkText(title);
|
|
2813
|
+
}
|
|
2814
|
+
if (locale === "ja")
|
|
2815
|
+
return /[\u3040-\u30ff]/.test(title) || this.hasCjkText(title);
|
|
2816
|
+
if (locale === "en" || locale === "pt")
|
|
2817
|
+
return !this.hasCjkText(title);
|
|
2818
|
+
return false;
|
|
2819
|
+
}
|
|
2820
|
+
hasCjkText(value) {
|
|
2821
|
+
return /[\u3400-\u9fff]/.test(value);
|
|
2822
|
+
}
|
|
2793
2823
|
resolveFirstProductTitleValue(value) {
|
|
2794
2824
|
if (value === void 0 || value === null || value === "")
|
|
2795
2825
|
return null;
|
|
@@ -71,6 +71,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
71
71
|
* await this.emitOrdersChanged([freshOrder], 'pubsub.bodyUpsert')
|
|
72
72
|
*/
|
|
73
73
|
async emitOrdersChanged(changedOrders = [], source) {
|
|
74
|
+
console.log("触发emitOrdersChanged");
|
|
74
75
|
const payload = {
|
|
75
76
|
list: this.store.list,
|
|
76
77
|
changedOrders: changedOrders.map((order) => this.normalizeOrderForMemoryList(order)),
|
|
@@ -239,7 +239,7 @@ export interface OrderPaymentItem {
|
|
|
239
239
|
rounding_amount?: OrderMoneyString;
|
|
240
240
|
/** 支付状态:paid / voided / payment_pending 等 */
|
|
241
241
|
status?: OrderPaymentRecordStatus;
|
|
242
|
-
/**
|
|
242
|
+
/** 支付时间(输入/输出均保留)。来源:OrderPayment.payment_time */
|
|
243
243
|
payment_time?: string | null;
|
|
244
244
|
/** 手续费配置。来源:OrderPayment.service_charge */
|
|
245
245
|
service_charge?: Record<string, unknown> | null;
|
|
@@ -168,9 +168,13 @@ function matchOrder(order, ctx) {
|
|
|
168
168
|
return true;
|
|
169
169
|
}
|
|
170
170
|
function matchBooking(booking, orderInfo, ctx) {
|
|
171
|
-
if (ctx.enableChildBookingFilter) {
|
|
172
|
-
const parentId = Number(
|
|
173
|
-
|
|
171
|
+
if (ctx.enableChildBookingFilter && booking.booking_id) {
|
|
172
|
+
const parentId = Number(
|
|
173
|
+
booking.parent_id ?? 0
|
|
174
|
+
);
|
|
175
|
+
const itemType = String(
|
|
176
|
+
booking.item_type ?? ""
|
|
177
|
+
);
|
|
174
178
|
const isMatched = parentId !== 0 && itemType !== "recurring_booking" || parentId === 0 && itemType === "recurring_booking";
|
|
175
179
|
if (!isMatched)
|
|
176
180
|
return false;
|
|
@@ -64,15 +64,15 @@ export declare class ScheduleModuleEx extends BaseModule implements Module, Sche
|
|
|
64
64
|
*/
|
|
65
65
|
getDateIsInSchedule(date: string, scheduleList: (ScheduleItem | number)[]): boolean;
|
|
66
66
|
/**
|
|
67
|
-
* 从
|
|
67
|
+
* 从 SQLite 加载日程数据
|
|
68
68
|
* @private
|
|
69
69
|
*/
|
|
70
|
-
private
|
|
70
|
+
private loadScheduleFromSQLite;
|
|
71
71
|
/**
|
|
72
|
-
* 保存日程数据到
|
|
72
|
+
* 保存日程数据到 SQLite
|
|
73
73
|
* @private
|
|
74
74
|
*/
|
|
75
|
-
private
|
|
75
|
+
private saveScheduleToSQLite;
|
|
76
76
|
/**
|
|
77
77
|
* 预加载模块数据(统一接口)
|
|
78
78
|
* 在模块注册后自动调用
|
|
@@ -40,7 +40,7 @@ var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
|
|
|
40
40
|
var import_utils = require("../../../solution/ShopDiscount/utils");
|
|
41
41
|
import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
42
42
|
import_dayjs.default.extend(import_isSameOrAfter.default);
|
|
43
|
-
var
|
|
43
|
+
var SCHEDULE_STORE_NAME = "schedule";
|
|
44
44
|
var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
|
|
45
45
|
// LoggerManager 实例
|
|
46
46
|
constructor(name, version) {
|
|
@@ -117,12 +117,12 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
|
|
|
117
117
|
const appPlugin = core.getPlugin("app");
|
|
118
118
|
if (appPlugin) {
|
|
119
119
|
const app = appPlugin.getApp();
|
|
120
|
-
this.dbManager = app.
|
|
120
|
+
this.dbManager = app.sqlite;
|
|
121
121
|
this.logger = app.logger;
|
|
122
122
|
if (this.dbManager) {
|
|
123
|
-
console.log("[Schedule]
|
|
123
|
+
console.log("[Schedule] SQLite 已初始化");
|
|
124
124
|
} else {
|
|
125
|
-
console.warn("[Schedule]
|
|
125
|
+
console.warn("[Schedule] SQLite 未找到");
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
this.logInfo("模块初始化完成", {
|
|
@@ -150,7 +150,7 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
|
|
|
150
150
|
scheduleCount: list.length,
|
|
151
151
|
duration: `${duration}ms`
|
|
152
152
|
});
|
|
153
|
-
await this.
|
|
153
|
+
await this.saveScheduleToSQLite(list);
|
|
154
154
|
this.setScheduleList(list);
|
|
155
155
|
return list;
|
|
156
156
|
} catch (error) {
|
|
@@ -220,13 +220,13 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
|
|
|
220
220
|
this.store.map.clear();
|
|
221
221
|
if (this.dbManager) {
|
|
222
222
|
try {
|
|
223
|
-
await this.dbManager.clear(
|
|
224
|
-
console.log("[Schedule]
|
|
225
|
-
this.logInfo("
|
|
223
|
+
await this.dbManager.clear(SCHEDULE_STORE_NAME);
|
|
224
|
+
console.log("[Schedule] SQLite 缓存已清空");
|
|
225
|
+
this.logInfo("SQLite 缓存已清空");
|
|
226
226
|
} catch (error) {
|
|
227
227
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
228
|
-
console.error("[Schedule] 清空
|
|
229
|
-
this.logError("清空
|
|
228
|
+
console.error("[Schedule] 清空 SQLite 缓存失败:", error);
|
|
229
|
+
this.logError("清空 SQLite 缓存失败", { error: errorMessage });
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
this.logInfo("缓存清空完成");
|
|
@@ -255,51 +255,58 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
|
|
|
255
255
|
return result;
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
258
|
-
* 从
|
|
258
|
+
* 从 SQLite 加载日程数据
|
|
259
259
|
* @private
|
|
260
260
|
*/
|
|
261
|
-
async
|
|
261
|
+
async loadScheduleFromSQLite() {
|
|
262
262
|
if (!this.dbManager) {
|
|
263
|
-
this.logWarning("
|
|
263
|
+
this.logWarning("loadScheduleFromSQLite: SQLite 不可用");
|
|
264
264
|
return [];
|
|
265
265
|
}
|
|
266
266
|
try {
|
|
267
|
-
const scheduleList = await this.dbManager.getAll(
|
|
268
|
-
this.logInfo("从
|
|
267
|
+
const scheduleList = await this.dbManager.getAll(SCHEDULE_STORE_NAME);
|
|
268
|
+
this.logInfo("从 SQLite 加载日程数据", {
|
|
269
269
|
scheduleCount: (scheduleList == null ? void 0 : scheduleList.length) ?? 0
|
|
270
270
|
});
|
|
271
271
|
return scheduleList || [];
|
|
272
272
|
} catch (error) {
|
|
273
273
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
274
|
-
console.error("[Schedule] 从
|
|
275
|
-
this.logError("从
|
|
274
|
+
console.error("[Schedule] 从 SQLite 读取数据失败:", error);
|
|
275
|
+
this.logError("从 SQLite 读取数据失败", { error: errorMessage });
|
|
276
276
|
return [];
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
/**
|
|
280
|
-
* 保存日程数据到
|
|
280
|
+
* 保存日程数据到 SQLite
|
|
281
281
|
* @private
|
|
282
282
|
*/
|
|
283
|
-
async
|
|
283
|
+
async saveScheduleToSQLite(scheduleList) {
|
|
284
284
|
if (!this.dbManager) {
|
|
285
|
-
this.logWarning("
|
|
285
|
+
this.logWarning("saveScheduleToSQLite: SQLite 不可用");
|
|
286
286
|
return;
|
|
287
287
|
}
|
|
288
|
-
this.logInfo("开始保存日程数据到
|
|
288
|
+
this.logInfo("开始保存日程数据到 SQLite", { scheduleCount: scheduleList.length });
|
|
289
289
|
try {
|
|
290
|
-
await this.dbManager.clear(
|
|
291
|
-
|
|
292
|
-
(
|
|
293
|
-
|
|
294
|
-
|
|
290
|
+
await this.dbManager.clear(SCHEDULE_STORE_NAME);
|
|
291
|
+
if (scheduleList.length > 0) {
|
|
292
|
+
if (typeof this.dbManager.bulkAdd === "function") {
|
|
293
|
+
await this.dbManager.bulkAdd(SCHEDULE_STORE_NAME, scheduleList);
|
|
294
|
+
} else if (typeof this.dbManager.bulkUpdate === "function") {
|
|
295
|
+
await this.dbManager.bulkUpdate(SCHEDULE_STORE_NAME, scheduleList);
|
|
296
|
+
} else {
|
|
297
|
+
await Promise.all(scheduleList.map(
|
|
298
|
+
(schedule) => this.dbManager.add(SCHEDULE_STORE_NAME, schedule)
|
|
299
|
+
));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
295
302
|
console.log(
|
|
296
|
-
`[Schedule] 已将 ${scheduleList.length} 条日程数据保存到
|
|
303
|
+
`[Schedule] 已将 ${scheduleList.length} 条日程数据保存到 SQLite`
|
|
297
304
|
);
|
|
298
|
-
this.logInfo("日程数据已保存到
|
|
305
|
+
this.logInfo("日程数据已保存到 SQLite", { scheduleCount: scheduleList.length });
|
|
299
306
|
} catch (error) {
|
|
300
307
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
301
|
-
console.error("[Schedule] 保存数据到
|
|
302
|
-
this.logError("保存数据到
|
|
308
|
+
console.error("[Schedule] 保存数据到 SQLite 失败:", error);
|
|
309
|
+
this.logError("保存数据到 SQLite 失败", {
|
|
303
310
|
scheduleCount: scheduleList.length,
|
|
304
311
|
error: errorMessage
|
|
305
312
|
});
|
|
@@ -314,31 +321,30 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
|
|
|
314
321
|
const startTime = Date.now();
|
|
315
322
|
this.logInfo("开始预加载数据");
|
|
316
323
|
try {
|
|
317
|
-
const cachedData = await this.
|
|
324
|
+
const cachedData = await this.loadScheduleFromSQLite();
|
|
318
325
|
if (cachedData && cachedData.length > 0) {
|
|
319
326
|
console.log(
|
|
320
|
-
`[Schedule] 从
|
|
327
|
+
`[Schedule] 从 SQLite 加载了 ${cachedData.length} 条日程数据`
|
|
321
328
|
);
|
|
322
329
|
this.store.scheduleList = (0, import_lodash_es.cloneDeep)(cachedData);
|
|
323
330
|
this.syncScheduleMap();
|
|
324
331
|
const duration = Date.now() - startTime;
|
|
325
|
-
this.logInfo("预加载完成(从
|
|
332
|
+
this.logInfo("预加载完成(从 SQLite)", {
|
|
326
333
|
scheduleCount: cachedData.length,
|
|
327
334
|
duration: `${duration}ms`,
|
|
328
|
-
source: "
|
|
335
|
+
source: "SQLite"
|
|
329
336
|
});
|
|
330
337
|
return;
|
|
331
338
|
}
|
|
332
|
-
console.log("[Schedule]
|
|
333
|
-
this.logInfo("
|
|
339
|
+
console.log("[Schedule] SQLite 中没有缓存数据,从服务器加载...");
|
|
340
|
+
this.logInfo("SQLite 中没有缓存数据,准备从服务器加载");
|
|
334
341
|
} catch (error) {
|
|
335
342
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
336
|
-
console.warn("[Schedule] 从
|
|
337
|
-
this.logWarning("从
|
|
343
|
+
console.warn("[Schedule] 从 SQLite 加载数据失败:", error);
|
|
344
|
+
this.logWarning("从 SQLite 加载数据失败,准备从服务器加载", { error: errorMessage });
|
|
338
345
|
}
|
|
339
346
|
const scheduleList = await this.loadAllSchedule();
|
|
340
347
|
if (scheduleList && scheduleList.length > 0) {
|
|
341
|
-
await this.saveScheduleToIndexDB(scheduleList);
|
|
342
348
|
this.store.scheduleList = (0, import_lodash_es.cloneDeep)(scheduleList);
|
|
343
349
|
this.syncScheduleMap();
|
|
344
350
|
const duration = Date.now() - startTime;
|
|
@@ -144,7 +144,7 @@ function buildBaseData(params) {
|
|
|
144
144
|
var _a;
|
|
145
145
|
const { order, shopInfo, locale } = params;
|
|
146
146
|
const orderNumber = stringify(
|
|
147
|
-
order.
|
|
147
|
+
order.buzzer || order.shop_full_order_number
|
|
148
148
|
);
|
|
149
149
|
return {
|
|
150
150
|
shop_name: stringify(shopInfo.name || order.shop_name),
|
|
@@ -168,21 +168,24 @@ function buildProducts(order, locale, productMap) {
|
|
|
168
168
|
const originalPrice = product.original_price ?? product.selling_price ?? product.payment_price ?? product.price ?? 0;
|
|
169
169
|
const sellingPrice = product.selling_price ?? product.payment_price ?? product.price ?? originalPrice;
|
|
170
170
|
const productTitle = resolveProductTitle({ product, productMap, locale });
|
|
171
|
+
const currencySymbol = getCurrencySymbol(order, null);
|
|
172
|
+
const options = normalizeProductOptions({ product, locale, currencySymbol });
|
|
173
|
+
const combinations = normalizeProductCombinations({
|
|
174
|
+
product,
|
|
175
|
+
productMap,
|
|
176
|
+
locale,
|
|
177
|
+
currencySymbol
|
|
178
|
+
});
|
|
171
179
|
return {
|
|
172
180
|
product_title: productTitle,
|
|
173
181
|
product_quantity: quantity,
|
|
174
|
-
selling_price: formatMoney(sellingPrice,
|
|
175
|
-
original_price: formatMoney(originalPrice,
|
|
176
|
-
total_original_price: formatMoney(new import_decimal.default(toMoneyNumber(originalPrice)).mul(quantity),
|
|
182
|
+
selling_price: formatMoney(sellingPrice, currencySymbol),
|
|
183
|
+
original_price: formatMoney(originalPrice, currencySymbol),
|
|
184
|
+
total_original_price: formatMoney(new import_decimal.default(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
|
|
177
185
|
extension_list: Array.isArray(product.extension_list) ? product.extension_list : [],
|
|
178
|
-
...
|
|
179
|
-
options: product.options.map((option) => ({
|
|
180
|
-
name: getLocalizedValue(option.name || option.title, locale),
|
|
181
|
-
value: getLocalizedValue(option.value || option.option || option.item, locale)
|
|
182
|
-
}))
|
|
183
|
-
} : {},
|
|
186
|
+
...options.length ? { options } : {},
|
|
184
187
|
...product.variant ? { variant: getLocalizedValue(product.variant, locale) } : {},
|
|
185
|
-
...Array.isArray(product.combinations) ? { combinations: product.combinations } : {}
|
|
188
|
+
...Array.isArray(product.combinations) ? { combinations: product.combinations } : combinations.length ? { combinations } : {}
|
|
186
189
|
};
|
|
187
190
|
});
|
|
188
191
|
}
|
|
@@ -204,6 +207,77 @@ function resolveProductTitle(params) {
|
|
|
204
207
|
locale
|
|
205
208
|
);
|
|
206
209
|
}
|
|
210
|
+
function normalizeProductOptions(params) {
|
|
211
|
+
var _a;
|
|
212
|
+
const { product, locale, currencySymbol } = params;
|
|
213
|
+
const rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray((_a = product.product_sku) == null ? void 0 : _a.option) ? product.product_sku.option : [];
|
|
214
|
+
return rawOptions.map((option) => {
|
|
215
|
+
const price = option.original_price ?? option.add_price ?? option.price;
|
|
216
|
+
const value = option.value ?? option.option ?? option.item;
|
|
217
|
+
return {
|
|
218
|
+
name: getLocalizedValue(option.name || option.title, locale),
|
|
219
|
+
...option.num !== void 0 || option.quantity !== void 0 ? { num: toNumber(option.num ?? option.quantity, 1) } : {},
|
|
220
|
+
...price !== void 0 && price !== null && price !== "" ? { price: formatMoney(price, currencySymbol) } : {},
|
|
221
|
+
...value !== void 0 && value !== null && value !== "" ? { value: getLocalizedValue(value, locale) } : {}
|
|
222
|
+
};
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function normalizeProductCombinations(params) {
|
|
226
|
+
const { product, productMap, locale, currencySymbol } = params;
|
|
227
|
+
const bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
|
|
228
|
+
return bundles.map((bundle) => {
|
|
229
|
+
const combinationsOptions = normalizeProductOptions({
|
|
230
|
+
product: {},
|
|
231
|
+
locale,
|
|
232
|
+
currencySymbol,
|
|
233
|
+
options: Array.isArray(bundle.option) ? bundle.option : []
|
|
234
|
+
});
|
|
235
|
+
const baseTitle = resolveBundleProductTitle({ bundle, productMap, locale });
|
|
236
|
+
const optionTitle = buildOptionTitleSuffix(combinationsOptions);
|
|
237
|
+
return {
|
|
238
|
+
product_title: `${baseTitle}${optionTitle}`,
|
|
239
|
+
product_quantity: toNumber(bundle.num ?? bundle.quantity ?? 1, 1),
|
|
240
|
+
price: formatBundlePrice(bundle, currencySymbol),
|
|
241
|
+
combinations_options: combinationsOptions
|
|
242
|
+
};
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function resolveBundleProductTitle(params) {
|
|
246
|
+
var _a, _b;
|
|
247
|
+
const { bundle, productMap, locale } = params;
|
|
248
|
+
const ownTitle = getLocalizedValue(
|
|
249
|
+
bundle.product_title || bundle.title || bundle.name || ((_a = bundle.product) == null ? void 0 : _a.title),
|
|
250
|
+
locale
|
|
251
|
+
);
|
|
252
|
+
if (ownTitle)
|
|
253
|
+
return ownTitle;
|
|
254
|
+
const productId = bundle.bundle_product_id ?? bundle._bundle_product_id ?? bundle.product_id ?? bundle.id;
|
|
255
|
+
const fallbackProduct = productId !== void 0 && productId !== null ? productMap[productId] || productMap[String(productId)] : null;
|
|
256
|
+
if (!fallbackProduct)
|
|
257
|
+
return "";
|
|
258
|
+
return getLocalizedValue(
|
|
259
|
+
fallbackProduct.product_title || fallbackProduct.title || fallbackProduct.name || fallbackProduct.format_title || ((_b = fallbackProduct.product) == null ? void 0 : _b.title),
|
|
260
|
+
locale
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
function buildOptionTitleSuffix(options) {
|
|
264
|
+
const text = options.map((option) => {
|
|
265
|
+
const name = stringify(option.name).trim();
|
|
266
|
+
if (!name)
|
|
267
|
+
return "";
|
|
268
|
+
const quantity = option.num ?? 1;
|
|
269
|
+
return `${name} x ${quantity}`;
|
|
270
|
+
}).filter(Boolean).join(", ");
|
|
271
|
+
return text ? `(${text})` : "";
|
|
272
|
+
}
|
|
273
|
+
function formatBundlePrice(bundle, currencySymbol) {
|
|
274
|
+
const value = bundle.bundle_selling_price ?? bundle.bundle_sum_price ?? bundle.price ?? 0;
|
|
275
|
+
const amount = new import_decimal.default(toMoneyNumber(value));
|
|
276
|
+
const isNegative = bundle.price_type === "markdown" || bundle.price_type === "markup" && bundle.price_type_ext === "product_price";
|
|
277
|
+
if (isNegative)
|
|
278
|
+
return `-${currencySymbol}${amount.abs().toFixed(2)}`;
|
|
279
|
+
return formatMoney(amount, currencySymbol);
|
|
280
|
+
}
|
|
207
281
|
function buildFees(params) {
|
|
208
282
|
const { order, shopInfo, locale, products, summary, currencySymbol } = params;
|
|
209
283
|
const fees = [];
|