예제 #1
0
        /// <summary>
        /// 购物车转购物车明细简单对象(用于Json存储)
        /// </summary>
        /// <param name="shoppingCart">购物车</param>
        /// <returns>Json格式的购物车明细集合</returns>
        /// <remarks>2013-09-26 吴文强 创建</remarks>
        public static List <JsonCartItem> ConvertJson(this CrShoppingCart shoppingCart)
        {
            var jsonCartItems = new List <JsonCartItem>();
            var items         = shoppingCart.GetShoppingCartItem();

            var promotionKeys = new List <string>();

            foreach (var item in items)
            {
                if (item.IsLock == (int)CustomerStatus.购物车是否锁定.是 && !string.IsNullOrEmpty(item.GroupCode))
                {
                    var keys = string.Format("{0},{1}", item.Promotions, item.GroupCode);
                    if (promotionKeys.Contains(keys))
                    {
                        continue;
                    }
                    promotionKeys.Add(keys);
                }

                jsonCartItems.Add(new JsonCartItem()
                {
                    IsChecked        = item.IsChecked,
                    GroupCode        = item.GroupCode,
                    IsLock           = item.IsLock,
                    ProductSysNo     = item.ProductSysNo,
                    Promotions       = item.Promotions,
                    Quantity         = item.Quantity,
                    ProductSalesType = item.ProductSalesType
                });
            }
            return(jsonCartItems);
        }
예제 #2
0
 /// <summary>
 /// 购物车商品数(不包含赠品)
 /// </summary>
 /// <param name="shoppingCart">购物车</param>
 /// <returns>购物车商品数</returns>
 /// <remarks>2013-10-16 吴文强 创建</remarks>
 public static int CartItemNumber(this CrShoppingCart shoppingCart)
 {
     return(shoppingCart.GetShoppingCartItem()
            .Where(t => t.ProductSalesType != (int)CustomerStatus.商品销售类型.赠品).Sum(t => t.Quantity));
 }
