@pisell/pisellos 3.0.29 → 3.0.31
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/modules/Cart/index.js +29 -3
- package/dist/modules/Cart/types.d.ts +6 -0
- package/dist/modules/Cart/utils.d.ts +2 -0
- package/dist/modules/Cart/utils.js +36 -3
- package/dist/modules/Order/index.d.ts +3 -1
- package/dist/modules/Order/index.js +25 -5
- package/dist/modules/Order/types.d.ts +1 -0
- package/dist/modules/Product/types.d.ts +2 -0
- package/dist/solution/BookingByStep/index.d.ts +18 -1
- package/dist/solution/BookingByStep/index.js +217 -30
- package/lib/modules/Cart/index.js +20 -2
- package/lib/modules/Cart/types.d.ts +6 -0
- package/lib/modules/Cart/utils.d.ts +2 -0
- package/lib/modules/Cart/utils.js +27 -5
- package/lib/modules/Order/index.d.ts +3 -1
- package/lib/modules/Order/index.js +17 -5
- package/lib/modules/Order/types.d.ts +1 -0
- package/lib/modules/Product/types.d.ts +2 -0
- package/lib/solution/BookingByStep/index.d.ts +18 -1
- package/lib/solution/BookingByStep/index.js +197 -25
- package/package.json +1 -1
|
@@ -112,7 +112,7 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
112
112
|
key: "addItem",
|
|
113
113
|
value: (function () {
|
|
114
114
|
var _addItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
|
|
115
|
-
var account, product, bundle, options, date, cartItem, items;
|
|
115
|
+
var account, product, bundle, options, date, cartItem, targetVariant, items;
|
|
116
116
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
117
117
|
while (1) switch (_context2.prev = _context2.next) {
|
|
118
118
|
case 0:
|
|
@@ -122,6 +122,18 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
122
122
|
_origin: createCartItemOrigin()
|
|
123
123
|
};
|
|
124
124
|
if (product) {
|
|
125
|
+
// 判断组合商品,然后直接修改 product 里的价格和 is_charge_tax
|
|
126
|
+
if (product.product_variant_id) {
|
|
127
|
+
// 还需要判断 能从 variant 里找到对应的组合规格信息,才可以替换
|
|
128
|
+
targetVariant = product.variant.find(function (n) {
|
|
129
|
+
return n.id === product.product_variant_id;
|
|
130
|
+
});
|
|
131
|
+
if (targetVariant) {
|
|
132
|
+
product.price = targetVariant.price;
|
|
133
|
+
product.original_price = targetVariant.original_price;
|
|
134
|
+
product.is_charge_tax = targetVariant.is_charge_tax;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
125
137
|
cartItem._productOrigin = cloneDeep(product);
|
|
126
138
|
cartItem._productInit = cloneDeep(product);
|
|
127
139
|
cartItem._bundleOrigin = cloneDeep(bundle);
|
|
@@ -130,7 +142,8 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
130
142
|
cartItem: cartItem,
|
|
131
143
|
product: product,
|
|
132
144
|
bundle: bundle,
|
|
133
|
-
options: options
|
|
145
|
+
options: options,
|
|
146
|
+
product_variant_id: product.product_variant_id
|
|
134
147
|
});
|
|
135
148
|
}
|
|
136
149
|
if (account) {
|
|
@@ -234,6 +247,18 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
234
247
|
tempCartItem = cartItem;
|
|
235
248
|
}
|
|
236
249
|
if (product) {
|
|
250
|
+
// 判断组合商品,然后直接修改 product 里的价格和 is_charge_tax
|
|
251
|
+
if (product.product_variant_id) {
|
|
252
|
+
// 还需要判断 能从 variant 里找到对应的组合规格信息,才可以替换
|
|
253
|
+
var targetVariant = product.variant.find(function (n) {
|
|
254
|
+
return n.id === product.product_variant_id;
|
|
255
|
+
});
|
|
256
|
+
if (targetVariant) {
|
|
257
|
+
product.price = targetVariant.price;
|
|
258
|
+
product.original_price = targetVariant.original_price;
|
|
259
|
+
product.is_charge_tax = targetVariant.is_charge_tax;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
237
262
|
tempCartItem._productOrigin = cloneDeep(product);
|
|
238
263
|
tempCartItem._bundleOrigin = cloneDeep(bundle);
|
|
239
264
|
tempCartItem._optionsOrigin = cloneDeep(options);
|
|
@@ -241,7 +266,8 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
241
266
|
cartItem: tempCartItem,
|
|
242
267
|
product: product,
|
|
243
268
|
bundle: bundle,
|
|
244
|
-
options: options
|
|
269
|
+
options: options,
|
|
270
|
+
product_variant_id: product.product_variant_id
|
|
245
271
|
});
|
|
246
272
|
}
|
|
247
273
|
if (discounts) {
|
|
@@ -140,6 +140,8 @@ export interface CartItem {
|
|
|
140
140
|
_bundleOrigin?: any[];
|
|
141
141
|
/** 商品规格原始数据 */
|
|
142
142
|
_optionsOrigin?: any[];
|
|
143
|
+
/** 商品规格组合字符串,提供给 UI 展示的 */
|
|
144
|
+
product_option_string?: string;
|
|
143
145
|
}
|
|
144
146
|
/**
|
|
145
147
|
* 购物车状态接口
|
|
@@ -168,6 +170,8 @@ export interface IAddItemParams {
|
|
|
168
170
|
/** 结束时间 */
|
|
169
171
|
endTime: string;
|
|
170
172
|
};
|
|
173
|
+
/** 商品组合规格ID */
|
|
174
|
+
product_variant_id?: number;
|
|
171
175
|
}
|
|
172
176
|
/**
|
|
173
177
|
* 更新购物车信息参数
|
|
@@ -209,6 +213,8 @@ export interface IUpdateItemParams {
|
|
|
209
213
|
/** 关联表单记录ID */
|
|
210
214
|
form_record_ids: number[];
|
|
211
215
|
}[];
|
|
216
|
+
/** 商品组合规格ID */
|
|
217
|
+
product_variant_id?: number;
|
|
212
218
|
}
|
|
213
219
|
/**
|
|
214
220
|
* 折扣
|
|
@@ -40,12 +40,14 @@ export declare const formatProductToCartItem: (params: {
|
|
|
40
40
|
product: ProductData;
|
|
41
41
|
bundle?: any;
|
|
42
42
|
options?: any;
|
|
43
|
+
product_variant_id?: number;
|
|
43
44
|
}) => CartItem;
|
|
44
45
|
export declare const formatProductToCartItemOrigin: (params: {
|
|
45
46
|
cartItem: CartItem;
|
|
46
47
|
product: ProductData;
|
|
47
48
|
bundle?: any;
|
|
48
49
|
options?: any;
|
|
50
|
+
product_variant_id?: number;
|
|
49
51
|
}) => any;
|
|
50
52
|
/**
|
|
51
53
|
* 格式化折扣到购物车
|
|
@@ -79,7 +79,8 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
|
|
|
79
79
|
var cartItem = params.cartItem,
|
|
80
80
|
product = params.product,
|
|
81
81
|
bundle = params.bundle,
|
|
82
|
-
options = params.options
|
|
82
|
+
options = params.options,
|
|
83
|
+
product_variant_id = params.product_variant_id;
|
|
83
84
|
var num = 1; // 当前按照单个商品加入购物车
|
|
84
85
|
if (product) {
|
|
85
86
|
cartItem.id = product === null || product === void 0 ? void 0 : product.id;
|
|
@@ -110,6 +111,31 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
|
|
|
110
111
|
if (options !== null && options !== void 0 && options.length) {
|
|
111
112
|
cartItem.options = formatOptions(options);
|
|
112
113
|
}
|
|
114
|
+
// 拼装出 product_option_string
|
|
115
|
+
if (product_variant_id) {
|
|
116
|
+
var _product$variant$find;
|
|
117
|
+
var sku_key = (_product$variant$find = product.variant.find(function (n) {
|
|
118
|
+
return n.id === product_variant_id;
|
|
119
|
+
})) === null || _product$variant$find === void 0 ? void 0 : _product$variant$find.sku_key;
|
|
120
|
+
if (sku_key) {
|
|
121
|
+
var sku_key_arr = sku_key.split('_');
|
|
122
|
+
var product_option_string = [];
|
|
123
|
+
sku_key_arr.forEach(function (item) {
|
|
124
|
+
var _targetVariantGroup$v;
|
|
125
|
+
var keyMap = item.split(':');
|
|
126
|
+
var targetVariantGroup = product.variant_group.find(function (n) {
|
|
127
|
+
return String(n.position_id) === keyMap[0];
|
|
128
|
+
});
|
|
129
|
+
var targetVariantItem = targetVariantGroup === null || targetVariantGroup === void 0 || (_targetVariantGroup$v = targetVariantGroup.variant_item) === null || _targetVariantGroup$v === void 0 ? void 0 : _targetVariantGroup$v.find(function (n) {
|
|
130
|
+
return String(n.position_id) === keyMap[1];
|
|
131
|
+
});
|
|
132
|
+
if (targetVariantGroup && targetVariantItem) {
|
|
133
|
+
product_option_string.push("".concat(targetVariantGroup.name, ":").concat(targetVariantItem.name));
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
cartItem.product_option_string = product_option_string.join(', ');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
113
139
|
|
|
114
140
|
// 如果商品有定金规则,则计算定金
|
|
115
141
|
if ((product === null || product === void 0 || (_product$custom_depos = product.custom_deposit_data) === null || _product$custom_depos === void 0 ? void 0 : _product$custom_depos.has_deposit) == 1) {
|
|
@@ -129,14 +155,15 @@ export var formatProductToCartItemOrigin = function formatProductToCartItemOrigi
|
|
|
129
155
|
var cartItem = params.cartItem,
|
|
130
156
|
product = params.product,
|
|
131
157
|
bundle = params.bundle,
|
|
132
|
-
options = params.options
|
|
158
|
+
options = params.options,
|
|
159
|
+
product_variant_id = params.product_variant_id;
|
|
133
160
|
var origin = cartItem._origin;
|
|
134
161
|
if (product) {
|
|
135
162
|
var _origin$product, _origin$product2, _product$duration, _product$duration2;
|
|
136
163
|
origin.product = _objectSpread(_objectSpread({}, origin.product || {}), {}, {
|
|
137
164
|
num: 1,
|
|
138
165
|
product_id: product.id,
|
|
139
|
-
product_variant_id:
|
|
166
|
+
product_variant_id: product_variant_id || 0,
|
|
140
167
|
product_bundle: ((_origin$product = origin.product) === null || _origin$product === void 0 ? void 0 : _origin$product.product_bundle) || [],
|
|
141
168
|
product_option_item: ((_origin$product2 = origin.product) === null || _origin$product2 === void 0 ? void 0 : _origin$product2.product_option_item) || []
|
|
142
169
|
});
|
|
@@ -180,6 +207,12 @@ export var formatDiscountToCartItemOrigin = function formatDiscountToCartItemOri
|
|
|
180
207
|
origin.product = {};
|
|
181
208
|
}
|
|
182
209
|
origin.product.discount_list = discounts;
|
|
210
|
+
} else {
|
|
211
|
+
// 如果折扣为空,则清空折扣列表
|
|
212
|
+
if (!origin.product) {
|
|
213
|
+
origin.product = {};
|
|
214
|
+
}
|
|
215
|
+
origin.product.discount_list = [];
|
|
183
216
|
}
|
|
184
217
|
return origin;
|
|
185
218
|
};
|
|
@@ -10,7 +10,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
10
10
|
constructor(name?: string, version?: string);
|
|
11
11
|
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
12
12
|
createOrder(params: CommitOrderParams['query']): {
|
|
13
|
-
type:
|
|
13
|
+
type: "virtual" | "appointment_booking";
|
|
14
14
|
platform: string;
|
|
15
15
|
sales_channel: string;
|
|
16
16
|
order_sales_channel: string;
|
|
@@ -18,6 +18,8 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
18
18
|
shop_note: string;
|
|
19
19
|
schedule_date: string;
|
|
20
20
|
is_deposit: number;
|
|
21
|
+
relation_products: any[];
|
|
22
|
+
relation_forms: any[];
|
|
21
23
|
};
|
|
22
24
|
checkBeforeSubmitOrder(params: {
|
|
23
25
|
cartItems: CartItem[];
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
2
8
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
9
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
10
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
@@ -55,14 +61,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
55
61
|
key: "createOrder",
|
|
56
62
|
value: function createOrder(params) {
|
|
57
63
|
var order = {
|
|
58
|
-
type: 'appointment_booking',
|
|
64
|
+
type: params.type || 'appointment_booking',
|
|
65
|
+
// 要从外面拿,virtual
|
|
59
66
|
platform: 'H5',
|
|
60
67
|
sales_channel: 'my_pisel',
|
|
61
68
|
order_sales_channel: 'online_store',
|
|
62
69
|
bookings: [],
|
|
63
70
|
shop_note: '',
|
|
64
71
|
schedule_date: '',
|
|
65
|
-
is_deposit: 0
|
|
72
|
+
is_deposit: 0,
|
|
73
|
+
relation_products: [],
|
|
74
|
+
relation_forms: []
|
|
66
75
|
};
|
|
67
76
|
var is_deposit = 0; // 是否存在定金,0 不存在,1 存在
|
|
68
77
|
if (params.cartItems.length > 0) {
|
|
@@ -74,13 +83,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
74
83
|
item._origin.duration = duration;
|
|
75
84
|
item._origin.sub_type = durationType;
|
|
76
85
|
}
|
|
77
|
-
|
|
86
|
+
// 零售都视为普通商品
|
|
87
|
+
if (order.type === 'virtual') {
|
|
88
|
+
var _order$relation_forms;
|
|
89
|
+
order.relation_products.push(item._origin.product);
|
|
90
|
+
var relationForms = item._origin.relation_forms || [];
|
|
91
|
+
(_order$relation_forms = order.relation_forms).push.apply(_order$relation_forms, _toConsumableArray(relationForms));
|
|
92
|
+
delete item._origin.relation_forms;
|
|
93
|
+
} else {
|
|
94
|
+
order.bookings.push(item._origin);
|
|
95
|
+
}
|
|
78
96
|
if (item !== null && item !== void 0 && item.deposit) {
|
|
79
97
|
is_deposit = 1;
|
|
80
98
|
}
|
|
81
99
|
});
|
|
82
|
-
|
|
83
|
-
|
|
100
|
+
if (order.type === 'appointment_booking') {
|
|
101
|
+
var firstCartItem = params.cartItems[0];
|
|
102
|
+
order.schedule_date = firstCartItem.start_date + ' ' + firstCartItem.start_time + ':00';
|
|
103
|
+
}
|
|
84
104
|
order.is_deposit = is_deposit;
|
|
85
105
|
}
|
|
86
106
|
return order;
|
|
@@ -167,7 +167,10 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
167
167
|
holder_id: string;
|
|
168
168
|
resources_code: string | number;
|
|
169
169
|
timeSlots?: TimeSliceItem;
|
|
170
|
-
countMap: Record<number,
|
|
170
|
+
countMap: Record<number, {
|
|
171
|
+
pax: number;
|
|
172
|
+
time: TimeSliceItem;
|
|
173
|
+
}[]>;
|
|
171
174
|
capacity?: number;
|
|
172
175
|
}): {
|
|
173
176
|
selectedResource: any;
|
|
@@ -209,4 +212,18 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
209
212
|
setOtherData(key: string, value: any): void;
|
|
210
213
|
getOtherData(key: string): any;
|
|
211
214
|
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
215
|
+
/**
|
|
216
|
+
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
217
|
+
*
|
|
218
|
+
* @param {string} cartItemId
|
|
219
|
+
* @param {string} resourceCode
|
|
220
|
+
* @return {*}
|
|
221
|
+
* @memberof BookingByStepImpl
|
|
222
|
+
*/
|
|
223
|
+
getResourcesByCartItemAndCode(cartItemId: string, resourceCode: string): any;
|
|
224
|
+
getAvailableDateForSession(params?: {
|
|
225
|
+
startDate?: string;
|
|
226
|
+
endDate?: string;
|
|
227
|
+
type?: 'month';
|
|
228
|
+
}): Promise<ITime[]>;
|
|
212
229
|
}
|
|
@@ -233,7 +233,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
233
233
|
return this.request.post("/product/query", {
|
|
234
234
|
open_quotation: 1,
|
|
235
235
|
open_bundle: 0,
|
|
236
|
-
extension_type: ['product_appointment', 'appointment_ticket', 'session_product', 'session_ticket'],
|
|
236
|
+
extension_type: ['product_appointment', 'appointment_ticket', 'session_product', 'session_ticket', 'normal'],
|
|
237
237
|
with: ['category', 'collection', 'resourceRelation'],
|
|
238
238
|
status: 'published',
|
|
239
239
|
num: 500,
|
|
@@ -1060,40 +1060,44 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1060
1060
|
key: "submitOrder",
|
|
1061
1061
|
value: function () {
|
|
1062
1062
|
var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
|
|
1063
|
-
var cartItems, newCartItems;
|
|
1063
|
+
var cartItems, newCartItems, type;
|
|
1064
1064
|
return _regeneratorRuntime().wrap(function _callee21$(_context22) {
|
|
1065
1065
|
while (1) switch (_context22.prev = _context22.next) {
|
|
1066
1066
|
case 0:
|
|
1067
1067
|
cartItems = this.store.cart.getItems();
|
|
1068
1068
|
newCartItems = cloneDeep(cartItems); // 先整个临时的逻辑,把购物车里所有商品的资源给他格式化一下
|
|
1069
1069
|
newCartItems.forEach(function (item) {
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
item._origin.metadata
|
|
1070
|
+
if (item._origin.resources && item._origin.resources.length) {
|
|
1071
|
+
var _item$_productOrigin, _item$_origin;
|
|
1072
|
+
item._origin.resources = item._origin.resources.map(function (n) {
|
|
1073
|
+
var newResourcesItem = cloneDeep(n);
|
|
1074
|
+
delete newResourcesItem.id;
|
|
1075
|
+
delete newResourcesItem.main_field;
|
|
1076
|
+
delete newResourcesItem.resourceType;
|
|
1077
|
+
return _objectSpread({}, newResourcesItem);
|
|
1078
|
+
});
|
|
1079
|
+
var formatCapacity = formatDefaultCapacitys({
|
|
1080
|
+
capacity: (_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 ? void 0 : _item$_productOrigin.capacity,
|
|
1081
|
+
product_bundle: item._origin.product.product_bundle
|
|
1082
|
+
});
|
|
1083
|
+
var currentCapacity = getSumCapacity({
|
|
1084
|
+
capacity: formatCapacity
|
|
1085
|
+
});
|
|
1086
|
+
if (!((_item$_origin = item._origin) !== null && _item$_origin !== void 0 && _item$_origin.metadata)) {
|
|
1087
|
+
item._origin.metadata = {};
|
|
1088
|
+
}
|
|
1089
|
+
item._origin.metadata.capacity = formatCapacity;
|
|
1090
|
+
item._origin.number = currentCapacity;
|
|
1087
1091
|
}
|
|
1088
|
-
item._origin.metadata.capacity = formatCapacity;
|
|
1089
|
-
item._origin.number = currentCapacity;
|
|
1090
1092
|
});
|
|
1093
|
+
type = this.otherParams.isRetailTemplate ? 'virtual' : 'appointment_booking';
|
|
1091
1094
|
return _context22.abrupt("return", this.store.order.submitOrder({
|
|
1092
1095
|
query: {
|
|
1093
|
-
cartItems: newCartItems
|
|
1096
|
+
cartItems: newCartItems,
|
|
1097
|
+
type: type
|
|
1094
1098
|
}
|
|
1095
1099
|
}));
|
|
1096
|
-
case
|
|
1100
|
+
case 5:
|
|
1097
1101
|
case "end":
|
|
1098
1102
|
return _context22.stop();
|
|
1099
1103
|
}
|
|
@@ -1211,6 +1215,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1211
1215
|
});
|
|
1212
1216
|
}
|
|
1213
1217
|
this.store.cart.updateItem(params);
|
|
1218
|
+
if (this.otherParams.isRetailTemplate) {
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1214
1221
|
var allOriginResources = [];
|
|
1215
1222
|
var dateRange = this.store.date.getDateRange();
|
|
1216
1223
|
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
@@ -1796,7 +1803,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1796
1803
|
// resourcesUseableMap[n.id] = false;
|
|
1797
1804
|
// continue
|
|
1798
1805
|
// }
|
|
1799
|
-
|
|
1806
|
+
// const recordCount = countMap[n.id] || 0;
|
|
1800
1807
|
// n.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
|
|
1801
1808
|
// time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
|
|
1802
1809
|
// 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
|
|
@@ -1807,13 +1814,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1807
1814
|
if (mTimes.length === 0) {
|
|
1808
1815
|
return 0; // continue
|
|
1809
1816
|
}
|
|
1817
|
+
// 计算在时间片内有交集的预约容量总和
|
|
1818
|
+
var totalCapacity = (countMap[n.id] || []).reduce(function (sum, item) {
|
|
1819
|
+
var hasOverlap = !dayjs(item.time.start_at).isAfter(dayjs(timeSlots.start_at)) && !dayjs(item.time.end_at).isBefore(dayjs(timeSlots.end_at));
|
|
1820
|
+
return hasOverlap ? sum + item.pax : sum;
|
|
1821
|
+
}, 0);
|
|
1810
1822
|
var canUseTime = mTimes.find(function (item) {
|
|
1811
1823
|
var _cartItem$_productOri10;
|
|
1812
1824
|
var res = getIsUsableByTimeItem({
|
|
1813
1825
|
timeSlice: timeSlots,
|
|
1814
1826
|
time: item,
|
|
1815
1827
|
resource: n,
|
|
1816
|
-
currentCount:
|
|
1828
|
+
currentCount: totalCapacity + (capacity || 0),
|
|
1817
1829
|
resourcesUseableMap: resourcesUseableMap,
|
|
1818
1830
|
cut_off_time: (_cartItem$_productOri10 = cartItem._productOrigin) === null || _cartItem$_productOri10 === void 0 ? void 0 : _cartItem$_productOri10.cut_off_time
|
|
1819
1831
|
});
|
|
@@ -1884,6 +1896,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1884
1896
|
// 一个账号一个账号处理
|
|
1885
1897
|
var errorList = [];
|
|
1886
1898
|
var selectResourcesMap = {};
|
|
1899
|
+
var selectResourcesWithTimeSlots = {};
|
|
1887
1900
|
var accountList = this.store.accountList.getAccounts();
|
|
1888
1901
|
var selectForCartResources = function selectForCartResources(cartItems) {
|
|
1889
1902
|
var recordTimeSlots = cloneDeep(timeSlots);
|
|
@@ -1916,8 +1929,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1916
1929
|
var currentResourceConfig = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.product_resource) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.resources) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.find(function (n) {
|
|
1917
1930
|
return n.code === resources_code;
|
|
1918
1931
|
});
|
|
1932
|
+
var resourceBookingType = (currentResourceConfig === null || currentResourceConfig === void 0 ? void 0 : currentResourceConfig.type) || 'single';
|
|
1919
1933
|
// 只有 duration 类商品需要这个操作
|
|
1920
|
-
if (index !== 0 && recordTimeSlots &&
|
|
1934
|
+
if (index !== 0 && recordTimeSlots && resourceBookingType === 'single' && (_item$_productOrigin5 = item._productOrigin) !== null && _item$_productOrigin5 !== void 0 && _item$_productOrigin5.duration) {
|
|
1921
1935
|
var _item$_productOrigin$, _item$_productOrigin6, _ref9, _item$_productOrigin7, _item$_productOrigin$2, _item$_productOrigin8, _ref10, _item$_productOrigin9;
|
|
1922
1936
|
var start_at = dayjs(recordTimeSlots.end_time).add((_item$_productOrigin$ = (_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.duration) === null || _item$_productOrigin6 === void 0 ? void 0 : _item$_productOrigin6.value) !== null && _item$_productOrigin$ !== void 0 ? _item$_productOrigin$ : 0, (_ref9 = (_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.duration) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.type) !== null && _ref9 !== void 0 ? _ref9 : 'minutes');
|
|
1923
1937
|
var end_at = start_at.add((_item$_productOrigin$2 = (_item$_productOrigin8 = item._productOrigin) === null || _item$_productOrigin8 === void 0 || (_item$_productOrigin8 = _item$_productOrigin8.duration) === null || _item$_productOrigin8 === void 0 ? void 0 : _item$_productOrigin8.value) !== null && _item$_productOrigin$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref10 = (_item$_productOrigin9 = item._productOrigin) === null || _item$_productOrigin9 === void 0 || (_item$_productOrigin9 = _item$_productOrigin9.duration) === null || _item$_productOrigin9 === void 0 ? void 0 : _item$_productOrigin9.type) !== null && _ref10 !== void 0 ? _ref10 : 'minutes');
|
|
@@ -1934,7 +1948,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1934
1948
|
holder_id: item.holder_id,
|
|
1935
1949
|
resources_code: resources_code,
|
|
1936
1950
|
timeSlots: recordTimeSlots,
|
|
1937
|
-
countMap:
|
|
1951
|
+
countMap: selectResourcesWithTimeSlots,
|
|
1938
1952
|
capacity: currentCapacity
|
|
1939
1953
|
});
|
|
1940
1954
|
// // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
|
|
@@ -1942,10 +1956,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1942
1956
|
// return
|
|
1943
1957
|
// }
|
|
1944
1958
|
if (res !== null && res !== void 0 && res.selectedResource) {
|
|
1945
|
-
if (!
|
|
1946
|
-
|
|
1959
|
+
if (!selectResourcesWithTimeSlots[res.selectedResource.id]) {
|
|
1960
|
+
selectResourcesWithTimeSlots[res.selectedResource.id] = [{
|
|
1961
|
+
pax: currentCapacity,
|
|
1962
|
+
time: recordTimeSlots
|
|
1963
|
+
}];
|
|
1947
1964
|
} else {
|
|
1948
|
-
|
|
1965
|
+
selectResourcesWithTimeSlots[res.selectedResource.id].push({
|
|
1966
|
+
pax: currentCapacity,
|
|
1967
|
+
time: recordTimeSlots
|
|
1968
|
+
});
|
|
1949
1969
|
}
|
|
1950
1970
|
res.selectedResource.capacity = currentCapacity;
|
|
1951
1971
|
checkSubResourcesCapacity(res.selectedResource);
|
|
@@ -2476,6 +2496,173 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2476
2496
|
}
|
|
2477
2497
|
return getProductTypeById;
|
|
2478
2498
|
}()
|
|
2499
|
+
/**
|
|
2500
|
+
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
2501
|
+
*
|
|
2502
|
+
* @param {string} cartItemId
|
|
2503
|
+
* @param {string} resourceCode
|
|
2504
|
+
* @return {*}
|
|
2505
|
+
* @memberof BookingByStepImpl
|
|
2506
|
+
*/
|
|
2507
|
+
}, {
|
|
2508
|
+
key: "getResourcesByCartItemAndCode",
|
|
2509
|
+
value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
2510
|
+
var _cartItem$_productOri11, _cartItem$_productOri12;
|
|
2511
|
+
var dateRange = this.store.date.getDateRange();
|
|
2512
|
+
var resources = [];
|
|
2513
|
+
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
2514
|
+
dateRange.forEach(function (n) {
|
|
2515
|
+
if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
|
|
2516
|
+
});
|
|
2517
|
+
}
|
|
2518
|
+
if (!resources.length) {
|
|
2519
|
+
var dateList = this.store.date.getDateList();
|
|
2520
|
+
dateList.forEach(function (n) {
|
|
2521
|
+
if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
|
|
2522
|
+
});
|
|
2523
|
+
}
|
|
2524
|
+
var resourcesMap = getResourcesMap(cloneDeep(resources));
|
|
2525
|
+
var cartItems = this.store.cart.getItems();
|
|
2526
|
+
var cartItem = cartItems.find(function (item) {
|
|
2527
|
+
return item._id === cartItemId;
|
|
2528
|
+
});
|
|
2529
|
+
if (!cartItem) return [];
|
|
2530
|
+
var selectedResources = [];
|
|
2531
|
+
var formatCapacity = formatDefaultCapacitys({
|
|
2532
|
+
capacity: (_cartItem$_productOri11 = cartItem._productOrigin) === null || _cartItem$_productOri11 === void 0 ? void 0 : _cartItem$_productOri11.capacity,
|
|
2533
|
+
product_bundle: cartItem._origin.product.product_bundle
|
|
2534
|
+
});
|
|
2535
|
+
cartItem._origin.metadata.capacity = formatCapacity;
|
|
2536
|
+
var currentCapacity = getSumCapacity({
|
|
2537
|
+
capacity: formatCapacity
|
|
2538
|
+
});
|
|
2539
|
+
if (cartItem.holder_id) {
|
|
2540
|
+
selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
|
|
2541
|
+
} else {
|
|
2542
|
+
selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
|
|
2543
|
+
}
|
|
2544
|
+
var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri12 = cartItem._productOrigin) === null || _cartItem$_productOri12 === void 0 || (_cartItem$_productOri12 = _cartItem$_productOri12.product_resource) === null || _cartItem$_productOri12 === void 0 ? void 0 : _cartItem$_productOri12.resources) || [], selectedResources, currentCapacity);
|
|
2545
|
+
var targetResource = productResources.find(function (resource) {
|
|
2546
|
+
return resource.code === resourceCode;
|
|
2547
|
+
});
|
|
2548
|
+
if (!targetResource) return [];
|
|
2549
|
+
if (cartItem._origin.start_time) {
|
|
2550
|
+
var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
|
|
2551
|
+
var endTime = dayjs("".concat(cartItem._origin.end_date, " ").concat(cartItem._origin.end_time));
|
|
2552
|
+
var resourcesUseableMap = {};
|
|
2553
|
+
targetResource.renderList = targetResource.renderList.sort(function (a, b) {
|
|
2554
|
+
var _a$metadata5, _b$metadata5;
|
|
2555
|
+
var aIsCombined = ((_a$metadata5 = a.metadata) === null || _a$metadata5 === void 0 || (_a$metadata5 = _a$metadata5.combined_resource) === null || _a$metadata5 === void 0 ? void 0 : _a$metadata5.status) === 1;
|
|
2556
|
+
var bIsCombined = ((_b$metadata5 = b.metadata) === null || _b$metadata5 === void 0 || (_b$metadata5 = _b$metadata5.combined_resource) === null || _b$metadata5 === void 0 ? void 0 : _b$metadata5.status) === 1;
|
|
2557
|
+
if (aIsCombined && !bIsCombined) return 1;
|
|
2558
|
+
if (!aIsCombined && bIsCombined) return -1;
|
|
2559
|
+
return 0;
|
|
2560
|
+
});
|
|
2561
|
+
targetResource.renderList = targetResource.renderList.filter(function (m) {
|
|
2562
|
+
var mTimes = m.times.filter(function (n) {
|
|
2563
|
+
return !dayjs(n.start_at).isAfter(dayjs(startTime)) && !dayjs(n.end_at).isBefore(dayjs(endTime));
|
|
2564
|
+
});
|
|
2565
|
+
if (mTimes.length === 0) return false;
|
|
2566
|
+
var canUseArr = mTimes.map(function (item) {
|
|
2567
|
+
var _cartItem$_productOri13;
|
|
2568
|
+
var res = getIsUsableByTimeItem({
|
|
2569
|
+
timeSlice: {
|
|
2570
|
+
start_time: startTime.format('HH:mm'),
|
|
2571
|
+
end_time: endTime.format('HH:mm'),
|
|
2572
|
+
start_at: startTime,
|
|
2573
|
+
end_at: endTime
|
|
2574
|
+
},
|
|
2575
|
+
time: item,
|
|
2576
|
+
resource: m,
|
|
2577
|
+
currentCount: currentCapacity || 0,
|
|
2578
|
+
resourcesUseableMap: resourcesUseableMap,
|
|
2579
|
+
cut_off_time: (_cartItem$_productOri13 = cartItem._productOrigin) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.cut_off_time
|
|
2580
|
+
});
|
|
2581
|
+
if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
|
|
2582
|
+
resourcesUseableMap[m.id] = res.usable;
|
|
2583
|
+
}
|
|
2584
|
+
return res.usable;
|
|
2585
|
+
});
|
|
2586
|
+
if (m.onlyComputed) return false;
|
|
2587
|
+
return !canUseArr.some(function (n) {
|
|
2588
|
+
return n === false;
|
|
2589
|
+
});
|
|
2590
|
+
});
|
|
2591
|
+
} else {
|
|
2592
|
+
targetResource.renderList = targetResource.renderList.filter(function (n) {
|
|
2593
|
+
var _cartItem$_productOri14;
|
|
2594
|
+
var recordCount = n.capacity || 0;
|
|
2595
|
+
if (n.onlyComputed) return false;
|
|
2596
|
+
var timeSlots = getTimeSlicesByResource({
|
|
2597
|
+
resource: n,
|
|
2598
|
+
duration: ((_cartItem$_productOri14 = cartItem._productOrigin) === null || _cartItem$_productOri14 === void 0 || (_cartItem$_productOri14 = _cartItem$_productOri14.duration) === null || _cartItem$_productOri14 === void 0 ? void 0 : _cartItem$_productOri14.value) || 0,
|
|
2599
|
+
split: 10,
|
|
2600
|
+
currentDate: dateRange[0].date
|
|
2601
|
+
});
|
|
2602
|
+
return recordCount >= currentCapacity && timeSlots.length > 0;
|
|
2603
|
+
});
|
|
2604
|
+
}
|
|
2605
|
+
return targetResource.renderList;
|
|
2606
|
+
}
|
|
2607
|
+
}, {
|
|
2608
|
+
key: "getAvailableDateForSession",
|
|
2609
|
+
value: function () {
|
|
2610
|
+
var _getAvailableDateForSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
|
|
2611
|
+
var params,
|
|
2612
|
+
startDate,
|
|
2613
|
+
endDate,
|
|
2614
|
+
type,
|
|
2615
|
+
tempProducts,
|
|
2616
|
+
_ref15,
|
|
2617
|
+
resourceIds,
|
|
2618
|
+
rules,
|
|
2619
|
+
resourcesMap,
|
|
2620
|
+
res,
|
|
2621
|
+
_args29 = arguments;
|
|
2622
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context29) {
|
|
2623
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
2624
|
+
case 0:
|
|
2625
|
+
params = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
|
|
2626
|
+
// 开始日期如果小于今天,直接以今天当做开始日期
|
|
2627
|
+
startDate = params.startDate, endDate = params.endDate, type = params.type; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
|
|
2628
|
+
if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
|
|
2629
|
+
startDate = dayjs().format('YYYY-MM-DD');
|
|
2630
|
+
}
|
|
2631
|
+
// 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
|
|
2632
|
+
endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
|
|
2633
|
+
tempProducts = []; // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
|
|
2634
|
+
if (this.store.currentProduct) {
|
|
2635
|
+
tempProducts = [_objectSpread(_objectSpread({}, this.store.currentProduct.getData()), {}, {
|
|
2636
|
+
_schedule: this.store.currentProduct.getOtherParams()['schedule']
|
|
2637
|
+
})];
|
|
2638
|
+
}
|
|
2639
|
+
// 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
|
|
2640
|
+
_ref15 = getAvailableProductResources(tempProducts) || {}, resourceIds = _ref15.resourceIds, rules = _ref15.rules, resourcesMap = _ref15.resourcesMap;
|
|
2641
|
+
this.otherParams.currentResourcesMap = resourcesMap;
|
|
2642
|
+
_context29.next = 10;
|
|
2643
|
+
return this.store.date.getResourceDates({
|
|
2644
|
+
query: {
|
|
2645
|
+
start_date: startDate || '',
|
|
2646
|
+
end_date: endDate || '',
|
|
2647
|
+
resource_ids: resourceIds
|
|
2648
|
+
},
|
|
2649
|
+
rules: rules,
|
|
2650
|
+
type: type
|
|
2651
|
+
});
|
|
2652
|
+
case 10:
|
|
2653
|
+
res = _context29.sent;
|
|
2654
|
+
return _context29.abrupt("return", res);
|
|
2655
|
+
case 12:
|
|
2656
|
+
case "end":
|
|
2657
|
+
return _context29.stop();
|
|
2658
|
+
}
|
|
2659
|
+
}, _callee28, this);
|
|
2660
|
+
}));
|
|
2661
|
+
function getAvailableDateForSession() {
|
|
2662
|
+
return _getAvailableDateForSession.apply(this, arguments);
|
|
2663
|
+
}
|
|
2664
|
+
return getAvailableDateForSession;
|
|
2665
|
+
}()
|
|
2479
2666
|
}]);
|
|
2480
2667
|
return BookingByStepImpl;
|
|
2481
2668
|
}(BaseModule);
|
|
@@ -76,6 +76,14 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
76
76
|
_origin: (0, import_utils.createCartItemOrigin)()
|
|
77
77
|
};
|
|
78
78
|
if (product) {
|
|
79
|
+
if (product.product_variant_id) {
|
|
80
|
+
const targetVariant = product.variant.find((n) => n.id === product.product_variant_id);
|
|
81
|
+
if (targetVariant) {
|
|
82
|
+
product.price = targetVariant.price;
|
|
83
|
+
product.original_price = targetVariant.original_price;
|
|
84
|
+
product.is_charge_tax = targetVariant.is_charge_tax;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
79
87
|
cartItem._productOrigin = (0, import_lodash_es.cloneDeep)(product);
|
|
80
88
|
cartItem._productInit = (0, import_lodash_es.cloneDeep)(product);
|
|
81
89
|
cartItem._bundleOrigin = (0, import_lodash_es.cloneDeep)(bundle);
|
|
@@ -84,7 +92,8 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
84
92
|
cartItem,
|
|
85
93
|
product,
|
|
86
94
|
bundle,
|
|
87
|
-
options
|
|
95
|
+
options,
|
|
96
|
+
product_variant_id: product.product_variant_id
|
|
88
97
|
});
|
|
89
98
|
}
|
|
90
99
|
if (account) {
|
|
@@ -140,6 +149,14 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
140
149
|
tempCartItem = cartItem;
|
|
141
150
|
}
|
|
142
151
|
if (product) {
|
|
152
|
+
if (product.product_variant_id) {
|
|
153
|
+
const targetVariant = product.variant.find((n) => n.id === product.product_variant_id);
|
|
154
|
+
if (targetVariant) {
|
|
155
|
+
product.price = targetVariant.price;
|
|
156
|
+
product.original_price = targetVariant.original_price;
|
|
157
|
+
product.is_charge_tax = targetVariant.is_charge_tax;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
143
160
|
tempCartItem._productOrigin = (0, import_lodash_es.cloneDeep)(product);
|
|
144
161
|
tempCartItem._bundleOrigin = (0, import_lodash_es.cloneDeep)(bundle);
|
|
145
162
|
tempCartItem._optionsOrigin = (0, import_lodash_es.cloneDeep)(options);
|
|
@@ -147,7 +164,8 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
147
164
|
cartItem: tempCartItem,
|
|
148
165
|
product,
|
|
149
166
|
bundle,
|
|
150
|
-
options
|
|
167
|
+
options,
|
|
168
|
+
product_variant_id: product.product_variant_id
|
|
151
169
|
});
|
|
152
170
|
}
|
|
153
171
|
if (discounts) {
|
|
@@ -140,6 +140,8 @@ export interface CartItem {
|
|
|
140
140
|
_bundleOrigin?: any[];
|
|
141
141
|
/** 商品规格原始数据 */
|
|
142
142
|
_optionsOrigin?: any[];
|
|
143
|
+
/** 商品规格组合字符串,提供给 UI 展示的 */
|
|
144
|
+
product_option_string?: string;
|
|
143
145
|
}
|
|
144
146
|
/**
|
|
145
147
|
* 购物车状态接口
|
|
@@ -168,6 +170,8 @@ export interface IAddItemParams {
|
|
|
168
170
|
/** 结束时间 */
|
|
169
171
|
endTime: string;
|
|
170
172
|
};
|
|
173
|
+
/** 商品组合规格ID */
|
|
174
|
+
product_variant_id?: number;
|
|
171
175
|
}
|
|
172
176
|
/**
|
|
173
177
|
* 更新购物车信息参数
|
|
@@ -209,6 +213,8 @@ export interface IUpdateItemParams {
|
|
|
209
213
|
/** 关联表单记录ID */
|
|
210
214
|
form_record_ids: number[];
|
|
211
215
|
}[];
|
|
216
|
+
/** 商品组合规格ID */
|
|
217
|
+
product_variant_id?: number;
|
|
212
218
|
}
|
|
213
219
|
/**
|
|
214
220
|
* 折扣
|
|
@@ -40,12 +40,14 @@ export declare const formatProductToCartItem: (params: {
|
|
|
40
40
|
product: ProductData;
|
|
41
41
|
bundle?: any;
|
|
42
42
|
options?: any;
|
|
43
|
+
product_variant_id?: number;
|
|
43
44
|
}) => CartItem;
|
|
44
45
|
export declare const formatProductToCartItemOrigin: (params: {
|
|
45
46
|
cartItem: CartItem;
|
|
46
47
|
product: ProductData;
|
|
47
48
|
bundle?: any;
|
|
48
49
|
options?: any;
|
|
50
|
+
product_variant_id?: number;
|
|
49
51
|
}) => any;
|
|
50
52
|
/**
|
|
51
53
|
* 格式化折扣到购物车
|
|
@@ -109,8 +109,8 @@ var createCartItemOrigin = () => {
|
|
|
109
109
|
};
|
|
110
110
|
};
|
|
111
111
|
var formatProductToCartItem = (params) => {
|
|
112
|
-
var _a;
|
|
113
|
-
const { cartItem, product, bundle, options } = params;
|
|
112
|
+
var _a, _b;
|
|
113
|
+
const { cartItem, product, bundle, options, product_variant_id } = params;
|
|
114
114
|
const num = 1;
|
|
115
115
|
if (product) {
|
|
116
116
|
cartItem.id = product == null ? void 0 : product.id;
|
|
@@ -136,7 +136,24 @@ var formatProductToCartItem = (params) => {
|
|
|
136
136
|
if (options == null ? void 0 : options.length) {
|
|
137
137
|
cartItem.options = formatOptions(options);
|
|
138
138
|
}
|
|
139
|
-
if (
|
|
139
|
+
if (product_variant_id) {
|
|
140
|
+
const sku_key = (_a = product.variant.find((n) => n.id === product_variant_id)) == null ? void 0 : _a.sku_key;
|
|
141
|
+
if (sku_key) {
|
|
142
|
+
const sku_key_arr = sku_key.split("_");
|
|
143
|
+
const product_option_string = [];
|
|
144
|
+
sku_key_arr.forEach((item) => {
|
|
145
|
+
var _a2;
|
|
146
|
+
const keyMap = item.split(":");
|
|
147
|
+
const targetVariantGroup = product.variant_group.find((n) => String(n.position_id) === keyMap[0]);
|
|
148
|
+
const targetVariantItem = (_a2 = targetVariantGroup == null ? void 0 : targetVariantGroup.variant_item) == null ? void 0 : _a2.find((n) => String(n.position_id) === keyMap[1]);
|
|
149
|
+
if (targetVariantGroup && targetVariantItem) {
|
|
150
|
+
product_option_string.push(`${targetVariantGroup.name}:${targetVariantItem.name}`);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
cartItem.product_option_string = product_option_string.join(", ");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (((_b = product == null ? void 0 : product.custom_deposit_data) == null ? void 0 : _b.has_deposit) == 1) {
|
|
140
157
|
cartItem.deposit = getProductDeposit({
|
|
141
158
|
cartItem,
|
|
142
159
|
product,
|
|
@@ -151,14 +168,14 @@ var formatProductToCartItem = (params) => {
|
|
|
151
168
|
};
|
|
152
169
|
var formatProductToCartItemOrigin = (params) => {
|
|
153
170
|
var _a, _b, _c, _d;
|
|
154
|
-
const { cartItem, product, bundle, options } = params;
|
|
171
|
+
const { cartItem, product, bundle, options, product_variant_id } = params;
|
|
155
172
|
let origin = cartItem._origin;
|
|
156
173
|
if (product) {
|
|
157
174
|
origin.product = {
|
|
158
175
|
...origin.product || {},
|
|
159
176
|
num: 1,
|
|
160
177
|
product_id: product.id,
|
|
161
|
-
product_variant_id:
|
|
178
|
+
product_variant_id: product_variant_id || 0,
|
|
162
179
|
product_bundle: ((_a = origin.product) == null ? void 0 : _a.product_bundle) || [],
|
|
163
180
|
product_option_item: ((_b = origin.product) == null ? void 0 : _b.product_option_item) || []
|
|
164
181
|
};
|
|
@@ -187,6 +204,11 @@ var formatDiscountToCartItemOrigin = (params) => {
|
|
|
187
204
|
origin.product = {};
|
|
188
205
|
}
|
|
189
206
|
origin.product.discount_list = discounts;
|
|
207
|
+
} else {
|
|
208
|
+
if (!origin.product) {
|
|
209
|
+
origin.product = {};
|
|
210
|
+
}
|
|
211
|
+
origin.product.discount_list = [];
|
|
190
212
|
}
|
|
191
213
|
return origin;
|
|
192
214
|
};
|
|
@@ -10,7 +10,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
10
10
|
constructor(name?: string, version?: string);
|
|
11
11
|
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
12
12
|
createOrder(params: CommitOrderParams['query']): {
|
|
13
|
-
type:
|
|
13
|
+
type: "virtual" | "appointment_booking";
|
|
14
14
|
platform: string;
|
|
15
15
|
sales_channel: string;
|
|
16
16
|
order_sales_channel: string;
|
|
@@ -18,6 +18,8 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
18
18
|
shop_note: string;
|
|
19
19
|
schedule_date: string;
|
|
20
20
|
is_deposit: number;
|
|
21
|
+
relation_products: any[];
|
|
22
|
+
relation_forms: any[];
|
|
21
23
|
};
|
|
22
24
|
checkBeforeSubmitOrder(params: {
|
|
23
25
|
cartItems: CartItem[];
|
|
@@ -37,14 +37,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
37
37
|
}
|
|
38
38
|
createOrder(params) {
|
|
39
39
|
const order = {
|
|
40
|
-
type: "appointment_booking",
|
|
40
|
+
type: params.type || "appointment_booking",
|
|
41
|
+
// 要从外面拿,virtual
|
|
41
42
|
platform: "H5",
|
|
42
43
|
sales_channel: "my_pisel",
|
|
43
44
|
order_sales_channel: "online_store",
|
|
44
45
|
bookings: [],
|
|
45
46
|
shop_note: "",
|
|
46
47
|
schedule_date: "",
|
|
47
|
-
is_deposit: 0
|
|
48
|
+
is_deposit: 0,
|
|
49
|
+
relation_products: [],
|
|
50
|
+
relation_forms: []
|
|
48
51
|
};
|
|
49
52
|
let is_deposit = 0;
|
|
50
53
|
if (params.cartItems.length > 0) {
|
|
@@ -54,13 +57,22 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
54
57
|
item._origin.duration = duration;
|
|
55
58
|
item._origin.sub_type = durationType;
|
|
56
59
|
}
|
|
57
|
-
order.
|
|
60
|
+
if (order.type === "virtual") {
|
|
61
|
+
order.relation_products.push(item._origin.product);
|
|
62
|
+
const relationForms = item._origin.relation_forms || [];
|
|
63
|
+
order.relation_forms.push(...relationForms);
|
|
64
|
+
delete item._origin.relation_forms;
|
|
65
|
+
} else {
|
|
66
|
+
order.bookings.push(item._origin);
|
|
67
|
+
}
|
|
58
68
|
if (item == null ? void 0 : item.deposit) {
|
|
59
69
|
is_deposit = 1;
|
|
60
70
|
}
|
|
61
71
|
});
|
|
62
|
-
|
|
63
|
-
|
|
72
|
+
if (order.type === "appointment_booking") {
|
|
73
|
+
const firstCartItem = params.cartItems[0];
|
|
74
|
+
order.schedule_date = firstCartItem.start_date + " " + firstCartItem.start_time + ":00";
|
|
75
|
+
}
|
|
64
76
|
order.is_deposit = is_deposit;
|
|
65
77
|
}
|
|
66
78
|
return order;
|
|
@@ -167,7 +167,10 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
167
167
|
holder_id: string;
|
|
168
168
|
resources_code: string | number;
|
|
169
169
|
timeSlots?: TimeSliceItem;
|
|
170
|
-
countMap: Record<number,
|
|
170
|
+
countMap: Record<number, {
|
|
171
|
+
pax: number;
|
|
172
|
+
time: TimeSliceItem;
|
|
173
|
+
}[]>;
|
|
171
174
|
capacity?: number;
|
|
172
175
|
}): {
|
|
173
176
|
selectedResource: any;
|
|
@@ -209,4 +212,18 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
209
212
|
setOtherData(key: string, value: any): void;
|
|
210
213
|
getOtherData(key: string): any;
|
|
211
214
|
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
215
|
+
/**
|
|
216
|
+
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
217
|
+
*
|
|
218
|
+
* @param {string} cartItemId
|
|
219
|
+
* @param {string} resourceCode
|
|
220
|
+
* @return {*}
|
|
221
|
+
* @memberof BookingByStepImpl
|
|
222
|
+
*/
|
|
223
|
+
getResourcesByCartItemAndCode(cartItemId: string, resourceCode: string): any;
|
|
224
|
+
getAvailableDateForSession(params?: {
|
|
225
|
+
startDate?: string;
|
|
226
|
+
endDate?: string;
|
|
227
|
+
type?: 'month';
|
|
228
|
+
}): Promise<ITime[]>;
|
|
212
229
|
}
|
|
@@ -186,7 +186,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
186
186
|
"product_appointment",
|
|
187
187
|
"appointment_ticket",
|
|
188
188
|
"session_product",
|
|
189
|
-
"session_ticket"
|
|
189
|
+
"session_ticket",
|
|
190
|
+
"normal"
|
|
190
191
|
],
|
|
191
192
|
with: ["category", "collection", "resourceRelation"],
|
|
192
193
|
status: "published",
|
|
@@ -534,25 +535,28 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
534
535
|
const newCartItems = (0, import_lodash_es.cloneDeep)(cartItems);
|
|
535
536
|
newCartItems.forEach((item) => {
|
|
536
537
|
var _a, _b;
|
|
537
|
-
item._origin.resources
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
item._origin.metadata
|
|
538
|
+
if (item._origin.resources && item._origin.resources.length) {
|
|
539
|
+
item._origin.resources = item._origin.resources.map((n) => {
|
|
540
|
+
const newResourcesItem = (0, import_lodash_es.cloneDeep)(n);
|
|
541
|
+
delete newResourcesItem.id;
|
|
542
|
+
delete newResourcesItem.main_field;
|
|
543
|
+
delete newResourcesItem.resourceType;
|
|
544
|
+
return { ...newResourcesItem };
|
|
545
|
+
});
|
|
546
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
547
|
+
capacity: (_a = item._productOrigin) == null ? void 0 : _a.capacity,
|
|
548
|
+
product_bundle: item._origin.product.product_bundle
|
|
549
|
+
});
|
|
550
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
551
|
+
if (!((_b = item._origin) == null ? void 0 : _b.metadata)) {
|
|
552
|
+
item._origin.metadata = {};
|
|
553
|
+
}
|
|
554
|
+
item._origin.metadata.capacity = formatCapacity;
|
|
555
|
+
item._origin.number = currentCapacity;
|
|
551
556
|
}
|
|
552
|
-
item._origin.metadata.capacity = formatCapacity;
|
|
553
|
-
item._origin.number = currentCapacity;
|
|
554
557
|
});
|
|
555
|
-
|
|
558
|
+
const type = this.otherParams.isRetailTemplate ? "virtual" : "appointment_booking";
|
|
559
|
+
return this.store.order.submitOrder({ query: { cartItems: newCartItems, type } });
|
|
556
560
|
}
|
|
557
561
|
// 拉起支付模块
|
|
558
562
|
async pay() {
|
|
@@ -592,6 +596,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
592
596
|
});
|
|
593
597
|
}
|
|
594
598
|
this.store.cart.updateItem(params);
|
|
599
|
+
if (this.otherParams.isRetailTemplate) {
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
595
602
|
const allOriginResources = [];
|
|
596
603
|
const dateRange = this.store.date.getDateRange();
|
|
597
604
|
if (dateRange == null ? void 0 : dateRange.length) {
|
|
@@ -1134,20 +1141,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1134
1141
|
if (timeSlots) {
|
|
1135
1142
|
let targetResource = null;
|
|
1136
1143
|
for (const n of resources) {
|
|
1137
|
-
const recordCount = countMap[n.id] || 0;
|
|
1138
1144
|
const mTimes = n.times.filter((n2) => {
|
|
1139
1145
|
return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at));
|
|
1140
1146
|
});
|
|
1141
1147
|
if (mTimes.length === 0) {
|
|
1142
1148
|
continue;
|
|
1143
1149
|
}
|
|
1150
|
+
const totalCapacity = (countMap[n.id] || []).reduce((sum, item) => {
|
|
1151
|
+
const hasOverlap = !(0, import_dayjs.default)(item.time.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) && !(0, import_dayjs.default)(item.time.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at));
|
|
1152
|
+
return hasOverlap ? sum + item.pax : sum;
|
|
1153
|
+
}, 0);
|
|
1144
1154
|
const canUseTime = mTimes.find((item) => {
|
|
1145
1155
|
var _a2;
|
|
1146
1156
|
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
1147
1157
|
timeSlice: timeSlots,
|
|
1148
1158
|
time: item,
|
|
1149
1159
|
resource: n,
|
|
1150
|
-
currentCount:
|
|
1160
|
+
currentCount: totalCapacity + (capacity || 0),
|
|
1151
1161
|
resourcesUseableMap,
|
|
1152
1162
|
cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
|
|
1153
1163
|
});
|
|
@@ -1198,6 +1208,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1198
1208
|
}
|
|
1199
1209
|
const errorList = [];
|
|
1200
1210
|
const selectResourcesMap = {};
|
|
1211
|
+
const selectResourcesWithTimeSlots = {};
|
|
1201
1212
|
const accountList = this.store.accountList.getAccounts();
|
|
1202
1213
|
const selectForCartResources = (cartItems2) => {
|
|
1203
1214
|
let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
|
|
@@ -1218,7 +1229,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1218
1229
|
}
|
|
1219
1230
|
if (recordTimeSlots) {
|
|
1220
1231
|
const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find((n) => n.code === resources_code);
|
|
1221
|
-
|
|
1232
|
+
const resourceBookingType = (currentResourceConfig == null ? void 0 : currentResourceConfig.type) || "single";
|
|
1233
|
+
if (index !== 0 && recordTimeSlots && resourceBookingType === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration)) {
|
|
1222
1234
|
let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
|
|
1223
1235
|
((_g = (_f = item._productOrigin) == null ? void 0 : _f.duration) == null ? void 0 : _g.value) ?? 0,
|
|
1224
1236
|
((_i = (_h = item._productOrigin) == null ? void 0 : _h.duration) == null ? void 0 : _i.type) ?? "minutes"
|
|
@@ -1239,14 +1251,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1239
1251
|
holder_id: item.holder_id,
|
|
1240
1252
|
resources_code,
|
|
1241
1253
|
timeSlots: recordTimeSlots,
|
|
1242
|
-
countMap:
|
|
1254
|
+
countMap: selectResourcesWithTimeSlots,
|
|
1243
1255
|
capacity: currentCapacity
|
|
1244
1256
|
});
|
|
1245
1257
|
if (res == null ? void 0 : res.selectedResource) {
|
|
1246
|
-
if (!
|
|
1247
|
-
|
|
1258
|
+
if (!selectResourcesWithTimeSlots[res.selectedResource.id]) {
|
|
1259
|
+
selectResourcesWithTimeSlots[res.selectedResource.id] = [
|
|
1260
|
+
{
|
|
1261
|
+
pax: currentCapacity,
|
|
1262
|
+
time: recordTimeSlots
|
|
1263
|
+
}
|
|
1264
|
+
];
|
|
1248
1265
|
} else {
|
|
1249
|
-
|
|
1266
|
+
selectResourcesWithTimeSlots[res.selectedResource.id].push({
|
|
1267
|
+
pax: currentCapacity,
|
|
1268
|
+
time: recordTimeSlots
|
|
1269
|
+
});
|
|
1250
1270
|
}
|
|
1251
1271
|
res.selectedResource.capacity = currentCapacity;
|
|
1252
1272
|
(0, import_resources.checkSubResourcesCapacity)(res.selectedResource);
|
|
@@ -1692,6 +1712,158 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1692
1712
|
}
|
|
1693
1713
|
return "normal";
|
|
1694
1714
|
}
|
|
1715
|
+
/**
|
|
1716
|
+
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
1717
|
+
*
|
|
1718
|
+
* @param {string} cartItemId
|
|
1719
|
+
* @param {string} resourceCode
|
|
1720
|
+
* @return {*}
|
|
1721
|
+
* @memberof BookingByStepImpl
|
|
1722
|
+
*/
|
|
1723
|
+
getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
1724
|
+
var _a, _b, _c;
|
|
1725
|
+
const dateRange = this.store.date.getDateRange();
|
|
1726
|
+
const resources = [];
|
|
1727
|
+
if (dateRange == null ? void 0 : dateRange.length) {
|
|
1728
|
+
dateRange.forEach((n) => {
|
|
1729
|
+
if (n.resource)
|
|
1730
|
+
resources.push(...n.resource);
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
if (!resources.length) {
|
|
1734
|
+
const dateList = this.store.date.getDateList();
|
|
1735
|
+
dateList.forEach((n) => {
|
|
1736
|
+
if (n.resource)
|
|
1737
|
+
resources.push(...n.resource);
|
|
1738
|
+
});
|
|
1739
|
+
}
|
|
1740
|
+
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
1741
|
+
const cartItems = this.store.cart.getItems();
|
|
1742
|
+
const cartItem = cartItems.find((item) => item._id === cartItemId);
|
|
1743
|
+
if (!cartItem)
|
|
1744
|
+
return [];
|
|
1745
|
+
let selectedResources = [];
|
|
1746
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
1747
|
+
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
1748
|
+
product_bundle: cartItem._origin.product.product_bundle
|
|
1749
|
+
});
|
|
1750
|
+
cartItem._origin.metadata.capacity = formatCapacity;
|
|
1751
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
1752
|
+
if (cartItem.holder_id) {
|
|
1753
|
+
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1754
|
+
cartItems,
|
|
1755
|
+
cartItem.holder_id,
|
|
1756
|
+
resourcesMap
|
|
1757
|
+
);
|
|
1758
|
+
} else {
|
|
1759
|
+
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
1760
|
+
cartItems,
|
|
1761
|
+
cartItem._id,
|
|
1762
|
+
resourcesMap
|
|
1763
|
+
);
|
|
1764
|
+
}
|
|
1765
|
+
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
1766
|
+
resourcesMap,
|
|
1767
|
+
((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
1768
|
+
selectedResources,
|
|
1769
|
+
currentCapacity
|
|
1770
|
+
);
|
|
1771
|
+
const targetResource = productResources.find((resource) => resource.code === resourceCode);
|
|
1772
|
+
if (!targetResource)
|
|
1773
|
+
return [];
|
|
1774
|
+
if (cartItem._origin.start_time) {
|
|
1775
|
+
const startTime = (0, import_dayjs.default)(
|
|
1776
|
+
`${cartItem._origin.start_date} ${cartItem._origin.start_time}`
|
|
1777
|
+
);
|
|
1778
|
+
const endTime = (0, import_dayjs.default)(
|
|
1779
|
+
`${cartItem._origin.end_date} ${cartItem._origin.end_time}`
|
|
1780
|
+
);
|
|
1781
|
+
const resourcesUseableMap = {};
|
|
1782
|
+
targetResource.renderList = targetResource.renderList.sort((a, b) => {
|
|
1783
|
+
var _a2, _b2, _c2, _d;
|
|
1784
|
+
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
1785
|
+
const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
|
|
1786
|
+
if (aIsCombined && !bIsCombined)
|
|
1787
|
+
return 1;
|
|
1788
|
+
if (!aIsCombined && bIsCombined)
|
|
1789
|
+
return -1;
|
|
1790
|
+
return 0;
|
|
1791
|
+
});
|
|
1792
|
+
targetResource.renderList = targetResource.renderList.filter((m) => {
|
|
1793
|
+
const mTimes = m.times.filter((n) => {
|
|
1794
|
+
return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(startTime)) && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(endTime));
|
|
1795
|
+
});
|
|
1796
|
+
if (mTimes.length === 0)
|
|
1797
|
+
return false;
|
|
1798
|
+
const canUseArr = mTimes.map((item) => {
|
|
1799
|
+
var _a2;
|
|
1800
|
+
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
1801
|
+
timeSlice: {
|
|
1802
|
+
start_time: startTime.format("HH:mm"),
|
|
1803
|
+
end_time: endTime.format("HH:mm"),
|
|
1804
|
+
start_at: startTime,
|
|
1805
|
+
end_at: endTime
|
|
1806
|
+
},
|
|
1807
|
+
time: item,
|
|
1808
|
+
resource: m,
|
|
1809
|
+
currentCount: currentCapacity || 0,
|
|
1810
|
+
resourcesUseableMap,
|
|
1811
|
+
cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
|
|
1812
|
+
});
|
|
1813
|
+
if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
|
|
1814
|
+
resourcesUseableMap[m.id] = res.usable;
|
|
1815
|
+
}
|
|
1816
|
+
return res.usable;
|
|
1817
|
+
});
|
|
1818
|
+
if (m.onlyComputed)
|
|
1819
|
+
return false;
|
|
1820
|
+
return !canUseArr.some((n) => n === false);
|
|
1821
|
+
});
|
|
1822
|
+
} else {
|
|
1823
|
+
targetResource.renderList = targetResource.renderList.filter((n) => {
|
|
1824
|
+
var _a2, _b2;
|
|
1825
|
+
const recordCount = n.capacity || 0;
|
|
1826
|
+
if (n.onlyComputed)
|
|
1827
|
+
return false;
|
|
1828
|
+
const timeSlots = (0, import_resources.getTimeSlicesByResource)({
|
|
1829
|
+
resource: n,
|
|
1830
|
+
duration: ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 0,
|
|
1831
|
+
split: 10,
|
|
1832
|
+
currentDate: dateRange[0].date
|
|
1833
|
+
});
|
|
1834
|
+
return recordCount >= currentCapacity && timeSlots.length > 0;
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
return targetResource.renderList;
|
|
1838
|
+
}
|
|
1839
|
+
async getAvailableDateForSession(params = {}) {
|
|
1840
|
+
let { startDate, endDate, type } = params;
|
|
1841
|
+
if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
|
|
1842
|
+
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
1843
|
+
}
|
|
1844
|
+
endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
|
|
1845
|
+
let tempProducts = [];
|
|
1846
|
+
if (this.store.currentProduct) {
|
|
1847
|
+
tempProducts = [
|
|
1848
|
+
{
|
|
1849
|
+
...this.store.currentProduct.getData(),
|
|
1850
|
+
_schedule: this.store.currentProduct.getOtherParams()["schedule"]
|
|
1851
|
+
}
|
|
1852
|
+
];
|
|
1853
|
+
}
|
|
1854
|
+
const { resourceIds, rules, resourcesMap } = (0, import_products.getAvailableProductResources)(tempProducts) || {};
|
|
1855
|
+
this.otherParams.currentResourcesMap = resourcesMap;
|
|
1856
|
+
const res = await this.store.date.getResourceDates({
|
|
1857
|
+
query: {
|
|
1858
|
+
start_date: startDate || "",
|
|
1859
|
+
end_date: endDate || "",
|
|
1860
|
+
resource_ids: resourceIds
|
|
1861
|
+
},
|
|
1862
|
+
rules,
|
|
1863
|
+
type
|
|
1864
|
+
});
|
|
1865
|
+
return res;
|
|
1866
|
+
}
|
|
1695
1867
|
};
|
|
1696
1868
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1697
1869
|
0 && (module.exports = {
|