@pisell/pisellos 0.0.253 → 0.0.255

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.
@@ -17,6 +17,23 @@ export declare class DateModule extends BaseModule implements Module, DateModule
17
17
  getDateList(): ITime[];
18
18
  setDateList(dateList: ITime[]): void;
19
19
  fetchResourceDates(params: IGetAvailableTimeListParams): Promise<any>;
20
+ /**
21
+ * 将时间向上取整到下一个10分钟整数
22
+ *
23
+ * @param time dayjs 时间对象
24
+ * @returns 向上取整后的时间字符串 (YYYY-MM-DD HH:mm 格式)
25
+ */
26
+ private roundUpToNext10Minutes;
27
+ /**
28
+ * 校正资源时间段数据
29
+ *
30
+ * 如果时间段的 start_at 早于资源的 start_time,将其同步为 start_time 的下一个10分钟整数
31
+ * 如果修正后 end_at 也早于修正后的 start_time,则删除该时间段
32
+ *
33
+ * @param resourcesData 资源数据数组
34
+ * @returns 校正后的资源数据数组
35
+ */
36
+ private correctResourceTimeSlots;
20
37
  getResourceAvailableTimeList(params: IGetAvailableTimeListParams): Promise<ITime[]>;
21
38
  clearDateRange(): void;
22
39
  storeChange(): void;
@@ -32,6 +32,7 @@ __export(Date_exports, {
32
32
  DateModule: () => DateModule
33
33
  });
34
34
  module.exports = __toCommonJS(Date_exports);
35
+ var import_dayjs = __toESM(require("dayjs"));
35
36
  var import_BaseModule = require("../BaseModule");
36
37
  var import_utils = require("./utils");
37
38
  var import_cloneDeep = __toESM(require("lodash-es/cloneDeep"));
@@ -138,11 +139,74 @@ var DateModule = class extends import_BaseModule.BaseModule {
138
139
  }, {
139
140
  useCache
140
141
  });
142
+ if ((res == null ? void 0 : res.data) && Array.isArray(res.data)) {
143
+ res.data = this.correctResourceTimeSlots(res.data);
144
+ }
141
145
  return res;
142
146
  } catch (error) {
143
147
  console.error(error);
144
148
  }
145
149
  }
