@pisell/pisellos 0.0.229 → 0.0.231

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 (65) hide show
  1. package/dist/modules/Order/index.d.ts +13 -2
  2. package/dist/modules/Order/index.js +84 -1
  3. package/dist/modules/Order/types.d.ts +43 -0
  4. package/dist/modules/Order/types.js +8 -0
  5. package/dist/modules/Payment/cash.d.ts +8 -0
  6. package/dist/modules/Payment/cash.js +20 -1
  7. package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  8. package/dist/modules/Payment/cashRecommendationAlgorithm.js +423 -0
  9. package/dist/modules/Payment/eftpos.js +1 -1
  10. package/dist/modules/Payment/index.d.ts +57 -94
  11. package/dist/modules/Payment/index.js +810 -1109
  12. package/dist/modules/Payment/mx51.d.ts +0 -0
  13. package/dist/modules/Payment/mx51.js +0 -0
  14. package/dist/modules/Payment/types.d.ts +358 -50
  15. package/dist/modules/Payment/types.js +103 -4
  16. package/dist/modules/Payment/utils.d.ts +17 -0
  17. package/dist/modules/Payment/utils.js +62 -0
  18. package/dist/modules/Payment/walletpass.d.ts +96 -0
  19. package/dist/modules/Payment/walletpass.js +492 -0
  20. package/dist/modules/Schedule/index.d.ts +9 -0
  21. package/dist/modules/Schedule/index.js +60 -0
  22. package/dist/solution/BookingTicket/index.d.ts +1 -1
  23. package/dist/solution/Checkout/appointmentDemo.json +1 -0
  24. package/dist/solution/Checkout/index.d.ts +415 -0
  25. package/dist/solution/Checkout/index.js +3622 -0
  26. package/dist/solution/Checkout/types.d.ts +737 -0
  27. package/dist/solution/Checkout/types.js +137 -0
  28. package/dist/solution/Checkout/utils/index.d.ts +73 -0
  29. package/dist/{modules/Payment/wallet.js → solution/Checkout/utils/index.js} +363 -70
  30. package/dist/solution/index.d.ts +1 -0
  31. package/dist/solution/index.js +2 -1
  32. package/lib/modules/Order/index.d.ts +13 -2
  33. package/lib/modules/Order/index.js +58 -1
  34. package/lib/modules/Order/types.d.ts +43 -0
  35. package/lib/modules/Payment/cash.d.ts +8 -0
  36. package/lib/modules/Payment/cash.js +14 -1
  37. package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  38. package/lib/modules/Payment/cashRecommendationAlgorithm.js +342 -0
  39. package/lib/modules/Payment/eftpos.js +1 -1
  40. package/lib/modules/Payment/index.d.ts +57 -94
  41. package/lib/modules/Payment/index.js +363 -525
  42. package/lib/modules/Payment/mx51.d.ts +0 -0
  43. package/lib/modules/Payment/mx51.js +0 -0
  44. package/lib/modules/Payment/types.d.ts +358 -50
  45. package/lib/modules/Payment/types.js +37 -2
  46. package/lib/modules/Payment/utils.d.ts +17 -0
  47. package/lib/modules/Payment/utils.js +67 -0
  48. package/lib/modules/Payment/walletpass.d.ts +96 -0
  49. package/lib/modules/Payment/walletpass.js +304 -0
  50. package/lib/modules/Schedule/index.d.ts +9 -0
  51. package/lib/modules/Schedule/index.js +36 -0
  52. package/lib/solution/BookingTicket/index.d.ts +1 -1
  53. package/lib/solution/Checkout/appointmentDemo.json +1 -0
  54. package/lib/solution/Checkout/index.d.ts +415 -0
  55. package/lib/solution/Checkout/index.js +2107 -0
  56. package/lib/solution/Checkout/types.d.ts +737 -0
  57. package/lib/solution/Checkout/types.js +80 -0
  58. package/lib/solution/Checkout/utils/index.d.ts +73 -0
  59. package/lib/solution/Checkout/utils/index.js +266 -0
  60. package/lib/solution/index.d.ts +1 -0
  61. package/lib/solution/index.js +3 -1
  62. package/package.json +1 -1
  63. package/dist/modules/Payment/wallet.d.ts +0 -11
  64. package/lib/modules/Payment/wallet.d.ts +0 -11
  65. package/lib/modules/Payment/wallet.js +0 -51
