Exemplo n.º 1
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("订单状态异常。");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 订单在线支付
        /// </summary>
        /// <param name="order">订单对象</param>
        /// <param name="totalFee">支付金额</param>
        /// <param name="orderOrgID">支付方式(支付宝,财富通,工行,农行等)</param>
        /// <param name="tradeNo">支付交易号</param>
        /// <returns>返回修改订单成功与否</returns>
        public bool OrderOnLinePayment(Order order, double totalFee, int orderOrgID, string tradeNo)
        {
            //支付成功,改写数据库订单信息
            //添加支付记录信息
            //添加订单状态跟踪信息

            LogUtils.Log(
                string.Format("系统更新在线支付订单信息,订单编码:{0},支付平台编码:{1},支付交易号:{2}", order.ID, orderOrgID, tradeNo),
                "OrderOnLinePayment",
                Category.Info,
                null,
                this.userID);

            order.Status = order.Status == 100 ? 0 : order.Status;
            this.orderDA.SqlServer.BeginTransaction();
            var transaction = this.orderDA.SqlServer.Transaction;
            try
            {
                this.Edit(order, transaction);
                var orderPaymentDa = new DAFactoryTransact().CreateOrderPaymentDA();
                var payment = new Order_Payment
                                  {
                                      OrderID = order.ID,
                                      IsDelete = 0,
                                      IsUseAccount = false,
                                      IsUseCoupon = false,
                                      IsUseIntegral = false,
                                      PaymentMoney = totalFee,
                                      TradeNo = tradeNo,
                                      PaymentOrgID = orderOrgID,
                                      CreateTime = DateTime.Now
                                  };
                orderPaymentDa.Insert(payment, transaction);

                new OrderStatusTrackingService().Add(
                    new Order_Status_Tracking
                    {
                        OrderID = order.ID,
                        EmployeeID = isBackage ? this.userID : 0,
                        UserID = isBackage?0:this.userID,
                        Remark = "订单已支付",
                        Status = order.Status
                    },
                    transaction);
                transaction.Commit();

                //检查是否可以由系统自动确认订单
                try
                {
                    if (!this.ConfirmOrderBySystem(order,payment))
                    {
                        LogUtils.Log(
                            string.Format("在线支付成功后,订单自动确认失败,订单编码:{0},支付平台编码:{1},支付交易号:{2}", order.ID, orderOrgID, tradeNo),
                            "在线支付订单状态更新",
                            Category.Warn,
                            null,
                            this.userID);
                    }
                    else
                    {
                        LogUtils.Log(
                            string.Format("在线支付成功后,订单自动确认成功,订单编码:{0},支付平台编码:{1},支付交易号:{2}", order.ID, orderOrgID, tradeNo),
                            "在线支付订单状态更新",
                            Category.Info,
                            null,
                            this.userID);
                    }
                }
                catch (Exception ex)
                {
                    LogUtils.Log(
                            string.Format("在线支付成功后,订单自动确认时出错,订单编码:{0},支付平台编码:{1},支付交易号:{2},错误信息:{3},堆栈:{4}", order.ID, orderOrgID, tradeNo,ex.Message,ex.StackTrace),
                            "在线支付订单状态更新",
                            Category.Error,
                            null,
                            this.userID);
                }

                return true;
            }
            catch(Exception exception)
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                    if (transaction.Connection!=null&&transaction.Connection.State != ConnectionState.Closed)
                    {
                        transaction.Connection.Close();
                    }
                }

                TextLogger.Instance.Log("更新订单支付信息出错~~", Category.Error, exception);
                LogUtils.Log(
                    string.Format(
                        "用户,UserID={0}已支付订单{1},处理订单状态是出错。错误信息:{2}",
                        this.userID,
                        order.OrderCode,
                        exception.Message),
                    "UpdatePayment",
                    Category.Error);
                return false;
            }
        }
