@pisell/pisellos 1.0.60 → 1.0.62

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;
@@ -1,4 +1,6 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
2
4
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
5
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
6
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -21,6 +23,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
21
23
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
22
24
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
23
25
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
26
+ import dayjs from 'dayjs';
24
27
  import { BaseModule } from "../BaseModule";
25
28
  import { disableAllDates, generateMonthDates, handleAvailableDateByResource, handleAvailableDatesByRules } from "./utils";
26
29
  import cloneDeep from 'lodash-es/cloneDeep';
@@ -204,22 +207,107 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
204
207
  });
205
208
  case 6:
206
209
  res = _context3.sent;
210
+ // 校正资源时间段数据
211
+ if (res !== null && res !== void 0 && res.data && Array.isArray(res.data)) {
212
+ res.data = this.correctResourceTimeSlots(res.data);
213
+ }
207
214
  return _context3.abrupt("return", res);
208
- case 10:
209
- _context3.prev = 10;
215
+ case 11:
216
+ _context3.prev = 11;
210
217
  _context3.t0 = _context3["catch"](3);
211
218
  console.error(_context3.t0);
212
- case 13:
219
+ case 14:
213
220
  case "end":
214
221
  return _context3.stop();
215
222
  }
216
- }, _callee3, this, [[3, 10]]);
223
+ }, _callee3, this, [[3, 11]]);
217
224
  }));
218
225
  function fetchResourceDates(_x4) {
219
226
  return _fetchResourceDates.apply(this, arguments);
220
227
  }
221
228
  return fetchResourceDates;
222
229
  }()
