@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.
Files changed (130) hide show
  1. package/dist/modules/Account/index.d.ts +4 -2
  2. package/dist/modules/Account/index.js +23 -36
  3. package/dist/modules/Account/types.d.ts +1 -0
  4. package/dist/modules/AccountList/index.d.ts +2 -0
  5. package/dist/modules/AccountList/index.js +34 -11
  6. package/dist/modules/Cart/index.d.ts +17 -11
  7. package/dist/modules/Cart/index.js +179 -121
  8. package/dist/modules/Cart/types.d.ts +98 -9
  9. package/dist/modules/Cart/types.js +8 -0
  10. package/dist/modules/Cart/utils.d.ts +114 -0
  11. package/dist/modules/Cart/utils.js +345 -0
  12. package/dist/modules/Date/index.d.ts +11 -12
  13. package/dist/modules/Date/index.js +104 -60
  14. package/dist/modules/Date/types.d.ts +51 -20
  15. package/dist/modules/Date/types.js +2 -5
  16. package/dist/modules/Date/utils.d.ts +35 -0
  17. package/dist/modules/Date/utils.js +211 -0
  18. package/dist/modules/Discount/index.d.ts +26 -0
  19. package/dist/modules/Discount/index.js +234 -0
  20. package/dist/modules/Discount/types.d.ts +66 -0
  21. package/dist/modules/Discount/types.js +5 -0
  22. package/dist/modules/Order/index.d.ts +16 -12
  23. package/dist/modules/Order/index.js +38 -166
  24. package/dist/modules/Order/types.d.ts +18 -41
  25. package/dist/modules/Order/types.js +0 -14
  26. package/dist/modules/Payment/index.d.ts +0 -2
  27. package/dist/modules/Payment/index.js +45 -76
  28. package/dist/modules/Payment/types.d.ts +0 -2
  29. package/dist/modules/Payment/types.js +2 -0
  30. package/dist/modules/Product/types.d.ts +48 -1
  31. package/dist/modules/ProductList/index.d.ts +1 -0
  32. package/dist/modules/ProductList/index.js +21 -1
  33. package/dist/modules/ProductList/types.d.ts +1 -0
  34. package/dist/modules/Resource/types.d.ts +6 -2
  35. package/dist/modules/Rules/index.d.ts +32 -0
  36. package/dist/modules/Rules/index.js +423 -0
  37. package/dist/modules/Rules/types.d.ts +46 -0
  38. package/dist/modules/Rules/types.js +5 -0
  39. package/dist/modules/Summary/index.d.ts +13 -0
  40. package/dist/modules/Summary/index.js +80 -0
  41. package/dist/modules/Summary/types.d.ts +13 -0
  42. package/dist/modules/Summary/types.js +1 -0
  43. package/dist/modules/Summary/utils.d.ts +19 -0
  44. package/dist/modules/Summary/utils.js +56 -0
  45. package/dist/plugins/index.d.ts +3 -2
  46. package/dist/plugins/index.js +2 -1
  47. package/dist/plugins/request.d.ts +4 -3
  48. package/dist/plugins/request.js +30 -30
  49. package/dist/plugins/shopStore.d.ts +4 -0
  50. package/dist/plugins/shopStore.js +1 -0
  51. package/dist/solution/BookingByStep/index.d.ts +73 -12
  52. package/dist/solution/BookingByStep/index.js +635 -99
  53. package/dist/solution/BookingByStep/types.d.ts +2 -0
  54. package/dist/solution/BookingByStep/types.js +11 -8
  55. package/dist/solution/BookingByStep/utils/products.d.ts +11 -0
  56. package/dist/solution/BookingByStep/utils/products.js +47 -0
  57. package/dist/solution/BookingByStep/utils/resources.d.ts +59 -10
  58. package/dist/solution/BookingByStep/utils/resources.js +144 -79
  59. package/dist/solution/ShopDiscount/index.d.ts +50 -0
  60. package/dist/solution/ShopDiscount/index.js +546 -0
  61. package/dist/solution/ShopDiscount/types.d.ts +24 -0
  62. package/dist/solution/ShopDiscount/types.js +10 -0
  63. package/dist/solution/ShopDiscount/utils.d.ts +1 -0
  64. package/dist/solution/ShopDiscount/utils.js +7 -0
  65. package/dist/solution/index.d.ts +1 -0
  66. package/dist/solution/index.js +2 -1
  67. package/lib/modules/Account/index.d.ts +4 -2
  68. package/lib/modules/Account/index.js +14 -3
  69. package/lib/modules/Account/types.d.ts +1 -0
  70. package/lib/modules/AccountList/index.d.ts +2 -0
  71. package/lib/modules/AccountList/index.js +17 -0
  72. package/lib/modules/Cart/index.d.ts +17 -11
  73. package/lib/modules/Cart/index.js +72 -21
  74. package/lib/modules/Cart/types.d.ts +98 -9
  75. package/lib/modules/Cart/utils.d.ts +114 -0
  76. package/lib/modules/Cart/utils.js +320 -0
  77. package/lib/modules/Date/index.d.ts +11 -12
  78. package/lib/modules/Date/index.js +50 -31
  79. package/lib/modules/Date/types.d.ts +51 -20
  80. package/lib/modules/Date/types.js +0 -4
  81. package/lib/modules/Date/utils.d.ts +35 -0
  82. package/lib/modules/Date/utils.js +167 -0
  83. package/lib/modules/Discount/index.d.ts +26 -0
  84. package/lib/modules/Discount/index.js +118 -0
  85. package/lib/modules/Discount/types.d.ts +66 -0
  86. package/lib/modules/Discount/types.js +33 -0
  87. package/lib/modules/Order/index.d.ts +16 -12
  88. package/lib/modules/Order/index.js +23 -51
  89. package/lib/modules/Order/types.d.ts +18 -41
  90. package/lib/modules/Payment/index.d.ts +0 -2
  91. package/lib/modules/Payment/index.js +6 -17
  92. package/lib/modules/Payment/types.d.ts +0 -2
  93. package/lib/modules/Product/types.d.ts +48 -1
  94. package/lib/modules/ProductList/index.d.ts +1 -0
  95. package/lib/modules/ProductList/index.js +4 -0
  96. package/lib/modules/ProductList/types.d.ts +1 -0
  97. package/lib/modules/Resource/types.d.ts +6 -2
  98. package/lib/modules/Rules/index.d.ts +32 -0
  99. package/lib/modules/Rules/index.js +283 -0
  100. package/lib/modules/Rules/types.d.ts +46 -0
  101. package/lib/modules/Rules/types.js +33 -0
  102. package/lib/modules/Summary/index.d.ts +13 -0
  103. package/lib/modules/Summary/index.js +49 -0
  104. package/lib/modules/Summary/types.d.ts +13 -0
  105. package/lib/modules/Summary/types.js +17 -0
  106. package/lib/modules/Summary/utils.d.ts +19 -0
  107. package/lib/modules/Summary/utils.js +79 -0
  108. package/lib/plugins/index.d.ts +3 -2
  109. package/lib/plugins/index.js +3 -1
  110. package/lib/plugins/request.d.ts +4 -3
  111. package/lib/plugins/request.js +4 -20
  112. package/lib/plugins/shopStore.d.ts +4 -0
  113. package/lib/plugins/shopStore.js +17 -0
  114. package/lib/solution/BookingByStep/index.d.ts +73 -12
  115. package/lib/solution/BookingByStep/index.js +451 -24
  116. package/lib/solution/BookingByStep/types.d.ts +2 -0
  117. package/lib/solution/BookingByStep/types.js +3 -0
  118. package/lib/solution/BookingByStep/utils/products.d.ts +11 -0
  119. package/lib/solution/BookingByStep/utils/products.js +60 -0
  120. package/lib/solution/BookingByStep/utils/resources.d.ts +59 -10
  121. package/lib/solution/BookingByStep/utils/resources.js +106 -49
  122. package/lib/solution/ShopDiscount/index.d.ts +50 -0
  123. package/lib/solution/ShopDiscount/index.js +321 -0
  124. package/lib/solution/ShopDiscount/types.d.ts +24 -0
  125. package/lib/solution/ShopDiscount/types.js +38 -0
  126. package/lib/solution/ShopDiscount/utils.d.ts +1 -0
  127. package/lib/solution/ShopDiscount/utils.js +32 -0
  128. package/lib/solution/index.d.ts +1 -0
  129. package/lib/solution/index.js +3 -1
  130. package/package.json +4 -4
