예제 #1
0
        /// <summary>
        /// 新增订单发票
        /// </summary>
        /// <param name="orderInvoice">
        /// 订单发票
        /// </param>
        /// <param name="transaction">
        /// 事务对象
        /// </param>
        /// <returns>
        /// 新增的订单编码
        /// </returns>
        public int Insert(Order_Invoice orderInvoice, SqlTransaction transaction)
        {
            var paras = new List<SqlParameter>
                            {
                                this.SqlServer.CreateSqlParameter(
                                    "OrderID",
                                    SqlDbType.Int,
                                    orderInvoice.OrderID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "InvoiceTypeID",
                                    SqlDbType.Int,
                                    orderInvoice.InvoiceTypeID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "InvoiceContentID",
                                    SqlDbType.Int,
                                    orderInvoice.InvoiceContentID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "InvoiceTitle",
                                    SqlDbType.NVarChar,
                                    orderInvoice.InvoiceTitle,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "InvoiceCost",
                                    SqlDbType.Float,
                                    orderInvoice.InvoiceCost,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "CreateTime",
                                    SqlDbType.DateTime,
                                    DateTime.Now,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "ReferenceID",
                                    SqlDbType.Int,
                                    null,
                                    ParameterDirection.Output)
                            };

            this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_Order_Invoice_Insert", paras, transaction);
            return (int)paras.Find(e => e.ParameterName == "ReferenceID").Value;
        }
예제 #2
0
        /// <summary>
        /// 确认订单
        /// </summary>
        /// <param name="order">
        /// 订单对象
        /// </param>
        /// <param name="orderProducts">
        /// 订单商品列表
        /// </param>
        /// <param name="orderInvoice">
        /// 订单发票
        /// </param>
        /// <param name="userRecieveAddress">
        /// 用户收货地址信息
        /// </param>
        public void ManualConfirmOrder(
            Order order, 
            List<Order_Product> orderProducts, 
            Order_Invoice orderInvoice, 
            User_RecieveAddress userRecieveAddress)
        {
            //todo: 订单数据需要从数据库取一次
            /************
             * 一、修改订单
             * 1. 修改收货人信息。
             * 2. 修改订单商品信息
             * 3. 修改订单发票信息
             * 4. 修改订单信息
             * 二、确认订单
             * 1.推送到ERP系统
             * 2.修改订单为确认状态
             * ***********/
            SqlTransaction transaction = null;
            var orderProductService = new OrderProductService();
            Order orignalOrder = this.EditOrderInfo(order, orderProducts, orderInvoice, userRecieveAddress);

            switch (orignalOrder.Status)
            {
                case 100:
                    throw new Exception("此订单处于等待支付状态,不允许确认。");
                case 1:
                    throw new Exception("此订单已确认,请不要重复操作!");
                case 2:
                    throw new Exception("此订单已发货");
                case 3:
                    throw new Exception("此订单已签收");
                case 4:
                case 6:
                case 8:
                    throw new Exception("此订单已取消");
                case 5:
                    throw new Exception("此订单已损失");
                case 0:
                    //确认订单
                    try
                    {
                        Order_Payment payment = null;
                        if (order.PaymentStatus == 1)
                        {
                            payment = new OrderPaymentService().QueryByOrderID(order.ID);
                        }

                        orderProducts = orderProductService.QueryByOrderId(order.ID);
                        this.orderDA.SqlServer.BeginTransaction();
                        transaction = this.orderDA.SqlServer.Transaction;
                        this.ConfirmByUpdateOrder(orignalOrder, transaction, payment, orderProducts);

                        new OrderStatusTrackingService().Add(
                            new Order_Status_Tracking
                            {
                                OrderID = order.ID,
                                EmployeeID = isBackage ? this.userID : 0,
                                Remark = "订单已经确认,等待出库",
                                Status = 1,  // 已确认的订单状态为码 1
                                UserID = order.UserID
                            },
                            transaction);

                        transaction.Commit();
                    }
                    catch (Exception exception)
                    {
                        if (transaction != null)
                        {
                            transaction.Rollback();
                        }

                        LogUtils.Log(
                            string.Format(
                                "确认订单出错,订单编码{0},操作人ID:{1},错误信息:{2},内部错误:{3},堆栈信息:{4}",
                                order.ID,
                                this.userID,
                                exception.Message,
                                exception.InnerException,
                                exception.StackTrace),
                            "确认订单--服务层",
                            Category.Fatal);
                        throw;
                    }

                    // 写订单修改日志
                    try
                    {
                        var orderStatusLogService = new OrderStatusLogService();
                        orderStatusLogService.Insert(
                            new Order_Status_Log
                            {
                                EmployeeID = this.userID,
                                OrderID = order.ID,
                                Remark = order.Description,
                                Status = 1
                            },
                            null);
                    }
                    catch (Exception exception)
                    {
                        TextLogger.Instance.Log(
                            string.Format("后台订单确认--订单状态日志写入错误.(订单编码:{0},操作员编码:{1})", order.ID, this.userID),
                            Category.Error,
                            exception);
                    }
                    break;
                default:
                    throw new Exception("订单状态异常。");
            }
        }
