예제 #1
0
        public void CreateOutStorage(CreateOutStorageExt createOutStorageExt)
        {
            Check.Argument.IsNotNull(createOutStorageExt, "createOutStorageExt");
            Check.Argument.IsNotNull(createOutStorageExt.OutStorage, "createOutStorageExt.OutStorage");
            Check.Argument.IsNotNull(createOutStorageExt.WayBillInfos, "createOutStorageExt.WayBillInfos");

            DateTime      outStorageCreatedOn = DateTime.Now;
            List <string> waybillinfoIds      = new List <string>();

            createOutStorageExt.WayBillInfos.Each(p => waybillinfoIds.Add(p.WayBillNumber));
            var wayBills = _wayBillInfoRepository.GetList(p => waybillinfoIds.Contains(p.WayBillNumber));

            List <WayBillEventLog>     listWayBillEventLog     = new List <WayBillEventLog>();
            List <OutStorageInfo>      listOutStorageInfo      = new List <OutStorageInfo>();
            List <CustomerOrderStatus> listCustomerOrderStatus = new List <CustomerOrderStatus>();
            List <string> listWaybillSend      = new List <string>();
            List <string> listWaybillWaitOrder = new List <string>();
            List <int>    listCustomerOrderId  = new List <int>();

            var outShippingMethodId   = createOutStorageExt.WayBillInfos.First().OutShippingMethodID;
            var outShippingMethodName = createOutStorageExt.WayBillInfos.First().OutShippingMethodName;

            createOutStorageExt.WayBillInfos.Each(p =>
            {
                #region 修改运单资料信息和订单状态

                var oldstatus   = WayBill.StatusToValue(WayBill.StatusEnum.Have);
                var wayBillInfo = wayBills.Find(w => w.WayBillNumber == p.WayBillNumber && w.Status == oldstatus);

                if (wayBillInfo == null)
                {
                    throw new ArgumentException("该运单号\"{0}\"不存在,或则是当前状态不是已收货!".FormatWith(p.WayBillNumber));
                }

                //有跟踪号
                if (p.HaveTrackingNum)
                {
                    if (p.TrackingNumber == "null" || string.IsNullOrEmpty(p.TrackingNumber))
                    {
                        //修改运单状态  待转单
                        listWaybillWaitOrder.Add(p.WayBillNumber);
                    }
                    else
                    {
                        //修改运单状态  已发货
                        listWaybillSend.Add(p.WayBillNumber);
                    }
                }
                else
                {
                    //修改运单状态  已发货
                    listWaybillSend.Add(p.WayBillNumber);
                }


                //插入订单状态记录
                listCustomerOrderStatus.Add(new CustomerOrderStatus
                {
                    CustomerOrderID = wayBillInfo.CustomerOrderID.Value,
                    CreatedOn       = DateTime.Now,
                    Status          = CustomerOrder.StatusToValue(CustomerOrder.StatusEnum.Send)
                });

                listCustomerOrderId.Add(wayBillInfo.CustomerOrderID.Value);

                #region 录入内部信息

                var wayBillEventLog = new WayBillEventLog()
                {
                    WayBillNumber = wayBillInfo.WayBillNumber,
                    EventCode     = (int)WayBillEvent.EventCodeEnum.OutStorage,
                    Description   = WayBillEvent.GetEventCodeDescription((int)WayBillEvent.EventCodeEnum.OutStorage),
                    EventDate     = outStorageCreatedOn,
                    LastUpdatedOn = outStorageCreatedOn,
                    Operator      = _workContext.User.UserUame,
                };
                listWayBillEventLog.Add(wayBillEventLog);

                #endregion

                #endregion
            });


            //createOutStorageExt.WayBillInfos.Each(p =>
            //    {
            //        #region 修改运单资料信息和订单状态

            //        var oldstatus = WayBill.StatusToValue(WayBill.StatusEnum.Have);
            //        var wayBillInfo = wayBills.Find(w => w.WayBillNumber == p.WayBillNumber && w.Status == oldstatus);

            //        if (wayBillInfo == null)
            //        {
            //            throw new ArgumentException("该运单号\"{0}\"不存在,或则是当前状态不是已收货!".FormatWith(p.WayBillNumber));
            //        }
            //        wayBillInfo.OutShippingMethodID = p.OutShippingMethodID;
            //        wayBillInfo.OutShippingMethodName = p.OutShippingMethodName;
            //        wayBillInfo.OutStorageID = createOutStorageExt.OutStorage.OutStorageID;
            //        wayBillInfo.VenderCode = createOutStorageExt.OutStorage.VenderCode;

            //        //有跟踪号
            //        if (p.HaveTrackingNum)
            //        {
            //            if (p.TrackingNumber == "null" || string.IsNullOrEmpty(p.TrackingNumber))
            //            {
            //                //修改运单状态  待转单
            //                wayBillInfo.Status = WayBill.StatusToValue(WayBill.StatusEnum.WaitOrder);
            //            }
            //            else
            //            {
            //                //修改运单状态  已发货
            //                wayBillInfo.Status = WayBill.StatusToValue(WayBill.StatusEnum.Send);
            //            }
            //        }
            //        else
            //        {
            //            //修改运单状态  已发货
            //            wayBillInfo.Status = WayBill.StatusToValue(WayBill.StatusEnum.Send);
            //        }


            //        if (wayBillInfo.CustomerOrderID.HasValue)
            //        {
            //            //修改订单状态
            //            wayBillInfo.CustomerOrderInfo.Status =
            //                CustomerOrder.StatusToValue(CustomerOrder.StatusEnum.Send);
            //            wayBillInfo.CustomerOrderInfo.LastUpdatedBy = _workContext.User.UserUame;
            //            wayBillInfo.CustomerOrderInfo.LastUpdatedOn = DateTime.Now;

            //            //插入订单状态记录
            //            listCustomerOrderStatus.Add(new CustomerOrderStatus
            //            {
            //                CustomerOrderID = wayBillInfo.CustomerOrderID.Value,
            //                CreatedOn = DateTime.Now,
            //                Status = CustomerOrder.StatusToValue(CustomerOrder.StatusEnum.Send)
            //            });

            //        }
            //        wayBillInfo.LastUpdatedBy = _workContext.User.UserUame;
            //        wayBillInfo.LastUpdatedOn = DateTime.Now;
            //        wayBillInfo.OutStorageCreatedOn = outStorageCreatedOn;
            //        _wayBillInfoRepository.Modify(wayBillInfo);

            //        #endregion

            //        #region 录入内部信息

            //        //Add By zxq
            //        //Time:2014-09-15
            //        var wayBillEventLog = new WayBillEventLog()
            //        {
            //            WayBillNumber = wayBillInfo.WayBillNumber,
            //            EventCode = (int)WayBillEvent.EventCodeEnum.OutStorage,
            //            Description = WayBillEvent.GetEventCodeDescription((int)WayBillEvent.EventCodeEnum.OutStorage),
            //            EventDate = DateTime.Now,
            //            LastUpdatedOn = DateTime.Now,
            //            Operator = _workContext.User.UserUame,
            //        };
            //        listWayBillEventLog.Add(wayBillEventLog);

            //        #endregion
            //    });

            //生成出仓资料
            var outStorage = new OutStorageInfo();
            outStorage = createOutStorageExt.OutStorage;
            outStorage.DeliveryStaff = outStorage.CreatedBy = outStorage.LastUpdatedBy = _workContext.User.UserUame;
            outStorage.CreatedOn     = outStorage.LastUpdatedOn = outStorageCreatedOn;
            outStorage.Status        = 1;

            if (createOutStorageExt.WayBillInfos.First().OutShippingMethodName == "国际小包优+")
            {
                var    countryCode    = createOutStorageExt.WayBillInfos.First().CountryCode;
                string sequenceNumber = SequenceNumberService.GetSequenceNumber("U-");
                _mailPostBagInfoRepository.Add(new MailPostBagInfo()
                {
                    CountryCode   = countryCode,
                    OutStorageID  = outStorage.OutStorageID,
                    IsBattery     = createOutStorageExt.WayBillInfos.First().IsBattery,
                    PostBagNumber = sequenceNumber.Replace("-", "-" + countryCode + "-"),
                    TotalWeight   = createOutStorageExt.WayBillInfos.Sum(p => p.Weight),
                    CreatedBy     = outStorage.LastUpdatedBy,
                    CreatedOn     = DateTime.Now,
                    LastUpdatedBy = outStorage.LastUpdatedBy,
                    LastUpdatedOn = DateTime.Now,
                });
            }
            //_outStorageInfoRepository.Add(outStorage);

            listOutStorageInfo.Add(outStorage);

            using (var transaction = new TransactionScope())
            {
                _wayBillInfoRepository.BulkInsert("WayBillEventLogs", listWayBillEventLog);
                _wayBillInfoRepository.BulkInsert("OutStorageInfos", listOutStorageInfo);
                _wayBillInfoRepository.BulkInsert("CustomerOrderStatuses", listCustomerOrderStatus);

                if (listWaybillSend.Any())
                {
                    _wayBillInfoRepository.Modify(w => new WayBillInfo()
                    {
                        OutShippingMethodID   = outShippingMethodId,
                        OutShippingMethodName = outShippingMethodName,
                        OutStorageID          = createOutStorageExt.OutStorage.OutStorageID,
                        VenderCode            = createOutStorageExt.OutStorage.VenderCode,
                        LastUpdatedBy         = _workContext.User.UserUame,
                        LastUpdatedOn         = outStorageCreatedOn,
                        OutStorageCreatedOn   = outStorageCreatedOn,
                        Status = WayBill.StatusToValue(WayBill.StatusEnum.Send),
                    }, w => listWaybillSend.Contains(w.WayBillNumber));
                }


                if (listWaybillWaitOrder.Any())
                {
                    _wayBillInfoRepository.Modify(w => new WayBillInfo()
                    {
                        OutShippingMethodID   = outShippingMethodId,
                        OutShippingMethodName = outShippingMethodName,
                        OutStorageID          = createOutStorageExt.OutStorage.OutStorageID,
                        VenderCode            = createOutStorageExt.OutStorage.VenderCode,
                        LastUpdatedBy         = _workContext.User.UserUame,
                        LastUpdatedOn         = outStorageCreatedOn,
                        OutStorageCreatedOn   = outStorageCreatedOn,
                        Status = WayBill.StatusToValue(WayBill.StatusEnum.WaitOrder),
                    }, w => listWaybillWaitOrder.Contains(w.WayBillNumber));
                }

                if (listCustomerOrderId.Any())
                {
                    _customerOrderInfoRepository.Modify(c => new CustomerOrderInfo()
                    {
                        Status        = CustomerOrder.StatusToValue(CustomerOrder.StatusEnum.Send),
                        LastUpdatedBy = _workContext.User.UserUame,
                        LastUpdatedOn = outStorageCreatedOn,
                    }, c => listCustomerOrderId.Contains(c.CustomerOrderID));
                }
                //_wayBillInfoRepository.UnitOfWork.Commit();

                _mailPostBagInfoRepository.UnitOfWork.Commit();

                transaction.Complete();
            }
            //创建总包号
            if (createOutStorageExt.IsCreateTotalPackageNumber.HasValue)
            {
                if (createOutStorageExt.IsCreateTotalPackageNumber.Value)
                {
                    //创建新的
                    var totalPackageInfo = new TotalPackageInfo
                    {
                        CreatedBy          = _workContext.User.UserUame,
                        LastUpdatedBy      = _workContext.User.UserUame,
                        CreatedOn          = outStorageCreatedOn,
                        LastUpdatedOn      = outStorageCreatedOn,
                        TotalPackageNumber = createOutStorageExt.TotalPackageNumber,
                        Remark             = createOutStorageExt.Remark,
                        TotalQty           = createOutStorageExt.TotalQty,
                        TotalVotes         = createOutStorageExt.TotalVotes,
                        TotalWeight        = createOutStorageExt.TotalWeight,
                        VenderCode         = createOutStorageExt.OutStorage.VenderCode,
                        VenderName         = createOutStorageExt.OutStorage.VenderName
                    };
                    _totalPackageInfoRepository.Add(totalPackageInfo);

                    var relational = new TotalPackageOutStorageRelationalInfo
                    {
                        OutStorageID       = createOutStorageExt.OutStorage.OutStorageID,
                        TotalPackageNumber = createOutStorageExt.TotalPackageNumber,
                        CreatedOn          = DateTime.Now
                    };
                    _totalPackageOutStorageRelationalInfoRepository.Add(relational);
                }
                else
                {
                    ////追加到已存在的总包号里面
                    var totalPackageInfo =
                        _totalPackageInfoRepository.Single(
                            p =>
                            p.TotalPackageNumber == createOutStorageExt.TotalPackageNumber &&
                            p.VenderCode == createOutStorageExt.OutStorage.VenderCode);
                    if (totalPackageInfo != null)
                    {
                        totalPackageInfo.TotalQty     += createOutStorageExt.TotalQty;
                        totalPackageInfo.TotalVotes   += createOutStorageExt.TotalVotes;
                        totalPackageInfo.TotalWeight  += createOutStorageExt.TotalWeight;
                        totalPackageInfo.LastUpdatedBy = _workContext.User.UserUame;
                        totalPackageInfo.LastUpdatedOn = outStorageCreatedOn;
                        _totalPackageInfoRepository.Modify(totalPackageInfo);
                        var relational = new TotalPackageOutStorageRelationalInfo
                        {
                            OutStorageID       = createOutStorageExt.OutStorage.OutStorageID,
                            TotalPackageNumber = createOutStorageExt.TotalPackageNumber,
                            CreatedOn          = DateTime.Now
                        };
                        _totalPackageOutStorageRelationalInfoRepository.Add(relational);
                    }
                }
                using (var transaction = new TransactionScope())
                {
                    _totalPackageInfoRepository.UnitOfWork.Commit();
                    _totalPackageOutStorageRelationalInfoRepository.UnitOfWork.Commit();
                    transaction.Complete();
                }
            }
        }
