/// <summary> /// 取消积分支付,返还积分 /// </summary> protected virtual void CancelPointPay() { if (CurrentSO.BaseInfo.PointPay > 0) { ExternalDomainBroker.AdjustPoint(new BizEntity.Customer.AdjustPointRequest { CustomerSysNo = CurrentSO.BaseInfo.CustomerSysNo, Point = CurrentSO.BaseInfo.PointPay, PointType = (int)ECCentral.BizEntity.Customer.AdjustPointType.AbandonSO, SOSysNo = SOSysNo, Memo = ResourceHelper.Get("Res_SO_Abandon_AdjustPoint"), Source = SOConst.DomainName, OperationType = ECCentral.BizEntity.Customer.AdjustPointOperationType.Abandon, }); } }
/// <summary> /// 给用户加积分 /// </summary> /// <param name="soInfo"></param> public void AddPointForCustomer(SOInfo soInfo) { if (!soInfo.BaseInfo.PayWhenReceived.Value && soInfo.BaseInfo.GainPoint != 0) { //给款到发货的客户加积分 ExternalDomainBroker.AdjustPoint(new BizEntity.Customer.AdjustPointRequest { CustomerSysNo = soInfo.BaseInfo.CustomerSysNo, Memo = string.Format("SO#:{0}-购物送积分", soInfo.SysNo), OperationType = ECCentral.BizEntity.Customer.AdjustPointOperationType.AddOrReduce, Point = soInfo.BaseInfo.GainPoint, PointType = (int)ECCentral.BizEntity.Customer.AdjustPointType.SalesDiscountPoint, SOSysNo = soInfo.SysNo, Source = SOConst.DomainName, }); } }
//改单 /// <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="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更改团购订单"); }