예제 #1
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);
        }
예제 #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Order o = new Order();
            o.OrderNo = CreateOrderNo();// rastgele oluştur
            o.UserId = new Guid(Membership.GetUser().ProviderUserKey.ToString());
            o.Date = DateTime.Now;

            OrderBLL ob = new OrderBLL();

            ob.Add(o);

            ProductBLL pb = new ProductBLL();
            foreach (var p in Helper.Sepet)
            {
                OrderDetail od = new OrderDetail();
                od.OrderId = o.Id;
                od.ProductId = p.Id;
                od.Quantity = p.Quantity;

                OrderDetailBLL obll = new OrderDetailBLL();
                obll.Add(od);

                Product pr = pb.Get(x => x.Id == p.Id).FirstOrDefault();

                pr.Stock -= p.Quantity;
                pb.Update(pr);

                Helper.Sepet = new List<ProductDTO>();

            }
        }
예제 #3
0
        protected void lbtOrderSubmit_Click(object sender, EventArgs e)
        {
            MemberEntity          member            = (MemberEntity)Session["usr"];
            BookCartBLL           cartBLL           = new BookCartBLL();
            List <BookCartEntity> list              = cartBLL.list(member.MemberId);
            MyOrderEntity         orderEntity       = new MyOrderEntity();
            MyOrderBLL            orderBLL          = new MyOrderBLL();
            OrderDetailEntity     orderDetailEntity = new OrderDetailEntity();

            orderEntity.OrderCode    = DateTime.Now.ToString("yyyyMMddhhmmss") + member.MemberId;
            orderEntity.MemberId     = member.MemberId;
            orderEntity.OrderPeople  = txtMemberName.Text;
            orderEntity.OrderPhone   = txtPhone.Text;
            orderEntity.OrderAddress = txtAddress.Text;
            decimal counpic = 0;

            foreach (BookCartEntity item in list)
            {
                if (item.IsSelect == 1)
                {
                    counpic += (item.BookCount * (item.BookInfo.BookPrice * item.BookInfo.BookDisCount));
                }
            }
            orderEntity.OrderAllMoney = counpic;
            orderEntity.OrderStatus   = 1;
            orderBLL.Add(orderEntity);
            orderEntity = orderBLL.list(orderEntity.OrderCode);
            OrderDetailBLL orderDetailBLL = new OrderDetailBLL();

            foreach (BookCartEntity item in list)
            {
                if (item.IsSelect == 1)
                {
                    orderDetailEntity.OrderId       = orderEntity.OrderId;
                    orderDetailEntity.BookId        = item.BookId;
                    orderDetailEntity.BookSalePrice = (item.BookInfo.BookPrice * item.BookInfo.BookDisCount);
                    orderDetailEntity.BookSaleCount = item.BookCount;
                    orderDetailBLL.Add(orderDetailEntity);
                    cartBLL.Delete(item.CartId);
                }
            }
            Response.Redirect("~/Member/OrderList.aspx");
        }
