Exemple #1
0
        /// <summary>
        /// 读取购物车--Sessions.ProductBuyCount
        /// </summary>
        private void ReadCart()
        {
            var cartList = CartBLL.ReadList(base.UserId);

            //关联的商品
            int count = 0;

            int[] ids      = cartList.Select(k => k.ProductId).ToArray();
            var   products = ProductBLL.SearchList(1, ids.Count(), new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            int productCount = 0;

            //规格
            foreach (var cart in cartList)
            {
                cart.Product = products.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo();

                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    productCount += cart.BuyCount;
                }
                else
                {
                    productCount += cart.BuyCount;
                }
            }
            Sessions.ProductBuyCount = productCount;
        }
Exemple #2
0
        /// <summary>
        /// 添加订单产品
        /// </summary>
        /// <param name="orderID"></param>
        protected void AddOrderProduct(int orderID)
        {
            List <CartInfo> cartList = CartBLL.ReadList(base.UserId);

            //读取产品
            checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));
            int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));

            cartList = CartBLL.ReadList(base.UserId);
            cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList();

            string strProductID = string.Empty;

            foreach (CartInfo cart in cartList)
            {
                if (strProductID == string.Empty)
                {
                    strProductID = cart.ProductId.ToString();
                }
                else
                {
                    strProductID += "," + cart.ProductId.ToString();
                }
            }
            List <ProductInfo> productList = new List <ProductInfo>();

            if (strProductID != string.Empty)
            {
                ProductSearchInfo productSearch = new ProductSearchInfo();
                productSearch.InProductId = strProductID;
                productList = ProductBLL.SearchList(productSearch);
            }
            //会员价格
            //List<MemberPriceInfo> memberPriceList = MemberPriceBLL.ReadMemberPriceByProductGrade(strProductID, base.GradeID);
            //添加订单产品
            Dictionary <string, bool> cartDic            = new Dictionary <string, bool>();
            Dictionary <int, int>     cartOrderDetailDic = new Dictionary <int, int>();

            foreach (CartInfo cart in cartList)
            {
                ProductInfo     product     = ProductBLL.ReadProductByProductList(productList, cart.ProductId);
                OrderDetailInfo orderDetail = new OrderDetailInfo();
                orderDetail.OrderId       = orderID;
                orderDetail.ProductId     = cart.ProductId;
                orderDetail.ProductName   = cart.ProductName;
                orderDetail.ProductWeight = product.Weight;
                orderDetail.SendPoint     = product.SendPoint;

                orderDetail.ProductPrice = ProductBLL.GetCurrentPriceWithStandard(product.Id, base.GradeID, cart.StandardValueList);

                orderDetail.BuyCount = cart.BuyCount;

                orderDetail.RandNumber = cart.RandNumber;
                int orderDetailID = OrderDetailBLL.Add(orderDetail);
                cartOrderDetailDic.Add(cart.Id, orderDetailID);
            }

            CartBLL.Delete(cartIds, base.UserId);
            //CartBLL.Clear(base.UserId);
        }
Exemple #3
0
        /// <summary>
        /// 读取购物车
        /// </summary>
        private void ReadCart()
        {
            cartList = CartBLL.ReadList(base.UserId);

            //关联的商品
            int count = 0;

            int[] ids      = cartList.Select(k => k.ProductId).ToArray();
            var   products = ProductBLL.SearchList(1, ids.Count(), new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            //规格
            foreach (var cart in cartList)
            {
                cart.Product = products.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo();

                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    //使用规格的价格和库存
                    var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    cart.Price            = standardRecord.SalePrice;
                    cart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount;
                    //规格集合
                    cart.Standards = ProductTypeStandardBLL.ReadList(Array.ConvertAll <string, int>(standardRecord.StandardIdList.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k)));
                }
                else
                {
                    cart.Price            = cart.Product.SalePrice;
                    cart.LeftStorageCount = cart.Product.TotalStorageCount - cart.Product.OrderCount;
                }
            }
        }
Exemple #4
0
        //计算商品优惠金额
        protected void SelectProductFavor()
        {
            decimal favorMoney = 0;
            int     favorId    = RequestHelper.GetQueryString <int>("favorId");

            if (favorId > 0)
            {
                var theFavor = FavorableActivityBLL.Read(favorId);
                checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));
                int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
                cartList = CartBLL.ReadList(base.UserId);
                cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList();
                //关联的商品
                int   count       = 0;
                int[] ids         = cartList.Select(k => k.ProductId).ToArray();
                var   productList = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                    InProductId = string.Join(",", ids)
                }, ref count);
                decimal tmoney = 0;
                foreach (var tmpcart in cartList)
                {
                    tmpcart.Product = productList.FirstOrDefault(k => k.Id == tmpcart.ProductId) ?? new ProductInfo();
                    if (tmpcart.Product.ClassId.IndexOf(theFavor.ClassIds) > -1)
                    {
                        if (!string.IsNullOrEmpty(tmpcart.StandardValueList))
                        {
                            //使用规格的库存
                            var standardRecord = ProductTypeStandardRecordBLL.Read(tmpcart.ProductId, tmpcart.StandardValueList);
                            tmpcart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount;
                            tmpcart.Price            = ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID);
                            tmoney += tmpcart.Price * tmpcart.BuyCount;
                        }
                        else
                        {
                            tmpcart.Price = ProductBLL.GetCurrentPrice(tmpcart.Product.SalePrice, base.GradeID);
                            tmoney       += tmpcart.Price * tmpcart.BuyCount;
                        }
                    }
                }
                switch (theFavor.ReduceWay)
                {
                case (int)FavorableMoney.Money:
                    favorMoney += theFavor.ReduceMoney;
                    break;

                case (int)FavorableMoney.Discount:
                    favorMoney += tmoney * (100 - theFavor.ReduceDiscount) / 100;
                    break;

                default:
                    break;
                }
                ResponseHelper.Write("ok|" + Math.Round(favorMoney, 2));
            }
            ResponseHelper.End();
        }
Exemple #5
0
        private void SelectShipping()
        {
            int shippingId = RequestHelper.GetQueryString <int>("shippingId");
            int addressId  = RequestHelper.GetQueryString <int>("addressId");

            string checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));

            int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
            if (string.IsNullOrEmpty(checkCart) || cartIds.Length < 1)
            {
                ResponseHelper.Write("error|请选择需要购买的商品");
                ResponseHelper.End();
            }

            var address = UserAddressBLL.Read(addressId, base.UserId);

            //计算配送费用
            List <CartInfo> cartList = CartBLL.ReadList(base.UserId).Where(k => cartIds.Contains(k.Id)).ToList();

            if (cartList.Count < 1)
            {
                ResponseHelper.Write("error|请选择需要购买的商品");
                ResponseHelper.End();
            }

            int count = 0;

            int[] ids         = cartList.Select(k => k.ProductId).ToArray();
            var   productList = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            cartList.ForEach(k => k.Product = productList.FirstOrDefault(k2 => k2.Id == k.ProductId) ?? new ProductInfo());

            decimal shippingMoney = 0;
            //首先根据ShopId分组,根据供应商的不同来分别计算运费
            //然后将分拆后的供应商商品,按单个商品独立计算运费(相同商品购买多个则叠加计算)
            ShippingInfo       shipping       = ShippingBLL.Read(shippingId);
            ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shippingId, address.RegionId);

            var shopIds = cartList.GroupBy(k => k.Product.ShopId).Select(k => k.Key).ToList();

            foreach (var shopId in shopIds)
            {
                var shopCartList = cartList.Where(k => k.Product.ShopId == shopId).ToList();
                foreach (var shopCartSplit in shopCartList)
                {
                    shippingMoney += ShippingRegionBLL.ReadShippingMoney(shipping, shippingRegion, shopCartSplit);
                }
            }

            //decimal shippingMoney = ShippingRegionBLL.ReadShippingMoney(shippingId, address.RegionId, cartList);
            ResponseHelper.Write("ok|" + Math.Round(shippingMoney, 2).ToString());
            ResponseHelper.End();
        }
Exemple #6
0
        /// <summary>
        /// 改变购买数量
        /// </summary>
        private void ChangeBuyCount()
        {
            string  strCartId = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("StrCartId"));
            int     buyCount  = RequestHelper.GetQueryString <int>("BuyCount");
            int     oldCount  = RequestHelper.GetQueryString <int>("OldCount");
            decimal price     = RequestHelper.GetQueryString <decimal>("Price");

            int[] ids = Array.ConvertAll <string, int>(strCartId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));

            CartBLL.Update(ids, buyCount, base.UserId);
            var totalCount = CartBLL.ReadList(base.UserId).Where(k => k.Id.ToString() == strCartId).Sum(k => k.BuyCount);
            var totalPrice = totalCount * price;

            ResponseHelper.Write(strCartId + "|" + totalCount + "|" + totalPrice);
            ResponseHelper.End();
        }
