@pisell/pisellos 0.0.10 → 0.0.13
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/Account/index.d.ts +4 -2
- package/dist/modules/Account/index.js +23 -36
- package/dist/modules/Account/types.d.ts +1 -0
- package/dist/modules/AccountList/index.d.ts +2 -0
- package/dist/modules/AccountList/index.js +34 -11
- package/dist/modules/Cart/index.d.ts +17 -11
- package/dist/modules/Cart/index.js +179 -121
- package/dist/modules/Cart/types.d.ts +98 -9
- package/dist/modules/Cart/types.js +8 -0
- package/dist/modules/Cart/utils.d.ts +114 -0
- package/dist/modules/Cart/utils.js +345 -0
- package/dist/modules/Date/index.d.ts +11 -12
- package/dist/modules/Date/index.js +104 -60
- package/dist/modules/Date/types.d.ts +51 -20
- package/dist/modules/Date/types.js +2 -5
- package/dist/modules/Date/utils.d.ts +35 -0
- package/dist/modules/Date/utils.js +211 -0
- package/dist/modules/Discount/index.d.ts +26 -0
- package/dist/modules/Discount/index.js +234 -0
- package/dist/modules/Discount/types.d.ts +66 -0
- package/dist/modules/Discount/types.js +5 -0
- package/dist/modules/Order/index.d.ts +16 -12
- package/dist/modules/Order/index.js +38 -166
- package/dist/modules/Order/types.d.ts +18 -41
- package/dist/modules/Order/types.js +0 -14
- package/dist/modules/Payment/index.d.ts +0 -2
- package/dist/modules/Payment/index.js +45 -76
- package/dist/modules/Payment/types.d.ts +0 -2
- package/dist/modules/Payment/types.js +2 -0
- package/dist/modules/Product/types.d.ts +48 -1
- package/dist/modules/ProductList/index.d.ts +1 -0
- package/dist/modules/ProductList/index.js +21 -1
- package/dist/modules/ProductList/types.d.ts +1 -0
- package/dist/modules/Resource/types.d.ts +6 -2
- package/dist/modules/Rules/index.d.ts +32 -0
- package/dist/modules/Rules/index.js +423 -0
- package/dist/modules/Rules/types.d.ts +46 -0
- package/dist/modules/Rules/types.js +5 -0
- package/dist/modules/Summary/index.d.ts +13 -0
- package/dist/modules/Summary/index.js +80 -0
- package/dist/modules/Summary/types.d.ts +13 -0
- package/dist/modules/Summary/types.js +1 -0
- package/dist/modules/Summary/utils.d.ts +19 -0
- package/dist/modules/Summary/utils.js +56 -0
- package/dist/plugins/index.d.ts +3 -2
- package/dist/plugins/index.js +2 -1
- package/dist/plugins/request.d.ts +4 -3
- package/dist/plugins/request.js +30 -30
- package/dist/plugins/shopStore.d.ts +4 -0
- package/dist/plugins/shopStore.js +1 -0
- package/dist/solution/BookingByStep/index.d.ts +73 -12
- package/dist/solution/BookingByStep/index.js +635 -99
- package/dist/solution/BookingByStep/types.d.ts +2 -0
- package/dist/solution/BookingByStep/types.js +11 -8
- package/dist/solution/BookingByStep/utils/products.d.ts +11 -0
- package/dist/solution/BookingByStep/utils/products.js +47 -0
- package/dist/solution/BookingByStep/utils/resources.d.ts +59 -10
- package/dist/solution/BookingByStep/utils/resources.js +144 -79
- package/dist/solution/ShopDiscount/index.d.ts +50 -0
- package/dist/solution/ShopDiscount/index.js +546 -0
- package/dist/solution/ShopDiscount/types.d.ts +24 -0
- package/dist/solution/ShopDiscount/types.js +10 -0
- package/dist/solution/ShopDiscount/utils.d.ts +1 -0
- package/dist/solution/ShopDiscount/utils.js +7 -0
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +2 -1
- package/lib/modules/Account/index.d.ts +4 -2
- package/lib/modules/Account/index.js +14 -3
- package/lib/modules/Account/types.d.ts +1 -0
- package/lib/modules/AccountList/index.d.ts +2 -0
- package/lib/modules/AccountList/index.js +17 -0
- package/lib/modules/Cart/index.d.ts +17 -11
- package/lib/modules/Cart/index.js +72 -21
- package/lib/modules/Cart/types.d.ts +98 -9
- package/lib/modules/Cart/utils.d.ts +114 -0
- package/lib/modules/Cart/utils.js +320 -0
- package/lib/modules/Date/index.d.ts +11 -12
- package/lib/modules/Date/index.js +50 -31
- package/lib/modules/Date/types.d.ts +51 -20
- package/lib/modules/Date/types.js +0 -4
- package/lib/modules/Date/utils.d.ts +35 -0
- package/lib/modules/Date/utils.js +167 -0
- package/lib/modules/Discount/index.d.ts +26 -0
- package/lib/modules/Discount/index.js +118 -0
- package/lib/modules/Discount/types.d.ts +66 -0
- package/lib/modules/Discount/types.js +33 -0
- package/lib/modules/Order/index.d.ts +16 -12
- package/lib/modules/Order/index.js +23 -51
- package/lib/modules/Order/types.d.ts +18 -41
- package/lib/modules/Payment/index.d.ts +0 -2
- package/lib/modules/Payment/index.js +6 -17
- package/lib/modules/Payment/types.d.ts +0 -2
- package/lib/modules/Product/types.d.ts +48 -1
- package/lib/modules/ProductList/index.d.ts +1 -0
- package/lib/modules/ProductList/index.js +4 -0
- package/lib/modules/ProductList/types.d.ts +1 -0
- package/lib/modules/Resource/types.d.ts +6 -2
- package/lib/modules/Rules/index.d.ts +32 -0
- package/lib/modules/Rules/index.js +283 -0
- package/lib/modules/Rules/types.d.ts +46 -0
- package/lib/modules/Rules/types.js +33 -0
- package/lib/modules/Summary/index.d.ts +13 -0
- package/lib/modules/Summary/index.js +49 -0
- package/lib/modules/Summary/types.d.ts +13 -0
- package/lib/modules/Summary/types.js +17 -0
- package/lib/modules/Summary/utils.d.ts +19 -0
- package/lib/modules/Summary/utils.js +79 -0
- package/lib/plugins/index.d.ts +3 -2
- package/lib/plugins/index.js +3 -1
- package/lib/plugins/request.d.ts +4 -3
- package/lib/plugins/request.js +4 -20
- package/lib/plugins/shopStore.d.ts +4 -0
- package/lib/plugins/shopStore.js +17 -0
- package/lib/solution/BookingByStep/index.d.ts +73 -12
- package/lib/solution/BookingByStep/index.js +451 -24
- package/lib/solution/BookingByStep/types.d.ts +2 -0
- package/lib/solution/BookingByStep/types.js +3 -0
- package/lib/solution/BookingByStep/utils/products.d.ts +11 -0
- package/lib/solution/BookingByStep/utils/products.js +60 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +59 -10
- package/lib/solution/BookingByStep/utils/resources.js +106 -49
- package/lib/solution/ShopDiscount/index.d.ts +50 -0
- package/lib/solution/ShopDiscount/index.js +321 -0
- package/lib/solution/ShopDiscount/types.d.ts +24 -0
- package/lib/solution/ShopDiscount/types.js +38 -0
- package/lib/solution/ShopDiscount/utils.d.ts +1 -0
- package/lib/solution/ShopDiscount/utils.js +32 -0
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +3 -1
- package/package.json +4 -4
|
@@ -17,7 +17,7 @@ export interface ProductData {
|
|
|
17
17
|
/** 商品slug */
|
|
18
18
|
slug: string;
|
|
19
19
|
/** draft:草稿;published:已发布;pending:待发布;archived:已归档 */
|
|
20
|
-
status:
|
|
20
|
+
status: "draft" | "published" | "pending" | "archived";
|
|
21
21
|
/** 库存数量 */
|
|
22
22
|
stock_quantity: number;
|
|
23
23
|
/** 销售数量 */
|
|
@@ -132,10 +132,26 @@ export interface ProductData {
|
|
|
132
132
|
base_price: string;
|
|
133
133
|
/** 规格列表 */
|
|
134
134
|
variant: any[];
|
|
135
|
+
/** 媒体 */
|
|
135
136
|
media: ProductMedia[];
|
|
137
|
+
/** 标签 */
|
|
136
138
|
tags: ProductTag[];
|
|
139
|
+
/** 分类 */
|
|
137
140
|
categories: ProductCategory[];
|
|
141
|
+
/** 套餐组 */
|
|
138
142
|
bundle_groups: ProductBundleGroup[];
|
|
143
|
+
/** 商品资源 */
|
|
144
|
+
product_resource?: {
|
|
145
|
+
resources?: ProductResourceItem[];
|
|
146
|
+
};
|
|
147
|
+
/** 组合商品id,动态附加 */
|
|
148
|
+
product_variant_id?: number;
|
|
149
|
+
/** 套餐信息 */
|
|
150
|
+
bundle?: any[];
|
|
151
|
+
/** 商品选项组成 */
|
|
152
|
+
options?: any[];
|
|
153
|
+
/** 商品原信息 */
|
|
154
|
+
origin?: any;
|
|
139
155
|
}
|
|
140
156
|
/**
|
|
141
157
|
* 商品媒体信息接口
|
|
@@ -387,3 +403,34 @@ export interface ProductBundleItem {
|
|
|
387
403
|
/** 明细库存 */
|
|
388
404
|
stock_quantity: string;
|
|
389
405
|
}
|
|
406
|
+
/**
|
|
407
|
+
* 商品资源
|
|
408
|
+
*/
|
|
409
|
+
export interface ProductResourceItem {
|
|
410
|
+
/** 资源是否启用:0: 禁用, 1: 启用 */
|
|
411
|
+
status: 0 | 1;
|
|
412
|
+
/** 资源id */
|
|
413
|
+
id: number;
|
|
414
|
+
/** 资源标题 */
|
|
415
|
+
title: string;
|
|
416
|
+
/** 资源编码 */
|
|
417
|
+
code: "resource";
|
|
418
|
+
/** 默认资源 */
|
|
419
|
+
default_resource?: number[];
|
|
420
|
+
/** 可选资源 */
|
|
421
|
+
optional_resource?: number[];
|
|
422
|
+
/** 资源类型id */
|
|
423
|
+
resource_type_id: number;
|
|
424
|
+
/** 选择类型 */
|
|
425
|
+
select_type?: {
|
|
426
|
+
type: "single";
|
|
427
|
+
min: 1;
|
|
428
|
+
max: 1;
|
|
429
|
+
};
|
|
430
|
+
/** 创建时间 */
|
|
431
|
+
created_at: string;
|
|
432
|
+
/** 更新时间 */
|
|
433
|
+
updated_at: string;
|
|
434
|
+
/** 可用资源列表 */
|
|
435
|
+
renderList?: any[];
|
|
436
|
+
}
|
|
@@ -13,4 +13,5 @@ export declare class ProductList extends BaseModule implements Module {
|
|
|
13
13
|
getProducts(): Promise<ProductData[]>;
|
|
14
14
|
getProduct(id: number): Promise<Product | undefined>;
|
|
15
15
|
addProduct(products: ProductData[]): Promise<void>;
|
|
16
|
+
selectProducts(products: ProductData[]): Promise<void>;
|
|
16
17
|
}
|
|
@@ -39,6 +39,7 @@ var ProductList = class extends import_BaseModule.BaseModule {
|
|
|
39
39
|
this.store = options.store;
|
|
40
40
|
this.store.productMap = /* @__PURE__ */ new Map();
|
|
41
41
|
this.store.list = [];
|
|
42
|
+
this.store.selectProducts = [];
|
|
42
43
|
this.storeChange();
|
|
43
44
|
}
|
|
44
45
|
async storeChange(path, value) {
|
|
@@ -65,6 +66,9 @@ var ProductList = class extends import_BaseModule.BaseModule {
|
|
|
65
66
|
async addProduct(products) {
|
|
66
67
|
this.store.list = [...this.store.list, ...products];
|
|
67
68
|
}
|
|
69
|
+
async selectProducts(products) {
|
|
70
|
+
this.store.selectProducts = products;
|
|
71
|
+
}
|
|
68
72
|
};
|
|
69
73
|
// Annotate the CommonJS export names for ESM import in node:
|
|
70
74
|
0 && (module.exports = {
|
|
@@ -16,12 +16,16 @@ export interface ResourceTimeSlot {
|
|
|
16
16
|
* 资源信息
|
|
17
17
|
*/
|
|
18
18
|
export interface Resource {
|
|
19
|
-
id: string;
|
|
20
|
-
|
|
19
|
+
id: string | number;
|
|
20
|
+
main_field: string;
|
|
21
|
+
form_id: string | number;
|
|
21
22
|
type: string;
|
|
22
23
|
capacity: number;
|
|
23
24
|
timeSlots: ResourceTimeSlot[];
|
|
24
25
|
metadata?: Record<string, any>;
|
|
26
|
+
startTime?: string;
|
|
27
|
+
endTime?: string;
|
|
28
|
+
resourceType?: string;
|
|
25
29
|
}
|
|
26
30
|
/**
|
|
27
31
|
* 资源列表状态
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Module, PisellCore, ModuleOptions } from "../../types";
|
|
2
|
+
import { BaseModule } from "../BaseModule";
|
|
3
|
+
import { Rules, RulesModuleAPI, DiscountResult } from "./types";
|
|
4
|
+
import { Discount } from "../Discount/types";
|
|
5
|
+
export declare class RulesModule extends BaseModule implements Module, RulesModuleAPI {
|
|
6
|
+
protected defaultName: string;
|
|
7
|
+
protected defaultVersion: string;
|
|
8
|
+
private store;
|
|
9
|
+
private hooks;
|
|
10
|
+
constructor(name?: string, version?: string);
|
|
11
|
+
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
12
|
+
setRulesList(rulesList: Rules[]): Promise<void>;
|
|
13
|
+
getRulesList(): Rules[];
|
|
14
|
+
isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, }: {
|
|
15
|
+
oldDiscountList: Discount[];
|
|
16
|
+
newDiscountList: Discount[];
|
|
17
|
+
productList: any[];
|
|
18
|
+
}): {
|
|
19
|
+
isAvailable: boolean;
|
|
20
|
+
discountList: Discount[];
|
|
21
|
+
productList: any[];
|
|
22
|
+
};
|
|
23
|
+
calcDiscount({ discountList, productList, }: {
|
|
24
|
+
discountList: Discount[];
|
|
25
|
+
productList: any[];
|
|
26
|
+
}, options?: {
|
|
27
|
+
isSelected?: boolean;
|
|
28
|
+
discountId: number;
|
|
29
|
+
}): DiscountResult;
|
|
30
|
+
destroy(): Promise<void>;
|
|
31
|
+
clear(): Promise<void>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
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/modules/Rules/index.ts
|
|
20
|
+
var Rules_exports = {};
|
|
21
|
+
__export(Rules_exports, {
|
|
22
|
+
RulesModule: () => RulesModule
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(Rules_exports);
|
|
25
|
+
var import_BaseModule = require("../BaseModule");
|
|
26
|
+
var import_types = require("./types");
|
|
27
|
+
var import_utils = require("../../solution/ShopDiscount/utils");
|
|
28
|
+
var RulesModule = class extends import_BaseModule.BaseModule {
|
|
29
|
+
constructor(name, version) {
|
|
30
|
+
super(name, version);
|
|
31
|
+
this.defaultName = "rules";
|
|
32
|
+
this.defaultVersion = "1.0.0";
|
|
33
|
+
this.hooks = {};
|
|
34
|
+
}
|
|
35
|
+
async initialize(core, options) {
|
|
36
|
+
this.core = core;
|
|
37
|
+
this.hooks = options == null ? void 0 : options.hooks;
|
|
38
|
+
this.store = options == null ? void 0 : options.store;
|
|
39
|
+
}
|
|
40
|
+
async setRulesList(rulesList) {
|
|
41
|
+
this.store.rulesList = rulesList;
|
|
42
|
+
await this.core.effects.emit(import_types.RulesHooks.OnRulesListChange, rulesList);
|
|
43
|
+
}
|
|
44
|
+
getRulesList() {
|
|
45
|
+
return this.store.rulesList;
|
|
46
|
+
}
|
|
47
|
+
// 判断discountList 是否可以对当前productList生效
|
|
48
|
+
isDiscountListAvailable({
|
|
49
|
+
oldDiscountList,
|
|
50
|
+
newDiscountList,
|
|
51
|
+
productList
|
|
52
|
+
}) {
|
|
53
|
+
if (!newDiscountList || newDiscountList.length === 0) {
|
|
54
|
+
return {
|
|
55
|
+
isAvailable: false,
|
|
56
|
+
discountList: oldDiscountList,
|
|
57
|
+
productList
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const mergedDiscountList = (0, import_utils.uniqueById)([
|
|
61
|
+
...oldDiscountList,
|
|
62
|
+
...newDiscountList
|
|
63
|
+
]);
|
|
64
|
+
const result = this.calcDiscount({
|
|
65
|
+
discountList: mergedDiscountList,
|
|
66
|
+
productList: [...productList]
|
|
67
|
+
});
|
|
68
|
+
let hasApplicableDiscount = false;
|
|
69
|
+
const newDiscountIds = newDiscountList.map((discount) => discount.id);
|
|
70
|
+
result.productList.forEach((product) => {
|
|
71
|
+
const { discount_list } = this.hooks.getProduct(product);
|
|
72
|
+
if (discount_list && discount_list.length > 0) {
|
|
73
|
+
const usedNewDiscount = discount_list.some(
|
|
74
|
+
(discount) => newDiscountIds.includes(discount.resource_id)
|
|
75
|
+
);
|
|
76
|
+
if (usedNewDiscount) {
|
|
77
|
+
hasApplicableDiscount = true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
isAvailable: hasApplicableDiscount,
|
|
83
|
+
discountList: hasApplicableDiscount ? result.discountList : oldDiscountList,
|
|
84
|
+
productList: hasApplicableDiscount ? result.productList : productList
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
calcDiscount({
|
|
88
|
+
discountList,
|
|
89
|
+
productList
|
|
90
|
+
}, options) {
|
|
91
|
+
const editModeDiscount = [];
|
|
92
|
+
const addModeDiscount = [];
|
|
93
|
+
discountList.forEach((discount) => {
|
|
94
|
+
if (discount.isEditMode) {
|
|
95
|
+
editModeDiscount.push(discount);
|
|
96
|
+
} else {
|
|
97
|
+
addModeDiscount.push(discount);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const filteredDiscountList = addModeDiscount.filter((discount) => {
|
|
101
|
+
return !discount.isManualSelect;
|
|
102
|
+
});
|
|
103
|
+
const sortedDiscountList = [...filteredDiscountList].sort((a, b) => {
|
|
104
|
+
if (a.expire_time && b.expire_time) {
|
|
105
|
+
const timeA = new Date(a.expire_time).getTime();
|
|
106
|
+
const timeB = new Date(b.expire_time).getTime();
|
|
107
|
+
return timeA - timeB;
|
|
108
|
+
}
|
|
109
|
+
return a.expire_time ? -1 : b.expire_time ? 1 : 0;
|
|
110
|
+
});
|
|
111
|
+
const sortedProductList = [...productList].sort((a, b) => {
|
|
112
|
+
const aProduct = this.hooks.getProduct(a);
|
|
113
|
+
const bProduct = this.hooks.getProduct(b);
|
|
114
|
+
const priceA = parseFloat(aProduct.price || "0");
|
|
115
|
+
const priceB = parseFloat(bProduct.price || "0");
|
|
116
|
+
return priceB - priceA;
|
|
117
|
+
});
|
|
118
|
+
const usedDiscounts = /* @__PURE__ */ new Map();
|
|
119
|
+
const discountApplicability = /* @__PURE__ */ new Map();
|
|
120
|
+
const discountApplicableProducts = /* @__PURE__ */ new Map();
|
|
121
|
+
addModeDiscount.forEach((discount) => {
|
|
122
|
+
discountApplicability.set(discount.id, []);
|
|
123
|
+
discountApplicableProducts.set(discount.id, []);
|
|
124
|
+
});
|
|
125
|
+
const processedProductsMap = /* @__PURE__ */ new Map();
|
|
126
|
+
const appliedDiscountProducts = /* @__PURE__ */ new Map();
|
|
127
|
+
sortedProductList.forEach((originProduct) => {
|
|
128
|
+
const product = this.hooks.getProduct(originProduct);
|
|
129
|
+
addModeDiscount.forEach((discount) => {
|
|
130
|
+
var _a;
|
|
131
|
+
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
132
|
+
if (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
|
|
133
|
+
(_a = discountApplicability.get(discount.id)) == null ? void 0 : _a.push(product.id);
|
|
134
|
+
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
135
|
+
applicableProducts.push({
|
|
136
|
+
amount: product.price,
|
|
137
|
+
type: discount.tag,
|
|
138
|
+
resource_id: discount.id,
|
|
139
|
+
title: discount.format_title,
|
|
140
|
+
original_amount: product.origin_total
|
|
141
|
+
});
|
|
142
|
+
discountApplicableProducts.set(discount.id, applicableProducts);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
sortedProductList.forEach((originProduct) => {
|
|
147
|
+
var _a;
|
|
148
|
+
const product = this.hooks.getProduct(originProduct);
|
|
149
|
+
if (product == null ? void 0 : product.booking_id) {
|
|
150
|
+
processedProductsMap.set(product._id, originProduct);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const applicableDiscounts = sortedDiscountList.filter((discount) => {
|
|
154
|
+
if (usedDiscounts.get(discount.id))
|
|
155
|
+
return false;
|
|
156
|
+
const limitedData = discount.limited_relation_product_data;
|
|
157
|
+
if (limitedData.type === "product_all") {
|
|
158
|
+
return true;
|
|
159
|
+
} else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
});
|
|
164
|
+
const selectedDiscount = applicableDiscounts[0];
|
|
165
|
+
let isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && !((_a = product.discount_list) == null ? void 0 : _a.length);
|
|
166
|
+
if ((options == null ? void 0 : options.discountId) && (options == null ? void 0 : options.discountId) === (selectedDiscount == null ? void 0 : selectedDiscount.id)) {
|
|
167
|
+
isManualDiscount = false;
|
|
168
|
+
}
|
|
169
|
+
if (applicableDiscounts.length === 0 || isManualDiscount) {
|
|
170
|
+
processedProductsMap.set(
|
|
171
|
+
product._id,
|
|
172
|
+
this.hooks.setProduct(originProduct, {
|
|
173
|
+
...isManualDiscount ? {} : {
|
|
174
|
+
total: product.origin_total || product.total,
|
|
175
|
+
price: product.price
|
|
176
|
+
},
|
|
177
|
+
discount_list: []
|
|
178
|
+
})
|
|
179
|
+
);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
usedDiscounts.set(selectedDiscount.id, true);
|
|
183
|
+
const appliedProducts = appliedDiscountProducts.get(selectedDiscount.id) || [];
|
|
184
|
+
const discountDetail = {
|
|
185
|
+
amount: product.price,
|
|
186
|
+
type: selectedDiscount.tag,
|
|
187
|
+
resource_id: selectedDiscount.id,
|
|
188
|
+
title: selectedDiscount.format_title,
|
|
189
|
+
original_amount: product.origin_total,
|
|
190
|
+
product_id: selectedDiscount.product_id
|
|
191
|
+
};
|
|
192
|
+
appliedProducts.push(discountDetail);
|
|
193
|
+
appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
|
|
194
|
+
processedProductsMap.set(
|
|
195
|
+
product._id,
|
|
196
|
+
this.hooks.setProduct(originProduct, {
|
|
197
|
+
discount_list: [discountDetail],
|
|
198
|
+
price: 0,
|
|
199
|
+
total: (product.origin_total || product.total) - product.price,
|
|
200
|
+
origin_total: product.origin_total || product.total
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
});
|
|
204
|
+
const processedProductList = productList.map((originProduct) => {
|
|
205
|
+
const product = this.hooks.getProduct(originProduct);
|
|
206
|
+
return processedProductsMap.get(product._id) || this.hooks.setProduct(originProduct, {
|
|
207
|
+
discount_list: [],
|
|
208
|
+
total: product.total,
|
|
209
|
+
origin_total: product.origin_total,
|
|
210
|
+
price: product.price
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
const updatedDiscountList = addModeDiscount.map((discount) => {
|
|
214
|
+
const applicableProducts = discountApplicability.get(discount.id) || [];
|
|
215
|
+
const applicableProductDetails = discountApplicableProducts.get(discount.id) || [];
|
|
216
|
+
const appliedProductDetails = appliedDiscountProducts.get(discount.id) || [];
|
|
217
|
+
const isAvailable = applicableProducts.length > 0;
|
|
218
|
+
if (typeof discount.isSelected === "boolean" && discount.isSelected === false && discount.isManualSelect) {
|
|
219
|
+
return {
|
|
220
|
+
...discount,
|
|
221
|
+
isUsed: false,
|
|
222
|
+
isSelected: false,
|
|
223
|
+
isAvailable,
|
|
224
|
+
// 正确设置可用性
|
|
225
|
+
applicableProductIds: applicableProducts,
|
|
226
|
+
// 添加可抵扣的商品详情
|
|
227
|
+
applicableProductDetails,
|
|
228
|
+
// 添加实际抵扣的商品详情(对于未选中的优惠券,为空数组)
|
|
229
|
+
appliedProductDetails: []
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
if (usedDiscounts.get(discount.id)) {
|
|
233
|
+
return {
|
|
234
|
+
...discount,
|
|
235
|
+
isUsed: true,
|
|
236
|
+
isSelected: true,
|
|
237
|
+
// 标记为可用,因为它已被应用
|
|
238
|
+
isAvailable: true,
|
|
239
|
+
// 记录适用的商品IDs
|
|
240
|
+
applicableProductIds: applicableProducts,
|
|
241
|
+
// 添加可抵扣的商品详情
|
|
242
|
+
applicableProductDetails,
|
|
243
|
+
// 添加实际抵扣的商品详情
|
|
244
|
+
appliedProductDetails
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
let isSelected = typeof discount.isSelected === "boolean" ? discount.isSelected : void 0;
|
|
248
|
+
if (isAvailable && !discount.isManualSelect) {
|
|
249
|
+
isSelected = true;
|
|
250
|
+
} else if (!appliedProductDetails.length) {
|
|
251
|
+
isSelected = false;
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
...discount,
|
|
255
|
+
// 如果有适用的商品,标记为可用
|
|
256
|
+
isAvailable,
|
|
257
|
+
isSelected,
|
|
258
|
+
// 记录适用的商品IDs
|
|
259
|
+
applicableProductIds: applicableProducts,
|
|
260
|
+
// 添加可抵扣的商品详情
|
|
261
|
+
applicableProductDetails,
|
|
262
|
+
// 添加实际抵扣的商品详情(对于未使用的优惠券,为空数组)
|
|
263
|
+
appliedProductDetails: []
|
|
264
|
+
};
|
|
265
|
+
});
|
|
266
|
+
return {
|
|
267
|
+
productList: processedProductList,
|
|
268
|
+
discountList: [...editModeDiscount, ...updatedDiscountList]
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
async destroy() {
|
|
272
|
+
this.core.effects.offByModuleDestroy(this.name);
|
|
273
|
+
await this.core.effects.emit(import_types.RulesHooks.OnDestroy, {});
|
|
274
|
+
console.log("[Rules] 已销毁");
|
|
275
|
+
}
|
|
276
|
+
async clear() {
|
|
277
|
+
console.log("[Rules] clear");
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
281
|
+
0 && (module.exports = {
|
|
282
|
+
RulesModule
|
|
283
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Discount } from "../Discount/types";
|
|
2
|
+
export declare enum RulesHooks {
|
|
3
|
+
OnRulesListChange = "rules:onRulesListChange",
|
|
4
|
+
OnDestroy = "rules:onDestroy"
|
|
5
|
+
}
|
|
6
|
+
export interface Rules {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
discount: number;
|
|
11
|
+
}
|
|
12
|
+
export interface RulesState {
|
|
13
|
+
rulesList: Rules[];
|
|
14
|
+
}
|
|
15
|
+
export interface DiscountResult {
|
|
16
|
+
productList: any[];
|
|
17
|
+
discountList: any[];
|
|
18
|
+
}
|
|
19
|
+
export interface RulesModuleAPI {
|
|
20
|
+
setRulesList: (rulesList: Rules[]) => Promise<void>;
|
|
21
|
+
clear: () => Promise<void>;
|
|
22
|
+
calcDiscount: (params: {
|
|
23
|
+
discountList: any[];
|
|
24
|
+
productList: any[];
|
|
25
|
+
}) => DiscountResult;
|
|
26
|
+
}
|
|
27
|
+
type ProductDetail = {
|
|
28
|
+
isManualDiscount?: boolean;
|
|
29
|
+
booking_id: any;
|
|
30
|
+
id: number;
|
|
31
|
+
price: number | string;
|
|
32
|
+
total: number;
|
|
33
|
+
discount_list: Discount[];
|
|
34
|
+
origin_total: number;
|
|
35
|
+
_id: string;
|
|
36
|
+
};
|
|
37
|
+
export interface RulesParamsHooks {
|
|
38
|
+
getProduct: (product: Record<string, any>) => ProductDetail;
|
|
39
|
+
setProduct: (product: Record<string, any>, values: {
|
|
40
|
+
total?: number;
|
|
41
|
+
discount_list: any[];
|
|
42
|
+
origin_total?: number;
|
|
43
|
+
price?: number;
|
|
44
|
+
}) => Record<string, any>;
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
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/modules/Rules/types.ts
|
|
20
|
+
var types_exports = {};
|
|
21
|
+
__export(types_exports, {
|
|
22
|
+
RulesHooks: () => RulesHooks
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(types_exports);
|
|
25
|
+
var RulesHooks = /* @__PURE__ */ ((RulesHooks2) => {
|
|
26
|
+
RulesHooks2["OnRulesListChange"] = "rules:onRulesListChange";
|
|
27
|
+
RulesHooks2["OnDestroy"] = "rules:onDestroy";
|
|
28
|
+
return RulesHooks2;
|
|
29
|
+
})(RulesHooks || {});
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
RulesHooks
|
|
33
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Module, PisellCore, ModuleOptions } from "../../types";
|
|
2
|
+
import { BaseModule } from "../BaseModule";
|
|
3
|
+
import { CartItem } from "../Cart/types";
|
|
4
|
+
import { ISummaryState, ISummaryModuleAPI } from "./types";
|
|
5
|
+
export declare class SummaryModule extends BaseModule implements Module, ISummaryModuleAPI {
|
|
6
|
+
protected defaultName: string;
|
|
7
|
+
protected defaultVersion: string;
|
|
8
|
+
private shopStore;
|
|
9
|
+
private store;
|
|
10
|
+
constructor(name?: string, version?: string);
|
|
11
|
+
initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
|
|
12
|
+
getSummary(cartItems: CartItem[]): Promise<ISummaryState["summary"]>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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/modules/Summary/index.ts
|
|
20
|
+
var Summary_exports = {};
|
|
21
|
+
__export(Summary_exports, {
|
|
22
|
+
SummaryModule: () => SummaryModule
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(Summary_exports);
|
|
25
|
+
var import_BaseModule = require("../BaseModule");
|
|
26
|
+
var import_utils = require("./utils");
|
|
27
|
+
var SummaryModule = class extends import_BaseModule.BaseModule {
|
|
28
|
+
constructor(name, version) {
|
|
29
|
+
super(name, version);
|
|
30
|
+
this.defaultName = "summary";
|
|
31
|
+
this.defaultVersion = "1.0.0";
|
|
32
|
+
}
|
|
33
|
+
async initialize(core, options) {
|
|
34
|
+
this.core = core;
|
|
35
|
+
this.store = options.store;
|
|
36
|
+
this.shopStore = this.core.getPlugin("shopStore");
|
|
37
|
+
}
|
|
38
|
+
async getSummary(cartItems) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
const shopInfo = ((_b = (_a = this.shopStore.get("core")) == null ? void 0 : _a.core) == null ? void 0 : _b.shop) || {};
|
|
41
|
+
const summary = (0, import_utils.calculatePriceDetails)(shopInfo, cartItems);
|
|
42
|
+
this.store.summary = summary;
|
|
43
|
+
return this.store.summary;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
SummaryModule
|
|
49
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CartItem } from "../Cart/types";
|
|
2
|
+
export interface ISummaryState {
|
|
3
|
+
summary: {
|
|
4
|
+
subtotal: string | number;
|
|
5
|
+
total: string | number;
|
|
6
|
+
taxTitle?: string;
|
|
7
|
+
totalTaxFee?: string | number;
|
|
8
|
+
isPriceIncludeTax?: 0 | 1;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface ISummaryModuleAPI {
|
|
12
|
+
getSummary(cartItems: CartItem[]): Promise<ISummaryState["summary"]>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/modules/Summary/types.ts
|
|
16
|
+
var types_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
|
+
import { CartItem } from "../Cart/types";
|
|
3
|
+
import { ISummaryState } from "./types";
|
|
4
|
+
export declare const calculatePriceDetails: (shopInfo: any, items: CartItem[]) => ISummaryState["summary"];
|
|
5
|
+
/**
|
|
6
|
+
* 计算商品小计(不含其他费用)
|
|
7
|
+
* @param items - 购物车商品数组
|
|
8
|
+
* @returns 商品总价字符串,保留2位小数
|
|
9
|
+
*/
|
|
10
|
+
export declare const calculateSubtotal: (items: CartItem[]) => string;
|
|
11
|
+
/**
|
|
12
|
+
* @title: 单个商品的税费
|
|
13
|
+
* @description:
|
|
14
|
+
* 单个商品的税费 = 商品销售单价(折扣后) * 税率 * is_charge_tax /( 1+ 税率 * is_price_include_tax)
|
|
15
|
+
* $taxFee = $price * $taxRate * $isChargeTax / (1 + $taxRate * $isPriceIncludeTax);
|
|
16
|
+
* @return {*}
|
|
17
|
+
* @Author: xiangfeng.xue
|
|
18
|
+
*/
|
|
19
|
+
export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => Decimal | "0.00";
|