@pisell/pisellos 0.0.328 → 0.0.330
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/Payment/index.js +56 -46
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.d.ts +9 -0
- package/dist/solution/BookingByStep/index.js +416 -19
- package/dist/solution/BookingByStep/utils/capacity.d.ts +2 -1
- package/dist/solution/BookingByStep/utils/capacity.js +7 -4
- package/dist/solution/Checkout/index.d.ts +46 -1
- package/dist/solution/Checkout/index.js +820 -503
- package/lib/modules/Payment/index.js +27 -40
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.d.ts +9 -0
- package/lib/solution/BookingByStep/index.js +276 -37
- package/lib/solution/BookingByStep/utils/capacity.d.ts +2 -1
- package/lib/solution/BookingByStep/utils/capacity.js +4 -4
- package/lib/solution/BookingTicket/index.js +6 -0
- package/lib/solution/Checkout/index.d.ts +46 -1
- package/lib/solution/Checkout/index.js +258 -63
- package/package.json +1 -1
|
@@ -30,6 +30,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
30
30
|
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); }
|
|
31
31
|
import { BaseModule } from "../../modules/BaseModule";
|
|
32
32
|
import { createModule } from "./types";
|
|
33
|
+
import { formatProductToCartItem, createCartItemOrigin, getUniqueId, handleVariantProduct } from "../../modules/Cart/utils";
|
|
33
34
|
import { getAvailableProductResources } from "./utils/products";
|
|
34
35
|
import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection, isConflict } from "./utils/resources";
|
|
35
36
|
import dayjs from 'dayjs';
|
|
@@ -3072,6 +3073,402 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3072
3073
|
minAvailableCount: minAvailableCount
|
|
3073
3074
|
};
|
|
3074
3075
|
}
|
|
3076
|
+
|
|
3077
|
+
/**
|
|
3078
|
+
* 将 ProductData 转换为 CartItem,但不添加到购物车
|
|
3079
|
+
* 参考 addProductToCart 方法的实现
|
|
3080
|
+
*/
|
|
3081
|
+
}, {
|
|
3082
|
+
key: "convertProductToCartItem",
|
|
3083
|
+
value: function convertProductToCartItem(product) {
|
|
3084
|
+
var _ref11 = product || {},
|
|
3085
|
+
bundle = _ref11.bundle,
|
|
3086
|
+
options = _ref11.options,
|
|
3087
|
+
origin = _ref11.origin,
|
|
3088
|
+
product_variant_id = _ref11.product_variant_id,
|
|
3089
|
+
_ref11$quantity = _ref11.quantity,
|
|
3090
|
+
quantity = _ref11$quantity === void 0 ? 1 : _ref11$quantity;
|
|
3091
|
+
|
|
3092
|
+
// 处理商品数据,类似 addProductToCart 中的逻辑
|
|
3093
|
+
var productData = _objectSpread(_objectSpread({}, origin), {}, {
|
|
3094
|
+
product_variant_id: product_variant_id
|
|
3095
|
+
});
|
|
3096
|
+
|
|
3097
|
+
// 处理组合商品
|
|
3098
|
+
var processedProduct = handleVariantProduct(productData);
|
|
3099
|
+
|
|
3100
|
+
// 创建基础的 CartItem
|
|
3101
|
+
var cartItem = {
|
|
3102
|
+
_id: getUniqueId('temp_'),
|
|
3103
|
+
_origin: createCartItemOrigin(),
|
|
3104
|
+
_productOrigin: processedProduct,
|
|
3105
|
+
_productInit: product
|
|
3106
|
+
};
|
|
3107
|
+
|
|
3108
|
+
// 获取当前活跃账户
|
|
3109
|
+
var activeAccount = this.getActiveAccount();
|
|
3110
|
+
|
|
3111
|
+
// 使用格式化函数填充 CartItem 数据
|
|
3112
|
+
formatProductToCartItem({
|
|
3113
|
+
cartItem: cartItem,
|
|
3114
|
+
product: processedProduct,
|
|
3115
|
+
bundle: bundle,
|
|
3116
|
+
options: options,
|
|
3117
|
+
product_variant_id: product_variant_id,
|
|
3118
|
+
quantity: quantity
|
|
3119
|
+
});
|
|
3120
|
+
return cartItem;
|
|
3121
|
+
}
|
|
3122
|
+
}, {
|
|
3123
|
+
key: "checkMaxDurationCapacityForDetailNums",
|
|
3124
|
+
value: function checkMaxDurationCapacityForDetailNums(currentProduct) {
|
|
3125
|
+
var _this16 = this;
|
|
3126
|
+
var cartItems = cloneDeep(this.store.cart.getItems());
|
|
3127
|
+
|
|
3128
|
+
// 将 ProductData 转换为 CartItem 但不真正添加到购物车
|
|
3129
|
+
var currentCartItem = this.convertProductToCartItem(currentProduct);
|
|
3130
|
+
cartItems.push(currentCartItem);
|
|
3131
|
+
if (cartItems.length === 0) return {
|
|
3132
|
+
success: true,
|
|
3133
|
+
minAvailableCount: 0
|
|
3134
|
+
};
|
|
3135
|
+
|
|
3136
|
+
// 将购物车商品分为有时间的和没有时间的
|
|
3137
|
+
var itemsWithTime = [];
|
|
3138
|
+
var itemsWithoutTime = [];
|
|
3139
|
+
// 记录每种资源类型的可用数量
|
|
3140
|
+
var availableCountsByResourceType = [];
|
|
3141
|
+
cartItems.forEach(function (cartItem) {
|
|
3142
|
+
if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
|
|
3143
|
+
itemsWithTime.push(cartItem);
|
|
3144
|
+
} else {
|
|
3145
|
+
itemsWithoutTime.push(cartItem);
|
|
3146
|
+
}
|
|
3147
|
+
});
|
|
3148
|
+
|
|
3149
|
+
// 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
|
|
3150
|
+
var processedItemsWithoutTime = [];
|
|
3151
|
+
if (itemsWithoutTime.length > 0) {
|
|
3152
|
+
// 按资源类型分组处理没有时间的商品
|
|
3153
|
+
var itemsByResourceType = {};
|
|
3154
|
+
itemsWithoutTime.forEach(function (cartItem) {
|
|
3155
|
+
var _cartItem$_productOri13;
|
|
3156
|
+
if (!cartItem._productOrigin) return;
|
|
3157
|
+
var resourceTypes = ((_cartItem$_productOri13 = cartItem._productOrigin.product_resource) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.resources) || [];
|
|
3158
|
+
resourceTypes.forEach(function (resourceType) {
|
|
3159
|
+
if (resourceType.status === 1) {
|
|
3160
|
+
var _resourceType$id2;
|
|
3161
|
+
var resourceCode = resourceType.code || ((_resourceType$id2 = resourceType.id) === null || _resourceType$id2 === void 0 ? void 0 : _resourceType$id2.toString());
|
|
3162
|
+
if (!itemsByResourceType[resourceCode]) {
|
|
3163
|
+
itemsByResourceType[resourceCode] = [];
|
|
3164
|
+
}
|
|
3165
|
+
// 避免重复添加同一个商品
|
|
3166
|
+
if (!itemsByResourceType[resourceCode].find(function (item) {
|
|
3167
|
+
return item._id === cartItem._id;
|
|
3168
|
+
})) {
|
|
3169
|
+
itemsByResourceType[resourceCode].push(cartItem);
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
});
|
|
3173
|
+
});
|
|
3174
|
+
|
|
3175
|
+
// 为每种资源类型检查容量
|
|
3176
|
+
var dateRange = this.store.date.getDateRange();
|
|
3177
|
+
if (!dateRange || dateRange.length === 0) return {
|
|
3178
|
+
success: false,
|
|
3179
|
+
minAvailableCount: 0
|
|
3180
|
+
};
|
|
3181
|
+
var resourcesDates = this.store.date.getDateList();
|
|
3182
|
+
var targetResourceDate = resourcesDates.find(function (n) {
|
|
3183
|
+
return n.date === dateRange[0].date;
|
|
3184
|
+
});
|
|
3185
|
+
if (!targetResourceDate) return {
|
|
3186
|
+
success: false,
|
|
3187
|
+
minAvailableCount: 0
|
|
3188
|
+
};
|
|
3189
|
+
var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
|
|
3190
|
+
|
|
3191
|
+
// 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
|
|
3192
|
+
var resourceCodeToFormIdMap = {};
|
|
3193
|
+
|
|
3194
|
+
// 遍历购物车中的商品,收集所有资源类型配置
|
|
3195
|
+
Object.values(itemsByResourceType).flat().forEach(function (cartItem) {
|
|
3196
|
+
var _cartItem$_productOri14;
|
|
3197
|
+
if ((_cartItem$_productOri14 = cartItem._productOrigin) !== null && _cartItem$_productOri14 !== void 0 && (_cartItem$_productOri14 = _cartItem$_productOri14.product_resource) !== null && _cartItem$_productOri14 !== void 0 && _cartItem$_productOri14.resources) {
|
|
3198
|
+
cartItem._productOrigin.product_resource.resources.forEach(function (resourceConfig) {
|
|
3199
|
+
// 只处理启用的资源类型 (status === 1)
|
|
3200
|
+
if (resourceConfig.status === 1 && resourceConfig.code) {
|
|
3201
|
+
var _resourceConfig$id2, _resourceConfig$resou2;
|
|
3202
|
+
var formId = ((_resourceConfig$id2 = resourceConfig.id) === null || _resourceConfig$id2 === void 0 ? void 0 : _resourceConfig$id2.toString()) || ((_resourceConfig$resou2 = resourceConfig.resource_type_id) === null || _resourceConfig$resou2 === void 0 ? void 0 : _resourceConfig$resou2.toString());
|
|
3203
|
+
if (formId) {
|
|
3204
|
+
resourceCodeToFormIdMap[resourceConfig.code] = formId;
|
|
3205
|
+
}
|
|
3206
|
+
}
|
|
3207
|
+
});
|
|
3208
|
+
}
|
|
3209
|
+
});
|
|
3210
|
+
var hasCapacityIssue = false;
|
|
3211
|
+
var resourceCapacityInfo = [];
|
|
3212
|
+
|
|
3213
|
+
// 用于跟踪已处理的商品,避免重复添加
|
|
3214
|
+
var processedCartItemIds = new Set();
|
|
3215
|
+
|
|
3216
|
+
// 先检查所有资源类型,收集可用数量信息
|
|
3217
|
+
var _loop5 = function _loop5() {
|
|
3218
|
+
var _resourceTypeConfig2;
|
|
3219
|
+
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
3220
|
+
resourceCode = _Object$entries3$_i[0],
|
|
3221
|
+
items = _Object$entries3$_i[1];
|
|
3222
|
+
// 获取该资源类型对应的 form_id
|
|
3223
|
+
var targetFormId = resourceCodeToFormIdMap[resourceCode];
|
|
3224
|
+
if (!targetFormId) {
|
|
3225
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u627E\u4E0D\u5230\u5BF9\u5E94\u7684 form_id"));
|
|
3226
|
+
return {
|
|
3227
|
+
v: {
|
|
3228
|
+
success: false,
|
|
3229
|
+
minAvailableCount: 0
|
|
3230
|
+
}
|
|
3231
|
+
};
|
|
3232
|
+
}
|
|
3233
|
+
|
|
3234
|
+
// 获取该资源类型的所有资源
|
|
3235
|
+
var resourcesOfThisType = [];
|
|
3236
|
+
items.forEach(function (cartItem) {
|
|
3237
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
3238
|
+
productResourceIds.forEach(function (resourceId) {
|
|
3239
|
+
var _resource$form_id2;
|
|
3240
|
+
var resource = resourcesMap[resourceId];
|
|
3241
|
+
if (resource && ((_resource$form_id2 = resource.form_id) === null || _resource$form_id2 === void 0 ? void 0 : _resource$form_id2.toString()) === targetFormId) {
|
|
3242
|
+
// 避免重复添加同一个资源
|
|
3243
|
+
if (!resourcesOfThisType.find(function (r) {
|
|
3244
|
+
return r.id === resource.id;
|
|
3245
|
+
})) {
|
|
3246
|
+
resourcesOfThisType.push(resource);
|
|
3247
|
+
}
|
|
3248
|
+
}
|
|
3249
|
+
});
|
|
3250
|
+
});
|
|
3251
|
+
if (resourcesOfThisType.length === 0) {
|
|
3252
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u627E\u5230\u53EF\u7528\u8D44\u6E90"));
|
|
3253
|
+
return {
|
|
3254
|
+
v: {
|
|
3255
|
+
success: false,
|
|
3256
|
+
minAvailableCount: 0
|
|
3257
|
+
}
|
|
3258
|
+
};
|
|
3259
|
+
}
|
|
3260
|
+
|
|
3261
|
+
// 检查资源类型(单个预约 vs 多个预约)
|
|
3262
|
+
// 从商品配置中获取资源类型信息
|
|
3263
|
+
var resourceTypeConfig = null;
|
|
3264
|
+
var _iterator4 = _createForOfIteratorHelper(items),
|
|
3265
|
+
_step4;
|
|
3266
|
+
try {
|
|
3267
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
3268
|
+
var _cartItem$_productOri15;
|
|
3269
|
+
var cartItem = _step4.value;
|
|
3270
|
+
if ((_cartItem$_productOri15 = cartItem._productOrigin) !== null && _cartItem$_productOri15 !== void 0 && (_cartItem$_productOri15 = _cartItem$_productOri15.product_resource) !== null && _cartItem$_productOri15 !== void 0 && _cartItem$_productOri15.resources) {
|
|
3271
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
|
|
3272
|
+
return r.code === resourceCode && r.status === 1;
|
|
3273
|
+
});
|
|
3274
|
+
if (resourceTypeConfig) break;
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
} catch (err) {
|
|
3278
|
+
_iterator4.e(err);
|
|
3279
|
+
} finally {
|
|
3280
|
+
_iterator4.f();
|
|
3281
|
+
}
|
|
3282
|
+
var isMultipleBooking = ((_resourceTypeConfig2 = resourceTypeConfig) === null || _resourceTypeConfig2 === void 0 ? void 0 : _resourceTypeConfig2.type) === 'multiple';
|
|
3283
|
+
var totalAvailable;
|
|
3284
|
+
var requiredAmount;
|
|
3285
|
+
var availableAmount;
|
|
3286
|
+
if (isMultipleBooking) {
|
|
3287
|
+
// 多个预约:计算容量
|
|
3288
|
+
totalAvailable = resourcesOfThisType.reduce(function (sum, resource) {
|
|
3289
|
+
return sum + (resource.capacity || 0);
|
|
3290
|
+
}, 0);
|
|
3291
|
+
requiredAmount = items.reduce(function (sum, cartItem) {
|
|
3292
|
+
var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
|
|
3293
|
+
currentCapacity = _getCapacityInfoByCar8.currentCapacity;
|
|
3294
|
+
return sum + currentCapacity;
|
|
3295
|
+
}, 0);
|
|
3296
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
3297
|
+
} else {
|
|
3298
|
+
// 单个预约:计算资源个数
|
|
3299
|
+
totalAvailable = resourcesOfThisType.length;
|
|
3300
|
+
requiredAmount = items.reduce(function (sum, cartItem) {
|
|
3301
|
+
return sum + (cartItem.num || 1);
|
|
3302
|
+
}, 0);
|
|
3303
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
3304
|
+
}
|
|
3305
|
+
|
|
3306
|
+
// 记录资源容量信息
|
|
3307
|
+
resourceCapacityInfo.push({
|
|
3308
|
+
code: resourceCode,
|
|
3309
|
+
available: availableAmount,
|
|
3310
|
+
total: totalAvailable,
|
|
3311
|
+
required: requiredAmount,
|
|
3312
|
+
isMultiple: isMultipleBooking
|
|
3313
|
+
});
|
|
3314
|
+
availableCountsByResourceType.push(availableAmount);
|
|
3315
|
+
|
|
3316
|
+
// 检查是否有容量问题
|
|
3317
|
+
if (requiredAmount > totalAvailable) {
|
|
3318
|
+
hasCapacityIssue = true;
|
|
3319
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " ").concat(isMultipleBooking ? '容量' : '资源数量', "\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredAmount, ", \u603B\u5171 ").concat(totalAvailable));
|
|
3320
|
+
}
|
|
3321
|
+
|
|
3322
|
+
// 为通过检测的商品分配一个公共可用时间段
|
|
3323
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u8D44\u6E90\u65F6\u95F4\u4FE1\u606F:"), resourcesOfThisType.map(function (r) {
|
|
3324
|
+
return {
|
|
3325
|
+
id: r.id,
|
|
3326
|
+
times: r.times.map(function (t) {
|
|
3327
|
+
return "".concat(t.start_at, " - ").concat(t.end_at);
|
|
3328
|
+
})
|
|
3329
|
+
};
|
|
3330
|
+
}));
|
|
3331
|
+
|
|
3332
|
+
// 找到所有资源都可用的时间段
|
|
3333
|
+
var commonTimeSlots = _this16.findCommonAvailableTimeSlots(resourcesOfThisType);
|
|
3334
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
|
|
3335
|
+
if (commonTimeSlots.length === 0) {
|
|
3336
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
|
|
3337
|
+
return {
|
|
3338
|
+
v: {
|
|
3339
|
+
success: false,
|
|
3340
|
+
minAvailableCount: 0
|
|
3341
|
+
}
|
|
3342
|
+
};
|
|
3343
|
+
}
|
|
3344
|
+
|
|
3345
|
+
// 使用第一个公共可用时间段,但只处理未处理过的商品
|
|
3346
|
+
var firstCommonSlot = commonTimeSlots[0];
|
|
3347
|
+
console.log("\u4F7F\u7528\u516C\u5171\u65F6\u95F4\u6BB5: ".concat(firstCommonSlot.startTime, " - ").concat(firstCommonSlot.endTime));
|
|
3348
|
+
items.forEach(function (cartItem) {
|
|
3349
|
+
// 只处理未处理过的商品,避免重复添加
|
|
3350
|
+
if (!processedCartItemIds.has(cartItem._id)) {
|
|
3351
|
+
processedCartItemIds.add(cartItem._id);
|
|
3352
|
+
var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
|
|
3353
|
+
start_date: dateRange[0].date,
|
|
3354
|
+
start_time: firstCommonSlot.startTime,
|
|
3355
|
+
end_time: firstCommonSlot.endTime,
|
|
3356
|
+
end_date: dateRange[0].date
|
|
3357
|
+
});
|
|
3358
|
+
processedItemsWithoutTime.push(processedItem);
|
|
3359
|
+
}
|
|
3360
|
+
});
|
|
3361
|
+
},
|
|
3362
|
+
_ret5;
|
|
3363
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries(itemsByResourceType); _i3 < _Object$entries3.length; _i3++) {
|
|
3364
|
+
_ret5 = _loop5();
|
|
3365
|
+
if (_ret5) return _ret5.v;
|
|
3366
|
+
}
|
|
3367
|
+
|
|
3368
|
+
// 如果有容量问题,找出限制最严格的资源类型,返回其总容量
|
|
3369
|
+
if (hasCapacityIssue) {
|
|
3370
|
+
// 找出超出容量的资源类型中,总容量最少的那个
|
|
3371
|
+
var overCapacityResources = resourceCapacityInfo.filter(function (info) {
|
|
3372
|
+
return info.required > info.total;
|
|
3373
|
+
});
|
|
3374
|
+
if (overCapacityResources.length > 0) {
|
|
3375
|
+
var _minTotalCapacity2 = Math.min.apply(Math, _toConsumableArray(overCapacityResources.map(function (info) {
|
|
3376
|
+
return info.total;
|
|
3377
|
+
})));
|
|
3378
|
+
return {
|
|
3379
|
+
success: false,
|
|
3380
|
+
minAvailableCount: _minTotalCapacity2
|
|
3381
|
+
};
|
|
3382
|
+
}
|
|
3383
|
+
// 如果没有超出容量的(理论上不应该发生),返回总容量最少的
|
|
3384
|
+
var minTotalCapacity = Math.min.apply(Math, _toConsumableArray(resourceCapacityInfo.map(function (info) {
|
|
3385
|
+
return info.total;
|
|
3386
|
+
})));
|
|
3387
|
+
return {
|
|
3388
|
+
success: false,
|
|
3389
|
+
minAvailableCount: minTotalCapacity
|
|
3390
|
+
};
|
|
3391
|
+
}
|
|
3392
|
+
}
|
|
3393
|
+
|
|
3394
|
+
// 合并所有商品(有时间的 + 处理后的没有时间的)
|
|
3395
|
+
var allProcessedItems = [].concat(itemsWithTime, processedItemsWithoutTime);
|
|
3396
|
+
|
|
3397
|
+
// 按时间段分组检查
|
|
3398
|
+
var cartItemsByTimeSlot = {};
|
|
3399
|
+
allProcessedItems.forEach(function (cartItem) {
|
|
3400
|
+
if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
|
|
3401
|
+
var timeSlotKey = "".concat(cartItem.start_date, "_").concat(cartItem.start_time, "_").concat(cartItem.end_date || cartItem.start_date, "_").concat(cartItem.end_time);
|
|
3402
|
+
if (!cartItemsByTimeSlot[timeSlotKey]) {
|
|
3403
|
+
cartItemsByTimeSlot[timeSlotKey] = [];
|
|
3404
|
+
}
|
|
3405
|
+
cartItemsByTimeSlot[timeSlotKey].push(cartItem);
|
|
3406
|
+
});
|
|
3407
|
+
// 检查每个时间段是否有足够的资源容量
|
|
3408
|
+
var _loop6 = function _loop6() {
|
|
3409
|
+
var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
|
|
3410
|
+
timeSlotKey = _Object$entries4$_i[0],
|
|
3411
|
+
itemsInTimeSlot = _Object$entries4$_i[1];
|
|
3412
|
+
var _timeSlotKey$split3 = timeSlotKey.split('_'),
|
|
3413
|
+
_timeSlotKey$split4 = _slicedToArray(_timeSlotKey$split3, 4),
|
|
3414
|
+
startDate = _timeSlotKey$split4[0],
|
|
3415
|
+
startTime = _timeSlotKey$split4[1],
|
|
3416
|
+
endDate = _timeSlotKey$split4[2],
|
|
3417
|
+
endTime = _timeSlotKey$split4[3];
|
|
3418
|
+
var timeSlotStart = "".concat(startDate, " ").concat(startTime);
|
|
3419
|
+
var timeSlotEnd = "".concat(endDate, " ").concat(endTime);
|
|
3420
|
+
|
|
3421
|
+
// 获取这个时间段所有商品涉及的资源
|
|
3422
|
+
var allResourcesForTimeSlot = [];
|
|
3423
|
+
var resourcesIdSet = new Set();
|
|
3424
|
+
|
|
3425
|
+
// 获取资源数据
|
|
3426
|
+
var dateRange = _this16.store.date.getDateRange();
|
|
3427
|
+
var resourcesDates = _this16.store.date.getDateList();
|
|
3428
|
+
var targetResourceDate = resourcesDates.find(function (n) {
|
|
3429
|
+
return n.date === startDate;
|
|
3430
|
+
});
|
|
3431
|
+
if (!targetResourceDate) return 0; // continue
|
|
3432
|
+
var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
|
|
3433
|
+
itemsInTimeSlot.forEach(function (cartItem) {
|
|
3434
|
+
if (!cartItem._productOrigin) return;
|
|
3435
|
+
|
|
3436
|
+
// 获取商品的资源配置
|
|
3437
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
3438
|
+
productResourceIds.forEach(function (resourceId) {
|
|
3439
|
+
if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
|
|
3440
|
+
resourcesIdSet.add(resourceId);
|
|
3441
|
+
allResourcesForTimeSlot.push(resourcesMap[resourceId]);
|
|
3442
|
+
}
|
|
3443
|
+
});
|
|
3444
|
+
});
|
|
3445
|
+
|
|
3446
|
+
// 按资源类型分组检查容量
|
|
3447
|
+
if (!checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
|
|
3448
|
+
// 如果有可用数量记录,返回最小值;否则返回 0
|
|
3449
|
+
var _minAvailableCount2 = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
|
|
3450
|
+
return {
|
|
3451
|
+
v: {
|
|
3452
|
+
success: false,
|
|
3453
|
+
minAvailableCount: _minAvailableCount2
|
|
3454
|
+
}
|
|
3455
|
+
};
|
|
3456
|
+
}
|
|
3457
|
+
},
|
|
3458
|
+
_ret6;
|
|
3459
|
+
for (var _i4 = 0, _Object$entries4 = Object.entries(cartItemsByTimeSlot); _i4 < _Object$entries4.length; _i4++) {
|
|
3460
|
+
_ret6 = _loop6();
|
|
3461
|
+
if (_ret6 === 0) continue;
|
|
3462
|
+
if (_ret6) return _ret6.v;
|
|
3463
|
+
}
|
|
3464
|
+
|
|
3465
|
+
// 全部通过检测,返回成功和最小可用数量
|
|
3466
|
+
var minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
|
|
3467
|
+
return {
|
|
3468
|
+
success: true,
|
|
3469
|
+
minAvailableCount: minAvailableCount
|
|
3470
|
+
};
|
|
3471
|
+
}
|
|
3075
3472
|
}, {
|
|
3076
3473
|
key: "setOtherData",
|
|
3077
3474
|
value: function setOtherData(key, value) {
|
|
@@ -3143,7 +3540,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3143
3540
|
}, {
|
|
3144
3541
|
key: "getResourcesByCartItemAndCode",
|
|
3145
3542
|
value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
3146
|
-
var _cartItem$
|
|
3543
|
+
var _cartItem$_productOri16;
|
|
3147
3544
|
var dateRange = this.store.date.getDateRange();
|
|
3148
3545
|
var resources = [];
|
|
3149
3546
|
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
@@ -3166,16 +3563,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3166
3563
|
});
|
|
3167
3564
|
if (!cartItem) return [];
|
|
3168
3565
|
var selectedResources = [];
|
|
3169
|
-
var
|
|
3170
|
-
currentCapacity =
|
|
3171
|
-
formatCapacity =
|
|
3566
|
+
var _getCapacityInfoByCar9 = getCapacityInfoByCartItem(cartItem),
|
|
3567
|
+
currentCapacity = _getCapacityInfoByCar9.currentCapacity,
|
|
3568
|
+
formatCapacity = _getCapacityInfoByCar9.formatCapacity;
|
|
3172
3569
|
cartItem._origin.metadata.capacity = formatCapacity;
|
|
3173
3570
|
if (cartItem.holder_id) {
|
|
3174
3571
|
selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
|
|
3175
3572
|
} else {
|
|
3176
3573
|
selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
|
|
3177
3574
|
}
|
|
3178
|
-
var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$
|
|
3575
|
+
var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri16 = cartItem._productOrigin) === null || _cartItem$_productOri16 === void 0 || (_cartItem$_productOri16 = _cartItem$_productOri16.product_resource) === null || _cartItem$_productOri16 === void 0 ? void 0 : _cartItem$_productOri16.resources) || [], selectedResources, currentCapacity);
|
|
3179
3576
|
var targetResource = productResources.find(function (resource) {
|
|
3180
3577
|
return resource.code === resourceCode;
|
|
3181
3578
|
});
|
|
@@ -3198,7 +3595,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3198
3595
|
});
|
|
3199
3596
|
if (mTimes.length === 0) return false;
|
|
3200
3597
|
var canUseArr = mTimes.map(function (item) {
|
|
3201
|
-
var _cartItem$
|
|
3598
|
+
var _cartItem$_productOri17;
|
|
3202
3599
|
var res = getIsUsableByTimeItem({
|
|
3203
3600
|
timeSlice: {
|
|
3204
3601
|
start_time: startTime.format('HH:mm'),
|
|
@@ -3210,7 +3607,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3210
3607
|
resource: m,
|
|
3211
3608
|
currentCount: currentCapacity || 0,
|
|
3212
3609
|
resourcesUseableMap: resourcesUseableMap,
|
|
3213
|
-
cut_off_time: (_cartItem$
|
|
3610
|
+
cut_off_time: (_cartItem$_productOri17 = cartItem._productOrigin) === null || _cartItem$_productOri17 === void 0 ? void 0 : _cartItem$_productOri17.cut_off_time
|
|
3214
3611
|
});
|
|
3215
3612
|
if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
|
|
3216
3613
|
resourcesUseableMap[m.id] = res.usable;
|
|
@@ -3224,12 +3621,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3224
3621
|
});
|
|
3225
3622
|
} else {
|
|
3226
3623
|
targetResource.renderList = targetResource.renderList.filter(function (n) {
|
|
3227
|
-
var _cartItem$
|
|
3624
|
+
var _cartItem$_productOri18;
|
|
3228
3625
|
var recordCount = n.capacity || 0;
|
|
3229
3626
|
if (n.onlyComputed) return false;
|
|
3230
3627
|
var timeSlots = getTimeSlicesByResource({
|
|
3231
3628
|
resource: n,
|
|
3232
|
-
duration: ((_cartItem$
|
|
3629
|
+
duration: ((_cartItem$_productOri18 = cartItem._productOrigin) === null || _cartItem$_productOri18 === void 0 || (_cartItem$_productOri18 = _cartItem$_productOri18.duration) === null || _cartItem$_productOri18 === void 0 ? void 0 : _cartItem$_productOri18.value) || 10,
|
|
3233
3630
|
split: 10,
|
|
3234
3631
|
currentDate: dateRange[0].date
|
|
3235
3632
|
});
|
|
@@ -3247,12 +3644,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3247
3644
|
}, {
|
|
3248
3645
|
key: "getTimeslotsScheduleByDateRange",
|
|
3249
3646
|
value: (function () {
|
|
3250
|
-
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(
|
|
3251
|
-
var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results,
|
|
3647
|
+
var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref12) {
|
|
3648
|
+
var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i5, _dates, date;
|
|
3252
3649
|
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
3253
3650
|
while (1) switch (_context26.prev = _context26.next) {
|
|
3254
3651
|
case 0:
|
|
3255
|
-
startDate =
|
|
3652
|
+
startDate = _ref12.startDate, endDate = _ref12.endDate, scheduleIds = _ref12.scheduleIds, resources = _ref12.resources;
|
|
3256
3653
|
console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
|
|
3257
3654
|
startDate: startDate,
|
|
3258
3655
|
endDate: endDate,
|
|
@@ -3269,8 +3666,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3269
3666
|
}
|
|
3270
3667
|
// 如果不支持 Web Worker,使用同步方式处理
|
|
3271
3668
|
results = {};
|
|
3272
|
-
for (
|
|
3273
|
-
date = _dates[
|
|
3669
|
+
for (_i5 = 0, _dates = dates; _i5 < _dates.length; _i5++) {
|
|
3670
|
+
date = _dates[_i5];
|
|
3274
3671
|
results[date] = this.getTimeslotBySchedule({
|
|
3275
3672
|
date: date,
|
|
3276
3673
|
scheduleIds: scheduleIds,
|
|
@@ -3311,7 +3708,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3311
3708
|
openResources,
|
|
3312
3709
|
allProductResources,
|
|
3313
3710
|
targetSchedules,
|
|
3314
|
-
|
|
3711
|
+
_loop7,
|
|
3315
3712
|
_args28 = arguments;
|
|
3316
3713
|
return _regeneratorRuntime().wrap(function _callee27$(_context28) {
|
|
3317
3714
|
while (1) switch (_context28.prev = _context28.next) {
|
|
@@ -3388,9 +3785,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3388
3785
|
}
|
|
3389
3786
|
});
|
|
3390
3787
|
targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
|
|
3391
|
-
|
|
3788
|
+
_loop7 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop7() {
|
|
3392
3789
|
var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
|
|
3393
|
-
return _regeneratorRuntime().wrap(function
|
|
3790
|
+
return _regeneratorRuntime().wrap(function _loop7$(_context27) {
|
|
3394
3791
|
while (1) switch (_context27.prev = _context27.next) {
|
|
3395
3792
|
case 0:
|
|
3396
3793
|
currentDateStr = currentDate.format('YYYY-MM-DD');
|
|
@@ -3493,14 +3890,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3493
3890
|
case "end":
|
|
3494
3891
|
return _context27.stop();
|
|
3495
3892
|
}
|
|
3496
|
-
},
|
|
3893
|
+
}, _loop7);
|
|
3497
3894
|
});
|
|
3498
3895
|
case 28:
|
|
3499
3896
|
if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
|
|
3500
3897
|
_context28.next = 34;
|
|
3501
3898
|
break;
|
|
3502
3899
|
}
|
|
3503
|
-
return _context28.delegateYield(
|
|
3900
|
+
return _context28.delegateYield(_loop7(), "t0", 30);
|
|
3504
3901
|
case 30:
|
|
3505
3902
|
if (!_context28.t0) {
|
|
3506
3903
|
_context28.next = 32;
|
|
@@ -15,8 +15,9 @@ export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any
|
|
|
15
15
|
* @return {*}
|
|
16
16
|
* @Author: zhiwei.Wang
|
|
17
17
|
*/
|
|
18
|
-
export declare const getSumCapacity: ({ capacity }: {
|
|
18
|
+
export declare const getSumCapacity: ({ capacity, num }: {
|
|
19
19
|
capacity: CapacityItem[];
|
|
20
|
+
num: number;
|
|
20
21
|
}) => number;
|
|
21
22
|
/**
|
|
22
23
|
* 给定购物车数据,返回对应的 capacity 信息和套餐 capacity
|
|
@@ -60,7 +60,9 @@ export var formatDefaultCapacitys = function formatDefaultCapacitys(_ref) {
|
|
|
60
60
|
* @Author: zhiwei.Wang
|
|
61
61
|
*/
|
|
62
62
|
export var getSumCapacity = function getSumCapacity(_ref2) {
|
|
63
|
-
var capacity = _ref2.capacity
|
|
63
|
+
var capacity = _ref2.capacity,
|
|
64
|
+
_ref2$num = _ref2.num,
|
|
65
|
+
num = _ref2$num === void 0 ? 1 : _ref2$num;
|
|
64
66
|
var sum = 0;
|
|
65
67
|
var _iterator = _createForOfIteratorHelper(capacity || []),
|
|
66
68
|
_step;
|
|
@@ -74,7 +76,7 @@ export var getSumCapacity = function getSumCapacity(_ref2) {
|
|
|
74
76
|
} finally {
|
|
75
77
|
_iterator.f();
|
|
76
78
|
}
|
|
77
|
-
return sum;
|
|
79
|
+
return sum * num;
|
|
78
80
|
};
|
|
79
81
|
|
|
80
82
|
/**
|
|
@@ -85,13 +87,14 @@ export var getSumCapacity = function getSumCapacity(_ref2) {
|
|
|
85
87
|
* @return {*}
|
|
86
88
|
*/
|
|
87
89
|
export function getCapacityInfoByCartItem(targetCartItem) {
|
|
88
|
-
var _targetCartItem$_prod;
|
|
90
|
+
var _targetCartItem$_prod, _targetCartItem$_orig;
|
|
89
91
|
var formatCapacity = formatDefaultCapacitys({
|
|
90
92
|
capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
|
|
91
93
|
product_bundle: targetCartItem._origin.product.product_bundle
|
|
92
94
|
});
|
|
93
95
|
var currentCapacity = getSumCapacity({
|
|
94
|
-
capacity: formatCapacity
|
|
96
|
+
capacity: formatCapacity,
|
|
97
|
+
num: (targetCartItem === null || targetCartItem === void 0 || (_targetCartItem$_orig = targetCartItem._origin) === null || _targetCartItem$_orig === void 0 || (_targetCartItem$_orig = _targetCartItem$_orig.product) === null || _targetCartItem$_orig === void 0 ? void 0 : _targetCartItem$_orig.quantity) || 1
|
|
95
98
|
});
|
|
96
99
|
return {
|
|
97
100
|
formatCapacity: formatCapacity,
|
|
@@ -19,6 +19,7 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
19
19
|
private store;
|
|
20
20
|
private otherParams;
|
|
21
21
|
private logger;
|
|
22
|
+
private calculationCache;
|
|
22
23
|
order: OrderModule;
|
|
23
24
|
payment: PaymentModule;
|
|
24
25
|
constructor(name?: string, version?: string);
|
|
@@ -302,16 +303,46 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
302
303
|
* 删除本地 IndexDB 中超过指定天数且已同步到后端的订单数据
|
|
303
304
|
*/
|
|
304
305
|
private cleanupExpiredOrdersAsync;
|
|
306
|
+
/**
|
|
307
|
+
* 清除计算缓存
|
|
308
|
+
*/
|
|
309
|
+
private clearCalculationCache;
|
|
310
|
+
/**
|
|
311
|
+
* 批量获取订单数据(用于性能优化)
|
|
312
|
+
* 一次性获取所有需要的数据,避免重复查询
|
|
313
|
+
*/
|
|
314
|
+
private fetchOrderDataBatch;
|
|
315
|
+
/**
|
|
316
|
+
* 从支付项数组计算已支付金额(纯计算,不查询数据库)
|
|
317
|
+
*/
|
|
318
|
+
private calculatePaidAmountFromItems;
|
|
305
319
|
/**
|
|
306
320
|
* 计算已支付金额(从 Payment 模块获取最新数据)
|
|
321
|
+
*
|
|
322
|
+
* 注意:此方法保持独立性,可以单独调用。
|
|
323
|
+
* 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
|
|
307
324
|
*/
|
|
308
325
|
private calculatePaidAmountAsync;
|
|
326
|
+
/**
|
|
327
|
+
* 从订单和支付项计算剩余金额(纯计算,不查询数据库)
|
|
328
|
+
*/
|
|
329
|
+
private calculateRemainingAmountFromData;
|
|
330
|
+
/**
|
|
331
|
+
* 从订单和支付项计算剩余总金额(纯计算,排除定金)
|
|
332
|
+
*/
|
|
333
|
+
private calculateRemainingTotalAmountFromData;
|
|
309
334
|
/**
|
|
310
335
|
* 计算剩余未支付金额(从 Payment 模块获取最新数据)
|
|
336
|
+
*
|
|
337
|
+
* 注意:此方法保持独立性,可以单独调用。
|
|
338
|
+
* 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
|
|
311
339
|
*/
|
|
312
340
|
private calculateRemainingAmountAsync;
|
|
313
341
|
/**
|
|
314
342
|
* 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
|
|
343
|
+
*
|
|
344
|
+
* 注意:此方法保持独立性,可以单独调用。
|
|
345
|
+
* 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
|
|
315
346
|
*/
|
|
316
347
|
private calculateRemainingTotalAmountAsync;
|
|
317
348
|
/**
|
|
@@ -320,12 +351,24 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
320
351
|
private updateBalanceDueAmount;
|
|
321
352
|
/**
|
|
322
353
|
* 更新 stateAmount 为当前剩余未支付金额
|
|
354
|
+
*
|
|
355
|
+
* 优化版本:批量获取数据,避免重复查询数据库
|
|
323
356
|
*/
|
|
324
357
|
private updateStateAmountToRemaining;
|
|
358
|
+
/**
|
|
359
|
+
* 检查订单支付是否完成(优化版,复用已获取的数据)
|
|
360
|
+
*
|
|
361
|
+
* @param paymentItems 已获取的支付项数据
|
|
362
|
+
* @param remainingAmount 已计算的剩余金额
|
|
363
|
+
*/
|
|
364
|
+
private checkOrderPaymentCompletionOptimized;
|
|
325
365
|
/**
|
|
326
366
|
* 检查订单支付是否完成
|
|
327
367
|
*
|
|
328
368
|
* 当剩余待付款金额 <= 0 时,触发订单支付完成事件
|
|
369
|
+
*
|
|
370
|
+
* 注意:此方法保持独立性,可以单独调用。
|
|
371
|
+
* 在 updateStateAmountToRemaining 中会使用优化版本。
|
|
329
372
|
*/
|
|
330
373
|
private checkOrderPaymentCompletion;
|
|
331
374
|
/**
|
|
@@ -381,6 +424,8 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
|
|
|
381
424
|
* 重置 store 状态
|
|
382
425
|
*
|
|
383
426
|
* 在创建新订单前调用,确保状态完全干净
|
|
427
|
+
*
|
|
428
|
+
* 🚀 性能优化:改为同步方法,事件发射不阻塞主流程
|
|
384
429
|
*/
|
|
385
|
-
private
|
|
430
|
+
private resetStoreState;
|
|
386
431
|
}
|