Exemple #7
0
        private void SelectShipping()
        {
            int shippingId = RequestHelper.GetQueryString <int>("shippingId");
            //if (shippingId <= 0) {
            //    ResponseHelper.Write("error|请选择配送方式");
            //    ResponseHelper.End();
            //}
            string regionId  = StringHelper.AddSafe(RequestHelper.GetQueryString <string>("regionId"));
            int    favorId   = RequestHelper.GetQueryString <int>("favorId");
            string checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));

            int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
            if (string.IsNullOrEmpty(checkCart) || cartIds.Length < 1)
            {
                ResponseHelper.Write("error|请选择需要购买的商品");
                ResponseHelper.End();
            }

            //计算配送费用
            List <CartInfo> cartList = CartBLL.ReadList(base.UserId).Where(k => cartIds.Contains(k.Id)).ToList();

            if (cartList.Count < 1)
            {
                ResponseHelper.Write("error|请选择需要购买的商品");
                ResponseHelper.End();
            }

            int count = 0;
            //购物车结算金额
            decimal cartTotalPrice = 0;

            int[] ids         = cartList.Select(k => k.ProductId).ToArray();
            var   productList = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            cartList.ForEach(k => k.Product = productList.FirstOrDefault(k2 => k2.Id == k.ProductId) ?? new ProductInfo());
            foreach (var cart in cartList)
            {
                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    //使用规格的价格和库存
                    var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    cartTotalPrice += ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID) * cart.BuyCount;
                }
                else
                {
                    cartTotalPrice += ProductBLL.GetCurrentPrice(cart.Product.SalePrice, base.GradeID) * cart.BuyCount;
                }
            }

            //首先根据ShopId分组,根据供应商的不同来分别计算运费
            //然后将分拆后的供应商商品,按单个商品独立计算运费(相同商品购买多个则叠加计算)
            ShippingInfo       shipping       = ShippingBLL.Read(shippingId);
            ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shippingId, regionId);
            decimal            shippingMoney  = ShippingRegionBLL.ReadShippingMoney(shippingId, regionId, cartList);
            //var shopIds = cartList.GroupBy(k => k.Product.ShopId).Select(k => k.Key).ToList();
            //foreach (var shopId in shopIds)
            //{
            //    var shopCartList = cartList.Where(k => k.Product.ShopId == shopId).ToList();
            //    foreach (var shopCartSplit in shopCartList)
            //    {
            //        shippingMoney += ShippingRegionBLL.ReadShippingMoney(shipping, shippingRegion, shopCartSplit);
            //    }
            //}
            decimal favorableMoney = 0;

            #region 计算优惠费用
            if (favorId > 0)
            {
                var theFavorable = FavorableActivityBLL.Read(favorId);
                if (("," + theFavorable.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && cartTotalPrice >= theFavorable.OrderProductMoney)
                {
                    switch (theFavorable.ReduceWay)
                    {
                    case (int)FavorableMoney.Money:
                        favorableMoney += theFavorable.ReduceMoney;
                        break;

                    case (int)FavorableMoney.Discount:
                        favorableMoney += cartTotalPrice * (100 - theFavorable.ReduceDiscount) / 100;
                        break;

                    default:
                        break;
                    }
                    if (theFavorable.ShippingWay == (int)FavorableShipping.Free && ShippingRegionBLL.IsRegionIn(regionId, theFavorable.RegionId))
                    {
                        favorableMoney += shippingMoney;
                    }
                }
            }
            #endregion

            ResponseHelper.Write("ok|" + Math.Round(shippingMoney, 2).ToString() + "|" + Math.Round(favorableMoney, 2));
            ResponseHelper.End();
        }
Exemple #8
0
        protected override void PageLoad()
        {
            base.PageLoad();

            //登录验证
            if (base.UserId <= 0)
            {
                string redirectUrl = "/Mobile/login.html?RedirectUrl=/mobile/CheckOut.html";

                ResponseHelper.Redirect(redirectUrl);
                ResponseHelper.End();
            }

            //购物车验证
            checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));
            int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
            if (string.IsNullOrEmpty(checkCart) || cartIds.Length < 1)
            {
                ResponseHelper.Redirect("/Mobile/cart.html");
                ResponseHelper.End();
            }


            //cart list
            #region cart list
            //商品清单
            cartList = CartBLL.ReadList(base.UserId);
            cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList();
            if (cartList.Count < 1)
            {
                ResponseHelper.Redirect("/Mobile/cart.html");
                ResponseHelper.End();
            }

            //关联的商品
            int   count    = 0;
            int[] ids      = cartList.Select(k => k.ProductId).ToArray();
            var   products = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            //规格
            foreach (var cart in cartList)
            {
                cart.Product = products.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo();

                if (cart.Product.StandardType == 1)
                {
                    //使用规格的价格和库存
                    var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    cart.Price            = standardRecord.SalePrice;
                    cart.LeftStorageCount = standardRecord.Storage - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList);
                    //规格集合
                    cart.Standards = ProductTypeStandardBLL.ReadList(Array.ConvertAll <string, int>(standardRecord.StandardIdList.Split(';'), k => Convert.ToInt32(k)));
                }
                else
                {
                    cart.Price            = cart.Product.SalePrice;
                    cart.LeftStorageCount = cart.Product.TotalStorageCount - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList);
                }

                if (cart.LeftStorageCount <= 0)
                {
                    ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html");
                }
            }
            #endregion

            //收货地址
            addressList = UserAddressBLL.ReadList(base.UserId);
            addressList = addressList.OrderByDescending(k => k.IsDefault).ToList();
            singleUnlimitClass.DataSource = RegionBLL.ReadRegionUnlimitClass();

            totalProductMoney = cartList.Sum(k => k.BuyCount * k.Price);
            //用户信息
            var user = UserBLL.Read(base.UserId);
            if (user.Id > 0)
            {
                //读取优惠券
                List <UserCouponInfo> tempUserCouponList = UserCouponBLL.ReadCanUse(base.UserId);
                foreach (UserCouponInfo userCoupon in tempUserCouponList)
                {
                    CouponInfo tempCoupon = CouponBLL.Read(userCoupon.CouponId);
                    if (tempCoupon.UseMinAmount <= totalProductMoney)
                    {
                        userCouponList.Add(userCoupon);
                    }
                }

                moneyLeft = UserBLL.ReadUserMore(base.UserId).MoneyLeft;
            }
            //读取优惠活动
            favorableActivity = FavorableActivityBLL.Read(DateTime.Now, DateTime.Now, 0);
            if (favorableActivity.Id > 0)
            {
                if (("," + favorableActivity.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && Sessions.ProductTotalPrice >= favorableActivity.OrderProductMoney)
                {
                    if (favorableActivity.GiftId != string.Empty)
                    {
                        FavorableActivityGiftSearchInfo giftSearch = new FavorableActivityGiftSearchInfo();
                        giftSearch.InGiftIds = Array.ConvertAll <string, int>(favorableActivity.GiftId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
                        giftList             = FavorableActivityGiftBLL.SearchList(giftSearch);
                    }
                }
                else
                {
                    favorableActivity = new FavorableActivityInfo();
                }
            }
            //支付方式列表
            payPluginsList = PayPlugins.ReadProductBuyPayPluginsList();

            Title = "结算中心";
        }
Exemple #9
0
        /// <summary>
        /// 提交数据
        /// </summary>
        protected override void PostBack()
        {
            string url = "/Mobile/CheckOut.html";
            //检查地址
            string consignee = StringHelper.AddSafe(RequestHelper.GetForm <string>("Consignee"));

            if (consignee == string.Empty)
            {
                ScriptHelper.AlertFront("收货人姓名不能为空", url);
            }
            string tel    = StringHelper.AddSafe(RequestHelper.GetForm <string>("Tel"));
            string mobile = StringHelper.AddSafe(RequestHelper.GetForm <string>("Mobile"));

            if (tel == string.Empty && mobile == string.Empty)
            {
                ScriptHelper.AlertFront("固定电话,手机必须得填写一个", url);
            }
            string zipCode = StringHelper.AddSafe(RequestHelper.GetForm <string>("ZipCode"));
            string address = StringHelper.AddSafe(RequestHelper.GetForm <string>("Address"));

            if (address == string.Empty)
            {
                ScriptHelper.AlertFront("地址不能为空", url);
            }
            //验证配送方式
            int shippingID = RequestHelper.GetForm <int>("ShippingID");

            if (shippingID == int.MinValue)
            {
                ScriptHelper.AlertFront("请选择配送方式", url);
            }

            //检查金额
            decimal productMoney = 0;

            #region 计算订单金额
            checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));
            int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));

            cartList = CartBLL.ReadList(base.UserId);
            cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList();
            if (cartList.Count < 1)
            {
                ResponseHelper.Redirect("/Mobile/cart.html");
                ResponseHelper.End();
            }

            //关联的商品
            int   count    = 0;
            int[] ids      = cartList.Select(k => k.ProductId).ToArray();
            var   products = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            //规格与库存判断
            foreach (var cart in cartList)
            {
                cart.Product = products.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo();

                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    //使用规格的价格和库存
                    var standardRecord   = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    int leftStorageCount = standardRecord.Storage - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList);
                    if (leftStorageCount >= cart.BuyCount)
                    {
                        cart.Price            = standardRecord.SalePrice;
                        cart.LeftStorageCount = leftStorageCount;
                        //规格集合
                        cart.Standards = ProductTypeStandardBLL.ReadList(Array.ConvertAll <string, int>(standardRecord.StandardIdList.Split(';'), k => Convert.ToInt32(k)));
                    }
                    else
                    {
                        ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html");
                    }
                }
                else
                {
                    int leftStorageCount = cart.Product.TotalStorageCount - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList);
                    if (leftStorageCount >= cart.BuyCount)
                    {
                        cart.Price            = cart.Product.SalePrice;
                        cart.LeftStorageCount = leftStorageCount;
                    }
                    else
                    {
                        ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html");
                    }
                }
            }
            #endregion
            productMoney = cartList.Sum(k => k.BuyCount * k.Price);

            decimal favorableMoney = 0;
            decimal shippingMoney  = 0;
            #region 计算运费与优惠金额
            string regionID = RequestHelper.GetForm <string>("RegionID");
            //计算配送费用
            ShippingInfo       shipping       = ShippingBLL.Read(shippingID);
            ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shippingID, regionID);
            switch (shipping.ShippingType)
            {
            case (int)ShippingType.Fixed:
                shippingMoney = shippingRegion.FixedMoeny;
                break;

            case (int)ShippingType.Weight:
                decimal cartProductWeight = Sessions.ProductTotalWeight;
                if (cartProductWeight <= shipping.FirstWeight)
                {
                    shippingMoney = shippingRegion.FirstMoney;
                }
                else
                {
                    shippingMoney = shippingRegion.FirstMoney + Math.Ceiling((cartProductWeight - shipping.FirstWeight) / shipping.AgainWeight) * shippingRegion.AgainMoney;
                }
                break;

            case (int)ShippingType.ProductCount:
                int cartProductCount = Sessions.ProductBuyCount;
                shippingMoney = shippingRegion.OneMoeny + (cartProductCount - 1) * shippingRegion.AnotherMoeny;
                break;

            default:
                break;
            }
            //计算优惠费用
            FavorableActivityInfo favorableActivity = FavorableActivityBLL.Read(DateTime.Now, DateTime.Now, 0);
            if (favorableActivity.Id > 0)
            {
                if (("," + favorableActivity.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && Sessions.ProductTotalPrice >= favorableActivity.OrderProductMoney)
                {
                    switch (favorableActivity.ReduceWay)
                    {
                    case (int)FavorableMoney.Money:
                        favorableMoney += favorableActivity.ReduceMoney;
                        break;

                    case (int)FavorableMoney.Discount:
                        favorableMoney += Sessions.ProductTotalPrice * (10 - favorableActivity.ReduceDiscount) / 10;
                        break;

                    default:
                        break;
                    }
                    if (favorableActivity.ShippingWay == (int)FavorableShipping.Free && ShippingRegionBLL.IsRegionIn(regionID, favorableActivity.RegionId))
                    {
                        favorableMoney += shippingMoney;
                    }
                }
            }
            #endregion

            decimal balance = RequestHelper.GetForm <decimal>("Balance");
            moneyLeft = UserBLL.ReadUserMore(base.UserId).MoneyLeft;
            if (balance > moneyLeft)
            {
                balance = 0;
                ScriptHelper.AlertFront("金额有错误,请重新检查", url);
            }


            decimal        couponMoney   = 0;
            string         userCouponStr = RequestHelper.GetForm <string>("UserCoupon");
            UserCouponInfo userCoupon    = new UserCouponInfo();
            if (userCouponStr != string.Empty)
            {
                int couponID = 0;
                if (int.TryParse(userCouponStr.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)[0], out couponID))
                {
                    userCoupon = UserCouponBLL.Read(couponID, base.UserId);
                    if (userCoupon.UserId == base.UserId && userCoupon.IsUse == 0)
                    {
                        couponMoney = CouponBLL.Read(userCoupon.CouponId).Money;
                    }
                }
            }
            if (productMoney - favorableMoney + shippingMoney - balance - couponMoney < 0)
            {
                ScriptHelper.AlertFront("金额有错误,请重新检查", url);
            }
            //支付方式
            string         payKey     = RequestHelper.GetForm <string>("Pay");
            PayPluginsInfo payPlugins = PayPlugins.ReadPayPlugins(payKey);
            //添加订单
            OrderInfo order = new OrderInfo();
            order.OrderNumber = ShopCommon.CreateOrderNumber();
            order.IsActivity  = (int)BoolType.False;
            if (productMoney - favorableMoney + shippingMoney - balance - couponMoney == 0 || payPlugins.IsCod == (int)BoolType.True)
            {
                order.OrderStatus = (int)OrderStatus.WaitCheck;
            }
            else
            {
                order.OrderStatus = (int)OrderStatus.WaitPay;
            }
            order.OrderNote      = string.Empty;
            order.ProductMoney   = productMoney;
            order.Balance        = balance;
            order.FavorableMoney = favorableMoney;
            order.OtherMoney     = 0;
            order.CouponMoney    = couponMoney;
            order.Consignee      = consignee;
            SingleUnlimitClass singleUnlimitClass = new SingleUnlimitClass();
            order.RegionId = singleUnlimitClass.ClassID;
            order.Address  = address;
            order.ZipCode  = zipCode;
            order.Tel      = tel;
            if (base.UserId == 0)
            {
                order.Email = StringHelper.AddSafe(RequestHelper.GetForm <string>("Email"));
            }
            else
            {
                order.Email = CookiesHelper.ReadCookieValue("UserEmail");
            }
            order.Mobile              = mobile;
            order.ShippingId          = shippingID;
            order.ShippingDate        = RequestHelper.DateNow;
            order.ShippingNumber      = string.Empty;
            order.ShippingMoney       = shippingMoney;
            order.PayKey              = payKey;
            order.PayName             = payPlugins.Name;
            order.PayDate             = RequestHelper.DateNow;;
            order.IsRefund            = (int)BoolType.False;
            order.FavorableActivityId = RequestHelper.GetForm <int>("FavorableActivityID");
            order.GiftId              = RequestHelper.GetForm <int>("GiftID");
            order.InvoiceTitle        = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceTitle"));
            order.InvoiceContent      = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceContent"));
            order.UserMessage         = StringHelper.AddSafe(RequestHelper.GetForm <string>("UserMessage"));
            order.AddDate             = RequestHelper.DateNow;
            order.IP       = ClientHelper.IP;
            order.UserId   = base.UserId;
            order.UserName = base.UserName;
            int orderID = OrderBLL.Add(order);
            //使用余额
            if (balance > 0)
            {
                UserAccountRecordInfo userAccountRecord = new UserAccountRecordInfo();
                userAccountRecord.Money    = -balance;
                userAccountRecord.Point    = 0;
                userAccountRecord.Date     = RequestHelper.DateNow;
                userAccountRecord.IP       = ClientHelper.IP;
                userAccountRecord.Note     = "支付订单:";
                userAccountRecord.UserId   = base.UserId;
                userAccountRecord.UserName = base.UserName;
                UserAccountRecordBLL.Add(userAccountRecord);
            }
            //使用优惠券
            string strUserCoupon = RequestHelper.GetForm <string>("UserCoupon");
            if (couponMoney > 0 && strUserCoupon != "0|0")
            {
                userCoupon.IsUse   = (int)BoolType.True;
                userCoupon.OrderId = orderID;
                UserCouponBLL.Update(userCoupon);
            }
            AddOrderProduct(orderID);
            //更改产品库存订单数量
            ProductBLL.ChangeOrderCountByOrder(orderID, ChangeAction.Plus);
            ResponseHelper.Redirect("/Mobile/Finish-I" + orderID.ToString() + ".html");
        }