150
+ /**
151
+ * 将时间向上取整到下一个10分钟整数
152
+ *
153
+ * @param time dayjs 时间对象
154
+ * @returns 向上取整后的时间字符串 (YYYY-MM-DD HH:mm 格式)
155
+ */
156
+ roundUpToNext10Minutes(time) {
157
+ const minutes = time.minute();
158
+ const remainder = minutes % 10;
159
+ if (remainder === 0) {
160
+ return time.format("YYYY-MM-DD HH:mm");
161
+ } else {
162
+ const minutesToAdd = 10 - remainder;
163
+ const roundedTime = time.add(minutesToAdd, "minute");
164
+ return roundedTime.format("YYYY-MM-DD HH:mm");
165
+ }
166
+ }
167
+ /**
168
+ * 校正资源时间段数据
169
+ *
170
+ * 如果时间段的 start_at 早于资源的 start_time,将其同步为 start_time 的下一个10分钟整数
171
+ * 如果修正后 end_at 也早于修正后的 start_time,则删除该时间段
172
+ *
173
+ * @param resourcesData 资源数据数组
174
+ * @returns 校正后的资源数据数组
175
+ */
176
+ correctResourceTimeSlots(resourcesData) {
177
+ return resourcesData.map((resource) => {
178
+ if (!resource.times || !Array.isArray(resource.times) || !resource.start_time) {
179
+ return resource;
180
+ }
181
+ const resourceStartTime = (0, import_dayjs.default)(resource.start_time);
182
+ const correctedTimes = resource.times.map((timeSlot) => {
183
+ if (!timeSlot.start_at || !timeSlot.end_at) {
184
+ return timeSlot;
185
+ }
186
+ const startAt = (0, import_dayjs.default)(timeSlot.start_at);
187
+ const endAt = (0, import_dayjs.default)(timeSlot.end_at);
188
+ if (startAt.isBefore(resourceStartTime)) {
189
+ const roundedStartTime = this.roundUpToNext10Minutes(resourceStartTime);
190
+ const roundedStartTimeDayjs = (0, import_dayjs.default)(roundedStartTime);
191
+ console.log(`[DateModule] 修正时间段开始时间: ${timeSlot.start_at} -> ${roundedStartTime} (资源ID: ${resource.id}, 原始start_time: ${resource.start_time})`);
192
+ const correctedTimeSlot = {
193
+ ...timeSlot,
194
+ start_at: roundedStartTime
195
+ };
196
+ if (endAt.isBefore(roundedStartTimeDayjs)) {
197
+ console.log(`[DateModule] 时间段无效,将被删除: ${timeSlot.start_at} - ${timeSlot.end_at} (资源ID: ${resource.id}, 修正后start_time: ${roundedStartTime})`);
198
+ return null;
199
+ }
200
+ return correctedTimeSlot;
201
+ }
202
+ return timeSlot;
203
+ }).filter((timeSlot) => timeSlot !== null);
204
+ return {
205
+ ...resource,
206
+ times: correctedTimes
207
+ };
208
+ });
209
+ }
146
210
  async getResourceAvailableTimeList(params) {
147
211
  var _a;
148
212
  const { query, rules, type } = params;
@@ -47,7 +47,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
47
47
  this.core = core;
48
48
  this.store = options.store;
49
49
  this.request = this.core.getPlugin("request");
50
- this.logger = this.core.getPlugin("logger");
50
+ const appPlugin = this.core.getPlugin("app");
51
+ if (!appPlugin) {
52
+ throw new Error("Order 模块需要 app 插件支持");
53
+ }
54
+ const app = appPlugin.getApp();
55
+ this.logger = app.logger;
51
56
  this.logInfo("OrderModule initialized successfully");
52
57
  }
53
58
  /**
@@ -504,7 +504,7 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
504
504
  * 为某个订单添加支付项(新方法)
505
505
  */
506
506
  async addPaymentItemAsync(orderUuid, paymentItem) {
507
- var _a;
507
+ var _a, _b, _c;
508
508
  this.logInfo("Starting addPaymentItemAsync", {
509
509
  orderUuid,
510
510
  paymentAmount: paymentItem.amount,
@@ -532,6 +532,8 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
532
532
  order_payment_type: paymentItem.order_payment_type || "normal",
533
533
  // 默认为正常支付
534
534
  metadata: {
535
+ ...paymentItem.metadata,
536
+ // 保留传入的所有 metadata 字段
535
537
  unique_payment_number: paymentUuid
536
538
  // 设置唯一支付号为支付项的 uuid
537
539
  }
@@ -547,7 +549,14 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
547
549
  orderUuid,
548
550
  paymentUuid: newPaymentItem.uuid,
549
551
  uniquePaymentNumber: (_a = newPaymentItem.metadata) == null ? void 0 : _a.unique_payment_number,
550
- newExpectAmount: order.expect_amount
552
+ newExpectAmount: order.expect_amount,
553
+ paymentAmount: newPaymentItem.amount,
554
+ paymentCode: newPaymentItem.code,
555
+ orderPaymentType: newPaymentItem.order_payment_type,
556
+ metadataFields: Object.keys(newPaymentItem.metadata || {}),
557
+ // 现金支付找零信息
558
+ actualPaidAmount: (_b = newPaymentItem.metadata) == null ? void 0 : _b.actual_paid_amount,
559
+ changeGivenAmount: (_c = newPaymentItem.metadata) == null ? void 0 : _c.change_given_amount
551
560
  });
552
561
  } catch (error) {
553
562
  console.error("[PaymentModule] 添加支付项失败", error);
@@ -111,6 +111,10 @@ export interface PaymentItem {
111
111
  unique_payment_number?: string;
112
112
  /** rouding规则 */
113
113
  rounding_rule?: any;
114
+ /** 实付金额(现金支付时的实际给出金额) */
115
+ actual_paid_amount?: number;
116
+ /** 找零金额(现金支付时的找零金额) */
117
+ change_given_amount?: number;
114
118
  };
115
119
  /** rouding金额 */
116
120
  rounding_amount?: string;
@@ -230,6 +234,10 @@ export interface PaymentItemInput {
230
234
  unique_payment_number?: string;
231
235
  /** rounding规则 */
232
236
  rounding_rule?: any;
237
+ /** 实付金额(现金支付时的实际给出金额) */
238
+ actual_paid_amount?: number;
239
+ /** 找零金额(现金支付时的找零金额) */
240
+ change_given_amount?: number;
233
241
  };
234
242
  }
