@pisell/pisellos 2.3.59 → 2.3.61
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/core/index.d.ts +0 -7
- package/dist/core/index.js +66 -109
- package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -1
- package/dist/model/strategy/adapter/walletPass/type.d.ts +5 -0
- package/dist/model/strategy/adapter/walletPass/utils.js +57 -24
- package/dist/modules/Payment/types.d.ts +2 -0
- package/dist/modules/Payment/utils.js +4 -1
- package/dist/modules/Payment/walletpass.d.ts +11 -0
- package/dist/modules/Payment/walletpass.js +204 -49
- package/dist/modules/ProductList/index.js +2 -1
- package/dist/modules/Quotation/index.d.ts +0 -6
- package/dist/modules/Quotation/index.js +19 -75
- package/dist/plugins/request.d.ts +0 -1
- package/dist/server/index.js +62 -74
- package/dist/server/modules/floor-plan/index.d.ts +0 -4
- package/dist/server/modules/floor-plan/index.js +98 -240
- package/dist/server/modules/order/index.d.ts +5 -6
- package/dist/server/modules/order/index.js +78 -176
- package/dist/server/modules/products/index.d.ts +0 -2
- package/dist/server/modules/products/index.js +3 -17
- package/dist/server/modules/resource/index.js +13 -21
- package/dist/solution/BaseSales/index.d.ts +5 -0
- package/dist/solution/BaseSales/index.js +311 -281
- package/lib/core/index.d.ts +0 -7
- package/lib/core/index.js +3 -20
- package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -1
- package/lib/model/strategy/adapter/walletPass/type.d.ts +5 -0
- package/lib/model/strategy/adapter/walletPass/utils.js +62 -10
- package/lib/modules/Payment/types.d.ts +2 -0
- package/lib/modules/Payment/utils.js +5 -1
- package/lib/modules/Payment/walletpass.d.ts +11 -0
- package/lib/modules/Payment/walletpass.js +183 -15
- package/lib/modules/ProductList/index.js +2 -1
- package/lib/modules/Quotation/index.d.ts +0 -6
- package/lib/modules/Quotation/index.js +5 -49
- package/lib/plugins/request.d.ts +0 -1
- package/lib/server/modules/floor-plan/index.d.ts +0 -4
- package/lib/server/modules/floor-plan/index.js +6 -54
- package/lib/server/modules/order/index.d.ts +5 -6
- package/lib/server/modules/order/index.js +23 -105
- package/lib/server/modules/products/index.d.ts +0 -2
- package/lib/server/modules/products/index.js +4 -15
- package/lib/server/modules/resource/index.js +2 -7
- package/lib/solution/BaseSales/index.d.ts +5 -0
- package/lib/solution/BaseSales/index.js +11 -0
- package/package.json +1 -1
|
@@ -32,49 +32,32 @@ var QuotationModule = class extends import_BaseModule.BaseModule {
|
|
|
32
32
|
this.store = { list: [] };
|
|
33
33
|
}
|
|
34
34
|
async initialize(core, options) {
|
|
35
|
-
var _a, _b;
|
|
36
35
|
this.core = core;
|
|
37
36
|
this.request = core.getPlugin("request");
|
|
38
37
|
if (!this.request)
|
|
39
38
|
throw new Error("QuotationModule 需要 request 插件支持");
|
|
40
|
-
this.app = (_b = (_a = core.getPlugin("app")) == null ? void 0 : _a.getApp) == null ? void 0 : _b.call(_a);
|
|
41
39
|
this.store = { list: [] };
|
|
42
40
|
}
|
|
43
41
|
async loadQuotations(params) {
|
|
42
|
+
var _a;
|
|
44
43
|
const query = {};
|
|
45
44
|
if (params == null ? void 0 : params.channel)
|
|
46
45
|
query.channel = params.channel;
|
|
47
46
|
if ((params == null ? void 0 : params.channel) === "online_store") {
|
|
48
47
|
query.channel = "online-store";
|
|
49
48
|
}
|
|
50
|
-
let initialResultApplied = false;
|
|
51
|
-
const applyRemoteUpdate = (response) => {
|
|
52
|
-
this.applyQuotationResponse(response);
|
|
53
|
-
if (initialResultApplied) {
|
|
54
|
-
this.notifyQuotationListUpdated();
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
49
|
const res = await this.request.get(
|
|
58
50
|
"/quotation/available",
|
|
59
51
|
query,
|
|
60
|
-
{
|
|
61
|
-
cache: {
|
|
62
|
-
type: "indexDB",
|
|
63
|
-
updateCache: true,
|
|
64
|
-
cacheKeyData: this.getQuotationCacheKeyData(query)
|
|
65
|
-
},
|
|
66
|
-
cacheUpdateChange: applyRemoteUpdate
|
|
67
|
-
}
|
|
52
|
+
{ useCache: false, osServer: true }
|
|
68
53
|
);
|
|
69
|
-
|
|
70
|
-
|
|
54
|
+
const list = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) || (res == null ? void 0 : res.list) || [];
|
|
55
|
+
list.sort((a, b) => b.sort - a.sort);
|
|
56
|
+
this.store.list = list;
|
|
71
57
|
}
|
|
72
58
|
getQuotationList() {
|
|
73
59
|
return this.store.list;
|
|
74
60
|
}
|
|
75
|
-
setQuotationListUpdatedListener(listener) {
|
|
76
|
-
this.quotationListUpdatedListener = listener;
|
|
77
|
-
}
|
|
78
61
|
getQuotationCustomerScopeInfo() {
|
|
79
62
|
const customerById = /* @__PURE__ */ new Map();
|
|
80
63
|
const quotationScopes = this.store.list.filter((quotation) => Array.isArray(quotation.customer) && quotation.customer.length > 0).map((quotation) => {
|
|
@@ -173,33 +156,6 @@ var QuotationModule = class extends import_BaseModule.BaseModule {
|
|
|
173
156
|
setScheduleResolver(resolver) {
|
|
174
157
|
this.scheduleResolver = resolver;
|
|
175
158
|
}
|
|
176
|
-
applyQuotationResponse(response) {
|
|
177
|
-
var _a;
|
|
178
|
-
const source = ((_a = response == null ? void 0 : response.data) == null ? void 0 : _a.list) || (response == null ? void 0 : response.list) || [];
|
|
179
|
-
this.store.list = [...source].sort((a, b) => Number(b.sort || 0) - Number(a.sort || 0));
|
|
180
|
-
}
|
|
181
|
-
notifyQuotationListUpdated() {
|
|
182
|
-
var _a;
|
|
183
|
-
try {
|
|
184
|
-
(_a = this.quotationListUpdatedListener) == null ? void 0 : _a.call(this);
|
|
185
|
-
} catch (error) {
|
|
186
|
-
console.warn("[QuotationModule] 报价单后台更新回调失败", error);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
getQuotationCacheKeyData(query) {
|
|
190
|
-
var _a, _b, _c;
|
|
191
|
-
let shopId = "";
|
|
192
|
-
try {
|
|
193
|
-
const storedCore = (_c = (_b = (_a = this.app) == null ? void 0 : _a.storage) == null ? void 0 : _b.getStorage) == null ? void 0 : _c.call(_b, "core");
|
|
194
|
-
const coreInfo = typeof storedCore === "string" ? JSON.parse(storedCore || "{}") : storedCore || {};
|
|
195
|
-
shopId = String((coreInfo == null ? void 0 : coreInfo.id) || "");
|
|
196
|
-
} catch {
|
|
197
|
-
}
|
|
198
|
-
return {
|
|
199
|
-
...query,
|
|
200
|
-
shop_id: shopId
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
159
|
isQuotationVisibleForCustomer(quotation, customerId) {
|
|
204
160
|
const customers = quotation.customer || [];
|
|
205
161
|
if (customers.length === 0)
|
package/lib/plugins/request.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ export declare class FloorPlanModule extends BaseModule implements Module {
|
|
|
10
10
|
private store;
|
|
11
11
|
private request;
|
|
12
12
|
private logger;
|
|
13
|
-
private dbManager;
|
|
14
13
|
private floorPlanDataSource;
|
|
15
14
|
private pendingSyncMessages;
|
|
16
15
|
private syncTimer?;
|
|
@@ -29,9 +28,6 @@ export declare class FloorPlanModule extends BaseModule implements Module {
|
|
|
29
28
|
private mergeItems;
|
|
30
29
|
private removeByIds;
|
|
31
30
|
private loadListFromServer;
|
|
32
|
-
private loadListFromSQLite;
|
|
33
|
-
private saveListToSQLite;
|
|
34
|
-
private refreshListFromServer;
|
|
35
31
|
fetchByIdFromServer(id: number | string): Promise<FloorPlanItem | null>;
|
|
36
32
|
fetchByCodeFromServer(code: string): Promise<FloorPlanItem | null>;
|
|
37
33
|
preload(): Promise<void>;
|
|
@@ -25,7 +25,6 @@ module.exports = __toCommonJS(floor_plan_exports);
|
|
|
25
25
|
var import_BaseModule = require("../../../modules/BaseModule");
|
|
26
26
|
var import_types = require("./types");
|
|
27
27
|
var FLOOR_PLAN_SYNC_DEBOUNCE_MS = 3e3;
|
|
28
|
-
var FLOOR_PLAN_STORE_NAME = "floor_plans";
|
|
29
28
|
var FloorPlanModule = class extends import_BaseModule.BaseModule {
|
|
30
29
|
constructor(name, version) {
|
|
31
30
|
super(name, version);
|
|
@@ -51,7 +50,6 @@ var FloorPlanModule = class extends import_BaseModule.BaseModule {
|
|
|
51
50
|
if (appPlugin) {
|
|
52
51
|
const app = appPlugin.getApp();
|
|
53
52
|
this.logger = app.logger;
|
|
54
|
-
this.dbManager = app.sqlite || app.dbManager;
|
|
55
53
|
}
|
|
56
54
|
this.initFloorPlanDataSource();
|
|
57
55
|
this.setupFloorPlanSync();
|
|
@@ -161,45 +159,6 @@ var FloorPlanModule = class extends import_BaseModule.BaseModule {
|
|
|
161
159
|
return [];
|
|
162
160
|
}
|
|
163
161
|
}
|
|
164
|
-
async loadListFromSQLite() {
|
|
165
|
-
if (!this.dbManager)
|
|
166
|
-
return [];
|
|
167
|
-
try {
|
|
168
|
-
const list = await this.dbManager.getAll(FLOOR_PLAN_STORE_NAME);
|
|
169
|
-
return Array.isArray(list) ? list : [];
|
|
170
|
-
} catch (error) {
|
|
171
|
-
this.logWarning("从 SQLite 读取平面图失败", {
|
|
172
|
-
error: error instanceof Error ? error.message : String(error)
|
|
173
|
-
});
|
|
174
|
-
return [];
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
async saveListToSQLite(list) {
|
|
178
|
-
if (!this.dbManager)
|
|
179
|
-
return;
|
|
180
|
-
try {
|
|
181
|
-
await this.dbManager.clear(FLOOR_PLAN_STORE_NAME);
|
|
182
|
-
if (list.length > 0) {
|
|
183
|
-
await this.dbManager.bulkAdd(FLOOR_PLAN_STORE_NAME, list);
|
|
184
|
-
}
|
|
185
|
-
} catch (error) {
|
|
186
|
-
this.logWarning("保存平面图到 SQLite 失败", {
|
|
187
|
-
count: list.length,
|
|
188
|
-
error: error instanceof Error ? error.message : String(error)
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
async refreshListFromServer() {
|
|
193
|
-
const list = await this.loadListFromServer();
|
|
194
|
-
if (list.length === 0) {
|
|
195
|
-
this.logWarning("远端平面图刷新完成但列表为空");
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
this.replaceStore(list);
|
|
199
|
-
await this.saveListToSQLite(list);
|
|
200
|
-
this.core.effects.emit(import_types.FloorPlanHooks.onFloorPlansChanged, this.getSortedList());
|
|
201
|
-
this.logInfo("远端平面图刷新完成", { count: list.length });
|
|
202
|
-
}
|
|
203
162
|
async fetchByIdFromServer(id) {
|
|
204
163
|
try {
|
|
205
164
|
const res = await this.request.get(
|
|
@@ -231,19 +190,14 @@ var FloorPlanModule = class extends import_BaseModule.BaseModule {
|
|
|
231
190
|
}
|
|
232
191
|
async preload() {
|
|
233
192
|
this.logInfo("开始预加载平面图列表");
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
236
|
-
this.replaceStore(
|
|
193
|
+
const list = await this.loadListFromServer();
|
|
194
|
+
if (list.length > 0) {
|
|
195
|
+
this.replaceStore(list);
|
|
237
196
|
this.core.effects.emit(import_types.FloorPlanHooks.onFloorPlansChanged, this.getSortedList());
|
|
238
|
-
this.logInfo("
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
error: error instanceof Error ? error.message : String(error)
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
return;
|
|
197
|
+
this.logInfo("预加载完成", { count: list.length });
|
|
198
|
+
} else {
|
|
199
|
+
this.logWarning("预加载完成但列表为空");
|
|
245
200
|
}
|
|
246
|
-
await this.refreshListFromServer();
|
|
247
201
|
}
|
|
248
202
|
initFloorPlanDataSource() {
|
|
249
203
|
var _a, _b;
|
|
@@ -345,7 +299,6 @@ var FloorPlanModule = class extends import_BaseModule.BaseModule {
|
|
|
345
299
|
}
|
|
346
300
|
}
|
|
347
301
|
if (changed) {
|
|
348
|
-
await this.saveListToSQLite(this.store.list);
|
|
349
302
|
this.core.effects.emit(import_types.FloorPlanHooks.onFloorPlansChanged, this.getSortedList());
|
|
350
303
|
this.core.effects.emit(import_types.FloorPlanHooks.onFloorPlanSyncCompleted, null);
|
|
351
304
|
}
|
|
@@ -354,7 +307,6 @@ var FloorPlanModule = class extends import_BaseModule.BaseModule {
|
|
|
354
307
|
this.store.list = [];
|
|
355
308
|
this.store.map.clear();
|
|
356
309
|
this.store.codeMap.clear();
|
|
357
|
-
await this.saveListToSQLite([]);
|
|
358
310
|
}
|
|
359
311
|
destroy() {
|
|
360
312
|
var _a;
|
|
@@ -290,14 +290,13 @@ export declare class OrderModule extends BaseModule implements Module {
|
|
|
290
290
|
private logDuplicateOrders;
|
|
291
291
|
private compactOrderListByIdentity;
|
|
292
292
|
/**
|
|
293
|
-
*
|
|
294
|
-
*
|
|
293
|
+
* 当前订单拉取窗口:
|
|
294
|
+
* - 优先使用 createdAtQuery.sales_time_between(已按营业日边界初始化)
|
|
295
|
+
* - 无法解析时退化为自然日窗口
|
|
295
296
|
*/
|
|
296
|
-
private
|
|
297
|
+
private getCurrentPullWindow;
|
|
297
298
|
private hasPulledOrdersToday;
|
|
298
299
|
private markOrderPulledAtNow;
|
|
299
|
-
private clearOrderSnapshotMarker;
|
|
300
|
-
private getCurrentShopId;
|
|
301
300
|
private getStorageItem;
|
|
302
301
|
private setStorageItem;
|
|
303
302
|
private loadOrdersFromSQLite;
|
|
@@ -335,7 +334,7 @@ export declare class OrderModule extends BaseModule implements Module {
|
|
|
335
334
|
* 用于 SSE 全量拉取与营业日窗口裁剪。
|
|
336
335
|
*
|
|
337
336
|
* @example
|
|
338
|
-
*
|
|
337
|
+
* await this.replaceOrdersSnapshotInSQLite(orderList)
|
|
339
338
|
*/
|
|
340
339
|
private replaceOrdersSnapshotInSQLite;
|
|
341
340
|
/**
|
|
@@ -40,7 +40,6 @@ var import_types = require("./types");
|
|
|
40
40
|
var import_payment_utils = require("../../../modules/Order/payment-utils");
|
|
41
41
|
var INDEXDB_STORE_NAME = "orders";
|
|
42
42
|
var ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY = "server_order_last_full_fetch_at";
|
|
43
|
-
var ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY = "server_order_last_full_fetch_shop_id";
|
|
44
43
|
var ORDER_SYNC_THROTTLE_MS_STORAGE_KEY = "order_sync_throttle_ms";
|
|
45
44
|
var DEFAULT_ORDER_SYNC_THROTTLE_MS = 2e3;
|
|
46
45
|
var ORDER_SQLITE_DEDUPE_MS = 15e3;
|
|
@@ -525,27 +524,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
525
524
|
return DEFAULT_ORDER_SYNC_THROTTLE_MS;
|
|
526
525
|
}
|
|
527
526
|
async preload() {
|
|
528
|
-
let cachedOrders = null;
|
|
529
|
-
if (this.dbManager) {
|
|
530
|
-
try {
|
|
531
|
-
cachedOrders = await this.loadOrdersFromSQLite({ throwOnError: true });
|
|
532
|
-
} catch (error) {
|
|
533
|
-
this.logWarning("preload-SQLite读取失败,回退远端全量拉取", {
|
|
534
|
-
error: error instanceof Error ? error.message : String(error)
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
if (cachedOrders !== null && this.hasPulledOrdersToday()) {
|
|
539
|
-
const memoryOrders = this.normalizeOrdersForMemoryList(
|
|
540
|
-
cachedOrders,
|
|
541
|
-
"preload.sqliteMemory"
|
|
542
|
-
);
|
|
543
|
-
this.store.list = (0, import_lodash_es.cloneDeep)(memoryOrders);
|
|
544
|
-
this.syncOrdersMap();
|
|
545
|
-
await this.core.effects.emit(import_types.OrderHooks.onOrdersLoaded, this.store.list);
|
|
546
|
-
await this.emitOrdersChanged([], "preload.sqlite");
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
527
|
const orders = await this.loadOrdersByServer();
|
|
550
528
|
this.store.list = (0, import_lodash_es.cloneDeep)(orders);
|
|
551
529
|
this.syncOrdersMap();
|
|
@@ -774,7 +752,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
774
752
|
async loadOrdersByServer() {
|
|
775
753
|
var _a;
|
|
776
754
|
let orderList = [];
|
|
777
|
-
let hasFetchedRemoteSnapshot = false;
|
|
778
755
|
const protectedOrdersBeforeRemoteFetch = (await this.loadOrdersFromSQLite()).filter(
|
|
779
756
|
(order) => this.shouldProtectLocalOrderFromRemoteSnapshot(order)
|
|
780
757
|
);
|
|
@@ -798,27 +775,18 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
798
775
|
this.logInfo("loadOrdersByServer-SSE拉取成功", {
|
|
799
776
|
count: orderList.length
|
|
800
777
|
});
|
|
801
|
-
|
|
778
|
+
this.markOrderPulledAtNow();
|
|
802
779
|
this.lastServerFullFetchAtMs = Date.now();
|
|
803
780
|
} catch {
|
|
804
781
|
this.logInfo("loadOrdersByServer-SSE拉取失败,保持当前内存订单");
|
|
805
782
|
return this.store.list;
|
|
806
783
|
}
|
|
807
784
|
}
|
|
808
|
-
|
|
809
|
-
this.clearOrderSnapshotMarker();
|
|
810
|
-
}
|
|
811
|
-
const {
|
|
812
|
-
orders: mergedOrders,
|
|
813
|
-
persisted: isRemoteSnapshotPersisted
|
|
814
|
-
} = await this.replaceOrdersSnapshotInSQLite(
|
|
785
|
+
const mergedOrders = await this.replaceOrdersSnapshotInSQLite(
|
|
815
786
|
orderList,
|
|
816
787
|
"loadOrdersByServer",
|
|
817
788
|
protectedOrdersBeforeRemoteFetch
|
|
818
789
|
);
|
|
819
|
-
if (hasFetchedRemoteSnapshot && isRemoteSnapshotPersisted) {
|
|
820
|
-
this.markOrderPulledAtNow();
|
|
821
|
-
}
|
|
822
790
|
const memoryOrders = this.normalizeOrdersForMemoryList(
|
|
823
791
|
mergedOrders,
|
|
824
792
|
"loadOrdersByServer.memory"
|
|
@@ -2151,29 +2119,20 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2151
2119
|
return { list, removedCount };
|
|
2152
2120
|
}
|
|
2153
2121
|
/**
|
|
2154
|
-
*
|
|
2155
|
-
*
|
|
2122
|
+
* 当前订单拉取窗口:
|
|
2123
|
+
* - 优先使用 createdAtQuery.sales_time_between(已按营业日边界初始化)
|
|
2124
|
+
* - 无法解析时退化为自然日窗口
|
|
2156
2125
|
*/
|
|
2157
|
-
|
|
2158
|
-
var _a;
|
|
2126
|
+
getCurrentPullWindow() {
|
|
2127
|
+
var _a, _b;
|
|
2159
2128
|
const now = (0, import_dayjs.default)();
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
const
|
|
2163
|
-
const
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
const boundaryTime = String(boundary.time || "").trim();
|
|
2167
|
-
const todayBoundary = (0, import_dayjs.default)(`${now.format("YYYY-MM-DD")} ${boundaryTime}`);
|
|
2168
|
-
if (todayBoundary.isValid()) {
|
|
2169
|
-
const startAt2 = now.isBefore(todayBoundary) ? todayBoundary.subtract(1, "day") : todayBoundary;
|
|
2170
|
-
return {
|
|
2171
|
-
startAt: startAt2,
|
|
2172
|
-
endExclusiveAt: startAt2.add(1, "day")
|
|
2173
|
-
};
|
|
2174
|
-
}
|
|
2129
|
+
const range = (_b = (_a = this.store) == null ? void 0 : _a.createdAtQuery) == null ? void 0 : _b.sales_time_between;
|
|
2130
|
+
if (Array.isArray(range) && range.length >= 2) {
|
|
2131
|
+
const startAt2 = (0, import_dayjs.default)(range[0]);
|
|
2132
|
+
const endExclusiveAt = (0, import_dayjs.default)(range[1]);
|
|
2133
|
+
if (startAt2.isValid() && endExclusiveAt.isValid() && endExclusiveAt.isAfter(startAt2)) {
|
|
2134
|
+
return { startAt: startAt2, endExclusiveAt };
|
|
2175
2135
|
}
|
|
2176
|
-
} catch {
|
|
2177
2136
|
}
|
|
2178
2137
|
const startAt = now.startOf("day");
|
|
2179
2138
|
return { startAt, endExclusiveAt: startAt.add(1, "day") };
|
|
@@ -2182,51 +2141,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2182
2141
|
const lastFullFetchAt = this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY);
|
|
2183
2142
|
if (!lastFullFetchAt)
|
|
2184
2143
|
return false;
|
|
2185
|
-
const currentShopId = this.getCurrentShopId();
|
|
2186
|
-
const lastFullFetchShopId = this.getStorageItem(
|
|
2187
|
-
ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY
|
|
2188
|
-
);
|
|
2189
|
-
if (!currentShopId || !lastFullFetchShopId || currentShopId !== lastFullFetchShopId) {
|
|
2190
|
-
return false;
|
|
2191
|
-
}
|
|
2192
2144
|
const parsed = (0, import_dayjs.default)(lastFullFetchAt);
|
|
2193
2145
|
if (!parsed.isValid())
|
|
2194
2146
|
return false;
|
|
2195
|
-
const { startAt, endExclusiveAt } = this.
|
|
2147
|
+
const { startAt, endExclusiveAt } = this.getCurrentPullWindow();
|
|
2196
2148
|
return (parsed.isAfter(startAt) || parsed.isSame(startAt)) && parsed.isBefore(endExclusiveAt);
|
|
2197
2149
|
}
|
|
2198
2150
|
markOrderPulledAtNow() {
|
|
2199
|
-
const currentShopId = this.getCurrentShopId();
|
|
2200
|
-
if (!currentShopId)
|
|
2201
|
-
return;
|
|
2202
2151
|
this.setStorageItem(
|
|
2203
2152
|
ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY,
|
|
2204
2153
|
(0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
|
|
2205
2154
|
);
|
|
2206
|
-
this.setStorageItem(
|
|
2207
|
-
ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY,
|
|
2208
|
-
currentShopId
|
|
2209
|
-
);
|
|
2210
|
-
}
|
|
2211
|
-
clearOrderSnapshotMarker() {
|
|
2212
|
-
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, "");
|
|
2213
|
-
this.setStorageItem(ORDER_LAST_FULL_FETCH_SHOP_ID_STORAGE_KEY, "");
|
|
2214
|
-
}
|
|
2215
|
-
getCurrentShopId() {
|
|
2216
|
-
var _a;
|
|
2217
|
-
try {
|
|
2218
|
-
const appPlugin = this.core.getPlugin("app");
|
|
2219
|
-
const app = appPlugin == null ? void 0 : appPlugin.getApp();
|
|
2220
|
-
if (!app)
|
|
2221
|
-
return null;
|
|
2222
|
-
const coreData = app.data.store.getStore().getDataByModel("core");
|
|
2223
|
-
const shopId = (_a = coreData == null ? void 0 : coreData.core) == null ? void 0 : _a.id;
|
|
2224
|
-
if (shopId === void 0 || shopId === null || shopId === "")
|
|
2225
|
-
return null;
|
|
2226
|
-
return String(shopId);
|
|
2227
|
-
} catch {
|
|
2228
|
-
return null;
|
|
2229
|
-
}
|
|
2230
2155
|
}
|
|
2231
2156
|
getStorageItem(key) {
|
|
2232
2157
|
var _a;
|
|
@@ -2253,7 +2178,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2253
2178
|
} catch {
|
|
2254
2179
|
}
|
|
2255
2180
|
}
|
|
2256
|
-
async loadOrdersFromSQLite(
|
|
2181
|
+
async loadOrdersFromSQLite() {
|
|
2257
2182
|
if (!this.dbManager)
|
|
2258
2183
|
return [];
|
|
2259
2184
|
try {
|
|
@@ -2261,9 +2186,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2261
2186
|
return (orders || []).map(
|
|
2262
2187
|
(order) => this.normalizeOrderCollectionsForIngress(order, "loadOrdersFromSQLite")
|
|
2263
2188
|
);
|
|
2264
|
-
} catch
|
|
2265
|
-
if (options.throwOnError)
|
|
2266
|
-
throw error;
|
|
2189
|
+
} catch {
|
|
2267
2190
|
return [];
|
|
2268
2191
|
}
|
|
2269
2192
|
}
|
|
@@ -2485,17 +2408,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2485
2408
|
* 用于 SSE 全量拉取与营业日窗口裁剪。
|
|
2486
2409
|
*
|
|
2487
2410
|
* @example
|
|
2488
|
-
*
|
|
2411
|
+
* await this.replaceOrdersSnapshotInSQLite(orderList)
|
|
2489
2412
|
*/
|
|
2490
2413
|
async replaceOrdersSnapshotInSQLite(orderList, source, protectedOrdersBeforeRemoteFetch = []) {
|
|
2491
2414
|
if (!this.dbManager) {
|
|
2492
|
-
return
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
).list,
|
|
2497
|
-
persisted: false
|
|
2498
|
-
};
|
|
2415
|
+
return this.compactOrderListByIdentity(
|
|
2416
|
+
orderList.map((order) => this.normalizeRemoteSyncedOrder(order)),
|
|
2417
|
+
`${source}.snapshotNoDb`
|
|
2418
|
+
).list;
|
|
2499
2419
|
}
|
|
2500
2420
|
const remoteSnapshot = (0, import_lodash_es.cloneDeep)(orderList).map(
|
|
2501
2421
|
(order) => this.normalizeOrderCollectionsForIngress(order, `${source}.remoteIngress`)
|
|
@@ -2504,7 +2424,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2504
2424
|
remoteSnapshot.map((order) => this.normalizeRemoteSyncedOrder(order)),
|
|
2505
2425
|
`${source}.remoteSnapshot`
|
|
2506
2426
|
).list;
|
|
2507
|
-
let persisted = false;
|
|
2508
2427
|
try {
|
|
2509
2428
|
await this.runInOrderSQLiteSaveQueue(async () => {
|
|
2510
2429
|
const existingOrders = typeof this.dbManager.getAll === "function" ? await this.dbManager.getAll(INDEXDB_STORE_NAME) : [];
|
|
@@ -2569,14 +2488,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2569
2488
|
count: mergedSnapshot.length
|
|
2570
2489
|
});
|
|
2571
2490
|
});
|
|
2572
|
-
persisted = true;
|
|
2573
2491
|
} catch (error) {
|
|
2574
2492
|
this.logError("全量保存订单到 SQLite 失败", {
|
|
2575
2493
|
error: error instanceof Error ? error.message : String(error),
|
|
2576
2494
|
orderList: remoteSnapshot.length
|
|
2577
2495
|
});
|
|
2578
2496
|
}
|
|
2579
|
-
return
|
|
2497
|
+
return mergedSnapshot;
|
|
2580
2498
|
}
|
|
2581
2499
|
/**
|
|
2582
2500
|
* 清空订单模块的内存数据和本地 SQLite 订单表。
|
|
@@ -2592,7 +2510,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2592
2510
|
await this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
2593
2511
|
});
|
|
2594
2512
|
}
|
|
2595
|
-
this.
|
|
2513
|
+
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, "");
|
|
2596
2514
|
this.emitOrdersChanged([], "clear");
|
|
2597
2515
|
}
|
|
2598
2516
|
};
|
|
@@ -25,7 +25,6 @@ export declare class ProductsModule extends BaseModule implements Module {
|
|
|
25
25
|
private quotationBridgeLoadedKey?;
|
|
26
26
|
private quotationBridgeRefreshPromise?;
|
|
27
27
|
private quotationBridgeRefreshKey?;
|
|
28
|
-
private quotationBridgeUpdatedCallback?;
|
|
29
28
|
private quotationScheduleCache;
|
|
30
29
|
private quotationScheduleCacheSource;
|
|
31
30
|
private quotationScheduleCacheLoaded;
|
|
@@ -73,7 +72,6 @@ export declare class ProductsModule extends BaseModule implements Module {
|
|
|
73
72
|
scheduleModule?: any;
|
|
74
73
|
channel?: string;
|
|
75
74
|
customer_id?: number | string;
|
|
76
|
-
onQuotationUpdated?: () => void;
|
|
77
75
|
}): Promise<void>;
|
|
78
76
|
/**
|
|
79
77
|
* 刷新桥接器内的报价单列表。
|
|
@@ -192,7 +192,7 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
192
192
|
* Server 层负责传入完整 schedule 模块,Products 只负责把报价单计算结果转成价格响应形状。
|
|
193
193
|
*/
|
|
194
194
|
async setupQuotationPriceBridge(params) {
|
|
195
|
-
var _a
|
|
195
|
+
var _a;
|
|
196
196
|
if (!this.core) {
|
|
197
197
|
this.logWarning("setupQuotationPriceBridge: core 尚未初始化");
|
|
198
198
|
return;
|
|
@@ -211,13 +211,13 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
211
211
|
this.quotationScheduleCacheSource = params.scheduleModule;
|
|
212
212
|
}
|
|
213
213
|
this.quotationPriceBridge.setScheduleResolver((id) => {
|
|
214
|
-
var _a2,
|
|
214
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
215
215
|
const scheduleId = String(id);
|
|
216
216
|
if (this.quotationScheduleCache.has(scheduleId)) {
|
|
217
217
|
return this.quotationScheduleCache.get(scheduleId);
|
|
218
218
|
}
|
|
219
219
|
if (!this.quotationScheduleCacheLoaded) {
|
|
220
|
-
const scheduleList = ((
|
|
220
|
+
const scheduleList = ((_b = (_a2 = params.scheduleModule).getScheduleList) == null ? void 0 : _b.call(_a2)) || [];
|
|
221
221
|
for (const schedule of scheduleList) {
|
|
222
222
|
this.quotationScheduleCache.set(String(schedule.id), schedule);
|
|
223
223
|
}
|
|
@@ -226,21 +226,12 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
226
226
|
if (this.quotationScheduleCache.has(scheduleId)) {
|
|
227
227
|
return this.quotationScheduleCache.get(scheduleId);
|
|
228
228
|
}
|
|
229
|
-
const schedules = ((_d = (
|
|
229
|
+
const schedules = ((_d = (_c = params.scheduleModule).getScheduleListByIds) == null ? void 0 : _d.call(_c, [id])) || ((_f = (_e = params.scheduleModule).getScheduleByIds) == null ? void 0 : _f.call(_e, [id])) || [];
|
|
230
230
|
if (schedules[0])
|
|
231
231
|
this.quotationScheduleCache.set(scheduleId, schedules[0]);
|
|
232
232
|
return schedules[0];
|
|
233
233
|
});
|
|
234
234
|
}
|
|
235
|
-
if (params.onQuotationUpdated) {
|
|
236
|
-
this.quotationBridgeUpdatedCallback = params.onQuotationUpdated;
|
|
237
|
-
}
|
|
238
|
-
(_c = (_b = this.quotationPriceBridge).setQuotationListUpdatedListener) == null ? void 0 : _c.call(_b, () => {
|
|
239
|
-
var _a2;
|
|
240
|
-
this.quotationBridgeLoadedKey = this.getQuotationBridgeScopeKey();
|
|
241
|
-
this.clearPriceCache();
|
|
242
|
-
(_a2 = this.quotationBridgeUpdatedCallback) == null ? void 0 : _a2.call(this);
|
|
243
|
-
});
|
|
244
235
|
await this.refreshQuotationPriceBridge({ customer_id: params.customer_id });
|
|
245
236
|
}
|
|
246
237
|
/**
|
|
@@ -807,8 +798,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
807
798
|
*/
|
|
808
799
|
clearPriceCache() {
|
|
809
800
|
this.productsPriceCache.clear();
|
|
810
|
-
this.quotationScheduleCache.clear();
|
|
811
|
-
this.quotationScheduleCacheLoaded = false;
|
|
812
801
|
console.log("[ProductsModule] 🗑️ 商品价格缓存已清空");
|
|
813
802
|
}
|
|
814
803
|
/**
|
|
@@ -88,18 +88,13 @@ var ResourceModule = class extends import_BaseModule.BaseModule {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
async preload() {
|
|
91
|
+
await this.setupResourceSync();
|
|
91
92
|
const cachedResources = await this.loadResourcesFromSQLite();
|
|
92
93
|
if (cachedResources.length > 0) {
|
|
93
94
|
this.store.list = (0, import_lodash_es.cloneDeep)(cachedResources).map((item) => this.normalizeResource(item));
|
|
94
95
|
this.syncResourcesMap();
|
|
95
96
|
await this.safeEmit(import_types.ResourceHooks.onResourcesChanged, this.store.list);
|
|
96
|
-
|
|
97
|
-
this.logError("后台初始化资源同步失败", error);
|
|
98
|
-
});
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
await this.setupResourceSync();
|
|
102
|
-
if (this.store.list.length === 0) {
|
|
97
|
+
} else {
|
|
103
98
|
const resources = await this.loadResourcesByServer();
|
|
104
99
|
if (resources.length > 0) {
|
|
105
100
|
this.store.list = (0, import_lodash_es.cloneDeep)(resources).map((item) => this.normalizeResource(item));
|
|
@@ -362,6 +362,11 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
362
362
|
selected: boolean;
|
|
363
363
|
source?: WalletAssetSelectionSource;
|
|
364
364
|
}): Promise<WalletAssetsState>;
|
|
365
|
+
/** 更新已选钱包资产的手动使用金额,并同步 pending payment。 */
|
|
366
|
+
updateWalletAssetAmount(params: {
|
|
367
|
+
assetId: WalletAssetId;
|
|
368
|
+
amount: number;
|
|
369
|
+
}): Promise<WalletAssetsState>;
|
|
365
370
|
/** 扫码精确查券;仅可用资产会被自动选中。 */
|
|
366
371
|
scanWalletAsset(code: string): Promise<ScanWalletAssetResult>;
|
|
367
372
|
/** 清空全部未确认钱包选择,已支付钱包项由 Order 模块继续保留。 */
|
|
@@ -2657,6 +2657,17 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
|
|
|
2657
2657
|
await this.syncSelectedWalletAssets(state);
|
|
2658
2658
|
return this.publishWalletAssetsState(state);
|
|
2659
2659
|
}
|
|
2660
|
+
/** 更新已选钱包资产的手动使用金额,并同步 pending payment。 */
|
|
2661
|
+
async updateWalletAssetAmount(params) {
|
|
2662
|
+
if (!this.store.payment)
|
|
2663
|
+
throw new Error("payment 模块未初始化");
|
|
2664
|
+
const state = this.store.payment.wallet.updateWalletAssetAmount(
|
|
2665
|
+
params.assetId,
|
|
2666
|
+
params.amount
|
|
2667
|
+
);
|
|
2668
|
+
await this.syncSelectedWalletAssets(state);
|
|
2669
|
+
return this.publishWalletAssetsState(state);
|
|
2670
|
+
}
|
|
2660
2671
|
/** 扫码精确查券;仅可用资产会被自动选中。 */
|
|
2661
2672
|
async scanWalletAsset(code) {
|
|
2662
2673
|
if (!this.store.payment)
|