Exemple #10
0
        protected override void PageLoad()
        {
            base.PageLoad();

            string action = RequestHelper.GetQueryString <string>("Action");

            switch (action)
            {
            case "Submit":
                this.Submit();
                break;
            }

            //登录验证
            if (base.UserId <= 0)
            {
                string redirectUrl = string.IsNullOrEmpty(isMobile)
                    ? "/user/login.html?RedirectUrl=/checkout.html"
                    : isMobile + "/login.aspx?RedirectUrl=/mobile/CheckOut.aspx";

                ResponseHelper.Redirect(redirectUrl);
                ResponseHelper.End();
            }

            //购物车验证
            checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));
            int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
            if (string.IsNullOrEmpty(checkCart) || cartIds.Length < 1)
            {
                ResponseHelper.Redirect("/cart.html");
                ResponseHelper.End();
            }

            //用户信息
            var user = UserBLL.Read(base.UserId);

            //cart list
            #region cart list
            //商品清单
            cartList = CartBLL.ReadList(base.UserId);
            cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList();
            if (cartList.Count < 1)
            {
                ResponseHelper.Redirect("/cart.html");
                ResponseHelper.End();
            }

            //关联的商品
            int   count    = 0;
            int[] ids      = cartList.Select(k => k.ProductId).ToArray();
            var   products = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            //规格
            foreach (var cart in cartList)
            {
                cart.Product = products.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo();

                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    //使用规格的价格和库存
                    var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    cart.Price            = standardRecord.SalePrice;
                    cart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount;
                    //规格集合
                    cart.Standards = ProductTypeStandardBLL.ReadList(Array.ConvertAll <string, int>(standardRecord.StandardIdList.Split(';'), k => Convert.ToInt32(k)));
                }
                else
                {
                    cart.Price            = cart.Product.SalePrice;
                    cart.LeftStorageCount = cart.Product.TotalStorageCount - cart.Product.OrderCount;
                }
            }
            #endregion

            //收货地址
            addressList = UserAddressBLL.ReadList(base.UserId);
            addressList = addressList.OrderByDescending(k => k.IsDefault).ToList();
            singleUnlimitClass.DataSource = RegionBLL.ReadRegionUnlimitClass();

            var totalProductMoney = cartList.Sum(k => k.BuyCount * k.Price);
            //取得图楼卡余额的webservice
            if (!string.IsNullOrEmpty(user.CardNo) && !string.IsNullOrEmpty(user.CardPwd))
            {
                bool isSuccess; string msg;
                isSuccess = true;
                msg       = "";
                //var account = WebService.Account.GetAccount(user.CardNo, user.CardPwd, out isSuccess, out msg);
                moneyLeft = 0;// account.Zacc + account.Sacc;
                if (moneyLeft > 0)
                {
                    moneyCanUse = moneyLeft > totalProductMoney ? totalProductMoney : moneyLeft;
                }
            }

            /*----------------不可使用积分-------------------------------------------------------------------------
            *  decimal totalRate = (decimal)ShopConfig.ReadConfigInfo().BuyPointTotalRate;
            *  decimal pointRate = (decimal)ShopConfig.ReadConfigInfo().BuyPointMoneyRate;
            *  if (totalRate > 0 && pointRate > 0 && pointLeft > 0)
            *  {
            *   var pointPayMoney = Math.Round(totalProductMoney * totalRate, 2, MidpointRounding.AwayFromZero);
            *   pointCanUse = pointPayMoney * pointRate;
            *   if (pointCanUse > pointLeft)
            *   {
            *       pointCanUse = pointLeft;
            *   }
            *  }
            *  ----------------不可使用积分-------------------------------------------------------------------------*/

            //支付方式列表
            payPluginsList = PayPlugins.ReadProductBuyPayPluginsList();

            Title = "结算中心";
        }
Exemple #11
0
        private void Submit()
        {
            /*-----------重新验证选择的商品------------------------------------------*/
            checkCart = StringHelper.AddSafe(RequestHelper.GetForm <string>("CheckCart"));
            int[]  cartIds          = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
            string checkCartCookies = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));

            if (checkCart != checkCartCookies)
            {
                ResponseHelper.Write("error|购买商品发生了变化,请重新提交|" + isMobile + "/cart.html");
                ResponseHelper.End();
            }

            if (string.IsNullOrEmpty(checkCart) || cartIds.Length < 1)
            {
                ResponseHelper.Write("error|请选择需要购买的商品|" + isMobile + "/cart.html");
                ResponseHelper.End();
            }
            /*----------------------------------------------------------------------*/

            /*-----------读取购物车清单---------------------------------------------*/
            List <CartInfo> cartList = CartBLL.ReadList(base.UserId);

            cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList();
            if (cartList.Count <= 0)
            {
                ResponseHelper.Write("error|请选择需要购买的商品|" + isMobile + "/cart.html");
                ResponseHelper.End();
            }
            /*----------------------------------------------------------------------*/

            /*-----------必要性检查:收货地址,配送方式,支付方式-------------------*/
            var address = new UserAddressInfo {
                Id = RequestHelper.GetForm <int>("address_id")
            };
            var shipping = new ShippingInfo {
                Id = RequestHelper.GetForm <int>("ShippingId")
            };
            var pay = new PayPluginsInfo {
                Key = StringHelper.AddSafe(RequestHelper.GetForm <string>("pay"))
            };

            bool reNecessaryCheck = false;

