UNPKG

tplus-pos

Version:

pos module

184 lines (156 loc) 7.49 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.QuantityMeetEnableProcessor = undefined; var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _Enum = require('../../../../commom/Enum'); var _cloneDeep2 = require('lodash/cloneDeep'); var _cloneDeep3 = _interopRequireDefault(_cloneDeep2); var _mobx = require('mobx'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var QuantityMeetEnableProcessor = exports.QuantityMeetEnableProcessor = function () { function QuantityMeetEnableProcessor() { (0, _classCallCheck3.default)(this, QuantityMeetEnableProcessor); } (0, _createClass3.default)(QuantityMeetEnableProcessor, null, [{ key: 'execute', value: function execute(promotionList) { var _this = this; promotionList.forEach(function (item) { //查询此促销对应零售明细行金额总和 if (item.TrussCondition == _Enum.TrussCondition.DR_TrussCondition_00) //控制组合数量 { _this.CalcEnableForQuantityControl(item); } else //不控制组合数量 { _this.CalcEnableForNoQuantityControl(item); } }); } //计算控制组合数量的促销是否可用 }, { key: 'CalcEnableForQuantityControl', value: function CalcEnableForQuantityControl(promotionDto) { var _this2 = this; //如果控制组合数量,则需要判断每一个明细都要满足 promotionDto.Details.forEach(function (info) { var totalQuantity = _this2.getTotalQuantityForControl(promotionDto, info); if (info.TrussQuantity > totalQuantity) { promotionDto.IsEnable = false; return false; } }); } //获取总数量 }, { key: 'getTotalQuantityForControl', value: function getTotalQuantityForControl(promotionDto, detail) { var totalQuantity = 0; switch (promotionDto.PromotionObject) { case _Enum.PromotionObject.DR_PromotionObject_00: // 存货类型 promotionDto.RetailDetails.filter(function (it) { return it.Idinventory == detail.Idinventory && it.Idunit == detail.Idunit; }).forEach(function (item) { totalQuantity = Math.Add(totalQuantity, item.Quantity); }); break; case _Enum.PromotionObject.DR_PromotionObject_01: // 分类 promotionDto.RetailDetails.filter(function (it) { return it.Inventory.InventoryClass.InId.indexOf(detail.Inid) == 0; }).forEach(function (item) { totalQuantity = Math.Add(totalQuantity, item.Quantity); }); break; case _Enum.PromotionObject.DR_PromotionObject_02: // 品牌 promotionDto.RetailDetails.filter(function (it) { return it.Inventory.ProductInfo.Id == detail.CorpBrand.Id; }).forEach(function (item) { totalQuantity = Math.Add(totalQuantity, item.Quantity); }); break; } return totalQuantity; } //计算不控制组合数量的促销是否可用 }, { key: 'CalcEnableForNoQuantityControl', value: function CalcEnableForNoQuantityControl(promotionDto) { var totalQuantity = 0; promotionDto.RetailDetails.forEach(function (detail) { totalQuantity = Math.Add(totalQuantity, detail.Quantity); }); var meetQuantity = 0; var subsDetails = []; switch (promotionDto.PromotionType) { //单品满赠 case _Enum.PromotionType.DR_PromotionType_05: if (promotionDto.Details[0].QuantityMeet > totalQuantity) { promotionDto.IsEnable = false; } break; //组合满返 case _Enum.PromotionType.DR_PromotionType_03: // count = promotionDto.SubsDetails.length; subsDetails = (0, _cloneDeep3.default)((0, _mobx.toJS)(promotionDto.SubsDetails)); promotionDto.SubsDetails = []; subsDetails.forEach(function (detail) { meetQuantity = detail.QuantityMeet; if (meetQuantity <= totalQuantity) { //item.SubsDetails.splice(index, 1); promotionDto.SubsDetails.push(detail); } }); // for (let index = 0; index < count; index++) { // meetQuantity = promotionDto.SubsDetails[index].QuantityMeet; // if (meetQuantity > totalQuantity) { // promotionDto.SubsDetails.splice(index, 1); // } // } if (promotionDto.SubsDetails.length == 0) { promotionDto.IsEnable = false; } break; case _Enum.PromotionType.DR_PromotionType_07: //组合满赠 meetQuantity = promotionDto.QuantityMeet; if (meetQuantity > totalQuantity) { promotionDto.IsEnable = false; } break; case _Enum.PromotionType.DR_PromotionType_02: //整单返现 // count = promotionDto.Details.length; subsDetails = (0, _cloneDeep3.default)((0, _mobx.toJS)(promotionDto.SubsDetails)); promotionDto.SubsDetails = []; subsDetails.forEach(function (detail) { meetQuantity = detail.QuantityMeet; if (meetQuantity <= totalQuantity) { //item.SubsDetails.splice(index, 1); promotionDto.SubsDetails.push(detail); } }); // for (let index = 0; index < count; index++) { // meetQuantity = promotionDto.Details[index].QuantityMeet; // if (meetQuantity > totalQuantity) { // promotionDto.Details.splice(index, 1); // } // } if (promotionDto.Details.length == 0) { promotionDto.IsEnable = false; } break; } } }]); return QuantityMeetEnableProcessor; }(); /** * 计算可用的数量满足的促销方式 */ //# sourceMappingURL=QuantityMeetEnableProcessor.js.map