예제 #3
0
        public Order EditOrderInfo(
            Order order,
            List<Order_Product> orderProducts,
            Order_Invoice orderInvoice,
            User_RecieveAddress userRecieveAddress)
        {
            SqlTransaction transaction = null;
            var orignalOrder = this.QueryById(order.ID);

            //int rowCount, pageCount;
            if (orignalOrder == null)
            {
                throw new ArgumentException("订单获取错误");
            }

            try
            {
                orignalOrder.CpsID = order.CpsID;
                orignalOrder.DeliveryCost = order.DeliveryCost;
                orignalOrder.Description = order.Description;
                orignalOrder.IsRequireInvoice = order.IsRequireInvoice;

                new UserReceiveAddressService().Modify(userRecieveAddress, out transaction);
                new OrderProductService().ModifyOrderProductByOrderID(orderProducts, orignalOrder.CpsID, order.ID, transaction);

                if (order.IsRequireInvoice)
                {
                    orderInvoice.OrderID = order.ID;
                    if (orderInvoice.ID > 0)
                    {
                        new OrderInvoiceService().Modify(orderInvoice, transaction);
                    }
                    else
                    {
                        new OrderInvoiceService().Add(orderInvoice, transaction);
                    }
                }

                foreach (var orderProduct in orderProducts)
                {
                    order.TotalMoney += orderProduct.TransactPrice * orderProduct.Quantity;
                }

                order.TotalIntegral = (int)order.TotalMoney;
                orignalOrder.TotalIntegral = order.TotalIntegral;
                orignalOrder.TotalMoney = order.TotalMoney;
                this.Edit(orignalOrder, transaction);

                transaction.Commit();
            }
            catch (Exception ex)
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }

                LogUtils.Log(
                    string.Format(
                        "确认订单是修改订单信息出错,订单编码{0},操作人ID:{1},错误信息:{2},堆栈信息:{3}",
                        order.ID,
                        this.userID,
                        ex.Message,
                        ex.StackTrace),
                    "确认订单--服务层",
                    Category.Fatal);

                throw;
            }

            return orignalOrder;
        }