예제 #3
0
        /// <summary>
        /// 购物车转销售单明细
        /// </summary>
        /// <param name="cacheKey">缓存Key</param>
        /// <param name="orderSysNo">订单号</param>
        /// <param name="transactionSysNo">事物编号</param>
        /// <param name="shoppingCart">购物车</param>
        /// <returns>销售单明细集合</returns>
        /// <remarks>2013-09-10 吴文强 创建</remarks>
        public List <SoOrderItem> ShoppingCartToOrderItem(string cacheKey, int orderSysNo, string transactionSysNo, CrShoppingCart shoppingCart)
        {
            var orderItems      = new List <SoOrderItem>();
            var removeCartSysNo = new List <int>();

            //获取购物车中所有赠品
            var shoppingCartGiftItems =
                shoppingCart.GetShoppingCartItem().Where(sci => sci.ProductSalesType == (int)CustomerStatus.商品销售类型.赠品);

            var order    = SoOrderBo.Instance.GetEntity(orderSysNo);
            var customer = CrCustomerBo.Instance.GetModel(order.CustomerSysNo);

            foreach (var cartGroup in shoppingCart.ShoppingCartGroups)
            {
                #region 添加商品
                //添加商品
                foreach (var cartItem in cartGroup.ShoppingCartItems)
                {
                    var groupName      = string.Empty;
                    var usedPromotions = string.Empty;
                    if (cartItem.IsLock == (int)CustomerStatus.购物车是否锁定.是)
                    {
                        groupName = cartGroup.GroupPromotions != null && cartGroup.GroupPromotions.Count > 0
                                        ? cartGroup.GroupPromotions[0].Description
                                        : string.Empty;
                        usedPromotions = cartGroup.Promotions;
                    }
                    else
                    {
                        if (cartItem.Promotions != null)
                        {
                            var proms =
                                cartItem.Promotions.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries)
                                .Select(t => Convert.ToInt32(t));
                            if (cartGroup.GroupPromotions != null)
                            {
                                usedPromotions = string.Join(";",
                                                             cartGroup.GroupPromotions.Where(
                                                                 t => proms.Contains(t.PromotionSysNo) && t.IsUsed)
                                                             .Select(s => s.PromotionSysNo.ToString()));
                            }
                        }
                    }

                    orderItems.Add(new SoOrderItem()
                    {
                        OrderSysNo       = orderSysNo,
                        TransactionSysNo = transactionSysNo,

                        ProductSysNo          = cartItem.ProductSysNo,
                        ProductName           = cartItem.ProductName,
                        Quantity              = cartItem.Quantity,
                        OriginalPrice         = cartItem.OriginPrice,
                        SalesUnitPrice        = cartItem.SalesUnitPrice,
                        SalesAmount           = cartItem.SaleTotalAmount,
                        DiscountAmount        = cartItem.DiscountAmount,
                        ChangeAmount          = 0,
                        RealStockOutQuantity  = 0,
                        ProductSalesType      = cartItem.ProductSalesType,
                        ProductSalesTypeSysNo = cartItem.ProductSalesTypeSysNo,
                        GroupCode             = cartItem.GroupCode,
                        GroupName             = groupName,
                        UsedPromotions        = usedPromotions//UsedPromotions = cartItem.UsedPromotions
                    });
                    //需要从购物车中移除的系统编号
                    removeCartSysNo.Add(cartItem.SysNo);
                }
                #endregion

                #region 添加商品组赠品
                //添加赠品
                if (cartGroup.GroupPromotions != null)
                {
                    foreach (var groupPromotion in cartGroup.GroupPromotions)
                    {
                        if (groupPromotion.UsedGiftProducts == null)
                        {
                            continue;
                        }
                        foreach (var giftProduct in groupPromotion.UsedGiftProducts)
                        {
                            var product = PdProductBo.Instance.GetProduct(giftProduct.ProductSysNo);
                            if (product == null)
                            {
                                continue;
                            }

                            //从购物车获取数据
                            orderItems.Add(new SoOrderItem()
                            {
                                OrderSysNo       = orderSysNo,
                                TransactionSysNo = transactionSysNo,

                                ProductSysNo         = giftProduct.ProductSysNo,
                                ProductName          = giftProduct.ProductName,
                                Quantity             = 1,
                                OriginalPrice        = PdPriceBo.Instance.GetUserRankPrice(giftProduct.ProductSysNo, customer.LevelSysNo),
                                SalesUnitPrice       = giftProduct.PurchasePrice,
                                SalesAmount          = giftProduct.PurchasePrice,
                                DiscountAmount       = 0,
                                ChangeAmount         = 0,
                                RealStockOutQuantity = 0,
                                ProductSalesType     = (int)CustomerStatus.商品销售类型.赠品,

                                ProductSalesTypeSysNo = giftProduct.SysNo,
                                GroupCode             = string.Empty,
                                GroupName             = string.Empty,
                                UsedPromotions        = giftProduct.PromotionSysNo.ToString()
                            });

                            //需要从购物车中移除的系统编号
                            removeCartSysNo.Add(giftProduct.ProductSysNo);
                        }
                    }
                }
                #endregion
            }

            #region 添加订单赠品
            //添加赠品
            if (shoppingCart.GroupPromotions != null)
            {
                foreach (var groupPromotion in shoppingCart.GroupPromotions)
                {
                    if (groupPromotion.UsedGiftProducts == null)
                    {
                        continue;
                    }
                    foreach (var giftProduct in groupPromotion.UsedGiftProducts)
                    {
                        var product = PdProductBo.Instance.GetProduct(giftProduct.ProductSysNo);
                        if (product == null)
                        {
                            continue;
                        }

                        //从购物车获取数据
                        orderItems.Add(new SoOrderItem()
                        {
                            OrderSysNo       = orderSysNo,
                            TransactionSysNo = transactionSysNo,

                            ProductSysNo         = giftProduct.ProductSysNo,
                            ProductName          = giftProduct.ProductName,
                            Quantity             = 1,
                            OriginalPrice        = PdPriceBo.Instance.GetUserRankPrice(giftProduct.ProductSysNo, customer.LevelSysNo),
                            SalesUnitPrice       = giftProduct.PurchasePrice,
                            SalesAmount          = giftProduct.PurchasePrice,
                            DiscountAmount       = 0,
                            ChangeAmount         = 0,
                            RealStockOutQuantity = 0,
                            ProductSalesType     = (int)CustomerStatus.商品销售类型.赠品,

                            ProductSalesTypeSysNo = giftProduct.SysNo,
                            GroupCode             = string.Empty,
                            GroupName             = string.Empty,
                            UsedPromotions        = giftProduct.PromotionSysNo.ToString()
                        });

                        //需要从购物车中移除的系统编号
                        removeCartSysNo.Add(giftProduct.ProductSysNo);
                    }
                }
            }
            #endregion

            return(orderItems);
        }