@pisell/pisellos 0.0.207 → 0.0.208
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/effects/index.d.ts +1 -1
- package/dist/modules/Rules/types.d.ts +1 -1
- package/dist/modules/Schedule/type.d.ts +7 -7
- package/dist/modules/Schedule/types.d.ts +9 -9
- package/dist/solution/BookingByStep/index.d.ts +1 -0
- package/dist/solution/BookingByStep/index.js +8 -5
- package/dist/solution/BookingByStep/utils/resources.d.ts +1 -1
- package/dist/solution/ShopDiscount/types.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/lib/core/index.js +28 -27
- package/lib/effects/index.d.ts +1 -1
- package/lib/effects/index.js +7 -3
- package/lib/modules/Account/index.js +10 -9
- package/lib/modules/AccountList/index.js +11 -14
- package/lib/modules/BaseModule.js +3 -6
- package/lib/modules/Cart/index.js +9 -14
- package/lib/modules/Cart/utils/cartProduct.js +6 -3
- package/lib/modules/Date/index.js +4 -8
- package/lib/modules/Date/types.js +0 -1
- package/lib/modules/Discount/index.js +6 -11
- package/lib/modules/Guests/index.js +15 -10
- package/lib/modules/Order/index.js +2 -4
- package/lib/modules/Payment/cash.js +1 -1
- package/lib/modules/Payment/eftpos.js +1 -1
- package/lib/modules/Payment/index.js +86 -98
- package/lib/modules/Payment/wallet.js +1 -1
- package/lib/modules/Product/index.js +5 -6
- package/lib/modules/ProductList/index.js +4 -5
- package/lib/modules/Resource/index.js +12 -8
- package/lib/modules/Rules/index.js +13 -10
- package/lib/modules/Rules/types.d.ts +1 -1
- package/lib/modules/Schedule/index.js +5 -8
- package/lib/modules/Schedule/type.d.ts +7 -7
- package/lib/modules/Schedule/types.d.ts +9 -9
- package/lib/modules/Schedule/utils.js +4 -2
- package/lib/modules/Step/index.js +4 -7
- package/lib/modules/Summary/index.js +4 -9
- package/lib/plugins/request.js +33 -34
- package/lib/plugins/window.js +113 -101
- package/lib/solution/BookingByStep/index.d.ts +1 -0
- package/lib/solution/BookingByStep/index.js +77 -52
- package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
- package/lib/solution/BookingByStep/utils/resources.js +8 -4
- package/lib/solution/BookingByStep/utils/timeslots.js +12 -6
- package/lib/solution/BuyTickets/index.js +15 -15
- package/lib/solution/ShopDiscount/index.js +11 -15
- package/lib/solution/ShopDiscount/types.d.ts +1 -1
- package/lib/types/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -43,7 +43,8 @@ function calculateResourceAvailableTime({
|
|
|
43
43
|
const matchingTimes = resource.times.filter((time) => {
|
|
44
44
|
return (0, import_dayjs.default)(time.start_at).isSame((0, import_dayjs.default)(timeSlots.start_at), "day");
|
|
45
45
|
});
|
|
46
|
-
if (matchingTimes.length === 0)
|
|
46
|
+
if (matchingTimes.length === 0)
|
|
47
|
+
return 0;
|
|
47
48
|
const overlaps = [];
|
|
48
49
|
for (const time of matchingTimes) {
|
|
49
50
|
const overlapStart = (0, import_dayjs.default)(time.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) ? (0, import_dayjs.default)(time.start_at) : (0, import_dayjs.default)(timeSlots.start_at);
|
|
@@ -52,7 +53,8 @@ function calculateResourceAvailableTime({
|
|
|
52
53
|
overlaps.push({ start: overlapStart, end: overlapEnd });
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
if (overlaps.length === 0)
|
|
56
|
+
if (overlaps.length === 0)
|
|
57
|
+
return 0;
|
|
56
58
|
overlaps.sort((a, b) => a.start.diff(b.start));
|
|
57
59
|
const merged = [];
|
|
58
60
|
let current = overlaps[0];
|
|
@@ -85,13 +87,15 @@ function findFastestAvailableResource({
|
|
|
85
87
|
const todayTimes = resource.times.filter((time) => {
|
|
86
88
|
return (0, import_dayjs.default)(time.start_at).isSame(currentTime, "day");
|
|
87
89
|
});
|
|
88
|
-
if (todayTimes.length === 0)
|
|
90
|
+
if (todayTimes.length === 0)
|
|
91
|
+
continue;
|
|
89
92
|
todayTimes.sort((a, b) => {
|
|
90
93
|
return (0, import_dayjs.default)(a.start_at).diff((0, import_dayjs.default)(b.start_at));
|
|
91
94
|
});
|
|
92
95
|
for (const time of todayTimes) {
|
|
93
96
|
const startTime = (0, import_dayjs.default)(time.start_at);
|
|
94
|
-
if (startTime.isBefore(currentTime))
|
|
97
|
+
if (startTime.isBefore(currentTime))
|
|
98
|
+
continue;
|
|
95
99
|
if (resource.resourceType === "single") {
|
|
96
100
|
const hasBooking = (_a = time.event_list) == null ? void 0 : _a.some((event) => {
|
|
97
101
|
return (0, import_dayjs.default)(event.start_at).isSame(startTime);
|
|
@@ -125,8 +129,10 @@ function findFastestAvailableResource({
|
|
|
125
129
|
}
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
|
-
if (!fastestTime || fastestResources.length === 0)
|
|
129
|
-
|
|
132
|
+
if (!fastestTime || fastestResources.length === 0)
|
|
133
|
+
return null;
|
|
134
|
+
if (fastestResources.length === 1)
|
|
135
|
+
return fastestResources[0];
|
|
130
136
|
let maxIdleTime = 0;
|
|
131
137
|
let selectedResource = null;
|
|
132
138
|
for (const resource of fastestResources) {
|
|
@@ -28,26 +28,23 @@ var import_types = require("./types");
|
|
|
28
28
|
var import_BaseModule = require("../../modules/BaseModule");
|
|
29
29
|
__reExport(BuyTickets_exports, require("./types"), module.exports);
|
|
30
30
|
var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
|
|
31
|
-
// 提供给 baseModule 用的默认名称 和 默认版本
|
|
32
|
-
defaultName = "buyTickets";
|
|
33
|
-
defaultVersion = "1.0.0";
|
|
34
|
-
isSolution = true;
|
|
35
|
-
request;
|
|
36
|
-
window;
|
|
37
|
-
store;
|
|
38
|
-
otherParams = {};
|
|
39
31
|
constructor(name, version) {
|
|
40
32
|
super(name, version);
|
|
33
|
+
// 提供给 baseModule 用的默认名称 和 默认版本
|
|
34
|
+
this.defaultName = "buyTickets";
|
|
35
|
+
this.defaultVersion = "1.0.0";
|
|
36
|
+
this.isSolution = true;
|
|
37
|
+
this.otherParams = {};
|
|
41
38
|
}
|
|
42
39
|
async initialize(core, options) {
|
|
43
40
|
this.core = core;
|
|
44
41
|
this.store = options.store || {};
|
|
45
42
|
this.otherParams = options.otherParams || {};
|
|
46
|
-
console.log("[BuyTickets]
|
|
43
|
+
console.log("[BuyTickets] 初始化完成");
|
|
47
44
|
this.request = core.getPlugin("request");
|
|
48
45
|
this.window = core.getPlugin("window");
|
|
49
46
|
if (!this.request) {
|
|
50
|
-
throw new Error("
|
|
47
|
+
throw new Error("购物车模块需要 request 插件支持");
|
|
51
48
|
}
|
|
52
49
|
if (this.otherParams.prodctIds) {
|
|
53
50
|
await this.loadProductsByIds(this.otherParams.prodctIds);
|
|
@@ -79,7 +76,7 @@ var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
|
|
|
79
76
|
}
|
|
80
77
|
async destroy() {
|
|
81
78
|
await this.core.effects.emit(import_types.BuyTicketsHooks.onDestroy, {});
|
|
82
|
-
console.log("[BuyTickets]
|
|
79
|
+
console.log("[BuyTickets] 已销毁");
|
|
83
80
|
}
|
|
84
81
|
// 获取当前绑定的所有商品
|
|
85
82
|
async getProducts() {
|
|
@@ -97,8 +94,10 @@ var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
|
|
|
97
94
|
var _a, _b;
|
|
98
95
|
const mainProduct = await ((_a = this.store.mainProducts) == null ? void 0 : _a.getProduct(id));
|
|
99
96
|
const otherProduct = await ((_b = this.store.otherProducts) == null ? void 0 : _b.getProduct(id));
|
|
100
|
-
if (mainProduct)
|
|
101
|
-
|
|
97
|
+
if (mainProduct)
|
|
98
|
+
return mainProduct;
|
|
99
|
+
if (otherProduct)
|
|
100
|
+
return otherProduct;
|
|
102
101
|
return Promise.reject("Not fund product for id: " + id);
|
|
103
102
|
}
|
|
104
103
|
// 商品列表页提交
|
|
@@ -107,12 +106,13 @@ var BuyTicketsImpl = class extends import_BaseModule.BaseModule {
|
|
|
107
106
|
...data,
|
|
108
107
|
products: this.getProducts()
|
|
109
108
|
});
|
|
110
|
-
if (res.status === false)
|
|
109
|
+
if (res.status === false)
|
|
110
|
+
return res;
|
|
111
111
|
this.window.localStorage.setItem(
|
|
112
112
|
"buyTickets:listSubmit",
|
|
113
113
|
JSON.stringify({ ...data, products: this.getProducts() })
|
|
114
114
|
);
|
|
115
|
-
console.log("listSubmit
|
|
115
|
+
console.log("listSubmit 应该走逻辑层的 API 发请求了");
|
|
116
116
|
}
|
|
117
117
|
// 购物车提交
|
|
118
118
|
async cartSubmit(data) {
|
|
@@ -39,16 +39,12 @@ var import_Discount = require("../../modules/Discount");
|
|
|
39
39
|
var import_Rules = require("../../modules/Rules");
|
|
40
40
|
var import_decimal = __toESM(require("decimal.js"));
|
|
41
41
|
var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
42
|
-
defaultName = "shopDiscount";
|
|
43
|
-
defaultVersion = "1.0.0";
|
|
44
|
-
isSolution = true;
|
|
45
|
-
request;
|
|
46
|
-
window;
|
|
47
|
-
store;
|
|
48
|
-
options = {};
|
|
49
|
-
hooks;
|
|
50
42
|
constructor(name, version) {
|
|
51
43
|
super(name, version);
|
|
44
|
+
this.defaultName = "shopDiscount";
|
|
45
|
+
this.defaultVersion = "1.0.0";
|
|
46
|
+
this.isSolution = true;
|
|
47
|
+
this.options = {};
|
|
52
48
|
this.store = {
|
|
53
49
|
customer: null,
|
|
54
50
|
productList: [],
|
|
@@ -63,7 +59,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
63
59
|
this.options = options;
|
|
64
60
|
this.store = { ...this.store, ...options.store || {} };
|
|
65
61
|
this.hooks = (_b = (_a = options.otherParams) == null ? void 0 : _a.rules) == null ? void 0 : _b.hooks;
|
|
66
|
-
console.log("[ShopDiscount]
|
|
62
|
+
console.log("[ShopDiscount] 初始化完成");
|
|
67
63
|
this.initializePlugins();
|
|
68
64
|
this.registerDependentModules();
|
|
69
65
|
this.registerEventListeners();
|
|
@@ -76,7 +72,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
76
72
|
(_b = this.store.rules) == null ? void 0 : _b.destroy();
|
|
77
73
|
this.core.effects.offByModuleDestroy(this.name);
|
|
78
74
|
await this.core.effects.emit(import_types.ShopDiscountHooks.onDestroy, {});
|
|
79
|
-
console.log("[ShopDiscount]
|
|
75
|
+
console.log("[ShopDiscount] 已销毁");
|
|
80
76
|
}
|
|
81
77
|
async clear() {
|
|
82
78
|
var _a, _b;
|
|
@@ -91,10 +87,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
91
87
|
this.request = this.core.getPlugin("request");
|
|
92
88
|
this.window = this.core.getPlugin("window");
|
|
93
89
|
if (!this.request) {
|
|
94
|
-
throw new Error("ShopDiscount
|
|
90
|
+
throw new Error("ShopDiscount需要 request 插件支持");
|
|
95
91
|
}
|
|
96
92
|
if (!this.window) {
|
|
97
|
-
throw new Error("ShopDiscount
|
|
93
|
+
throw new Error("ShopDiscount需要 window 插件支持");
|
|
98
94
|
}
|
|
99
95
|
}
|
|
100
96
|
registerDependentModules() {
|
|
@@ -258,7 +254,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
258
254
|
discountList: newDiscountList || this.getDiscountList()
|
|
259
255
|
};
|
|
260
256
|
} catch (error) {
|
|
261
|
-
console.error("[ShopDiscount]
|
|
257
|
+
console.error("[ShopDiscount] 扫码出错:", error);
|
|
262
258
|
return {
|
|
263
259
|
type: "clientCalc",
|
|
264
260
|
isAvailable: false,
|
|
@@ -388,7 +384,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
388
384
|
);
|
|
389
385
|
}
|
|
390
386
|
} catch (error) {
|
|
391
|
-
console.error("[ShopDiscount]
|
|
387
|
+
console.error("[ShopDiscount] 获取客户钱包信息出错:", error);
|
|
392
388
|
}
|
|
393
389
|
}
|
|
394
390
|
// 加载准备配置
|
|
@@ -421,7 +417,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
421
417
|
newDiscountList
|
|
422
418
|
);
|
|
423
419
|
} catch (error) {
|
|
424
|
-
console.error("[ShopDiscount]
|
|
420
|
+
console.error("[ShopDiscount] 加载准备配置出错:", error);
|
|
425
421
|
}
|
|
426
422
|
}
|
|
427
423
|
};
|
|
@@ -10,7 +10,7 @@ export declare enum ShopDiscountHooks {
|
|
|
10
10
|
onRulesListChange = "shopDiscount:onRulesListChange",
|
|
11
11
|
onLoadPrepareCalcResult = "shopDiscount:onLoadPrepareCalcResult"
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export type Customer = {
|
|
14
14
|
id: string | number;
|
|
15
15
|
name: string;
|
|
16
16
|
email: string;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface ModuleOptions {
|
|
|
27
27
|
initialState?: Record<string, any>;
|
|
28
28
|
otherParams?: Record<string, any>;
|
|
29
29
|
}
|
|
30
|
-
export
|
|
30
|
+
export type EventHandler = (data?: any) => void;
|
|
31
31
|
export interface PisellCore {
|
|
32
32
|
registerPlugin: (plugin: Plugin, options?: PluginOptions) => void;
|
|
33
33
|
getPlugin: <T extends Plugin>(name: string) => T | null;
|