@pisell/pisellos 1.0.0 → 1.0.1

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.
Files changed (53) hide show
  1. package/dist/modules/Cart/index.d.ts +0 -14
  2. package/dist/modules/Cart/index.js +0 -36
  3. package/dist/modules/Cart/utils/cartProduct.js +1 -10
  4. package/dist/modules/Date/index.js +6 -57
  5. package/dist/modules/Discount/index.d.ts +0 -1
  6. package/dist/modules/Discount/index.js +7 -15
  7. package/dist/modules/Discount/types.d.ts +0 -10
  8. package/dist/modules/ProductList/index.d.ts +0 -7
  9. package/dist/modules/ProductList/index.js +39 -102
  10. package/dist/modules/Rules/index.js +71 -196
  11. package/dist/modules/Rules/types.d.ts +0 -6
  12. package/dist/modules/Schedule/index.d.ts +1 -9
  13. package/dist/modules/Schedule/index.js +2 -122
  14. package/dist/modules/Schedule/types.d.ts +0 -13
  15. package/dist/solution/BookingByStep/index.d.ts +30 -120
  16. package/dist/solution/BookingByStep/index.js +1065 -750
  17. package/dist/solution/BookingByStep/utils/resources.d.ts +31 -29
  18. package/dist/solution/BookingByStep/utils/resources.js +94 -39
  19. package/dist/solution/BookingByStep/utils/timeslots.d.ts +0 -11
  20. package/dist/solution/BookingByStep/utils/timeslots.js +0 -15
  21. package/dist/solution/ShopDiscount/index.d.ts +0 -2
  22. package/dist/solution/ShopDiscount/index.js +32 -93
  23. package/lib/modules/Cart/index.d.ts +0 -14
  24. package/lib/modules/Cart/index.js +0 -32
  25. package/lib/modules/Cart/utils/cartProduct.js +1 -1
  26. package/lib/modules/Date/index.js +10 -62
  27. package/lib/modules/Discount/index.d.ts +0 -1
  28. package/lib/modules/Discount/index.js +6 -18
  29. package/lib/modules/Discount/types.d.ts +0 -10
  30. package/lib/modules/ProductList/index.d.ts +0 -7
  31. package/lib/modules/ProductList/index.js +0 -45
  32. package/lib/modules/Rules/index.js +56 -147
  33. package/lib/modules/Rules/types.d.ts +0 -6
  34. package/lib/modules/Schedule/index.d.ts +1 -9
  35. package/lib/modules/Schedule/index.js +1 -79
  36. package/lib/modules/Schedule/types.d.ts +0 -13
  37. package/lib/solution/BookingByStep/index.d.ts +30 -120
  38. package/lib/solution/BookingByStep/index.js +581 -392
  39. package/lib/solution/BookingByStep/utils/resources.d.ts +31 -29
  40. package/lib/solution/BookingByStep/utils/resources.js +59 -23
  41. package/lib/solution/BookingByStep/utils/timeslots.d.ts +0 -11
  42. package/lib/solution/BookingByStep/utils/timeslots.js +0 -7
  43. package/lib/solution/ShopDiscount/index.d.ts +0 -2
  44. package/lib/solution/ShopDiscount/index.js +18 -85
  45. package/package.json +1 -1
  46. package/dist/modules/Cart/utils/changePrice.d.ts +0 -3
  47. package/dist/modules/Cart/utils/changePrice.js +0 -104
  48. package/dist/solution/BookingByStep/utils/capacity.d.ts +0 -47
  49. package/dist/solution/BookingByStep/utils/capacity.js +0 -132
  50. package/lib/modules/Cart/utils/changePrice.d.ts +0 -3
  51. package/lib/modules/Cart/utils/changePrice.js +0 -78
  52. package/lib/solution/BookingByStep/utils/capacity.d.ts +0 -47
  53. package/lib/solution/BookingByStep/utils/capacity.js +0 -106