예제 #4
0
        /// <summary>
        /// 拆分不同的供应商商品,生成订单
        /// </summary>
        private List <int> SplitShopProduct(List <CartInfo> cartList, OrderInfo mainOrder)
        {
            List <int> orderIds = new List <int>();

            /*-----------根据ShopId分组---------------------------------------------*/
            var shopIds = cartList.GroupBy(k => k.Product.ShopId).Select(k => k.Key).ToList();
            /*----------------------------------------------------------------------*/

            /*-----------积分抵扣额度、比率(不可使用积分)-----------------------------
             * decimal totalRate = (decimal)ShopConfig.ReadConfigInfo().BuyPointTotalRate;
             * decimal pointRate = (decimal)ShopConfig.ReadConfigInfo().BuyPointMoneyRate;
             * /*----------------------------------------------------------------------*/

            var pay = PayPlugins.ReadPayPlugins(mainOrder.PayKey);

            //
            //循环产生订单
            foreach (var shopId in shopIds)
            {
                var shopCartList = cartList.Where(k => k.Product.ShopId == shopId).ToList();

                /*-----------分拆后的订单价格---------------------------------------*/
                //运费 (去掉平均分配运费,根据供应商的不同来分别计算运费)
                //decimal shippingMoney = mainOrder.ShippingMoney / shopIds.Count;

                decimal shippingMoney = 0;
                //然后将分拆后的供应商商品,按单个商品独立计算运费(相同商品购买多个则叠加计算)
                ShippingInfo       shipping       = ShippingBLL.Read(mainOrder.ShippingId);
                ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(mainOrder.ShippingId, mainOrder.RegionId);

                foreach (var shopCartSplit in shopCartList)
                {
                    shippingMoney += ShippingRegionBLL.ReadShippingMoney(shipping, shippingRegion, shopCartSplit);
                }

                //产品金额
                decimal productMoney = 0;
                shopCartList.ForEach(k => productMoney += k.BuyCount * k.Price);
                /*------------------------------------------------------------------*/

                decimal pointMoney = 0;
                int     point      = 0;

                /*-----------根据比率,分配积分抵扣金额(不可使用积分)----------------
                 * decimal pointMoney = 0;
                 * int point = 0;
                 * if (mainOrder.Point > 0)
                 * {
                 *  pointMoney = productMoney * totalRate;
                 *  point = (int)(pointMoney * pointRate);
                 *  if (point > mainOrder.Point)
                 *  {
                 *      point = mainOrder.Point;
                 *      pointMoney = Math.Round(point / pointRate, 2);
                 *  }
                 * }
                 * /*----------------------------------------------------------------------*/

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

                /*-----------分配余额---------------------------------------------------*/
                decimal balance = 0;
                if (mainOrder.Balance > 0)
                {
                    balance = mainOrder.Balance;
                    if (balance > payMoney)
                    {
                        balance = payMoney;
                    }
                }
                payMoney -= balance;
                /*----------------------------------------------------------------------*/


                /*-----------添加订单---------------------------------------------------*/
                OrderInfo order = new OrderInfo();
                order.ShopId        = shopId;
                order.OrderNumber   = ShopCommon.CreateOrderNumber();
                order.IsActivity    = (int)BoolType.False;
                order.OrderStatus   = payMoney == 0 || pay.IsCod == (int)BoolType.True ? (int)OrderStatus.WaitCheck : (int)OrderStatus.WaitPay;
                order.ProductMoney  = productMoney;
                order.Consignee     = mainOrder.Consignee;
                order.RegionId      = mainOrder.RegionId;
                order.Address       = mainOrder.Address;
                order.ZipCode       = mainOrder.ZipCode;
                order.Tel           = mainOrder.Tel;
                order.Mobile        = mainOrder.Mobile;
                order.Email         = mainOrder.Email;
                order.ShippingId    = mainOrder.ShippingId;
                order.ShippingDate  = RequestHelper.DateNow;
                order.ShippingMoney = shippingMoney;
                order.Point         = point;
                order.PointMoney    = pointMoney;
                order.Balance       = balance;
                order.PayKey        = mainOrder.PayKey;
                order.PayName       = mainOrder.PayName;
                order.PayDate       = RequestHelper.DateNow;
                order.IsRefund      = (int)BoolType.False;
                order.UserMessage   = mainOrder.UserMessage;
                order.AddDate       = RequestHelper.DateNow;
                order.IP            = ClientHelper.IP;
                order.UserId        = base.UserId;
                order.UserName      = base.UserName;
                int orderId = OrderBLL.Add(order);

                //添加订单产品
                foreach (var cart in shopCartList)
                {
                    var orderDetail = new OrderDetailInfo();
                    orderDetail.OrderId       = orderId;
                    orderDetail.ProductId     = cart.ProductId;
                    orderDetail.ProductName   = cart.ProductName;
                    orderDetail.ProductWeight = cart.Product.Weight;
                    orderDetail.ProductPrice  = cart.Price;
                    orderDetail.BidPrice      = cart.Product.BidPrice;
                    orderDetail.BuyCount      = cart.BuyCount;

                    OrderDetailBLL.Add(orderDetail);
                }
                /*----------------------------------------------------------------------*/

                /*-----------使用余额、积分(余额消费记录更改到同步订单金额到图楼泛生活会员管理系统成功后,才予记录)
                 * if (balance > 0 && order.OrderStatus == (int)OrderStatus.WaitCheck)
                 * {
                 *  var accountRecord = new UserAccountRecordInfo
                 *  {
                 *      RecordType = (int)AccountRecordType.Money,
                 *      Money = -balance,
                 *      Point = 0,
                 *      Date = DateTime.Now,
                 *      IP = ClientHelper.IP,
                 *      Note = "支付订单:" + order.OrderNumber,
                 *      UserId = base.UserId,
                 *      UserName = base.UserName
                 *  };
                 *  UserAccountRecordBLL.Add(accountRecord);
                 * }
                 * ------------------------------------------------------------------------*/
                /*-----------不可使用积分-------------------------------------------------
                 * if (point > 0)
                 * {
                 *  var accountRecord = new UserAccountRecordInfo
                 *  {
                 *      RecordType = (int)AccountRecordType.Point,
                 *      Money = 0,
                 *      Point = -point,
                 *      Date = DateTime.Now,
                 *      IP = ClientHelper.IP,
                 *      Note = "支付订单:" + order.OrderNumber,
                 *      UserId = base.UserId,
                 *      UserName = base.UserName
                 *  };
                 *  UserAccountRecordBLL.Add(accountRecord);
                 * }
                 * ------------------------------------------------------------------------*/
                /*----------------------------------------------------------------------*/

                /*-----------更改产品库存订单数量---------------------------------------*/
                ProductBLL.ChangeOrderCountByOrder(orderId, ChangeAction.Plus);
                /*----------------------------------------------------------------------*/

                mainOrder.Point   -= point;
                mainOrder.Balance -= balance;
                orderIds.Add(orderId);
            }

            return(orderIds);
        }