235
243
  /**
@@ -90,7 +90,8 @@ var WalletPassPaymentImpl = class {
90
90
  async initializeWalletDataFromBusinessAsync(businessData) {
91
91
  var _a, _b;
92
92
  const startTime = Date.now();
93
- if (Number(((_a = businessData == null ? void 0 : businessData.amountInfo) == null ? void 0 : _a.totalAmount) || 0) <= 0 || Number(((_b = businessData == null ? void 0 : businessData.amountInfo) == null ? void 0 : _b.subTotal) || 0) <= 0) {
93
+ const walletParams = this.generateWalletParams(businessData);
94
+ if (Number(((_a = businessData == null ? void 0 : businessData.amountInfo) == null ? void 0 : _a.totalAmount) || 0) < 0 || Number(((_b = businessData == null ? void 0 : businessData.amountInfo) == null ? void 0 : _b.subTotal) || 0) < 0) {
94
95
  return {
95
96
  walletRecommendList: [],
96
97
  userIdentificationCodes: []
@@ -101,7 +102,6 @@ var WalletPassPaymentImpl = class {
101
102
  startTime
102
103
  });
103
104
  try {
104
- const walletParams = this.generateWalletParams(businessData);
105
105
  const result = await this.initializeWalletDataAsync(walletParams);
106
106
  const endTime = Date.now();
107
107
  const duration = endTime - startTime;
@@ -379,6 +379,21 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
379
379
  * 验证结账参数
380
380
  */
381
381
  private validateCheckoutParams;
382
+ /**
383
+ * 处理现金支付项的找零逻辑
384
+ *
385
+ * @param paymentItem 原始支付项
386
+ * @returns 处理后的支付项(包含找零信息)
387
+ */
388
+ private processCashPaymentItem;
389
+ /**
390
+ * 判断是否为现金支付
391
+ *
392
+ * @param paymentCode 支付代码
393
+ * @param paymentType 支付类型
394
+ * @returns 是否为现金支付
395
+ */
396
+ private isCashPayment;
382
397
  /**
383
398
  * 预加载支付方式(在初始化时调用)
384
399
  */
@@ -45,7 +45,12 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
45
45
  if (!this.request) {
46
46
  throw new Error("Checkout 解决方案需要 request 插件支持");
47
47
  }
48
- this.logger = core.getPlugin("logger");
48
+ const appPlugin = core.getPlugin("app");
49
+ if (!appPlugin) {
50
+ throw new Error("Checkout 解决方案需要 app 插件支持");
51
+ }
52
+ const app = appPlugin.getApp();
53
+ this.logger = app.logger;
49
54
  this.order = new import_Order.OrderModule();
50
55
  this.payment = new import_Payment.PaymentModule();