@@ -1,47 +0,0 @@
1
- import { CartItem } from "../../../modules";
2
- import { CapacityItem, ResourceItem } from "./resources";
3
- /**
4
- * @title: 基于选择的商品格式化容量
5
- * @description:
6
- * @param {any} param1
7
- * @return {*}
8
- * @Author: zhiwei.Wang
9
- */
10
- export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any) => CapacityItem[];
11
- /**
12
- * @title: 获取总容量
13
- * @description:
14
- * @param {object} capacity 为 formatDefaultCapacitys()的结果
15
- * @return {*}
16
- * @Author: zhiwei.Wang
17
- */
18
- export declare const getSumCapacity: ({ capacity }: {
19
- capacity: CapacityItem[];
20
- }) => number;
21
- /**
22
- * 给定购物车数据,返回对应的 capacity 信息和套餐 capacity
23
- *
24
- * @export
25
- * @param {CartItem} targetCartItem
26
- * @return {*}
27
- */
28
- export declare function getCapacityInfoByCartItem(targetCartItem: CartItem): {
29
- formatCapacity: CapacityItem[];
30
- currentCapacity: number;
31
- };
32
- /**
33
- * @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
34
- * @description:
35
- * @param {object} resource
36
- * @return {*}
37
- * @Author: jinglin.tan
38
- */
39
- export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void;
40
- /**
41
- * 检查资源是否有足够的容量供额外使用
42
- * @param currentCapacity - 当前已使用的容量
43
- * @param requiredCapacity - 需要的额外容量
44
- * @param maxCapacity - 最大允许容量
45
- * @returns 如果资源可以容纳额外的容量则返回 true
46
- */
47
- export declare const checkResourceCanUseByCapacity: (currentCapacity: number, requiredCapacity: number, maxCapacity: number) => boolean;
@@ -1,132 +0,0 @@
1
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
- 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); }
3
- 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; }
4
- /**
5
- * @title: 基于选择的商品格式化容量
6
- * @description:
7
- * @param {any} param1
8
- * @return {*}
9
- * @Author: zhiwei.Wang
10
- */
11
- export var formatDefaultCapacitys = function formatDefaultCapacitys(_ref) {
12
- var capacity = _ref.capacity,
13
- product_bundle = _ref.product_bundle;
14
- if ((capacity === null || capacity === void 0 ? void 0 : capacity.type) === 'package') {
15
- return (product_bundle || []).map(function (d) {
16
- var id = d.bundle_product_id;
17
- var item = ((capacity === null || capacity === void 0 ? void 0 : capacity.package) || []).find(function (item) {
18
- return item.product_id === id;
19
- });
20
- return {
21
- id: id,
22
- value: item ? d.num || 0 : 0,
23
- name: (item === null || item === void 0 ? void 0 : item.name) || (d === null || d === void 0 ? void 0 : d.title)
24
- };
25
- });
26
- }
27
- if ((capacity === null || capacity === void 0 ? void 0 : capacity.type) === 'custom') {
28
- return ((capacity === null || capacity === void 0 ? void 0 : capacity.custom) || []).map(function (d) {
29
- return {
30
- id: d.id,
31
- value: d.min,
32
- name: d.name
33
- };
34
- });
35
- }
36
-
37
- // 默认为1
38
- return [{
39
- id: 0,
40
- value: 1,
41
- name: ''
42
- }];
43
- };
44
-
45
- /**
46
- * @title: 获取总容量
47
- * @description:
48
- * @param {object} capacity 为 formatDefaultCapacitys()的结果
49
- * @return {*}
50
- * @Author: zhiwei.Wang
51
- */
52
- export var getSumCapacity = function getSumCapacity(_ref2) {
53
- var capacity = _ref2.capacity;
54
- var sum = 0;
55
- var _iterator = _createForOfIteratorHelper(capacity || []),
56
- _step;
57
- try {
58
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
59
- var item = _step.value;
60
- sum += item.value;
61
- }
62
- } catch (err) {
63
- _iterator.e(err);
64
- } finally {
65
- _iterator.f();
66
- }
67
- return sum;
68
- };
69
-
70
- /**
71
- * 给定购物车数据,返回对应的 capacity 信息和套餐 capacity
72
- *
73
- * @export
74
- * @param {CartItem} targetCartItem
75
- * @return {*}
76
- */
77
- export function getCapacityInfoByCartItem(targetCartItem) {
78
- var _targetCartItem$_prod;
79
- var formatCapacity = formatDefaultCapacitys({
80
- capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
81
- product_bundle: targetCartItem._origin.product.product_bundle
82
- });
83
- var currentCapacity = getSumCapacity({
84
- capacity: formatCapacity
85
- });
86
- return {
87
- formatCapacity: formatCapacity,
88
- currentCapacity: currentCapacity
89
- };
90
- }
91
-
92
- /**
93
- * @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
94
- * @description:
95
- * @param {object} resource
96
- * @return {*}
97
- * @Author: jinglin.tan
98
- */
99
- export var checkSubResourcesCapacity = function checkSubResourcesCapacity(resource) {
100
- if (resource.children && resource.children.length) {
101
- var countCapacity = resource.capacity; // 100
102
- resource.children.forEach(function (child, index) {
103
- if (index === resource.children.length - 1) {
104
- // 如果是最后一个资源,直接拿剩余未分配完的容量去占用
105
- // 哪怕这个东西会超过资源本身的 capacity也得让他占,PRD 里有写
106
- child.capacity = countCapacity;
107
- return;
108
- }
109
- if (child.capacity <= countCapacity) {
110
- countCapacity -= child.capacity; // 100 - = 90
111
- } else {
112
- child.capacity = countCapacity; // 10
113
- countCapacity = 0; // 0
114
- }
115
- });
116
- }
117
- };
118
-
119
- /**
120
- * 检查资源是否有足够的容量供额外使用
121
- * @param currentCapacity - 当前已使用的容量
122
- * @param requiredCapacity - 需要的额外容量
123
- * @param maxCapacity - 最大允许容量
124
- * @returns 如果资源可以容纳额外的容量则返回 true
125
- */
126
- export var checkResourceCanUseByCapacity = function checkResourceCanUseByCapacity(currentCapacity, requiredCapacity, maxCapacity) {
127
- // Handle edge cases early
128
- if (currentCapacity < 0 || requiredCapacity < 0 || maxCapacity <= 0) {
129
- return false;
130
- }
131
- return currentCapacity + requiredCapacity <= maxCapacity;
132
- };
@@ -1,3 +0,0 @@
1
- import { Product } from "../../Product";
2
- import { CartItem, IUpdateItemParams } from "../types";
3
- export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<Product | undefined>, updateCart: (item: IUpdateItemParams) => void): Promise<void>;
@@ -1,78 +0,0 @@
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/Cart/utils/changePrice.ts
30
- var changePrice_exports = {};
31
- __export(changePrice_exports, {
32
- updateAllCartItemPrice: () => updateAllCartItemPrice
33
- });
34
- module.exports = __toCommonJS(changePrice_exports);
35
- var import_decimal = __toESM(require("decimal.js"));
36
- async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCart) {
37
- for (const item of cartItems) {
38
- const targetProduct = priceData.find((n) => n.id === item.id);
39
- const cartProduct = await getProduct(
40
- item.id
41
- );
42
- const productInfo = cartProduct == null ? void 0 : cartProduct.getData();
43
- let bundle = item._bundleOrigin;
44
- productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
45
- productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
46
- bundle = bundle == null ? void 0 : bundle.map((n) => {
47
- var _a;
48
- const targetBundle = (_a = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a.find(
49
- (m) => m.id === n.group_id
50
- );
51
- if (targetBundle) {
52
- const targetBundleItem = targetBundle.bundle_item.find(
53
- (m) => m.id === n.id
54
- );
55
- if (targetBundleItem.price_type === "markdown") {
56
- targetBundleItem.price = new import_decimal.default(targetBundleItem.price || 0).mul(-1).toNumber();
57
- }
58
- if (targetBundleItem) {
59
- return {
60
- ...n,
61
- price: targetBundleItem.price,
62
- base_price: targetBundleItem.base_price
63
- };
64
- }
65
- }
66
- return n;
67
- });
68
- updateCart({
69
- _id: item._id,
70
- product: productInfo,
71
- bundle
72
- });
73
- }
74
- }
75
- // Annotate the CommonJS export names for ESM import in node:
76
- 0 && (module.exports = {
77
- updateAllCartItemPrice
78
- });
@@ -1,47 +0,0 @@
1
- import { CartItem } from "../../../modules";
2
- import { CapacityItem, ResourceItem } from "./resources";
3
- /**
4
- * @title: 基于选择的商品格式化容量
5
- * @description:
6
- * @param {any} param1
7
- * @return {*}
8
- * @Author: zhiwei.Wang
9
- */
10
- export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any) => CapacityItem[];
11
- /**
12
- * @title: 获取总容量
13
- * @description:
14
- * @param {object} capacity 为 formatDefaultCapacitys()的结果
15
- * @return {*}
16
- * @Author: zhiwei.Wang
17
- */
18
- export declare const getSumCapacity: ({ capacity }: {
19
- capacity: CapacityItem[];
20
- }) => number;
21
- /**
22
- * 给定购物车数据,返回对应的 capacity 信息和套餐 capacity
23
- *
24
- * @export
25
- * @param {CartItem} targetCartItem
26
- * @return {*}
27
- */
28
- export declare function getCapacityInfoByCartItem(targetCartItem: CartItem): {
29
- formatCapacity: CapacityItem[];
30
- currentCapacity: number;
31
- };
32
- /**
33
- * @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
34
- * @description:
35
- * @param {object} resource
36
- * @return {*}
37
- * @Author: jinglin.tan
38
- */
39
- export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void;
40
- /**
41
- * 检查资源是否有足够的容量供额外使用
42
- * @param currentCapacity - 当前已使用的容量
43
- * @param requiredCapacity - 需要的额外容量
44
- * @param maxCapacity - 最大允许容量
45
- * @returns 如果资源可以容纳额外的容量则返回 true
46
- */
47
- export declare const checkResourceCanUseByCapacity: (currentCapacity: number, requiredCapacity: number, maxCapacity: number) => boolean;
@@ -1,106 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/solution/BookingByStep/utils/capacity.ts
20
- var capacity_exports = {};
21
- __export(capacity_exports, {
22
- checkResourceCanUseByCapacity: () => checkResourceCanUseByCapacity,
23
- checkSubResourcesCapacity: () => checkSubResourcesCapacity,
24
- formatDefaultCapacitys: () => formatDefaultCapacitys,
25
- getCapacityInfoByCartItem: () => getCapacityInfoByCartItem,
26
- getSumCapacity: () => getSumCapacity
27
- });
28
- module.exports = __toCommonJS(capacity_exports);
29
- var formatDefaultCapacitys = ({
30
- capacity,
31
- product_bundle
32
- }) => {
33
- if ((capacity == null ? void 0 : capacity.type) === "package") {
34
- return (product_bundle || []).map((d) => {
35
- const id = d.bundle_product_id;
36
- const item = ((capacity == null ? void 0 : capacity.package) || []).find(
37
- (item2) => item2.product_id === id
38
- );
39
- return {
40
- id,
41
- value: item ? d.num || 0 : 0,
42
- name: (item == null ? void 0 : item.name) || (d == null ? void 0 : d.title)
43
- };
44
- });
45
- }
46
- if ((capacity == null ? void 0 : capacity.type) === "custom") {
47
- return ((capacity == null ? void 0 : capacity.custom) || []).map((d) => {
48
- return {
49
- id: d.id,
50
- value: d.min,
51
- name: d.name
52
- };
53
- });
54
- }
55
- return [{ id: 0, value: 1, name: "" }];
56
- };
57
- var getSumCapacity = ({ capacity }) => {
58
- let sum = 0;
59
- for (let item of capacity || []) {
60
- sum += item.value;
61
- }
62
- return sum;
63
- };
64
- function getCapacityInfoByCartItem(targetCartItem) {
65
- var _a;
66
- const formatCapacity = formatDefaultCapacitys({
67
- capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
68
- product_bundle: targetCartItem._origin.product.product_bundle
69
- });
70
- const currentCapacity = getSumCapacity({ capacity: formatCapacity });
71
- return {
72
- formatCapacity,
73
- currentCapacity
74
- };
75
- }
76
- var checkSubResourcesCapacity = (resource) => {
77
- if (resource.children && resource.children.length) {
78
- let countCapacity = resource.capacity;
79
- resource.children.forEach((child, index) => {
80
- if (index === resource.children.length - 1) {
81
- child.capacity = countCapacity;
82
- return;
83
- }
84
- if (child.capacity <= countCapacity) {
85
- countCapacity -= child.capacity;
86
- } else {
87
- child.capacity = countCapacity;
88
- countCapacity = 0;
89
- }
90
- });
91
- }
92
- };
93
- var checkResourceCanUseByCapacity = (currentCapacity, requiredCapacity, maxCapacity) => {
94
- if (currentCapacity < 0 || requiredCapacity < 0 || maxCapacity <= 0) {
95
- return false;
96
- }
97
- return currentCapacity + requiredCapacity <= maxCapacity;
98
- };
99
- // Annotate the CommonJS export names for ESM import in node:
100
- 0 && (module.exports = {
101
- checkResourceCanUseByCapacity,
102
- checkSubResourcesCapacity,
103
- formatDefaultCapacitys,
104
- getCapacityInfoByCartItem,
105
- getSumCapacity
106
- });