230
+ /**
231
+ * 将时间向上取整到下一个10分钟整数
232
+ *
233
+ * @param time dayjs 时间对象
234
+ * @returns 向上取整后的时间字符串 (YYYY-MM-DD HH:mm 格式)
235
+ */
236
+ }, {
237
+ key: "roundUpToNext10Minutes",
238
+ value: function roundUpToNext10Minutes(time) {
239
+ var minutes = time.minute();
240
+ var remainder = minutes % 10;
241
+ if (remainder === 0) {
242
+ // 如果已经是10分钟的整数,保持不变
243
+ return time.format('YYYY-MM-DD HH:mm');
244
+ } else {
245
+ // 向上取整到下一个10分钟
246
+ var minutesToAdd = 10 - remainder;
247
+ var roundedTime = time.add(minutesToAdd, 'minute');
248
+ return roundedTime.format('YYYY-MM-DD HH:mm');
249
+ }
250
+ }
251
+
252
+ /**
253
+ * 校正资源时间段数据
254
+ *
255
+ * 如果时间段的 start_at 早于资源的 start_time,将其同步为 start_time 的下一个10分钟整数
256
+ * 如果修正后 end_at 也早于修正后的 start_time,则删除该时间段
257
+ *
258
+ * @param resourcesData 资源数据数组
259
+ * @returns 校正后的资源数据数组
260
+ */
261
+ }, {
262
+ key: "correctResourceTimeSlots",
263
+ value: function correctResourceTimeSlots(resourcesData) {
264
+ var _this2 = this;
265
+ return resourcesData.map(function (resource) {
266
+ // 检查资源是否有 times 数组和 start_time
267
+ if (!resource.times || !Array.isArray(resource.times) || !resource.start_time) {
268
+ return resource;
269
+ }
270
+ var resourceStartTime = dayjs(resource.start_time);
271
+
272
+ // 过滤和修正时间段
273
+ var correctedTimes = resource.times.map(function (timeSlot) {
274
+ if (!timeSlot.start_at || !timeSlot.end_at) {
275
+ return timeSlot;
276
+ }
277
+ var startAt = dayjs(timeSlot.start_at);
278
+ var endAt = dayjs(timeSlot.end_at);
279
+
280
+ // 如果 start_at 早于资源的 start_time,需要修正
281
+ if (startAt.isBefore(resourceStartTime)) {
282
+ // 将 start_time 向上取整到下一个10分钟整数
283
+ var roundedStartTime = _this2.roundUpToNext10Minutes(resourceStartTime);
284
+ var roundedStartTimeDayjs = dayjs(roundedStartTime);
285
+ console.log("[DateModule] \u4FEE\u6B63\u65F6\u95F4\u6BB5\u5F00\u59CB\u65F6\u95F4: ".concat(timeSlot.start_at, " -> ").concat(roundedStartTime, " (\u8D44\u6E90ID: ").concat(resource.id, ", \u539F\u59CBstart_time: ").concat(resource.start_time, ")"));
286
+
287
+ // 将 start_at 修正为向上取整后的时间
288
+ var correctedTimeSlot = _objectSpread(_objectSpread({}, timeSlot), {}, {
289
+ start_at: roundedStartTime
290
+ });
291
+
292
+ // 检查修正后的 end_at 是否也早于修正后的 start_time
293
+ if (endAt.isBefore(roundedStartTimeDayjs)) {
294
+ console.log("[DateModule] \u65F6\u95F4\u6BB5\u65E0\u6548\uFF0C\u5C06\u88AB\u5220\u9664: ".concat(timeSlot.start_at, " - ").concat(timeSlot.end_at, " (\u8D44\u6E90ID: ").concat(resource.id, ", \u4FEE\u6B63\u540Estart_time: ").concat(roundedStartTime, ")"));
295
+ return null; // 标记为删除
296
+ }
297
+ return correctedTimeSlot;
298
+ }
299
+
300
+ // 不需要修正的时间段直接返回
301
+ return timeSlot;
302
+ }).filter(function (timeSlot) {
303
+ return timeSlot !== null;
304
+ }); // 过滤掉被删除的时间段
305
+
306
+ return _objectSpread(_objectSpread({}, resource), {}, {
307
+ times: correctedTimes
308
+ });
309
+ });
310
+ }
223
311
  }, {
224
312
  key: "getResourceAvailableTimeList",
225
313
  value: function () {
@@ -47,15 +47,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
47
47
  key: "initialize",
48
48
  value: function () {
49
49
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
50
+ var appPlugin, app;
50
51
  return _regeneratorRuntime().wrap(function _callee$(_context) {
51
52
  while (1) switch (_context.prev = _context.next) {
52
53
  case 0:
53
54
  this.core = core;
54
55
  this.store = options.store;
55
56
  this.request = this.core.getPlugin('request');
56
- this.logger = this.core.getPlugin('logger');
57
+ appPlugin = this.core.getPlugin('app');
58
+ if (appPlugin) {
59
+ _context.next = 6;
60
+ break;
61
+ }
62
+ throw new Error('Order 模块需要 app 插件支持');
63
+ case 6:
64
+ app = appPlugin.getApp();
65
+ this.logger = app.logger;
57
66
  this.logInfo('OrderModule initialized successfully');
58
- case 5:
67
+ case 9:
59
68
  case "end":
60
69
  return _context.stop();
61
70
  }
@@ -31,19 +31,19 @@ export declare class PaymentModule extends BaseModule implements Module, Payment
31
31
  /**
32
32
  * 记录信息日志
33
33
  */
34
- private logInfo;
34
+ logInfo(title: string, metadata?: any): void;
35
35
  /**
36
36
  * 记录警告日志
37
37
  */
38
- private logWarning;
38
+ logWarning(title: string, metadata?: any): void;
39
39
  /**
40
40
  * 记录错误日志
41
41
  */
42
- private logError;
42
+ logError(title: string, error?: any, metadata?: any): void;
43
43
  /**
44
44
  * 记录调试日志
45
45
  */
46
- private logDebug;
46
+ logDebug(title: string, metadata?: any): void;
47
47
  /**
48
48
  * 网络恢复以后,尝试执行队列
49
49
  *
@@ -1030,7 +1030,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1030
1030
  key: "addPaymentItemAsync",
1031
1031
  value: (function () {
1032
1032
  var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderUuid, paymentItem) {
1033
- var _newPaymentItem$metad, order, paymentUuid, newPaymentItem;
1033
+ var _newPaymentItem$metad, _newPaymentItem$metad2, _newPaymentItem$metad3, order, paymentUuid, newPaymentItem;
1034
1034
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1035
1035
  while (1) switch (_context13.prev = _context13.next) {
1036
1036
  case 0:
@@ -1066,9 +1066,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1066
1066
  // 新支付项默认为活跃状态
1067
1067
  order_payment_type: paymentItem.order_payment_type || 'normal',
1068
1068
  // 默认为正常支付
1069
- metadata: {
1069
+ metadata: _objectSpread(_objectSpread({}, paymentItem.metadata), {}, {
1070
+ // 保留传入的所有 metadata 字段
1070
1071
  unique_payment_number: paymentUuid // 设置唯一支付号为支付项的 uuid
1071
- }
1072
+ })
1072
1073
  };
1073
1074
  order.payment.push(newPaymentItem);
1074
1075
  this.recalculateOrderAmount(order);
@@ -1085,7 +1086,14 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1085
1086
  orderUuid: orderUuid,
1086
1087
  paymentUuid: newPaymentItem.uuid,
1087
1088
  uniquePaymentNumber: (_newPaymentItem$metad = newPaymentItem.metadata) === null || _newPaymentItem$metad === void 0 ? void 0 : _newPaymentItem$metad.unique_payment_number,
1088
- newExpectAmount: order.expect_amount
1089
+ newExpectAmount: order.expect_amount,
1090
+ paymentAmount: newPaymentItem.amount,
1091
+ paymentCode: newPaymentItem.code,
1092
+ orderPaymentType: newPaymentItem.order_payment_type,
1093
+ metadataFields: Object.keys(newPaymentItem.metadata || {}),
1094
+ // 现金支付找零信息
1095
+ actualPaidAmount: (_newPaymentItem$metad2 = newPaymentItem.metadata) === null || _newPaymentItem$metad2 === void 0 ? void 0 : _newPaymentItem$metad2.actual_paid_amount,
1096
+ changeGivenAmount: (_newPaymentItem$metad3 = newPaymentItem.metadata) === null || _newPaymentItem$metad3 === void 0 ? void 0 : _newPaymentItem$metad3.change_given_amount
1089
1097
  });
1090
1098
  _context13.next = 23;
1091
1099
  break;
@@ -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
  /**