예제 #4
0
        /// <summary>
        /// 添加订单
        /// </summary>
        /// <param name="order">
        /// 订单兑现
        /// </param>
        /// <param name="orderProducts">
        /// 订单商品列表
        /// </param>
        /// <param name="invoice">
        /// 发票信息
        /// </param>
        /// <param name="Coupons">赠送的优惠券信息</param>
        /// <param name="promotes">订单促销信息</param>
        /// <returns>
        /// 已添加订单的编码
        /// </returns>
        public int Add(Order order, List<Order_Product> orderProducts, Order_Invoice invoice, List<Gift_Coupon> Coupons = null, List<Order_Product_Promote> promotes = null)
        {
            // 1.添加订单
            // 2.添加订单商品
            // 3.添加发票(若有)
            var orderProductService = new OrderProductService();
            SqlTransaction transaction = null;
            int orderId;
            try
            {
                if (order.TotalMoney == 0) //如果0,则认为是前端的订单,需要从新计算金额,不能享受到优惠和促销
                {
                    double totalMoney = 0;
                    foreach (var orderProduct in orderProducts)
                    {
                        totalMoney += orderProduct.TransactPrice * orderProduct.Quantity;
                    }

                    order.TotalMoney = totalMoney;
                    order.DeliveryCost = totalMoney >= 100 ? 0 : 10; // todo: 读取数据库配置,设置运费。
                }

                order.TotalIntegral = (int)order.TotalMoney / 1;

                orderId = this.orderDA.Insert(order, out transaction);
                order.ID = orderId;

                orderProductService.BatchAddOrderProduct(orderProducts, order.CpsID, orderId, transaction);

                if (invoice != null)
                {
                    invoice.OrderID = orderId;
                    invoice.InvoiceCost = order.TotalMoney;
                    new OrderInvoiceService().Add(invoice, transaction);
                }

                //赠送优惠券
                if (Coupons != null && Coupons.Count > 0)
                {
                    foreach (var giftCoupon in Coupons)
                    {
                        switch (giftCoupon.CouponType)
                        {
                            case 0:
                                //默认新方法的券状态为2,未激活
                                new CouponCashBindingService().Add(orderId, giftCoupon.CouponID, this.userID, "购物赠券", 2, transaction);
                                break;
                            case 1:
                                //默认新方法的券状态为2,未激活
                                new CouponDecreaseBindingService().Add(orderId, giftCoupon.CouponID, this.userID, "购物赠券", 2, transaction);
                                break;
                        }
                    }
                }

                if (promotes != null && promotes.Count > 0)
                {
                    foreach (var promote in promotes)
                    {
                        promote.OrderID = orderId;
                    }

                    var rowCount = new OrderProductPromoteService().BatchAdd(promotes, transaction);
                    if (rowCount < 1)
                    {
                        LogUtils.Log("添加订单(订单号:" + order.OrderCode + ")时添加的订单商品促销信息数为:" + rowCount, "添加订单服务层", Category.Info);
                    }
                }

                string remark;

                if (order.PaymentMethodID == 1||order.PaymentMethodID == 2)
                {
                    remark = "添加订单成功,等待确认";
                }
                else
                {
                    remark = order.PaymentStatus == 0 ? "添加订单成功,等待付款" : "添加订单成功,等待确认";
                }

                new OrderStatusTrackingService().Add(
                    new Order_Status_Tracking
                        {
                            OrderID = orderId,
                            EmployeeID = isBackage? this.userID:0,
                            Remark = remark,
                            Status = 0,
                            UserID = order.UserID
                        },
                    transaction);
                transaction.Commit();
            }
            catch (Exception)
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }

                throw;
            }

            // 写订单修改日志
            try
            {
                var orderStatusLogService = new OrderStatusLogService();
                orderStatusLogService.Insert(
                    new Order_Status_Log
                    {
                        EmployeeID = isBackage? this.userID:0, // 若是后台,则填写操作员工编码
                        OrderID = orderId,
                        Remark = order.Description,
                        Status = 0
                    },
                    null);
            }
            catch (Exception exception)
            {
                TextLogger.Instance.Log(
                    string.Format("后台添加订单--订单状态日志写入错误.(订单编码:{0},操作员编码:{1})", order.ID, this.userID),
                    Category.Error,
                    exception);
            }

            return orderId;
        }
예제 #5
0
        /// <summary>
        /// 修改订单发票
        /// </summary>
        /// <param name="orderInvoice">
        /// 订单发票对象
        /// </param>
        /// <param name="transaction">
        /// 事务对象
        /// </param>
        public void Update(Order_Invoice orderInvoice, SqlTransaction transaction)
        {
            var paras = new List<SqlParameter>
                            {
                                this.SqlServer.CreateSqlParameter(
                                    "OrderID",
                                    SqlDbType.Int,
                                    orderInvoice.OrderID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "InvoiceTypeID",
                                    SqlDbType.Int,
                                    orderInvoice.InvoiceTypeID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "InvoiceContentID",
                                    SqlDbType.Int,
                                    orderInvoice.InvoiceContentID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "InvoiceTitle",
                                    SqlDbType.NVarChar,
                                    orderInvoice.InvoiceTitle,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "InvoiceCost",
                                    SqlDbType.Float,
                                    orderInvoice.InvoiceCost,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "ID",
                                    SqlDbType.Int,
                                    orderInvoice.ID,
                                    ParameterDirection.Input)
                            };

            this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_Order_Invoice_Update", paras, transaction);
        }
