@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.
- package/dist/modules/Cart/index.d.ts +0 -14
- package/dist/modules/Cart/index.js +0 -36
- package/dist/modules/Cart/utils/cartProduct.js +1 -10
- package/dist/modules/Date/index.js +6 -57
- package/dist/modules/Discount/index.d.ts +0 -1
- package/dist/modules/Discount/index.js +7 -15
- package/dist/modules/Discount/types.d.ts +0 -10
- package/dist/modules/ProductList/index.d.ts +0 -7
- package/dist/modules/ProductList/index.js +39 -102
- package/dist/modules/Rules/index.js +71 -196
- package/dist/modules/Rules/types.d.ts +0 -6
- package/dist/modules/Schedule/index.d.ts +1 -9
- package/dist/modules/Schedule/index.js +2 -122
- package/dist/modules/Schedule/types.d.ts +0 -13
- package/dist/solution/BookingByStep/index.d.ts +30 -120
- package/dist/solution/BookingByStep/index.js +1065 -750
- package/dist/solution/BookingByStep/utils/resources.d.ts +31 -29
- package/dist/solution/BookingByStep/utils/resources.js +94 -39
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +0 -11
- package/dist/solution/BookingByStep/utils/timeslots.js +0 -15
- package/dist/solution/ShopDiscount/index.d.ts +0 -2
- package/dist/solution/ShopDiscount/index.js +32 -93
- package/lib/modules/Cart/index.d.ts +0 -14
- package/lib/modules/Cart/index.js +0 -32
- package/lib/modules/Cart/utils/cartProduct.js +1 -1
- package/lib/modules/Date/index.js +10 -62
- package/lib/modules/Discount/index.d.ts +0 -1
- package/lib/modules/Discount/index.js +6 -18
- package/lib/modules/Discount/types.d.ts +0 -10
- package/lib/modules/ProductList/index.d.ts +0 -7
- package/lib/modules/ProductList/index.js +0 -45
- package/lib/modules/Rules/index.js +56 -147
- package/lib/modules/Rules/types.d.ts +0 -6
- package/lib/modules/Schedule/index.d.ts +1 -9
- package/lib/modules/Schedule/index.js +1 -79
- package/lib/modules/Schedule/types.d.ts +0 -13
- package/lib/solution/BookingByStep/index.d.ts +30 -120
- package/lib/solution/BookingByStep/index.js +581 -392
- package/lib/solution/BookingByStep/utils/resources.d.ts +31 -29
- package/lib/solution/BookingByStep/utils/resources.js +59 -23
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +0 -11
- package/lib/solution/BookingByStep/utils/timeslots.js +0 -7
- package/lib/solution/ShopDiscount/index.d.ts +0 -2
- package/lib/solution/ShopDiscount/index.js +18 -85
- package/package.json +1 -1
- package/dist/modules/Cart/utils/changePrice.d.ts +0 -3
- package/dist/modules/Cart/utils/changePrice.js +0 -104
- package/dist/solution/BookingByStep/utils/capacity.d.ts +0 -47
- package/dist/solution/BookingByStep/utils/capacity.js +0 -132
- package/lib/modules/Cart/utils/changePrice.d.ts +0 -3
- package/lib/modules/Cart/utils/changePrice.js +0 -78
- package/lib/solution/BookingByStep/utils/capacity.d.ts +0 -47
- package/lib/solution/BookingByStep/utils/capacity.js +0 -106
|
@@ -79,7 +79,7 @@ export declare const formatResources: ({ booking, resources, }: {
|
|
|
79
79
|
* @return {*}
|
|
80
80
|
* @Author: zhiwei.Wang
|
|
81
81
|
*/
|
|
82
|
-
export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary
|
|
82
|
+
export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary }: {
|
|
83
83
|
resource: ResourceItem;
|
|
84
84
|
duration: number;
|
|
85
85
|
split: number;
|
|
@@ -97,10 +97,7 @@ export declare const getTimeSlicesByResource: ({ resource, duration, split, curr
|
|
|
97
97
|
} | undefined;
|
|
98
98
|
} | undefined;
|
|
99
99
|
hasFlexibleDuration?: boolean | undefined;
|
|
100
|
-
operating_day_boundary?:
|
|
101
|
-
type: string;
|
|
102
|
-
time: string;
|
|
103
|
-
} | undefined;
|
|
100
|
+
operating_day_boundary?: string | undefined;
|
|
104
101
|
}) => TimeSliceItem[];
|
|
105
102
|
/**
|
|
106
103
|
* @title: 获取时间切片列表的交集
|
|
@@ -138,7 +135,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
|
|
|
138
135
|
* @return {*}
|
|
139
136
|
* @Author: zhiwei.Wang
|
|
140
137
|
*/
|
|
141
|
-
export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary
|
|
138
|
+
export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary }: {
|
|
142
139
|
resourceIds: number[];
|
|
143
140
|
resourcesMap: any;
|
|
144
141
|
duration: number;
|
|
@@ -157,10 +154,7 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
|
|
|
157
154
|
} | undefined;
|
|
158
155
|
} | undefined;
|
|
159
156
|
hasFlexibleDuration?: boolean | undefined;
|
|
160
|
-
operating_day_boundary?:
|
|
161
|
-
type: string;
|
|
162
|
-
time: string;
|
|
163
|
-
} | undefined;
|
|
157
|
+
operating_day_boundary?: string | undefined;
|
|
164
158
|
}) => any[];
|
|
165
159
|
/**
|
|
166
160
|
* @title: 获取其他人的已选资源
|
|
@@ -180,11 +174,37 @@ export declare const getOthersSelectedResources: (cartItems: CartItem[], account
|
|
|
180
174
|
* @Author: jinglin.tan
|
|
181
175
|
*/
|
|
182
176
|
export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
|
|
183
|
-
|
|
177
|
+
interface CapacityItem {
|
|
184
178
|
id: number;
|
|
185
179
|
value: number;
|
|
186
180
|
name: string;
|
|
187
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* @title: 基于选择的商品格式化容量
|
|
184
|
+
* @description:
|
|
185
|
+
* @param {any} param1
|
|
186
|
+
* @return {*}
|
|
187
|
+
* @Author: zhiwei.Wang
|
|
188
|
+
*/
|
|
189
|
+
export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any) => CapacityItem[];
|
|
190
|
+
/**
|
|
191
|
+
* @title: 获取总容量
|
|
192
|
+
* @description:
|
|
193
|
+
* @param {object} capacity 为 formatDefaultCapacitys()的结果
|
|
194
|
+
* @return {*}
|
|
195
|
+
* @Author: zhiwei.Wang
|
|
196
|
+
*/
|
|
197
|
+
export declare const getSumCapacity: ({ capacity }: {
|
|
198
|
+
capacity: CapacityItem[];
|
|
199
|
+
}) => number;
|
|
200
|
+
/**
|
|
201
|
+
* @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
|
|
202
|
+
* @description:
|
|
203
|
+
* @param {object} resource
|
|
204
|
+
* @return {*}
|
|
205
|
+
* @Author: jinglin.tan
|
|
206
|
+
*/
|
|
207
|
+
export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void;
|
|
188
208
|
/**
|
|
189
209
|
* @title: 根据日期范围过滤日程
|
|
190
210
|
*
|
|
@@ -222,22 +242,4 @@ export declare function getResourcesIdsByProduct(product: ProductData): number[]
|
|
|
222
242
|
* @return {*}
|
|
223
243
|
*/
|
|
224
244
|
export declare function sortCombinedResources(resourcesList: ResourceItem[]): ResourceItem[];
|
|
225
|
-
/**
|
|
226
|
-
* 传入一个资源组,根据 formid筛出相同类型的资源
|
|
227
|
-
*
|
|
228
|
-
* @export
|
|
229
|
-
* @param {ResourceItem[]} resources
|
|
230
|
-
* @param {string} form_id
|
|
231
|
-
* @return {*}
|
|
232
|
-
*/
|
|
233
|
-
export declare function filterResourcesByFormItem(resources: ResourceItem[], form_id: string): ResourceItem[];
|
|
234
|
-
/**
|
|
235
|
-
* 传入两个资源,确认这两个资源是否有交集(包括组合资源)
|
|
236
|
-
*
|
|
237
|
-
* @export
|
|
238
|
-
* @param {ResourceItem} resource1
|
|
239
|
-
* @param {ResourceItem} resource2
|
|
240
|
-
* @return {*}
|
|
241
|
-
*/
|
|
242
|
-
export declare function checkTwoResourcesIntersection(resource1: ResourceItem, resource2: ResourceItem): true | undefined;
|
|
243
245
|
export {};
|
|
@@ -463,8 +463,7 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref5) {
|
|
|
463
463
|
}
|
|
464
464
|
if (_status.usable) {
|
|
465
465
|
// 如果有hasFlexibleDuration,且timeSlice.start_at 大于等于operating_day_boundary,则不添加时间切片
|
|
466
|
-
|
|
467
|
-
if (hasFlexibleDuration && operating_day_boundary && timeSlice.start_time >= (operatingBoundaryDateTime || '23:59')) {
|
|
466
|
+
if (hasFlexibleDuration && operating_day_boundary && timeSlice.start_time >= operating_day_boundary) {
|
|
468
467
|
break;
|
|
469
468
|
}
|
|
470
469
|
// 添加时间切片 09:00 ~ 10:00 09:20 ~ 10:20 09:00 ~ 10:00 09:20 ~ 10:20 11:00 ~ 12:00 11:20 ~ 12:20
|
|
@@ -702,6 +701,99 @@ export var getOthersCartSelectedResources = function getOthersCartSelectedResour
|
|
|
702
701
|
return acc;
|
|
703
702
|
}, []);
|
|
704
703
|
};
|
|
704
|
+
/**
|
|
705
|
+
* @title: 基于选择的商品格式化容量
|
|
706
|
+
* @description:
|
|
707
|
+
* @param {any} param1
|
|
708
|
+
* @return {*}
|
|
709
|
+
* @Author: zhiwei.Wang
|
|
710
|
+
*/
|
|
711
|
+
export var formatDefaultCapacitys = function formatDefaultCapacitys(_ref7) {
|
|
712
|
+
var capacity = _ref7.capacity,
|
|
713
|
+
product_bundle = _ref7.product_bundle;
|
|
714
|
+
if ((capacity === null || capacity === void 0 ? void 0 : capacity.type) === 'package') {
|
|
715
|
+
return (product_bundle || []).map(function (d) {
|
|
716
|
+
var id = d.bundle_product_id;
|
|
717
|
+
var item = ((capacity === null || capacity === void 0 ? void 0 : capacity.package) || []).find(function (item) {
|
|
718
|
+
return item.product_id === id;
|
|
719
|
+
});
|
|
720
|
+
return {
|
|
721
|
+
id: id,
|
|
722
|
+
value: item ? d.num || 0 : 0,
|
|
723
|
+
name: (item === null || item === void 0 ? void 0 : item.name) || (d === null || d === void 0 ? void 0 : d.title)
|
|
724
|
+
};
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
if ((capacity === null || capacity === void 0 ? void 0 : capacity.type) === 'custom') {
|
|
728
|
+
return ((capacity === null || capacity === void 0 ? void 0 : capacity.custom) || []).map(function (d) {
|
|
729
|
+
return {
|
|
730
|
+
id: d.id,
|
|
731
|
+
value: d.min,
|
|
732
|
+
name: d.name
|
|
733
|
+
};
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// 默认为1
|
|
738
|
+
return [{
|
|
739
|
+
id: 0,
|
|
740
|
+
value: 1,
|
|
741
|
+
name: ''
|
|
742
|
+
}];
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* @title: 获取总容量
|
|
747
|
+
* @description:
|
|
748
|
+
* @param {object} capacity 为 formatDefaultCapacitys()的结果
|
|
749
|
+
* @return {*}
|
|
750
|
+
* @Author: zhiwei.Wang
|
|
751
|
+
*/
|
|
752
|
+
export var getSumCapacity = function getSumCapacity(_ref8) {
|
|
753
|
+
var capacity = _ref8.capacity;
|
|
754
|
+
var sum = 0;
|
|
755
|
+
var _iterator2 = _createForOfIteratorHelper(capacity || []),
|
|
756
|
+
_step2;
|
|
757
|
+
try {
|
|
758
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
759
|
+
var item = _step2.value;
|
|
760
|
+
sum += item.value;
|
|
761
|
+
}
|
|
762
|
+
} catch (err) {
|
|
763
|
+
_iterator2.e(err);
|
|
764
|
+
} finally {
|
|
765
|
+
_iterator2.f();
|
|
766
|
+
}
|
|
767
|
+
return sum;
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
|
|
772
|
+
* @description:
|
|
773
|
+
* @param {object} resource
|
|
774
|
+
* @return {*}
|
|
775
|
+
* @Author: jinglin.tan
|
|
776
|
+
*/
|
|
777
|
+
export var checkSubResourcesCapacity = function checkSubResourcesCapacity(resource) {
|
|
778
|
+
if (resource.children && resource.children.length) {
|
|
779
|
+
var countCapacity = resource.capacity; // 100
|
|
780
|
+
resource.children.forEach(function (child, index) {
|
|
781
|
+
if (index === resource.children.length - 1) {
|
|
782
|
+
// 如果是最后一个资源,直接拿剩余未分配完的容量去占用
|
|
783
|
+
// 哪怕这个东西会超过资源本身的 capacity也得让他占,PRD 里有写
|
|
784
|
+
child.capacity = countCapacity;
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
if (child.capacity <= countCapacity) {
|
|
788
|
+
countCapacity -= child.capacity; // 100 - = 90
|
|
789
|
+
} else {
|
|
790
|
+
child.capacity = countCapacity; // 10
|
|
791
|
+
countCapacity = 0; // 0
|
|
792
|
+
}
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
|
|
705
797
|
/**
|
|
706
798
|
* @title: 根据日期范围过滤日程
|
|
707
799
|
*
|
|
@@ -799,41 +891,4 @@ export function sortCombinedResources(resourcesList) {
|
|
|
799
891
|
return aIsCombined === bIsCombined ? 0 : aIsCombined ? 1 : -1;
|
|
800
892
|
});
|
|
801
893
|
return newResourcesList;
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
/**
|
|
805
|
-
* 传入一个资源组,根据 formid筛出相同类型的资源
|
|
806
|
-
*
|
|
807
|
-
* @export
|
|
808
|
-
* @param {ResourceItem[]} resources
|
|
809
|
-
* @param {string} form_id
|
|
810
|
-
* @return {*}
|
|
811
|
-
*/
|
|
812
|
-
export function filterResourcesByFormItem(resources, form_id) {
|
|
813
|
-
return resources.filter(function (n) {
|
|
814
|
-
return n.form_id === form_id;
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
/**
|
|
819
|
-
* 传入两个资源,确认这两个资源是否有交集(包括组合资源)
|
|
820
|
-
*
|
|
821
|
-
* @export
|
|
822
|
-
* @param {ResourceItem} resource1
|
|
823
|
-
* @param {ResourceItem} resource2
|
|
824
|
-
* @return {*}
|
|
825
|
-
*/
|
|
826
|
-
export function checkTwoResourcesIntersection(resource1, resource2) {
|
|
827
|
-
var _resource1$metadata$c, _resource2$metadata$c;
|
|
828
|
-
// 检查主资源ID是否匹配
|
|
829
|
-
if (resource1.id === resource2.id) return true;
|
|
830
|
-
// 检查组合资源的情况
|
|
831
|
-
if (((_resource1$metadata$c = resource1.metadata.combined_resource) === null || _resource1$metadata$c === void 0 ? void 0 : _resource1$metadata$c.status) === 1 && (
|
|
832
|
-
// 如果现在选择的是组合资源,需要判断
|
|
833
|
-
// 1、当前其他购物车里是否选了当前组合资源的子资源
|
|
834
|
-
// 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
|
|
835
|
-
resource1.metadata.combined_resource.resource_ids.includes(resource2.id) || resource1.metadata.combined_resource.resource_ids.some(function (n) {
|
|
836
|
-
return resource2.metadata.combined_resource.resource_ids.includes(n);
|
|
837
|
-
}))) return true;
|
|
838
|
-
if (((_resource2$metadata$c = resource2.metadata.combined_resource) === null || _resource2$metadata$c === void 0 ? void 0 : _resource2$metadata$c.status) === 1 && resource2.metadata.combined_resource.resource_ids.includes(resource2.id)) return true;
|
|
839
894
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Dayjs } from "dayjs";
|
|
2
1
|
import { ResourceItem, TimeSliceItem } from "./resources";
|
|
3
2
|
/**
|
|
4
3
|
* 计算资源在指定时间段内的总可用时间(以分钟为单位)
|
|
@@ -24,13 +23,3 @@ export declare function findFastestAvailableResource({ resources, currentCapacit
|
|
|
24
23
|
currentCapacity?: number;
|
|
25
24
|
countMap?: Record<number, number>;
|
|
26
25
|
}): ResourceItem | null;
|
|
27
|
-
/**
|
|
28
|
-
* 给定一个时间列表,通过开始和结束时间过滤出符合条件的时间段
|
|
29
|
-
*
|
|
30
|
-
* @export
|
|
31
|
-
* @param {TimeSliceItem[]} times
|
|
32
|
-
* @param {Dayjs} startTime
|
|
33
|
-
* @param {Dayjs} endTime
|
|
34
|
-
* @return {*}
|
|
35
|
-
*/
|
|
36
|
-
export declare function filterConditionTimeSlots(times: TimeSliceItem[], startTime: Dayjs, endTime: Dayjs): TimeSliceItem[];
|
|
@@ -206,19 +206,4 @@ export function findFastestAvailableResource(_ref2) {
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
return selectedResource;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* 给定一个时间列表,通过开始和结束时间过滤出符合条件的时间段
|
|
213
|
-
*
|
|
214
|
-
* @export
|
|
215
|
-
* @param {TimeSliceItem[]} times
|
|
216
|
-
* @param {Dayjs} startTime
|
|
217
|
-
* @param {Dayjs} endTime
|
|
218
|
-
* @return {*}
|
|
219
|
-
*/
|
|
220
|
-
export function filterConditionTimeSlots(times, startTime, endTime) {
|
|
221
|
-
return times.filter(function (n) {
|
|
222
|
-
return !dayjs(n.start_at).isAfter(dayjs(startTime)) && !dayjs(n.end_at).isBefore(dayjs(endTime));
|
|
223
|
-
});
|
|
224
209
|
}
|
|
@@ -10,7 +10,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
10
10
|
private window;
|
|
11
11
|
private store;
|
|
12
12
|
private options;
|
|
13
|
-
private hooks?;
|
|
14
13
|
constructor(name?: string, version?: string);
|
|
15
14
|
initialize(core: PisellCore, options: any): Promise<void>;
|
|
16
15
|
destroy(): Promise<void>;
|
|
@@ -38,7 +37,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
38
37
|
isAvailable: boolean;
|
|
39
38
|
productList: Record<string, any>[];
|
|
40
39
|
discountList: Discount[];
|
|
41
|
-
type: "server" | "clientCalc";
|
|
42
40
|
}>;
|
|
43
41
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
44
42
|
private getCustomer;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
var _excluded = ["wallet_pass_list"];
|
|
1
2
|
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
|
|
3
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
3
5
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
6
|
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."); }
|
|
5
7
|
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); }
|
|
@@ -28,7 +30,6 @@ import { BaseModule } from "../../modules/BaseModule";
|
|
|
28
30
|
import { ShopDiscountHooks } from "./types";
|
|
29
31
|
import { DiscountModule } from "../../modules/Discount";
|
|
30
32
|
import { RulesModule } from "../../modules/Rules";
|
|
31
|
-
import Decimal from 'decimal.js';
|
|
32
33
|
export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
33
34
|
_inherits(ShopDiscountImpl, _BaseModule);
|
|
34
35
|
var _super = _createSuper(ShopDiscountImpl);
|
|
@@ -44,7 +45,6 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
44
45
|
_defineProperty(_assertThisInitialized(_this), "window", void 0);
|
|
45
46
|
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
46
47
|
_defineProperty(_assertThisInitialized(_this), "options", {});
|
|
47
|
-
_defineProperty(_assertThisInitialized(_this), "hooks", void 0);
|
|
48
48
|
_this.store = {
|
|
49
49
|
customer: null,
|
|
50
50
|
productList: [],
|
|
@@ -59,14 +59,12 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
59
59
|
key: "initialize",
|
|
60
60
|
value: function () {
|
|
61
61
|
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
|
|
62
|
-
var _options$otherParams;
|
|
63
62
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
64
63
|
while (1) switch (_context.prev = _context.next) {
|
|
65
64
|
case 0:
|
|
66
65
|
this.core = core;
|
|
67
66
|
this.options = options;
|
|
68
67
|
this.store = _objectSpread(_objectSpread({}, this.store), options.store || {});
|
|
69
|
-
this.hooks = (_options$otherParams = options.otherParams) === null || _options$otherParams === void 0 || (_options$otherParams = _options$otherParams.rules) === null || _options$otherParams === void 0 ? void 0 : _options$otherParams.hooks;
|
|
70
68
|
console.log('[ShopDiscount] 初始化完成');
|
|
71
69
|
|
|
72
70
|
// 获取依赖的插件
|
|
@@ -77,7 +75,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
77
75
|
|
|
78
76
|
// 注册事件监听
|
|
79
77
|
this.registerEventListeners();
|
|
80
|
-
case
|
|
78
|
+
case 7:
|
|
81
79
|
case "end":
|
|
82
80
|
return _context.stop();
|
|
83
81
|
}
|
|
@@ -198,8 +196,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
198
196
|
_this2.loadPrepareConfig({
|
|
199
197
|
customerId: customer.id,
|
|
200
198
|
action: 'create',
|
|
201
|
-
with_good_pass: 1
|
|
202
|
-
with_discount_card: 1
|
|
199
|
+
with_good_pass: 1
|
|
203
200
|
});
|
|
204
201
|
});
|
|
205
202
|
}
|
|
@@ -327,23 +324,11 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
327
324
|
break;
|
|
328
325
|
}
|
|
329
326
|
return _context5.abrupt("return", {
|
|
330
|
-
type: "clientCalc",
|
|
331
327
|
isAvailable: false,
|
|
332
328
|
productList: this.store.productList || [],
|
|
333
329
|
discountList: this.getDiscountList()
|
|
334
330
|
});
|
|
335
331
|
case 10:
|
|
336
|
-
if (resultDiscountList.length) {
|
|
337
|
-
_context5.next = 12;
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
return _context5.abrupt("return", {
|
|
341
|
-
type: "server",
|
|
342
|
-
isAvailable: false,
|
|
343
|
-
productList: this.store.productList || [],
|
|
344
|
-
discountList: this.getDiscountList()
|
|
345
|
-
});
|
|
346
|
-
case 12:
|
|
347
332
|
withScanList = resultDiscountList.map(function (item) {
|
|
348
333
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
349
334
|
isScan: true
|
|
@@ -359,39 +344,37 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
359
344
|
discountList: this.getDiscountList()
|
|
360
345
|
}, newProductList = _ref3.productList, newDiscountList = _ref3.discountList, isAvailable = _ref3.isAvailable;
|
|
361
346
|
if (!isAvailable) {
|
|
362
|
-
_context5.next =
|
|
347
|
+
_context5.next = 18;
|
|
363
348
|
break;
|
|
364
349
|
}
|
|
365
350
|
this.setDiscountList(newDiscountList || []);
|
|
366
351
|
this.setProductList(newProductList || []);
|
|
367
352
|
if (!(this.isWalkIn() && resultDiscountList.length && ((_this$options$otherPa6 = this.options.otherParams) === null || _this$options$otherPa6 === void 0 ? void 0 : _this$options$otherPa6.platform) === 'shop')) {
|
|
368
|
-
_context5.next =
|
|
353
|
+
_context5.next = 18;
|
|
369
354
|
break;
|
|
370
355
|
}
|
|
371
|
-
_context5.next =
|
|
356
|
+
_context5.next = 18;
|
|
372
357
|
return this.getCustomerWallet(resultDiscountList[0].customer_id);
|
|
373
|
-
case
|
|
358
|
+
case 18:
|
|
374
359
|
return _context5.abrupt("return", {
|
|
375
|
-
type: "clientCalc",
|
|
376
360
|
isAvailable: isAvailable || false,
|
|
377
361
|
productList: newProductList || this.store.productList || [],
|
|
378
362
|
discountList: newDiscountList || this.getDiscountList()
|
|
379
363
|
});
|
|
380
|
-
case
|
|
381
|
-
_context5.prev =
|
|
364
|
+
case 21:
|
|
365
|
+
_context5.prev = 21;
|
|
382
366
|
_context5.t1 = _context5["catch"](0);
|
|
383
367
|
console.error('[ShopDiscount] 扫码出错:', _context5.t1);
|
|
384
368
|
return _context5.abrupt("return", {
|
|
385
|
-
type: "clientCalc",
|
|
386
369
|
isAvailable: false,
|
|
387
370
|
productList: this.store.productList || [],
|
|
388
371
|
discountList: this.getDiscountList()
|
|
389
372
|
});
|
|
390
|
-
case
|
|
373
|
+
case 25:
|
|
391
374
|
case "end":
|
|
392
375
|
return _context5.stop();
|
|
393
376
|
}
|
|
394
|
-
}, _callee5, this, [[0,
|
|
377
|
+
}, _callee5, this, [[0, 21]]);
|
|
395
378
|
}));
|
|
396
379
|
function scanCode(_x4) {
|
|
397
380
|
return _scanCode.apply(this, arguments);
|
|
@@ -446,42 +429,25 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
446
429
|
}, {
|
|
447
430
|
key: "setDiscountList",
|
|
448
431
|
value: function setDiscountList(discountList) {
|
|
449
|
-
var
|
|
450
|
-
_this$store$discount5;
|
|
432
|
+
var _this$store$discount5;
|
|
451
433
|
var productList = this.store.productList || [];
|
|
452
434
|
var editModeDiscountList = [];
|
|
453
435
|
productList.forEach(function (item) {
|
|
454
436
|
if (item.booking_id) {
|
|
455
|
-
var _this3$hooks;
|
|
456
|
-
var product = (_this3$hooks = _this3.hooks) === null || _this3$hooks === void 0 ? void 0 : _this3$hooks.getProduct(item);
|
|
457
437
|
(item.discount_list || []).forEach(function (discount) {
|
|
458
|
-
if (discount.id &&
|
|
459
|
-
var
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
discount.tag = discount.type;
|
|
472
|
-
}
|
|
473
|
-
editModeDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
|
|
474
|
-
isEditMode: true,
|
|
475
|
-
limited_relation_product_data: {},
|
|
476
|
-
savedAmount: discount.amount * ((product === null || product === void 0 ? void 0 : product.num) || 1),
|
|
477
|
-
isAvailable: true,
|
|
478
|
-
id: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) || discount.id,
|
|
479
|
-
format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
|
|
480
|
-
isDisabled: true,
|
|
481
|
-
isSelected: true,
|
|
482
|
-
product_id: ((_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.product_id) || discount.product_id
|
|
483
|
-
}));
|
|
484
|
-
}
|
|
438
|
+
if (discount.id && discount.type === 'good_pass') {
|
|
439
|
+
var _discount$discount, _discount$discount2, _discount$discount3;
|
|
440
|
+
editModeDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
|
|
441
|
+
isEditMode: true,
|
|
442
|
+
limited_relation_product_data: {},
|
|
443
|
+
savedAmount: discount.amount,
|
|
444
|
+
isAvailable: true,
|
|
445
|
+
id: ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id,
|
|
446
|
+
format_title: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.title) || discount.format_title,
|
|
447
|
+
isDisabled: true,
|
|
448
|
+
isSelected: true,
|
|
449
|
+
product_id: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.product_id) || discount.product_id
|
|
450
|
+
}));
|
|
485
451
|
}
|
|
486
452
|
});
|
|
487
453
|
}
|
|
@@ -489,32 +455,6 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
489
455
|
var newDiscountList = [].concat(editModeDiscountList, _toConsumableArray(discountList.filter(function (item) {
|
|
490
456
|
return !item.isDisabled;
|
|
491
457
|
})));
|
|
492
|
-
var allUsedProductIds = newDiscountList.map(function (n) {
|
|
493
|
-
var _n$appliedProductDeta;
|
|
494
|
-
return n.isSelected ? (_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
|
|
495
|
-
var _n$discount;
|
|
496
|
-
return (_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.product_id;
|
|
497
|
-
}) : [];
|
|
498
|
-
}).flat();
|
|
499
|
-
newDiscountList.forEach(function (item) {
|
|
500
|
-
var _item$applicableProdu;
|
|
501
|
-
var isProductFree = function isProductFree(id) {
|
|
502
|
-
var _this3$hooks2;
|
|
503
|
-
var targetProduct = productList.find(function (n) {
|
|
504
|
-
return n.id === id;
|
|
505
|
-
});
|
|
506
|
-
var product = (_this3$hooks2 = _this3.hooks) === null || _this3$hooks2 === void 0 ? void 0 : _this3$hooks2.getProduct(targetProduct);
|
|
507
|
-
return Number(product === null || product === void 0 ? void 0 : product.price) === 0;
|
|
508
|
-
};
|
|
509
|
-
var isAllProductUsedOrFree = (_item$applicableProdu = item.applicableProductIds) === null || _item$applicableProdu === void 0 ? void 0 : _item$applicableProdu.every(function (id) {
|
|
510
|
-
return (allUsedProductIds === null || allUsedProductIds === void 0 ? void 0 : allUsedProductIds.includes(id)) || isProductFree(id);
|
|
511
|
-
});
|
|
512
|
-
if (!item.isSelected && isAllProductUsedOrFree) {
|
|
513
|
-
item.isDisabledForProductUsed = true;
|
|
514
|
-
} else {
|
|
515
|
-
item.isDisabledForProductUsed = false;
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
458
|
(_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 || _this$store$discount5.setDiscountList(newDiscountList);
|
|
519
459
|
this.emitDiscountListChange(newDiscountList);
|
|
520
460
|
return newDiscountList;
|
|
@@ -533,14 +473,14 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
533
473
|
key: "getCustomerWallet",
|
|
534
474
|
value: function () {
|
|
535
475
|
var _getCustomerWallet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(id) {
|
|
536
|
-
var result, customer;
|
|
476
|
+
var result, _result$data, wallet_pass_list, customer;
|
|
537
477
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
538
478
|
while (1) switch (_context7.prev = _context7.next) {
|
|
539
479
|
case 0:
|
|
540
480
|
_context7.prev = 0;
|
|
541
481
|
_context7.next = 3;
|
|
542
|
-
return this.request.get("/customer/info/".concat(id), {
|
|
543
|
-
|
|
482
|
+
return this.request.get("/customer/info/wallet/".concat(id), {
|
|
483
|
+
wallet_pass_tags: ['good_pass']
|
|
544
484
|
});
|
|
545
485
|
case 3:
|
|
546
486
|
result = _context7.sent;
|
|
@@ -548,7 +488,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
548
488
|
_context7.next = 9;
|
|
549
489
|
break;
|
|
550
490
|
}
|
|
551
|
-
|
|
491
|
+
_result$data = result.data, wallet_pass_list = _result$data.wallet_pass_list, customer = _objectWithoutProperties(_result$data, _excluded);
|
|
552
492
|
this.setCustomer(customer);
|
|
553
493
|
_context7.next = 9;
|
|
554
494
|
return this.core.effects.emit(ShopDiscountHooks.onScanCustomerChange, customer);
|
|
@@ -586,8 +526,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
586
526
|
return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.loadPrepareConfig({
|
|
587
527
|
customer_id: customerId,
|
|
588
528
|
action: 'create',
|
|
589
|
-
with_good_pass: 1
|
|
590
|
-
with_discount_card: 1
|
|
529
|
+
with_good_pass: 1
|
|
591
530
|
});
|
|
592
531
|
case 4:
|
|
593
532
|
goodPassList = _context8.sent;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
3
|
import { CartItem, CartModuleAPI, ECartItemCheckType, ECartItemInfoType, IAddItemParams, IUpdateItemParams } from './types';
|
|
4
|
-
import { Account } from '../Account';
|
|
5
4
|
export * from './types';
|
|
6
5
|
/**
|
|
7
6
|
* 购物车模块实现
|
|
@@ -68,17 +67,4 @@ export declare class CartModule extends BaseModule implements Module, CartModule
|
|
|
68
67
|
clear(): void;
|
|
69
68
|
storeChange(): void;
|
|
70
69
|
checkCartItemByType(cartItem: CartItem, type: ECartItemCheckType): boolean;
|
|
71
|
-
/**
|
|
72
|
-
* 基于rowkey 合并商品,目前只有普通商品需要合并
|
|
73
|
-
*
|
|
74
|
-
* @param {string} rowKey
|
|
75
|
-
* @param {number} quantity
|
|
76
|
-
* @return {*}
|
|
77
|
-
* @memberof CartModule
|
|
78
|
-
*/
|
|
79
|
-
mergeCartItemByRowKey(params: {
|
|
80
|
-
rowKey?: string;
|
|
81
|
-
quantity?: number;
|
|
82
|
-
account?: Account;
|
|
83
|
-
}): boolean;
|
|
84
70
|
}
|
|
@@ -27,7 +27,6 @@ var import_BaseModule = require("../BaseModule");
|
|
|
27
27
|
var import_types = require("./types");
|
|
28
28
|
var import_utils = require("./utils");
|
|
29
29
|
var import_lodash_es = require("lodash-es");
|
|
30
|
-
var import_utils2 = require("../Product/utils");
|
|
31
30
|
__reExport(Cart_exports, require("./types"), module.exports);
|
|
32
31
|
var CartModule = class extends import_BaseModule.BaseModule {
|
|
33
32
|
constructor(name, version) {
|
|
@@ -311,37 +310,6 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
311
310
|
}
|
|
312
311
|
return result;
|
|
313
312
|
}
|
|
314
|
-
/**
|
|
315
|
-
* 基于rowkey 合并商品,目前只有普通商品需要合并
|
|
316
|
-
*
|
|
317
|
-
* @param {string} rowKey
|
|
318
|
-
* @param {number} quantity
|
|
319
|
-
* @return {*}
|
|
320
|
-
* @memberof CartModule
|
|
321
|
-
*/
|
|
322
|
-
mergeCartItemByRowKey(params) {
|
|
323
|
-
const { rowKey, quantity, account } = params;
|
|
324
|
-
let flag = false;
|
|
325
|
-
const cartItems = this.getItems();
|
|
326
|
-
const targetCartItem = cartItems.find(
|
|
327
|
-
(n) => {
|
|
328
|
-
var _a;
|
|
329
|
-
return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
|
|
330
|
-
}
|
|
331
|
-
);
|
|
332
|
-
const isSameAccount = (account == null ? void 0 : account.id) === (targetCartItem == null ? void 0 : targetCartItem.holder_id);
|
|
333
|
-
if (rowKey && targetCartItem && (0, import_utils2.isNormalProduct)(targetCartItem._productOrigin) && isSameAccount) {
|
|
334
|
-
this.updateItem({
|
|
335
|
-
_id: targetCartItem._id,
|
|
336
|
-
product: {
|
|
337
|
-
...targetCartItem._productOrigin,
|
|
338
|
-
quantity: (targetCartItem.num || 1) + (quantity || 1)
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
flag = true;
|
|
342
|
-
}
|
|
343
|
-
return flag;
|
|
344
|
-
}
|
|
345
313
|
};
|
|
346
314
|
// Annotate the CommonJS export names for ESM import in node:
|
|
347
315
|
0 && (module.exports = {
|
|
@@ -194,7 +194,7 @@ var getProductOriginTotalPrice = (params) => {
|
|
|
194
194
|
return accumulator + Number(currentValue.price) * Number(currentValue.num);
|
|
195
195
|
}, price);
|
|
196
196
|
}
|
|
197
|
-
return price;
|
|
197
|
+
return price * num;
|
|
198
198
|
};
|
|
199
199
|
var formatOptions = (options) => {
|
|
200
200
|
if (!(options == null ? void 0 : options.length))
|