UNPKG

tplus-pos

Version:

pos module

97 lines (80 loc) 3.88 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.CalcSinglePromotionProcessor = undefined; var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); require('../../../../commom/Challenger'); var _Enum = require('../../../../commom/Enum'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** *计算单品促销的促销方案 * * @export * @class CalcSinglePromotionProcessor */ var CalcSinglePromotionProcessor = exports.CalcSinglePromotionProcessor = function () { function CalcSinglePromotionProcessor() { (0, _classCallCheck3.default)(this, CalcSinglePromotionProcessor); } (0, _createClass3.default)(CalcSinglePromotionProcessor, null, [{ key: 'execute', value: function execute(retailDto, detailDto, promotionList) { var _this = this; var detailList = retailDto.RetailDetails.filter(function (it) { return it.Idinventory == detailDto.Idinventory && it.Idunit == detailDto.Idunit && (!it.PromotionTypeStr || it.PromotionTypeStr && it.PromotionTypeStr.indexOf(_Enum.PromotionSign.SingleCashBackSign) == -1 && it.PromotionTypeStr.indexOf(_Enum.PromotionSign.SingleFullGiftSign) == -1); }); if (detailList.length == 0) { return; } var matchList = promotionList.filter(function (it) { return _this.IsSingleQuantityMatch(it, detailList); }); if (!matchList || matchList.length == 0) { return null; } matchList.forEach(function (item) { item.RetailDetails = detailList.filter(function (it) { return it.DiscountRate * it.MemberDiscountRate >= item.AboveDiscountEffect; }); }); return matchList; } //数量是否匹配 }, { key: 'IsSingleQuantityMatch', value: function IsSingleQuantityMatch(promotionDto, detailList) { var effectList = detailList.filter(function (it) { return it.DiscountRate * it.MemberDiscountRate >= promotionDto.AboveDiscountEffect; }); var totalQuantity = effectList.Sum("Quantity"); switch (promotionDto.PromotionObject) { case _Enum.PromotionObject.DR_PromotionObject_00: //存货 return promotionDto.Details.some(function (it) { return it.Idinventory == detailList[0].Idinventory && it.Idunit == detailList[0].Idunit && it.QuantityMeet <= totalQuantity; }); case _Enum.PromotionObject.DR_PromotionObject_01: //分类 return promotionDto.Details.some(function (detail) { return effectList.filter(function (it) { return it.Inventory.InventoryClass.InId.indexOf(detail.Inid) == 0; }).Sum("Quantity") >= detail.QuantityMeet; }); case _Enum.PromotionObject.DR_PromotionObject_02: //品牌 return promotionDto.Details.some(function (detail) { return effectList.filter(function (it) { return it.Inventory.ProductInfo.Id == detail.CorpBrand.Id; }).Sum("Quantity") >= detail.QuantityMeet; }); } return false; } }]); return CalcSinglePromotionProcessor; }(); //# sourceMappingURL=CalcSinglePromotionProcessor.js.map