예제 #1
0
        public static string CreateRMARequest(RMARequestInfo request)
        {
            OrderInfo result = CustomerDA.GetQuerySODetailInfo(request.CustomerSysNo.Value, request.SOSysNo.Value);
            //检查是否重复创建
            Dictionary <int, int> master = new Dictionary <int, int>();

            request.Registers.ForEach(r =>
            {
                if (r.SOItemType.Value == SOProductType.Product)
                {
                    if (master.ContainsKey(r.ProductSysNo.Value))
                    {
                        master[r.ProductSysNo.Value] += r.Quantity.Value;
                    }
                    else
                    {
                        master.Add(r.ProductSysNo.Value, r.Quantity.Value);
                    }
                }
            });
            // verify master so items
            foreach (KeyValuePair <int, int> pair in master)
            {
                var soitem = result.SOItemList.Find(s => s.ProductSysNo == pair.Key &&
                                                    s.ProductType == SOItemType.ForSale);
                int regQty = RegisterDA.GetRegisterQty(
                    pair.Key, (int)SOProductType.Product, request.SOSysNo.Value);
                if (soitem.Quantity < regQty + pair.Value)
                {
                    throw new BusinessException("商品【{0}】的售后申请正在处理中,请不要重复申请", soitem.ProductTitle);
                }
            }

            using (TransactionScope ts = new TransactionScope())
            {
                request.SysNo     = RequestDA.CreateSysNo();
                request.RequestID = GenerateId(request.SysNo.Value);
                //创建申请单初始状态为【待审核】
                request.Status        = RMARequestStatus.WaitingAudit;
                request.ShippingType  = DeliveryType.SELF;//request.ShippingType.Trim();
                request.InvoiceType   = InvoiceType.SELF;
                request.StockType     = StockType.SELF;
                request.MerchantSysNo = result.SellerSysNo;
                RequestDA.Create(request);

                request.Registers.ForEach(register =>
                {
                    var soitem = result.SOItemList.Find(s => s.ProductSysNo == register.ProductSysNo &&
                                                        (int)s.ProductType == (int)register.SOItemType);
                    register.ProductID        = soitem.ProductID;
                    register.ProductName      = soitem.ProductName;
                    register.CustomerDesc     = register.RMAReasonDesc;
                    register.Status           = RMARequestStatus.WaitingAudit;
                    register.OwnBy            = RMAOwnBy.Origin;
                    register.Location         = RMALocation.Origin;
                    register.RevertStatus     = null;
                    register.ShippedWarehouse = result.StockSysNo;

                    register.IsWithin7Days     = false;
                    register.IsRecommendRefund = false;
                    register.NewProductStatus  = RMANewProductStatus.Origin;
                    register.NextHandler       = RMANextHandler.RMA;
                    register.SOItemType        = (SOProductType)soitem.ProductType;
                    for (int i = 0; i < register.Quantity; i++)
                    {
                        register.SysNo = RegisterDA.CreateSysNo();

                        RegisterDA.Create(register);
                        RegisterDA.InsertRequestItem(request.SysNo.Value, register.SysNo.Value);
                    }
                });
                ts.Complete();
            }
            return(request.RequestID);
        }