doReNecessaryCheck:
            if (address.Id < 1)
            {
                ResponseHelper.Write("error|请选择收货地址|");
                ResponseHelper.End();
            }
            if (shipping.Id < 1)
            {
                ResponseHelper.Write("error|请选择配送方式|");
                ResponseHelper.End();
            }
            if (string.IsNullOrEmpty(pay.Key))
            {
                ResponseHelper.Write("error|请选择支付方式|");
                ResponseHelper.End();
            }

            //读取数据库中的数据,进行重复验证
            if (!reNecessaryCheck)
            {
                address  = UserAddressBLL.Read(address.Id, base.UserId);
                shipping = ShippingBLL.Read(shipping.Id);
                pay      = PayPlugins.ReadPayPlugins(pay.Key);

                reNecessaryCheck = true;
                goto doReNecessaryCheck;
            }
            /*----------------------------------------------------------------------*/

            /*-----------商品清单、商品总价、邮费价格、库存检查---------------------*/
            decimal productMoney = 0;
            int     count        = 0;

            int[] ids      = cartList.Select(k => k.ProductId).ToArray();
            var   products = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            foreach (var cart in cartList)
            {
                cart.Product = products.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo();

                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    //使用规格的价格和库存
                    var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    cart.Price            = standardRecord.SalePrice;
                    cart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount;
                }
                else
                {
                    cart.Price            = cart.Product.SalePrice;
                    cart.LeftStorageCount = cart.Product.TotalStorageCount - cart.Product.OrderCount;
                }

                //不需要检查库存,所有商品均可购买
                ////检查库存
                //if (cart.BuyCount > cart.LeftStorageCount)
                //{
                //    ResponseHelper.Write("error|商品[" + cart.ProductName + "]库存不足,无法购买|");
                //    ResponseHelper.End();
                //}

                productMoney += cart.BuyCount * cart.Price;
            }

            decimal shippingMoney = 0;
            //首先根据ShopId分组,根据供应商的不同来分别计算运费
            //然后将分拆后的供应商商品,按单个商品独立计算运费(相同商品购买多个则叠加计算)
            ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shipping.Id, address.RegionId);

            var shopIds = cartList.GroupBy(k => k.Product.ShopId).Select(k => k.Key).ToList();

            foreach (var shopId in shopIds)
            {
                var shopCartList = cartList.Where(k => k.Product.ShopId == shopId).ToList();
                foreach (var shopCartSplit in shopCartList)
                {
                    shippingMoney += ShippingRegionBLL.ReadShippingMoney(shipping, shippingRegion, shopCartSplit);
                }
            }
            /*----------------------------------------------------------------------*/

            int     point      = 0;
            decimal pointMoney = 0;

            /*-----------计算积分金额(不可使用积分)-----------------------------------
             * decimal totalRate = (decimal)ShopConfig.ReadConfigInfo().BuyPointTotalRate;
             * decimal pointRate = (decimal)ShopConfig.ReadConfigInfo().BuyPointMoneyRate;
             * int point = RequestHelper.GetForm<int>("point");
             * decimal pointMoney = 0;
             * if (totalRate > 0 && pointRate > 0 && point > 0)
             * {
             *  var member = WebService.Member.GetMember();
             *  decimal leftPoint = member.Point;
             *  if (point > leftPoint)
             *  {
             *      ResponseHelper.Write("error|您的积分不足|");
             *      ResponseHelper.End();
             *  }
             *  else
             *  {
             *      pointMoney = Math.Round(point / pointRate, 2);
             *
             *      if (pointMoney > productMoney * totalRate)
             *      {
             *          ResponseHelper.Write("error|" + "您最多可以使用 " + (productMoney * totalRate * pointRate) + " 积分|");
             *          ResponseHelper.End();
             *      }
             *  }
             * }
             * ------------------------------------------------------------------------*/

            /*-----------应付总价---------------------------------------------------*/
            //decimal payMoney = productMoney + shippingMoney - pointMoney;
            decimal payMoney = productMoney + shippingMoney;
            /*----------------------------------------------------------------------*/

            var user = UserBLL.Read(base.UserId);
            /*-----------计算图楼卡余额---------------------------------------------*/
            decimal balance = RequestHelper.GetForm <decimal>("money");

            if (balance > 0)
            {
                bool isSuccess; string msg;
                isSuccess = true;
                msg       = "";
                //var account = WebService.Account.GetAccount(user.CardNo, user.CardPwd, out isSuccess, out msg);
                if (!isSuccess)
                {
                    ResponseHelper.Write("error|" + msg + "|");
                    ResponseHelper.End();
                }

                if (balance > 0 /*(account.Zacc + account.Sacc)*/)
                {
                    ResponseHelper.Write("error|您的图楼卡余额不足|");
                    ResponseHelper.End();
                }
                else
                {
                    if (balance > payMoney)
                    {
                        ResponseHelper.Write("error|" + "您只需使用 " + payMoney + " 元即可支付订单|");
                        ResponseHelper.End();
                    }
                }
            }
            payMoney -= balance;
            /*----------------------------------------------------------------------*/

            /*-----------检查金额---------------------------------------------------*/
            if (payMoney < 0)
            {
                ResponseHelper.Write("error|金额有错误,请重新检查|");
                ResponseHelper.End();
            }
            /*----------------------------------------------------------------------*/

            /*-----------组装基础订单模型,循环生成订单-----------------------------*/
            OrderInfo order = new OrderInfo();

            order.ProductMoney  = productMoney;
            order.Consignee     = address.Consignee;
            order.RegionId      = address.RegionId;
            order.Address       = address.Address;
            order.ZipCode       = address.ZipCode;
            order.Tel           = address.Tel;
            order.Mobile        = address.Mobile;
            order.Email         = CookiesHelper.ReadCookieValue("UserEmail");
            order.ShippingId    = shipping.Id;
            order.ShippingDate  = RequestHelper.DateNow;
            order.ShippingMoney = shippingMoney;
            order.Point         = point;
            order.PointMoney    = pointMoney;
            order.Balance       = balance;
            order.PayKey        = pay.Key;
            order.PayName       = pay.Name;
            order.PayDate       = RequestHelper.DateNow;
            order.IsRefund      = (int)BoolType.False;
            order.UserMessage   = StringHelper.AddSafe(RequestHelper.GetForm <string>("msg"));
            order.AddDate       = RequestHelper.DateNow;
            order.IP            = ClientHelper.IP;
            order.UserId        = base.UserId;
            order.UserName      = base.UserName;

            //循环生成订单
            var orderIds = SplitShopProduct(cartList, order);
            /*----------------------------------------------------------------------*/

            var orders = OrderBLL.ReadList(orderIds.ToArray(), base.UserId);

            /*-----------如果使用了图楼卡支付,需同步到会员管理系统中---------------*/
            /*第二步,在订单付款操作(用户端)中,同步图楼卡余额*/
            if (balance > 0)
            {
                List <string[]> paras = new List <string[]>();
                foreach (var oo in orders)
                {
                    if (oo.Balance > 0 && oo.OrderStatus == (int)OrderStatus.WaitCheck)
                    {
                        string[] para = new string[2];
                        para[0] = oo.OrderNumber;
                        para[1] = oo.Balance.ToString();
                        paras.Add(para);
                    }
                }

                //如果有全额使用了图楼卡余额支付的订单,需同步到会员管理系统中
                if (paras.Count > 0)
                {
                    bool isSuccess; string msg;
                    isSuccess = true;
                    msg       = "";
                    //WebService.Account.Purchase(user.CardNo, user.CardPwd, paras, out isSuccess, out msg);

                    //同步失败,删除订单及相关信息
                    if (!isSuccess)
                    {
                        //删除订单、订单详细、订单状态相关数据
                        OrderBLL.Delete(orderIds.ToArray(), base.UserId);

                        //更改产品库存订单数量
                        foreach (var orderId in orderIds)
                        {
                            ProductBLL.ChangeOrderCountByOrder(orderId, ChangeAction.Minus);
                        }
                        ResponseHelper.Write("error|" + msg + "|");
                        ResponseHelper.End();
                    }
                    else
                    {
                        //记录用户余额消费记录
                        foreach (var par in paras)
                        {
                            var accountRecord = new UserAccountRecordInfo
                            {
                                RecordType = (int)AccountRecordType.Money,
                                Money      = -decimal.Parse(par[1]),
                                Point      = 0,
                                Date       = DateTime.Now,
                                IP         = ClientHelper.IP,
                                Note       = "支付订单:" + par[0],
                                UserId     = base.UserId,
                                UserName   = base.UserName
                            };
                            UserAccountRecordBLL.Add(accountRecord);
                        }
                    }
                }
            }
            /*----------------------------------------------------------------------*/

            /*-----------删除购物车中已下单的商品-----------------------------------*/
            CartBLL.Delete(cartIds, base.UserId);
            CookiesHelper.DeleteCookie("CheckCart");
            /*----------------------------------------------------------------------*/

            /*如果所有订单均由图楼卡支付完成,则跳转到会员中心,否则跳转到支付提示页面*/
            if (orders.Count(k => k.OrderStatus == (int)OrderStatus.WaitPay) > 0)
            {
                ResponseHelper.Write("ok||/finish.html?id=" + string.Join(",", orders.Select(k => k.Id).ToArray()));
            }
            else
            {
                ResponseHelper.Write("ok||/user/index.html");
            }
            ResponseHelper.End();
            /*----------------------------------------------------------------------*/
        }
