@pisell/pisellos 2.2.210 → 2.2.212
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/BookingContext/index.d.ts +13 -2
- package/dist/modules/BookingContext/index.js +198 -68
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +3 -0
- package/dist/modules/Order/index.d.ts +36 -0
- package/dist/modules/Order/index.js +312 -127
- package/dist/modules/Order/types.d.ts +4 -1
- package/dist/modules/Order/utils.d.ts +1 -0
- package/dist/modules/Order/utils.js +12 -7
- package/dist/modules/Quotation/index.js +2 -1
- package/dist/modules/SalesSummary/index.d.ts +1 -0
- package/dist/modules/SalesSummary/index.js +29 -15
- package/dist/modules/SurchargeList/index.d.ts +16 -0
- package/dist/modules/SurchargeList/index.js +162 -0
- package/dist/modules/SurchargeList/types.d.ts +11 -0
- package/dist/modules/SurchargeList/types.js +1 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.js +1075 -915
- package/dist/server/modules/order/index.d.ts +9 -0
- package/dist/server/modules/order/index.js +557 -411
- package/dist/server/modules/order/utils/filterBookings.js +25 -2
- package/dist/server/modules/order/utils/filterOrders.js +3 -2
- package/dist/server/test.json +713 -0
- package/dist/server/utils/small-ticket.d.ts +1 -1
- package/dist/server/utils/small-ticket.js +1 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +22 -20
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/modules/BookingContext/index.d.ts +13 -2
- package/lib/modules/BookingContext/index.js +99 -28
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +3 -0
- package/lib/modules/Order/index.d.ts +36 -0
- package/lib/modules/Order/index.js +123 -1
- package/lib/modules/Order/types.d.ts +4 -1
- package/lib/modules/Order/utils.d.ts +1 -0
- package/lib/modules/Order/utils.js +12 -4
- package/lib/modules/Quotation/index.js +1 -1
- package/lib/modules/SalesSummary/index.d.ts +1 -0
- package/lib/modules/SalesSummary/index.js +11 -1
- package/lib/modules/SurchargeList/index.d.ts +16 -0
- package/lib/modules/SurchargeList/index.js +89 -0
- package/lib/modules/SurchargeList/types.d.ts +11 -0
- package/lib/modules/SurchargeList/types.js +17 -0
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +2 -0
- package/lib/server/index.d.ts +8 -0
- package/lib/server/index.js +134 -19
- package/lib/server/modules/order/index.d.ts +9 -0
- package/lib/server/modules/order/index.js +107 -19
- package/lib/server/modules/order/utils/filterBookings.js +17 -2
- package/lib/server/modules/order/utils/filterOrders.js +3 -2
- package/lib/server/test.json +713 -0
- package/lib/server/utils/small-ticket.d.ts +1 -1
- package/lib/server/utils/small-ticket.js +1 -35
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +12 -7
- package/package.json +1 -1
|
@@ -249,7 +249,7 @@ export interface OrderTempOrder {
|
|
|
249
249
|
delivery_type?: string;
|
|
250
250
|
table_number?: Record<string, any>;
|
|
251
251
|
schedule_date: string;
|
|
252
|
-
created_at: string;
|
|
252
|
+
created_at: string | undefined;
|
|
253
253
|
request_unique_idempotency_token?: string;
|
|
254
254
|
products: OrderProduct[];
|
|
255
255
|
bookings: any[];
|
|
@@ -261,6 +261,7 @@ export interface OrderTempOrder {
|
|
|
261
261
|
contacts_info: Record<string, any> | null;
|
|
262
262
|
holder: Record<string, any> | null;
|
|
263
263
|
metadata: Record<string, any>;
|
|
264
|
+
summary?: OrderSummary;
|
|
264
265
|
_extend?: {
|
|
265
266
|
productsByUid?: Record<string, Record<string, any>>;
|
|
266
267
|
[key: string]: any;
|
|
@@ -280,6 +281,7 @@ export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'p
|
|
|
280
281
|
form_record_id: number | string;
|
|
281
282
|
}>;
|
|
282
283
|
products: OrderSubmitProduct[];
|
|
284
|
+
summary?: OrderSummary;
|
|
283
285
|
small_ticket_data_flag?: number;
|
|
284
286
|
}
|
|
285
287
|
export interface OrderState {
|
|
@@ -410,6 +412,7 @@ export interface SubmitSalesOrderParams {
|
|
|
410
412
|
contacts_info: Record<string, any> | null;
|
|
411
413
|
holder: Record<string, any> | null;
|
|
412
414
|
metadata: Record<string, any>;
|
|
415
|
+
summary?: OrderSummary;
|
|
413
416
|
small_ticket_data_flag?: number;
|
|
414
417
|
};
|
|
415
418
|
}
|
|
@@ -187,6 +187,7 @@ export declare function buildSubmitPayload(params: {
|
|
|
187
187
|
businessCode?: string;
|
|
188
188
|
channel?: string;
|
|
189
189
|
type?: string;
|
|
190
|
+
summary?: OrderSummary | null;
|
|
190
191
|
enhance?: SubmitPayloadEnhancer;
|
|
191
192
|
}): OrderSubmitPayload;
|
|
192
193
|
export declare function mapPaymentItemToOrderPayment(paymentItem: OrderPaymentSource): OrderPaymentData;
|
|
@@ -608,7 +608,8 @@ var SUBMIT_BOOKING_METADATA_WHITELIST = [
|
|
|
608
608
|
"collect_pax",
|
|
609
609
|
"capacity",
|
|
610
610
|
"holder_id",
|
|
611
|
-
"resource_select_type"
|
|
611
|
+
"resource_select_type",
|
|
612
|
+
"holder"
|
|
612
613
|
];
|
|
613
614
|
function normalizeBookingIsAll(booking) {
|
|
614
615
|
return booking.is_all === true || booking.is_all === 1 || booking.is_all === "1" || booking.is_all === "true" ? 1 : 0;
|
|
@@ -684,7 +685,7 @@ function createDefaultTempOrder(params) {
|
|
|
684
685
|
surcharge_fee: "0.00",
|
|
685
686
|
note: "",
|
|
686
687
|
schedule_date: params.now,
|
|
687
|
-
created_at:
|
|
688
|
+
created_at: void 0,
|
|
688
689
|
request_unique_idempotency_token: "",
|
|
689
690
|
vouchers: [],
|
|
690
691
|
products: [],
|
|
@@ -711,6 +712,7 @@ function buildSubmitPayload(params) {
|
|
|
711
712
|
businessCode,
|
|
712
713
|
channel,
|
|
713
714
|
type,
|
|
715
|
+
summary,
|
|
714
716
|
enhance
|
|
715
717
|
} = params;
|
|
716
718
|
const scheduleDate = tempOrder.schedule_date || tempOrder.created_at || formatDateTime(now);
|
|
@@ -778,7 +780,7 @@ function buildSubmitPayload(params) {
|
|
|
778
780
|
// contacts: tempOrder.contacts || [],
|
|
779
781
|
contacts_info: tempOrder.contacts_info && !Array.isArray(tempOrder.contacts_info) ? tempOrder.contacts_info : null,
|
|
780
782
|
// holder: tempOrder.holder || null,
|
|
781
|
-
|
|
783
|
+
summary: summary || tempOrder.summary || (0, import_utils.createEmptySummary)(),
|
|
782
784
|
metadata: (() => {
|
|
783
785
|
const {
|
|
784
786
|
collect_pax: _collectPax,
|
|
@@ -791,7 +793,13 @@ function buildSubmitPayload(params) {
|
|
|
791
793
|
(product) => normalizeSubmitProduct(product)
|
|
792
794
|
)
|
|
793
795
|
};
|
|
794
|
-
|
|
796
|
+
if (!enhance)
|
|
797
|
+
return payload;
|
|
798
|
+
const enhancedPayload = enhance(payload, { tempOrder, bookingUuid, now });
|
|
799
|
+
return {
|
|
800
|
+
...enhancedPayload,
|
|
801
|
+
summary: enhancedPayload.summary ?? payload.summary
|
|
802
|
+
};
|
|
795
803
|
}
|
|
796
804
|
function mapPaymentItemToOrderPayment(paymentItem) {
|
|
797
805
|
const item = paymentItem;
|
|
@@ -49,7 +49,7 @@ var QuotationModule = class extends import_BaseModule.BaseModule {
|
|
|
49
49
|
const res = await this.request.get(
|
|
50
50
|
"/quotation/available",
|
|
51
51
|
query,
|
|
52
|
-
{ useCache: false }
|
|
52
|
+
{ useCache: false, osServer: true }
|
|
53
53
|
);
|
|
54
54
|
const list = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) || (res == null ? void 0 : res.list) || [];
|
|
55
55
|
list.sort((a, b) => a.sort - b.sort);
|
|
@@ -8,6 +8,7 @@ export declare class SalesSummaryModule extends BaseModule implements Module, Sa
|
|
|
8
8
|
private appPlugin;
|
|
9
9
|
private store;
|
|
10
10
|
private request;
|
|
11
|
+
private surchargeListModuleName;
|
|
11
12
|
constructor(name?: string, version?: string);
|
|
12
13
|
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
13
14
|
getSurchargeList(): Promise<void>;
|
|
@@ -38,15 +38,17 @@ var SalesSummaryModule = class extends import_BaseModule.BaseModule {
|
|
|
38
38
|
super(name, version);
|
|
39
39
|
this.defaultName = "salesSummary";
|
|
40
40
|
this.defaultVersion = "1.0.0";
|
|
41
|
+
this.surchargeListModuleName = "surchargeList";
|
|
41
42
|
}
|
|
42
43
|
async initialize(core, options) {
|
|
43
|
-
var _a, _b;
|
|
44
|
+
var _a, _b, _c;
|
|
44
45
|
this.core = core;
|
|
45
46
|
this.store = options.store;
|
|
46
47
|
this.appPlugin = this.core.getPlugin("app");
|
|
47
48
|
this.request = this.core.getPlugin("request");
|
|
48
49
|
this.store.surchargeList = ((_a = options.initialState) == null ? void 0 : _a.surchargeList) || [];
|
|
49
50
|
this.store.summary = ((_b = options.initialState) == null ? void 0 : _b.summary) || (0, import_utils.createEmptySalesSummary)();
|
|
51
|
+
this.surchargeListModuleName = ((_c = options.otherParams) == null ? void 0 : _c.surchargeListModuleName) || "surchargeList";
|
|
50
52
|
if (!this.appPlugin) {
|
|
51
53
|
throw new Error("SalesSummaryModule 需要 app 插件支持");
|
|
52
54
|
}
|
|
@@ -57,9 +59,17 @@ var SalesSummaryModule = class extends import_BaseModule.BaseModule {
|
|
|
57
59
|
}
|
|
58
60
|
async getSurchargeList() {
|
|
59
61
|
try {
|
|
62
|
+
const surchargeListModule = this.core.getModule(
|
|
63
|
+
this.surchargeListModuleName
|
|
64
|
+
);
|
|
65
|
+
if (surchargeListModule == null ? void 0 : surchargeListModule.getSurchargeList) {
|
|
66
|
+
this.store.surchargeList = await surchargeListModule.getSurchargeList();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
60
69
|
const surchargeList = await this.request.get(
|
|
61
70
|
"/order/custom-surcharge/available/v2",
|
|
62
71
|
{
|
|
72
|
+
// TODO 真实的渠道
|
|
63
73
|
channel: "online-store",
|
|
64
74
|
is_assemble_product_data: 1,
|
|
65
75
|
is_assemble_schedule_data: 1,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Module, ModuleOptions, PisellCore } from '../../types';
|
|
2
|
+
import { BaseModule } from '../BaseModule';
|
|
3
|
+
import { SurchargeListItem, SurchargeListModuleAPI } from './types';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export declare class SurchargeListModule extends BaseModule implements Module, SurchargeListModuleAPI {
|
|
6
|
+
protected defaultName: string;
|
|
7
|
+
protected defaultVersion: string;
|
|
8
|
+
private request;
|
|
9
|
+
private store;
|
|
10
|
+
private loadingPromise;
|
|
11
|
+
constructor(name?: string, version?: string);
|
|
12
|
+
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
13
|
+
getSurchargeList(): Promise<SurchargeListItem[]>;
|
|
14
|
+
refreshSurchargeList(): Promise<SurchargeListItem[]>;
|
|
15
|
+
private loadSurchargeList;
|
|
16
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/modules/SurchargeList/index.ts
|
|
21
|
+
var SurchargeList_exports = {};
|
|
22
|
+
__export(SurchargeList_exports, {
|
|
23
|
+
SurchargeListModule: () => SurchargeListModule
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(SurchargeList_exports);
|
|
26
|
+
var import_BaseModule = require("../BaseModule");
|
|
27
|
+
__reExport(SurchargeList_exports, require("./types"), module.exports);
|
|
28
|
+
var SurchargeListModule = class extends import_BaseModule.BaseModule {
|
|
29
|
+
constructor(name, version) {
|
|
30
|
+
super(name, version);
|
|
31
|
+
this.defaultName = "surchargeList";
|
|
32
|
+
this.defaultVersion = "1.0.0";
|
|
33
|
+
this.loadingPromise = null;
|
|
34
|
+
}
|
|
35
|
+
async initialize(core, options) {
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
this.core = core;
|
|
38
|
+
this.store = options.store;
|
|
39
|
+
this.request = this.core.getPlugin("request");
|
|
40
|
+
const hasInitialSurchargeList = Array.isArray(
|
|
41
|
+
(_a = options.initialState) == null ? void 0 : _a.surchargeList
|
|
42
|
+
);
|
|
43
|
+
this.store.surchargeList = hasInitialSurchargeList ? (_b = options.initialState) == null ? void 0 : _b.surchargeList : [];
|
|
44
|
+
this.store.isLoaded = Boolean((_c = options.initialState) == null ? void 0 : _c.isLoaded) || hasInitialSurchargeList;
|
|
45
|
+
if (!this.request) {
|
|
46
|
+
throw new Error("SurchargeListModule 需要 request 插件支持");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async getSurchargeList() {
|
|
50
|
+
if (this.store.isLoaded)
|
|
51
|
+
return this.store.surchargeList;
|
|
52
|
+
if (this.loadingPromise)
|
|
53
|
+
return this.loadingPromise;
|
|
54
|
+
this.loadingPromise = this.loadSurchargeList();
|
|
55
|
+
return this.loadingPromise;
|
|
56
|
+
}
|
|
57
|
+
async refreshSurchargeList() {
|
|
58
|
+
this.loadingPromise = this.loadSurchargeList();
|
|
59
|
+
return this.loadingPromise;
|
|
60
|
+
}
|
|
61
|
+
async loadSurchargeList() {
|
|
62
|
+
try {
|
|
63
|
+
const surchargeList = await this.request.get(
|
|
64
|
+
"/order/custom-surcharge/available/v2",
|
|
65
|
+
{
|
|
66
|
+
channel: "online-store",
|
|
67
|
+
is_assemble_product_data: 1,
|
|
68
|
+
is_assemble_schedule_data: 1,
|
|
69
|
+
with: ["relationSchedule"]
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
this.store.surchargeList = (surchargeList == null ? void 0 : surchargeList.data) || [];
|
|
73
|
+
this.store.isLoaded = true;
|
|
74
|
+
return this.store.surchargeList;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.warn("[SurchargeListModule] 加载附加费配置失败", error);
|
|
77
|
+
this.store.surchargeList = [];
|
|
78
|
+
this.store.isLoaded = true;
|
|
79
|
+
return this.store.surchargeList;
|
|
80
|
+
} finally {
|
|
81
|
+
this.loadingPromise = null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
SurchargeListModule,
|
|
88
|
+
...require("./types")
|
|
89
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface SurchargeListItem {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}
|
|
4
|
+
export interface SurchargeListState {
|
|
5
|
+
surchargeList: SurchargeListItem[];
|
|
6
|
+
isLoaded: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface SurchargeListModuleAPI {
|
|
9
|
+
getSurchargeList(): Promise<SurchargeListItem[]>;
|
|
10
|
+
refreshSurchargeList(): Promise<SurchargeListItem[]>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/modules/SurchargeList/types.ts
|
|
16
|
+
var types_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(types_exports);
|
package/lib/modules/index.d.ts
CHANGED
package/lib/modules/index.js
CHANGED
|
@@ -30,6 +30,7 @@ __reExport(modules_exports, require("./Resource"), module.exports);
|
|
|
30
30
|
__reExport(modules_exports, require("./Step"), module.exports);
|
|
31
31
|
__reExport(modules_exports, require("./Summary"), module.exports);
|
|
32
32
|
__reExport(modules_exports, require("./SalesSummary"), module.exports);
|
|
33
|
+
__reExport(modules_exports, require("./SurchargeList"), module.exports);
|
|
33
34
|
__reExport(modules_exports, require("./Schedule"), module.exports);
|
|
34
35
|
__reExport(modules_exports, require("./Quotation"), module.exports);
|
|
35
36
|
__reExport(modules_exports, require("./ScanOrderLogger"), module.exports);
|
|
@@ -51,6 +52,7 @@ __reExport(modules_exports, require("./BookingContext"), module.exports);
|
|
|
51
52
|
...require("./Step"),
|
|
52
53
|
...require("./Summary"),
|
|
53
54
|
...require("./SalesSummary"),
|
|
55
|
+
...require("./SurchargeList"),
|
|
54
56
|
...require("./Schedule"),
|
|
55
57
|
...require("./Quotation"),
|
|
56
58
|
...require("./ScanOrderLogger"),
|
package/lib/server/index.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ declare class Server {
|
|
|
27
27
|
payment?: PaymentServerModule;
|
|
28
28
|
private paymentRouteModule?;
|
|
29
29
|
private paymentRouteModuleInFlight?;
|
|
30
|
+
private quotationAvailableCache;
|
|
31
|
+
private quotationAvailableInFlight;
|
|
30
32
|
/** GET 前缀路由(最长前缀优先匹配) */
|
|
31
33
|
private prefixRouterGet;
|
|
32
34
|
router: Router;
|
|
@@ -177,6 +179,9 @@ declare class Server {
|
|
|
177
179
|
private registerServerRoutes;
|
|
178
180
|
private getPaymentRouteModule;
|
|
179
181
|
private handlePaymentMethods;
|
|
182
|
+
private handleQuotationAvailable;
|
|
183
|
+
private fetchQuotationAvailableFromAPI;
|
|
184
|
+
private isSuccessfulRemoteResponse;
|
|
180
185
|
/**
|
|
181
186
|
* 根据 subscriberId 移除商品查询订阅者
|
|
182
187
|
*/
|
|
@@ -432,6 +437,9 @@ declare class Server {
|
|
|
432
437
|
private shouldForceRemoteSalesDetail;
|
|
433
438
|
private buildOrderSalesDetailBackendPath;
|
|
434
439
|
private extractOrderDataFromCheckoutResponse;
|
|
440
|
+
private getCheckoutExternalSaleNumber;
|
|
441
|
+
private buildCheckoutSyncSuccessPatch;
|
|
442
|
+
private isMergeableCheckoutOrder;
|
|
435
443
|
private normalizeCheckoutResponse;
|
|
436
444
|
private isCheckoutResponseRejected;
|
|
437
445
|
private extractBackendErrorResponse;
|
package/lib/server/index.js
CHANGED
|
@@ -53,6 +53,8 @@ var import_small_ticket = require("./utils/small-ticket");
|
|
|
53
53
|
__reExport(server_exports, require("./modules"), module.exports);
|
|
54
54
|
var Server = class {
|
|
55
55
|
constructor(core) {
|
|
56
|
+
this.quotationAvailableCache = /* @__PURE__ */ new Map();
|
|
57
|
+
this.quotationAvailableInFlight = /* @__PURE__ */ new Map();
|
|
56
58
|
/** GET 前缀路由(最长前缀优先匹配) */
|
|
57
59
|
this.prefixRouterGet = [];
|
|
58
60
|
// 路由注册表
|
|
@@ -167,6 +169,29 @@ var Server = class {
|
|
|
167
169
|
data: payMethods
|
|
168
170
|
};
|
|
169
171
|
};
|
|
172
|
+
this.handleQuotationAvailable = async ({ data }) => {
|
|
173
|
+
const queryPayload = data && typeof data === "object" ? { ...data } : {};
|
|
174
|
+
const cacheKey = this.stableSerialize(queryPayload);
|
|
175
|
+
if (this.quotationAvailableCache.has(cacheKey)) {
|
|
176
|
+
this.logInfo("handleQuotationAvailable: 命中运行时缓存", { cacheKey });
|
|
177
|
+
return this.quotationAvailableCache.get(cacheKey);
|
|
178
|
+
}
|
|
179
|
+
const inFlight = this.quotationAvailableInFlight.get(cacheKey);
|
|
180
|
+
if (inFlight) {
|
|
181
|
+
this.logInfo("handleQuotationAvailable: 复用进行中的请求", { cacheKey });
|
|
182
|
+
return inFlight;
|
|
183
|
+
}
|
|
184
|
+
const requestPromise = this.fetchQuotationAvailableFromAPI(queryPayload).then((response) => {
|
|
185
|
+
if (this.isSuccessfulRemoteResponse(response)) {
|
|
186
|
+
this.quotationAvailableCache.set(cacheKey, response);
|
|
187
|
+
}
|
|
188
|
+
return response;
|
|
189
|
+
}).finally(() => {
|
|
190
|
+
this.quotationAvailableInFlight.delete(cacheKey);
|
|
191
|
+
});
|
|
192
|
+
this.quotationAvailableInFlight.set(cacheKey, requestPromise);
|
|
193
|
+
return requestPromise;
|
|
194
|
+
};
|
|
170
195
|
/**
|
|
171
196
|
* 处理商品查询请求
|
|
172
197
|
* 存储订阅者信息,便于数据变更时推送最新结果
|
|
@@ -1091,7 +1116,7 @@ var Server = class {
|
|
|
1091
1116
|
return this.taskTimeout("app.request 不可用");
|
|
1092
1117
|
}
|
|
1093
1118
|
try {
|
|
1094
|
-
const response = await this.app.request.post(
|
|
1119
|
+
const response = await this.app.request.post(backendPath, data, {
|
|
1095
1120
|
isShopApi: true,
|
|
1096
1121
|
customToast: () => {
|
|
1097
1122
|
}
|
|
@@ -1105,28 +1130,47 @@ var Server = class {
|
|
|
1105
1130
|
return this.taskFail("BACKEND_REJECTED", message, response);
|
|
1106
1131
|
}
|
|
1107
1132
|
const fresh = this.extractOrderDataFromCheckoutResponse(response);
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1133
|
+
const externalSaleNumber = this.getCheckoutExternalSaleNumber(data, payload);
|
|
1134
|
+
const shouldMergeRemoteOrder = fresh ? this.isMergeableCheckoutOrder(fresh, externalSaleNumber) : false;
|
|
1135
|
+
let syncedOrder;
|
|
1136
|
+
if (this.order && fresh && shouldMergeRemoteOrder) {
|
|
1137
|
+
syncedOrder = {
|
|
1138
|
+
...fresh,
|
|
1139
|
+
external_sale_number: fresh.external_sale_number ?? externalSaleNumber,
|
|
1140
|
+
need_sync: 0
|
|
1141
|
+
};
|
|
1117
1142
|
await this.order.upsertOrdersFromRemote([syncedOrder]);
|
|
1118
|
-
this.logInfo(`${title}: sync_sales
|
|
1143
|
+
this.logInfo(`${title}: sync_sales 完整订单已同步到本地`, {
|
|
1119
1144
|
order_id: fresh.order_id,
|
|
1120
|
-
external_sale_number:
|
|
1145
|
+
external_sale_number: syncedOrder.external_sale_number,
|
|
1121
1146
|
order_number: fresh.order_number
|
|
1122
1147
|
});
|
|
1148
|
+
} else if (this.order && externalSaleNumber && typeof this.order.markOrderSyncedByExternalSaleNumber === "function") {
|
|
1149
|
+
const patch = this.buildCheckoutSyncSuccessPatch(fresh);
|
|
1150
|
+
const result = await this.order.markOrderSyncedByExternalSaleNumber({
|
|
1151
|
+
externalSaleNumber,
|
|
1152
|
+
patch
|
|
1153
|
+
});
|
|
1154
|
+
syncedOrder = (result == null ? void 0 : result.order) || {
|
|
1155
|
+
...data,
|
|
1156
|
+
...patch,
|
|
1157
|
+
external_sale_number: externalSaleNumber,
|
|
1158
|
+
need_sync: 0
|
|
1159
|
+
};
|
|
1160
|
+
this.logInfo(`${title}: sync_sales 已按 external_sale_number 标记本地订单`, {
|
|
1161
|
+
order_id: (syncedOrder == null ? void 0 : syncedOrder.order_id) ?? null,
|
|
1162
|
+
external_sale_number: externalSaleNumber,
|
|
1163
|
+
hasRemoteOrder: !!fresh,
|
|
1164
|
+
mergedRemoteOrder: false
|
|
1165
|
+
});
|
|
1123
1166
|
} else {
|
|
1124
1167
|
this.logWarning(`${title}: sync_sales Order 模块未注册`, {
|
|
1125
1168
|
backendPath,
|
|
1126
|
-
|
|
1169
|
+
external_sale_number: externalSaleNumber,
|
|
1170
|
+
order_id: fresh == null ? void 0 : fresh.order_id
|
|
1127
1171
|
});
|
|
1128
1172
|
}
|
|
1129
|
-
if (this.shouldPrintSyncedOrder({ checkoutData: data, syncedOrder })) {
|
|
1173
|
+
if (syncedOrder && this.shouldPrintSyncedOrder({ checkoutData: data, syncedOrder })) {
|
|
1130
1174
|
await this.dispatchPrintOtherReceiptTask({
|
|
1131
1175
|
checkoutData: data,
|
|
1132
1176
|
syncedOrder,
|
|
@@ -1135,7 +1179,7 @@ var Server = class {
|
|
|
1135
1179
|
});
|
|
1136
1180
|
}
|
|
1137
1181
|
return this.taskOk({
|
|
1138
|
-
order: syncedOrder,
|
|
1182
|
+
order: syncedOrder ?? null,
|
|
1139
1183
|
response: this.normalizeCheckoutResponse(response)
|
|
1140
1184
|
});
|
|
1141
1185
|
} catch (error) {
|
|
@@ -1504,6 +1548,16 @@ var Server = class {
|
|
|
1504
1548
|
path: "/shop/pay/custom-payment/all",
|
|
1505
1549
|
handler: this.handlePaymentMethods.bind(this)
|
|
1506
1550
|
},
|
|
1551
|
+
{
|
|
1552
|
+
method: "get",
|
|
1553
|
+
path: "/shop/quotation/available",
|
|
1554
|
+
handler: this.handleQuotationAvailable.bind(this)
|
|
1555
|
+
},
|
|
1556
|
+
{
|
|
1557
|
+
method: "get",
|
|
1558
|
+
path: "/quotation/available",
|
|
1559
|
+
handler: this.handleQuotationAvailable.bind(this)
|
|
1560
|
+
},
|
|
1507
1561
|
{
|
|
1508
1562
|
method: "post",
|
|
1509
1563
|
path: "/shop/order/sales/checkout",
|
|
@@ -1552,6 +1606,31 @@ var Server = class {
|
|
|
1552
1606
|
});
|
|
1553
1607
|
return this.paymentRouteModuleInFlight;
|
|
1554
1608
|
}
|
|
1609
|
+
async fetchQuotationAvailableFromAPI(data) {
|
|
1610
|
+
var _a;
|
|
1611
|
+
const requester = ((_a = this.app) == null ? void 0 : _a.request) || this.core.getPlugin("request");
|
|
1612
|
+
if (!(requester == null ? void 0 : requester.get)) {
|
|
1613
|
+
this.logError("fetchQuotationAvailableFromAPI: request 不可用");
|
|
1614
|
+
return {
|
|
1615
|
+
code: 500,
|
|
1616
|
+
message: "request 不可用",
|
|
1617
|
+
data: { list: [] },
|
|
1618
|
+
status: false
|
|
1619
|
+
};
|
|
1620
|
+
}
|
|
1621
|
+
return requester.get("/shop/quotation/available", data);
|
|
1622
|
+
}
|
|
1623
|
+
isSuccessfulRemoteResponse(response) {
|
|
1624
|
+
if (!response)
|
|
1625
|
+
return false;
|
|
1626
|
+
if (response.status === false)
|
|
1627
|
+
return false;
|
|
1628
|
+
if (typeof response.status === "number" && response.status >= 400)
|
|
1629
|
+
return false;
|
|
1630
|
+
if (response.code !== void 0 && response.code !== 200 && response.code !== "200")
|
|
1631
|
+
return false;
|
|
1632
|
+
return true;
|
|
1633
|
+
}
|
|
1555
1634
|
/**
|
|
1556
1635
|
* 根据 subscriberId 移除商品查询订阅者
|
|
1557
1636
|
*/
|
|
@@ -2214,7 +2293,7 @@ var Server = class {
|
|
|
2214
2293
|
return res == null ? void 0 : res.short_number;
|
|
2215
2294
|
}
|
|
2216
2295
|
}
|
|
2217
|
-
return this.getAppData("device_id") || 0;
|
|
2296
|
+
return String(this.getAppData("device_id") || 0).slice(-2);
|
|
2218
2297
|
}
|
|
2219
2298
|
buildCheckoutTaskIdempotencyKey(data) {
|
|
2220
2299
|
const identity = (data == null ? void 0 : data.request_unique_idempotency_token) || (data == null ? void 0 : data.external_sale_number) || (data == null ? void 0 : data.order_id) || (data == null ? void 0 : data.shop_order_number) || (data == null ? void 0 : data.shop_full_order_number);
|
|
@@ -2261,7 +2340,7 @@ var Server = class {
|
|
|
2261
2340
|
return next;
|
|
2262
2341
|
}
|
|
2263
2342
|
async dispatchCheckoutSyncTask(params) {
|
|
2264
|
-
var _a, _b, _c;
|
|
2343
|
+
var _a, _b, _c, _d;
|
|
2265
2344
|
this.registerDeviceTaskActions();
|
|
2266
2345
|
const deviceTask = this.getDeviceTaskPlugin();
|
|
2267
2346
|
const debugDeviceId = await this.getShortNumberOrDeviceId();
|
|
@@ -2277,6 +2356,7 @@ var Server = class {
|
|
|
2277
2356
|
payload: {
|
|
2278
2357
|
backendPath: params.backendPath,
|
|
2279
2358
|
data: params.data,
|
|
2359
|
+
external_sale_number: (_a = params.data) == null ? void 0 : _a.external_sale_number,
|
|
2280
2360
|
title: params.title
|
|
2281
2361
|
},
|
|
2282
2362
|
retry_limit: 5,
|
|
@@ -2284,7 +2364,7 @@ var Server = class {
|
|
|
2284
2364
|
name: "同步订单",
|
|
2285
2365
|
source: "server",
|
|
2286
2366
|
source_type: "order",
|
|
2287
|
-
source_id: ((
|
|
2367
|
+
source_id: ((_b = params.data) == null ? void 0 : _b.order_id) || ((_c = params.data) == null ? void 0 : _c.external_sale_number) || ((_d = params.data) == null ? void 0 : _d.shop_order_number)
|
|
2288
2368
|
});
|
|
2289
2369
|
this.logInfo(`${params.title}: sync_sales 任务已派发`, {
|
|
2290
2370
|
uuid: result == null ? void 0 : result.uuid,
|
|
@@ -2381,7 +2461,9 @@ var Server = class {
|
|
|
2381
2461
|
});
|
|
2382
2462
|
if ((pendingResult == null ? void 0 : pendingResult.status) === true) {
|
|
2383
2463
|
const pendingOrder = pendingResult.data;
|
|
2384
|
-
if (pendingOrder && this.shouldBuildSmallTicketData(checkoutData) && this.isSalesOrderFullyPaid(pendingOrder)
|
|
2464
|
+
if (pendingOrder && this.shouldBuildSmallTicketData(checkoutData) && this.isSalesOrderFullyPaid(pendingOrder) && // TODO 这里先加个兼容,只有 type 为 virtual 才走打印
|
|
2465
|
+
// 后期需要迁移到 picoding ,根据工作流配置
|
|
2466
|
+
checkoutData.type === "virtual") {
|
|
2385
2467
|
await this.dispatchLocalReceiptPrint({
|
|
2386
2468
|
checkoutData,
|
|
2387
2469
|
order: pendingOrder,
|
|
@@ -2771,6 +2853,39 @@ var Server = class {
|
|
|
2771
2853
|
}
|
|
2772
2854
|
return null;
|
|
2773
2855
|
}
|
|
2856
|
+
getCheckoutExternalSaleNumber(data, payload) {
|
|
2857
|
+
var _a;
|
|
2858
|
+
const candidates = [
|
|
2859
|
+
payload == null ? void 0 : payload.external_sale_number,
|
|
2860
|
+
data == null ? void 0 : data.external_sale_number,
|
|
2861
|
+
(_a = payload == null ? void 0 : payload.data) == null ? void 0 : _a.external_sale_number
|
|
2862
|
+
];
|
|
2863
|
+
const value = candidates.find((candidate) => candidate !== void 0 && candidate !== null && candidate !== "");
|
|
2864
|
+
return value === void 0 ? void 0 : String(value);
|
|
2865
|
+
}
|
|
2866
|
+
buildCheckoutSyncSuccessPatch(fresh) {
|
|
2867
|
+
if (!fresh)
|
|
2868
|
+
return {};
|
|
2869
|
+
const patch = {};
|
|
2870
|
+
if (fresh.order_id !== void 0 && fresh.order_id !== null)
|
|
2871
|
+
patch.order_id = fresh.order_id;
|
|
2872
|
+
if (fresh.order_number !== void 0 && fresh.order_number !== null) {
|
|
2873
|
+
patch.order_number = fresh.order_number;
|
|
2874
|
+
}
|
|
2875
|
+
return patch;
|
|
2876
|
+
}
|
|
2877
|
+
isMergeableCheckoutOrder(order, externalSaleNumber) {
|
|
2878
|
+
if (!order || typeof order !== "object")
|
|
2879
|
+
return false;
|
|
2880
|
+
const orderExternalSaleNumber = order.external_sale_number;
|
|
2881
|
+
if (externalSaleNumber && orderExternalSaleNumber !== void 0 && orderExternalSaleNumber !== null && String(orderExternalSaleNumber) !== externalSaleNumber) {
|
|
2882
|
+
return false;
|
|
2883
|
+
}
|
|
2884
|
+
if (externalSaleNumber && (orderExternalSaleNumber === void 0 || orderExternalSaleNumber === null || orderExternalSaleNumber === "")) {
|
|
2885
|
+
return false;
|
|
2886
|
+
}
|
|
2887
|
+
return Array.isArray(order.products) || Array.isArray(order.bookings) || Array.isArray(order.payments) || !!order.summary || order.order_number !== void 0 || order.payment_status !== void 0 || order.status !== void 0;
|
|
2888
|
+
}
|
|
2774
2889
|
normalizeCheckoutResponse(response) {
|
|
2775
2890
|
if (response && typeof response === "object" && (response.code !== void 0 || response.status !== void 0)) {
|
|
2776
2891
|
return response;
|
|
@@ -87,6 +87,7 @@ export declare class OrderModule extends BaseModule implements Module {
|
|
|
87
87
|
*/
|
|
88
88
|
silentRefresh(): Promise<OrderData[]>;
|
|
89
89
|
getOrdersByResourceId(resourceId: string | number): OrderData[];
|
|
90
|
+
private normalizeOrderForMemoryList;
|
|
90
91
|
/**
|
|
91
92
|
* 仅覆盖本地已存在的订单;不存在则直接跳过,不落库、不 emit。
|
|
92
93
|
* 适用于"按 order_id 主动刷新本地订单详情"的代理场景。
|
|
@@ -99,6 +100,13 @@ export declare class OrderModule extends BaseModule implements Module {
|
|
|
99
100
|
* 供 /update/localOrder 等在「本地尚无该单」时写入新建单。
|
|
100
101
|
*/
|
|
101
102
|
upsertOrdersFromRemote(freshOrders: OrderData[]): Promise<void>;
|
|
103
|
+
markOrderSyncedByExternalSaleNumber(params: {
|
|
104
|
+
externalSaleNumber: OrderId;
|
|
105
|
+
patch?: Partial<OrderData>;
|
|
106
|
+
}): Promise<{
|
|
107
|
+
updated: boolean;
|
|
108
|
+
order?: OrderData;
|
|
109
|
+
}>;
|
|
102
110
|
/**
|
|
103
111
|
* 将本地待同步订单按 SQLite storage key 合并进 store 并落库。
|
|
104
112
|
* checkout 离线兜底可能没有 order_id,但通常会有 external_sale_number。
|
|
@@ -111,6 +119,7 @@ export declare class OrderModule extends BaseModule implements Module {
|
|
|
111
119
|
getRoutes(): RouteDefinition[];
|
|
112
120
|
destroy(): void;
|
|
113
121
|
private syncOrdersMap;
|
|
122
|
+
private getOrderIdentityKeys;
|
|
114
123
|
private extractResourceIds;
|
|
115
124
|
private getOrderDateKey;
|
|
116
125
|
/**
|