Beispiel #1
0
        /// <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更改团购订单");
        }