Example #1
0
        /// <summary>
        /// 作废订单
        /// </summary>
        /// <param name="isSynch">是否同步作废</param>
        /// <param name="IsImmediatelyReturnStock">是否立即返还库存</param>
        /// <param name="isAO"></param>
        protected virtual void AbandonSO()
        {
            int    couponSysNo = CouponList != null && CouponList.Count > 0 ? CouponList[0].ProductSysNo.Value : 0;
            string couponCode  = string.Empty;

            var shopProducts = CurrentSO.Items.Where(p => p.InventoryType == BizEntity.IM.ProductInventoryType.GetShopInventory);

            //ERP库存调整
            ERPInventoryAdjustInfo erpAdjustInfo = new ERPInventoryAdjustInfo
            {
                OrderSysNo     = this.CurrentSO.SysNo.Value,
                OrderType      = "SO",
                AdjustItemList = new List <ERPItemInventoryInfo>(),
                Memo           = "作废减少销售数量"
            };

            foreach (var item in shopProducts)
            {
                ERPItemInventoryInfo adjustItem = new ERPItemInventoryInfo
                {
                    ProductSysNo     = item.ProductSysNo,
                    B2CSalesQuantity = -item.Quantity.Value
                };

                erpAdjustInfo.AdjustItemList.Add(adjustItem);
            }

            if (erpAdjustInfo.AdjustItemList.Count > 0)
            {
                string adjustXml = ECCentral.Service.Utility.SerializationUtility.ToXmlString(erpAdjustInfo);
                ObjectFactory <ICommonBizInteract> .Instance.CreateOperationLog(string.Format("作废减少销售数量:{0}", adjustXml)
                                                                                , BizLogType.Sale_SO_VoideSO
                                                                                , this.CurrentSO.SysNo.Value
                                                                                , this.CurrentSO.CompanyCode);

                //ObjectFactory<IAdjustERPInventory>.Instance.AdjustERPInventory(erpAdjustInfo);
            }

            //IsolationLevel与上层事务IsolationLevel有冲突,去除
            //TransactionOptions options = new TransactionOptions
            //{
            //    IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted
            //};
            //using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))

            #region 如果是拆分后的子单,还需要更新主单信息。
            if (CurrentSO.BaseInfo.SplitType == SOSplitType.SubSO)
            {
                //重新计算主订单SOAmt,ShipPrice,PrepayAmt,PremiumAmt
                SOInfo masterSO = SODA.GetSOBySOSysNo(CurrentSO.BaseInfo.SOSplitMaster.Value);
                masterSO.BaseInfo.PremiumAmount   -= CurrentSO.BaseInfo.PremiumAmount;
                masterSO.BaseInfo.PrepayAmount    -= CurrentSO.BaseInfo.PrepayAmount;
                masterSO.BaseInfo.ShipPrice       -= CurrentSO.BaseInfo.ShipPrice;
                masterSO.BaseInfo.SOAmount        -= CurrentSO.BaseInfo.SOAmount;
                masterSO.BaseInfo.GainPoint       -= CurrentSO.BaseInfo.GainPoint;
                masterSO.BaseInfo.PointPay        -= CurrentSO.BaseInfo.PointPay;
                masterSO.BaseInfo.PromotionAmount -= CurrentSO.BaseInfo.PromotionAmount;
                masterSO.BaseInfo.PayPrice        -= CurrentSO.BaseInfo.PayPrice;
                masterSO.BaseInfo.CouponAmount    -= CurrentSO.BaseInfo.CouponAmount;
                masterSO.BaseInfo.PointPayAmount  -= CurrentSO.BaseInfo.PointPayAmount;

                //删除对应主单中的商品
                foreach (SOItemInfo item in CurrentSO.Items)
                {
                    //除优惠券外的商品
                    if (item.ProductType != SOProductType.Coupon)
                    {
                        SODA.DeleteSOItemBySOSysNoAndProductSysNo(masterSO.SysNo.Value, item.ProductSysNo.Value);
                    }
                }
                //更新主订单金额
                SODA.UpdateSOAmountInfo(masterSO.BaseInfo);
            }

            #endregion 如果是子单,还需要更新主单信息

            //取消优惠券使用
            CancelCoupon();

            //  保存作废订单信息
            SaveCurrentSO();
            //if (AppSettingManager.GetSetting(SOConst.DomainName, "PaymentInventory").ToString().ToLower() != "true")
            //{
            //    // 调整仓库,返还商品库存
            //    AdjustInventory();
            //}
            //SOProcessor sopro = new SOProcessor();
            //DateTime? SOCreatDate = CurrentSO.BaseInfo.CreateTime;
            //foreach (var item in CurrentSO.Items)
            //{
            //    if (sopro.CheckReturnInventory(item.ProductSysNo.Value, SOCreatDate.Value))
            //    {
            //        // 调整仓库,返还商品库存
            //        AdjustInventory();
            //    }
            //}

            //调整仓库,返还商品库存
            AdjustInventory();

            //订单支付
            CancelSOPay();

            // 如果订单有奖品,则要退还奖品。
            if (CurrentSO.Items != null && CurrentSO.Items.Exists(x => x.ProductType == SOProductType.Award))
            {
                ExternalDomainBroker.ReturnAwardForSO(SOSysNo);
            }
            // 取消配送
            CancelDelivery();

            // 作废订单的虚库申请
            AbandonSOVirtualItemRequest();
            // 提交作废订单之前,所做的操作。
            PreCommit();

            WriteLog(CurrentSO);
        }