예제 #2
0
 //获取运单列表信息
 public List <WayBillInfo> GetWayBillInfos(List <string> trackNumber)
 {
     return(_wayBillInfoRepository.GetList(p => trackNumber.Contains(p.TrackingNumber)));
 }
예제 #3
0
        /// <summary>
        /// 批量审核通过退回
        /// Add By zhengsong
        /// </summary>
        /// <param name="wayBilllist"></param>
        /// <returns></returns>
        public bool ReturnAuditList(string[] wayBilllist)
        {
            bool reuslt = false;

            try
            {
                var returnGoods = _returnGoodsRepository.GetList(p => wayBilllist.Contains(p.WayBillNumber) && p.Status != (int)ReturnGood.ReturnStatusEnum.Audited);
                var waybills    = _wayBillInfoRepository.GetList(p => wayBilllist.Contains(p.WayBillNumber) && p.Status != (int)WayBill.StatusEnum.Return);

                var receivingExpenses = _receivingExpensRepository.GetList(p => wayBilllist.Contains(p.WayBillNumber));
                returnGoods.ForEach(p =>
                {
                    //修改退货记录表状态
                    p.Status        = (int)ReturnGood.ReturnStatusEnum.Audited;
                    p.Auditor       = _workContext.User.UserUame;
                    p.AuditorDate   = DateTime.Now;
                    p.LastUpdatedBy = _workContext.User.UserUame;
                    p.LastUpdatedOn = DateTime.Now;

                    //修改运单,定单状态
                    var waybill = waybills.FirstOrDefault(z => z.WayBillNumber == p.WayBillNumber);
                    if (waybill != null)
                    {
                        waybill.Status                          = (int)WayBill.StatusEnum.Return;
                        waybill.LastUpdatedBy                   = _workContext.User.UserUame;
                        waybill.LastUpdatedOn                   = DateTime.Now;
                        waybill.IsHold                          = false;
                        waybill.CustomerOrderInfo.Status        = (int)CustomerOrder.StatusEnum.Return;
                        waybill.CustomerOrderInfo.IsHold        = false;
                        waybill.CustomerOrderInfo.LastUpdatedBy = _workContext.User.UserUame;
                        waybill.CustomerOrderInfo.LastUpdatedOn = DateTime.Now;
                        _wayBillInfoRepository.Modify(waybill);
                    }
                    var receivingExpense = receivingExpenses.FirstOrDefault(z => z.WayBillNumber == p.WayBillNumber);
                    //是否退运费
                    if (p.IsReturnShipping)
                    {
                        //添加一个收货费用明细退费记录,并且修改收货费用审核表状态
                        ReceivingExpensesEditExt receivingExpensesEditExt =
                            _financialService.GetReceivingExpensesEditExt(p.WayBillNumber);
                        //如果没有费用就不添加费用明细
                        if (receivingExpensesEditExt.TotalFeeFinal.HasValue ||
                            receivingExpensesEditExt.TotalFeeOriginal.HasValue)
                        {
                            #region 在收货费用详细表添加一个退回数据,状态为4
                            if (receivingExpensesEditExt.TotalFeeFinal.HasValue)
                            {
                                p.ShippingFee = receivingExpensesEditExt.TotalFeeFinal.Value;
                            }
                            else
                            {
                                p.ShippingFee = receivingExpensesEditExt.TotalFeeOriginal.Value;
                            }
                            _financialService.UpdateReceivingExpenseInfo(p.WayBillNumber, _workContext.User.UserUame);

                            #endregion
                        }
                        else
                        {
                            //要退费用但是还没生成
                            if (receivingExpense != null)
                            {
                                receivingExpense.IsNoGet = true;
                            }
                            _receivingExpensRepository.Modify(receivingExpense);
                        }
                    }
                    else
                    {
                        //修改收货费用审核表状态
                        if (receivingExpense != null)
                        {
                            //不退费用测不修改货费用审核表状态跟验收时间
                            //receivingExpense.Status = (int)Financial.ReceivingExpenseStatusEnum.Audited;
                            //receivingExpense.AcceptanceDate = DateTime.Now;
                            receivingExpense.LastUpdatedBy = _workContext.User.UserUame;
                            receivingExpense.LastUpdatedOn = DateTime.Now;
                            _receivingExpensRepository.Modify(receivingExpense);
                        }
                        p.ShippingFee = 0;
                    }
                    _returnGoodsRepository.Modify(p);
                });
                _returnGoodsRepository.UnitOfWork.Commit();
                _wayBillInfoRepository.UnitOfWork.Commit();
                _receivingExpensRepository.UnitOfWork.Commit();
                reuslt = true;
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
            return(reuslt);
        }
예제 #4
0
 //获取运单列表信息
 public List <WayBillInfo> GetWayBillInfoList(List <string> trackNumber)
 {
     return(_wayBillInfoRepository.GetList(p => trackNumber.Contains(p.WayBillNumber) || trackNumber.Contains(p.CustomerOrderNumber) || trackNumber.Contains(p.TrackingNumber)));
 }