Exemplo n.º 1
0
 public int AddB2BOrder(OrderModel orderModel)
 {
     try
     {
         List <OrderApproval> orderApproval = new List <OrderApproval>();
         var approvalProcess = _omsAccessor.Get <ApprovalProcess>().Where(p => p.Id == orderModel.ApprovalProcessId && p.Isvalid).Include(p => p.ApprovalProcessDetail).FirstOrDefault();
         if (approvalProcess != null)
         {
             foreach (var item in approvalProcess.ApprovalProcessDetail)
             {
                 OrderApproval o = new OrderApproval
                 {
                     CreatedBy = _workContext.CurrentUser.Id,
                     UserId    = item.UserId,
                     Sort      = item.Sort,
                     State     = OrderApprovalState.Unaudited
                 };
                 orderApproval.Add(o);
             }
         }
         Order order = new Order
         {
             SerialNumber      = orderModel.SerialNumber,
             Type              = OrderType.B2B,
             ShopId            = 0,
             State             = OrderState.ToBeTurned,
             WriteBackState    = WriteBackState.NoWrite,
             IsLocked          = false,
             LockStock         = false,
             CustomerName      = orderModel.CustomerName,
             CustomerPhone     = orderModel.CustomerPhone,
             CustomerMark      = orderModel.CustomerMark,
             AddressDetail     = orderModel.AddressDetail,
             WarehouseId       = orderModel.WarehouseId,
             CustomerId        = orderModel.CustomerId,
             PriceTypeId       = orderModel.PriceTypeId,
             DeliveryTypeId    = orderModel.DeliveryTypeId,
             OrderApproval     = orderApproval,
             ApprovalProcessId = orderModel.ApprovalProcessId,
             CreatedBy         = _workContext.CurrentUser.Id,
             InvoiceType       = orderModel.InvoiceType,
         };
         _omsAccessor.Insert(order);
         _omsAccessor.SaveChanges();
         return(order.Id);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 修改订单,需要重新审核
        /// </summary>
        /// <param name="orderModel"></param>
        /// <returns></returns>
        public Order Re_Review(int orderId, int approvalProcessId = 0)
        {
            var order = _omsAccessor.Get <Order>().Where(p => p.Id == orderId && p.Isvalid).Include(p => p.OrderProduct).FirstOrDefault();

            if (order == null)
            {
                return(new Order());
            }
            if (approvalProcessId == 0)
            {
                approvalProcessId = order.ApprovalProcessId;
            }
            List <OrderApproval> orderApproval = _omsAccessor.Get <OrderApproval>().Where(p => p.OrderId == orderId && p.Isvalid && p.State != OrderApprovalState.Failure).ToList();

            orderApproval.Each(p => p.State = OrderApprovalState.Failure);
            var approvalProcess = _omsAccessor.Get <ApprovalProcess>().Where(p => p.Id == approvalProcessId && p.Isvalid).Include(p => p.ApprovalProcessDetail).FirstOrDefault();

            if (approvalProcess != null)
            {
                foreach (var item in approvalProcess.ApprovalProcessDetail)
                {
                    OrderApproval o = new OrderApproval
                    {
                        CreatedBy = _workContext.CurrentUser.Id,
                        UserId    = item.UserId,
                        Sort      = item.Sort,
                        State     = OrderApprovalState.Unaudited
                    };
                    orderApproval.Add(o);
                }
            }
            order.State = OrderState.ToBeTurned;//修改订单,需要重新待审核
            if (order.LockStock)
            {
                //如果锁定库存,需先释放库存
                foreach (var item in order.OrderProduct)
                {
                    if (item.SaleProduct != null)
                    {
                        item.SaleProduct.LockStock      = item.SaleProduct.LockStock + item.Quantity;
                        item.SaleProduct.AvailableStock = item.SaleProduct.AvailableStock - item.Quantity;
                    }
                }
                //已解锁
                order.LockStock = false;
            }
            order.OrderApproval = orderApproval;
            return(order);
        }
Exemplo n.º 3
0
 public OrderApprovalTest()
 {
     _orderRepository = new InMemOrderRepository();
     _orderApproval   = new OrderApproval(_orderRepository);
 }