Exemple #12
0
        protected override void PageLoad()
        {
            base.PageLoad();
            //检查用户的待付款订单是否超时失效,超时则更新为失效状态
            OrderBLL.CheckOrderPayTime(base.UserId);
            type     = RequestHelper.GetQueryString <string>("type");
            cartList = CartBLL.ReadList(base.UserId);
            topNav   = 7;
            keywords = RequestHelper.GetQueryString <string>("keywords");
            int currentPage = RequestHelper.GetQueryString <int>("Page");

            if (currentPage < 1)
            {
                currentPage = 1;
            }
            int             pageSize    = 10;
            int             count       = 0;
            OrderSearchInfo orderSearch = new OrderSearchInfo();

            orderSearch.UserId   = base.UserId;
            orderSearch.IsDelete = 0;
            if (!string.IsNullOrEmpty(keywords))
            {
                orderSearch.OrderNumber = keywords;
            }
            if (!string.IsNullOrEmpty(type))
            {
                int tt = 0;
                switch (type)
                {
                case "1": tt = (int)OrderStatus.WaitPay; break;

                case "2": tt = (int)OrderStatus.WaitCheck; break;

                case "3": tt = (int)OrderStatus.Shipping; break;

                case "4": tt = (int)OrderStatus.HasShipping; break;

                case "5": tt = (int)OrderStatus.NoEffect; break;
                }
                orderSearch.OrderStatus = tt;
            }

            orderList = OrderBLL.SearchList(currentPage, pageSize, orderSearch, ref count);
            //commonPagerClass.CurrentPage = currentPage;
            //commonPagerClass.PageSize = pageSize;
            //commonPagerClass.Count = count;
            //commonPagerClass.FirstPage = "<<首页";
            //commonPagerClass.PreviewPage = "<<上一页";
            //commonPagerClass.NextPage = "下一页>>";
            //commonPagerClass.LastPage = "末页>>";
            //commonPagerClass.ListType = false;
            //commonPagerClass.DisCount = false;
            //commonPagerClass.PrenextType = true;
            commonPagerClass.Init(currentPage, pageSize, count, !string.IsNullOrEmpty(isMobile));

            proListHot = ProductBLL.SearchList(1, 12, new ProductSearchInfo {
                IsHot = 1,
            }, ref count);
            #region 对应状态个数
            //OrderSearchInfo orderSearch1 = new OrderSearchInfo();
            //orderSearch1.UserId = base.UserId;
            //if (!string.IsNullOrEmpty(keywords))
            //{
            //    orderSearch1.OrderNumber = keywords;
            //}
            arrT[0] = OrderBLL.SearchList(currentPage, pageSize, new OrderSearchInfo {
                UserId = base.UserId, IsDelete = 0
            }, ref count).Count;
            orderSearch.OrderStatus = (int)(OrderStatus.WaitPay);
            arrT[1] = OrderBLL.SearchList(currentPage, pageSize, orderSearch, ref count).Count;
            orderSearch.OrderStatus = (int)(OrderStatus.Shipping);
            arrT[2] = OrderBLL.SearchList(currentPage, pageSize, orderSearch, ref count).Count;
            orderSearch.OrderStatus = (int)(OrderStatus.HasShipping);
            arrT[3] = OrderBLL.SearchList(currentPage, pageSize, orderSearch, ref count).Count;
            orderSearch.OrderStatus = (int)(OrderStatus.WaitCheck);
            arrT[4] = OrderBLL.SearchList(currentPage, pageSize, orderSearch, ref count).Count;
            orderSearch.OrderStatus = (int)(OrderStatus.NoEffect);
            arrT[5] = OrderBLL.SearchList(currentPage, pageSize, orderSearch, ref count).Count;
            #endregion
        }
        private void SelectShipping()
        {
            int    shippingId = RequestHelper.GetQueryString <int>("shippingId");
            int    addressId  = RequestHelper.GetQueryString <int>("addressId");
            int    favorId    = RequestHelper.GetQueryString <int>("favorId");
            string checkCart  = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));

            int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
            if (string.IsNullOrEmpty(checkCart) || cartIds.Length < 1)
            {
                ResponseHelper.Write("error|请选择需要购买的商品");
                ResponseHelper.End();
            }

            var address = UserAddressBLL.Read(addressId, base.UserId);

            //计算配送费用
            List <CartInfo> cartList = CartBLL.ReadList(base.UserId).Where(k => cartIds.Contains(k.Id)).ToList();

            if (cartList.Count < 1)
            {
                ResponseHelper.Write("error|请选择需要购买的商品");
                ResponseHelper.End();
            }

            int count = 0;
            //购物车结算金额
            decimal cartTotalPrice = 0;

            int[] ids         = cartList.Select(k => k.ProductId).ToArray();
            var   productList = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            cartList.ForEach(k => k.Product = productList.FirstOrDefault(k2 => k2.Id == k.ProductId) ?? new ProductInfo());
            foreach (var cart in cartList)
            {
                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    //使用规格的价格和库存
                    var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    cartTotalPrice += ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID) * cart.BuyCount;
                }
                else
                {
                    cartTotalPrice += ProductBLL.GetCurrentPrice(cart.Product.SalePrice, base.GradeID) * cart.BuyCount;
                }
            }

            ShippingInfo       shipping       = ShippingBLL.Read(shippingId);
            ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shippingId, address.RegionId);

            decimal shippingMoney  = ShippingRegionBLL.ReadShippingMoney(shippingId, address.RegionId, cartList);
            decimal favorableMoney = 0;

            #region 计算优惠费用--原始方式
            //FavorableActivityInfo favorableActivity = FavorableActivityBLL.Read(DateTime.Now, DateTime.Now, 0);
            //if (favorableActivity.Id > 0)
            //{
            //    if (("," + favorableActivity.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && Sessions.ProductTotalPrice >= favorableActivity.OrderProductMoney)
            //    {
            //        switch (favorableActivity.ReduceWay)
            //        {
            //            case (int)FavorableMoney.Money:
            //                favorableMoney += favorableActivity.ReduceMoney;
            //                break;
            //            case (int)FavorableMoney.Discount:
            //                favorableMoney += Sessions.ProductTotalPrice * (100 - favorableActivity.ReduceDiscount) / 100;
            //                break;
            //            default:
            //                break;
            //        }
            //        if (favorableActivity.ShippingWay == (int)FavorableShipping.Free && ShippingRegionBLL.IsRegionIn(address.RegionId, favorableActivity.RegionId))
            //        {
            //            favorableMoney += shippingMoney;
            //        }
            //    }
            //}
            #endregion
            #region 计算优惠费用
            if (favorId > 0)
            {
                var theFavorable = FavorableActivityBLL.Read(favorId);
                if (("," + theFavorable.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && cartTotalPrice >= theFavorable.OrderProductMoney)
                {
                    switch (theFavorable.ReduceWay)
                    {
                    case (int)FavorableMoney.Money:
                        favorableMoney += theFavorable.ReduceMoney;
                        break;

                    case (int)FavorableMoney.Discount:
                        favorableMoney += cartTotalPrice * (100 - theFavorable.ReduceDiscount) / 100;
                        break;

                    default:
                        break;
                    }
                    if (theFavorable.ShippingWay == (int)FavorableShipping.Free && ShippingRegionBLL.IsRegionIn(address.RegionId, theFavorable.RegionId))
                    {
                        favorableMoney += shippingMoney;
                    }
                }
            }
            #endregion
            ResponseHelper.Write("ok|" + Math.Round(shippingMoney, 2).ToString() + "|" + Math.Round(favorableMoney, 2));
            ResponseHelper.End();
        }
Exemple #14
0
        protected override void PageLoad()
        {
            base.PageLoad();
            istop = 1;
            string action = RequestHelper.GetQueryString <string>("Action");

            switch (action)
            {
            case "Submit":
                this.Submit();
                break;

            case "SelectProductFavor":   //读取商品优惠
                this.SelectProductFavor();
                break;

            case "ReadingGifts":    //读取礼品列表
                this.ReadingGifts();
                break;
            }

            //登录验证
            if (base.UserId <= 0)
            {
                ResponseHelper.Redirect("/user/login.html?RedirectUrl=/checkout.html");
                ResponseHelper.End();
            }
            if (base._UserType == (int)UserType.Provider)
            {
                ResponseHelper.Redirect("/");
                ResponseHelper.End();
            }

            //购物车验证
            checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));
            int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
            if (string.IsNullOrEmpty(checkCart) || cartIds.Length < 1)
            {
                ResponseHelper.Redirect("/cart.html");
                ResponseHelper.End();
            }

            //用户信息
            var user = UserBLL.ReadUserMore(base.UserId);

            //剩余积分
            pointLeft = user.PointLeft;
            //cart list
            #region cart list
            //商品清单
            cartList = CartBLL.ReadList(base.UserId);
            cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList();
            if (cartList.Count < 1)
            {
                ResponseHelper.Redirect("/cart.html");
                ResponseHelper.End();
            }

            //关联的商品
            int   count       = 0;
            int[] ids         = cartList.Select(k => k.ProductId).ToArray();
            var   productList = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            //规格
            foreach (var cart in cartList)
            {
                cart.Product = productList.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo();

                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    //使用规格的库存
                    var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    cart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount;
                    cart.Price            = ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID);
                    //规格集合
                    if (!string.IsNullOrEmpty(standardRecord.StandardIdList))
                    {
                        cart.Standards = ProductTypeStandardBLL.ReadList(Array.ConvertAll <string, int>(standardRecord.StandardIdList.Split(';'), k => Convert.ToInt32(k)));
                    }
                }
                else
                {
                    cart.Price            = ProductBLL.GetCurrentPrice(cart.Product.SalePrice, base.GradeID);
                    cart.LeftStorageCount = cart.Product.TotalStorageCount - cart.Product.OrderCount;
                }


                //检查库存
                if (cart.BuyCount > cart.LeftStorageCount)
                {
                    ScriptHelper.AlertFront("商品[" + cart.ProductName + "]库存不足,无法购买");
                    ResponseHelper.End();
                }
            }

            #endregion

            //收货地址
            addressList = UserAddressBLL.ReadList(base.UserId);
            addressList = addressList.OrderByDescending(k => k.IsDefault).ToList();
            singleUnlimitClass.DataSource = RegionBLL.ReadRegionUnlimitClass();

            var totalProductMoney = cartList.Sum(k => k.BuyCount * k.Price);

            //支付方式列表
            payPluginsList = PayPlugins.ReadProductBuyPayPluginsList();
            #region 优惠券
            if (user.Id > 0)
            {
                //读取优惠券
                List <UserCouponInfo> tempUserCouponList = UserCouponBLL.ReadCanUse(base.UserId);
                foreach (UserCouponInfo userCoupon in tempUserCouponList)
                {
                    CouponInfo tempCoupon = CouponBLL.Read(userCoupon.CouponId);
                    if (tempCoupon.UseMinAmount <= totalProductMoney)
                    {
                        userCouponList.Add(userCoupon);
                    }
                }
            }
            #endregion
            #region 获取符合条件(时间段,用户等级,金额限制)的商品分类优惠活动列表,默认使用第一个

            var tmpfavorableActivityList = FavorableActivityBLL.ReadList(DateTime.Now, DateTime.Now).Where <FavorableActivityInfo>(f => f.Type == (int)FavorableType.ProductClass && ("," + f.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1).ToList();
            foreach (var favorable in tmpfavorableActivityList)
            {
                decimal tmoney = 0;
                //tmoney = cartList.Where(c => c.Product.ClassId.IndexOf(favorable.ClassIds) > -1).Sum(k => k.BuyCount * k.Price);
                foreach (var tmpcart in cartList)
                {
                    if (tmpcart.Product.ClassId.IndexOf(favorable.ClassIds) > -1)
                    {
                        if (!string.IsNullOrEmpty(tmpcart.StandardValueList))
                        {
                            //使用规格的库存
                            var standardRecord = ProductTypeStandardRecordBLL.Read(tmpcart.ProductId, tmpcart.StandardValueList);
                            tmpcart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount;
                            tmpcart.Price            = ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID);
                            tmoney += tmpcart.Price * tmpcart.BuyCount;
                        }
                        else
                        {
                            tmpcart.Price = ProductBLL.GetCurrentPrice(tmpcart.Product.SalePrice, base.GradeID);
                            tmoney       += tmpcart.Price * tmpcart.BuyCount;
                        }
                    }
                }
                if (tmoney >= favorable.OrderProductMoney)
                {
                    productFavorableActivityList.Add(favorable);
                }
            }
            #endregion
            Title = "结算中心";
        }