예제 #6
0
        public ActionResult Add(int addressID, int payMethod, string productIds, string intro, 
            int isRequireInvoice, string invoiceTitle, int invoiceContent, int ctype, int cId, double account)
        {
            /***************
             * 前台添加订单流程:
             * 1.检查是否用券,若用,则检查券是否存在,是否符合使用条件。
             * 2.检查是否用余额抵扣,若用,则检查用户是否有足够余额。
             * 3.检查用户是否开发票,若是,检查发票内容是否填写。
             * 4.检查用户收货地址ID是否填写正确
             * 5.检查商品ID列表是否正确
             * todo:下单时检查商品库存
             * ********************/

            #region 检查是否用券
            //todo:券检查
            #endregion

            #region 余额抵用检查

            if (account > 0)
            {
                if (!CheckAccountBalance(account))
                {
                    return this.Json(new AjaxResponse(-1, "账户余额不足"));
                }
            }

            #endregion

            #region 检查发票信息

            if (isRequireInvoice > 0)
            {
                if (invoiceContent < 0)
                {
                    return this.Json(new AjaxResponse(-1, "发票内容错误"));
                }
            }

            #endregion

            #region 检查收货地址ID是否填写正确

            if (addressID <= 0)
            {
                return this.Json(new AjaxResponse(-1, "收货地址错误"));
            }

            var address = new UserReceiveAddressService().QueryByID(addressID);

            //收货地址必须与用户对应
            if (address == null || address.UserID != this.UserSession.UserID)
            {
                return this.Json(new AjaxResponse(-1, "收货地址错误"));
            }

            var addressModel = DataTransfer.Transfer<UserReceiveAddressModel>(address, typeof(User_RecieveAddress));

            if (!new UtilityController().ValidSupportRegion(addressModel.ProvinceID))
            {
                return this.Json(new AjaxResponse(-1, "对不起," + addressModel.CountyName("-") + "暂不支持。"));
            }

            #endregion

            var orderService = new OrderService(this.UserSession.UserID, false);
            try
            {
                var cart = MongoDBHelper.GetModel<UserCartModel>(u => u.VisitorKey == this.UserSession.VisitorKey);
                if (cart == null || cart.BuyList == null || cart.BuyList.Count < 1)
                {
                    return this.Json(new AjaxResponse(-1, "商品不存在或已下架。"));
                }

                string message;

                #region 检查商品列表信息

                if (!CheckBuyProducts(cart.BuyList, out message))
                {
                    LogUtils.Log(
                        message,
                        "前台提交订单:Add",
                        Category.Info,
                        this.UserSession.SessionId,
                        this.UserSession.UserID,
                        "Order/Add");
                    return this.Json(new AjaxResponse(0, message));
                }

                #endregion

                //获取促销相关信息
                var productDictionary = new Dictionary<int, int>();

                foreach (var orderProduct in cart.BuyList)
                {
                    productDictionary.Add(orderProduct.ProductID, orderProduct.Quantity);
                }

                var orderBill = this.GetOrderBill(productDictionary); //new OrderBillServices().QueryOrderBill(productDictionary, this.UserSession.UserID);

                if (orderBill == null
                    || ((orderBill.Products == null || orderBill.Products.Count < 1)
                        && (orderBill.SuitPromoteInfos == null || orderBill.SuitPromoteInfos.Count < 1)))
                {
                    LogUtils.Log("没有获取订单促销信息", "Add", Category.Warn);
                    return this.Json(new AjaxResponse(-1, "商品不存在或者已下架。"));
                }

                #region 检查促销活动

                //限购验证
                foreach (var cartProduct in orderBill.Products)
                {
                    //验证是否有多选一情况
                    if (cartProduct.DenyFlag > 0)
                    {
                        switch (cartProduct.DenyFlag)
                        {
                            case 1:
                                return this.Json(new AjaxResponse(0, string.Format("对不起,{0} 只允许新会员购买!", cartProduct.ProductName)));
                            case 2:
                                return this.Json(new AjaxResponse(0, string.Format("对不起,{0} 只允许老会员购买!", cartProduct.ProductName)));
                            case 3:
                                return
                                    this.Json(new AjaxResponse(0, string.Format("对不起,{0} 只允许通过手机验证会员购买!", cartProduct.ProductName)));
                            case 4:
                                return
                                    this.Json(new AjaxResponse(0, string.Format("对不起,{0} 只允许通过邮箱验证会员购买。", cartProduct.ProductName)));
                            case 5:
                                return this.Json(new AjaxResponse(0, string.Format("对不起,{0} 请先登录。", cartProduct.ProductName)));
                            default:
                                return
                                    this.Json(new AjaxResponse(0, string.Format("对不起,{0} 您不满足此商品的购买条件。", cartProduct.ProductName)));
                        }
                    }

                    //验证多选一互斥促销
                    if (cartProduct.Promotes!=null&&cartProduct.Promotes.FirstOrDefault(p => p.PromoteType == 4) != null && !string.IsNullOrWhiteSpace(cartProduct.Exclude))
                    {
                        var userCart = MongoDBHelper.GetModel<UserCartModel>(u => u.VisitorKey == this.UserSession.VisitorKey);
                        if (userCart != null && userCart.ProductItems.Count > 0)
                        {
                            var excludes = cartProduct.Exclude.Split(',');
                            if (excludes.Length > 0)
                            {
                                foreach (var item in userCart.ProductItems)
                                {
                                    if (item.ProductID != cartProduct.ProductID && excludes.Contains(item.ProductID.ToString()))
                                    {
                                        return
                                            this.Json(
                                                new AjaxResponse(
                                                    0,
                                                    string.Format(
                                                        "对不起,【{0}】与【{1}】不能同时购买。",
                                                        item.ProductName,
                                                        cartProduct.ProductName)));
                                    }
                                }
                            }
                        }
                    }

                    //判断是否是限时抢购,且是否超出了限制量。
                    if (cartProduct.LimitedBuyQuantity > 0 && cartProduct.MaxBuyQuantity < cartProduct.Quantity)
                    {
                        LogUtils.Log("用户订单商品数量超出了限时抢购数量", "Add", Category.Info);
                        return
                            this.Json(
                                new AjaxResponse(
                                    0,
                                    string.Format(
                                        "对不起,{0} 每人限购{1}件,你还可以购买{2}件。",
                                        cartProduct.ProductName,
                                        cartProduct.LimitedBuyQuantity,
                                        cartProduct.MaxBuyQuantity)));
                    }

                    //若是限时抢购,判断是否还有活动库存
                    if (cartProduct.LimitedBuyQuantity > 0 && cartProduct.PromoteResidueQuantity < cartProduct.Quantity)
                    {
                        LogUtils.Log(
                            string.Format(
                                "{0} 活动库存不满足,库存仅剩 {1},用户下单{2}",
                                cartProduct.ProductName,
                                cartProduct.PromoteResidueQuantity,
                                cartProduct.Quantity),
                            "Add",
                            Category.Info);

                        return
                            this.Json(
                                new AjaxResponse(
                                    0,
                                    string.Format(
                                        "对不起,{0} 活动库存不满足,库存仅剩 {1}件。",
                                        cartProduct.ProductName,
                                        cartProduct.PromoteResidueQuantity)));
                    }
                }

                //检查组合促销商品限购情况
                if (orderBill.SuitPromoteInfos != null)
                {
                    foreach (var suitPromoteInfo in orderBill.SuitPromoteInfos)
                    {
                        if (suitPromoteInfo.Products != null)
                        {
                            foreach (var cartProduct in suitPromoteInfo.Products)
                            {
                                //判断是否是限时抢购,且是否超出了限制量。
                                if (cartProduct.LimitedBuyQuantity > 0 && cartProduct.MaxBuyQuantity < cartProduct.Quantity)
                                {
                                    LogUtils.Log("用户订单商品数量超出了限时抢购数量", "Add", Category.Info);
                                    return
                                        this.Json(
                                            new AjaxResponse(
                                                0,
                                                string.Format(
                                                    "对不起,{0} 每人限购{1}件,你还可以购买{2}件。",
                                                    cartProduct.ProductName,
                                                    cartProduct.LimitedBuyQuantity,
                                                    cartProduct.MaxBuyQuantity)));
                                }

                                //若是限时抢购,判断是否还有活动库存
                                if (cartProduct.LimitedBuyQuantity > 0 && cartProduct.PromoteResidueQuantity < cartProduct.Quantity)
                                {
                                    LogUtils.Log(
                                        string.Format(
                                            "{0} 活动库存不满足,库存仅剩 {1},用户下单{2}",
                                            cartProduct.ProductName,
                                            cartProduct.PromoteResidueQuantity,
                                            cartProduct.Quantity),
                                        "Add",
                                        Category.Info);

                                    return
                                        this.Json(
                                            new AjaxResponse(
                                                0,
                                                string.Format(
                                                    "对不起,{0} 活动库存不满足,库存仅剩 {1}件。",
                                                    cartProduct.ProductName,
                                                    cartProduct.PromoteResidueQuantity)));
                                }
                            }
                        }
                    }
                }
                #endregion

                DateTime createTime;
                var orderCode = MadeCodeService.GetOrderCode(out createTime);
                var order = new Order
                                {
                                    UserID = this.UserSession.UserID,
                                    RecieveAddressID = addressID,
                                    CpsID = 0,
                                    PaymentMethodID = payMethod,
                                    OrderCode = orderCode,
                                    OrderNumber = MadeCodeService.ReverseOrderCode(orderCode, createTime),
                                    TotalMoney = 0,
                                    TotalIntegral = 0,
                                    PaymentStatus = 0,
                                    IsRequireInvoice = isRequireInvoice != 0,
                                    Status = payMethod == 0 ? 100 : 0, // 若是在线支付,则设置为等待付款,否则设置为等待确认
                                    Remark = intro,
                                    CreateTime = createTime
                                };

                //获取CPS信息
                order.CpsID = this.GetCpsID();

                Order_Invoice invoice = null;

                if (isRequireInvoice!=0) //需要开发票
                {
                    invoice = new Order_Invoice
                                  {
                                      InvoiceContentID = invoiceContent,
                                      InvoiceTitle =
                                          string.IsNullOrWhiteSpace(invoiceTitle) ? "个人" : invoiceTitle,
                                      InvoiceTypeID = 0
                                  };
                }

                var promoteList = new List<Order_Product_Promote>();
                var buyProducts=new List<Order_Product>();
                var giftCoupons = new List<Gift_Coupon>();

                double totalAmount = 0, totalDiscount = 0, tempDiscount = 0;

                totalAmount += SetBuyList(order.ID, orderBill.Products, ref buyProducts, ref promoteList, out tempDiscount);
                totalDiscount += tempDiscount;

                //组合促销商品
                if (orderBill.SuitPromoteInfos != null)
                {
                    foreach (var suitPromote in orderBill.SuitPromoteInfos)
                    {
                        totalDiscount += suitPromote.PromoteDiscount;

                        totalAmount += SetBuyList(
                            order.ID,
                            suitPromote.Products,
                            ref buyProducts,
                            ref promoteList,
                            out tempDiscount);

                        totalDiscount += tempDiscount;

                        //成交价 = 单品成交价 - 组合优惠摊牌金额
                        if (suitPromote.PromoteDiscount > 0)
                        {
                            for (var i = 0; i < buyProducts.Count; i++)
                            {
                                if (suitPromote.Products.Exists(p => p.ProductID == buyProducts[i].ProductID))
                                {
                                    buyProducts[i].TransactPrice -= buyProducts[i].TransactPrice / suitPromote.TotalPrice
                                                                    * suitPromote.PromoteDiscount;

                                    //组合促销信息
                                    promoteList.Add(
                                        new Order_Product_Promote
                                        {
                                            ProductID = buyProducts[i].ProductID,
                                            PromoteID = suitPromote.PromoteID,
                                            PromoteDiscount =
                                                Math.Round(
                                                    buyProducts[i].TransactPrice / suitPromote.TotalPrice
                                                    * suitPromote.PromoteDiscount,
                                                    2),
                                            PromoteType = suitPromote.PromoteType
                                        });
                                }
                            }
                        }

                        //赠品
                        if (suitPromote.GiftProducts != null)
                        {
                            foreach (var giftProduct in suitPromote.GiftProducts)
                            {
                                var product = new Order_Product
                                                  {
                                                      ProductID = giftProduct.ProductID,
                                                      ProductName = "【赠品】" + giftProduct.ProductName,
                                                      Quantity = giftProduct.Quantity,
                                                      PromotionID = giftProduct.PromotID,
                                                      PromotionType = giftProduct.PromotType,
                                                      TransactPrice = 0,
                                                      PromotionResult = 1,
                                                      Integral = 0,
                                                      RebateRate = 0,
                                                      Commission = 0,
                                                      CreateTime = DateTime.Now
                                                  };
                                buyProducts.Add(product);

                                promoteList.Add(
                                    new Order_Product_Promote
                                        {
                                            OrderID = order.ID,
                                            ProductID = giftProduct.ProductID,
                                            PromoteID = giftProduct.PromotID,
                                            PromoteType = giftProduct.PromotType,
                                            ExtField = "赠品"
                                        });
                            }
                        }

                        if (suitPromote.GiftCoupons != null)
                        {
                            giftCoupons.AddRange(suitPromote.GiftCoupons);
                        }
                    }
                }

                order.TotalMoney = orderBill.TotalPrice - orderBill.TotalDiscount;

                //todo:特殊促销处理,此处为了快速开发,硬编码
                foreach (var cartProduct in buyProducts)
                {
                    if (cartProduct.ProductID == 4153)
                    {
                        order.TotalMoney = order.TotalMoney - cartProduct.TransactPrice;
                        cartProduct.TransactPrice = 0;
                        cartProduct.Quantity = 1;
                    }
                }

                order.DeliveryCost = order.TotalMoney >= 100 ? 0 : 10; //todo:需要改掉
                order.Discount = totalDiscount;
                var orderId = orderService.Add(order, buyProducts, invoice, giftCoupons, promoteList);
                this.ResetUserCart(cart, buyProducts);

                //更新特殊活动
                foreach (var orderProduct in buyProducts)
                {
                    var specialPromotes = MongoDBHelper.GetModels<SpecialPromote>(p => p.GiftProductID == orderProduct.ProductID && p.ID > 0);

                    if (specialPromotes != null && specialPromotes.Count > 0) //若不是,则直接跳过
                    {
                        var specialPromote = specialPromotes[0]; //一个赠品只能参加一个活动

                        var userPromote = specialPromote.UserPromotes.FirstOrDefault(u => u.UserID == this.UserSession.UserID);

                        //即使找不到参加活动的记录,但领取了商品,我们依然认为此用户已经参加了活动
                        if (userPromote == null)
                        {
                            userPromote = new UserPromote { UserID = this.UserSession.UserID };
                        }

                        userPromote.OrderID = order.ID;
                        userPromote.HasGetGift=true;
                        userPromote.GetGiftTime = DateTime.Now;
                        userPromote.GiftID = orderProduct.ProductID;

                        specialPromote.UserPromotes.Remove(u => u.UserID == userPromote.UserID);
                        specialPromote.UserPromotes.Add(userPromote);

                        MongoDBHelper.UpdateModel<SpecialPromote>(specialPromote, sp => sp.ID == specialPromote.ID);
                    }
                }

                LogUtils.Log(
                    "前台添加订单成功,订单编码:" + orderId + "\n\r",
                    "Order.Add",
                    Category.Info,
                    this.UserSession.SessionId,
                    this.UserSession.UserID);

                return this.Json(new AjaxResponse(1, "订单提交成功", order.OrderCode));
            }
            catch (Exception ex)
            {
                LogUtils.Log(
                    "前台添加订单出错了,错误信息:"+ex.Message+"\n\r"+ex.StackTrace,
                    "Order.Add",
                    Category.Error,
                    this.UserSession.SessionId,
                    this.UserSession.UserID);
                return this.Json(new AjaxResponse(-2, "对不起,提交订单出错了。"));
            }
        }
 /// <summary>
 /// 修改订单发票
 /// </summary>
 /// <param name="orderInvoice">
 /// 订单发票对象
 /// </param>
 /// <param name="transaction">
 /// 事务对象
 /// </param>
 public void Modify(Order_Invoice orderInvoice, SqlTransaction transaction)
 {
     this.orderInvoiceDA.Update(orderInvoice, transaction);
 }
 /// <summary>
 /// 添加一条订单发票
 /// </summary>
 /// <param name="orderInvoice">
 /// 订单发票对象
 /// </param>
 /// <param name="transaction">
 /// 事务对象
 /// </param>
 /// <returns>
 /// The <see cref="int"/>.
 /// </returns>
 public int Add(Order_Invoice orderInvoice, SqlTransaction transaction)
 {
     return this.orderInvoiceDA.Insert(orderInvoice, transaction);
 }