예제 #5
0
        protected void Submit()
        {
            string             userName           = base.UserName;
            string             userEmail          = CookiesHelper.ReadCookieValue("UserEmail");
            SingleUnlimitClass singleUnlimitClass = new SingleUnlimitClass();

            //检测积分
            int id = RequestHelper.GetForm <int>("updateId");

            if (id < 1)
            {
                ResponseHelper.Write("error|无效的请求");
                ResponseHelper.End();
            }
            if (singleUnlimitClass.ClassID.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Length < 3)
            {
                ResponseHelper.Write("error|请填写完整的地区信息");
                ResponseHelper.End();
                ResponseHelper.End();
            }

            var pointLeft = UserAccountRecordBLL.SumPoint(base.UserId);

            Gift = PointProductBLL.Read(id);
            if (Gift.Point > pointLeft)
            {
                ResponseHelper.Write("error|您当前的积分不足以兑取该礼品");
                ResponseHelper.End();
            }
            //库存
            int num = RequestHelper.GetForm <int>("num");

            if (num > (Gift.TotalStorageCount - Gift.SendCount))
            {
                ResponseHelper.Write("error|该礼品库存不足");
                ResponseHelper.End();
            }

            //添加订单
            OrderInfo order = new OrderInfo();

            order.OrderNumber         = ShopCommon.CreateOrderNumber();
            order.IsActivity          = (int)BoolType.True;
            order.OrderStatus         = (int)OrderStatus.WaitCheck;
            order.OrderNote           = "积分兑换奖品";
            order.ProductMoney        = 0;
            order.Balance             = 0;
            order.FavorableMoney      = 0;
            order.OtherMoney          = 0;
            order.CouponMoney         = 0;
            order.Consignee           = StringHelper.AddSafe(RequestHelper.GetForm <string>("username"));
            order.RegionId            = singleUnlimitClass.ClassID;
            order.Address             = StringHelper.AddSafe(RequestHelper.GetForm <string>("address"));
            order.ZipCode             = StringHelper.AddSafe(RequestHelper.GetForm <string>("zipcode"));
            order.Tel                 = StringHelper.AddSafe(RequestHelper.GetForm <string>("tel"));
            order.Email               = userEmail;
            order.Mobile              = StringHelper.AddSafe(RequestHelper.GetForm <string>("mobile"));
            order.ShippingId          = 0;
            order.ShippingDate        = RequestHelper.DateNow;
            order.ShippingNumber      = string.Empty;
            order.ShippingMoney       = 0;
            order.PayKey              = string.Empty;
            order.PayName             = string.Empty;
            order.PayDate             = RequestHelper.DateNow;;
            order.IsRefund            = (int)BoolType.False;
            order.FavorableActivityId = 0;
            order.GiftId              = 0;
            order.InvoiceTitle        = string.Empty;
            order.InvoiceContent      = string.Empty;
            order.UserMessage         = string.Empty;
            order.AddDate             = RequestHelper.DateNow;
            order.IP            = ClientHelper.IP;
            order.UserId        = base.UserId;
            order.UserName      = userName;
            order.ActivityPoint = Gift.Point * num;
            int orderID = OrderBLL.Add(order);

            //添加订单详细
            OrderDetailInfo orderDetail = new OrderDetailInfo();

            orderDetail.OrderId       = orderID;
            orderDetail.ProductId     = Gift.Id;
            orderDetail.ProductName   = Gift.Name;
            orderDetail.ProductWeight = Gift.Weight;
            orderDetail.SendPoint     = 0;
            orderDetail.ProductPrice  = 0;
            orderDetail.ActivityPoint = Gift.Point;
            orderDetail.BuyCount      = num;
            orderDetail.ParentId      = 0;
            orderDetail.RandNumber    = string.Empty;
            orderDetail.GiftPackId    = 0;
            OrderDetailBLL.Add(orderDetail);

            //积分记录
            var accountRecord = new UserAccountRecordInfo
            {
                Money    = 0,
                Point    = -Gift.Point * num,
                Date     = DateTime.Now,
                IP       = ClientHelper.IP,
                Note     = "兑换礼品-" + Gift.Name,
                UserId   = base.UserId,
                UserName = base.UserName
            };

            UserAccountRecordBLL.Add(accountRecord);

            //更新商品的已兑换数量
            Dictionary <string, object> dict = new Dictionary <string, object>();

            dict.Add("SendCount", Gift.SendCount + num);
            PointProductBLL.UpdatePart(PointProductInfo.TABLENAME, dict, Gift.Id);

            ResponseHelper.Write("ok|" + orderID);
            ResponseHelper.End();
        }
예제 #6
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();
        }