@@ -0,0 +1,167 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/modules/Date/utils.ts
30
+ var utils_exports = {};
31
+ __export(utils_exports, {
32
+ disableAllDates: () => disableAllDates,
33
+ disableDatesBeforeOneDay: () => disableDatesBeforeOneDay,
34
+ generateMonthDates: () => generateMonthDates,
35
+ handleAvailableDateByResource: () => handleAvailableDateByResource,
36
+ handleAvailableDatesByRules: () => handleAvailableDatesByRules
37
+ });
38
+ module.exports = __toCommonJS(utils_exports);
39
+ var import_dayjs = __toESM(require("dayjs"));
40
+ var generateMonthDates = (startDate, endDate) => {
41
+ const start = (0, import_dayjs.default)(startDate).format("YYYY-MM-01");
42
+ const end = (0, import_dayjs.default)(endDate).format("YYYY-MM-DD");
43
+ const dates = [];
44
+ let currentDate = (0, import_dayjs.default)(start);
45
+ while ((0, import_dayjs.default)(currentDate).isBefore((0, import_dayjs.default)(end)) || (0, import_dayjs.default)(currentDate).isSame((0, import_dayjs.default)(end))) {
46
+ dates.push({
47
+ date: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD"),
48
+ week: (0, import_dayjs.default)(currentDate).format("ddd"),
49
+ weekNum: (0, import_dayjs.default)(currentDate).day(),
50
+ status: "available"
51
+ });
52
+ currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
53
+ }
54
+ return dates;
55
+ };
56
+ var disableAllDates = (dates) => {
57
+ return dates.map((date) => ({ ...date, status: "unavailable" }));
58
+ };
59
+ var disableDatesBeforeOneDay = (dates, oneDay) => {
60
+ const day = oneDay ? (0, import_dayjs.default)(oneDay).format("YYYY-MM-DD") : (0, import_dayjs.default)().format("YYYY-MM-DD");
61
+ return dates.map((date) => {
62
+ if ((0, import_dayjs.default)(date.date).isBefore(day)) {
63
+ return { ...date, status: "unavailable" };
64
+ } else {
65
+ return date;
66
+ }
67
+ });
68
+ };
69
+ var handleAvailableDateByResource = (resources, dates) => {
70
+ const dateMap = {};
71
+ resources.forEach((resource) => {
72
+ const { form_id, id, times, ...others } = resource;
73
+ times.forEach((time) => {
74
+ var _a;
75
+ const { start_at } = time;
76
+ const date = (0, import_dayjs.default)(start_at).format("YYYY-MM-DD");
77
+ if (!dateMap[date]) {
78
+ dateMap[date] = [{ form_id, id, ...others, times: [time] }];
79
+ } else {
80
+ const temp = (_a = dateMap[date].filter((item) => item.id === id)) == null ? void 0 : _a[0];
81
+ if (temp) {
82
+ temp.times.push(time);
83
+ } else {
84
+ dateMap[date].push({ form_id, id, ...others, times: [time] });
85
+ }
86
+ }
87
+ });
88
+ });
89
+ return dates.map((date) => {
90
+ const resource = dateMap[date.date];
91
+ if (resource) {
92
+ return { ...date, resource };
93
+ } else {
94
+ return { ...date, status: "unavailable", resource: [] };
95
+ }
96
+ });
97
+ };
98
+ var handleAvailableDatesByRules = (dates, rules) => {
99
+ let newDates = disableDatesBeforeOneDay(dates);
100
+ if (!(rules == null ? void 0 : rules.length)) {
101
+ return newDates;
102
+ }
103
+ let latestStartDate = "";
104
+ let earliestEndDate = "";
105
+ let resourceFormIds = [];
106
+ rules.forEach((rule) => {
107
+ var _a;
108
+ const { future_day, unit, unit_type } = (rule == null ? void 0 : rule.cut_off_time) || {};
109
+ if (future_day) {
110
+ const endDate = (0, import_dayjs.default)().add(future_day, "day");
111
+ if (!earliestEndDate || endDate.isBefore((0, import_dayjs.default)(earliestEndDate))) {
112
+ earliestEndDate = endDate.format("YYYY-MM-DD");
113
+ }
114
+ } else if (future_day === 0) {
115
+ const endDate = (0, import_dayjs.default)();
116
+ if (!earliestEndDate || endDate.isBefore((0, import_dayjs.default)(earliestEndDate))) {
117
+ earliestEndDate = endDate.format("YYYY-MM-DD");
118
+ }
119
+ }
120
+ if (unit && unit_type) {
121
+ const startDate = (0, import_dayjs.default)((0, import_dayjs.default)().add(unit, unit_type).format("YYYY-MM-DD"));
122
+ if (!latestStartDate || startDate.isAfter((0, import_dayjs.default)(latestStartDate))) {
123
+ latestStartDate = startDate.format("YYYY-MM-DD");
124
+ }
125
+ }
126
+ if ((_a = rule == null ? void 0 : rule.resourceFormIds) == null ? void 0 : _a.length) {
127
+ resourceFormIds = [.../* @__PURE__ */ new Set([...resourceFormIds, ...rule == null ? void 0 : rule.resourceFormIds])];
128
+ }
129
+ });
130
+ newDates = newDates.map((date) => {
131
+ var _a;
132
+ const disabledDate = { ...date, status: "unavailable" };
133
+ if (!((_a = date == null ? void 0 : date.resource) == null ? void 0 : _a.length)) {
134
+ return disabledDate;
135
+ }
136
+ if (latestStartDate || earliestEndDate) {
137
+ if (latestStartDate && (0, import_dayjs.default)(date.date).isBefore(latestStartDate)) {
138
+ return disabledDate;
139
+ }
140
+ if (earliestEndDate && (0, import_dayjs.default)(date.date).isAfter(earliestEndDate)) {
141
+ return disabledDate;
142
+ }
143
+ }
144
+ if (resourceFormIds == null ? void 0 : resourceFormIds.length) {
145
+ let hasReourceCount = 0;
146
+ resourceFormIds.forEach((formId) => {
147
+ var _a2;
148
+ if (((_a2 = date == null ? void 0 : date.resource) == null ? void 0 : _a2.find((item) => item.form_id === formId)) !== void 0) {
149
+ hasReourceCount++;
150
+ }
151
+ });
152
+ if (hasReourceCount < resourceFormIds.length) {
153
+ return disabledDate;
154
+ }
155
+ }
156
+ return date;
157
+ });
158
+ return newDates;
159
+ };
160
+ // Annotate the CommonJS export names for ESM import in node:
161
+ 0 && (module.exports = {
162
+ disableAllDates,
163
+ disableDatesBeforeOneDay,
164
+ generateMonthDates,
165
+ handleAvailableDateByResource,
166
+ handleAvailableDatesByRules
167
+ });
@@ -0,0 +1,26 @@
1
+ import { Module, PisellCore, ModuleOptions } from "../../types";
2
+ import { BaseModule } from "../BaseModule";
3
+ import { Discount, DiscountModuleAPI } from "./types";
4
+ export declare class DiscountModule extends BaseModule implements Module, DiscountModuleAPI {
5
+ protected defaultName: string;
6
+ protected defaultVersion: string;
7
+ private request;
8
+ private window;
9
+ private store;
10
+ constructor(name?: string, version?: string);
11
+ initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
12
+ setDiscountList(discountList: Discount[]): Promise<void>;
13
+ getDiscountList(): Discount[];
14
+ loadPrepareConfig(params: {
15
+ action?: "create";
16
+ with_good_pass: 0 | 1;
17
+ customer_id: number;
18
+ }): Promise<Discount[]>;
19
+ batchSearch(code: string): Promise<Discount[]>;
20
+ filterEnabledDiscountList(discountList: Discount[]): Discount[];
21
+ uniqueByProductId(discountList: Discount[]): Discount[];
22
+ filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
23
+ calcDiscountApplicableProductTotalPrice(discount: Discount): number;
24
+ destroy(): Promise<void>;
25
+ clear(): Promise<void>;
26
+ }
@@ -0,0 +1,118 @@
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/Discount/index.ts
20
+ var Discount_exports = {};
21
+ __export(Discount_exports, {
22
+ DiscountModule: () => DiscountModule
23
+ });
24
+ module.exports = __toCommonJS(Discount_exports);
25
+ var import_utils = require("../../solution/ShopDiscount/utils");
26
+ var import_BaseModule = require("../BaseModule");
27
+ var import_types = require("./types");
28
+ var DiscountModule = class extends import_BaseModule.BaseModule {
29
+ constructor(name, version) {
30
+ super(name, version);
31
+ this.defaultName = "discount";
32
+ this.defaultVersion = "1.0.0";
33
+ }
34
+ async initialize(core, options) {
35
+ this.core = core;
36
+ this.store = options == null ? void 0 : options.store;
37
+ this.request = core.getPlugin("request");
38
+ this.window = core.getPlugin("window");
39
+ if (!this.request) {
40
+ throw new Error("discount模块需要 request 插件支持");
41
+ }
42
+ if (!this.window) {
43
+ throw new Error("discount模块需要 window 插件支持");
44
+ }
45
+ }
46
+ async setDiscountList(discountList) {
47
+ this.store.discountList = discountList;
48
+ await this.core.effects.emit(
49
+ import_types.DiscountHooks.OnDiscountListChange,
50
+ discountList
51
+ );
52
+ }
53
+ getDiscountList() {
54
+ return this.store.discountList;
55
+ }
56
+ async loadPrepareConfig(params) {
57
+ var _a;
58
+ const prepareConfig = await this.request.post(
59
+ `/order/prepare/config`,
60
+ params
61
+ );
62
+ const goodPassList = this.uniqueByProductId(
63
+ this.filterEnabledDiscountList(
64
+ ((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || []
65
+ ) || []
66
+ ) || [];
67
+ return goodPassList;
68
+ }
69
+ async batchSearch(code) {
70
+ const result = await this.request.get(`/machinecode/batch-search`, {
71
+ code,
72
+ translate_flag: 1,
73
+ tag: "good_pass",
74
+ available: 1,
75
+ relation_product: 1
76
+ });
77
+ const resultDiscountList = this.uniqueByProductId(this.filterEnabledDiscountList((result == null ? void 0 : result.data) || []) || []) || [];
78
+ return resultDiscountList;
79
+ }
80
+ filterEnabledDiscountList(discountList) {
81
+ return discountList.filter(
82
+ (discount) => discount.limit_status === "enable" && Number((discount == null ? void 0 : discount.par_value) || 0) - Number((discount == null ? void 0 : discount.used_par_value) || 0) > 0
83
+ );
84
+ }
85
+ // 根据productIds去重
86
+ uniqueByProductId(discountList) {
87
+ return (0, import_utils.uniqueById)(discountList, "product_id");
88
+ }
89
+ filterDiscountListByProductIds(discountList, productIds) {
90
+ return discountList.filter((discount) => {
91
+ const applicableProductIds = discount.applicableProductIds || [];
92
+ return applicableProductIds.some((id) => productIds.includes(id));
93
+ });
94
+ }
95
+ calcDiscountApplicableProductTotalPrice(discount) {
96
+ if (discount.appliedProductDetails) {
97
+ return discount.appliedProductDetails.reduce((total, product) => {
98
+ const price = Number(product == null ? void 0 : product.amount) || 0;
99
+ return total + price;
100
+ }, 0);
101
+ }
102
+ return (discount == null ? void 0 : discount.savedAmount) || 0;
103
+ }
104
+ async destroy() {
105
+ this.store.discountList = [];
106
+ this.core.effects.offByModuleDestroy(this.name);
107
+ await this.core.effects.emit(import_types.DiscountHooks.OnDestroy, {});
108
+ console.log("[Discount] 已销毁");
109
+ }
110
+ async clear() {
111
+ this.store.discountList = [];
112
+ console.log("[Discount] clear");
113
+ }
114
+ };
115
+ // Annotate the CommonJS export names for ESM import in node:
116
+ 0 && (module.exports = {
117
+ DiscountModule
118
+ });
@@ -0,0 +1,66 @@
1
+ export declare enum DiscountHooks {
2
+ OnDiscountListChange = "discount:onDiscountListChange",
3
+ OnDestroy = "discount:onDestroy"
4
+ }
5
+ interface Product {
6
+ id: number;
7
+ title: string;
8
+ is_charge_tax: number;
9
+ base_price: string;
10
+ }
11
+ interface Formattitle {
12
+ auto: string;
13
+ original: string;
14
+ en?: any;
15
+ 'zh-CN'?: any;
16
+ 'zh-HK'?: any;
17
+ }
18
+ interface Limitedrelationproductdata {
19
+ id: number;
20
+ type: 'product_all' | 'products' | 'product_collection';
21
+ product_ids: number[];
22
+ product_collection_id: number[];
23
+ }
24
+ interface ApplicableProductDetails {
25
+ amount: string;
26
+ type: string;
27
+ resource_id: number;
28
+ title: string;
29
+ original_amount: string;
30
+ }
31
+ export interface Discount {
32
+ id: number;
33
+ product_name: string;
34
+ encoded: string;
35
+ code: string;
36
+ tag: string;
37
+ expire_time?: string;
38
+ product_id: number;
39
+ relation_type: string;
40
+ par_value: string;
41
+ used_par_value: string;
42
+ limit_status: string;
43
+ limited_relation_product_data: Limitedrelationproductdata;
44
+ balance: string;
45
+ format_title: Formattitle;
46
+ product: Product;
47
+ resource_id?: number;
48
+ savedAmount?: number;
49
+ isEditMode?: boolean;
50
+ isManualSelect?: boolean;
51
+ isDisabled?: boolean;
52
+ isSelected?: boolean;
53
+ isAvailable?: boolean;
54
+ isUsed?: boolean;
55
+ applicableProductIds?: number[];
56
+ applicableProductDetails: ApplicableProductDetails[];
57
+ appliedProductDetails: ApplicableProductDetails[];
58
+ }
59
+ export interface DiscountState {
60
+ discountList: Discount[];
61
+ }
62
+ export interface DiscountModuleAPI {
63
+ setDiscountList: (discountList: Discount[]) => Promise<void>;
64
+ clear: () => Promise<void>;
65
+ }
66
+ 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/Discount/types.ts
20
+ var types_exports = {};
21
+ __export(types_exports, {
22
+ DiscountHooks: () => DiscountHooks
23
+ });
24
+ module.exports = __toCommonJS(types_exports);
25
+ var DiscountHooks = /* @__PURE__ */ ((DiscountHooks2) => {
26
+ DiscountHooks2["OnDiscountListChange"] = "discount:onDiscountListChange";
27
+ DiscountHooks2["OnDestroy"] = "discount:onDestroy";
28
+ return DiscountHooks2;
29
+ })(DiscountHooks || {});
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ DiscountHooks
33
+ });
@@ -1,17 +1,21 @@
1
- import { Module, PisellCore, ModuleOptions } from '../../types';
2
- import { BaseModule } from '../BaseModule';
3
- import { Order, OrderItem, OrderModuleAPI, OrderStatus } from './types';
1
+ import { Module, PisellCore, ModuleOptions } from "../../types";
2
+ import { BaseModule } from "../BaseModule";
3
+ import { OrderModuleAPI, CommitOrderParams } from "./types";
4
4
  export declare class OrderModule extends BaseModule implements Module, OrderModuleAPI {
5
5
  protected defaultName: string;
6
6
  protected defaultVersion: string;
7
- private state;
7
+ private store;
8
+ private request;
8
9
  constructor(name?: string, version?: string);
9
- initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
10
- createOrder(items: OrderItem[]): Promise<Order>;
11
- getOrder(orderId: string): Promise<Order>;
12
- updateOrderStatus(orderId: string, status: OrderStatus): Promise<void>;
13
- cancelOrder(orderId: string): Promise<void>;
14
- getOrderHistory(): Promise<Order[]>;
15
- getCurrentOrder(): Order | null;
16
- calculateTotalAmount(items: OrderItem[]): number;
10
+ initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
11
+ createOrder(params: CommitOrderParams["query"]): {
12
+ type: string;
13
+ platform: string;
14
+ sales_channel: string;
15
+ order_sales_channel: string;
16
+ bookings: any[];
17
+ shop_note: string;
18
+ schedule_date: string;
19
+ };
20
+ commitOrder(order: CommitOrderParams): Promise<void>;
17
21
  }
