@pisell/pisellos 0.0.26 → 0.0.28
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/AccountList/index.js +1 -0
- package/dist/modules/Cart/index.js +7 -9
- package/dist/solution/BookingByStep/index.d.ts +4 -1
- package/dist/solution/BookingByStep/index.js +112 -83
- package/dist/solution/BookingByStep/utils/resources.js +3 -0
- package/dist/solution/ShopDiscount/index.js +0 -1
- package/lib/modules/AccountList/index.js +1 -1
- package/lib/modules/Cart/index.js +0 -2
- package/lib/solution/BookingByStep/index.d.ts +4 -1
- package/lib/solution/BookingByStep/index.js +47 -46
- package/lib/solution/BookingByStep/utils/resources.js +3 -0
- package/lib/solution/ShopDiscount/index.js +0 -1
- package/package.json +1 -1
|
@@ -61,7 +61,6 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
61
61
|
case 0:
|
|
62
62
|
this.core = core;
|
|
63
63
|
this.store = options.store;
|
|
64
|
-
debugger;
|
|
65
64
|
if (Array.isArray((_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
|
|
66
65
|
this.store.list = options.initialState.list;
|
|
67
66
|
this.core.effects.emit("".concat(this.name, ":changed"), this.store.list);
|
|
@@ -80,20 +79,20 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
80
79
|
this.request = core.getPlugin("request");
|
|
81
80
|
this.window = core.getPlugin("window");
|
|
82
81
|
if (this.request) {
|
|
83
|
-
_context.next =
|
|
82
|
+
_context.next = 9;
|
|
84
83
|
break;
|
|
85
84
|
}
|
|
86
85
|
throw new Error("购物车模块需要 request 插件支持");
|
|
87
|
-
case
|
|
86
|
+
case 9:
|
|
88
87
|
if (this.window) {
|
|
89
|
-
_context.next =
|
|
88
|
+
_context.next = 11;
|
|
90
89
|
break;
|
|
91
90
|
}
|
|
92
91
|
throw new Error("购物车模块需要 window 插件支持");
|
|
93
|
-
case
|
|
92
|
+
case 11:
|
|
94
93
|
// this.store.temp = {};
|
|
95
94
|
console.log("[CartModule] 初始化完成");
|
|
96
|
-
case
|
|
95
|
+
case 12:
|
|
97
96
|
case "end":
|
|
98
97
|
return _context.stop();
|
|
99
98
|
}
|
|
@@ -116,7 +115,6 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
116
115
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
117
116
|
while (1) switch (_context2.prev = _context2.next) {
|
|
118
117
|
case 0:
|
|
119
|
-
debugger;
|
|
120
118
|
account = params.account, product = params.product, bundle = params.bundle, options = params.options; // 生成一个唯一的 ID
|
|
121
119
|
cartItem = {
|
|
122
120
|
_id: getUniqueId(),
|
|
@@ -143,9 +141,9 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
143
141
|
this.store.list = items;
|
|
144
142
|
|
|
145
143
|
// 触发事件
|
|
146
|
-
_context2.next =
|
|
144
|
+
_context2.next = 8;
|
|
147
145
|
return this.core.effects.emit("".concat(this.name, ":onAddItem"), cartItem);
|
|
148
|
-
case
|
|
146
|
+
case 8:
|
|
149
147
|
case "end":
|
|
150
148
|
return _context2.stop();
|
|
151
149
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Module, PisellCore } from "../../types";
|
|
2
2
|
import { BaseModule } from "../../modules/BaseModule";
|
|
3
|
+
import { Response } from "../../plugins";
|
|
3
4
|
import { BookingByStepState } from "./types";
|
|
4
5
|
import { CartItem, IUpdateItemParams, ProductData } from "../../modules";
|
|
5
6
|
import { Account } from "../../modules/Account/types";
|
|
@@ -59,6 +60,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
59
60
|
getProducts(): Promise<ProductData[]>;
|
|
60
61
|
setLoginAccount(accountId: string, accountInfo: Account): Promise<void>;
|
|
61
62
|
generateCartData(): Promise<void>;
|
|
63
|
+
getFreeProduct(id: string | number): Promise<Response<any>>;
|
|
62
64
|
submitOrder(): Promise<void>;
|
|
63
65
|
pay(): Promise<void>;
|
|
64
66
|
getPayInfo(): Promise<void>;
|
|
@@ -104,10 +106,11 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
104
106
|
timeSlots: any[];
|
|
105
107
|
selectedResource: any;
|
|
106
108
|
} | undefined;
|
|
107
|
-
autoSelectAccountResources({ holder_id, resources_code, timeSlots, }: {
|
|
109
|
+
autoSelectAccountResources({ holder_id, resources_code, timeSlots, countMap }: {
|
|
108
110
|
holder_id: string;
|
|
109
111
|
resources_code: string | number;
|
|
110
112
|
timeSlots?: TimeSliceItem;
|
|
113
|
+
countMap: Record<number, number>;
|
|
111
114
|
}): {
|
|
112
115
|
selectedResource: any;
|
|
113
116
|
timeSlots?: undefined;
|
|
@@ -75,8 +75,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
75
75
|
}
|
|
76
76
|
throw new Error("bookingByStep解决方案需要 request 插件支持");
|
|
77
77
|
case 9:
|
|
78
|
-
debugger;
|
|
79
|
-
|
|
80
78
|
// 如果有传 cacheid,默认需要收集上面这些模块里用户操作选中的数据
|
|
81
79
|
// 并且在上面 registerModule 的时候,读取 sessionStroage 里的数据,塞进默认值
|
|
82
80
|
targetCacheData = {};
|
|
@@ -107,7 +105,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
107
105
|
}
|
|
108
106
|
});
|
|
109
107
|
this.core.effects.emit(BookingByStepHooks.onInited, {});
|
|
110
|
-
case
|
|
108
|
+
case 14:
|
|
111
109
|
case "end":
|
|
112
110
|
return _context.stop();
|
|
113
111
|
}
|
|
@@ -481,16 +479,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
481
479
|
value: function () {
|
|
482
480
|
var _setLoginAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(accountId, accountInfo) {
|
|
483
481
|
var _this4 = this;
|
|
484
|
-
var account, cartItems;
|
|
482
|
+
var account, stateAccountId, cartItems;
|
|
485
483
|
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
486
484
|
while (1) switch (_context11.prev = _context11.next) {
|
|
487
485
|
case 0:
|
|
488
486
|
account = this.store.accountList.getAccount(accountId);
|
|
489
487
|
if (!account) {
|
|
490
|
-
_context11.next =
|
|
488
|
+
_context11.next = 9;
|
|
491
489
|
break;
|
|
492
490
|
}
|
|
493
|
-
|
|
491
|
+
stateAccountId = account.getId();
|
|
494
492
|
account.setAccountInfo(accountInfo);
|
|
495
493
|
// 然后去购物车,把原先关联了 holder_id 为 accountId 的商品,替换为 holder_id = accountInfo.id
|
|
496
494
|
cartItems = this.store.cart.getItems();
|
|
@@ -502,11 +500,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
502
500
|
});
|
|
503
501
|
}
|
|
504
502
|
});
|
|
505
|
-
|
|
503
|
+
this.store.accountList.updateAccountListById(stateAccountId, accountInfo);
|
|
504
|
+
_context11.next = 10;
|
|
506
505
|
break;
|
|
507
|
-
case 8:
|
|
508
|
-
throw new Error("\u6CA1\u6709\u627E\u5230".concat(accountId, "\u8D26\u6237"));
|
|
509
506
|
case 9:
|
|
507
|
+
throw new Error("\u6CA1\u6709\u627E\u5230".concat(accountId, "\u8D26\u6237"));
|
|
508
|
+
case 10:
|
|
510
509
|
case "end":
|
|
511
510
|
return _context11.stop();
|
|
512
511
|
}
|
|
@@ -533,17 +532,42 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
533
532
|
return _generateCartData.apply(this, arguments);
|
|
534
533
|
}
|
|
535
534
|
return generateCartData;
|
|
536
|
-
}() //
|
|
535
|
+
}() // 免费领取商品相关逻辑,上线了来不及加了,先放在这,后面要做到 payment 里面的
|
|
537
536
|
}, {
|
|
538
|
-
key: "
|
|
537
|
+
key: "getFreeProduct",
|
|
539
538
|
value: function () {
|
|
540
|
-
var
|
|
541
|
-
var
|
|
539
|
+
var _getFreeProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(id) {
|
|
540
|
+
var res;
|
|
542
541
|
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
543
542
|
while (1) switch (_context13.prev = _context13.next) {
|
|
544
543
|
case 0:
|
|
545
|
-
|
|
546
|
-
|
|
544
|
+
_context13.next = 2;
|
|
545
|
+
return this.request.post("/pay/order/free-pay/".concat(id));
|
|
546
|
+
case 2:
|
|
547
|
+
res = _context13.sent;
|
|
548
|
+
return _context13.abrupt("return", res);
|
|
549
|
+
case 4:
|
|
550
|
+
case "end":
|
|
551
|
+
return _context13.stop();
|
|
552
|
+
}
|
|
553
|
+
}, _callee13, this);
|
|
554
|
+
}));
|
|
555
|
+
function getFreeProduct(_x9) {
|
|
556
|
+
return _getFreeProduct.apply(this, arguments);
|
|
557
|
+
}
|
|
558
|
+
return getFreeProduct;
|
|
559
|
+
}() // 购物车提交订单
|
|
560
|
+
}, {
|
|
561
|
+
key: "submitOrder",
|
|
562
|
+
value: function () {
|
|
563
|
+
var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
564
|
+
var cartItems, newCartItems;
|
|
565
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
566
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
567
|
+
case 0:
|
|
568
|
+
cartItems = this.store.cart.getItems();
|
|
569
|
+
newCartItems = cloneDeep(cartItems); // 先整个临时的逻辑,把购物车里所有商品的资源给他格式化一下
|
|
570
|
+
newCartItems.forEach(function (item) {
|
|
547
571
|
item._origin.resources = item._origin.resources.map(function (n) {
|
|
548
572
|
var newResourcesItem = cloneDeep(n);
|
|
549
573
|
delete newResourcesItem.id;
|
|
@@ -552,16 +576,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
552
576
|
return _objectSpread({}, newResourcesItem);
|
|
553
577
|
});
|
|
554
578
|
});
|
|
555
|
-
return
|
|
579
|
+
return _context14.abrupt("return", this.store.order.commitOrder({
|
|
556
580
|
query: {
|
|
557
|
-
cartItems:
|
|
581
|
+
cartItems: newCartItems
|
|
558
582
|
}
|
|
559
583
|
}));
|
|
560
|
-
case
|
|
584
|
+
case 4:
|
|
561
585
|
case "end":
|
|
562
|
-
return
|
|
586
|
+
return _context14.stop();
|
|
563
587
|
}
|
|
564
|
-
},
|
|
588
|
+
}, _callee14, this);
|
|
565
589
|
}));
|
|
566
590
|
function submitOrder() {
|
|
567
591
|
return _submitOrder.apply(this, arguments);
|
|
@@ -571,14 +595,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
571
595
|
}, {
|
|
572
596
|
key: "pay",
|
|
573
597
|
value: function () {
|
|
574
|
-
var _pay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
575
|
-
return _regeneratorRuntime().wrap(function
|
|
576
|
-
while (1) switch (
|
|
598
|
+
var _pay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
|
599
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
600
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
577
601
|
case 0:
|
|
578
602
|
case "end":
|
|
579
|
-
return
|
|
603
|
+
return _context15.stop();
|
|
580
604
|
}
|
|
581
|
-
},
|
|
605
|
+
}, _callee15);
|
|
582
606
|
}));
|
|
583
607
|
function pay() {
|
|
584
608
|
return _pay.apply(this, arguments);
|
|
@@ -588,14 +612,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
588
612
|
}, {
|
|
589
613
|
key: "getPayInfo",
|
|
590
614
|
value: function () {
|
|
591
|
-
var _getPayInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
592
|
-
return _regeneratorRuntime().wrap(function
|
|
593
|
-
while (1) switch (
|
|
615
|
+
var _getPayInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
|
|
616
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
617
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
594
618
|
case 0:
|
|
595
619
|
case "end":
|
|
596
|
-
return
|
|
620
|
+
return _context16.stop();
|
|
597
621
|
}
|
|
598
|
-
},
|
|
622
|
+
}, _callee16);
|
|
599
623
|
}));
|
|
600
624
|
function getPayInfo() {
|
|
601
625
|
return _getPayInfo.apply(this, arguments);
|
|
@@ -605,15 +629,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
605
629
|
}, {
|
|
606
630
|
key: "setOtherParams",
|
|
607
631
|
value: function () {
|
|
608
|
-
var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
632
|
+
var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
|
|
609
633
|
var _ref4,
|
|
610
634
|
_ref4$cover,
|
|
611
635
|
cover,
|
|
612
|
-
|
|
613
|
-
return _regeneratorRuntime().wrap(function
|
|
614
|
-
while (1) switch (
|
|
636
|
+
_args17 = arguments;
|
|
637
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
638
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
615
639
|
case 0:
|
|
616
|
-
_ref4 =
|
|
640
|
+
_ref4 = _args17.length > 1 && _args17[1] !== undefined ? _args17[1] : {}, _ref4$cover = _ref4.cover, cover = _ref4$cover === void 0 ? false : _ref4$cover;
|
|
617
641
|
if (cover) {
|
|
618
642
|
this.otherParams = params;
|
|
619
643
|
} else {
|
|
@@ -621,11 +645,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
621
645
|
}
|
|
622
646
|
case 2:
|
|
623
647
|
case "end":
|
|
624
|
-
return
|
|
648
|
+
return _context17.stop();
|
|
625
649
|
}
|
|
626
|
-
},
|
|
650
|
+
}, _callee17, this);
|
|
627
651
|
}));
|
|
628
|
-
function setOtherParams(
|
|
652
|
+
function setOtherParams(_x10) {
|
|
629
653
|
return _setOtherParams.apply(this, arguments);
|
|
630
654
|
}
|
|
631
655
|
return setOtherParams;
|
|
@@ -633,16 +657,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
633
657
|
}, {
|
|
634
658
|
key: "getOtherParams",
|
|
635
659
|
value: function () {
|
|
636
|
-
var _getOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
637
|
-
return _regeneratorRuntime().wrap(function
|
|
638
|
-
while (1) switch (
|
|
660
|
+
var _getOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
|
|
661
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
662
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
639
663
|
case 0:
|
|
640
|
-
return
|
|
664
|
+
return _context18.abrupt("return", this.otherParams);
|
|
641
665
|
case 1:
|
|
642
666
|
case "end":
|
|
643
|
-
return
|
|
667
|
+
return _context18.stop();
|
|
644
668
|
}
|
|
645
|
-
},
|
|
669
|
+
}, _callee18, this);
|
|
646
670
|
}));
|
|
647
671
|
function getOtherParams() {
|
|
648
672
|
return _getOtherParams.apply(this, arguments);
|
|
@@ -893,7 +917,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
893
917
|
var _accountCartItems$0$_, _accountCartItems$;
|
|
894
918
|
var holder_id = _ref7.holder_id,
|
|
895
919
|
resources_code = _ref7.resources_code,
|
|
896
|
-
timeSlots = _ref7.timeSlots
|
|
920
|
+
timeSlots = _ref7.timeSlots,
|
|
921
|
+
countMap = _ref7.countMap;
|
|
897
922
|
var dateRange = this.store.date.getDateRange();
|
|
898
923
|
var cartItems = this.store.cart.getItems();
|
|
899
924
|
// 取到账号下所有的商品,然后根据商品的 duration 和资源列表,获取所有可用的资源
|
|
@@ -935,6 +960,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
935
960
|
try {
|
|
936
961
|
var _loop2 = function _loop2() {
|
|
937
962
|
var n = _step2.value;
|
|
963
|
+
var recordCount = countMap[n.id] || 0;
|
|
938
964
|
var canUseTime = n.times.find(function (item) {
|
|
939
965
|
return getIsUsableByTimeItem({
|
|
940
966
|
timeSlice: item,
|
|
@@ -943,7 +969,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
943
969
|
end_time: end_time
|
|
944
970
|
},
|
|
945
971
|
resource: n,
|
|
946
|
-
currentCount: 1
|
|
972
|
+
currentCount: recordCount + 1
|
|
947
973
|
});
|
|
948
974
|
});
|
|
949
975
|
if (canUseTime) {
|
|
@@ -998,6 +1024,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
998
1024
|
var resourcesMap = getResourcesMap(resources);
|
|
999
1025
|
// 一个账号一个账号处理
|
|
1000
1026
|
var errorList = [];
|
|
1027
|
+
var selectResourcesMap = {};
|
|
1001
1028
|
this.store.accountList.getAccounts().forEach(function (account) {
|
|
1002
1029
|
var cartItems = _this7.store.cart.getCartByAccount(account.getId());
|
|
1003
1030
|
// 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
|
|
@@ -1008,9 +1035,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1008
1035
|
var res = _this7.autoSelectAccountResources({
|
|
1009
1036
|
holder_id: item.holder_id,
|
|
1010
1037
|
resources_code: resources_code,
|
|
1011
|
-
timeSlots: timeSlots
|
|
1038
|
+
timeSlots: timeSlots,
|
|
1039
|
+
countMap: selectResourcesMap
|
|
1012
1040
|
});
|
|
1013
1041
|
if (res !== null && res !== void 0 && res.selectedResource) {
|
|
1042
|
+
if (!selectResourcesMap[res.selectedResource.id]) {
|
|
1043
|
+
selectResourcesMap[res.selectedResource.id] = 1;
|
|
1044
|
+
} else {
|
|
1045
|
+
selectResourcesMap[res.selectedResource.id]++;
|
|
1046
|
+
}
|
|
1014
1047
|
console.log(_this7.store.cart.getItems());
|
|
1015
1048
|
_this7.store.cart.updateItem({
|
|
1016
1049
|
_id: item._id,
|
|
@@ -1099,47 +1132,43 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1099
1132
|
}
|
|
1100
1133
|
|
|
1101
1134
|
// 提交时间切片,绑定到对应购物车的商品上,更新购物车
|
|
1102
|
-
// submitTimeSlot({
|
|
1103
|
-
// resourceProductData,
|
|
1104
|
-
// selectedResources,
|
|
1105
|
-
// timeSlots,
|
|
1106
|
-
// }: {
|
|
1107
|
-
// resourceProductData: any;
|
|
1108
|
-
// selectedResources: any[];
|
|
1109
|
-
// timeSlots: TimeSliceItem;
|
|
1110
|
-
// }) {
|
|
1111
|
-
// const newResources = cloneDeep(selectedResources);
|
|
1112
|
-
// newResources.forEach((n) => {
|
|
1113
|
-
// n.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
|
|
1114
|
-
// n.endTime = dayjs(n.startTime)
|
|
1115
|
-
// .add(
|
|
1116
|
-
// resourceProductData.product.duration.value,
|
|
1117
|
-
// resourceProductData.product.duration.type
|
|
1118
|
-
// )
|
|
1119
|
-
// .format("YYYY-MM-DD HH:mm");
|
|
1120
|
-
// delete n.times;
|
|
1121
|
-
// });
|
|
1122
|
-
// this.store.cart.updateItem({
|
|
1123
|
-
// _id: resourceProductData._id,
|
|
1124
|
-
// resources: newResources,
|
|
1125
|
-
// });
|
|
1126
|
-
// }
|
|
1127
1135
|
}, {
|
|
1128
1136
|
key: "submitTimeSlot",
|
|
1129
1137
|
value: function submitTimeSlot(timeSlots) {
|
|
1130
1138
|
var _this9 = this;
|
|
1139
|
+
// 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
|
|
1131
1140
|
var cartItems = this.store.cart.getItems();
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1141
|
+
|
|
1142
|
+
// 按账号分组
|
|
1143
|
+
var itemsByAccount = cartItems.reduce(function (acc, item) {
|
|
1144
|
+
var holderId = item.holder_id;
|
|
1145
|
+
if (!acc[holderId]) {
|
|
1146
|
+
acc[holderId] = [];
|
|
1147
|
+
}
|
|
1148
|
+
acc[holderId].push(item);
|
|
1149
|
+
return acc;
|
|
1150
|
+
}, {});
|
|
1151
|
+
|
|
1152
|
+
// 处理每个账号的商品
|
|
1153
|
+
Object.values(itemsByAccount).forEach(function (accountItems) {
|
|
1154
|
+
var currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
|
|
1155
|
+
accountItems.forEach(function (item, index) {
|
|
1156
|
+
var newResources = cloneDeep(item._origin.resources);
|
|
1157
|
+
newResources.forEach(function (resource) {
|
|
1158
|
+
var _item$_productOrigin$2, _item$_productOrigin4, _ref8, _item$_productOrigin5;
|
|
1159
|
+
resource.startTime = currentStartTime;
|
|
1160
|
+
resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$2 = (_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.duration) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.value) !== null && _item$_productOrigin$2 !== void 0 ? _item$_productOrigin$2 : 0, (_ref8 = (_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.duration) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.type) !== null && _ref8 !== void 0 ? _ref8 : "minutes").format("YYYY-MM-DD HH:mm");
|
|
1161
|
+
delete resource.times;
|
|
1162
|
+
});
|
|
1163
|
+
_this9.store.cart.updateItem({
|
|
1164
|
+
_id: item._id,
|
|
1165
|
+
resources: newResources
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1168
|
+
// 更新下一个商品的开始时间为当前商品的结束时间
|
|
1169
|
+
if (index < accountItems.length - 1) {
|
|
1170
|
+
currentStartTime = newResources[0].endTime;
|
|
1171
|
+
}
|
|
1143
1172
|
});
|
|
1144
1173
|
});
|
|
1145
1174
|
}
|
|
@@ -110,6 +110,9 @@ var checkCapacity = function checkCapacity(_ref) {
|
|
|
110
110
|
resource = _ref.resource,
|
|
111
111
|
_ref$currentCount = _ref.currentCount,
|
|
112
112
|
currentCount = _ref$currentCount === void 0 ? 1 : _ref$currentCount;
|
|
113
|
+
if (currentCount > resource.capacity) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
113
116
|
var conflict = (event_list || []).filter(function (d) {
|
|
114
117
|
return isConflict({
|
|
115
118
|
start_at: d.start_at,
|
|
@@ -165,7 +165,6 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
165
165
|
targetCacheData = data[this.options.otherParams.cacheId];
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
debugger;
|
|
169
168
|
// 注册优惠模块
|
|
170
169
|
var discount = new DiscountModule("".concat(this.name, "_discount"));
|
|
171
170
|
this.core.registerModule(discount, {
|
|
@@ -116,7 +116,7 @@ var AccountListModule = class extends import_BaseModule.BaseModule {
|
|
|
116
116
|
}
|
|
117
117
|
return account;
|
|
118
118
|
});
|
|
119
|
-
this.core.effects.emit(`${this.name}:changed`, { value: this.store.accountList });
|
|
119
|
+
this.core.effects.emit(`${this.name}:changed`, { path: "accounts", value: this.store.accountList });
|
|
120
120
|
}
|
|
121
121
|
async removeAccount(id) {
|
|
122
122
|
try {
|
|
@@ -42,7 +42,6 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
42
42
|
var _a, _b, _c;
|
|
43
43
|
this.core = core;
|
|
44
44
|
this.store = options.store;
|
|
45
|
-
debugger;
|
|
46
45
|
if (Array.isArray((_a = options.initialState) == null ? void 0 : _a.list)) {
|
|
47
46
|
this.store.list = options.initialState.list;
|
|
48
47
|
this.core.effects.emit(`${this.name}:changed`, this.store.list);
|
|
@@ -70,7 +69,6 @@ var CartModule = class extends import_BaseModule.BaseModule {
|
|
|
70
69
|
* 添加商品到购物车
|
|
71
70
|
*/
|
|
72
71
|
async addItem(params) {
|
|
73
|
-
debugger;
|
|
74
72
|
const { account, product, bundle, options } = params;
|
|
75
73
|
let cartItem = {
|
|
76
74
|
_id: (0, import_utils.getUniqueId)(),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Module, PisellCore } from "../../types";
|
|
2
2
|
import { BaseModule } from "../../modules/BaseModule";
|
|
3
|
+
import { Response } from "../../plugins";
|
|
3
4
|
import { BookingByStepState } from "./types";
|
|
4
5
|
import { CartItem, IUpdateItemParams, ProductData } from "../../modules";
|
|
5
6
|
import { Account } from "../../modules/Account/types";
|
|
@@ -59,6 +60,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
59
60
|
getProducts(): Promise<ProductData[]>;
|
|
60
61
|
setLoginAccount(accountId: string, accountInfo: Account): Promise<void>;
|
|
61
62
|
generateCartData(): Promise<void>;
|
|
63
|
+
getFreeProduct(id: string | number): Promise<Response<any>>;
|
|
62
64
|
submitOrder(): Promise<void>;
|
|
63
65
|
pay(): Promise<void>;
|
|
64
66
|
getPayInfo(): Promise<void>;
|
|
@@ -104,10 +106,11 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
104
106
|
timeSlots: any[];
|
|
105
107
|
selectedResource: any;
|
|
106
108
|
} | undefined;
|
|
107
|
-
autoSelectAccountResources({ holder_id, resources_code, timeSlots, }: {
|
|
109
|
+
autoSelectAccountResources({ holder_id, resources_code, timeSlots, countMap }: {
|
|
108
110
|
holder_id: string;
|
|
109
111
|
resources_code: string | number;
|
|
110
112
|
timeSlots?: TimeSliceItem;
|
|
113
|
+
countMap: Record<number, number>;
|
|
111
114
|
}): {
|
|
112
115
|
selectedResource: any;
|
|
113
116
|
timeSlots?: undefined;
|
|
@@ -59,7 +59,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
59
59
|
if (!this.request) {
|
|
60
60
|
throw new Error("bookingByStep解决方案需要 request 插件支持");
|
|
61
61
|
}
|
|
62
|
-
debugger;
|
|
63
62
|
let targetCacheData = {};
|
|
64
63
|
if ((_a = this.otherParams) == null ? void 0 : _a.cacheId) {
|
|
65
64
|
const sessionData = this.window.sessionStorage.getItem(this.name);
|
|
@@ -239,7 +238,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
239
238
|
async setLoginAccount(accountId, accountInfo) {
|
|
240
239
|
const account = this.store.accountList.getAccount(accountId);
|
|
241
240
|
if (account) {
|
|
242
|
-
|
|
241
|
+
let stateAccountId = account.getId();
|
|
243
242
|
account.setAccountInfo(accountInfo);
|
|
244
243
|
const cartItems = this.store.cart.getItems();
|
|
245
244
|
cartItems.forEach((item) => {
|
|
@@ -250,6 +249,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
250
249
|
});
|
|
251
250
|
}
|
|
252
251
|
});
|
|
252
|
+
this.store.accountList.updateAccountListById(stateAccountId, accountInfo);
|
|
253
253
|
} else {
|
|
254
254
|
throw new Error(`没有找到${accountId}账户`);
|
|
255
255
|
}
|
|
@@ -257,10 +257,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
257
257
|
// 生成购物车的正规数据
|
|
258
258
|
async generateCartData() {
|
|
259
259
|
}
|
|
260
|
+
// 免费领取商品相关逻辑,上线了来不及加了,先放在这,后面要做到 payment 里面的
|
|
261
|
+
async getFreeProduct(id) {
|
|
262
|
+
const res = await this.request.post(`/pay/order/free-pay/${id}`);
|
|
263
|
+
return res;
|
|
264
|
+
}
|
|
260
265
|
// 购物车提交订单
|
|
261
266
|
async submitOrder() {
|
|
262
267
|
const cartItems = this.store.cart.getItems();
|
|
263
|
-
|
|
268
|
+
const newCartItems = (0, import_lodash_es.cloneDeep)(cartItems);
|
|
269
|
+
newCartItems.forEach((item) => {
|
|
264
270
|
item._origin.resources = item._origin.resources.map((n) => {
|
|
265
271
|
const newResourcesItem = (0, import_lodash_es.cloneDeep)(n);
|
|
266
272
|
delete newResourcesItem.id;
|
|
@@ -269,7 +275,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
269
275
|
return { ...newResourcesItem };
|
|
270
276
|
});
|
|
271
277
|
});
|
|
272
|
-
return this.store.order.commitOrder({ query: { cartItems } });
|
|
278
|
+
return this.store.order.commitOrder({ query: { cartItems: newCartItems } });
|
|
273
279
|
}
|
|
274
280
|
// 拉起支付模块
|
|
275
281
|
async pay() {
|
|
@@ -471,7 +477,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
471
477
|
autoSelectAccountResources({
|
|
472
478
|
holder_id,
|
|
473
479
|
resources_code,
|
|
474
|
-
timeSlots
|
|
480
|
+
timeSlots,
|
|
481
|
+
countMap
|
|
475
482
|
}) {
|
|
476
483
|
var _a, _b, _c;
|
|
477
484
|
const dateRange = this.store.date.getDateRange();
|
|
@@ -501,12 +508,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
501
508
|
const end_time = (0, import_dayjs.default)(`${dateRange[0].date} ${start_time}`).add(duration, durationType).format("HH:mm");
|
|
502
509
|
let targetResource = null;
|
|
503
510
|
for (const n of resources) {
|
|
511
|
+
const recordCount = countMap[n.id] || 0;
|
|
504
512
|
const canUseTime = n.times.find(
|
|
505
513
|
(item) => (0, import_resources.getIsUsableByTimeItem)({
|
|
506
514
|
timeSlice: item,
|
|
507
515
|
time: { start_time, end_time },
|
|
508
516
|
resource: n,
|
|
509
|
-
currentCount: 1
|
|
517
|
+
currentCount: recordCount + 1
|
|
510
518
|
})
|
|
511
519
|
);
|
|
512
520
|
if (canUseTime) {
|
|
@@ -546,6 +554,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
546
554
|
});
|
|
547
555
|
const resourcesMap = (0, import_utils.getResourcesMap)(resources);
|
|
548
556
|
const errorList = [];
|
|
557
|
+
const selectResourcesMap = {};
|
|
549
558
|
this.store.accountList.getAccounts().forEach((account) => {
|
|
550
559
|
const cartItems = this.store.cart.getCartByAccount(account.getId());
|
|
551
560
|
const allCartItems = this.store.cart.getItems();
|
|
@@ -555,9 +564,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
555
564
|
const res = this.autoSelectAccountResources({
|
|
556
565
|
holder_id: item.holder_id,
|
|
557
566
|
resources_code,
|
|
558
|
-
timeSlots
|
|
567
|
+
timeSlots,
|
|
568
|
+
countMap: selectResourcesMap
|
|
559
569
|
});
|
|
560
570
|
if (res == null ? void 0 : res.selectedResource) {
|
|
571
|
+
if (!selectResourcesMap[res.selectedResource.id]) {
|
|
572
|
+
selectResourcesMap[res.selectedResource.id] = 1;
|
|
573
|
+
} else {
|
|
574
|
+
selectResourcesMap[res.selectedResource.id]++;
|
|
575
|
+
}
|
|
561
576
|
console.log(this.store.cart.getItems());
|
|
562
577
|
this.store.cart.updateItem({
|
|
563
578
|
_id: item._id,
|
|
@@ -634,47 +649,33 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
634
649
|
return timeSlots;
|
|
635
650
|
}
|
|
636
651
|
// 提交时间切片,绑定到对应购物车的商品上,更新购物车
|
|
637
|
-
// submitTimeSlot({
|
|
638
|
-
// resourceProductData,
|
|
639
|
-
// selectedResources,
|
|
640
|
-
// timeSlots,
|
|
641
|
-
// }: {
|
|
642
|
-
// resourceProductData: any;
|
|
643
|
-
// selectedResources: any[];
|
|
644
|
-
// timeSlots: TimeSliceItem;
|
|
645
|
-
// }) {
|
|
646
|
-
// const newResources = cloneDeep(selectedResources);
|
|
647
|
-
// newResources.forEach((n) => {
|
|
648
|
-
// n.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
|
|
649
|
-
// n.endTime = dayjs(n.startTime)
|
|
650
|
-
// .add(
|
|
651
|
-
// resourceProductData.product.duration.value,
|
|
652
|
-
// resourceProductData.product.duration.type
|
|
653
|
-
// )
|
|
654
|
-
// .format("YYYY-MM-DD HH:mm");
|
|
655
|
-
// delete n.times;
|
|
656
|
-
// });
|
|
657
|
-
// this.store.cart.updateItem({
|
|
658
|
-
// _id: resourceProductData._id,
|
|
659
|
-
// resources: newResources,
|
|
660
|
-
// });
|
|
661
|
-
// }
|
|
662
652
|
submitTimeSlot(timeSlots) {
|
|
663
653
|
const cartItems = this.store.cart.getItems();
|
|
664
|
-
cartItems.
|
|
665
|
-
const
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
654
|
+
const itemsByAccount = cartItems.reduce((acc, item) => {
|
|
655
|
+
const holderId = item.holder_id;
|
|
656
|
+
if (!acc[holderId]) {
|
|
657
|
+
acc[holderId] = [];
|
|
658
|
+
}
|
|
659
|
+
acc[holderId].push(item);
|
|
660
|
+
return acc;
|
|
661
|
+
}, {});
|
|
662
|
+
Object.values(itemsByAccount).forEach((accountItems) => {
|
|
663
|
+
let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
|
|
664
|
+
accountItems.forEach((item, index) => {
|
|
665
|
+
const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
|
|
666
|
+
newResources.forEach((resource) => {
|
|
667
|
+
var _a, _b, _c, _d;
|
|
668
|
+
resource.startTime = currentStartTime;
|
|
669
|
+
resource.endTime = (0, import_dayjs.default)(currentStartTime).add(((_b = (_a = item._productOrigin) == null ? void 0 : _a.duration) == null ? void 0 : _b.value) ?? 0, ((_d = (_c = item._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) ?? "minutes").format("YYYY-MM-DD HH:mm");
|
|
670
|
+
delete resource.times;
|
|
671
|
+
});
|
|
672
|
+
this.store.cart.updateItem({
|
|
673
|
+
_id: item._id,
|
|
674
|
+
resources: newResources
|
|
675
|
+
});
|
|
676
|
+
if (index < accountItems.length - 1) {
|
|
677
|
+
currentStartTime = newResources[0].endTime;
|
|
678
|
+
}
|
|
678
679
|
});
|
|
679
680
|
});
|
|
680
681
|
}
|
|
@@ -72,6 +72,9 @@ var formatResource = (resourceItem, booking) => {
|
|
|
72
72
|
return _resourceItem;
|
|
73
73
|
};
|
|
74
74
|
var checkCapacity = ({ event_list, timeSlice, resource, currentCount = 1 }) => {
|
|
75
|
+
if (currentCount > resource.capacity) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
75
78
|
let conflict = (event_list || []).filter((d) => {
|
|
76
79
|
return isConflict({ start_at: d.start_at, end_at: d.end_at }, { start_at: timeSlice.start_at, end_at: timeSlice.end_at });
|
|
77
80
|
});
|
|
@@ -91,7 +91,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
91
91
|
targetCacheData = data[this.options.otherParams.cacheId];
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
debugger;
|
|
95
94
|
const discount = new import_Discount.DiscountModule(`${this.name}_discount`);
|
|
96
95
|
this.core.registerModule(discount, {
|
|
97
96
|
initialState: targetCacheData == null ? void 0 : targetCacheData[discount.name],
|