示例#1
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
        }
示例#2
0
        /// <summary>
        /// The get order invoic info.
        /// </summary>
        /// <param name="orderId">
        /// The order id.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult GetOrderInvoicInfo(int orderId)
        {
            var orderInvoiceService = new OrderInvoiceService();
            var result = new AjaxResponse();
            try
            {
                var orderInvoice = orderInvoiceService.SelectByOrderID(orderId);
                if (orderInvoice == null)
                {
                    result.State = 2;
                }
                else
                {
                    result.State = 1;
                    if (string.IsNullOrWhiteSpace(orderInvoice.InvoiceTitle))
                    {
                        orderInvoice.InvoiceTitle = "个人";
                    }

                    result.Data = DataTransfer.Transfer<OrderInvoiceModel>(orderInvoice, typeof(Order_Invoice));
                }
            }
            catch (Exception exception)
            {
                result.State = -1;
                result.Message = exception.Message;
            }

            return this.Json(result, JsonRequestBehavior.AllowGet);
        }