Exemple #15
0
        private void Submit()
        {
            /*-----------重新验证选择的商品------------------------------------------*/
            checkCart = StringHelper.AddSafe(RequestHelper.GetForm <string>("CheckCart"));
            int[]  cartIds          = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
            string checkCartCookies = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));

            if (checkCart != checkCartCookies)
            {
                ResponseHelper.Write("error|购买商品发生了变化,请重新提交|/cart.html");
                ResponseHelper.End();
            }

            if (string.IsNullOrEmpty(checkCart) || cartIds.Length < 1)
            {
                ResponseHelper.Write("error|请选择需要购买的商品|/cart.html");
                ResponseHelper.End();
            }
            /*----------------------------------------------------------------------*/

            /*-----------读取购物车清单---------------------------------------------*/
            List <CartInfo> cartList = CartBLL.ReadList(base.UserId);

            cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList();
            if (cartList.Count <= 0)
            {
                ResponseHelper.Write("error|请选择需要购买的商品|/cart.html");
                ResponseHelper.End();
            }
            /*----------------------------------------------------------------------*/

            /*-----------必要性检查:收货地址,配送方式,支付方式-------------------*/
            var address = new UserAddressInfo {
                Id = RequestHelper.GetForm <int>("address_id")
            };
            var shipping = new ShippingInfo {
                Id = RequestHelper.GetForm <int>("ShippingId")
            };
            var pay = new PayPluginsInfo {
                Key = StringHelper.AddSafe(RequestHelper.GetForm <string>("pay"))
            };
            //订单优惠活动
            var favor = new FavorableActivityInfo {
                Id = RequestHelper.GetForm <int>("FavorableActivity")
            };
            //商品优惠
            var productfavor = new FavorableActivityInfo {
                Id = RequestHelper.GetForm <int>("ProductFavorableActivity")
            };
            bool reNecessaryCheck = false;

doReNecessaryCheck:
            if (address.Id < 1)
            {
                ResponseHelper.Write("error|请选择收货地址|");
                ResponseHelper.End();
            }
            if (shipping.Id < 1)
            {
                ResponseHelper.Write("error|请选择配送方式|");
                ResponseHelper.End();
            }
            if (string.IsNullOrEmpty(pay.Key))
            {
                ResponseHelper.Write("error|请选择支付方式|");
                ResponseHelper.End();
            }

            //读取数据库中的数据,进行重复验证
            if (!reNecessaryCheck)
            {
                address  = UserAddressBLL.Read(address.Id, base.UserId);
                shipping = ShippingBLL.Read(shipping.Id);
                pay      = PayPlugins.ReadPayPlugins(pay.Key);

                reNecessaryCheck = true;
                goto doReNecessaryCheck;
            }
            /*----------------------------------------------------------------------*/

            /*-----------商品清单、商品总价、邮费价格、库存检查---------------------*/
            var     user = UserBLL.ReadUserMore(base.UserId);
            decimal productMoney = 0, pointMoney = 0;
            int     count = 0;
            //输入的兑换积分数
            var costPoint = RequestHelper.GetForm <int>("costPoint");

            int[] ids         = cartList.Select(k => k.ProductId).ToArray();
            var   productList = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            foreach (var cart in cartList)
            {
                cart.Product = productList.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo();

                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    //使用规格的库存
                    var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    cart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount;
                    productMoney         += ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID) * (cart.BuyCount);
                }
                else
                {
                    cart.LeftStorageCount = cart.Product.TotalStorageCount - cart.Product.OrderCount;
                    productMoney         += ProductBLL.GetCurrentPrice(cart.Product.SalePrice, base.GradeID) * (cart.BuyCount);
                }

                //检查库存
                if (cart.BuyCount > cart.LeftStorageCount)
                {
                    ResponseHelper.Write("error|商品[" + cart.ProductName + "]库存不足,无法购买|");
                    ResponseHelper.End();
                }
            }

            ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shipping.Id, address.RegionId);
            decimal            shippingMoney  = ShippingRegionBLL.ReadShippingMoney(shipping.Id, shippingRegion.RegionId, cartList);

            /*----------------------------------------------------------------------*/
            #region 优惠券
            decimal        couponMoney   = 0;
            string         userCouponStr = RequestHelper.GetForm <string>("UserCoupon");
            UserCouponInfo userCoupon    = new UserCouponInfo();
            if (userCouponStr != string.Empty)
            {
                int couponID = 0;
                if (int.TryParse(userCouponStr.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)[0], out couponID))
                {
                    userCoupon = UserCouponBLL.Read(couponID, base.UserId);
                    if (userCoupon.UserId == base.UserId && userCoupon.IsUse == 0)
                    {
                        CouponInfo tempCoupon = CouponBLL.Read(userCoupon.CouponId);
                        if (tempCoupon.UseMinAmount <= productMoney)
                        {
                            couponMoney = CouponBLL.Read(userCoupon.CouponId).Money;
                        }
                        else
                        {
                            ResponseHelper.Write("error|结算金额小于该优惠券要求的最低消费的金额|");
                            ResponseHelper.End();
                        }
                    }
                }
            }
            #endregion
            #region 如果开启了:使用积分抵现,计算积分抵现的现金金额
            if (ShopConfig.ReadConfigInfo().EnablePointPay == 1)
            {
                if (costPoint > user.PointLeft || costPoint < 0)
                {
                    ResponseHelper.Write("error|输入的兑换积分数[" + costPoint + "]错误,请检查|");
                    ResponseHelper.End();
                }
                if (costPoint > 0)
                {
                    var PointToMoneyRate = ShopConfig.ReadConfigInfo().PointToMoney;
                    pointMoney = costPoint * (decimal)PointToMoneyRate / 100;
                }
            }
            #endregion
            #region 结算商品优惠金额
            decimal productfavorableMoney = 0;
            var     theFavor = FavorableActivityBLL.Read(productfavor.Id);
            if (theFavor.Id > 0)
            {
                decimal tmoney = 0;
                foreach (var tmpcart in cartList)
                {
                    tmpcart.Product = productList.FirstOrDefault(k => k.Id == tmpcart.ProductId) ?? new ProductInfo();
                    if (tmpcart.Product.ClassId.IndexOf(theFavor.ClassIds) > -1)
                    {
                        if (!string.IsNullOrEmpty(tmpcart.StandardValueList))
                        {
                            //使用规格的库存
                            var standardRecord = ProductTypeStandardRecordBLL.Read(tmpcart.ProductId, tmpcart.StandardValueList);
                            tmpcart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount;
                            tmpcart.Price            = ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID);
                            tmoney += tmpcart.Price * tmpcart.BuyCount;
                        }
                        else
                        {
                            tmpcart.Price = ProductBLL.GetCurrentPrice(tmpcart.Product.SalePrice, base.GradeID);
                            tmoney       += tmpcart.Price * tmpcart.BuyCount;
                        }
                    }
                }
                switch (theFavor.ReduceWay)
                {
                case (int)FavorableMoney.Money:
                    productfavorableMoney += theFavor.ReduceMoney;
                    break;

                case (int)FavorableMoney.Discount:
                    productfavorableMoney += tmoney * (100 - theFavor.ReduceDiscount) / 100;
                    break;

                default:
                    break;
                }
            }
            #endregion
            #region 计算订单优惠活动金额
            decimal favorableMoney = 0;
            favor = FavorableActivityBLL.Read(favor.Id);
            if (favor.Id > 0)
            {
                if (("," + favor.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && productMoney >= favor.OrderProductMoney)
                {
                    switch (favor.ReduceWay)
                    {
                    case (int)FavorableMoney.Money:
                        favorableMoney += favor.ReduceMoney;
                        break;

                    case (int)FavorableMoney.Discount:
                        favorableMoney += productMoney * (100 - favor.ReduceDiscount) / 100;
                        break;

                    default:
                        break;
                    }
                    if (favor.ShippingWay == (int)FavorableShipping.Free && ShippingRegionBLL.IsRegionIn(address.RegionId, favor.RegionId))
                    {
                        favorableMoney += shippingMoney;
                    }
                }
            }
            #endregion
            /*-----------应付总价---------------------------------------------------*/
            decimal payMoney = productMoney + shippingMoney - couponMoney - pointMoney - favorableMoney - productfavorableMoney;
            /*----------------------------------------------------------------------*/

            /*-----------检查金额---------------------------------------------------*/
            if (payMoney <= 0)
            {
                ResponseHelper.Write("error|金额有错误,请重新检查|");
                ResponseHelper.End();
            }
            /*----------------------------------------------------------------------*/


            /*-----------组装基础订单模型,循环生成订单-----------------------------*/
            OrderInfo order = new OrderInfo();
            order.ProductMoney = productMoney;
            order.OrderNumber  = ShopCommon.CreateOrderNumber();
            string         payKey     = RequestHelper.GetForm <string>("Pay");
            PayPluginsInfo payPlugins = PayPlugins.ReadPayPlugins(payKey);
            if (payMoney == 0 || payPlugins.IsCod == (int)BoolType.True)
            {
                order.OrderStatus = (int)OrderStatus.WaitCheck;
            }
            else
            {
                order.OrderStatus = (int)OrderStatus.WaitPay;
            }
            order.Consignee      = address.Consignee;
            order.RegionId       = address.RegionId;
            order.Address        = address.Address;
            order.ZipCode        = address.ZipCode;
            order.Tel            = address.Tel;
            order.Mobile         = address.Mobile;
            order.InvoiceTitle   = RequestHelper.GetForm <string>("InvoiceTitle");
            order.InvoiceContent = RequestHelper.GetForm <string>("InvoiceContent");
            order.GiftMessige    = RequestHelper.GetForm <string>("GiftMessige");
            order.Email          = CookiesHelper.ReadCookieValue("UserEmail");
            order.ShippingId     = shipping.Id;
            order.ShippingDate   = RequestHelper.DateNow;
            order.ShippingMoney  = shippingMoney;
            order.CouponMoney    = couponMoney;
            order.Point          = costPoint;
            order.PointMoney     = pointMoney;
            order.FavorableMoney = favorableMoney + productfavorableMoney;
            order.Balance        = 0;
            order.PayKey         = pay.Key;
            order.PayName        = pay.Name;
            order.PayDate        = RequestHelper.DateNow;
            order.IsRefund       = (int)BoolType.False;
            order.AddDate        = RequestHelper.DateNow;
            order.IP             = ClientHelper.IP;
            order.UserId         = base.UserId;
            order.UserName       = base.UserName;
            order.UserMessage    = RequestHelper.GetForm <string>("userMessage");
            order.GiftId         = RequestHelper.GetForm <int>("GiftID");
            order.IsNoticed      = 0;
            int orderId = OrderBLL.Add(order);

            //添加订单产品
            foreach (var cart in cartList)
            {
                var orderDetail = new OrderDetailInfo();
                orderDetail.OrderId           = orderId;
                orderDetail.ProductId         = cart.ProductId;
                orderDetail.ProductName       = cart.ProductName;
                orderDetail.StandardValueList = cart.StandardValueList;
                orderDetail.ProductWeight     = cart.Product.Weight;
                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    orderDetail.ProductPrice = ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID);
                }
                else
                {
                    orderDetail.ProductPrice = ProductBLL.GetCurrentPrice(cart.Product.SalePrice, base.GradeID);
                }

                orderDetail.BidPrice = cart.Product.BidPrice;
                orderDetail.BuyCount = cart.BuyCount;

                OrderDetailBLL.Add(orderDetail);
            }
            #region 更新优惠券状态--已使用
            //使用优惠券
            if (couponMoney > 0 && userCouponStr != "0|0")
            {
                userCoupon.IsUse   = (int)BoolType.True;
                userCoupon.OrderId = orderId;
                UserCouponBLL.Update(userCoupon);
            }
            #endregion
            #region 减少积分
            if (ShopConfig.ReadConfigInfo().EnablePointPay == 1 && costPoint > 0)
            {
                //减少积分
                UserAccountRecordInfo uarInfo = new UserAccountRecordInfo();
                uarInfo.RecordType = (int)AccountRecordType.Point;
                uarInfo.UserId     = base.UserId;
                uarInfo.UserName   = base.UserName;
                uarInfo.Note       = "支付订单:" + order.OrderNumber;
                uarInfo.Point      = -costPoint;
                uarInfo.Money      = 0;
                uarInfo.Date       = DateTime.Now;
                uarInfo.IP         = ClientHelper.IP;
                UserAccountRecordBLL.Add(uarInfo);
            }
            #endregion
            /*-----------更改产品库存订单数量---------------------------------------*/
            ProductBLL.ChangeOrderCountByOrder(orderId, ChangeAction.Plus);
            /*----------------------------------------------------------------------*/

            /*-----------删除购物车中已下单的商品-----------------------------------*/
            CartBLL.Delete(cartIds, base.UserId);
            CookiesHelper.DeleteCookie("CheckCart");
            /*----------------------------------------------------------------------*/

            ResponseHelper.Write("ok||/Finish.html?id=" + orderId);
            ResponseHelper.End();
        }
