@pisell/pisellos 2.1.174 → 2.1.176
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/dist/model/strategy/adapter/walletPass/evaluator.js +2 -4
- package/dist/modules/Discount/index.d.ts +3 -6
- package/dist/modules/Discount/index.js +23 -125
- package/dist/modules/Discount/types.d.ts +5 -34
- package/dist/modules/OpenData/types.d.ts +1 -0
- package/dist/modules/ProductList/index.js +13 -6
- package/dist/modules/Rules/index.d.ts +2 -12
- package/dist/modules/Rules/index.js +113 -377
- package/dist/modules/Rules/types.d.ts +2 -2
- package/dist/plugins/window.d.ts +0 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/ScanOrder/index.d.ts +7 -5
- package/dist/solution/ScanOrder/index.js +123 -31
- package/dist/solution/ScanOrder/resourceSchedule.d.ts +12 -0
- package/dist/solution/ScanOrder/resourceSchedule.js +300 -0
- package/dist/solution/ScanOrder/types.d.ts +9 -1
- package/dist/solution/ShopDiscount/index.d.ts +0 -3
- package/dist/solution/ShopDiscount/index.js +78 -161
- package/dist/solution/ShopDiscount/utils.d.ts +0 -1
- package/dist/solution/ShopDiscount/utils.js +1 -40
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
- package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -4
- package/lib/modules/Discount/index.d.ts +3 -6
- package/lib/modules/Discount/index.js +16 -66
- package/lib/modules/Discount/types.d.ts +5 -34
- package/lib/modules/OpenData/types.d.ts +1 -0
- package/lib/modules/ProductList/index.js +8 -1
- package/lib/modules/Rules/index.d.ts +2 -12
- package/lib/modules/Rules/index.js +69 -303
- package/lib/modules/Rules/types.d.ts +2 -2
- package/lib/plugins/window.d.ts +0 -2
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/ScanOrder/index.d.ts +7 -5
- package/lib/solution/ScanOrder/index.js +90 -12
- package/lib/solution/ScanOrder/resourceSchedule.d.ts +12 -0
- package/lib/solution/ScanOrder/resourceSchedule.js +272 -0
- package/lib/solution/ScanOrder/types.d.ts +9 -1
- package/lib/solution/ShopDiscount/index.d.ts +0 -3
- package/lib/solution/ShopDiscount/index.js +28 -78
- package/lib/solution/ShopDiscount/utils.d.ts +0 -1
- package/lib/solution/ShopDiscount/utils.js +1 -42
- package/package.json +1 -1
- package/dist/modules/Discount/availability.d.ts +0 -7
- package/dist/modules/Discount/availability.js +0 -52
- package/dist/modules/Discount/entitlementPass.d.ts +0 -34
- package/dist/modules/Discount/entitlementPass.js +0 -147
- package/dist/modules/Discount/entitlementState.d.ts +0 -8
- package/dist/modules/Discount/entitlementState.js +0 -205
- package/dist/modules/Rules/entitlementLines.d.ts +0 -8
- package/dist/modules/Rules/entitlementLines.js +0 -157
- package/lib/modules/Discount/availability.d.ts +0 -7
- package/lib/modules/Discount/availability.js +0 -91
- package/lib/modules/Discount/entitlementPass.d.ts +0 -34
- package/lib/modules/Discount/entitlementPass.js +0 -184
- package/lib/modules/Discount/entitlementState.d.ts +0 -8
- package/lib/modules/Discount/entitlementState.js +0 -206
- package/lib/modules/Rules/entitlementLines.d.ts +0 -8
- package/lib/modules/Rules/entitlementLines.js +0 -158
|
@@ -1,3 +1,4 @@
|
|
|
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); }
|
|
1
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; }
|
|
2
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; }
|
|
3
4
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
@@ -7,7 +8,6 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
7
8
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
9
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
9
10
|
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; }
|
|
10
|
-
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); }
|
|
11
11
|
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; }
|
|
12
12
|
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); } }
|
|
13
13
|
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); }); }; }
|
|
@@ -31,13 +31,6 @@ import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils"
|
|
|
31
31
|
import Decimal from 'decimal.js';
|
|
32
32
|
import { isBoolean } from 'lodash-es';
|
|
33
33
|
import dayjs from 'dayjs';
|
|
34
|
-
import { WalletPassEvaluator } from "../../model/strategy/adapter/walletPass/evaluator";
|
|
35
|
-
import { compareEntitlementPassPriority, getRemainingEntitlementUses, isEntitlementPass, isFullCoveragePass, resolveEntitlementQuota } from "../Discount/entitlementPass";
|
|
36
|
-
import { getDiscountUsageBlockReason, getDiscountUsageLimitFailKey } from "../Discount/availability";
|
|
37
|
-
import { withCommittedEntitlementDetails, isPersistedEntitlementLine } from "../Discount/entitlementState";
|
|
38
|
-
import { getDiscountTimeUnavailableReason } from "../../solution/ShopDiscount/utils";
|
|
39
|
-
import { cloneDeep } from 'lodash-es';
|
|
40
|
-
import { prepareEntitlementLines, finalizeEntitlementLines, isEntitlementRuntimeLine, rebuildEntitlementLine } from "./entitlementLines";
|
|
41
34
|
|
|
42
35
|
// 临时变量
|
|
43
36
|
var flatItem;
|
|
@@ -52,23 +45,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
52
45
|
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
53
46
|
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
54
47
|
_defineProperty(_assertThisInitialized(_this), "hooks", void 0);
|
|
55
|
-
_defineProperty(_assertThisInitialized(_this), "entitlementPassEnabled", false);
|
|
56
|
-
_defineProperty(_assertThisInitialized(_this), "defaultWalletPassEvaluator", void 0);
|
|
57
48
|
_this.hooks = {};
|
|
58
49
|
return _this;
|
|
59
50
|
}
|
|
60
51
|
_createClass(RulesModule, [{
|
|
61
|
-
key: "setEntitlementPassEnabled",
|
|
62
|
-
value: function setEntitlementPassEnabled(enabled) {
|
|
63
|
-
this.entitlementPassEnabled = enabled;
|
|
64
|
-
}
|
|
65
|
-
}, {
|
|
66
|
-
key: "getWalletPassEvaluator",
|
|
67
|
-
value: function getWalletPassEvaluator() {
|
|
68
|
-
var _this$core, _this$core$getWalletP, _this$defaultWalletPa;
|
|
69
|
-
return ((_this$core = this.core) === null || _this$core === void 0 || (_this$core = _this$core.getPlugin('window')) === null || _this$core === void 0 || (_this$core$getWalletP = _this$core.getWalletPassEvaluator) === null || _this$core$getWalletP === void 0 ? void 0 : _this$core$getWalletP.call(_this$core)) || ((_this$defaultWalletPa = this.defaultWalletPassEvaluator) !== null && _this$defaultWalletPa !== void 0 ? _this$defaultWalletPa : this.defaultWalletPassEvaluator = new WalletPassEvaluator());
|
|
70
|
-
}
|
|
71
|
-
}, {
|
|
72
52
|
key: "initialize",
|
|
73
53
|
value: function () {
|
|
74
54
|
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
|
|
@@ -115,69 +95,35 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
115
95
|
value: function getRulesList() {
|
|
116
96
|
return this.store.rulesList;
|
|
117
97
|
}
|
|
118
|
-
}, {
|
|
119
|
-
key: "normalizeHolderRecordIds",
|
|
120
|
-
value: function normalizeHolderRecordIds(value) {
|
|
121
|
-
var records = Array.isArray(value) ? value : [value];
|
|
122
|
-
return Array.from(new Set(records.map(function (record) {
|
|
123
|
-
if (record && _typeof(record) === 'object') {
|
|
124
|
-
return record.form_record_id;
|
|
125
|
-
}
|
|
126
|
-
return record;
|
|
127
|
-
}).filter(function (record) {
|
|
128
|
-
return record !== undefined && record !== null && record !== '' && record !== 0 && record !== '0';
|
|
129
|
-
}).map(String)));
|
|
130
|
-
}
|
|
131
98
|
|
|
132
|
-
|
|
133
|
-
* 商品未开启 Holder 选择时跳过匹配;已开启时,特定 form Holder 卡
|
|
134
|
-
* 只适用于同一 Holder Record,是否必填不影响匹配规则。
|
|
135
|
-
*/
|
|
99
|
+
// 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
|
|
136
100
|
}, {
|
|
137
101
|
key: "checkHolderMatch",
|
|
138
|
-
value: function checkHolderMatch(discount, product,
|
|
139
|
-
var _discount$holder
|
|
102
|
+
value: function checkHolderMatch(discount, product, holders) {
|
|
103
|
+
var _discount$holder;
|
|
140
104
|
// 非表单类型 holder 视为匹配
|
|
141
105
|
if (((_discount$holder = discount.holder) === null || _discount$holder === void 0 ? void 0 : _discount$holder.holder_type) !== 'form') return true;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// getProduct 会裁剪商品字段,从原始商品读取配置,套餐子项沿用父商品。
|
|
154
|
-
var holderConfig = (_ref = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_ref6 = (_ref7 = (_ref8 = (_ref9 = (_ref10 = (_holderSource$holder_ = holderSource === null || holderSource === void 0 ? void 0 : holderSource.holder_config) !== null && _holderSource$holder_ !== void 0 ? _holderSource$holder_ : holderSource === null || holderSource === void 0 || (_holderSource$metadat = holderSource.metadata) === null || _holderSource$metadat === void 0 ? void 0 : _holderSource$metadat.holder_config) !== null && _ref10 !== void 0 ? _ref10 : holderSource === null || holderSource === void 0 || (_holderSource$origin = holderSource.origin) === null || _holderSource$origin === void 0 ? void 0 : _holderSource$origin.holder_config) !== null && _ref9 !== void 0 ? _ref9 : holderSource === null || holderSource === void 0 || (_holderSource$metadat2 = holderSource.metadata) === null || _holderSource$metadat2 === void 0 || (_holderSource$metadat2 = _holderSource$metadat2.origin) === null || _holderSource$metadat2 === void 0 ? void 0 : _holderSource$metadat2.holder_config) !== null && _ref8 !== void 0 ? _ref8 : holderSource === null || holderSource === void 0 || (_holderSource$_origin = holderSource._origin) === null || _holderSource$_origin === void 0 ? void 0 : _holderSource$_origin.holder_config) !== null && _ref7 !== void 0 ? _ref7 : holderSource === null || holderSource === void 0 || (_holderSource$_origin2 = holderSource._origin) === null || _holderSource$_origin2 === void 0 || (_holderSource$_origin2 = _holderSource$_origin2.product) === null || _holderSource$_origin2 === void 0 ? void 0 : _holderSource$_origin2.holder_config) !== null && _ref6 !== void 0 ? _ref6 : holderSource === null || holderSource === void 0 || (_holderSource$_origin3 = holderSource._originData) === null || _holderSource$_origin3 === void 0 || (_holderSource$_origin3 = _holderSource$_origin3.product) === null || _holderSource$_origin3 === void 0 ? void 0 : _holderSource$_origin3.holder_config) !== null && _ref5 !== void 0 ? _ref5 : holderSource === null || holderSource === void 0 || (_holderSource$_produc = holderSource._productInit) === null || _holderSource$_produc === void 0 ? void 0 : _holderSource$_produc.holder_config) !== null && _ref4 !== void 0 ? _ref4 : holderSource === null || holderSource === void 0 || (_holderSource$_produc2 = holderSource._productOrigin) === null || _holderSource$_produc2 === void 0 ? void 0 : _holderSource$_produc2.holder_config) !== null && _ref3 !== void 0 ? _ref3 : holderSource === null || holderSource === void 0 || (_holderSource$_extend = holderSource._extend) === null || _holderSource$_extend === void 0 ? void 0 : _holderSource$_extend.holder_config) !== null && _ref2 !== void 0 ? _ref2 : holderSource === null || holderSource === void 0 || (_holderSource$_extend2 = holderSource._extend) === null || _holderSource$_extend2 === void 0 || (_holderSource$_extend2 = _holderSource$_extend2.product) === null || _holderSource$_extend2 === void 0 ? void 0 : _holderSource$_extend2.holder_config) !== null && _ref !== void 0 ? _ref : holderSource === null || holderSource === void 0 || (_holderSource$_extend3 = holderSource._extend) === null || _holderSource$_extend3 === void 0 || (_holderSource$_extend3 = _holderSource$_extend3.product) === null || _holderSource$_extend3 === void 0 || (_holderSource$_extend3 = _holderSource$_extend3.metadata) === null || _holderSource$_extend3 === void 0 ? void 0 : _holderSource$_extend3.holder_config;
|
|
155
|
-
var holderStatus = holderConfig === null || holderConfig === void 0 ? void 0 : holderConfig.status;
|
|
156
|
-
var holderEnabled = holderStatus == null || holderStatus === '' || holderStatus === true || ['enable', '1'].includes(String(holderStatus).trim().toLowerCase());
|
|
157
|
-
if (!holderEnabled || !(holderConfig !== null && holderConfig !== void 0 && holderConfig.resource_id)) {
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
var discountHolderIds = this.normalizeHolderRecordIds(discount.holder.holder_id);
|
|
161
|
-
if (!discountHolderIds.length) return false;
|
|
162
|
-
var productHolderIds = this.normalizeHolderRecordIds(product.holder_id);
|
|
163
|
-
var candidateHolderIds = productHolderIds.length || Array.isArray(product.holder_id) ? productHolderIds : this.normalizeHolderRecordIds(holders);
|
|
164
|
-
if (!candidateHolderIds.length) return false;
|
|
165
|
-
var discountHolderIdSet = new Set(discountHolderIds);
|
|
166
|
-
return candidateHolderIds.every(function (holderId) {
|
|
167
|
-
return discountHolderIdSet.has(holderId);
|
|
168
|
-
});
|
|
106
|
+
// 主预约holder, 目前(20251124)默认只考虑单个holder的情况
|
|
107
|
+
var orderHolderId = Array.isArray(holders) && holders.length > 0 ? holders[0].form_record_id : undefined;
|
|
108
|
+
var productHolderId = Array.isArray(product.holder_id) ? product.holder_id[0] : product.holder_id;
|
|
109
|
+
// 商品不需要选holder,则不对比holder,直接返回true,
|
|
110
|
+
if (!product.isNeedHolder) return true;
|
|
111
|
+
// 商品需要holder,但父预约及商品都无holder,返回false
|
|
112
|
+
if (!orderHolderId && !productHolderId) return false;
|
|
113
|
+
// 最终直接匹配 holder 是否相同
|
|
114
|
+
return (productHolderId || orderHolderId) === discount.holder.holder_id;
|
|
169
115
|
}
|
|
170
116
|
|
|
171
117
|
// 判断discountList 是否可以对当前productList生效
|
|
172
118
|
}, {
|
|
173
119
|
key: "isDiscountListAvailable",
|
|
174
|
-
value: function isDiscountListAvailable(
|
|
120
|
+
value: function isDiscountListAvailable(_ref) {
|
|
175
121
|
var _this2 = this;
|
|
176
|
-
var oldDiscountList =
|
|
177
|
-
newDiscountList =
|
|
178
|
-
productList =
|
|
179
|
-
holders =
|
|
180
|
-
isFormSubject =
|
|
122
|
+
var oldDiscountList = _ref.oldDiscountList,
|
|
123
|
+
newDiscountList = _ref.newDiscountList,
|
|
124
|
+
productList = _ref.productList,
|
|
125
|
+
holders = _ref.holders,
|
|
126
|
+
isFormSubject = _ref.isFormSubject;
|
|
181
127
|
// 首先检查是否有新的优惠券可应用
|
|
182
128
|
if (!newDiscountList || newDiscountList.length === 0) {
|
|
183
129
|
return {
|
|
@@ -188,7 +134,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
188
134
|
}
|
|
189
135
|
|
|
190
136
|
// 编辑商品已有商品券
|
|
191
|
-
if (
|
|
137
|
+
if (productList.every(function (item) {
|
|
192
138
|
var _product$discount_lis;
|
|
193
139
|
var product = _this2.hooks.getProduct(item);
|
|
194
140
|
return product.booking_id && (((_product$discount_lis = product.discount_list) === null || _product$discount_lis === void 0 ? void 0 : _product$discount_lis.length) || product.total == 0);
|
|
@@ -206,10 +152,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
206
152
|
var filteredOldDiscountList = oldDiscountList.filter(function (discount) {
|
|
207
153
|
return !discount.isEditMode && (discount.tag !== 'good_pass' || discount.isScan);
|
|
208
154
|
});
|
|
209
|
-
var mergedDiscountList = uniqueById([].concat(_toConsumableArray(
|
|
155
|
+
var mergedDiscountList = uniqueById([].concat(_toConsumableArray(filteredOldDiscountList), _toConsumableArray(newDiscountList)));
|
|
210
156
|
var result = this.calcDiscount({
|
|
211
157
|
discountList: mergedDiscountList,
|
|
212
|
-
productList:
|
|
158
|
+
productList: _toConsumableArray(productList),
|
|
213
159
|
holders: holders,
|
|
214
160
|
isFormSubject: isFormSubject
|
|
215
161
|
}, {
|
|
@@ -218,16 +164,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
218
164
|
|
|
219
165
|
// 检查是否有产品使用了新折扣
|
|
220
166
|
var hasApplicableDiscount = false;
|
|
221
|
-
var newDiscountIds =
|
|
222
|
-
return
|
|
223
|
-
})
|
|
167
|
+
var newDiscountIds = newDiscountList.map(function (discount) {
|
|
168
|
+
return discount.id;
|
|
169
|
+
});
|
|
224
170
|
|
|
225
171
|
// 遍历处理后的产品列表,检查是否有产品使用了新折扣
|
|
226
172
|
result.productList.forEach(function (product) {
|
|
227
|
-
var
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
bundle = mappedProduct.bundle;
|
|
173
|
+
var _this2$hooks$getProdu = _this2.hooks.getProduct(product),
|
|
174
|
+
discount_list = _this2$hooks$getProdu.discount_list,
|
|
175
|
+
bundle = _this2$hooks$getProdu.bundle;
|
|
231
176
|
var allDiscountList = _toConsumableArray(discount_list || []);
|
|
232
177
|
(bundle || []).forEach(function (item) {
|
|
233
178
|
allDiscountList.push.apply(allDiscountList, _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
|
|
@@ -236,7 +181,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
236
181
|
// 检查是否有使用新折扣的情况
|
|
237
182
|
var usedNewDiscount = allDiscountList.some(function (discount) {
|
|
238
183
|
var _discount$discount;
|
|
239
|
-
return newDiscountIds.
|
|
184
|
+
return newDiscountIds.includes(discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id);
|
|
240
185
|
});
|
|
241
186
|
if (usedNewDiscount) {
|
|
242
187
|
hasApplicableDiscount = true;
|
|
@@ -251,7 +196,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
251
196
|
}
|
|
252
197
|
return {
|
|
253
198
|
isAvailable: hasApplicableDiscount,
|
|
254
|
-
evaluatedDiscountList: result.discountList,
|
|
255
199
|
discountList: hasApplicableDiscount ? result.discountList : oldDiscountList,
|
|
256
200
|
productList: hasApplicableDiscount ? result.productList : productList,
|
|
257
201
|
unavailableReason: unavailableReason
|
|
@@ -281,7 +225,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
281
225
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
282
226
|
var item = _step3.value;
|
|
283
227
|
var product = this.hooks.getProduct(item);
|
|
284
|
-
var bookingTime =
|
|
228
|
+
var bookingTime = ((product === null || product === void 0 ? void 0 : product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss');
|
|
285
229
|
var filteredList = filterDiscountListByBookingTime([discount], bookingTime);
|
|
286
230
|
if (filteredList.length === 0) {
|
|
287
231
|
return UnavailableReason.TimeLimit;
|
|
@@ -306,7 +250,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
306
250
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
307
251
|
var _discount = _step2.value;
|
|
308
252
|
var limitedData = _discount.limited_relation_product_data;
|
|
309
|
-
if (!limitedData) return UnavailableReason.ProductNotApplicable;
|
|
310
253
|
var hasApplicableProduct = false;
|
|
311
254
|
var _iterator4 = _createForOfIteratorHelper(productList),
|
|
312
255
|
_step4;
|
|
@@ -341,68 +284,19 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
341
284
|
}
|
|
342
285
|
}, {
|
|
343
286
|
key: "calcDiscount",
|
|
344
|
-
value: function calcDiscount(
|
|
287
|
+
value: function calcDiscount(_ref2, options) {
|
|
345
288
|
var _this3 = this;
|
|
346
|
-
var discountList =
|
|
347
|
-
productList =
|
|
348
|
-
holders =
|
|
349
|
-
isFormSubject =
|
|
350
|
-
discountList = this.entitlementPassEnabled ? withCommittedEntitlementDetails(discountList, productList, this.hooks.getProduct) : discountList.filter(function (item) {
|
|
351
|
-
return !isEntitlementPass(item);
|
|
352
|
-
});
|
|
353
|
-
var usableEntitlements = discountList.filter(function (discount) {
|
|
354
|
-
return isEntitlementPass(discount) && !discount.isEditMode && !discount.isManualSelect && !getDiscountUsageBlockReason(discount);
|
|
355
|
-
});
|
|
356
|
-
var canUseEntitlement = function canUseEntitlement(originProduct) {
|
|
357
|
-
var _product$original_pri;
|
|
358
|
-
var product = _this3.hooks.getProduct(originProduct);
|
|
359
|
-
// 预判任一份可用就按份拆开,实际抵扣仍逐份核对 Holder。
|
|
360
|
-
var holderProducts = Array.isArray(product.holder_id) && product.holder_id.length > 1 ? product.holder_id.map(function (holder_id) {
|
|
361
|
-
return _objectSpread(_objectSpread({}, product), {}, {
|
|
362
|
-
holder_id: holder_id
|
|
363
|
-
});
|
|
364
|
-
}) : [product];
|
|
365
|
-
var items = [{
|
|
366
|
-
type: 'main',
|
|
367
|
-
id: product.id,
|
|
368
|
-
price: (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product.price
|
|
369
|
-
}].concat(_toConsumableArray((product.bundle || []).map(function (bundleItem) {
|
|
370
|
-
var _ref13, _bundleItem$_bundle_p, _bundleItem$original_;
|
|
371
|
-
return {
|
|
372
|
-
type: 'bundle',
|
|
373
|
-
id: (_ref13 = (_bundleItem$_bundle_p = bundleItem._bundle_product_id) !== null && _bundleItem$_bundle_p !== void 0 ? _bundleItem$_bundle_p : bundleItem.bundle_product_id) !== null && _ref13 !== void 0 ? _ref13 : bundleItem.product_id,
|
|
374
|
-
price: (_bundleItem$original_ = bundleItem.original_price) !== null && _bundleItem$original_ !== void 0 ? _bundleItem$original_ : bundleItem.price,
|
|
375
|
-
bundleItem: bundleItem
|
|
376
|
-
};
|
|
377
|
-
})));
|
|
378
|
-
return usableEntitlements.some(function (discount) {
|
|
379
|
-
var scope = discount.limited_relation_product_data;
|
|
380
|
-
if (!scope || !holderProducts.some(function (item) {
|
|
381
|
-
return _this3.checkHolderMatch(discount, item, originProduct, holders);
|
|
382
|
-
}) || !filterDiscountListByBookingTime([discount], dayjs(product.startDate || undefined).format('YYYY-MM-DD HH:mm:ss')).length) return false;
|
|
383
|
-
return items.some(function (item) {
|
|
384
|
-
var _scope$exclude_produc, _scope$product_ids;
|
|
385
|
-
return Number(item.price) > 0 && (scope.type === 'product_all' ? !(scope.filter === 1 && (_scope$exclude_produc = scope.exclude_product_ids) !== null && _scope$exclude_produc !== void 0 && _scope$exclude_produc.some(function (id) {
|
|
386
|
-
return String(id) === String(item.id);
|
|
387
|
-
})) : !!((_scope$product_ids = scope.product_ids) !== null && _scope$product_ids !== void 0 && _scope$product_ids.includes(item.id))) && _this3.checkPackageSubItemUsageRules(discount, _objectSpread(_objectSpread({}, item), {}, {
|
|
388
|
-
originProduct: originProduct,
|
|
389
|
-
parentProduct: product
|
|
390
|
-
}));
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
};
|
|
394
|
-
if (this.entitlementPassEnabled) productList = prepareEntitlementLines(productList, this.hooks, canUseEntitlement);
|
|
289
|
+
var discountList = _ref2.discountList,
|
|
290
|
+
productList = _ref2.productList,
|
|
291
|
+
holders = _ref2.holders,
|
|
292
|
+
isFormSubject = _ref2.isFormSubject;
|
|
395
293
|
var editModeDiscount = [];
|
|
396
294
|
var addModeDiscount = [];
|
|
397
295
|
discountList.forEach(function (discount) {
|
|
398
296
|
if (discount.isEditMode) {
|
|
399
297
|
editModeDiscount.push(discount);
|
|
400
298
|
} else {
|
|
401
|
-
addModeDiscount.push(
|
|
402
|
-
config: undefined,
|
|
403
|
-
reason: undefined,
|
|
404
|
-
reasonCode: undefined
|
|
405
|
-
}) : discount);
|
|
299
|
+
addModeDiscount.push(discount);
|
|
406
300
|
}
|
|
407
301
|
});
|
|
408
302
|
|
|
@@ -453,7 +347,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
453
347
|
// 2. 展开 bundle 子商品
|
|
454
348
|
if (product.bundle && Array.isArray(product.bundle) && product.bundle.length > 0) {
|
|
455
349
|
product.bundle.forEach(function (bundleItem, bundleIndex) {
|
|
456
|
-
var _ref14, _bundleItem$_bundle_p2;
|
|
457
350
|
flattened.push({
|
|
458
351
|
type: 'bundle',
|
|
459
352
|
originProduct: originProduct,
|
|
@@ -462,7 +355,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
462
355
|
bundleIndex: bundleIndex,
|
|
463
356
|
// 虚拟商品属性
|
|
464
357
|
price: Number(bundleItem.price || 0),
|
|
465
|
-
id:
|
|
358
|
+
id: bundleItem._bundle_product_id,
|
|
359
|
+
// 🔥 使用 _bundle_product_id
|
|
466
360
|
_id: "".concat(product._id, "_bundle_").concat(bundleIndex),
|
|
467
361
|
parentId: product._id,
|
|
468
362
|
num: bundleItem.num || 1,
|
|
@@ -568,9 +462,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
568
462
|
}
|
|
569
463
|
return 0;
|
|
570
464
|
}
|
|
571
|
-
if (isEntitlementPass(a) || isEntitlementPass(b)) {
|
|
572
|
-
return isEntitlementPass(a) && isEntitlementPass(b) ? compareEntitlementPassPriority(a, b) : isEntitlementPass(a) ? -1 : 1;
|
|
573
|
-
}
|
|
574
465
|
|
|
575
466
|
// 1. 先按优先级排序
|
|
576
467
|
var priorityA = getPriority(a);
|
|
@@ -622,10 +513,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
622
513
|
|
|
623
514
|
// 对扁平化后的列表按价格降序排序(用于应用优惠券时优先选择高价商品)
|
|
624
515
|
var sortedFlattenedList = flattenedList.sort(function (a, b) {
|
|
625
|
-
var
|
|
516
|
+
var _ref3, _a$original_price, _ref4, _b$original_price;
|
|
626
517
|
// 子商品优先使用 original_price,主商品使用 price
|
|
627
|
-
var priceA = new Decimal(a.type === 'bundle' ? (
|
|
628
|
-
var priceB = new Decimal(b.type === 'bundle' ? (
|
|
518
|
+
var priceA = new Decimal(a.type === 'bundle' ? (_ref3 = (_a$original_price = a.original_price) !== null && _a$original_price !== void 0 ? _a$original_price : a.price) !== null && _ref3 !== void 0 ? _ref3 : '0' : a.price || '0');
|
|
519
|
+
var priceB = new Decimal(b.type === 'bundle' ? (_ref4 = (_b$original_price = b.original_price) !== null && _b$original_price !== void 0 ? _b$original_price : b.price) !== null && _ref4 !== void 0 ? _ref4 : '0' : b.price || '0');
|
|
629
520
|
if (priceA.equals(priceB)) {
|
|
630
521
|
// 价格相同时,主商品优先
|
|
631
522
|
if (a.type !== b.type) {
|
|
@@ -673,93 +564,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
673
564
|
});
|
|
674
565
|
*/
|
|
675
566
|
|
|
676
|
-
//
|
|
567
|
+
// 标记已使用的优惠券
|
|
677
568
|
var usedDiscounts = new Map();
|
|
678
|
-
var entitlementUsageCounts = new Map();
|
|
679
|
-
var usedProductIdCounts = new Map();
|
|
680
|
-
var markDiscountUsed = function markDiscountUsed(discount) {
|
|
681
|
-
if (isEntitlementPass(discount)) {
|
|
682
|
-
entitlementUsageCounts.set(discount.id, (entitlementUsageCounts.get(discount.id) || 0) + 1);
|
|
683
|
-
} else {
|
|
684
|
-
usedDiscounts.set(discount.id, true);
|
|
685
|
-
}
|
|
686
|
-
usedProductIdCounts.set(discount.product_id, (usedProductIdCounts.get(discount.product_id) || 0) + 1);
|
|
687
|
-
};
|
|
688
|
-
|
|
689
|
-
// 沿用商品券逐份拆分,同一多次卡可重复分配,数量受本单剩余额度限制。
|
|
690
|
-
var getFullCoveragePasses = function getFullCoveragePasses(discounts, quantity) {
|
|
691
|
-
var allocated = [];
|
|
692
|
-
var productCounts = new Map(usedProductIdCounts);
|
|
693
|
-
var _iterator5 = _createForOfIteratorHelper(discounts),
|
|
694
|
-
_step5;
|
|
695
|
-
try {
|
|
696
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
697
|
-
var _discount$config;
|
|
698
|
-
var discount = _step5.value;
|
|
699
|
-
if (!isFullCoveragePass(discount) || allocated.length >= quantity) continue;
|
|
700
|
-
var count = isEntitlementPass(discount) ? getRemainingEntitlementUses(discount, entitlementUsageCounts.get(discount.id) || 0, quantity - allocated.length) : usedDiscounts.get(discount.id) ? 0 : 1;
|
|
701
|
-
var limit = Number(((_discount$config = discount.config) === null || _discount$config === void 0 ? void 0 : _discount$config.maxUsagePerOrder) || 0);
|
|
702
|
-
if (isEntitlementPass(discount) && limit > 0) {
|
|
703
|
-
count = Math.min(count, Math.max(0, Math.floor(limit) - (productCounts.get(discount.product_id) || 0)));
|
|
704
|
-
}
|
|
705
|
-
for (var i = 0; i < count; i++) allocated.push(discount);
|
|
706
|
-
productCounts.set(discount.product_id, (productCounts.get(discount.product_id) || 0) + count);
|
|
707
|
-
}
|
|
708
|
-
} catch (err) {
|
|
709
|
-
_iterator5.e(err);
|
|
710
|
-
} finally {
|
|
711
|
-
_iterator5.f();
|
|
712
|
-
}
|
|
713
|
-
return allocated;
|
|
714
|
-
};
|
|
715
|
-
var evaluator;
|
|
716
|
-
addModeDiscount.filter(isEntitlementPass).forEach(function (discount) {
|
|
717
|
-
var _evaluator, _discount$unified_ava, _discount$limited_rel, _discount$limited_rel2;
|
|
718
|
-
discount.usageLimitFailKey = getDiscountUsageLimitFailKey(discount);
|
|
719
|
-
discount.reasonCode = getDiscountUsageBlockReason(discount);
|
|
720
|
-
var quota = resolveEntitlementQuota(discount);
|
|
721
|
-
if (discount.reasonCode || !quota) {
|
|
722
|
-
discount.config = {
|
|
723
|
-
isAvailable: false
|
|
724
|
-
};
|
|
725
|
-
return;
|
|
726
|
-
}
|
|
727
|
-
(_evaluator = evaluator) !== null && _evaluator !== void 0 ? _evaluator : evaluator = _this3.getWalletPassEvaluator();
|
|
728
|
-
var result = evaluator.checkVoucherAvailability({
|
|
729
|
-
orderTotalAmount: productList.reduce(function (sum, item) {
|
|
730
|
-
var product = _this3.hooks.getProduct(item);
|
|
731
|
-
return sum.plus(new Decimal(product.origin_total || 0).times(product.quantity || product.num || 1));
|
|
732
|
-
}, new Decimal(0)).toNumber(),
|
|
733
|
-
// 策略按统一商品结构读主价与数量,套餐次数还需乘父商品份数。
|
|
734
|
-
products: sortedFlattenedList.map(function (item) {
|
|
735
|
-
var _item$parentProduct, _item$parentProduct2, _item$product;
|
|
736
|
-
return {
|
|
737
|
-
product_id: item.id,
|
|
738
|
-
price: item.price || 0,
|
|
739
|
-
main_product_selling_price: item.price || 0,
|
|
740
|
-
quantity: (item.quantity || item.num || 1) * (item.type === 'bundle' ? ((_item$parentProduct = item.parentProduct) === null || _item$parentProduct === void 0 ? void 0 : _item$parentProduct.quantity) || ((_item$parentProduct2 = item.parentProduct) === null || _item$parentProduct2 === void 0 ? void 0 : _item$parentProduct2.num) || 1 : 1),
|
|
741
|
-
product_options: item.type === 'main' ? (_item$product = item.product) === null || _item$product === void 0 ? void 0 : _item$product.options : undefined
|
|
742
|
-
};
|
|
743
|
-
}),
|
|
744
|
-
vouchers: [_objectSpread(_objectSpread({}, discount), {}, {
|
|
745
|
-
amount: Number(discount.par_value || 0),
|
|
746
|
-
balance: quota.type === 'unlimited' ? Number.MAX_SAFE_INTEGER : quota.balance,
|
|
747
|
-
type: 'entitlement_pass',
|
|
748
|
-
unified_available_status: (_discount$unified_ava = discount.unified_available_status) !== null && _discount$unified_ava !== void 0 ? _discount$unified_ava : 1,
|
|
749
|
-
available_product_type: (_discount$limited_rel = discount.limited_relation_product_data) === null || _discount$limited_rel === void 0 ? void 0 : _discount$limited_rel.type,
|
|
750
|
-
available_product_ids: (_discount$limited_rel2 = discount.limited_relation_product_data) === null || _discount$limited_rel2 === void 0 ? void 0 : _discount$limited_rel2.product_ids
|
|
751
|
-
})]
|
|
752
|
-
});
|
|
753
|
-
discount.config = _objectSpread(_objectSpread({}, result.config), {}, {
|
|
754
|
-
isAvailable: result.isAvailable
|
|
755
|
-
});
|
|
756
|
-
if (!result.isAvailable) {
|
|
757
|
-
discount.reason = result.reason;
|
|
758
|
-
discount.reasonCode = result.reasonCode || 'not_meet_the_required_conditions';
|
|
759
|
-
}
|
|
760
|
-
});
|
|
761
|
-
var entitlementTimeReasons = new Map();
|
|
762
|
-
var entitlementHolderMismatch = new Set();
|
|
763
569
|
|
|
764
570
|
// 记录每个优惠券适用的商品ID
|
|
765
571
|
var discountApplicability = new Map();
|
|
@@ -805,7 +611,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
805
611
|
|
|
806
612
|
// 编辑的商品使用了优惠券不可用
|
|
807
613
|
var isAvailableProduct = flatItem.type === 'main' ? !((_product2 = product) !== null && _product2 !== void 0 && _product2.booking_id && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.length && (_product4 = product) !== null && _product4 !== void 0 && (_product4 = _product4.discount_list) !== null && _product4 !== void 0 && _product4.every(function (d) {
|
|
808
|
-
return d.id && ['
|
|
614
|
+
return d.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(d.tag || d.type);
|
|
809
615
|
})) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem = flatItem.bundleItem) !== null && _flatItem$bundleItem !== void 0 && (_flatItem$bundleItem = _flatItem$bundleItem.discount_list) !== null && _flatItem$bundleItem !== void 0 && _flatItem$bundleItem.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem2 = flatItem.bundleItem) !== null && _flatItem$bundleItem2 !== void 0 && (_flatItem$bundleItem2 = _flatItem$bundleItem2.discount_list) !== null && _flatItem$bundleItem2 !== void 0 && _flatItem$bundleItem2.every(function (d) {
|
|
810
616
|
return d.id;
|
|
811
617
|
}));
|
|
@@ -825,7 +631,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
825
631
|
var limitedData = discount.limited_relation_product_data;
|
|
826
632
|
|
|
827
633
|
// 时间限制检查
|
|
828
|
-
var timeLimit = !!filterDiscountListByBookingTime([discount],
|
|
634
|
+
var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
829
635
|
if (!timeLimit) {
|
|
830
636
|
return false;
|
|
831
637
|
}
|
|
@@ -906,7 +712,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
906
712
|
// 收集该折扣卡适用的商品(排除被其他专属折扣卡占用的商品)
|
|
907
713
|
var applicableProducts = [];
|
|
908
714
|
sortedFlattenedList.forEach(function (flatItem) {
|
|
909
|
-
var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price,
|
|
715
|
+
var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price, _ref5, _flatItem$original_pr;
|
|
910
716
|
// 🔥 检查该商品是否被其他专属折扣卡占用
|
|
911
717
|
var occupyingDiscountId = occupiedItems.get(flatItem._id);
|
|
912
718
|
if (occupyingDiscountId !== undefined && occupyingDiscountId !== discount.id) {
|
|
@@ -934,7 +740,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
934
740
|
|
|
935
741
|
// 对于主商品:使用 price
|
|
936
742
|
// 对于子商品:优先使用 flatItem.original_price,否则使用 flatItem.price
|
|
937
|
-
var originalAmount = flatItem.type === 'main' ? Number((_product$price = product.price) !== null && _product$price !== void 0 ? _product$price : 0) : Number((
|
|
743
|
+
var originalAmount = flatItem.type === 'main' ? Number((_product$price = product.price) !== null && _product$price !== void 0 ? _product$price : 0) : Number((_ref5 = (_flatItem$original_pr = flatItem.original_price) !== null && _flatItem$original_pr !== void 0 ? _flatItem$original_pr : flatItem.price) !== null && _ref5 !== void 0 ? _ref5 : 0);
|
|
938
744
|
|
|
939
745
|
// 传递 parentQuantity 用于差值处理时判断是否是真正的"数量为1"
|
|
940
746
|
var productData = {
|
|
@@ -990,32 +796,22 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
990
796
|
originProduct = flatItem.originProduct;
|
|
991
797
|
}
|
|
992
798
|
addModeDiscount.forEach(function (discount) {
|
|
993
|
-
var
|
|
799
|
+
var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4;
|
|
994
800
|
var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
|
|
995
|
-
if (!limitedData || isEntitlementPass(discount) && ((_discount$config2 = discount.config) === null || _discount$config2 === void 0 ? void 0 : _discount$config2.isAvailable) === false) return;
|
|
996
|
-
|
|
997
801
|
// 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
|
|
998
802
|
var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
|
|
999
803
|
var isHolderMatch = _this3.checkHolderMatch(discount, {
|
|
1000
804
|
isNeedHolder: isFormSubject && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
|
|
1001
805
|
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
1002
|
-
},
|
|
806
|
+
}, holders);
|
|
1003
807
|
var timeLimit = true;
|
|
1004
|
-
|
|
1005
|
-
timeLimit = !!filterDiscountListByBookingTime([discount], useTime).length;
|
|
1006
|
-
if (isEntitlementPass(discount)) {
|
|
1007
|
-
var reason = getDiscountTimeUnavailableReason(discount, useTime);
|
|
1008
|
-
var reasons = entitlementTimeReasons.get(discount.id) || [];
|
|
1009
|
-
reasons.push(reason);
|
|
1010
|
-
entitlementTimeReasons.set(discount.id, reasons);
|
|
1011
|
-
if (!isHolderMatch) entitlementHolderMismatch.add(discount.id);
|
|
1012
|
-
}
|
|
808
|
+
timeLimit = !!filterDiscountListByBookingTime([discount], (((_product6 = product) === null || _product6 === void 0 ? void 0 : _product6.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
1013
809
|
// 是符合折扣的商品
|
|
1014
|
-
var isLimitedProduct = (limitedData.type === 'product_all'
|
|
810
|
+
var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
1015
811
|
|
|
1016
812
|
// 编辑的商品 使用了优惠券不可用
|
|
1017
813
|
var isAvailableProduct = flatItem.type === 'main' ? !((_product7 = product) !== null && _product7 !== void 0 && _product7.booking_id && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.length && (_product9 = product) !== null && _product9 !== void 0 && (_product9 = _product9.discount_list) !== null && _product9 !== void 0 && _product9.every(function (discount) {
|
|
1018
|
-
return discount.id && ['
|
|
814
|
+
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
1019
815
|
})) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem3 = flatItem.bundleItem) !== null && _flatItem$bundleItem3 !== void 0 && (_flatItem$bundleItem3 = _flatItem$bundleItem3.discount_list) !== null && _flatItem$bundleItem3 !== void 0 && _flatItem$bundleItem3.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem4 = flatItem.bundleItem) !== null && _flatItem$bundleItem4 !== void 0 && (_flatItem$bundleItem4 = _flatItem$bundleItem4.discount_list) !== null && _flatItem$bundleItem4 !== void 0 && _flatItem$bundleItem4.every(function (discount) {
|
|
1020
816
|
return discount.id;
|
|
1021
817
|
}));
|
|
@@ -1024,7 +820,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1024
820
|
var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
|
|
1025
821
|
|
|
1026
822
|
// 判断优惠券是否适用于该商品
|
|
1027
|
-
if (isAvailableProduct &&
|
|
823
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
|
|
1028
824
|
var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
|
|
1029
825
|
// 记录此优惠券适用的商品
|
|
1030
826
|
(_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
|
|
@@ -1032,7 +828,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1032
828
|
// 记录可抵扣的商品详情
|
|
1033
829
|
var applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
1034
830
|
var discountType = discount.tag || discount.type;
|
|
1035
|
-
var isGoodPass =
|
|
831
|
+
var isGoodPass = discountType === 'good_pass';
|
|
1036
832
|
|
|
1037
833
|
// 使用数量
|
|
1038
834
|
var num = isGoodPass || (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'main' ? 1 : product.num;
|
|
@@ -1048,7 +844,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1048
844
|
title: discount.format_title,
|
|
1049
845
|
original_amount: product.price || product.origin_total,
|
|
1050
846
|
pre_value: discount.par_value,
|
|
1051
|
-
product_id:
|
|
847
|
+
product_id: originProduct.id
|
|
1052
848
|
},
|
|
1053
849
|
metadata: {
|
|
1054
850
|
num: num,
|
|
@@ -1093,8 +889,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1093
889
|
}
|
|
1094
890
|
|
|
1095
891
|
// 已有优惠的商品跳过
|
|
1096
|
-
if (
|
|
1097
|
-
return discount.id && ['
|
|
892
|
+
if ((_product10 = product) !== null && _product10 !== void 0 && _product10.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product11 = product) !== null && _product11 !== void 0 && (_product11 = _product11.discount_list) !== null && _product11 !== void 0 && _product11.every(function (discount) {
|
|
893
|
+
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
1098
894
|
})) {
|
|
1099
895
|
if (flatItem.type === 'main') {
|
|
1100
896
|
processedProductsMap.set(product._id, [originProduct]);
|
|
@@ -1108,33 +904,31 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1108
904
|
|
|
1109
905
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
1110
906
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
1111
|
-
var
|
|
1112
|
-
if (isEntitlementPass(discount) && (((_discount$config3 = discount.config) === null || _discount$config3 === void 0 ? void 0 : _discount$config3.isAvailable) === false || getRemainingEntitlementUses(discount, entitlementUsageCounts.get(discount.id) || 0, 1) <= 0 || Number((_discount$config4 = discount.config) === null || _discount$config4 === void 0 ? void 0 : _discount$config4.maxUsagePerOrder) > 0 && (usedProductIdCounts.get(discount.product_id) || 0) >= Number((_discount$config5 = discount.config) === null || _discount$config5 === void 0 ? void 0 : _discount$config5.maxUsagePerOrder))) return false;
|
|
907
|
+
var _product$discount_lis3, _product$discount_lis4;
|
|
1113
908
|
// 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
|
|
1114
909
|
// 商品券时主商品价格为0不可用
|
|
1115
|
-
if ((Number(product.price) <= 0 || !product.price) && !((_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length) &&
|
|
910
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length) && (discount.tag || discount.type) === 'good_pass') return false;
|
|
1116
911
|
|
|
1117
912
|
// 折扣卡商品价格为0时不可用
|
|
1118
913
|
if ((Number(product.price) <= 0 || !product.price) && !((_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.find(function (n) {
|
|
1119
914
|
var _n$discount;
|
|
1120
915
|
return ((_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.resource_id) === discount.id;
|
|
1121
|
-
})) &&
|
|
916
|
+
})) && (discount.tag || discount.type) !== 'good_pass') return false;
|
|
1122
917
|
// 如果优惠券已被使用,则跳过
|
|
1123
918
|
var targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
1124
919
|
if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
|
|
1125
920
|
var limitedData = discount.limited_relation_product_data;
|
|
1126
|
-
if (!limitedData) return false;
|
|
1127
921
|
|
|
1128
922
|
// 拿到discount配置的holder信息 product信息 product.holder 不可用return false
|
|
1129
923
|
var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
|
|
1130
924
|
var isHolderMatch = _this3.checkHolderMatch(discount, {
|
|
1131
925
|
isNeedHolder: isFormSubject && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
|
|
1132
926
|
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
1133
|
-
},
|
|
927
|
+
}, holders);
|
|
1134
928
|
// 如果 holder 不匹配,则不适用
|
|
1135
929
|
if (!isHolderMatch) return false;
|
|
1136
930
|
var timeLimit = true;
|
|
1137
|
-
timeLimit = !!filterDiscountListByBookingTime([discount],
|
|
931
|
+
timeLimit = !!filterDiscountListByBookingTime([discount], (product.startDate || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
1138
932
|
if (!timeLimit) {
|
|
1139
933
|
return false;
|
|
1140
934
|
}
|
|
@@ -1164,12 +958,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1164
958
|
// 如果有 isScan 且 isSelected 的折扣卡,则优先选中,否则再选择第一个
|
|
1165
959
|
// 用于处理:先手动扫描了一张折扣卡,扫描完以后带入客户信息,但是之前那张折扣卡不是最优惠的情况
|
|
1166
960
|
var selectedDiscountCard = applicableDiscounts.find(function (n) {
|
|
1167
|
-
return n.isScan && n.isSelected &&
|
|
961
|
+
return n.isScan && n.isSelected && (n.tag || n.type) !== 'good_pass';
|
|
1168
962
|
});
|
|
1169
|
-
var
|
|
1170
|
-
return isEntitlementPass(item) && String(item.id) === String(options.discountId);
|
|
1171
|
-
}) : undefined;
|
|
1172
|
-
var selectedDiscount = explicitlySelected || selectedDiscountCard || applicableDiscounts[0];
|
|
963
|
+
var selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
|
|
1173
964
|
|
|
1174
965
|
// 如果是手动折扣,则不适用优惠券
|
|
1175
966
|
var isManualDiscount = false;
|
|
@@ -1177,8 +968,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1177
968
|
var _product$discount_lis5, _product12, _product12$every;
|
|
1178
969
|
// 主商品:判断自身是否手动折扣
|
|
1179
970
|
isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
|
|
1180
|
-
var
|
|
1181
|
-
return !((
|
|
971
|
+
var _ref6;
|
|
972
|
+
return !((_ref6 = item.discount_list || []) !== null && _ref6 !== void 0 && _ref6.length);
|
|
1182
973
|
}) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product12 = product) === null || _product12 === void 0 || (_product12 = _product12.discount_list) === null || _product12 === void 0 || (_product12$every = _product12.every) === null || _product12$every === void 0 ? void 0 : _product12$every.call(_product12, function (item) {
|
|
1183
974
|
return item.type === 'product';
|
|
1184
975
|
})));
|
|
@@ -1188,8 +979,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1188
979
|
if (parentProduct) {
|
|
1189
980
|
var _parentProduct$discou, _parentProduct$discou2, _parentProduct$discou3;
|
|
1190
981
|
isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
|
|
1191
|
-
var
|
|
1192
|
-
return !((
|
|
982
|
+
var _ref7;
|
|
983
|
+
return !((_ref7 = item.discount_list || []) !== null && _ref7 !== void 0 && _ref7.length);
|
|
1193
984
|
}) && (!((_parentProduct$discou = parentProduct.discount_list) !== null && _parentProduct$discou !== void 0 && _parentProduct$discou.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou2 = parentProduct.discount_list) === null || _parentProduct$discou2 === void 0 || (_parentProduct$discou3 = _parentProduct$discou2.every) === null || _parentProduct$discou3 === void 0 ? void 0 : _parentProduct$discou3.call(_parentProduct$discou2, function (item) {
|
|
1194
985
|
return item.type === 'product';
|
|
1195
986
|
})));
|
|
@@ -1281,8 +1072,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1281
1072
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1282
1073
|
}))]);
|
|
1283
1074
|
} else {
|
|
1284
|
-
var
|
|
1285
|
-
var total = product.inPromotion ? (
|
|
1075
|
+
var _ref8, _product$_promotion$f, _product13, _product$origin_total, _product$price2;
|
|
1076
|
+
var total = product.inPromotion ? (_ref8 = (_product$_promotion$f = (_product13 = product) === null || _product13 === void 0 || (_product13 = _product13._promotion) === null || _product13 === void 0 ? void 0 : _product13.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref8 !== void 0 ? _ref8 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
|
|
1286
1077
|
var main_product_selling_price = (_product$price2 = product.price) !== null && _product$price2 !== void 0 ? _product$price2 : product.main_product_selling_price;
|
|
1287
1078
|
if ((product.discount_list || []).some(function (item) {
|
|
1288
1079
|
return item.type === 'promotion';
|
|
@@ -1320,17 +1111,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1320
1111
|
}
|
|
1321
1112
|
|
|
1322
1113
|
// 是否需要拆分(商品券需要拆分)
|
|
1323
|
-
var isNeedSplit =
|
|
1114
|
+
var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
|
|
1324
1115
|
|
|
1325
1116
|
// 需要拆分出来的数量
|
|
1326
1117
|
var totalQuantity = product.quantity || product.num || 1;
|
|
1327
|
-
var
|
|
1328
|
-
return item !== selectedDiscount;
|
|
1329
|
-
})));
|
|
1330
|
-
var allocatedPasses = isNeedSplit ? applicableDiscounts.some(isEntitlementPass) ? getFullCoveragePasses(prioritizedDiscounts, totalQuantity) : applicableDiscounts.slice(0, Math.min(totalQuantity, applicableDiscounts.filter(function (item) {
|
|
1118
|
+
var availableGoodPassCount = applicableDiscounts.filter(function (item) {
|
|
1331
1119
|
return (item.tag || item.type) === 'good_pass';
|
|
1332
|
-
}).length
|
|
1333
|
-
var splitCount =
|
|
1120
|
+
}).length;
|
|
1121
|
+
var splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
|
|
1334
1122
|
var arr = [];
|
|
1335
1123
|
|
|
1336
1124
|
// 🔥 主商品和bundle子商品分别处理
|
|
@@ -1345,8 +1133,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1345
1133
|
}
|
|
1346
1134
|
for (var i = 0; i < splitCount; i++) {
|
|
1347
1135
|
var _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
|
|
1348
|
-
|
|
1349
|
-
|
|
1136
|
+
// 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
|
|
1137
|
+
var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
|
|
1138
|
+
// 标记优惠券为已使用
|
|
1139
|
+
usedDiscounts.set(_selectedDiscount.id, true);
|
|
1350
1140
|
|
|
1351
1141
|
// 记录实际应用了优惠券的商品信息
|
|
1352
1142
|
var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
|
|
@@ -1381,7 +1171,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1381
1171
|
amount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
|
|
1382
1172
|
}
|
|
1383
1173
|
var discountType = _selectedDiscount.tag || _selectedDiscount.type;
|
|
1384
|
-
var isGoodPass =
|
|
1174
|
+
var isGoodPass = discountType === 'good_pass';
|
|
1385
1175
|
var discountDetail = {
|
|
1386
1176
|
amount: amount,
|
|
1387
1177
|
type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : discountType,
|
|
@@ -1392,7 +1182,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1392
1182
|
resource_id: _selectedDiscount.id,
|
|
1393
1183
|
title: _selectedDiscount.format_title,
|
|
1394
1184
|
original_amount: product.price,
|
|
1395
|
-
product_id:
|
|
1185
|
+
product_id: originProduct.id,
|
|
1396
1186
|
percent: _selectedDiscount.par_value
|
|
1397
1187
|
},
|
|
1398
1188
|
// 前端使用的num数量,为了计算优惠金额
|
|
@@ -1420,7 +1210,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1420
1210
|
if (product.isClient) {
|
|
1421
1211
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1422
1212
|
discount_list: [discountDetail],
|
|
1423
|
-
price:
|
|
1213
|
+
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
1424
1214
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1425
1215
|
origin_total: getProductOriginTotalPrice({
|
|
1426
1216
|
product: {
|
|
@@ -1436,8 +1226,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1436
1226
|
} else {
|
|
1437
1227
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1438
1228
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion').concat([discountDetail]),
|
|
1439
|
-
_id: product._id.split('___')[0] + "___" + _selectedDiscount.id + index
|
|
1440
|
-
price:
|
|
1229
|
+
_id: product._id.split('___')[0] + "___" + _selectedDiscount.id + index,
|
|
1230
|
+
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
1441
1231
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1442
1232
|
total: _total,
|
|
1443
1233
|
origin_total: productOriginTotal,
|
|
@@ -1457,16 +1247,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1457
1247
|
// 生成有折扣的商品(每张商品券对应 num: 1)
|
|
1458
1248
|
for (var _i = 0; _i < discountNum; _i++) {
|
|
1459
1249
|
var _selectedDiscount2$me;
|
|
1460
|
-
var _selectedDiscount2 =
|
|
1461
|
-
|
|
1250
|
+
var _selectedDiscount2 = applicableDiscounts[_i];
|
|
1251
|
+
usedDiscounts.set(_selectedDiscount2.id, true);
|
|
1462
1252
|
|
|
1463
1253
|
// 🔥 生成唯一的 _id
|
|
1464
1254
|
var uniqueId = "".concat(flatItem._id, "_split_").concat(_i);
|
|
1465
1255
|
var _discountDetail = {
|
|
1466
|
-
amount: product.origin_total
|
|
1467
|
-
type:
|
|
1256
|
+
amount: product.origin_total,
|
|
1257
|
+
type: 'good_pass',
|
|
1468
1258
|
discount: {
|
|
1469
|
-
fixed_amount: product.origin_total
|
|
1259
|
+
fixed_amount: product.origin_total,
|
|
1470
1260
|
discount_calculation_mode: _selectedDiscount2 === null || _selectedDiscount2 === void 0 || (_selectedDiscount2$me = _selectedDiscount2.metadata) === null || _selectedDiscount2$me === void 0 ? void 0 : _selectedDiscount2$me.discount_calculation_mode,
|
|
1471
1261
|
resource_id: _selectedDiscount2.id,
|
|
1472
1262
|
title: _selectedDiscount2.format_title,
|
|
@@ -1512,14 +1302,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1512
1302
|
}));
|
|
1513
1303
|
}
|
|
1514
1304
|
} else {
|
|
1515
|
-
var
|
|
1305
|
+
var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu9;
|
|
1516
1306
|
// 折扣卡:不拆分数量,直接应用
|
|
1517
|
-
|
|
1307
|
+
var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
|
|
1308
|
+
usedDiscounts.set(_selectedDiscount3.id, true);
|
|
1518
1309
|
var _productOriginTotal = product.original_price || product.price || 0;
|
|
1519
1310
|
|
|
1520
1311
|
// 🔥 检查是否是 order_level 固定金额折扣卡
|
|
1521
|
-
var _isOrderLevel = isOrderLevelFixedAmountDiscount(
|
|
1522
|
-
var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
1312
|
+
var _isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount3);
|
|
1313
|
+
var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount3.id) : null;
|
|
1523
1314
|
var _productAllocation = _orderLevelAllocation === null || _orderLevelAllocation === void 0 ? void 0 : _orderLevelAllocation.get(flatItem._id);
|
|
1524
1315
|
var _targetProductTotal;
|
|
1525
1316
|
var fixedAmountPerItem;
|
|
@@ -1531,7 +1322,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1531
1322
|
_targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
|
|
1532
1323
|
} else {
|
|
1533
1324
|
// item_level 或其他类型:使用原有逻辑
|
|
1534
|
-
_targetProductTotal = getDiscountAmount(
|
|
1325
|
+
_targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
|
|
1535
1326
|
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
|
|
1536
1327
|
}
|
|
1537
1328
|
|
|
@@ -1539,21 +1330,21 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1539
1330
|
var _uniqueId = flatItem._id;
|
|
1540
1331
|
var _discountDetail2 = {
|
|
1541
1332
|
amount: fixedAmountPerItem * (product.num || 1),
|
|
1542
|
-
type:
|
|
1333
|
+
type: _selectedDiscount3.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount3.tag,
|
|
1543
1334
|
discount: {
|
|
1544
|
-
discount_card_type:
|
|
1335
|
+
discount_card_type: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me = _selectedDiscount3.metadata) === null || _selectedDiscount3$me === void 0 ? void 0 : _selectedDiscount3$me.discount_card_type,
|
|
1545
1336
|
fixed_amount: fixedAmountPerItem,
|
|
1546
|
-
discount_calculation_mode:
|
|
1547
|
-
resource_id:
|
|
1548
|
-
title:
|
|
1337
|
+
discount_calculation_mode: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me2 = _selectedDiscount3.metadata) === null || _selectedDiscount3$me2 === void 0 ? void 0 : _selectedDiscount3$me2.discount_calculation_mode,
|
|
1338
|
+
resource_id: _selectedDiscount3.id,
|
|
1339
|
+
title: _selectedDiscount3.format_title,
|
|
1549
1340
|
original_amount: product.original_price,
|
|
1550
1341
|
product_id: product.id,
|
|
1551
|
-
percent:
|
|
1342
|
+
percent: _selectedDiscount3.par_value
|
|
1552
1343
|
},
|
|
1553
1344
|
metadata: _objectSpread({
|
|
1554
1345
|
// 🔥 使用唯一的 _id
|
|
1555
1346
|
custom_product_bundle_map_id: _uniqueId,
|
|
1556
|
-
discount_rule_uncheck_flag:
|
|
1347
|
+
discount_rule_uncheck_flag: _selectedDiscount3 === null || _selectedDiscount3 === void 0 ? void 0 : _selectedDiscount3.discount_rule_uncheck_flag,
|
|
1557
1348
|
num: product.num || 1
|
|
1558
1349
|
}, _productDiscountDifference !== undefined && {
|
|
1559
1350
|
product_discount_difference: _productDiscountDifference
|
|
@@ -1562,9 +1353,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1562
1353
|
};
|
|
1563
1354
|
|
|
1564
1355
|
// 记录实际应用的折扣
|
|
1565
|
-
var _appliedProducts2 = appliedDiscountProducts.get(
|
|
1356
|
+
var _appliedProducts2 = appliedDiscountProducts.get(_selectedDiscount3.id) || [];
|
|
1566
1357
|
_appliedProducts2.push(_discountDetail2);
|
|
1567
|
-
appliedDiscountProducts.set(
|
|
1358
|
+
appliedDiscountProducts.set(_selectedDiscount3.id, _appliedProducts2);
|
|
1568
1359
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1569
1360
|
total: _targetProductTotal,
|
|
1570
1361
|
price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
|
|
@@ -1582,40 +1373,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1582
1373
|
originalProductList.forEach(function (originProduct) {
|
|
1583
1374
|
var product = _this3.hooks.getProduct(originProduct);
|
|
1584
1375
|
|
|
1585
|
-
// 已提交的扣次不参与运行时重组,避免价格或使用明细被二次改写。
|
|
1586
|
-
if (isPersistedEntitlementLine(originProduct, product)) {
|
|
1587
|
-
result.push(originProduct);
|
|
1588
|
-
return;
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
1376
|
// 获取主商品处理结果
|
|
1592
1377
|
var mainProductArr = processedProductsMap.get(product._id);
|
|
1593
|
-
if (isEntitlementRuntimeLine(originProduct, product) && !product.isManualDiscount && mainProductArr !== null && mainProductArr !== void 0 && mainProductArr.length) {
|
|
1594
|
-
var bundle = (product.bundle || []).flatMap(function (item, index) {
|
|
1595
|
-
var processed = processedFlatItemsMap.get("".concat(product._id, "_bundle_").concat(index));
|
|
1596
|
-
if (!(processed !== null && processed !== void 0 && processed.length)) return [item];
|
|
1597
|
-
return processed.map(function (child) {
|
|
1598
|
-
return _objectSpread(_objectSpread({}, item), {}, {
|
|
1599
|
-
_id: child._id,
|
|
1600
|
-
price: child.price,
|
|
1601
|
-
bundle_selling_price: child.price,
|
|
1602
|
-
num: child.num,
|
|
1603
|
-
discount_list: (child.discount_list || []).map(function (detail) {
|
|
1604
|
-
return _objectSpread(_objectSpread({}, detail), {}, {
|
|
1605
|
-
metadata: _objectSpread(_objectSpread({}, detail.metadata), {}, {
|
|
1606
|
-
num: child.num,
|
|
1607
|
-
custom_product_bundle_map_id: child._id
|
|
1608
|
-
})
|
|
1609
|
-
});
|
|
1610
|
-
})
|
|
1611
|
-
});
|
|
1612
|
-
});
|
|
1613
|
-
});
|
|
1614
|
-
result.push.apply(result, _toConsumableArray(mainProductArr.map(function (item) {
|
|
1615
|
-
return rebuildEntitlementLine(item, bundle, _this3.hooks);
|
|
1616
|
-
})));
|
|
1617
|
-
return;
|
|
1618
|
-
}
|
|
1619
1378
|
if (!mainProductArr || mainProductArr.length === 0) {
|
|
1620
1379
|
// 如果没有处理结果,返回默认商品
|
|
1621
1380
|
var getDefaultProduct = function getDefaultProduct() {
|
|
@@ -1678,7 +1437,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1678
1437
|
var hasGoodPass = processedBundleItems.some(function (item) {
|
|
1679
1438
|
var _item$discount_list;
|
|
1680
1439
|
return (_item$discount_list = item.discount_list) === null || _item$discount_list === void 0 ? void 0 : _item$discount_list.some(function (discount) {
|
|
1681
|
-
return
|
|
1440
|
+
return discount.type === 'good_pass' || discount.tag === 'good_pass';
|
|
1682
1441
|
});
|
|
1683
1442
|
});
|
|
1684
1443
|
if (hasGoodPass) {
|
|
@@ -2010,29 +1769,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2010
1769
|
|
|
2011
1770
|
// 获取此优惠券实际应用的商品详情
|
|
2012
1771
|
var appliedProductDetails = appliedDiscountProducts.get(discount.id) || [];
|
|
2013
|
-
if (isEntitlementPass(discount)) {
|
|
2014
|
-
var committed = discount.committedAppliedProductDetails || [];
|
|
2015
|
-
var details = [].concat(_toConsumableArray(committed), _toConsumableArray(appliedProductDetails));
|
|
2016
|
-
var _isAvailable = applicableProducts.length > 0;
|
|
2017
|
-
var timeReasons = entitlementTimeReasons.get(discount.id) || [];
|
|
2018
|
-
var timeReason = timeReasons.length ? timeReasons.every(Boolean) ? timeReasons[0] : undefined : getDiscountTimeUnavailableReason(discount, dayjs().format('YYYY-MM-DD HH:mm:ss'));
|
|
2019
|
-
var reasonCode = _isAvailable ? undefined : discount.reasonCode || timeReason || (entitlementHolderMismatch.has(discount.id) ? 'holder_not_matched' : 'product_not_applicable');
|
|
2020
|
-
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
2021
|
-
isAvailable: _isAvailable || committed.length > 0,
|
|
2022
|
-
isSelected: details.length > 0,
|
|
2023
|
-
isUsed: details.length > 0,
|
|
2024
|
-
reasonCode: reasonCode,
|
|
2025
|
-
reason: reasonCode === discount.reasonCode ? discount.reason : undefined,
|
|
2026
|
-
isManualSelect: options !== null && options !== void 0 && options.scan ? false : discount.isManualSelect,
|
|
2027
|
-
applicableProductIds: applicableProducts,
|
|
2028
|
-
applicableProductDetails: applicableProductDetails,
|
|
2029
|
-
appliedProductDetails: details,
|
|
2030
|
-
savedAmount: details.reduce(function (sum, detail) {
|
|
2031
|
-
var _detail$discount;
|
|
2032
|
-
return new Decimal(sum).plus(new Decimal(((_detail$discount = detail.discount) === null || _detail$discount === void 0 ? void 0 : _detail$discount.fixed_amount) || 0).mul(detail._num || 1)).toNumber();
|
|
2033
|
-
}, 0)
|
|
2034
|
-
});
|
|
2035
|
-
}
|
|
2036
1772
|
|
|
2037
1773
|
// 根据是否有适用商品决定isAvailable
|
|
2038
1774
|
var isAvailable = applicableProducts.length > 0;
|
|
@@ -2088,7 +1824,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2088
1824
|
});
|
|
2089
1825
|
console.log(processedProductList, 'processedProductList');
|
|
2090
1826
|
return {
|
|
2091
|
-
productList:
|
|
1827
|
+
productList: processedProductList,
|
|
2092
1828
|
discountList: [].concat(editModeDiscount, _toConsumableArray(updatedDiscountList))
|
|
2093
1829
|
};
|
|
2094
1830
|
}
|
|
@@ -2113,15 +1849,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2113
1849
|
var ruleType = usageRules.type;
|
|
2114
1850
|
// 套餐适用范围配置
|
|
2115
1851
|
var packageScope = usageRules === null || usageRules === void 0 ? void 0 : usageRules.package_scope;
|
|
2116
|
-
var
|
|
2117
|
-
|
|
2118
|
-
scopeType =
|
|
2119
|
-
|
|
2120
|
-
exclude_bundle_product_ids =
|
|
2121
|
-
|
|
2122
|
-
include_bundle_product_ids =
|
|
2123
|
-
|
|
2124
|
-
filter =
|
|
1852
|
+
var _ref9 = packageScope || {},
|
|
1853
|
+
_ref9$type = _ref9.type,
|
|
1854
|
+
scopeType = _ref9$type === void 0 ? 'product_all' : _ref9$type,
|
|
1855
|
+
_ref9$exclude_bundle_ = _ref9.exclude_bundle_product_ids,
|
|
1856
|
+
exclude_bundle_product_ids = _ref9$exclude_bundle_ === void 0 ? [] : _ref9$exclude_bundle_,
|
|
1857
|
+
_ref9$include_bundle_ = _ref9.include_bundle_product_ids,
|
|
1858
|
+
include_bundle_product_ids = _ref9$include_bundle_ === void 0 ? [] : _ref9$include_bundle_,
|
|
1859
|
+
_ref9$filter = _ref9.filter,
|
|
1860
|
+
filter = _ref9$filter === void 0 ? 0 : _ref9$filter;
|
|
2125
1861
|
var isMainProduct = flatItem.type === 'main'; // 单独购买
|
|
2126
1862
|
var isBundleItem = flatItem.type === 'bundle'; // 套餐中购买
|
|
2127
1863
|
|