Exemplo n.º 3
0
 public void Edit(Order order,SqlTransaction transaction)
 {
     this.orderDA.Update(order, transaction);
 }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
0
        /// <summary>
        /// 确认订单--修改订单信息
        /// </summary>
        /// <param name="order">
        /// 订单对象
        /// </param>
        /// <param name="transaction">
        /// 事务对象
        /// </param>
        /// <param name="orderProducts"></param>
        public void ConfirmByUpdateOrder(Order order, SqlTransaction transaction, Order_Payment orderPayment, List<Order_Product> orderProducts = null)
        {
            this.orderDA.UpdateForConfirmOrder(order, transaction);

            if (Utils.IsPushERP) //判断是否推送ERP
            {
                string errorMsg;
                if (!this.PushOrderToHwErp(order, orderProducts, transaction, out errorMsg, orderPayment))
                {
                    throw new Exception("订单推送失败,原因:" + errorMsg); //推送失败,主动抛出异常,让外边的程序进行回滚
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 系统自动确认订单
        /// </summary>
        /// <param name="order">
        /// 订单对象
        /// </param>
        /// <returns>
        /// 系统确认是否成功
        /// </returns>
        public bool ConfirmOrderBySystem(Order order, Order_Payment payment = null)
        {
            /**
             * 系统自动审核订单步骤
             * 1. 检查是否符合自动审核条件
             * 2. 改变订单状态至已确认(1)
             * 3. 添加订单跟踪信息
             * **/

            if (!this.ValidateConfirmOrderBySystem(order))
            {
                LogUtils.Log(
                            string.Format("系统自动确认订单失败,原因:不符合条件。订单编码:{0}", order.ID),
                            "检查订单自动确认是否符合条件:ConfirmOrderBySystem",
                            Category.Info,
                            null,
                            this.userID);

                TextLogger.Instance.Log("系统自动确认订单失败,原因:不符合条件", Category.Warn, null);
                return false;
            }

            LogUtils.Log(
                string.Format("检查订单符合系统自动确认条件。订单编码:{0}", order.ID),
                "检查订单自动确认是否符合条件:ConfirmOrderBySystem",
                Category.Info,
                null,
                this.userID);

            SqlTransaction transaction = null;

            try
            {
                this.orderDA.SqlServer.BeginTransaction();
                transaction = this.orderDA.SqlServer.Transaction;

                this.ConfirmByUpdateOrder(order, transaction, payment);

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

                LogUtils.Log(
                    string.Format("系统自动确认订单成功。订单编码:{0}", order.ID),
                    "系统自动确认订单:ConfirmOrderBySystem",
                    Category.Info,
                    null,
                    this.userID);

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

                LogUtils.Log(
                    string.Format(
                        "系统自动确认订单发生错误,需客服手动确认。订单编码:{0},错误信息:{1},堆栈:{2}",
                        order.ID,
                        exception.Message,
                        exception.StackTrace),
                    "系统自动确认订单:ConfirmOrderBySystem",
                    Category.Error,
                    null,
                    this.userID);

                TextLogger.Instance.Log("系统自动确认订单失败,需客服手动确认", Category.Error, exception);

                return false;
            }
        }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
0
        private bool PushOrderToHwErp(Order order, List<Order_Product> orderProducts, SqlTransaction transaction, out string errorMsg, Order_Payment payment = null)
        {
            #region 订单推送ERP

            #region 订单基本信息

            errorMsg = string.Empty;

            var hi = new HwRest.HwOrderInfo();

            hi.orderNumber = order.OrderCode;
            hi.orderDate = order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
            if (order.PaymentStatus == 1)
            {
                //var orderPayment = new OrderPaymentService().QueryByOrderID(order.ID);
                //if (orderPayment != null) hi.payTime = Convert.ToDateTime(orderPayment.CreateTime).ToString();

                //todo:若订单已在线支付,则认为是当前时间支付,因为在线支付订单是有系统在支付时自动确认的。当时不够准确。
                hi.payTime = payment == null ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : payment.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
            }

            if (string.IsNullOrWhiteSpace(hi.payTime))
            {
                hi.payTime = "";
            }

            var orderReceiveAddress = new UserReceiveAddressService().QueryByID(order.RecieveAddressID);

            hi.buyerNick = string.IsNullOrWhiteSpace(order.UserName) ? orderReceiveAddress.Consignee : order.UserName;
            hi.totalAmount = Math.Round(order.TotalMoney + order.DeliveryCost, 2).ToString();
            hi.payment = payment == null
                             ? (order.TotalMoney + order.DeliveryCost).ToString()
                             : Math.Round(payment.PaymentMoney, 2).ToString();
            hi.postAmount = order.DeliveryCost.ToString();
            hi.discount = order.Discount.ToString();
            hi.points = "";
            hi.pointsAmount = "";
            hi.couponsAmount = "";
            hi.virtualAmount = "";
            hi.fullMinus = "";
            var orderInvoice = new OrderInvoiceService().SelectByOrderID(order.ID);
            hi.invoiceTitle = orderInvoice != null ? orderInvoice.InvoiceTitle : "";
            hi.invoiceContent = orderInvoice != null ? orderInvoice.InvoiceContent : "";
            hi.invoiceAmount = orderInvoice != null ? orderInvoice.InvoiceCost.ToString() : "";
            hi.tradeFrom = "官网订单";

            if (order.PaymentMethodID == 0)
            {
                if (payment != null)
                {
                    hi.paymentType = payment.PaymentOrgName;
                }
                else
                {
                    hi.paymentType = "网上支付";
                }
                hi.sellerMemo = "";
            }
            else
            {
                hi.paymentType = "货到付款";
                hi.sellerMemo = "";
            }

            hi.consignee = orderReceiveAddress != null ? orderReceiveAddress.Consignee : order.UserName;
            if (orderReceiveAddress != null)
            {
                if (!string.IsNullOrWhiteSpace(orderReceiveAddress.CountyName(",")))
                {
                    var strs = orderReceiveAddress.CountyName(",").Split(',');
                    if (strs.Length == 3)
                    {
                        hi.province = strs[0];
                        hi.city = strs[1];
                        hi.cityarea = strs[2];
                    }
                    else
                    {
                        hi.cityarea = orderReceiveAddress.CountyName(",");
                        hi.province = "";
                        hi.city = "";
                    }
                }
            }
            else
            {
                hi.cityarea = "";
                hi.province = "";
                hi.city = "";
            }

            hi.address = orderReceiveAddress != null ? orderReceiveAddress.Address : "";
            hi.mobilePhone = orderReceiveAddress != null ? orderReceiveAddress.Mobile : "";
            hi.telephone = orderReceiveAddress != null ? orderReceiveAddress.Tel : "";
            hi.zip = orderReceiveAddress != null ? orderReceiveAddress.ZipCode : "";
            hi.buyerMessage ="客户备注:"+ order.Remark + ";客服备注:" + order.Description;

            #endregion

            #region 商品列表

            List<HwRest.HwProductList> hplist = new List<HwRest.HwProductList>();
            if (orderProducts == null || orderProducts.Count < 1)
            {
                orderProducts = new OrderProductService().QueryByOrderId(order.ID);
            }

            foreach (var orderProduct in orderProducts)
            {
                var hwProduct =
                    hplist.FirstOrDefault(p => p.productNumber == orderProduct.Barcode && orderProduct.TransactPrice <= 0);

                //赠品与正常商品合并
                if (hwProduct != null)
                {
                    hwProduct.orderCount = (int.Parse(hwProduct.orderCount) + orderProduct.Quantity).ToString();
                    hwProduct.giftCount = (int.Parse(hwProduct.giftCount) + orderProduct.Quantity).ToString();
                    //将商品价格当做优惠金额进行处理
                    hwProduct.discountFee = (int.Parse(hwProduct.discountFee) + int.Parse(hwProduct.price) * orderProduct.Quantity).ToString();
                }
                else
                {
                    HwRest.HwProductList hpl = new HwRest.HwProductList();
                    hpl.productNumber = orderProduct.Barcode; //新系统中没有商品编号,此处设为商品条形码
                    hpl.productName = orderProduct.ProductName;
                    hpl.skuNumber = orderProduct.Barcode;
                    hpl.skuName = "";
                    hpl.price = orderProduct.TransactPrice.ToString();
                    hpl.orderCount = orderProduct.Quantity.ToString();
                    hpl.giftCount = (orderProduct.TransactPrice > 0 ? 0 : orderProduct.Quantity).ToString();
                    hpl.amount = (orderProduct.TransactPrice * orderProduct.Quantity).ToString();
                    hpl.memo = orderProduct.TransactPrice > 0 ? "" : "【赠品】";
                    hpl.discountFee = "0";
                    hpl.barcode = orderProduct.Barcode;
                    hplist.Add(hpl);
                }
            }

            #endregion

            HwRest.OWebOrderItems OWebOrderItems = new HwRest.OWebOrderItems();
            OWebOrderItems.OWebOrderItem = hplist.ToArray();

            HwRest.HwOrderAdd_Info hai = new HwRest.HwOrderAdd_Info();
            hi.OWebOrderItems = OWebOrderItems;
            hai.OWebOrder = hi;

            HwRest.HwClient HwClient = new HwRest.HwClient();
            HwClient.XmlValues = hai.ToXmlParameter();
            HwClient.OrderNumber = hi.orderNumber;
            string HwBackXml = HwClient.Execute();

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(HwBackXml);
            XmlNode root = doc.SelectSingleNode("//Response");

            var log = new Order_Erp_Log
                          {
                              ERP = "HW_ERP",
                              OrderID = order.ID,
                              OperateType = 1,
                              ReqContent = HwClient.XmlValues,
                              ResContent = HwBackXml,
                              UserID = order.UserID,
                              Operator = isBackage ? this.userID : 0,
                              CreateTime = DateTime.Now
                          };

            if (payment != null)
            {
                log.ExtField = "在线支付订单,支付时间:" + payment.CreateTime;
            }

            var result = false;

            if (HwBackXml.Contains("推单异常") || root.FirstChild.InnerText.ToLower() != "true")
            {
                log.IsSuccess = false;

                //获取退单错误信息
                var errorNode = root.SelectSingleNode("//value");

                if (errorNode != null)
                {
                    errorMsg = errorNode.InnerText;
                }

                result = false;

                LogUtils.Log("订单推送失败,订单编码:" + order.ID + ",错误消息:" + HwBackXml, "订单推送ERP", Category.Error);
            }
            else
            {
                log.IsSuccess = true;
                result = true;
                LogUtils.Log("订单推送成功,订单编码:" + order.ID, "订单推送ERP");
            }

            try
            {
                var orderErpLogService = new OrderERPLogService();
                orderErpLogService.Add(log, null); //添加日志,无需事务,防止回滚
            }
            catch(Exception exception)
            {
                LogUtils.Log(
                    string.Format(
                        "[Order_ERP]订单推送成功,但是写入日志信息发生错误。订单编号:{0},错误信息:{1}/{2}",
                        order.OrderCode,
                        exception.Message,
                        exception.InnerException),
                    "[Order_ERP]订单推送",
                    Category.Error);
            }

            return result;

            #endregion
        }
Exemplo n.º 9
0
        /// <summary>
        /// 重置订单信息
        /// </summary>
        /// <param name="orderDetail"></param>
        /// <param name="products"></param>
        /// <param name="productList"></param>
        /// <returns></returns>
        private Order ResetOrderInfo(OrderDetailModel orderDetail, List<OrderProductModel> products, out List<Order_Product> productList)
        {
            productList = new List<Order_Product>();
            var orginalOrderProducts = new OrderProductService().QueryByOrderId(orderDetail.OrderInfo.ID);

            foreach (var product in products)
            {
                var originalOrderProduct = orginalOrderProducts.FirstOrDefault(p => p.ID == product.ID);
                Order_Product orderProduct = null;
                if (originalOrderProduct != null)
                {
                    originalOrderProduct.TransactPrice = product.TransactPrice;
                    originalOrderProduct.Quantity = product.Quantity;
                    orderProduct = originalOrderProduct;
                }
                else
                {
                    //新增的商品
                    orderProduct = DataTransfer.Transfer<Order_Product>(product, typeof(OrderProductModel));
                }

                productList.Add(orderProduct);
            }

            var order = new Order
                        {
                            CpsID = orderDetail.OrderInfo.CpsID,
                            DeliveryCost = orderDetail.OrderInfo.DeliveryCost,
                            Description = orderDetail.OrderInfo.Description,
                            ID = orderDetail.OrderInfo.ID,
                            IsRequireInvoice = orderDetail.OrderInfo.IsRequireInvoice
                        };
            return order;
        }
Exemplo n.º 10
0
 /// <summary>
 /// 判断订单是否能够由系统审核
 /// </summary>
 /// <param name="order">
 /// 订单对象
 /// </param>
 /// <returns>
 /// 是否能够被系统审核。可以:True,否则:false
 /// </returns>
 public bool ValidateConfirmOrderBySystem(Order order)
 {
     /*
      *符合系统审核订单的条件:
      *1. 在线支付,且已付款。
      *2. 货到付款,且总金额小于1000.待添加
      */
     return (order.PaymentMethodID == 0 && order.PaymentStatus == 1);
     //|| (order.PaymentMethodID == 1 && order.TotalMoney < 1000);
 }
Exemplo n.º 11
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, "对不起,提交订单出错了。"));
            }
        }