Exemple #16
0
        /// <summary>
        /// 提交数据
        /// </summary>
        protected override void PostBack()
        {
            string url = "/Mobile/CheckOut.html";
            //检查地址
            string consignee = StringHelper.AddSafe(RequestHelper.GetForm <string>("Consignee"));

            if (consignee == string.Empty)
            {
                ScriptHelper.AlertFront("收货人姓名不能为空", url);
            }
            string tel    = StringHelper.AddSafe(RequestHelper.GetForm <string>("Tel"));
            string mobile = StringHelper.AddSafe(RequestHelper.GetForm <string>("Mobile"));

            if (tel == string.Empty && mobile == string.Empty)
            {
                ScriptHelper.AlertFront("固定电话,手机必须得填写一个", url);
            }
            string zipCode = StringHelper.AddSafe(RequestHelper.GetForm <string>("ZipCode"));
            string address = StringHelper.AddSafe(RequestHelper.GetForm <string>("Address"));

            if (address == string.Empty)
            {
                ScriptHelper.AlertFront("地址不能为空", url);
            }
            //验证配送方式
            int shippingID = RequestHelper.GetForm <int>("ShippingID");

            if (shippingID == int.MinValue)
            {
                ScriptHelper.AlertFront("请选择配送方式", url);
            }
            //检查支付方式
            string payKey = RequestHelper.GetForm <string>("Pay");

            if (string.IsNullOrEmpty(payKey))
            {
                ScriptHelper.AlertFront("请选择付款方式", url);
            }
            PayPluginsInfo payPlugins = PayPlugins.ReadPayPlugins(payKey);
            //检查金额
            decimal productMoney = 0, pointMoney = 0;
            var     user = UserBLL.ReadUserMore(base.UserId);

            #region 计算订单金额
            checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));
            int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));

            cartList = CartBLL.ReadList(base.UserId);
            cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList();
            if (cartList.Count < 1)
            {
                ResponseHelper.Redirect("/Mobile/cart.html");
                ResponseHelper.End();
            }

            //关联的商品
            int   count    = 0;
            int[] ids      = cartList.Select(k => k.ProductId).ToArray();
            var   products = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);

            //规格与库存判断
            foreach (var cart in cartList)
            {
                cart.Product = products.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo();

                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    //使用规格的价格和库存
                    var standardRecord   = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    int leftStorageCount = standardRecord.Storage - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList);
                    if (leftStorageCount >= cart.BuyCount)
                    {
                        cart.Price            = standardRecord.SalePrice;
                        cart.LeftStorageCount = leftStorageCount;
                        //规格集合
                        cart.Standards = ProductTypeStandardBLL.ReadList(Array.ConvertAll <string, int>(standardRecord.StandardIdList.Split(';'), k => Convert.ToInt32(k)));
                    }
                    else
                    {
                        ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html");
                    }
                }
                else
                {
                    int leftStorageCount = cart.Product.TotalStorageCount - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList);
                    if (leftStorageCount >= cart.BuyCount)
                    {
                        cart.Price            = cart.Product.SalePrice;
                        cart.LeftStorageCount = leftStorageCount;
                    }
                    else
                    {
                        ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html");
                    }
                }
            }
            #endregion
            productMoney = cartList.Sum(k => k.BuyCount * k.Price);


            decimal shippingMoney = 0;
            //订单优惠活动
            var favor = new FavorableActivityInfo {
                Id = RequestHelper.GetForm <int>("FavorableActivity")
            };
            //商品优惠
            var productfavor = new FavorableActivityInfo {
                Id = RequestHelper.GetForm <int>("ProductFavorableActivity")
            };
            #region 计算运费
            string regionID = RequestHelper.GetForm <string>("RegionID");
            //计算配送费用
            ShippingInfo       shipping       = ShippingBLL.Read(shippingID);
            ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shippingID, regionID);
            switch (shipping.ShippingType)
            {
            case (int)ShippingType.Fixed:
                shippingMoney = shippingRegion.FixedMoeny;
                break;

            case (int)ShippingType.Weight:
                decimal cartProductWeight = Sessions.ProductTotalWeight;
                if (cartProductWeight <= shipping.FirstWeight)
                {
                    shippingMoney = shippingRegion.FirstMoney;
                }
                else
                {
                    shippingMoney = shippingRegion.FirstMoney + Math.Ceiling((cartProductWeight - shipping.FirstWeight) / shipping.AgainWeight) * shippingRegion.AgainMoney;
                }
                break;

            case (int)ShippingType.ProductCount:
                int cartProductCount = Sessions.ProductBuyCount;
                shippingMoney = shippingRegion.OneMoeny + (cartProductCount - 1) * shippingRegion.AnotherMoeny;
                break;

            default:
                break;
            }
            #endregion

            //decimal balance = RequestHelper.GetForm<decimal>("Balance");
            //moneyLeft = UserBLL.ReadUserMore(base.UserId).MoneyLeft;
            //if (balance > moneyLeft)
            //{
            //    balance = 0;
            //    ScriptHelper.AlertFront("金额有错误,请重新检查", url);
            //}
            #region 如果开启了:使用积分抵现,计算积分抵现的现金金额
            //输入的兑换积分数
            var costPoint = RequestHelper.GetForm <int>("costPoint");
            if (ShopConfig.ReadConfigInfo().EnablePointPay == 1)
            {
                if (costPoint > user.PointLeft || costPoint < 0)
                {
                    ResponseHelper.Write("error|输入的兑换积分数[" + costPoint + "]错误,请检查|");
                    ResponseHelper.End();
                }
                if (costPoint > 0)
                {
                    var PointToMoneyRate = ShopConfig.ReadConfigInfo().PointToMoney;
                    pointMoney = costPoint * (decimal)PointToMoneyRate / 100;
                }
            }
            #endregion
            #region 优惠券
            decimal        couponMoney   = 0;
            string         userCouponStr = RequestHelper.GetForm <string>("UserCoupon");
            UserCouponInfo userCoupon    = new UserCouponInfo();
            if (userCouponStr != string.Empty)
            {
                int couponID = 0;
                if (int.TryParse(userCouponStr.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)[0], out couponID))
                {
                    userCoupon = UserCouponBLL.Read(couponID, base.UserId);
                    if (userCoupon.UserId == base.UserId && userCoupon.IsUse == 0)
                    {
                        CouponInfo tempCoupon = CouponBLL.Read(userCoupon.CouponId);
                        if (tempCoupon.UseMinAmount <= productMoney)
                        {
                            couponMoney = CouponBLL.Read(userCoupon.CouponId).Money;
                        }
                        else
                        {
                            ScriptHelper.AlertFront("结算金额小于该优惠券要求的最低消费的金额", url);
                        }
                    }
                }
            }
            #endregion
            #region 结算商品优惠金额
            decimal productfavorableMoney = 0;
            var     theFavor = FavorableActivityBLL.Read(productfavor.Id);
            if (theFavor.Id > 0)
            {
                decimal tmoney = 0;
                foreach (var tmpcart in cartList)
                {
                    tmpcart.Product = products.FirstOrDefault(k => k.Id == tmpcart.ProductId) ?? new ProductInfo();
                    if (tmpcart.Product.ClassId.IndexOf(theFavor.ClassIds) > -1)
                    {
                        if (!string.IsNullOrEmpty(tmpcart.StandardValueList))
                        {
                            //使用规格的库存
                            var standardRecord = ProductTypeStandardRecordBLL.Read(tmpcart.ProductId, tmpcart.StandardValueList);
                            tmpcart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount;
                            tmpcart.Price            = ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID);
                            tmoney += tmpcart.Price * tmpcart.BuyCount;
                        }
                        else
                        {
                            tmpcart.Price = ProductBLL.GetCurrentPrice(tmpcart.Product.SalePrice, base.GradeID);
                            tmoney       += tmpcart.Price * tmpcart.BuyCount;
                        }
                    }
                }
                switch (theFavor.ReduceWay)
                {
                case (int)FavorableMoney.Money:
                    productfavorableMoney += theFavor.ReduceMoney;
                    break;

                case (int)FavorableMoney.Discount:
                    productfavorableMoney += tmoney * (100 - theFavor.ReduceDiscount) / 100;
                    break;

                default:
                    break;
                }
            }
            #endregion
            #region 计算订单优惠活动金额
            decimal favorableMoney = 0;
            favor = FavorableActivityBLL.Read(favor.Id);
            if (favor.Id > 0)
            {
                if (("," + favor.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && productMoney >= favor.OrderProductMoney)
                {
                    switch (favor.ReduceWay)
                    {
                    case (int)FavorableMoney.Money:
                        favorableMoney += favor.ReduceMoney;
                        break;

                    case (int)FavorableMoney.Discount:
                        favorableMoney += productMoney * (100 - favor.ReduceDiscount) / 100;
                        break;

                    default:
                        break;
                    }
                    if (favor.ShippingWay == (int)FavorableShipping.Free && ShippingRegionBLL.IsRegionIn(regionID, favor.RegionId))
                    {
                        favorableMoney += shippingMoney;
                    }
                }
            }
            #endregion
            /*-----------应付总价---------------------------------------------------*/
            decimal payMoney = productMoney + shippingMoney - couponMoney - pointMoney - favorableMoney - productfavorableMoney;
            //if (productMoney - favorableMoney + shippingMoney - balance - couponMoney <= 0)
            if (payMoney < 0)
            {
                ScriptHelper.AlertFront("金额有错误,请重新检查", url);
            }

            //添加订单
            OrderInfo order = new OrderInfo();
            order.OrderNumber = ShopCommon.CreateOrderNumber();
            order.IsActivity  = (int)BoolType.False;
            if (payMoney == 0 || payPlugins.IsCod == (int)BoolType.True)
            {
                order.OrderStatus = (int)OrderStatus.WaitCheck;
            }
            else
            {
                order.OrderStatus = (int)OrderStatus.WaitPay;
            }
            order.OrderNote      = string.Empty;
            order.ProductMoney   = productMoney;
            order.Balance        = 0;
            order.FavorableMoney = favorableMoney + productfavorableMoney;
            order.OtherMoney     = 0;
            order.CouponMoney    = couponMoney;
            order.Point          = costPoint;
            order.PointMoney     = pointMoney;
            order.Consignee      = consignee;
            SingleUnlimitClass singleUnlimitClass = new SingleUnlimitClass();
            order.RegionId = singleUnlimitClass.ClassID;
            order.Address  = address;
            order.ZipCode  = zipCode;
            order.Tel      = tel;
            if (base.UserId == 0)
            {
                order.Email = StringHelper.AddSafe(RequestHelper.GetForm <string>("Email"));
            }
            else
            {
                order.Email = CookiesHelper.ReadCookieValue("UserEmail");
            }
            order.Mobile              = mobile;
            order.ShippingId          = shippingID;
            order.ShippingDate        = RequestHelper.DateNow;
            order.ShippingNumber      = string.Empty;
            order.ShippingMoney       = shippingMoney;
            order.PayKey              = payKey;
            order.PayName             = payPlugins.Name;
            order.PayDate             = RequestHelper.DateNow;;
            order.IsRefund            = (int)BoolType.False;
            order.FavorableActivityId = RequestHelper.GetForm <int>("FavorableActivityID");
            order.GiftId              = RequestHelper.GetForm <int>("GiftID");
            order.InvoiceTitle        = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceTitle"));
            order.InvoiceContent      = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceContent"));
            order.UserMessage         = StringHelper.AddSafe(RequestHelper.GetForm <string>("UserMessage"));
            order.AddDate             = RequestHelper.DateNow;
            order.IP          = ClientHelper.IP;
            order.UserId      = base.UserId;
            order.UserName    = base.UserName;
            order.GiftMessige = RequestHelper.GetForm <string>("GiftMessige");
            order.IsNoticed   = 0;

            int orderID = OrderBLL.Add(order);
            //使用余额

            /*if (balance > 0)
             * {
             *  UserAccountRecordInfo userAccountRecord = new UserAccountRecordInfo();
             *  userAccountRecord.Money = -balance;
             *  userAccountRecord.Point = 0;
             *  userAccountRecord.Date = RequestHelper.DateNow;
             *  userAccountRecord.IP = ClientHelper.IP;
             *  userAccountRecord.Note = "支付订单:";
             *  userAccountRecord.UserId = base.UserId;
             *  userAccountRecord.UserName = base.UserName;
             *  UserAccountRecordBLL.Add(userAccountRecord);
             * }*/
            #region 减少积分
            if (ShopConfig.ReadConfigInfo().EnablePointPay == 1 && costPoint > 0)
            {
                //减少积分
                UserAccountRecordInfo uarInfo = new UserAccountRecordInfo();
                uarInfo.RecordType = (int)AccountRecordType.Point;
                uarInfo.UserId     = base.UserId;
                uarInfo.UserName   = base.UserName;
                uarInfo.Note       = "支付订单:" + order.OrderNumber;
                uarInfo.Point      = -costPoint;
                uarInfo.Money      = 0;
                uarInfo.Date       = DateTime.Now;
                uarInfo.IP         = ClientHelper.IP;
                UserAccountRecordBLL.Add(uarInfo);
            }
            #endregion
            #region 使用优惠券
            string strUserCoupon = RequestHelper.GetForm <string>("UserCoupon");
            if (couponMoney > 0 && !string.IsNullOrEmpty(strUserCoupon) && strUserCoupon != "0|0")
            {
                userCoupon.IsUse   = (int)BoolType.True;
                userCoupon.OrderId = orderID;
                UserCouponBLL.Update(userCoupon);
            }
            #endregion
            AddOrderProduct(orderID);
            //更改产品库存订单数量
            ProductBLL.ChangeOrderCountByOrder(orderID, ChangeAction.Plus);
            /*----------------------------------------------------------------------*/

            ResponseHelper.Redirect("/Mobile/Finish-I" + orderID.ToString() + ".html");
        }
        protected override void PageLoad()
        {
            base.PageLoad();

            string action = RequestHelper.GetQueryString <string>("Action");

            if (action == "SelectShipping")
            {
                this.SelectShipping();
            }

            int id = RequestHelper.GetQueryString <int>("id");

            address = UserAddressBLL.Read(id, base.UserId);

            if (string.IsNullOrEmpty(address.RegionId))
            {
                return;
            }

            //取出所有配送方式Id
            List <ShippingInfo> tempShippingList = ShippingBLL.ReadList();

            tempShippingList = tempShippingList.Where(k => k.IsEnabled == (int)BoolType.True).ToList();

            var shippingIds = new List <int>();

            tempShippingList.ForEach(k => shippingIds.Add(k.Id));

            //读取配送区域列表
            List <ShippingRegionInfo> shippingRegionList = ShippingRegionBLL.ReadList(shippingIds.ToArray());

            #region 读取购物车结算金额
            string checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart"));
            int[]  cartIds   = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k));
            if (string.IsNullOrEmpty(checkCart) || cartIds.Length < 1)
            {
                ResponseHelper.Write("error|请选择需要购买的商品");
                ResponseHelper.End();
            }
            //计算配送费用
            List <CartInfo> cartList = CartBLL.ReadList(base.UserId).Where(k => cartIds.Contains(k.Id)).ToList();
            if (cartList.Count < 1)
            {
                ResponseHelper.Write("error|请选择需要购买的商品");
                ResponseHelper.End();
            }
            int count = 0;
            //购物车结算金额
            decimal cartTotalPrice = 0;
            int[]   ids            = cartList.Select(k => k.ProductId).ToArray();
            var     productList    = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo {
                InProductId = string.Join(",", ids)
            }, ref count);
            cartList.ForEach(k => k.Product = productList.FirstOrDefault(k2 => k2.Id == k.ProductId) ?? new ProductInfo());
            foreach (var cart in cartList)
            {
                if (!string.IsNullOrEmpty(cart.StandardValueList))
                {
                    //使用规格的价格和库存
                    var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList);
                    cartTotalPrice += ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID) * cart.BuyCount;
                }
                else
                {
                    cartTotalPrice += ProductBLL.GetCurrentPrice(cart.Product.SalePrice, base.GradeID) * cart.BuyCount;
                }
            }
            #endregion
            #region 获取符合条件(时间段,用户等级,金额限制)的整站订单优惠活动列表,默认使用第一个
            favorableActivityList = FavorableActivityBLL.ReadList(DateTime.Now, DateTime.Now).Where <FavorableActivityInfo>(f => f.Type == (int)FavorableType.AllOrders && ("," + f.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && cartTotalPrice >= f.OrderProductMoney).ToList();
            #endregion
            //查找符合条件的配送方式
            foreach (ShippingInfo shipping in tempShippingList)
            {
                string tempRegionId = address.RegionId;
                while (tempRegionId.Length >= 1)
                {
                    bool isFind = false;
                    foreach (ShippingRegionInfo temp in shippingRegionList)
                    {
                        if (("|" + temp.RegionId + "|").IndexOf("|" + tempRegionId + "|") > -1 && temp.ShippingId == shipping.Id)
                        {
                            isFind = true;
                            shippingList.Add(shipping);
                            break;
                        }
                    }
                    if (isFind)
                    {
                        break;
                    }
                    else
                    {
                        tempRegionId = tempRegionId.Substring(0, tempRegionId.Length - 1);
                        tempRegionId = tempRegionId.Substring(0, tempRegionId.LastIndexOf('|') + 1);
                    }
                }
            }
        }