@pisell/pisellos 0.0.48 → 0.0.49
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/Order/index.js +8 -0
- package/dist/modules/Order/utils.d.ts +10 -0
- package/dist/modules/Order/utils.js +15 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +20 -8
- package/dist/solution/BookingByStep/utils/resources.d.ts +9 -0
- package/dist/solution/BookingByStep/utils/resources.js +54 -0
- package/lib/modules/Order/index.js +6 -0
- package/lib/modules/Order/utils.d.ts +10 -0
- package/lib/modules/Order/utils.js +45 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +37 -17
- package/lib/solution/BookingByStep/utils/resources.d.ts +9 -0
- package/lib/solution/BookingByStep/utils/resources.js +42 -0
- package/package.json +1 -1
|
@@ -16,6 +16,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
16
16
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
17
17
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
18
18
|
import { BaseModule } from "../BaseModule";
|
|
19
|
+
import { generateDuration } from "./utils";
|
|
19
20
|
export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
20
21
|
_inherits(OrderModule, _BaseModule);
|
|
21
22
|
var _super = _createSuper(OrderModule);
|
|
@@ -66,6 +67,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
66
67
|
var is_deposit = 0; // 是否存在定金,0 不存在,1 存在
|
|
67
68
|
if (params.cartItems.length > 0) {
|
|
68
69
|
params.cartItems.forEach(function (item) {
|
|
70
|
+
if (!item._origin.duration) {
|
|
71
|
+
var _generateDuration = generateDuration(item),
|
|
72
|
+
duration = _generateDuration.duration,
|
|
73
|
+
durationType = _generateDuration.durationType;
|
|
74
|
+
item._origin.duration = duration;
|
|
75
|
+
item._origin.sub_type = durationType;
|
|
76
|
+
}
|
|
69
77
|
order.bookings.push(item._origin);
|
|
70
78
|
if (item !== null && item !== void 0 && item.deposit) {
|
|
71
79
|
is_deposit = 1;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
/**
|
|
3
|
+
* 通过 session 类商品的开始时间结束时间生成商品的时长
|
|
4
|
+
* @param {CartItem} cartItem
|
|
5
|
+
* @return {*}
|
|
6
|
+
*/
|
|
7
|
+
export var generateDuration = function generateDuration(cartItem) {
|
|
8
|
+
var startDate = dayjs("".concat(cartItem.start_date, " ").concat(cartItem.start_time));
|
|
9
|
+
var endDate = dayjs("".concat(cartItem.end_date, " ").concat(cartItem.end_time));
|
|
10
|
+
var duration = endDate.diff(startDate, 'minutes');
|
|
11
|
+
return {
|
|
12
|
+
duration: duration,
|
|
13
|
+
durationType: 'minutes'
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -135,7 +135,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
135
135
|
_id: string;
|
|
136
136
|
product: ProductData | undefined;
|
|
137
137
|
resources: import("./utils/resources").ResourceItem[];
|
|
138
|
-
holder_id: string | number;
|
|
138
|
+
holder_id: string | number | undefined;
|
|
139
139
|
holder_name: string | undefined;
|
|
140
140
|
} | undefined;
|
|
141
141
|
getResourceTimeSlot({ product, resources, currentResourceId, }: {
|
|
@@ -27,7 +27,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
27
27
|
import { BaseModule } from "../../modules/BaseModule";
|
|
28
28
|
import { BookingByStepHooks, createModule } from "./types";
|
|
29
29
|
import { getAvailableProductResources } from "./utils/products";
|
|
30
|
-
import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, formatDefaultCapacitys, getSumCapacity, checkSubResourcesCapacity } from "./utils/resources";
|
|
30
|
+
import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, formatDefaultCapacitys, getSumCapacity, checkSubResourcesCapacity, getOthersCartSelectedResources } from "./utils/resources";
|
|
31
31
|
import dayjs from 'dayjs';
|
|
32
32
|
import { getResourcesMap } from "../../modules/Resource/utils";
|
|
33
33
|
import { cloneDeep } from 'lodash-es';
|
|
@@ -1089,7 +1089,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1089
1089
|
if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
|
|
1090
1090
|
});
|
|
1091
1091
|
}
|
|
1092
|
-
var resourcesMap = getResourcesMap(resources);
|
|
1092
|
+
var resourcesMap = getResourcesMap(cloneDeep(resources));
|
|
1093
1093
|
var cartItems = this.store.cart.getItems();
|
|
1094
1094
|
var arr = [];
|
|
1095
1095
|
var capacityMap = {};
|
|
@@ -1098,6 +1098,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1098
1098
|
var selectedResources = [];
|
|
1099
1099
|
if (cartItem.holder_id) {
|
|
1100
1100
|
selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
|
|
1101
|
+
} else {
|
|
1102
|
+
selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
|
|
1101
1103
|
}
|
|
1102
1104
|
var formatCapacity = formatDefaultCapacitys({
|
|
1103
1105
|
capacity: (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.capacity,
|
|
@@ -1157,15 +1159,21 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1157
1159
|
dateRange.forEach(function (n) {
|
|
1158
1160
|
if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
|
|
1159
1161
|
});
|
|
1160
|
-
|
|
1162
|
+
// 这里为什么要 cloneDeep:因为 getOthersSelectedResources 和 getOthersCartSelectedResources 会修改 resourcesMap 的 capacity
|
|
1163
|
+
// 用于确保后续分配的容量不会超出
|
|
1164
|
+
var resourcesMap = getResourcesMap(cloneDeep(resources));
|
|
1161
1165
|
var targetCartItem = cartItems.find(function (n) {
|
|
1162
1166
|
return n._id === id;
|
|
1163
1167
|
});
|
|
1164
1168
|
if (!targetCartItem) {
|
|
1165
1169
|
throw new Error("\u6CA1\u6709\u627E\u5230".concat(id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
|
|
1166
1170
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1171
|
+
var selectedResources = [];
|
|
1172
|
+
if (targetCartItem.holder_id) {
|
|
1173
|
+
selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap);
|
|
1174
|
+
} else {
|
|
1175
|
+
selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap);
|
|
1176
|
+
}
|
|
1169
1177
|
var formatCapacity = formatDefaultCapacitys({
|
|
1170
1178
|
capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
|
|
1171
1179
|
product_bundle: targetCartItem._origin.product.product_bundle
|
|
@@ -1392,7 +1400,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1392
1400
|
dateRange.forEach(function (n) {
|
|
1393
1401
|
if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
|
|
1394
1402
|
});
|
|
1395
|
-
var resourcesMap = getResourcesMap(resources);
|
|
1403
|
+
var resourcesMap = getResourcesMap(cloneDeep(resources));
|
|
1396
1404
|
// 一个账号一个账号处理
|
|
1397
1405
|
var errorList = [];
|
|
1398
1406
|
var selectResourcesMap = {};
|
|
@@ -1460,8 +1468,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1460
1468
|
// 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
|
|
1461
1469
|
var allCartItems = _this7.store.cart.getItems();
|
|
1462
1470
|
// 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
|
|
1463
|
-
|
|
1464
|
-
|
|
1471
|
+
var selectedResources = [];
|
|
1472
|
+
if (item.holder_id) {
|
|
1473
|
+
selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, resourcesMap);
|
|
1474
|
+
} else {
|
|
1475
|
+
selectedResources = getOthersCartSelectedResources(allCartItems, item._id, resourcesMap);
|
|
1476
|
+
}
|
|
1465
1477
|
var productResources = getResourcesByProduct(resourcesMap, ((_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.product_resource) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.resources) || [], selectedResources, currentCapacity);
|
|
1466
1478
|
// 自动选择 productResources 中对应 resources_code 的资源
|
|
1467
1479
|
var targetRenderList = (_productResources$fin = productResources.find(function (n) {
|
|
@@ -118,6 +118,15 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
|
|
|
118
118
|
* @Author: jinglin.tan
|
|
119
119
|
*/
|
|
120
120
|
export declare const getOthersSelectedResources: (cartItems: CartItem[], accountId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
|
|
121
|
+
/**
|
|
122
|
+
* @title: 获取其他购物车内商品的已选资源
|
|
123
|
+
* @description:
|
|
124
|
+
* @param {CartItem[]} cartItems
|
|
125
|
+
* @param {number | string} accountId
|
|
126
|
+
* @return {*}
|
|
127
|
+
* @Author: jinglin.tan
|
|
128
|
+
*/
|
|
129
|
+
export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
|
|
121
130
|
interface CapacityItem {
|
|
122
131
|
id: number;
|
|
123
132
|
value: number;
|
|
@@ -496,6 +496,57 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
|
|
|
496
496
|
return acc;
|
|
497
497
|
}
|
|
498
498
|
acc.push.apply(acc, _toConsumableArray(n.metadata.combined_resource.resource_ids));
|
|
499
|
+
n.metadata.combined_resource.resource_ids.forEach(function (m) {
|
|
500
|
+
resourcesMap[m].capacity -= n.num;
|
|
501
|
+
});
|
|
502
|
+
} else {
|
|
503
|
+
// 如果当前选中的不是组合资源,但是是别的组合资源里的子资源,则还需要把别的组合资源也加进来
|
|
504
|
+
// 去 resourcesMap 里找一下 n.id 是不是别的组合资源里的子资源,是的话把别的组合资源也加进来
|
|
505
|
+
Object.values(resourcesMap).forEach(function (m) {
|
|
506
|
+
if (m.combined_resource && m.combined_resource.status === 1) {
|
|
507
|
+
if (m.combined_resource.resource_ids.includes(n.id)) {
|
|
508
|
+
acc.push(m.id);
|
|
509
|
+
resourcesMap[m.id].capacity -= n.num;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
acc.push(n.id);
|
|
515
|
+
resourcesMap[n.id].capacity -= n.num;
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return acc;
|
|
520
|
+
}, []);
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* @title: 获取其他购物车内商品的已选资源
|
|
525
|
+
* @description:
|
|
526
|
+
* @param {CartItem[]} cartItems
|
|
527
|
+
* @param {number | string} accountId
|
|
528
|
+
* @return {*}
|
|
529
|
+
* @Author: jinglin.tan
|
|
530
|
+
*/
|
|
531
|
+
export var getOthersCartSelectedResources = function getOthersCartSelectedResources(cartItems, cartItemId, resourcesMap) {
|
|
532
|
+
return cartItems.reduce(function (acc, d) {
|
|
533
|
+
if (d._id !== cartItemId) {
|
|
534
|
+
var _d$_origin2;
|
|
535
|
+
if ((_d$_origin2 = d._origin) !== null && _d$_origin2 !== void 0 && _d$_origin2.resources) {
|
|
536
|
+
debugger;
|
|
537
|
+
d._origin.resources.forEach(function (n) {
|
|
538
|
+
// 如果是组合资源,还需要检查组合资源里子资源是否被占用过
|
|
539
|
+
if (n.metadata.combined_resource && n.metadata.combined_resource.status === 1) {
|
|
540
|
+
// 如果组合资源里子资源被占用过,则这个资源不可以进待选列表了
|
|
541
|
+
if (n.metadata.combined_resource.resource_ids.some(function (m) {
|
|
542
|
+
return acc.includes(m);
|
|
543
|
+
})) {
|
|
544
|
+
return acc;
|
|
545
|
+
}
|
|
546
|
+
acc.push.apply(acc, _toConsumableArray(n.metadata.combined_resource.resource_ids));
|
|
547
|
+
n.metadata.combined_resource.resource_ids.forEach(function (m) {
|
|
548
|
+
resourcesMap[m].capacity -= n.num;
|
|
549
|
+
});
|
|
499
550
|
} else {
|
|
500
551
|
// 如果当前选中的不是组合资源,但是是别的组合资源里的子资源,则还需要把别的组合资源也加进来
|
|
501
552
|
// 去 resourcesMap 里找一下 n.id 是不是别的组合资源里的子资源,是的话把别的组合资源也加进来
|
|
@@ -503,11 +554,14 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
|
|
|
503
554
|
if (m.combined_resource && m.combined_resource.status === 1) {
|
|
504
555
|
if (m.combined_resource.resource_ids.includes(n.id)) {
|
|
505
556
|
acc.push(m.id);
|
|
557
|
+
resourcesMap[m.id].capacity -= n.num;
|
|
506
558
|
}
|
|
507
559
|
}
|
|
508
560
|
});
|
|
509
561
|
}
|
|
510
562
|
acc.push(n.id);
|
|
563
|
+
// push 完以后,把 resourceMap 的 capacity 减掉当前的商品数量
|
|
564
|
+
resourcesMap[n.id].capacity -= n.num;
|
|
511
565
|
});
|
|
512
566
|
}
|
|
513
567
|
}
|
|
@@ -23,6 +23,7 @@ __export(Order_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(Order_exports);
|
|
25
25
|
var import_BaseModule = require("../BaseModule");
|
|
26
|
+
var import_utils = require("./utils");
|
|
26
27
|
var OrderModule = class extends import_BaseModule.BaseModule {
|
|
27
28
|
constructor(name, version) {
|
|
28
29
|
super(name, version);
|
|
@@ -48,6 +49,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
48
49
|
let is_deposit = 0;
|
|
49
50
|
if (params.cartItems.length > 0) {
|
|
50
51
|
params.cartItems.forEach((item) => {
|
|
52
|
+
if (!item._origin.duration) {
|
|
53
|
+
const { duration, durationType } = (0, import_utils.generateDuration)(item);
|
|
54
|
+
item._origin.duration = duration;
|
|
55
|
+
item._origin.sub_type = durationType;
|
|
56
|
+
}
|
|
51
57
|
order.bookings.push(item._origin);
|
|
52
58
|
if (item == null ? void 0 : item.deposit) {
|
|
53
59
|
is_deposit = 1;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/modules/Order/utils.ts
|
|
30
|
+
var utils_exports = {};
|
|
31
|
+
__export(utils_exports, {
|
|
32
|
+
generateDuration: () => generateDuration
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(utils_exports);
|
|
35
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
36
|
+
var generateDuration = (cartItem) => {
|
|
37
|
+
const startDate = (0, import_dayjs.default)(`${cartItem.start_date} ${cartItem.start_time}`);
|
|
38
|
+
const endDate = (0, import_dayjs.default)(`${cartItem.end_date} ${cartItem.end_time}`);
|
|
39
|
+
const duration = endDate.diff(startDate, "minutes");
|
|
40
|
+
return { duration, durationType: "minutes" };
|
|
41
|
+
};
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
generateDuration
|
|
45
|
+
});
|
|
@@ -135,7 +135,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
135
135
|
_id: string;
|
|
136
136
|
product: ProductData | undefined;
|
|
137
137
|
resources: import("./utils/resources").ResourceItem[];
|
|
138
|
-
holder_id: string | number;
|
|
138
|
+
holder_id: string | number | undefined;
|
|
139
139
|
holder_name: string | undefined;
|
|
140
140
|
} | undefined;
|
|
141
141
|
getResourceTimeSlot({ product, resources, currentResourceId, }: {
|
|
@@ -545,7 +545,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
545
545
|
resources.push(...n.resource);
|
|
546
546
|
});
|
|
547
547
|
}
|
|
548
|
-
const resourcesMap = (0, import_utils.getResourcesMap)(resources);
|
|
548
|
+
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
549
549
|
const cartItems = this.store.cart.getItems();
|
|
550
550
|
const arr = [];
|
|
551
551
|
const capacityMap = {};
|
|
@@ -558,6 +558,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
558
558
|
cartItem.holder_id,
|
|
559
559
|
resourcesMap
|
|
560
560
|
);
|
|
561
|
+
} else {
|
|
562
|
+
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
563
|
+
cartItems,
|
|
564
|
+
cartItem._id,
|
|
565
|
+
resourcesMap
|
|
566
|
+
);
|
|
561
567
|
}
|
|
562
568
|
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
563
569
|
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
@@ -621,18 +627,25 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
621
627
|
if (n.resource)
|
|
622
628
|
resources.push(...n.resource);
|
|
623
629
|
});
|
|
624
|
-
const resourcesMap = (0, import_utils.getResourcesMap)(resources);
|
|
630
|
+
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
625
631
|
const targetCartItem = cartItems.find((n) => n._id === id);
|
|
626
632
|
if (!targetCartItem) {
|
|
627
633
|
throw new Error(`没有找到${id}购物车商品`);
|
|
628
634
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
635
|
+
let selectedResources = [];
|
|
636
|
+
if (targetCartItem.holder_id) {
|
|
637
|
+
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
638
|
+
cartItems,
|
|
639
|
+
targetCartItem.holder_id,
|
|
640
|
+
resourcesMap
|
|
641
|
+
);
|
|
642
|
+
} else {
|
|
643
|
+
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
644
|
+
cartItems,
|
|
645
|
+
targetCartItem._id,
|
|
646
|
+
resourcesMap
|
|
647
|
+
);
|
|
648
|
+
}
|
|
636
649
|
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
637
650
|
capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
638
651
|
product_bundle: targetCartItem._origin.product.product_bundle
|
|
@@ -797,7 +810,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
797
810
|
if (n.resource)
|
|
798
811
|
resources.push(...n.resource);
|
|
799
812
|
});
|
|
800
|
-
const resourcesMap = (0, import_utils.getResourcesMap)(resources);
|
|
813
|
+
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
801
814
|
const errorList = [];
|
|
802
815
|
const selectResourcesMap = {};
|
|
803
816
|
this.store.accountList.getAccounts().forEach((account) => {
|
|
@@ -857,13 +870,20 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
857
870
|
}
|
|
858
871
|
} else {
|
|
859
872
|
const allCartItems = this.store.cart.getItems();
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
873
|
+
let selectedResources = [];
|
|
874
|
+
if (item.holder_id) {
|
|
875
|
+
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
876
|
+
allCartItems,
|
|
877
|
+
item.holder_id,
|
|
878
|
+
resourcesMap
|
|
879
|
+
);
|
|
880
|
+
} else {
|
|
881
|
+
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
882
|
+
allCartItems,
|
|
883
|
+
item._id,
|
|
884
|
+
resourcesMap
|
|
885
|
+
);
|
|
886
|
+
}
|
|
867
887
|
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
868
888
|
resourcesMap,
|
|
869
889
|
((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || [],
|
|
@@ -118,6 +118,15 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
|
|
|
118
118
|
* @Author: jinglin.tan
|
|
119
119
|
*/
|
|
120
120
|
export declare const getOthersSelectedResources: (cartItems: CartItem[], accountId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
|
|
121
|
+
/**
|
|
122
|
+
* @title: 获取其他购物车内商品的已选资源
|
|
123
|
+
* @description:
|
|
124
|
+
* @param {CartItem[]} cartItems
|
|
125
|
+
* @param {number | string} accountId
|
|
126
|
+
* @return {*}
|
|
127
|
+
* @Author: jinglin.tan
|
|
128
|
+
*/
|
|
129
|
+
export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
|
|
121
130
|
interface CapacityItem {
|
|
122
131
|
id: number;
|
|
123
132
|
value: number;
|
|
@@ -33,6 +33,7 @@ __export(resources_exports, {
|
|
|
33
33
|
formatDefaultCapacitys: () => formatDefaultCapacitys,
|
|
34
34
|
formatResources: () => formatResources,
|
|
35
35
|
getIsUsableByTimeItem: () => getIsUsableByTimeItem,
|
|
36
|
+
getOthersCartSelectedResources: () => getOthersCartSelectedResources,
|
|
36
37
|
getOthersSelectedResources: () => getOthersSelectedResources,
|
|
37
38
|
getResourcesByIds: () => getResourcesByIds,
|
|
38
39
|
getResourcesByProduct: () => getResourcesByProduct,
|
|
@@ -358,16 +359,56 @@ var getOthersSelectedResources = (cartItems, accountId, resourcesMap) => {
|
|
|
358
359
|
return acc;
|
|
359
360
|
}
|
|
360
361
|
acc.push(...n.metadata.combined_resource.resource_ids);
|
|
362
|
+
n.metadata.combined_resource.resource_ids.forEach((m) => {
|
|
363
|
+
resourcesMap[m].capacity -= n.num;
|
|
364
|
+
});
|
|
365
|
+
} else {
|
|
366
|
+
Object.values(resourcesMap).forEach((m) => {
|
|
367
|
+
if (m.combined_resource && m.combined_resource.status === 1) {
|
|
368
|
+
if (m.combined_resource.resource_ids.includes(n.id)) {
|
|
369
|
+
acc.push(m.id);
|
|
370
|
+
resourcesMap[m.id].capacity -= n.num;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
acc.push(n.id);
|
|
376
|
+
resourcesMap[n.id].capacity -= n.num;
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return acc;
|
|
381
|
+
}, []);
|
|
382
|
+
};
|
|
383
|
+
var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap) => {
|
|
384
|
+
return cartItems.reduce((acc, d) => {
|
|
385
|
+
var _a;
|
|
386
|
+
if (d._id !== cartItemId) {
|
|
387
|
+
if ((_a = d._origin) == null ? void 0 : _a.resources) {
|
|
388
|
+
debugger;
|
|
389
|
+
d._origin.resources.forEach((n) => {
|
|
390
|
+
if (n.metadata.combined_resource && n.metadata.combined_resource.status === 1) {
|
|
391
|
+
if (n.metadata.combined_resource.resource_ids.some(
|
|
392
|
+
(m) => acc.includes(m)
|
|
393
|
+
)) {
|
|
394
|
+
return acc;
|
|
395
|
+
}
|
|
396
|
+
acc.push(...n.metadata.combined_resource.resource_ids);
|
|
397
|
+
n.metadata.combined_resource.resource_ids.forEach((m) => {
|
|
398
|
+
resourcesMap[m].capacity -= n.num;
|
|
399
|
+
});
|
|
361
400
|
} else {
|
|
362
401
|
Object.values(resourcesMap).forEach((m) => {
|
|
363
402
|
if (m.combined_resource && m.combined_resource.status === 1) {
|
|
364
403
|
if (m.combined_resource.resource_ids.includes(n.id)) {
|
|
365
404
|
acc.push(m.id);
|
|
405
|
+
resourcesMap[m.id].capacity -= n.num;
|
|
366
406
|
}
|
|
367
407
|
}
|
|
368
408
|
});
|
|
369
409
|
}
|
|
370
410
|
acc.push(n.id);
|
|
411
|
+
resourcesMap[n.id].capacity -= n.num;
|
|
371
412
|
});
|
|
372
413
|
}
|
|
373
414
|
}
|
|
@@ -428,6 +469,7 @@ var checkSubResourcesCapacity = (resource) => {
|
|
|
428
469
|
formatDefaultCapacitys,
|
|
429
470
|
formatResources,
|
|
430
471
|
getIsUsableByTimeItem,
|
|
472
|
+
getOthersCartSelectedResources,
|
|
431
473
|
getOthersSelectedResources,
|
|
432
474
|
getResourcesByIds,
|
|
433
475
|
getResourcesByProduct,
|