Exemplo n.º 12
0
        public ActionResult AddOrder(
            List<ProductModel> products,
            int userID,
            int receiveAddressID,
            int paymentMethodID,
            bool isRequireInvoice,
            OrderInvoiceModel invoiceInfo,
            string description = null)
        {
            try
            {
                if (products == null || products.Count < 1)
                {
                    var data = new AjaxResponse(-1, "订单商品为空!");
                    return this.Json(data);
                }

                if (userID < 1)
                {
                    var data = new AjaxResponse(-1, "用户编码错误!");
                    return this.Json(data);
                }

                if (receiveAddressID < 1)
                {
                    var data = new AjaxResponse(-1, "收货信息地址编码错误!");
                    return this.Json(data);
                }

                if (paymentMethodID < 0)
                {
                    var data = new AjaxResponse(-1, "支付地址错误!");
                    return this.Json(data);
                }

                Order_Invoice invoice = null;
                if (isRequireInvoice)
                {
                    if (invoiceInfo.InvoiceContentID < 0)
                    {
                        var data = new AjaxResponse(-1, "发票消费类别错误!");
                        return this.Json(data);
                    }
                    else if (string.IsNullOrWhiteSpace(invoiceInfo.InvoiceTitle))
                    {
                        var data = new AjaxResponse(-1, "发票抬头为空!");
                        return this.Json(data);
                    }
                    else if (invoiceInfo.InvoiceCost < 0)
                    {
                        var data = new AjaxResponse(-1, "开票金额不能小于或等于0!");
                        return this.Json(data);
                    }

                    invoice = DataTransfer.Transfer<Order_Invoice>(invoiceInfo, typeof(OrderInvoiceModel));
                }

                DateTime createTime;
                var orderCode = MadeCodeService.GetOrderCode(out createTime);

                var orderService = new OrderService(this.SystemUserSession.EmployeeID);
                var order = new Order
                                {
                                    UserID = userID,
                                    RecieveAddressID = receiveAddressID,
                                    CpsID = 0,
                                    PaymentMethodID = paymentMethodID,
                                    OrderCode = orderCode,
                                    OrderNumber = MadeCodeService.ReverseOrderCode(orderCode, createTime),
                                    TotalMoney = 0,
                                    TotalIntegral = 0,
                                    PaymentStatus = 0,
                                    IsRequireInvoice = isRequireInvoice,
                                    Status = paymentMethodID == 0 ? 100 : 0,
                                    Description = string.IsNullOrWhiteSpace(description) ? "后台添加订单" : description,
                                    CreateTime = createTime
                                };

                var orderProducts = new List<Order_Product>();

                foreach (var productModel in products)
                {
                    if (productModel.Quantity > 0)
                    {
                        orderProducts.Add(
                            new Order_Product
                                {
                                    ProductID = productModel.ID,
                                    Quantity = productModel.Quantity,
                                    ProductName = productModel.Name,
                                    TransactPrice = productModel.GoujiuPrice,
                                    CreateTime = DateTime.Now
                                });
                    }
                }

                // 判断是否能够由系统自动确认订单,若能,则自动确认。
                orderService.Add(order, orderProducts, invoice);

                if (orderService.ValidateConfirmOrderBySystem(order))
                {
                    orderService.ConfirmOrderBySystem(order);
                }

                return this.Json(new AjaxResponse(1, "执行成功"));
            }
            catch (Exception exception)
            {
                var data = new AjaxResponse(-1, exception.Message);
                TextLogger.Instance.Log("后台添加订单发生错误", Category.Error, exception);
                return this.Json(data);
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// 添加订单
 /// </summary>
 /// <param name="order">
 /// 订单兑现
 /// </param>
 /// <param name="transaction">
 /// 数据库事务
 /// </param>
 /// <returns>
 /// 已添加订单的编码
 /// </returns>
 public int Insert(Order order, out SqlTransaction transaction)
 {
     this.SqlServer.BeginTransaction();
     transaction = this.SqlServer.Transaction;
     var paras = new List<SqlParameter>
                     {
                         this.SqlServer.CreateSqlParameter(
                             "UserID",
                             SqlDbType.Int,
                             order.UserID,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "RecieveAddressID",
                             SqlDbType.Int,
                             order.RecieveAddressID,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "CpsID",
                             SqlDbType.Int,
                             order.CpsID,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "PaymentMethodID",
                             SqlDbType.Int,
                             order.PaymentMethodID,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "OrderCode",
                             SqlDbType.VarChar,
                             order.OrderCode,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "OrderNumber",
                             SqlDbType.VarChar,
                             order.OrderNumber,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "TotalMoney",
                             SqlDbType.Float,
                             order.TotalMoney,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "Discount",
                             SqlDbType.Float,
                             order.Discount,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "TotalIntegral",
                             SqlDbType.Int,
                             order.TotalIntegral,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "PaymentStatus",
                             SqlDbType.Int,
                             order.PaymentStatus,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "Status",
                             SqlDbType.Int,
                             order.Status,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "Description",
                             SqlDbType.NVarChar,
                             order.Description,
                             ParameterDirection.Input),
                             this.SqlServer.CreateSqlParameter(
                             "Remark",
                             SqlDbType.NVarChar,
                             order.Remark,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "CreateTime",
                             SqlDbType.DateTime,
                             order.CreateTime,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "IsRequireInvoice",
                             SqlDbType.Bit,
                             order.IsRequireInvoice,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "DeliveryCost",
                             SqlDbType.Float,
                             order.DeliveryCost,
                             ParameterDirection.Input),
                         this.SqlServer.CreateSqlParameter(
                             "ReferenceID",
                             SqlDbType.Int,
                             order.ID,
                             ParameterDirection.Output)
                     };
     this.SqlServer.ExecuteNonQuery(
             CommandType.StoredProcedure,
             "sp_Order_Insert",
             paras,
             transaction);
     return (int)paras.Find(parameter => parameter.ParameterName == "ReferenceID").Value;
 }
Exemplo n.º 14
0
        /// <summary>
        /// 确认订单信息
        /// </summary>
        /// <param name="order">
        /// 订单对象
        /// </param>
        /// <param name="transaction">
        /// 事务对象
        /// </param>
        public void UpdateForConfirmOrder(Order order, SqlTransaction transaction)
        {
            var paras = new List<SqlParameter>
                            {
                                this.SqlServer.CreateSqlParameter(
                                    "ID",
                                    SqlDbType.Int,
                                    order.ID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "CpsID",
                                    SqlDbType.Int,
                                    order.CpsID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "DeliveryCost",
                                    SqlDbType.Float,
                                    order.DeliveryCost,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "TotalMoney",
                                    SqlDbType.Float,
                                    order.TotalMoney,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "TotalIntegral",
                                    SqlDbType.Float,
                                    order.TotalIntegral,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "Description",
                                    SqlDbType.NVarChar,
                                    order.Description,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "IsRequireInvoice",
                                    SqlDbType.Bit,
                                    order.IsRequireInvoice,
                                    ParameterDirection.Input)
                            };

            this.SqlServer.ExecuteNonQuery(CommandType.StoredProcedure, "sp_Order_UpdateForConfirmOrder", paras, transaction);
        }
Exemplo n.º 15
0
        public void Update(Order order, SqlTransaction transaction)
        {
            /**
             Create Procedure sp_Order_Update
                @ID int,
                @UserID int,
                @RecieveAddressID int,
                @CpsID int,
                @PaymentMethodID int,
                @OrderCode varchar(16),
                @OrderNumber varchar(16),
                @DeliveryCost float,
                @TotalMoney float,
                @TotalIntegral int,
                @PaymentStatus int,
                @IsRequireInvoice bit,
                @Status int,
                @Description nvarchar(512),
                @Remark nvarchar(512)
             **/

            this.SqlServer.BeginTransaction();
            if (transaction == null)
            {
                transaction = this.SqlServer.Transaction;
            }

            var paras = new List<SqlParameter>
                            {
                                this.SqlServer.CreateSqlParameter(
                                    "ID",
                                    SqlDbType.Int,
                                    order.ID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "UserID",
                                    SqlDbType.Int,
                                    order.UserID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "RecieveAddressID",
                                    SqlDbType.Int,
                                    order.RecieveAddressID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "CpsID",
                                    SqlDbType.Int,
                                    order.CpsID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "PaymentMethodID",
                                    SqlDbType.Int,
                                    order.PaymentMethodID,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "OrderCode",
                                    SqlDbType.VarChar,
                                    order.OrderCode,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "TotalMoney",
                                    SqlDbType.Float,
                                    order.TotalMoney,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "TotalIntegral",
                                    SqlDbType.Int,
                                    order.TotalIntegral,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "PaymentStatus",
                                    SqlDbType.Int,
                                    order.PaymentStatus,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "Status",
                                    SqlDbType.Int,
                                    order.Status,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "Description",
                                    SqlDbType.NVarChar,
                                    order.Description,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "Remark",
                                    SqlDbType.NVarChar,
                                    order.Remark,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "OrderNumber",
                                    SqlDbType.VarChar,
                                    order.OrderNumber,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "IsRequireInvoice",
                                    SqlDbType.Bit,
                                    order.IsRequireInvoice,
                                    ParameterDirection.Input),
                                this.SqlServer.CreateSqlParameter(
                                    "DeliveryCost",
                                    SqlDbType.Float,
                                    order.DeliveryCost,
                                    ParameterDirection.Input),
                                    this.SqlServer.CreateSqlParameter(
                                    "DeliveryCorporationID",
                                    SqlDbType.Float,
                                    order.DeliveryCorporationID,
                                    ParameterDirection.Input)
                            };

            this.SqlServer.ExecuteNonQuery(
                    CommandType.StoredProcedure,
                    "sp_Order_Update",
                    paras,
                    transaction);
        }