///// 计算积分返回 /// <summary> /// 计算积分返回 /// </summary> /// <param name="soInfo">订单信息</param> /// <param name="pointPay">已支付的积分款</param> /// <returns>应退积分</returns> private int GetReturnPoint(SOInfo soInfo, decimal pointPay) { pointPay = pointPay * ExternalDomainBroker.GetPointToMoneyRatio(); int usedPoint = Convert.ToInt32(pointPay); return(soInfo.BaseInfo.PointPay.Value + usedPoint);//用点数支付的是负值,所以这块用+ }
/// <summary> /// 分摊子订单 /// </summary> /// <param name="subSOList"></param> private void CalculateSubSO(List <SOInfo> subSOList) { // 按金额升序排列,保证分摊的最后订单的金额最大,减少分摊误差。 subSOList.Sort((o1, o2) => { return(o1.BaseInfo.SOAmount.Value.CompareTo(o2.BaseInfo.SOAmount.Value)); }); decimal masterSOTotalPrice = CurrentSO.BaseInfo.PromotionAmount.Value; //计算金额基数 decimal masterSOTotalWeight = 0; //计算重量基数 CurrentSO.Items.ForEach(item => { masterSOTotalPrice += item.Quantity.Value * item.OriginalPrice.Value; masterSOTotalWeight += item.Quantity.Value * item.Weight.Value; }); #region 分摊主的费用到子订单 int t_PointPay = CurrentSO.BaseInfo.PointPay.Value; decimal t_ShipPrice = CurrentSO.BaseInfo.ShipPrice.Value; decimal t_PayPrice = CurrentSO.BaseInfo.PayPrice.Value; decimal t_PremiumAmt = CurrentSO.BaseInfo.PremiumAmount.Value; decimal t_PrepayAmt = CurrentSO.BaseInfo.PrepayAmount.Value; decimal t_PromotionValue = CurrentSO.BaseInfo.CouponAmount.Value; decimal t_GiftCardPay = CurrentSO.BaseInfo.GiftCardPay.Value; decimal?t_OriginShipPrice = CurrentSO.ShippingInfo.OriginShipPrice ?? 0; decimal?t_PackageFee = CurrentSO.ShippingInfo.PackageFee ?? 0; decimal?t_RegisteredFee = CurrentSO.ShippingInfo.RegisteredFee ?? 0; decimal?t_ShippingFee = CurrentSO.ShippingInfo.ShippingFee ?? 0; decimal?t_Weight3PL = CurrentSO.ShippingInfo.Weight3PL ?? 0; decimal?t_WeightSO = CurrentSO.ShippingInfo.Weight ?? 0; int subSOIndex = 0; foreach (SOInfo soInfo in subSOList) { bool isLastSubSO = ++subSOIndex == subSOList.Count; decimal subSOWeight = 0; //订单总重量 decimal subSOTotalPrice = 0; //订单去优惠券折扣后的总价 soInfo.BaseInfo.PromotionAmount = 0; soInfo.BaseInfo.GainPoint = 0; soInfo.BaseInfo.CouponAmount = 0; soInfo.Items.ForEach(item => { item.SOSysNo = soInfo.SysNo; soInfo.BaseInfo.PromotionAmount += item.PromotionAmount.Value; //计算销售规则拆扣 soInfo.BaseInfo.GainPoint += item.GainPoint; //计算获得的积分 soInfo.BaseInfo.CouponAmount += item.CouponAmount; //计算优惠券折扣 subSOWeight += item.Weight.Value * item.Quantity.Value; //价格引用Price,而不是OriginalPrice,因为总价中不包含优惠券折扣。 subSOTotalPrice += item.Quantity.Value * item.Price.Value + item.PromotionAmount.Value; }); soInfo.ShippingInfo.Weight = subSOWeight; #region 分摊订单费用 decimal weightRate = subSOWeight / (masterSOTotalWeight <= 0 ? 1 : masterSOTotalWeight); //重量分摊比例 decimal priceRate = subSOTotalPrice / (masterSOTotalPrice <= 0 ? 1 : masterSOTotalPrice); //金额分摊比例 if (!isLastSubSO) // 不是最后一个子订单 { //根据重量来分摊运费 soInfo.BaseInfo.ShipPrice = UtilityHelper.ToMoney(CurrentSO.BaseInfo.ShipPrice.Value * weightRate); t_ShipPrice -= soInfo.BaseInfo.ShipPrice.Value; //根据价格来分摊积分支付 soInfo.BaseInfo.PointPay = (int)(Math.Round(CurrentSO.BaseInfo.PointPay.Value * priceRate)); t_PointPay -= soInfo.BaseInfo.PointPay.Value; soInfo.BaseInfo.PointPayAmount = Convert.ToDecimal(soInfo.BaseInfo.PointPay) / ExternalDomainBroker.GetPointToMoneyRatio(); //计算积分支付 //根据价格来分摊手续费 soInfo.BaseInfo.PayPrice = UtilityHelper.ToMoney(CurrentSO.BaseInfo.PayPrice.Value * priceRate); t_PayPrice -= soInfo.BaseInfo.PayPrice.Value; //根据价格来分摊积保价费 soInfo.BaseInfo.PremiumAmount = UtilityHelper.ToMoney(CurrentSO.BaseInfo.PremiumAmount.Value * priceRate); t_PremiumAmt -= soInfo.BaseInfo.PremiumAmount.Value; //余额支付的分摊比例 decimal priceRate_Prepay = soInfo.BaseInfo.SOTotalAmount / (CurrentSO.BaseInfo.SOTotalAmount <= 0 ? 1 : CurrentSO.BaseInfo.SOTotalAmount); //根据商品总价分摊余额支付 soInfo.BaseInfo.PrepayAmount = UtilityHelper.ToMoney(CurrentSO.BaseInfo.PrepayAmount.Value * priceRate_Prepay);//分摊余额支付 t_PrepayAmt -= soInfo.BaseInfo.PrepayAmount.Value; //根据商品总价分摊礼品卡支付 soInfo.BaseInfo.GiftCardPay = UtilityHelper.ToMoney(CurrentSO.BaseInfo.GiftCardPay.Value * priceRate_Prepay);//分摊礼品支付 t_GiftCardPay -= soInfo.BaseInfo.GiftCardPay.Value; } else // 最后一个子订单 { soInfo.BaseInfo.ShipPrice = UtilityHelper.ToMoney(t_ShipPrice); soInfo.BaseInfo.PointPay = t_PointPay; soInfo.BaseInfo.PointPayAmount = Convert.ToDecimal(soInfo.BaseInfo.PointPay) / ExternalDomainBroker.GetPointToMoneyRatio(); //计算积分支付 soInfo.BaseInfo.PayPrice = UtilityHelper.ToMoney(t_PayPrice); soInfo.BaseInfo.PremiumAmount = UtilityHelper.ToMoney(t_PremiumAmt); //余额支付的分摊比例 decimal priceRate_Prepay = soInfo.BaseInfo.SOTotalAmount / (CurrentSO.BaseInfo.SOTotalAmount <= 0 ? 1 : CurrentSO.BaseInfo.SOTotalAmount); soInfo.BaseInfo.PrepayAmount = UtilityHelper.ToMoney(t_PrepayAmt); soInfo.BaseInfo.GiftCardPay = UtilityHelper.ToMoney(t_GiftCardPay); } if (CurrentSO.SOGiftCardList.Count > 0) { decimal itemGiftCardPay = soInfo.BaseInfo.GiftCardPay.Value; foreach (ECCentral.BizEntity.IM.GiftCardRedeemLog giftCard in CurrentSO.SOGiftCardList) { if (itemGiftCardPay <= 0) { break; } if (giftCard.Amount <= 0) { continue; } if (giftCard.Amount >= itemGiftCardPay) { giftCard.Amount -= itemGiftCardPay; soInfo.SOGiftCardList.Add(new ECCentral.BizEntity.IM.GiftCardRedeemLog { Code = giftCard.Code, Amount = itemGiftCardPay }); itemGiftCardPay = 0; break; } else { itemGiftCardPay -= giftCard.Amount.Value; soInfo.SOGiftCardList.Add(new ECCentral.BizEntity.IM.GiftCardRedeemLog { Code = giftCard.Code, Amount = giftCard.Amount }); giftCard.Amount = 0; } if (itemGiftCardPay == 0M) { break; } } } if (IsAutoSplit) { soInfo.BaseInfo.Status = SOStatus.WaitingOutStock;//拆分后子单为待出库状态 } else { soInfo.BaseInfo.Status = SOStatus.Origin;//拆分后子单为待审核状态 } //拆单后需要重新计算每个子单是否是大件 soInfo.BaseInfo.IsLarge = SOCommon.ValidateIsLarge(soInfo.ShippingInfo.Weight.Value); // 是否大件商品 if (!isLastSubSO) { soInfo.ShippingInfo.OriginShipPrice = UtilityHelper.ToMoney((CurrentSO.ShippingInfo.OriginShipPrice ?? 0) * weightRate); t_OriginShipPrice -= soInfo.ShippingInfo.OriginShipPrice; soInfo.ShippingInfo.PackageFee = UtilityHelper.ToMoney((CurrentSO.ShippingInfo.PackageFee ?? 0) * weightRate); t_PackageFee -= soInfo.ShippingInfo.PackageFee; soInfo.ShippingInfo.RegisteredFee = UtilityHelper.ToMoney((CurrentSO.ShippingInfo.RegisteredFee ?? 0) * weightRate); t_RegisteredFee -= soInfo.ShippingInfo.RegisteredFee; soInfo.ShippingInfo.ShippingFee = UtilityHelper.ToMoney((CurrentSO.ShippingInfo.ShippingFee ?? 0) * weightRate); t_ShippingFee -= soInfo.ShippingInfo.ShippingFee; soInfo.ShippingInfo.Weight3PL = (int)((CurrentSO.ShippingInfo.Weight3PL ?? 0) * weightRate); t_Weight3PL -= soInfo.ShippingInfo.Weight3PL; soInfo.ShippingInfo.Weight = (int)((CurrentSO.ShippingInfo.Weight ?? 0) * weightRate); t_WeightSO -= soInfo.ShippingInfo.Weight; } else { soInfo.ShippingInfo.OriginShipPrice = t_OriginShipPrice; soInfo.ShippingInfo.PackageFee = t_PackageFee; soInfo.ShippingInfo.RegisteredFee = t_RegisteredFee; soInfo.ShippingInfo.ShippingFee = t_ShippingFee; soInfo.ShippingInfo.Weight3PL = t_Weight3PL; soInfo.ShippingInfo.Weight = t_WeightSO; } #endregion AssignSubSOPromotion(soInfo); AssignSubSOInvoice(soInfo); if (SubSOAssign != null) { SubSOAssign(soInfo); } List <ItemGrossProfitInfo> gorsses = new List <ItemGrossProfitInfo>(); foreach (ItemGrossProfitInfo gross in CurrentSO.ItemGrossProfitList) { foreach (SOItemInfo item in soInfo.Items) { if (gross.ProductSysNo == item.ProductSysNo) { ItemGrossProfitInfo subgross = SerializationUtility.DeepClone(gross); subgross.SOSysNo = soInfo.SysNo.Value; soInfo.ItemGrossProfitList.Add(subgross); } } } } #endregion }
/// <summary> /// 计算现金支付,需要先计算总金额,Promotion,积分。 /// soInfo.SOMaster.CashPay /// </summary> /// <param name="soInfo"></param> public void CalcCashPay(SOInfo soInfo) { soInfo.BaseInfo.CouponAmount = UtilityHelper.ToMoney(soInfo.Items.Sum(item => item.CouponAmount)); soInfo.BaseInfo.PointPayAmount = UtilityHelper.ToMoney(Convert.ToDecimal(soInfo.BaseInfo.PointPay) / ExternalDomainBroker.GetPointToMoneyRatio()); }
//改单 /// <summary> /// 改单 /// </summary> /// <param name="soSysNo">订单编号</param> public virtual void Update(int soSysNo) { var soProcessor = ObjectFactory <SOProcessor> .Instance; var soInfo = soProcessor.GetSOBySOSysNo(soSysNo); if (soInfo == null) { BizExceptionHelper.Throw("SO_SOIsNotExist"); } //是否货到付款 bool isPayWhenRecv = soProcessor.IsPayWhenReceived(soInfo.BaseInfo.PayTypeSysNo.Value); //查询订单出库记录 string outStock = m_da.GetOutStockString(soSysNo); //还没有出仓记录 if (string.IsNullOrEmpty(outStock)) { //直接作废 soProcessor.ProcessSO(new SOAction.SOCommandInfo { SOInfo = soInfo, Command = SOAction.SOCommand.Abandon }); return; } //获取出库收款信息 var invoiceMasterList = ExternalDomainBroker.GetSOInvoiceMaster(soSysNo); //计算总出库金额相关数据 //保价费 decimal premiumAmt = invoiceMasterList .Where(p => p.PremiumAmt.HasValue) .Sum(p => p.PremiumAmt.Value); //运费 decimal shippingCharge = invoiceMasterList .Where(p => p.ShippingCharge.HasValue) .Sum(p => p.ShippingCharge.Value); //附加费 decimal extraAmt = invoiceMasterList .Where(p => p.ExtraAmt.HasValue) .Sum(p => p.ExtraAmt.Value); //折扣金额 decimal discountAmt = invoiceMasterList .Where(p => p.DiscountAmt.HasValue) .Sum(p => p.DiscountAmt.Value); //优惠卷抵扣 decimal promotionAmt = invoiceMasterList .Where(p => p.PromotionAmt.HasValue) .Sum(p => p.PromotionAmt.Value); //获得积分? int pointAmt = invoiceMasterList .Where(p => p.GainPoint.HasValue) .Sum(p => p.GainPoint.Value); //出库发票额 decimal sumExtendPrice = invoiceMasterList .Where(p => p.InvoiceAmt.HasValue) .Sum(p => p.InvoiceAmt.Value); //礼品卡支付总额 decimal sumGiftCardPay = invoiceMasterList .Where(p => p.GiftCardPayAmt.HasValue) .Sum(p => p.GiftCardPayAmt.Value); //积分支付总额 decimal pointPay = invoiceMasterList .Where(p => p.PointPaid.HasValue) .Sum(p => p.PointPaid.Value); //计算多余额应退金额 decimal returnAmt = GetReturnAmt(soSysNo, sumExtendPrice, soInfo.BaseInfo.GiftCardPay.Value); //计算应退积分 int returnPoint = GetReturnPoint(soInfo, pointPay); //已预付款 decimal prePayAmount = invoiceMasterList .Where(p => p.PrepayAmt.HasValue) .Sum(p => p.PrepayAmt.Value); //预退款总额 decimal preReturnAmount = soInfo.BaseInfo.PrepayAmount.Value + prePayAmount; TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; options.Timeout = TransactionManager.DefaultTimeout; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { //删除未出库分仓的所有Item DeleteOrderItem4UpdatePending(soInfo.Items, soInfo.SysNo.Value, outStock); #region 更新so单据信息 //更新so单据信息 //删除后的SOInfo需要重新读取 //注意这里虽然事务没有提交,但是可以读取脏数据的方法获取 soInfo = soProcessor.GetSOBySOSysNo(soSysNo); soInfo.BaseInfo.PremiumAmount = premiumAmt; soInfo.BaseInfo.ShipPrice = shippingCharge; soInfo.BaseInfo.PayPrice = extraAmt; soInfo.BaseInfo.PointPay = 0; soInfo.BaseInfo.PromotionAmount = discountAmt; soInfo.BaseInfo.CouponAmount = promotionAmt; soInfo.BaseInfo.GainPoint = pointAmt; soInfo.BaseInfo.SOAmount = 0.0M; soInfo.Items.ForEach(x => { if (x.ProductType.HasValue && x.ProductType.Value != SOProductType.Coupon) { soInfo.BaseInfo.SOAmount += x.OriginalPrice * x.Quantity; } }); //现金支付为只读 //soInfo.BaseInfo.CashPay = soInfo.SOMaster.SOAmt + soInfo.SOMaster.PromotionValue + soMP.PointPay; soInfo.BaseInfo.PointPay = Convert.ToInt32(-1 * pointPay * ExternalDomainBroker.GetPointToMoneyRatio()); if (prePayAmount < 0.0M) { soInfo.BaseInfo.PrepayAmount = (-1) * prePayAmount; } soInfo.BaseInfo.GiftCardPay = (-1) * sumGiftCardPay; soProcessor.ProcessSO(new SOAction.SOCommandInfo { Command = SOAction.SOCommand.Update, SOInfo = soInfo }); #endregion 更新so单据信息 //更新改单状态 m_da.UpdateSOPendingStatus(soSysNo, SOPendingStatus.ChangeOrder); #warning 需要重构 重新计算是否并单 //重新计算是否并单 ObjectFactory <ISODA> .Instance.UpdateSOCombineInfo(soInfo.BaseInfo.SysNo.Value); //金额拆分 SOPriceSpliter priceSpliter = ObjectFactory <SOPriceSpliter> .Instance; priceSpliter.CurrentSO = soInfo; priceSpliter.SplitSO(); //重发消息 Resend_ShippingMessage(soSysNo); #region 调整积分 var pointAdjustReq = new ECCentral.BizEntity.Customer.AdjustPointRequest(); pointAdjustReq.CustomerSysNo = soInfo.BaseInfo.CustomerSysNo; pointAdjustReq.OperationType = ECCentral.BizEntity.Customer.AdjustPointOperationType.Abandon; pointAdjustReq.Point = returnPoint; pointAdjustReq.SOSysNo = soInfo.SysNo; pointAdjustReq.Source = "OrderMgmt"; pointAdjustReq.PointType = (int)ECCentral.BizEntity.Customer.AdjustPointType.UpdateSO; pointAdjustReq.Memo = ResourceHelper.Get("SO_Pending_ReturnPointMemo"); ExternalDomainBroker.AdjustPoint(pointAdjustReq); #endregion 调整积分 #region 退款(退余额) if (isPayWhenRecv) { //支持货到付款的改单 if (preReturnAmount > 0.0M) //(prepayAmt > sumExtendPrice) //预付款大于已出库总金额,要将多余的钱退回客户 { var customerPrepayReq = new CustomerPrepayLog(); customerPrepayReq.CustomerSysNo = soInfo.BaseInfo.CustomerSysNo; customerPrepayReq.SOSysNo = soInfo.SysNo; customerPrepayReq.AdjustAmount = preReturnAmount; customerPrepayReq.PrepayType = PrepayType.RemitReturn; customerPrepayReq.Note = ResourceHelper.Get("SO_Pending_PreReturnMemo", preReturnAmount); ExternalDomainBroker.AdjustPrePay(customerPrepayReq); } } else {//生成对应的多付款退款记录(invoiceservice)更新财务收款单中的OrderAmt金额(invoiceservice) if (returnAmt > 0) { //查询收款单 var incomeOrg = ExternalDomainBroker.GetValidSOIncomeInfo(soSysNo, SOIncomeOrderType.SO); if (incomeOrg == null) { BizExceptionHelper.Throw("SO_Income_Unknow", soSysNo.ToString()); } //修改原始的订单金额 incomeOrg.OrderAmt = incomeOrg.OrderAmt - returnAmt; ExternalDomainBroker.UpdateSOIncomeOrderAmount(incomeOrg.SysNo.Value, incomeOrg.OrderAmt.Value); //更新 //创建付款收支单 var income = new SOIncomeInfo { OrderSysNo = soInfo.SysNo , OrderAmt = -returnAmt , IncomeAmt = -returnAmt , OrderType = SOIncomeOrderType.OverPayment , Note = ResourceHelper.Get("SO_Pending_ReturnMemo") , Status = SOIncomeStatus.Origin , IncomeStyle = SOIncomeOrderStyle.Advanced , CompanyCode = soInfo.CompanyCode }; ExternalDomainBroker.CreateSOIncome(income); //创建银行收支单 SOIncomeRefundInfo refundInfo = new SOIncomeRefundInfo { SOSysNo = soInfo.SysNo , OrderSysNo = soInfo.SysNo , OrderType = RefundOrderType.OverPayment , RefundPayType = RefundPayType.PrepayRefund , RefundReason = 5 , Status = RefundStatus.Origin , Note = ResourceHelper.Get("SO_Pending_ReturnMemo") , RefundCashAmt = returnAmt , RefundPoint = 0 , ToleranceAmt = 0 , CompanyCode = soInfo.CompanyCode }; ExternalDomainBroker.CreateSOIncomeRefundInfo(refundInfo); } } #endregion 退款(退余额) #region 退礼品卡 //退礼品卡 if (sumGiftCardPay < 0.0M) { if (soInfo.SOGiftCardList != null) { List <GiftCard> reqList = new List <GiftCard>(); decimal needToPayAmt = sumGiftCardPay * (-1); for (int i = 0; i < soInfo.SOGiftCardList.Count; i++) { if (needToPayAmt <= 0) { soInfo.SOGiftCardList.RemoveAt(i); i--; continue; } soInfo.SOGiftCardList[i].AvailAmount = soInfo.SOGiftCardList[i].Amount.HasValue ? soInfo.SOGiftCardList[i].Amount.Value : 0; if (soInfo.SOGiftCardList[i].AvailAmount >= needToPayAmt) { soInfo.SOGiftCardList[i].Amount = needToPayAmt; soInfo.SOGiftCardList[i].AvailAmount -= needToPayAmt; needToPayAmt = 0; } else { soInfo.SOGiftCardList[i].Amount = soInfo.SOGiftCardList[i].AvailAmount; soInfo.SOGiftCardList[i].AvailAmount = 0; needToPayAmt -= soInfo.SOGiftCardList[i].Amount.Value; } reqList.Add(new GiftCard { Code = soInfo.SOGiftCardList[i].Code, ReferenceSOSysNo = soSysNo, CustomerSysNo = soInfo.SOGiftCardList[i].CustomerSysNo.Value, ConsumeAmount = soInfo.SOGiftCardList[i].Amount.Value }); } ExternalDomainBroker.GiftCardDeduction(reqList, soInfo.CompanyCode); } } #endregion 退礼品卡 scope.Complete(); } ExternalDomainBroker.WriteBizLog(ResourceHelper.Get("SO_Pending_UpdateLogFormat", soSysNo) , BizLogType.Sale_SO_Update , soSysNo , soInfo.CompanyCode); }
/// <summary> /// 创建财务负收款并作废订单 /// </summary> /// <param name="refundInfo"></param> /// <returns></returns> public void CreateAOAndAbandonSO(SOIncomeRefundInfo refundInfo) { IsOutStockOrder = false; if (CurrentSO.BaseInfo.Status == SOStatus.CustomsPass) { IsOutStockOrder = true; } if (CurrentSO.BaseInfo.Status != SOStatus.Origin && CurrentSO.BaseInfo.Status != SOStatus.WaitingOutStock //&& CurrentSO.BaseInfo.Status != SOStatus.OutStock ) { BizExceptionHelper.Throw("SO_CreateAO_SOStatusIsError"); } if (CurrentSOIncome == null) { BizExceptionHelper.Throw("SO_CreateAO_SOIncomeIsNull"); } SOIncomeInfo soIncomeInfo = new SOIncomeInfo { OrderAmt = -CurrentSOIncome.OrderAmt, OrderType = SOIncomeOrderType.AO, Note = ResourceHelper.Get("Res_SO_Abandon_CreateAO"), ReferenceID = "", Status = SOIncomeStatus.Origin, OrderSysNo = CurrentSO.SysNo, IncomeAmt = -(CurrentSOIncome.OrderAmt - CurrentSOIncome.PrepayAmt - CurrentSOIncome.GiftCardPayAmt), PayAmount = -(CurrentSOIncome.OrderAmt - CurrentSOIncome.PrepayAmt - CurrentSOIncome.GiftCardPayAmt), IncomeStyle = CurrentSOIncome.IncomeStyle, PrepayAmt = -CurrentSOIncome.PrepayAmt, GiftCardPayAmt = -CurrentSOIncome.GiftCardPayAmt, PointPay = -CurrentSOIncome.PointPay, CompanyCode = CurrentSO.CompanyCode }; SOIncomeRefundInfo soIncomeRefundInfo = new SOIncomeRefundInfo { OrderSysNo = refundInfo.SOSysNo, OrderType = RefundOrderType.AO, SOSysNo = refundInfo.SOSysNo, RefundPayType = refundInfo.RefundPayType, BankName = refundInfo.BankName, BranchBankName = refundInfo.BranchBankName, CardNumber = refundInfo.CardNumber, CardOwnerName = refundInfo.CardOwnerName, PostAddress = refundInfo.PostAddress, PostCode = refundInfo.PostCode, ReceiverName = refundInfo.ReceiverName, Note = refundInfo.Note, HaveAutoRMA = false, RefundPoint = 0, RefundReason = refundInfo.RefundReason, CompanyCode = CurrentSO.CompanyCode }; if (refundInfo.RefundPayType == RefundPayType.CashRefund) { soIncomeRefundInfo.Status = RefundStatus.Audit; } else { soIncomeRefundInfo.Status = RefundStatus.Origin; } if (refundInfo.RefundPayType == RefundPayType.TransferPointRefund) { soIncomeInfo.IncomeAmt = 0; soIncomeRefundInfo.RefundCashAmt = 0; soIncomeRefundInfo.RefundPoint = Convert.ToInt32(Decimal.Round(CurrentSO.BaseInfo.SOAmount.Value * ExternalDomainBroker.GetPointToMoneyRatio(), 0)); soIncomeRefundInfo.RefundGiftCard = CurrentSOIncome.GiftCardPayAmt; } else { soIncomeRefundInfo.RefundCashAmt = CurrentSOIncome.OrderAmt - CurrentSOIncome.GiftCardPayAmt; soIncomeRefundInfo.RefundGiftCard = CurrentSOIncome.GiftCardPayAmt; } ValidateAbandonSO(false); bool isHold = CurrentSO.BaseInfo.HoldStatus == SOHoldStatus.BackHold; if (IsOutStockOrder) { isHold = true; } //如果后台锁定 if (!isHold) { isHold = Holder.Hold(SOHolder.SOHoldReason.AbandonOrder, OPCCallBackType.AOAbandonCallBack); if (!isHold) { BizExceptionHelper.Throw("SO_Abandon_HoldIsAsyn"); } } if (isHold) //如果订单已经锁定 { CreateAOAndAbandonSO(soIncomeInfo, soIncomeRefundInfo); if (IsOutStockOrder) { SODA.UpdateSOStatusToReportedFailure(CurrentSO.SysNo.Value); CurrentSO.BaseInfo.Status = SOStatus.Reject; } SendMessage(); } }
/// <summary> /// 更新团购订单 /// </summary> /// <param name="CurrentSO"></param> /// <returns></returns> public void Update() { ValidationSOEntity(); ValidationGroupBuyingRules(); SOItemInfo groupBuyProduct = CurrentSO.Items.Find(item => item.ProductSysNo == ProductSysNo); if (groupBuyProduct == null) { return; } //可能有赠品,但是只会有一个主商品 int groupBuySysNo = groupBuyProduct.ReferenceSysNo.Value; GroupBuyingInfo gbInfo = ExternalDomainBroker.GetGroupBuyInfoBySysNo(groupBuySysNo); decimal dealPrice = gbInfo.GBPrice.HasValue ? gbInfo.GBPrice.Value : -1; if (dealPrice < 0) { throw new BizException(ResourceHelper.Get("SO_Audit_GroupNotDealPrice", CurrentSO.SysNo)); } if (groupBuyProduct != null && dealPrice < groupBuyProduct.Price) { SOInfo newSOInfo = new SOInfo(); //newSOInfo.SOItemList = SerializeHelper.DeepClone(soInfo.SOItemList); List <SOItemInfo> otherItems = CurrentSO.Items.FindAll(x => x.ProductSysNo != ProductSysNo); decimal oldSOAmt = 0.0m; if (otherItems != null && otherItems.Count > 0) { oldSOAmt = otherItems.Sum(x => x.OriginalPrice.Value * x.Quantity.Value); } decimal newSOAmt = oldSOAmt; if (groupBuyProduct.ProductType == SOProductType.Product) { groupBuyProduct.Price = dealPrice; groupBuyProduct.OriginalPrice = dealPrice; groupBuyProduct.SettlementStatus = SettlementStatus.Success; //团购订单不能用优惠卷 newSOAmt += dealPrice * groupBuyProduct.Quantity.Value; } int refundPoint = 0; decimal refundPrepay = 0.0m; decimal refundGiftCard = 0.0m; decimal difference = CurrentSO.BaseInfo.SOAmount.Value - newSOAmt; decimal newPrepayAmt = CurrentSO.BaseInfo.PrepayAmount.Value; decimal newGiftCardPay = CurrentSO.BaseInfo.GiftCardPay.Value; decimal newPremiumAmt = CurrentSO.BaseInfo.PremiumAmount.Value; int newPointPay = CurrentSO.BaseInfo.PointPay.Value; decimal newCashPay = newSOAmt - Math.Abs(CurrentSO.BaseInfo.PointPayAmount.Value); ECCentral.BizEntity.Common.ShippingType shippingType = ExternalDomainBroker.GetShippingTypeBySysNo(CurrentSO.ShippingInfo.ShipTypeSysNo.Value); if (CurrentSO.BaseInfo.IsPremium.Value) { if (shippingType != null && newSOAmt > shippingType.PremiumBase) { newPremiumAmt = UtilityHelper.ToMoney(newSOAmt * shippingType.PremiumRate.Value); } } decimal pointToMoneyRatio = ExternalDomainBroker.GetPointToMoneyRatio(); #region 退款逻辑 //退款优先级:1.先退现金支付(注意:不在这里退还),2.退余额支付,3.退礼品卡支付,4.退积分支付 // 1. 需退还的:余额支付金额,退礼支付品金额,积分支付金额的总合 decimal refundPayAmount = CurrentSO.BaseInfo.PrepayAmount.Value + CurrentSO.BaseInfo.GiftCardPay.Value + CurrentSO.BaseInfo.PointPayAmount.Value - (newSOAmt + newPremiumAmt + CurrentSO.BaseInfo.ShipPrice.Value); // 2. 如果使用余额支付,退到余额 if (refundPayAmount > 0) { refundPrepay = refundPayAmount > CurrentSO.BaseInfo.PrepayAmount ? CurrentSO.BaseInfo.PrepayAmount.Value : refundPayAmount; newPrepayAmt = CurrentSO.BaseInfo.PrepayAmount.Value - refundPrepay; refundPayAmount = refundPayAmount - refundPrepay; // 3. 如果使用礼品卡支付,退到礼品卡 if (refundPayAmount > 0) { refundGiftCard = refundPayAmount > CurrentSO.BaseInfo.GiftCardPay ? CurrentSO.BaseInfo.GiftCardPay.Value : refundPayAmount; newGiftCardPay = CurrentSO.BaseInfo.GiftCardPay.Value - refundGiftCard; refundPayAmount = refundPayAmount - refundGiftCard; // 4. 如果使用积分支付,退积分 if (refundPayAmount > 0) { decimal refundPointAmount = refundPayAmount > CurrentSO.BaseInfo.PointPayAmount ? CurrentSO.BaseInfo.PointPayAmount.Value : refundPayAmount; refundPayAmount = refundPayAmount - refundPointAmount; decimal newPontPayAmount = CurrentSO.BaseInfo.PointPayAmount.Value - refundPointAmount; newPointPay = (int)(newPontPayAmount * pointToMoneyRatio); refundPoint = (int)(refundPointAmount * pointToMoneyRatio); newCashPay = newSOAmt - newPontPayAmount; } } } #endregion ECCentral.BizEntity.Common.PayType payType = ExternalDomainBroker.GetPayTypeBySysNo(CurrentSO.BaseInfo.PayTypeSysNo.Value); decimal newPayPrice = Math.Max(UtilityHelper.ToMoney(payType.PayRate.Value * (newCashPay + CurrentSO.BaseInfo.ShipPrice.Value + newPremiumAmt - newPrepayAmt - newGiftCardPay)), 0M); CurrentSO.BaseInfo.SOAmount = newSOAmt; CurrentSO.BaseInfo.PremiumAmount = newPremiumAmt; CurrentSO.BaseInfo.PayPrice = newPayPrice; CurrentSO.BaseInfo.GiftCardPay = newGiftCardPay; CurrentSO.BaseInfo.PointPay = newPointPay; CurrentSO.BaseInfo.PointPayAmount = CurrentSO.BaseInfo.PointPay.Value / pointToMoneyRatio; CurrentSO.BaseInfo.PrepayAmount = newPrepayAmt; TransactionOptions options = new TransactionOptions(); options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options)) { SODA.UpdateGroupBuySOAmount(CurrentSO.BaseInfo); SODA.UpdateGroupBuyProduct(groupBuyProduct); if (refundPrepay > 0) { ExternalDomainBroker.AdjustPrePay(new BizEntity.Customer.CustomerPrepayLog { AdjustAmount = refundPrepay, CustomerSysNo = CurrentSO.BaseInfo.CustomerSysNo, Note = "Update SO For GroupBuying", PrepayType = ECCentral.BizEntity.Customer.PrepayType.SOPay, SOSysNo = CurrentSO.SysNo, }); } if (refundGiftCard > 0) { ExternalDomainBroker.GiftCardVoidForSOUpdate(newGiftCardPay, CurrentSO.SOGiftCardList, CurrentSO.CompanyCode); } if (refundPoint > 0) { ExternalDomainBroker.AdjustPoint(new BizEntity.Customer.AdjustPointRequest { CustomerSysNo = CurrentSO.BaseInfo.CustomerSysNo, Memo = "Update Group Buying SO", OperationType = ECCentral.BizEntity.Customer.AdjustPointOperationType.AddOrReduce, Point = refundPoint, PointType = (int)ECCentral.BizEntity.Customer.AdjustPointType.UpdateSO, SOSysNo = CurrentSO.SysNo, Source = SOConst.DomainName }); } scope.Complete(); } } WriteLog(BizEntity.Common.BizLogType.Sale_SO_Update, "IPP更改团购订单"); }