51
56
  this.store = {
@@ -874,6 +879,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
874
879
  if (oldAmount === formattedAmount) {
875
880
  return;
876
881
  }
882
+ this.logger.info("[Checkout] 设置自定义支付金额:", {
883
+ oldAmount,
884
+ newAmount: formattedAmount
885
+ });
877
886
  this.store.stateAmount = formattedAmount;
878
887
  await this.core.effects.emit(import_types.CheckoutHooks.OnStateAmountChanged, {
879
888
  oldAmount,
@@ -997,7 +1006,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
997
1006
  * @throws 当前没有活跃订单时抛出错误
998
1007
  */
999
1008
  async addPaymentItemAsync(paymentItem) {
1000
- var _a, _b, _c, _d;
1009
+ var _a, _b, _c, _d, _e, _f;
1001
1010
  this.logInfo("addPaymentItemAsync called", {
1002
1011
  paymentCode: paymentItem.code,
1003
1012
  paymentType: paymentItem.type,
@@ -1018,13 +1027,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1018
1027
  );
1019
1028
  }
1020
1029
  const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? "deposit" : "normal";
1030
+ const processedPaymentItem = await this.processCashPaymentItem(paymentItem);
1021
1031
  const metadata = {
1022
- ...paymentItem.metadata,
1032
+ ...processedPaymentItem.metadata,
1023
1033
  rounding_rule: this.otherParams.order_rounding_setting,
1024
1034
  shop_wallet_pass_id: this.otherParams.shop_wallet_pass_id
1025
1035
  };
1026
1036
  const paymentItemWithType = {
1027
- ...paymentItem,
1037
+ ...processedPaymentItem,
1028
1038
  order_payment_type: orderPaymentType,
1029
1039
  metadata
1030
1040
  };
@@ -1042,14 +1052,20 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1042
1052
  metadata: paymentItemWithType.metadata
1043
1053
  },
1044
1054
  orderDepositStatus: this.store.currentOrder.is_deposit,
1045
- calculatedOrderPaymentType: orderPaymentType
1055
+ calculatedOrderPaymentType: orderPaymentType,
1056
+ // 现金支付找零详情
1057
+ isCashPayment: this.isCashPayment(paymentItem.code, paymentItem.type),
1058
+ originalAmount: paymentItem.amount,
1059
+ processedAmount: paymentItemWithType.amount,
1060
+ actualPaidAmount: (_c = paymentItemWithType.metadata) == null ? void 0 : _c.actual_paid_amount,
1061
+ changeGivenAmount: (_d = paymentItemWithType.metadata) == null ? void 0 : _d.change_given_amount
1046
1062
  });
1047
1063
  await this.payment.addPaymentItemAsync(
1048
1064
  this.store.currentOrder.uuid,
1049
1065
  paymentItemWithType
1050
1066
  );
1051
1067
  console.log("[Checkout] 支付项添加成功");
1052
- const isEftposPayment = ((_c = paymentItem.type) == null ? void 0 : _c.toLowerCase()) === "eftpos" || ((_d = paymentItem.code) == null ? void 0 : _d.toUpperCase().includes("EFTPOS"));
1068
+ const isEftposPayment = ((_e = paymentItem.type) == null ? void 0 : _e.toLowerCase()) === "eftpos" || ((_f = paymentItem.code) == null ? void 0 : _f.toUpperCase().includes("EFTPOS"));
1053
1069
  console.log("[Checkout] EFTPOS 支付检查:", {
1054
1070
  paymentCode: paymentItem.code,
1055
1071
  paymentType: paymentItem.type,
@@ -1905,6 +1921,75 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1905
1921
  validateCheckoutParams(params) {
1906
1922
  return (0, import_utils.validateCheckoutData)(params);
1907
1923
  }
1924
+ /**
1925
+ * 处理现金支付项的找零逻辑
1926
+ *
1927
+ * @param paymentItem 原始支付项
1928
+ * @returns 处理后的支付项(包含找零信息)
1929
+ */
1930
+ async processCashPaymentItem(paymentItem) {
1931
+ const isCashPayment = this.isCashPayment(paymentItem.code, paymentItem.type);
1932
+ if (!isCashPayment) {
1933
+ return paymentItem;
1934
+ }
1935
+ try {
1936
+ const remainingAmountStr = await this.calculateRemainingAmountAsync();
1937
+ const remainingAmount = parseFloat(remainingAmountStr);
1938
+ const cashAmount = parseFloat(String(paymentItem.amount));
1939
+ console.log("[Checkout] 现金支付处理:", {
1940
+ cashAmount,
1941
+ remainingAmount,
1942
+ needsChange: cashAmount > remainingAmount
1943
+ });
1944
+ if (cashAmount <= remainingAmount) {
1945
+ return paymentItem;
1946
+ }
1947
+ const changeAmount = cashAmount - remainingAmount;
1948
+ console.log("[Checkout] 现金支付需要找零:", {
1949
+ actualPaidAmount: cashAmount,
1950
+ chargedAmount: remainingAmount,
1951
+ changeGivenAmount: changeAmount
1952
+ });
1953
+ const processedPaymentItem = {
1954
+ ...paymentItem,
1955
+ amount: remainingAmount,
1956
+ // 将 amount 设置为剩余待付金额
1957
+ metadata: {
1958
+ ...paymentItem.metadata,
1959
+ actual_paid_amount: cashAmount,
1960
+ // 实付金额
1961
+ change_given_amount: changeAmount
1962
+ // 找零金额
1963
+ }
1964
+ };
1965
+ this.logInfo("Cash payment with change processed", {
1966
+ originalAmount: cashAmount,
1967
+ chargedAmount: remainingAmount,
1968
+ changeAmount,
1969
+ paymentCode: paymentItem.code,
1970
+ paymentType: paymentItem.type
1971
+ });
1972
+ return processedPaymentItem;
1973
+ } catch (error) {
1974
+ console.error("[Checkout] 处理现金支付项时出错:", error);
1975
+ return paymentItem;
1976
+ }
1977
+ }
1978
+ /**
1979
+ * 判断是否为现金支付
1980
+ *
1981
+ * @param paymentCode 支付代码
1982
+ * @param paymentType 支付类型
1983
+ * @returns 是否为现金支付
1984
+ */
1985
+ isCashPayment(paymentCode, paymentType) {
1986
+ const codeUpper = (paymentCode == null ? void 0 : paymentCode.toUpperCase()) || "";
1987
+ const typeUpper = (paymentType == null ? void 0 : paymentType.toUpperCase()) || "";
1988
+ const cashIdentifiers = ["CASH", "CASHMANUAL", "MANUAL"];
1989
+ return cashIdentifiers.some(
1990
+ (identifier) => codeUpper.includes(identifier) || typeUpper.includes(identifier)
1991
+ );
1992
+ }
1908
1993
  /**
1909
1994
  * 预加载支付方式(在初始化时调用)
1910
1995
  */
@@ -2311,11 +2396,19 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2311
2396
  originalCount: paymentItems.length,
2312
2397
  processedCount: processedPaymentItems.length,
2313
2398
  sampleMetadata: (_b = processedPaymentItems[0]) == null ? void 0 : _b.metadata,
2314
- allPaymentItems: processedPaymentItems.map((p) => ({
2315
- code: p.code,
2316
- amount: p.amount,
2317
- metadata: p.metadata
2318
- }))
2399
+ allPaymentItems: processedPaymentItems.map((p) => {
2400
+ var _a2, _b2;
2401
+ return {
2402
+ code: p.code,
2403
+ amount: p.amount,
2404
+ voucherId: p.voucher_id,
2405
+ orderPaymentType: p.order_payment_type,
2406
+ metadata: p.metadata,
2407
+ // 现金支付找零信息
2408
+ actualPaidAmount: (_a2 = p.metadata) == null ? void 0 : _a2.actual_paid_amount,
2409
+ changeGivenAmount: (_b2 = p.metadata) == null ? void 0 : _b2.change_given_amount
2410
+ };
2411
+ })
2319
2412
  });
2320
2413
  const orderParams = {
2321
2414
  ...this.store.localOrderData,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.253",
4
+ "version": "0.0.255",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",