tplus-pos
Version:
pos module
371 lines (321 loc) • 19.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SelfSingleFullGiftProcessBlock = 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 _CalcSinglePromotionProcessor = require('./CalcSinglePromotionProcessor');
var _UpdateRetailDetailProcessor = require('../UpdateRetailDetailProcessor');
var _DetailCodeProcessor = require('../../DetailCodeProcessor');
var _QuantityChangeProcessorBlock = require('../../quantity/QuantityChangeProcessorBlock');
var _REAlgorithmAdapter2 = require('../../../../commom/REAlgorithmAdapter');
var _REAlgorithmAdapter3 = _interopRequireDefault(_REAlgorithmAdapter2);
var _MergeDetailsProcessorBlock = require('../../MergeDetailsProcessorBlock');
var _SummaryProcessorBlock = require('../../summary/SummaryProcessorBlock');
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 SelfSingleFullGiftProcessBlock = exports.SelfSingleFullGiftProcessBlock = function () {
function SelfSingleFullGiftProcessBlock() {
(0, _classCallCheck3.default)(this, SelfSingleFullGiftProcessBlock);
}
(0, _createClass3.default)(SelfSingleFullGiftProcessBlock, null, [{
key: 'execute',
value: function execute(retailDto, detailDto, promotionList) {
var _this = this;
if (!promotionList || promotionList.length == 0) {
return;
}
//找到适合执行的促销方案
var matchList = _CalcSinglePromotionProcessor.CalcSinglePromotionProcessor.execute(retailDto, detailDto, promotionList);
if (!matchList || matchList.length == 0) //执行促销
{
return;
}
matchList = matchList.sort(function (a, b) {
return b.PromotionId - a.PromotionId;
});
matchList.forEach(function (promotionDto) {
var detailList = retailDto.RetailDetails.filter(function (it) {
return it.Idinventory == detailDto.Idinventory && it.Idunit == detailDto.Idunit && (!it.PromotionTypeStr || it.PromotionTypeStr.indexOf(_Enum.PromotionSign.SingleCashBackSign) == -1) && (!it.PromotionTypeStr || it.PromotionTypeStr.indexOf(_Enum.PromotionSign.SingleFullGiftSign) == -1) && Math.Multiply(it.DiscountRate, it.MemberDiscountRate) >= promotionDto.AboveDiscountEffect;
});
var totalQuantity = detailList.Sum("Quantity");
if (promotionDto.Details && promotionDto.Details[0].QuantityMeet > totalQuantity) {
return;
}
promotionDto.RetailDetails = detailList;
//计算赠品数量
_this.SelfRunGiftRetailDetail(promotionDto, retailDto, promotionDto.Details[0].GiftItem, detailDto);
});
_MergeDetailsProcessorBlock.MergeDetailsProcessorBlock.execute(retailDto);
_DetailCodeProcessor.DetailCodeProcessor.execute(retailDto);
//执行完,调用零售单汇总
_SummaryProcessorBlock.SummaryProcessorBlock.execute(retailDto);
}
//自动执行单品满赠
}, {
key: 'SelfRunGiftRetailDetail',
value: function SelfRunGiftRetailDetail(promotionDto, retailDto, totalGiftQuantity, detailDto) {
var giftRetailDetailList = this.GetGiftDetailList(promotionDto, retailDto, totalGiftQuantity);
if (giftRetailDetailList.length > 0 && promotionDto.RetailDetails.length > 0) //存在赠品,自动执行
{
this.ExecSelfFullGift(promotionDto, giftRetailDetailList, retailDto);
if (promotionDto.IsMultipleGift) //成倍赠送,再次执行
{
promotionDto.RetailDetails = retailDto.RetailDetails.filter(function (it) {
return it.Idinventory == detailDto.Idinventory && it.Idunit == detailDto.Idunit && (!it.PromotionTypeStr || it.PromotionTypeStr.indexOf(_Enum.PromotionSign.SingleCashBackSign) == -1) && (!it.PromotionTypeStr || it.PromotionTypeStr.indexOf(_Enum.PromotionSign.SingleFullGiftSign) == -1) && Math.Multiply(it.DiscountRate, it.MemberDiscountRate) >= promotionDto.AboveDiscountEffect;
});
if (promotionDto.RetailDetails.length == 0) {
return;
}
var totalQuantity = promotionDto.RetailDetails.Sum("Quantity");
if (promotionDto.Details && promotionDto.Details[0].QuantityMeet > totalQuantity) {
return;
}
totalGiftQuantity = Math.Add(totalGiftQuantity, promotionDto.Details[0].GiftItem);
this.SelfRunGiftRetailDetail(promotionDto, retailDto, totalGiftQuantity, detailDto);
}
}
}
//执行满赠促销
}, {
key: 'ExecSelfFullGift',
value: function ExecSelfFullGift(promotionDto, giftRetailDetailList, retailDto) {
var _this2 = this;
if (promotionDto.IsMultipleGift) //成倍赠送 需要拆行
{
var totalQuantity = promotionDto.RetailDetails.Sum("Quantity");
//处理成倍赠送的满足条件的明细行拆分行
this.SplitRetailDetails(promotionDto, Math.Minus(totalQuantity, promotionDto.Details[0].QuantityMeet), promotionDto.RetailDetails, retailDto, null);
}
//转换赠品
giftRetailDetailList.forEach(function (item) {
var giftDto = retailDto.RetailDetails.find(function (it) {
return _this2.getDetailKey(it) == _this2.getDetailKey(item);
});
giftDto.TaxPrice = item.TaxPrice;
giftDto.IsPresent = true;
if (giftDto.TaxPrice > 0) {
giftDto.IsPresent = false;
}
if (!giftDto.RetailPrice || giftDto.RetailPrice <= 0) {
giftDto.RetailPrice = giftDto.TaxPrice;
giftDto.MemberPrice = giftDto.TaxPrice;
}
giftDto.TaxAmount = Math.Multiply(giftDto.TaxPrice, giftDto.Quantity);
giftDto.RetailAmount = Math.Multiply(giftDto.RetailPrice, giftDto.Quantity);
giftDto.DetailDiscountAmount = Math.Minus(giftDto.RetailAmount, giftDto.TaxAmount);
giftDto.IsDel = false;
giftDto.IsUseIntegralAndCash = false;
giftDto.IsUseStorage = false;
giftDto.IsMemberIntegralUsedPromotion = true;
JSON.setCellValue(giftDto, "isPromotionPresent", 'true');
JSON.setCellValue(giftDto, "promotionguid", promotionDto.ID);
JSON.setCellValue(giftDto, "maxgiftquantity", JSON.getCellValue(item, "maxgiftquantity"));
_UpdateRetailDetailProcessor.UpdateRetailDetailProcessor.execute(giftDto, promotionDto, false, giftDto.Code);
//数量改变事件
_QuantityChangeProcessorBlock.QuantityChangeProcessorBlock.execute(retailDto, giftDto, giftDto.Quantity, { isNotExecRunSingleDiscountProcessBlock: true });
var _REAlgorithmAdapter = new _REAlgorithmAdapter3.default(retailDto);
_REAlgorithmAdapter.DiscountAmountChange(giftDto);
});
//处理编码
_DetailCodeProcessor.DetailCodeProcessor.execute(retailDto);
//更新影响明细行
promotionDto.RetailDetails.forEach(function (item) {
var detailDto = retailDto.RetailDetails.find(function (it) {
return it.Code == item.Code;
});
if (detailDto) {
_UpdateRetailDetailProcessor.UpdateRetailDetailProcessor.execute(detailDto, promotionDto, false, retailDto.Code);
}
});
}
//获取赠品信息
}, {
key: 'GetGiftDetailList',
value: function GetGiftDetailList(promotionDto, retailDto, totalGiftQuantity) {
var _this3 = this;
var giftRetailDetailList = retailDto.RetailDetails.filter(function (c) {
return c.PromotionDetails && JSON.getCellValue(c, "promotionguid") == promotionDto.ID && JSON.getCellValue(c, "isPromotionPresent");
});
promotionDto.PromotionGifts.forEach(function (detail) {
var giftDetailList = retailDto.RetailDetails.filter(function (c) {
return c.Idinventory == detail.Idinventory && c.Idunit == detail.Idunit && !c.IsPresent && !c.PromotionTypeStr;
});
if (!giftDetailList || giftDetailList.length == 0) {
return;
}
var currentGiftQuantity = _this3.GetCurrentGiftQuantity(totalGiftQuantity, promotionDto, retailDto, detail);
var userdGiftQuantity = giftRetailDetailList.Sum("Quantity");
currentGiftQuantity = totalGiftQuantity - userdGiftQuantity > currentGiftQuantity ? currentGiftQuantity : totalGiftQuantity - userdGiftQuantity;
if (currentGiftQuantity <= 0) {
return;
}
//优先分出非满足条件的赠品数据
var pureGiftList = giftDetailList.filter(function (c) {
return !promotionDto.RetailDetails.some(function (k) {
return c.Idinventory == k.Idinventory && c.Idunit == k.Idunit;
});
});
var retailDetailGiftList = giftDetailList.filter(function (c) {
return promotionDto.RetailDetails.some(function (k) {
return c.Idinventory == k.Idinventory && c.Idunit == k.Idunit;
});
}).sort(function (a, b) {
return a.TaxPrice - b.TaxPrice;
});
var giftQuantity = pureGiftList.Sum("Quantity");
pureGiftList = pureGiftList.sort(function (a, b) {
return a.TaxPrice - b.TaxPrice;
});
if (giftQuantity > currentGiftQuantity) //需要将多的赠品进行拆行
{
var startQuantity = 0;
pureGiftList.forEach(function (item) {
startQuantity = Math.Add(startQuantity, item.Quantity);
if (startQuantity <= currentGiftQuantity) {
item.TaxPrice = detail.TaxPrice;
giftRetailDetailList.push(item);
return;
}
var quantity = Math.Minus(currentGiftQuantity, Math.Minus(startQuantity, item.Quantity));
if (quantity > 0) {
var retailDetail = (0, _cloneDeep3.default)((0, _mobx.toJS)(item));
item.Quantity = quantity;
item.TaxPrice = detail.TaxPrice;
giftRetailDetailList.push(item);
retailDetail.Quantity = Math.Minus(retailDetail.Quantity, item.Quantity);
//数量改变事件
_QuantityChangeProcessorBlock.QuantityChangeProcessorBlock.execute(retailDto, item, item.Quantity, { isNotExecRunSingleDiscountProcessBlock: true });
_QuantityChangeProcessorBlock.QuantityChangeProcessorBlock.execute(retailDto, retailDetail, retailDetail.Quantity, { isNotExecRunSingleDiscountProcessBlock: true });
var lastIndex = retailDto.RetailDetails.lastIndexOf(item);
retailDto.RetailDetails.splice(lastIndex + 1, 0, retailDetail);
//retailDto.RetailDetails.push(retailDetail);
}
});
return giftRetailDetailList;
}
var remainQuantity = currentGiftQuantity - giftQuantity;
//赠品和满足条件明细行重合的情况
if (remainQuantity > 0 && retailDetailGiftList.length > 0) {
//满足条件明细行和赠品明细行相同的赠品数量
var remainGiftQuantity = 0;
var quantityMeet = promotionDto.Details[0].QuantityMeet;
var totalQuantity = promotionDto.RetailDetails.Sum("Quantity");
if (totalQuantity > quantityMeet) {
remainGiftQuantity = remainQuantity > Math.Minus(totalQuantity, quantityMeet) ? Math.Minus(totalQuantity, quantityMeet) : remainQuantity;
}
if (remainGiftQuantity > 0) {
//处理赠品的拆分行
_this3.SplitRetailDetails(promotionDto, remainGiftQuantity, retailDetailGiftList, retailDto, pureGiftList);
}
}
pureGiftList.forEach(function (item) {
JSON.setCellValue(item, "maxgiftquantity", currentGiftQuantity);
item.TaxPrice = detail.TaxPrice;
giftRetailDetailList.push(item);
});
});
return giftRetailDetailList;
}
}, {
key: 'GetCurrentGiftQuantity',
value: function GetCurrentGiftQuantity(totalGiftQuantity, promotionDto, retailDto, giftDetail) {
var usedGiftRetailDetails = retailDto.RetailDetails.filter(function (c) {
return c.PromotionDetails && JSON.getCellValue(c, "promotionguid") == promotionDto.ID && JSON.getCellValue(c, "isPromotionPresent");
});
var usedTotalQuantity = usedGiftRetailDetails.Sum("Quantity");
var limitedTotalQuantity = Math.Minus(totalGiftQuantity, usedTotalQuantity);
var limitedCurrentQuantity = 0;
if (limitedTotalQuantity >= 0) {
var LimitedGiftQuantity = JSON.getCellValue(giftDetail, "LimitedGiftQuantity");
if (LimitedGiftQuantity && LimitedGiftQuantity > 0) //有赠品限制
{
var usedCurrentQuantity = usedGiftRetailDetails.filter(function (c) {
return c.Idinventory == giftDetail.Idinventory && c.Idunit == giftDetail.Idunit;
}).Sum("Quantity");
limitedCurrentQuantity = Math.Minus(LimitedGiftQuantity, usedCurrentQuantity);
limitedCurrentQuantity = limitedTotalQuantity > limitedCurrentQuantity ? limitedCurrentQuantity : limitedTotalQuantity;
} else {
limitedCurrentQuantity = limitedTotalQuantity;
}
}
return limitedCurrentQuantity;
}
}, {
key: 'SplitRetailDetails',
value: function SplitRetailDetails(promotionDto, remainQuantity, retailDetailGiftList, retailDto, pureGiftList) {
retailDetailGiftList = retailDetailGiftList.sort(function (a, b) {
return a.TaxPrice - b.TaxPrice;
});
retailDetailGiftList.forEach(function (item) {
if (remainQuantity <= 0) {
return;
}
var retailDetail = (0, _cloneDeep3.default)((0, _mobx.toJS)(item));
if (retailDetail.Quantity > remainQuantity) {
var findIndex = promotionDto.RetailDetails.findIndex(function (it) {
return it.Code == item.Code;
});
promotionDto.RetailDetails.splice(findIndex, 1);
item.Quantity = Math.Minus(item.Quantity, remainQuantity);
retailDetail.Quantity = remainQuantity;
retailDetail.Code = "999";
promotionDto.RetailDetails.push(item);
//数量改变事件
_QuantityChangeProcessorBlock.QuantityChangeProcessorBlock.execute(retailDto, item, item.Quantity, { isNotExecRunSingleDiscountProcessBlock: true });
_QuantityChangeProcessorBlock.QuantityChangeProcessorBlock.execute(retailDto, retailDetail, retailDetail.Quantity, { isNotExecRunSingleDiscountProcessBlock: true });
var lastIndex = retailDto.RetailDetails.lastIndexOf(item);
retailDto.RetailDetails.splice(lastIndex + 1, 0, retailDetail);
}
if (pureGiftList != null) {
pureGiftList.push(retailDetail);
}
remainQuantity = Math.Minus(remainQuantity, retailDetail.Quantity);
});
}
/**
* 获取当前列的key
*
* @param {*} detail
* @returns
*/
}, {
key: 'getDetailKey',
value: function getDetailKey(detail) {
var returnKey = "";
var keyFields = "FreeItem0,FreeItem1,FreeItem2,FreeItem3,FreeItem4,FreeItem5,FreeItem6,FreeItem7,FreeItem8,FreeItem9,Idinventory,Idunit,Idunit2,Batch,ProductionDate,ExpiryDate,Quantity,PromotionTypeStr,SerialNumber";
var keyArrays = keyFields.split(",");
for (var index = 0; index < keyArrays.length; index++) {
var value = "";
if (JSON.getCellValue(detail, keyArrays[index])) {
value = JSON.getCellValue(detail, keyArrays[index]);
}
if (value && (keyArrays[index] == 'ProductionDate' || keyArrays[index] == 'ExpiryDate')) {
var date = value;
if (typeof value == "string") {
date = new Date(value);
}
value = date.toLocaleDateString();
}
returnKey = returnKey + "|" + keyArrays[index] + "=" + value;
}
return returnKey;
}
}]);
return SelfSingleFullGiftProcessBlock;
}();
/**
*批量执行单品满赠相关处理
*
* @export
* @class SelfSingleFullGiftProcessBlock
*/
//# sourceMappingURL=SelfSingleFullGiftProcessBlock.js.map