@@ -0,0 +1,62 @@
1
+ // 获取walletPass可用最大金额
2
+ export var getAvailableMaxAmount = function getAvailableMaxAmount(data) {
3
+ return data.tag !== 'point_card' ? data.available_max_amount : data === null || data === void 0 ? void 0 : data.recommended_usage_amount;
4
+ };
5
+
6
+ /**
7
+ * 将walletPass列表数据转换为prepare_payments需要的数据格式
8
+ * @param list
9
+ */
10
+ export var formatWalletPassList2PreparePayments = function formatWalletPassList2PreparePayments(list) {
11
+ return (list || []).map(function (item) {
12
+ return {
13
+ voucher_id: item.id || 0,
14
+ amount: Number(getAvailableMaxAmount(item)) || 0,
15
+ tag: item.tag || ''
16
+ };
17
+ });
18
+ };
19
+
20
+ /**
21
+ * 对用户识别码列表进行排序
22
+ * 排序规则:正常数据 -> unified_available_status===1 -> 500601/500602 -> unified_available_status===0
23
+ * @param list 用户识别码列表
24
+ * @returns 排序后的列表
25
+ */
26
+ export var sortUserIdentificationCodeList = function sortUserIdentificationCodeList(list) {
27
+ if (!Array.isArray(list) || list.length === 0) {
28
+ return list;
29
+ }
30
+
31
+ // 定义中等优先级错误码
32
+ var middlePriorityErrorCodes = ['500601', '500602'];
33
+ return list.sort(function (a, b) {
34
+ // 确定每个项目的优先级
35
+ // 0: 正常数据(没有特定错误码且available_status不是1或0)
36
+ // 1: unified_available_status === 1
37
+ // 2: 中等优先级错误码(500601、500602) 此订单内不可用 订单没有剩余金额
38
+ // 3: unified_available_status === 0(最后)
39
+ var getPriority = function getPriority(item) {
40
+ var _item$unified_error_c;
41
+ var errorCode = (_item$unified_error_c = item.unified_error_code) === null || _item$unified_error_c === void 0 ? void 0 : _item$unified_error_c.toString();
42
+ var availableStatus = item.unified_available_status;
43
+
44
+ // 中等优先级错误码
45
+ if (errorCode && middlePriorityErrorCodes.includes(errorCode)) return 2;
46
+
47
+ // unified_available_status === 0 最后
48
+ if (availableStatus === 0) return 3;
49
+
50
+ // unified_available_status === 1
51
+ if (availableStatus === 1) return 1;
52
+
53
+ // 正常数据
54
+ return 0;
55
+ };
56
+ var aPriority = getPriority(a);
57
+ var bPriority = getPriority(b);
58
+
59
+ // 按优先级排序,优先级相同则保持原有顺序
60
+ return aPriority - bPriority;
61
+ });
62
+ };
@@ -0,0 +1,96 @@
1
+ import { WalletPassPayment, WalletDeductionRecommendParams, WalletRecommendItem, UserIdentificationCodeParams, UserIdentificationCodeItem, SearchIdentificationCodeParams, SearchIdentificationCodeItem, WalletInitBusinessData } from './types';
2
+ import type { PaymentModule } from './index';
3
+ /**
4
+ * 钱包支付实现
5
+ */
6
+ export declare class WalletPassPaymentImpl implements WalletPassPayment {
7
+ private paymentModule;
8
+ private walletRecommendList;
9
+ private userIdentificationCodes;
10
+ private searchResults;
11
+ private walletParams;
12
+ constructor(paymentModule: PaymentModule);
13
+ /**
14
+ * 发送事件的辅助方法
15
+ * 支持使用WalletPassHooks或PaymentHooks
16
+ */
17
+ private emitEvent;
18
+ /**
19
+ * 生成钱包API默认参数
20
+ * 根据业务数据生成标准的钱包API参数,并存储在模块中
21
+ */
22
+ generateWalletParams(businessData: WalletInitBusinessData): WalletDeductionRecommendParams;
23
+ /**
24
+ * 获取已存储的钱包参数
25
+ * 返回之前生成并存储的钱包参数
26
+ */
27
+ getStoredWalletParams(): WalletDeductionRecommendParams | null;
28
+ /**
29
+ * 清理已存储的钱包参数
30
+ * 清除之前存储的钱包参数
31
+ */
32
+ clearStoredWalletParams(): void;
33
+ /**
34
+ * 从业务数据初始化钱包数据
35
+ * 内部生成参数,然后调用标准的初始化流程
36
+ */
37
+ initializeWalletDataFromBusinessAsync(businessData: WalletInitBusinessData): Promise<{
38
+ walletRecommendList: WalletRecommendItem[];
39
+ userIdentificationCodes: UserIdentificationCodeItem[];
40
+ }>;
41
+ /**
42
+ * 初始化钱包数据
43
+ * 先获取推荐列表,再获取用户识别码列表(顺序执行)
44
+ */
45
+ initializeWalletDataAsync(baseParams: WalletDeductionRecommendParams): Promise<{
46
+ walletRecommendList: WalletRecommendItem[];
47
+ userIdentificationCodes: UserIdentificationCodeItem[];
48
+ }>;
49
+ getWalletPassRecommendListAsync(params: WalletDeductionRecommendParams): Promise<WalletRecommendItem[]>;
50
+ formatWalletPassList2PreparePayments(list: WalletRecommendItem[]): {
51
+ voucher_id: number;
52
+ amount: number;
53
+ tag: string;
54
+ }[];
55
+ getUserIdentificationCodeListAsync(params: UserIdentificationCodeParams): Promise<UserIdentificationCodeItem[]>;
56
+ /**
57
+ * 搜索识别码信息
58
+ * 通过识别码搜索相关的钱包通行证信息
59
+ * 基于 WalletDeductionRecommendParams 参数结构
60
+ */
61
+ searchIdentificationCodeAsync(params: SearchIdentificationCodeParams): Promise<SearchIdentificationCodeItem[]>;
62
+ processWalletPayment(amount: number, orderUuid: string, voucherId?: string): Promise<void>;
63
+ getWalletBalance(voucherId: string): Promise<number>;
64
+ /**
65
+ * 获取缓存的钱包推荐列表
66
+ */
67
+ getWalletRecommendList(): WalletRecommendItem[];
68
+ /**
69
+ * 获取缓存的用户识别码列表
70
+ */
71
+ getUserIdentificationCodes(): UserIdentificationCodeItem[];
72
+ /**
73
+ * 清除钱包推荐列表
74
+ */
75
+ clearWalletRecommendList(): void;
76
+ /**
77
+ * 清除用户识别码列表
78
+ */
79
+ clearUserIdentificationCodes(): void;
80
+ /**
81
+ * 获取缓存的搜索结果列表
82
+ */
83
+ getSearchResults(): SearchIdentificationCodeItem[];
84
+ /**
85
+ * 根据识别码查找搜索结果
86
+ */
87
+ findSearchResultByCode(code: string): SearchIdentificationCodeItem | undefined;
88
+ /**
89
+ * 清除搜索结果缓存
90
+ */
91
+ clearSearchResults(): void;
92
+ /**
93
+ * 清除所有缓存数据
94
+ */
95
+ clearAllCache(): void;
96
+ }
@@ -0,0 +1,492 @@
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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
+ 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
+ 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); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ 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; }
9
+ 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; }
10
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
11
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
12
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
13
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
15
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
+ 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; }
17
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
18
+ 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); }
19
+ import { WalletPassHooks } from "./types";
20
+ import { formatWalletPassList2PreparePayments as formatWalletPassList2PreparePaymentsUtils, sortUserIdentificationCodeList } from "./utils";
21
+
22
+ /**
23
+ * 钱包支付实现
24
+ */
25
+ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
26
+ function WalletPassPaymentImpl(paymentModule) {
27
+ _classCallCheck(this, WalletPassPaymentImpl);
28
+ _defineProperty(this, "walletRecommendList", []);
29
+ _defineProperty(this, "userIdentificationCodes", []);
30
+ _defineProperty(this, "searchResults", []);
31
+ _defineProperty(this, "walletParams", null);
32
+ this.paymentModule = paymentModule;
33
+ }
34
+
35
+ /**
36
+ * 发送事件的辅助方法
37
+ * 支持使用WalletPassHooks或PaymentHooks
38
+ */
39
+ _createClass(WalletPassPaymentImpl, [{
40
+ key: "emitEvent",
41
+ value: function emitEvent(hook, data) {
42
+ try {
43
+ this.paymentModule.core.effects.emit(hook, data);
44
+ } catch (error) {
45
+ console.error('[WalletPass] 发送事件失败:', hook, error);
46
+ }
47
+ }
48
+
49
+ /**
50
+ * 生成钱包API默认参数
51
+ * 根据业务数据生成标准的钱包API参数,并存储在模块中
52
+ */
53
+ }, {
54
+ key: "generateWalletParams",
55
+ value: function generateWalletParams(businessData) {
56
+ var customer_id = businessData.customer_id,
57
+ amountInfo = businessData.amountInfo,
58
+ products = businessData.products;
59
+
60
+ // 转换金额为数字类型
61
+ var totalAmount = Number(amountInfo.subTotal) || Number(amountInfo.totalAmount);
62
+ var walletParams = {
63
+ sale_channel: 'kiosk',
64
+ customer_id: 9752 || customer_id,
65
+ order_expect_amount: totalAmount,
66
+ order_product_amount: totalAmount,
67
+ order_wait_pay_amount: totalAmount,
68
+ order_behavior_count_customer_id: 1,
69
+ products: products,
70
+ prepare_payments: []
71
+ };
72
+
73
+ // 存储生成的参数到模块中
74
+ this.walletParams = walletParams;
75
+ console.log('[WalletPass] 钱包默认参数已生成并存储:', walletParams);
76
+ return walletParams;
77
+ }
78
+
79
+ /**
80
+ * 获取已存储的钱包参数
81
+ * 返回之前生成并存储的钱包参数
82
+ */
83
+ }, {
84
+ key: "getStoredWalletParams",
85
+ value: function getStoredWalletParams() {
86
+ return this.walletParams;
87
+ }
88
+
89
+ /**
90
+ * 清理已存储的钱包参数
91
+ * 清除之前存储的钱包参数
92
+ */
93
+ }, {
94
+ key: "clearStoredWalletParams",
95
+ value: function clearStoredWalletParams() {
96
+ this.walletParams = null;
97
+ console.log('[WalletPass] 已存储的钱包参数已清理');
98
+ }
99
+
100
+ /**
101
+ * 从业务数据初始化钱包数据
102
+ * 内部生成参数,然后调用标准的初始化流程
103
+ */
104
+ }, {
105
+ key: "initializeWalletDataFromBusinessAsync",
106
+ value: (function () {
107
+ var _initializeWalletDataFromBusinessAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(businessData) {
108
+ var walletParams;
109
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
110
+ while (1) switch (_context.prev = _context.next) {
111
+ case 0:
112
+ _context.prev = 0;
113
+ // 生成钱包API参数
114
+ walletParams = this.generateWalletParams(businessData); // 调用标准的初始化流程
115
+ _context.next = 4;
116
+ return this.initializeWalletDataAsync(walletParams);
117
+ case 4:
118
+ return _context.abrupt("return", _context.sent);
119
+ case 7:
120
+ _context.prev = 7;
121
+ _context.t0 = _context["catch"](0);
122
+ console.error('[WalletPass] 从业务数据初始化钱包数据失败:', _context.t0);
123
+ throw _context.t0;
124
+ case 11:
125
+ case "end":
126
+ return _context.stop();
127
+ }
128
+ }, _callee, this, [[0, 7]]);
129
+ }));
130
+ function initializeWalletDataFromBusinessAsync(_x) {
131
+ return _initializeWalletDataFromBusinessAsync.apply(this, arguments);
132
+ }
133
+ return initializeWalletDataFromBusinessAsync;
134
+ }()
135
+ /**
136
+ * 初始化钱包数据
137
+ * 先获取推荐列表,再获取用户识别码列表(顺序执行)
138
+ */
139
+ )
140
+ }, {
141
+ key: "initializeWalletDataAsync",
142
+ value: (function () {
143
+ var _initializeWalletDataAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(baseParams) {
144
+ var walletRecommendList, identificationParams, userIdentificationCodes;
145
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
146
+ while (1) switch (_context2.prev = _context2.next) {
147
+ case 0:
148
+ _context2.prev = 0;
149
+ _context2.next = 3;
150
+ return this.getWalletPassRecommendListAsync(baseParams);
151
+ case 3:
152
+ walletRecommendList = _context2.sent;
153
+ // 格式化用户识别码列表参数
154
+ identificationParams = _objectSpread(_objectSpread({}, baseParams), {}, {
155
+ available: 2,
156
+ prepare_payments: this.formatWalletPassList2PreparePayments(walletRecommendList),
157
+ other_exact_codes: [],
158
+ filter_prepare_wallet_pass: 1
159
+ }); // 再获取用户识别码列表
160
+ _context2.next = 7;
161
+ return this.getUserIdentificationCodeListAsync(identificationParams);
162
+ case 7:
163
+ userIdentificationCodes = _context2.sent;
164
+ return _context2.abrupt("return", {
165
+ walletRecommendList: walletRecommendList,
166
+ userIdentificationCodes: userIdentificationCodes
167
+ });
168
+ case 11:
169
+ _context2.prev = 11;
170
+ _context2.t0 = _context2["catch"](0);
171
+ console.error('[WalletPass] 初始化钱包数据失败:', _context2.t0);
172
+ throw _context2.t0;
173
+ case 15:
174
+ case "end":
175
+ return _context2.stop();
176
+ }
177
+ }, _callee2, this, [[0, 11]]);
178
+ }));
179
+ function initializeWalletDataAsync(_x2) {
180
+ return _initializeWalletDataAsync.apply(this, arguments);
181
+ }
182
+ return initializeWalletDataAsync;
183
+ }())
184
+ }, {
185
+ key: "getWalletPassRecommendListAsync",
186
+ value: function () {
187
+ var _getWalletPassRecommendListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
188
+ var response;
189
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
190
+ while (1) switch (_context3.prev = _context3.next) {
191
+ case 0:
192
+ _context3.prev = 0;
193
+ _context3.next = 3;
194
+ return this.paymentModule.request.post('/machinecode/prepare/deduction/recommend', params // 将 params 作为请求体数据
195
+ );
196
+ case 3:
197
+ response = _context3.sent;
198
+ this.walletRecommendList = (response === null || response === void 0 ? void 0 : response.data) || [];
199
+
200
+ // 发送钱包推荐列表更新事件(使用专用的WalletPassHooks)
201
+ this.emitEvent(WalletPassHooks.OnWalletRecommendListUpdated, {
202
+ walletRecommendList: this.walletRecommendList
203
+ });
204
+ console.log('[WalletPass] 钱包推荐列表已更新:', this.walletRecommendList.length, '项');
205
+ return _context3.abrupt("return", this.walletRecommendList);
206
+ case 10:
207
+ _context3.prev = 10;
208
+ _context3.t0 = _context3["catch"](0);
209
+ console.error('获取钱包推荐列表失败:', _context3.t0);
210
+ throw _context3.t0;
211
+ case 14:
212
+ case "end":
213
+ return _context3.stop();
214
+ }
215
+ }, _callee3, this, [[0, 10]]);
216
+ }));
217
+ function getWalletPassRecommendListAsync(_x3) {
218
+ return _getWalletPassRecommendListAsync.apply(this, arguments);
219
+ }
220
+ return getWalletPassRecommendListAsync;
221
+ }()
222
+ }, {
223
+ key: "formatWalletPassList2PreparePayments",
224
+ value: function formatWalletPassList2PreparePayments(list) {
225
+ return formatWalletPassList2PreparePaymentsUtils(list);
226
+ }
227
+ }, {
228
+ key: "getUserIdentificationCodeListAsync",
229
+ value: function () {
230
+ var _getUserIdentificationCodeListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
231
+ var newParams, response, sortedData;
232
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
233
+ while (1) switch (_context4.prev = _context4.next) {
234
+ case 0:
235
+ _context4.prev = 0;
236
+ newParams = _objectSpread(_objectSpread({}, this.walletParams), params);
237
+ _context4.next = 4;
238
+ return this.paymentModule.request.post('/machinecode/prepare/deduction', newParams);
239
+ case 4:
240
+ response = _context4.sent;
241
+ // 对获取到的数据进行排序,将错误码为 500100、500200、500300 的项目排到最后
242
+ sortedData = sortUserIdentificationCodeList((response === null || response === void 0 ? void 0 : response.data) || []);
243
+ this.userIdentificationCodes = sortedData;
244
+
245
+ // 发送用户识别码列表更新事件(使用专用的WalletPassHooks)
246
+ this.emitEvent(WalletPassHooks.OnUserIdentificationCodesUpdated, {
247
+ userIdentificationCodes: this.userIdentificationCodes
248
+ });
249
+ console.log('[WalletPass] 用户识别码列表已更新:', this.userIdentificationCodes.length, '项');
250
+ return _context4.abrupt("return", this.userIdentificationCodes);
251
+ case 12:
252
+ _context4.prev = 12;
253
+ _context4.t0 = _context4["catch"](0);
254
+ console.error('获取用户识别码列表失败:', _context4.t0);
255
+ throw _context4.t0;
256
+ case 16:
257
+ case "end":
258
+ return _context4.stop();
259
+ }
260
+ }, _callee4, this, [[0, 12]]);
261
+ }));
262
+ function getUserIdentificationCodeListAsync(_x4) {
263
+ return _getUserIdentificationCodeListAsync.apply(this, arguments);
264
+ }
265
+ return getUserIdentificationCodeListAsync;
266
+ }()
267
+ /**
268
+ * 搜索识别码信息
269
+ * 通过识别码搜索相关的钱包通行证信息
270
+ * 基于 WalletDeductionRecommendParams 参数结构
271
+ */
272
+ }, {
273
+ key: "searchIdentificationCodeAsync",
274
+ value: (function () {
275
+ var _searchIdentificationCodeAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
276
+ var baseWalletParams, searchParams, response, searchResults, _this$searchResults, existingCodes, newResults;
277
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
278
+ while (1) switch (_context5.prev = _context5.next) {
279
+ case 0:
280
+ _context5.prev = 0;
281
+ // 合并钱包参数和搜索参数
282
+ baseWalletParams = this.walletParams; // 构建完整的搜索参数,包含钱包扣款推荐的所有参数
283
+ searchParams = {
284
+ // 基础钱包参数
285
+ sale_channel: params.sale_channel || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.sale_channel),
286
+ customer_id: params.customer_id || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.customer_id),
287
+ order_expect_amount: params.order_expect_amount || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.order_expect_amount),
288
+ order_product_amount: params.order_product_amount || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.order_product_amount),
289
+ order_wait_pay_amount: params.order_wait_pay_amount || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.order_wait_pay_amount),
290
+ order_behavior_count_customer_id: params.order_behavior_count_customer_id || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.order_behavior_count_customer_id),
291
+ products: params.products || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.products),
292
+ prepare_payments: params.prepare_payments || (baseWalletParams === null || baseWalletParams === void 0 ? void 0 : baseWalletParams.prepare_payments),
293
+ multiple: 1,
294
+ // 搜索特有参数
295
+ code: params.code
296
+ };
297
+ _context5.next = 5;
298
+ return this.paymentModule.request.post('/machinecode/prepare/deduction/search', searchParams);
299
+ case 5:
300
+ response = _context5.sent;
301
+ searchResults = (response === null || response === void 0 ? void 0 : response.data) || []; // 将搜索结果存储到缓存数组中
302
+ if (searchResults.length > 0) {
303
+ // 避免重复存储相同的识别码
304
+ existingCodes = new Set(this.searchResults.map(function (item) {
305
+ return item.code;
306
+ }));
307
+ newResults = searchResults.filter(function (item) {
308
+ return !existingCodes.has(item.code);
309
+ });
310
+ (_this$searchResults = this.searchResults).push.apply(_this$searchResults, _toConsumableArray(newResults));
311
+ }
312
+
313
+ // 通过事件暴露当前搜索结果和缓存结果
314
+ this.emitEvent(WalletPassHooks.OnSearchIdentificationCodeCompleted, {
315
+ searchCode: params.code,
316
+ currentSearchResults: searchResults,
317
+ cachedSearchResults: _toConsumableArray(this.searchResults),
318
+ searchParams: params
319
+ });
320
+ return _context5.abrupt("return", searchResults);
321
+ case 12:
322
+ _context5.prev = 12;
323
+ _context5.t0 = _context5["catch"](0);
324
+ console.error('[WalletPass] 搜索识别码信息失败:', _context5.t0);
325
+ throw _context5.t0;
326
+ case 16:
327
+ case "end":
328
+ return _context5.stop();
329
+ }
330
+ }, _callee5, this, [[0, 12]]);
331
+ }));
332
+ function searchIdentificationCodeAsync(_x5) {
333
+ return _searchIdentificationCodeAsync.apply(this, arguments);
334
+ }
335
+ return searchIdentificationCodeAsync;
336
+ }())
337
+ }, {
338
+ key: "processWalletPayment",
339
+ value: function () {
340
+ var _processWalletPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(amount, orderUuid, voucherId) {
341
+ var walletMethod, paymentItem;
342
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
343
+ while (1) switch (_context6.prev = _context6.next) {
344
+ case 0:
345
+ _context6.next = 2;
346
+ return this.paymentModule.getWalletPaymentMethod();
347
+ case 2:
348
+ walletMethod = _context6.sent;
349
+ if (walletMethod) {
350
+ _context6.next = 5;
351
+ break;
352
+ }
353
+ throw new Error('钱包支付方式未找到');
354
+ case 5:
355
+ paymentItem = {
356
+ amount: amount.toString(),
357
+ code: walletMethod.code,
358
+ id: walletMethod.id,
359
+ name: walletMethod.name,
360
+ type: walletMethod.type,
361
+ voucher_id: voucherId || ''
362
+ };
363
+ _context6.next = 8;
364
+ return this.paymentModule.addPaymentItemAsync(orderUuid, paymentItem);
365
+ case 8:
366
+ case "end":
367
+ return _context6.stop();
368
+ }
369
+ }, _callee6, this);
370
+ }));
371
+ function processWalletPayment(_x6, _x7, _x8) {
372
+ return _processWalletPayment.apply(this, arguments);
373
+ }
374
+ return processWalletPayment;
375
+ }()
376
+ }, {
377
+ key: "getWalletBalance",
378
+ value: function () {
379
+ var _getWalletBalance = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(voucherId) {
380
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
381
+ while (1) switch (_context7.prev = _context7.next) {
382
+ case 0:
383
+ return _context7.abrupt("return", 0);
384
+ case 1:
385
+ case "end":
386
+ return _context7.stop();
387
+ }
388
+ }, _callee7);
389
+ }));
390
+ function getWalletBalance(_x9) {
391
+ return _getWalletBalance.apply(this, arguments);
392
+ }
393
+ return getWalletBalance;
394
+ }()
395
+ /**
396
+ * 获取缓存的钱包推荐列表
397
+ */
398
+ }, {
399
+ key: "getWalletRecommendList",
400
+ value: function getWalletRecommendList() {
401
+ return this.walletRecommendList;
402
+ }
403
+
404
+ /**
405
+ * 获取缓存的用户识别码列表
406
+ */
407
+ }, {
408
+ key: "getUserIdentificationCodes",
409
+ value: function getUserIdentificationCodes() {
410
+ return this.userIdentificationCodes;
411
+ }
412
+
413
+ /**
414
+ * 清除钱包推荐列表
415
+ */
416
+ }, {
417
+ key: "clearWalletRecommendList",
418
+ value: function clearWalletRecommendList() {
419
+ this.walletRecommendList = [];
420
+
421
+ // 发送钱包推荐列表清除事件
422
+ this.emitEvent(WalletPassHooks.OnWalletRecommendListCleared, {
423
+ clearedTypes: ['walletRecommendList']
424
+ });
425
+ console.log('[WalletPass] 钱包推荐列表已清除');
426
+ }
427
+
428
+ /**
429
+ * 清除用户识别码列表
430
+ */
431
+ }, {
432
+ key: "clearUserIdentificationCodes",
433
+ value: function clearUserIdentificationCodes() {
434
+ this.userIdentificationCodes = [];
435
+
436
+ // 发送用户识别码列表清除事件
437
+ this.emitEvent(WalletPassHooks.OnUserIdentificationCodesCleared, {
438
+ clearedTypes: ['userIdentificationCodes']
439
+ });
440
+ console.log('[WalletPass] 用户识别码列表已清除');
441
+ }
442
+
443
+ /**
444
+ * 获取缓存的搜索结果列表
445
+ */
446
+ }, {
447
+ key: "getSearchResults",
448
+ value: function getSearchResults() {
449
+ return this.searchResults;
450
+ }
451
+
452
+ /**
453
+ * 根据识别码查找搜索结果
454
+ */
455
+ }, {
456
+ key: "findSearchResultByCode",
457
+ value: function findSearchResultByCode(code) {
458
+ return this.searchResults.find(function (item) {
459
+ return item.code === code;
460
+ });
461
+ }
462
+
463
+ /**
464
+ * 清除搜索结果缓存
465
+ */
466
+ }, {
467
+ key: "clearSearchResults",
468
+ value: function clearSearchResults() {
469
+ this.searchResults = [];
470
+ console.log('[WalletPass] 搜索结果缓存已清除');
471
+ }
472
+
473
+ /**
474
+ * 清除所有缓存数据
475
+ */
476
+ }, {
477
+ key: "clearAllCache",
478
+ value: function clearAllCache() {
479
+ this.walletRecommendList = [];
480
+ this.userIdentificationCodes = [];
481
+ this.searchResults = [];
482
+ this.walletParams = null;
483
+
484
+ // 发送所有缓存清除事件
485
+ this.emitEvent(WalletPassHooks.OnWalletCacheCleared, {
486
+ clearedTypes: ['all']
487
+ });
488
+ console.log('[WalletPass] 所有缓存数据已清除(包括钱包参数和搜索结果)');
489
+ }
490
+ }]);
491
+ return WalletPassPaymentImpl;
492
+ }();