@@ -23,70 +23,42 @@ __export(Order_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(Order_exports);
25
25
  var import_BaseModule = require("../BaseModule");
26
- var import_types = require("./types");
27
26
  var OrderModule = class extends import_BaseModule.BaseModule {
28
27
  constructor(name, version) {
29
28
  super(name, version);
30
29
  this.defaultName = "order";
31
30
  this.defaultVersion = "1.0.0";
32
- this.state = {
33
- currentOrder: null,
34
- orderHistory: []
35
- };
36
31
  }
37
32
  async initialize(core, options) {
38
33
  this.core = core;
39
- if (options == null ? void 0 : options.initialState) {
40
- this.state = { ...this.state, ...options.initialState };
41
- }
34
+ this.store = options.store;
35
+ this.request = this.core.getPlugin("request");
42
36
  }
43
- async createOrder(items) {
37
+ createOrder(params) {
44
38
  const order = {
45
- id: Date.now().toString(),
46
- // 实际应该使用更可靠的 ID 生成方式
47
- orderNumber: `ORD-${Date.now()}`,
48
- status: "pending",
49
- items,
50
- totalAmount: this.calculateTotalAmount(items),
51
- createdAt: /* @__PURE__ */ new Date(),
52
- updatedAt: /* @__PURE__ */ new Date()
39
+ type: "appointment_booking",
40
+ platform: "H5",
41
+ sales_channel: "my_pisel",
42
+ order_sales_channel: "online_store",
43
+ bookings: [],
44
+ shop_note: "",
45
+ schedule_date: ""
53
46
  };
54
- this.state.currentOrder = order;
55
- await this.core.effects.emit(import_types.OrderHooks.OnOrderCreate, order);
56
- return order;
57
- }
58
- async getOrder(orderId) {
59
- const order = this.state.orderHistory.find((o) => o.id === orderId);
60
- if (!order)
61
- throw new Error("Order not found");
47
+ if (params.cartItems.length > 0) {
48
+ params.cartItems.forEach((item) => {
49
+ order.bookings.push(item._origin);
50
+ });
51
+ const firstCartItem = params.cartItems[0];
52
+ order.schedule_date = firstCartItem.start_date + " " + firstCartItem.start_time + ":00";
53
+ }
62
54
  return order;
63
55
  }
64
- async updateOrderStatus(orderId, status) {
65
- const order = this.state.orderHistory.find((o) => o.id === orderId);
66
- if (!order)
67
- return;
68
- order.status = status;
69
- order.updatedAt = /* @__PURE__ */ new Date();
70
- await this.core.effects.emit(import_types.OrderHooks.OnOrderStatusChange, { orderId, status });
71
- await this.core.effects.emit(import_types.OrderHooks.OnOrderUpdate, order);
72
- }
73
- async cancelOrder(orderId) {
74
- const order = this.state.orderHistory.find((o) => o.id === orderId);
75
- if (!order)
76
- return;
77
- order.status = "cancelled";
78
- order.updatedAt = /* @__PURE__ */ new Date();
79
- await this.core.effects.emit(import_types.OrderHooks.OnOrderCancel, order);
80
- await this.core.effects.emit(import_types.OrderHooks.OnOrderUpdate, order);
81
- }
82
- async getOrderHistory() {
83
- return this.state.orderHistory;
84
- }
85
- getCurrentOrder() {
86
- return this.state.currentOrder;
87
- }
88
- calculateTotalAmount(items) {
89
- return items.reduce((total, item) => total + item.price * item.quantity, 0);
56
+ async commitOrder(order) {
57
+ const { url, query } = order;
58
+ const fetchUrl = url || "/order/appointment";
59
+ const params = this.createOrder(query);
60
+ console.log(params);
61
+ return this.request.post(fetchUrl, params);
90
62
  }
91
63
  };
92
64
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,57 +1,34 @@
1
- import { Guest } from '../Guests/types';
2
- import { Resource } from '../Resource/types';
3
- import { TimeSlot } from '../Date/types';
1
+ import { CartItem } from "../Cart/types";
4
2
  export declare enum OrderHooks {
5
3
  OnOrderCreate = "order:onOrderCreate",
6
4
  OnOrderUpdate = "order:onOrderUpdate",
7
5
  OnOrderCancel = "order:onOrderCancel",
8
6
  OnOrderStatusChange = "order:onOrderStatusChange"
9
7
  }
10
- /**
11
- * 订单状态
12
- */
13
- export type OrderStatus = 'pending' | 'paid' | 'confirmed' | 'completed' | 'cancelled' | 'refunded';
14
- /**
15
- * 订单项
16
- */
17
- export interface OrderItem {
18
- id: string;
19
- productId: string;
20
- quantity: number;
21
- price: number;
22
- guest: Guest;
23
- resource: Resource;
24
- timeSlot: TimeSlot;
8
+ export interface OrderState {
25
9
  }
26
10
  /**
27
11
  * 订单信息
28
12
  */
29
- export interface Order {
30
- id: string;
31
- orderNumber: string;
32
- status: OrderStatus;
33
- items: OrderItem[];
34
- totalAmount: number;
35
- createdAt: Date;
36
- updatedAt: Date;
37
- metadata?: Record<string, any>;
38
- }
39
- /**
40
- * 订单模块状态
41
- */
42
- export interface OrderState {
43
- currentOrder: Order | null;
44
- orderHistory: Order[];
13
+ export interface CommitOrderParams {
14
+ url?: string;
15
+ query: {
16
+ cartItems: CartItem[];
17
+ };
45
18
  }
46
19
  /**
47
20
  * 订单模块 API
48
21
  */
49
22
  export interface OrderModuleAPI {
50
- createOrder: (items: OrderItem[]) => Promise<Order>;
51
- getOrder: (orderId: string) => Promise<Order>;
52
- updateOrderStatus: (orderId: string, status: OrderStatus) => Promise<void>;
53
- cancelOrder: (orderId: string) => Promise<void>;
54
- getOrderHistory: () => Promise<Order[]>;
55
- getCurrentOrder: () => Order | null;
56
- calculateTotalAmount: (items: OrderItem[]) => number;
23
+ /**
24
+ * 创建订单
25
+ * @param params 订单信息
26
+ * @returns 订单信息
27
+ */
28
+ createOrder: (params: CommitOrderParams["query"]) => any;
29
+ /**
30
+ * 提交订单
31
+ * @param params 订单信息
32
+ */
33
+ commitOrder: (params: CommitOrderParams) => Promise<void>;
57
34
  }
@@ -1,14 +1,12 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
3
  import { Payment, PaymentModuleAPI, PaymentMethod, PaymentStatus } from './types';
4
- import { Order } from '../Order/types';
5
4
  export declare class PaymentModule extends BaseModule implements Module, PaymentModuleAPI {
6
5
  protected defaultName: string;
7
6
  protected defaultVersion: string;
8
7
  private state;
9
8
  constructor(name?: string, version?: string);
10
9
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
11
- initPayment(order: Order, method: PaymentMethod): Promise<Payment>;
12
10
  processPayment(paymentId: string): Promise<void>;
13
11
  getPayment(paymentId: string): Promise<Payment>;
14
12
  getPaymentHistory(): Promise<Payment[]>;
@@ -40,23 +40,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
40
40
  this.state = { ...this.state, ...options.initialState };
41
41
  }
42
42
  }
43
- async initPayment(order, method) {
44
- const payment = {
45
- id: Date.now().toString(),
46
- // 实际应该使用更可靠的 ID 生成方式
47
- orderId: order.id,
48
- amount: order.totalAmount,
49
- currency: "CNY",
50
- // 默认货币
51
- method,
52
- status: "pending",
53
- createdAt: /* @__PURE__ */ new Date(),
54
- updatedAt: /* @__PURE__ */ new Date()
55
- };
56
- this.state.currentPayment = payment;
57
- await this.core.effects.emit(import_types.PaymentHooks.OnPaymentInit, payment);
58
- return payment;
59
- }
43
+ // async initPayment(order: OrderModule, method: PaymentMethod) {
44
+ // const payment: Payment = {}
45
+ // this.state.currentPayment = payment
46
+ // await this.core.effects.emit(PaymentHooks.OnPaymentInit, payment)
47
+ // return payment
48
+ // }
60
49
  async processPayment(paymentId) {
61
50
  const payment = this.state.paymentHistory.find((p) => p.id === paymentId);
62
51
  if (!payment)
@@ -1,4 +1,3 @@
1
- import { Order } from '../Order/types';
2
1
  export declare enum PaymentHooks {
3
2
  OnPaymentInit = "payment:onPaymentInit",
4
3
  OnPaymentSuccess = "payment:onPaymentSuccess",
@@ -39,7 +38,6 @@ export interface PaymentState {
39
38
  * 支付模块 API
40
39
  */
41
40
  export interface PaymentModuleAPI {
42
- initPayment: (order: Order, method: PaymentMethod) => Promise<Payment>;
43
41
  processPayment: (paymentId: string) => Promise<void>;
44
42
  getPayment: (paymentId: string) => Promise<Payment>;
45
43
  getPaymentHistory: () => Promise<Payment[]>;