private void btnCalculate_Click(object sender, RoutedEventArgs e) { if (ValidationManager.Validate(this.LayoutRoot)) { RefundVM vm = this.DataContext as RefundVM; refundFacade.Calculate(vm, (obj, args) => { vm.SOCashPointRate = args.Result.SOCashPointRate; vm.DeductPointFromAccount = args.Result.DeductPointFromAccount; vm.DeductPointFromCurrentCash = args.Result.DeductPointFromCurrentCash; vm.OrgPointAmt = args.Result.OrgPointAmt; vm.PointAmt = args.Result.PointAmt; vm.OrgCashAmt = args.Result.OrgCashAmt; vm.CashAmt = args.Result.CashAmt; vm.OrgGiftCardAmt = args.Result.OrgGiftCardAmt; vm.GiftCardAmt = args.Result.GiftCardAmt; vm.PriceprotectPoint = args.Result.PriceprotectPoint; //刷新界面的初算退款金额 vm.RefundItems.ForEach(item => { RefundItemInfo tmpInfo = args.Result.RefundItems.FirstOrDefault(x => x.RegisterSysNo == item.RegisterSysNo); if (tmpInfo != null) { item.RefundCash = tmpInfo.RefundCash; } }); Window.Alert(ResRefundMaintain.Info_OperateSuccessfully); }); } }
public void UpdateItemForRefund(RefundItemInfo entity) { DataCommand command = DataCommandManager.GetDataCommand("UpdateRefundItemForRefund"); command.SetParameterValue <RefundItemInfo>(entity); command.ExecuteNonQuery(); }
public RefundItemInfo InsertItem(RefundItemInfo entity) { DataCommand command = DataCommandManager.GetDataCommand("InsertRefundItem"); command.SetParameterValue <RefundItemInfo>(entity); object result = command.ExecuteScalar(); entity.SysNo = Convert.ToInt32(result); return(entity); }
/// <summary> /// 已发生的,退款单总的金额。 /// </summary> /// <param name="entity"></param> /// <returns></returns> public virtual RefundItemInfo GetRefundTotalAmount(RefundBalanceInfo entity) { RefundItemInfo result = null; DataCommand command = DataCommandManager.GetDataCommand("GetRefundTotalAmount"); command.SetParameterValue("@ProductSysNo", entity.ProductSysNo); command.SetParameterValue("@RefundSysNo", entity.OriginalRefundSysNo); command.SetParameterValue("@SoSysNo", entity.OriginalSOSysNo); result = command.ExecuteEntity <RefundItemInfo>(); return(result); }
/// <summary> /// 退款前的业务检查 /// </summary> /// <param name="refundInfo"></param> private void PreCheckForRefund(RefundBalanceInfo refundBalanceInfo, decimal totalRoBoBalanceAmt, decimal availShipPrice, out decimal ROAmt) { refundBalanceInfo.PointAmt = refundBalanceInfo.PointAmt.HasValue ? refundBalanceInfo.PointAmt.Value : 0; refundBalanceInfo.GiftCardAmt = refundBalanceInfo.GiftCardAmt.HasValue ? refundBalanceInfo.GiftCardAmt.Value : 0M; decimal point = refundBalanceInfo.PointAmt.Value; ROAmt = refundBalanceInfo.CashAmt.Value + refundBalanceInfo.GiftCardAmt.Value + (point / pointExchangeRate); if (refundBalanceInfo.ProductSysNo != 0) // 正常商品调整 { RefundItemInfo refundItem = refundBalanceDA.GetRefundTotalAmount(refundBalanceInfo); decimal tempRefunded = (refundItem.RefundPrice ?? 0M) + ROAmt + totalRoBoBalanceAmt; decimal productValue = refundItem.ProductValue ?? 0; if (productValue < tempRefunded) { throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "RefundTooMuch")); } if (tempRefunded < 0) { throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "NotGreaterThanRefundedAmt")); } } else // 运费补偿及其他 { if (availShipPrice < ROAmt) { throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "OverfullShipFee")); } //if (ROAmt < 0) //{ // throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "NotGreaterThanRefundedAmt")); //} if (refundBalanceInfo.PointAmt > 0) { throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "CannotUsePointsForRefundShipFee")); } } }
/// <summary> /// 计算退现金、初算退礼品卡、退现金、退礼品卡 /// </summary> /// <param name="entity"></param> /// <param name="soBaseInfo"></param> private void Calc(RefundBalanceInfo entity, SOBaseInfo soBaseInfo) { decimal availShipPrice, cashRemoveGiftCard, availGiftCard, totalRoBoBalanceAmt; int availPointAmt; CalculateAvailRefundAmt(entity, soBaseInfo, out availShipPrice, out cashRemoveGiftCard, out availGiftCard, out availPointAmt, out totalRoBoBalanceAmt); soBaseInfo.GiftCardPay = soBaseInfo.GiftCardPay ?? 0M; #region 根据可用退现金,修正调整单金额的现金、礼品卡、积分部分 if (entity.CashAmt > 0) { if (cashRemoveGiftCard >= entity.CashAmt)//有现金可作调整单 { entity.GiftCardAmt = 0; entity.PointAmt = 0; } else if (cashRemoveGiftCard == 0)//可退现金为0 { if (availGiftCard > 0) { if (entity.CashAmt <= availGiftCard)//礼品卡可用 { entity.GiftCardAmt = entity.CashAmt; entity.PointAmt = 0; } else//退完礼品卡还有金额转为积分 { entity.GiftCardAmt = availGiftCard; entity.PointAmt = Convert.ToInt32(Decimal.Round((entity.CashAmt.Value - availGiftCard) * pointExchangeRate, 0)); if (entity.PointAmt > availPointAmt) { entity.PointAmt = availPointAmt; } if (availGiftCard == 0 && availPointAmt == 0) { throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "RefundTooMuch")); } if (availGiftCard == 0 && entity.CashAmt.Value < 0.1m) { throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "OnlyAdjustPoints")); } } } else { entity.PointAmt = Convert.ToInt32(Decimal.Round(entity.CashAmt.Value * pointExchangeRate, 0)); } entity.CashAmt = 0; } else//有部分现金可退,剩余部分使用礼品卡 { entity.GiftCardAmt = entity.CashAmt - cashRemoveGiftCard; if (entity.GiftCardAmt > availGiftCard) { entity.PointAmt = Convert.ToInt32(Decimal.Round((entity.GiftCardAmt.Value - availGiftCard) * pointExchangeRate, 0)); if (entity.PointAmt > availPointAmt) { entity.PointAmt = availPointAmt; } entity.GiftCardAmt = availGiftCard; } else { entity.PointAmt = 0; } entity.CashAmt = cashRemoveGiftCard; } } else { entity.GiftCardAmt = 0; entity.PointAmt = 0; } #endregion 根据可用退现金,修正调整单金额的现金、礼品卡、积分部分 if (entity.ProductSysNo != 0) //商品调整 { #region SOItem RefundItemInfo refundItem = refundBalanceDA.GetRefundTotalAmount(entity); decimal tempRefunded = (refundItem.RefundPrice ?? 0M) + entity.CashAmt.Value + totalRoBoBalanceAmt; decimal productValue = refundItem.ProductValue ?? 0; if (productValue < tempRefunded) { throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "RefundTooMuch")); } if (tempRefunded < 0) { throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "NotGreaterThanRefundedAmt")); } #region 现金、礼品卡、积分金额划分 decimal refundAmt = entity.CashAmt.Value + entity.GiftCardAmt.Value; if (refundAmt > 0 && entity.PointAmt == 0) { #region 计算 现金与积分比率 decimal originalSOCashPointRate = 0; //不四舍五入的比率:现金部分与总额的比例 decimal pointOnly = 0; // 仅积分支付部分对应的价值 decimal cashOnly = 0; // 仅现金支付部分对应的价值 decimal totalPromotionDiscount = 0; //优惠券 List <SOItemInfo> soItems = ExternalDomainBroker.GetSOItemList(entity.OriginalSOSysNo.Value); soItems.ForEach(item => { if (item.PayType == ProductPayType.PointOnly) { pointOnly += item.Price.Value * item.Quantity.Value + item.PromotionAmount.Value; } else if (item.PayType == ProductPayType.MoneyOnly) { cashOnly += item.Price.Value * item.Quantity.Value + item.PromotionAmount.Value; } totalPromotionDiscount += item.PromotionAmount.Value * item.Quantity.Value; }); //表示只有仅积分或仅现金部分,没有均支持 if ((soBaseInfo.SOAmount + soBaseInfo.PromotionAmount) - (totalPromotionDiscount + pointOnly + cashOnly) == 0M) { //仅现金 if (pointOnly == 0 && cashOnly > 0) { originalSOCashPointRate = 1; } else //仅积分 { originalSOCashPointRate = 0; } } else if (soBaseInfo.CashPay - cashOnly == 0) { originalSOCashPointRate = 1; } else if (soBaseInfo.PointPay - pointOnly == 0) { originalSOCashPointRate = 0; } else { //表示均支持的现金部分与均支持的总额的比例 originalSOCashPointRate = (soBaseInfo.CashPay + soBaseInfo.PromotionAmount.Value - cashOnly) / (soBaseInfo.SOAmount.Value + soBaseInfo.PromotionAmount.Value - (totalPromotionDiscount + pointOnly + cashOnly)); } #endregion 计算 现金与积分比率 //根据单件退款额度,调整比率精度 int decimals = Decimal.Round(refundAmt, 0).ToString().Length + 2; //实际计算精度 decimal SOCashPointRate = Decimal.Round(originalSOCashPointRate, decimals); int refundPoint = Convert.ToInt32(Decimal.Round(refundAmt * (1 - SOCashPointRate) * pointExchangeRate, 0)); decimal refundCash = refundAmt - (Decimal.Round(refundAmt * (1 - SOCashPointRate), 2)); //积分补偿 decimal pointRedeem = -Decimal.Round((Decimal.Round(refundAmt * (1 - SOCashPointRate) * pointExchangeRate, 0) - (refundAmt * (1 - SOCashPointRate) * pointExchangeRate)) / pointExchangeRate, 2); refundCash += pointRedeem; #region 分配现金、礼品卡 if (refundPoint < 0) { refundPoint = 0; } if (entity.CashAmt > 0) { if (entity.GiftCardAmt == 0) { entity.CashAmt = refundCash; } else { if (entity.CashAmt > refundCash) { entity.GiftCardAmt = entity.CashAmt - refundCash; } else { entity.GiftCardAmt = refundCash - entity.CashAmt; } } } else { entity.GiftCardAmt = refundCash; } entity.PointAmt = refundPoint; if (entity.PointAmt > availPointAmt) { entity.PointAmt = availPointAmt; } #endregion 分配现金、礼品卡 #endregion 现金、礼品卡、积分金额划分 } #endregion SOItem } else //运费补偿及其他 { #region 运费补偿及其他 if (availShipPrice < entity.CashAmt.Value) { throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "OverfullShipFee")); } //if (entity.CashAmt.Value < 0) //{ // throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "NotGreaterThanRefundedAmt")); //} if (entity.PointAmt > 0) { throw new BizException(ResouceManager.GetMessageString("RMA.RefundBalance", "CannotUsePointsForRefundShipFee")); } #endregion 运费补偿及其他 } }