コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="order"></param>
        /// <param name="smart"></param>
        private async Task DealOrder(SuccinctOrder order, AsNum.Xmj.Entity.Order eo, bool smart)
        {
            //var eo = biz.GetOrder(order.OrderID, false);

            if (!smart || (eo == null || (
                               (byte)eo.Status != (byte)order.OrderStatus) ||
                           eo.InIssue != order.InIssue
                           ))
            {
                this.LogObserverable.Value.Notify(string.Format("更新订单 {0}", order.OrderID), true);
                var od = await this.GetOrderDetail(order.OrderID);

                //转换为数据库实体
                var o = this.CombineOrderData(od, order);

                var biz = GlobalData.MefContainer.GetExportedValue <IOrder>();
                biz.AddOrEdit(o);
                if (biz.HasError)
                {
                    var str = string.Join(";", biz.Errors.Select(kv => string.Join("{0} : {1}", kv.Key, kv.Value)));
                    this.LogObserverable.Value.Notify(string.Format("订单 {0} : {1}", o.OrderNO, str), false);
                }
            }
            else
            {
                //this.LogObserverable.Value.Notify(string.Format("订单 {0} 未发生变化,跳过", order.OrderID), true);
            }
        }
コード例 #2
0
        /// <summary>
        /// 合并两个接口返回的订单数据
        /// </summary>
        /// <param name="dOrder"></param>
        /// <param name="sOrder"></param>
        /// <returns></returns>
        private AE.Order CombineOrderData(DetailOrder dOrder, SuccinctOrder sOrder)
        {
            var ao = new AE.Order()
            {
                InIssue = sOrder.InIssue,
                //dOrder 的 Amount 不是调整后的价格.
                Amount   = sOrder.Amount.Total,// dOrder.OrderAmount.Total;
                CreteOn  = dOrder.CreateOn,
                Currency = dOrder.OrderAmount.Currency.CurrencyCode,

                OrderNO     = dOrder.OrderNO,
                PaymentOn   = dOrder.PaymentOn,
                PaymentType = sOrder.PaymentType,
                Status      = ((byte)dOrder.Status).ToEnum <AE.OrderStatus>(),
                OffTime     = DateTime.Now.Add(sOrder.OutLeftTime)
            };

            #region details
            ao.Details = dOrder.ChildOrders.Select(d => {
                var sDetail = sOrder.Products.Find(so => so.ChildID.Equals(d.ID));
                return(new AE.OrderDetail()
                {
                    ProductPrice = sDetail.UnitPrice.Total,
                    DeliveryTime = sDetail.DeliveryTime,
                    Image = sDetail.Image,//dOrder 里没有这个数据
                    LotNum = d.LotNum,
                    OrderNO = sOrder.OrderID,
                    PrepareDays = sDetail.PrepareDays,
                    ProductID = d.ProductID,
                    ProductName = d.ProductName,
                    Remark = sDetail.OrderMessage,
                    SKUCode = d.SKUCode,
                    SnapURL = sDetail.SnapURL,
                    SubOrderNO = d.ID,
                    Unit = d.Unit,
                    UnitQty = d.Count,
                    LogisticsType = sDetail.LogisticsType,
                    //老订单返回的没有 LogisticsAmount
                    LogisticAmount = sDetail.LogisticsAmount == null ? 0 : sDetail.LogisticsAmount.Total,
                    Attrs = d.Attributes.SKU.Select(s => new AE.OrderDetailAttribute()
                    {
                        Order = s.Order,
                        OrderNO = dOrder.OrderNO,
                        SubOrderNO = d.ID,
                        AttrStr = string.IsNullOrWhiteSpace(s.CustomValue) ? string.Format("{0}: {1}", s.Name, s.Value) : s.CustomValue,
                        CompatibleStr = s.CompatibleStr
                    }).ToList()
                });
            }
                                                   ).ToList();
            #endregion ;

            #region OrgReceiver
            ao.OrgReceiver = new AE.Receiver()
            {
                OrderNO     = dOrder.OrderNO,
                Address     = string.IsNullOrWhiteSpace(dOrder.Receiver.Address2) ? dOrder.Receiver.Address : string.Format("{0} , {1}", dOrder.Receiver.Address, dOrder.Receiver.Address2),
                City        = dOrder.Receiver.City,
                CountryCode = dOrder.Receiver.CountryCode,
                Mobi        = dOrder.Receiver.Mobi,
                Name        = dOrder.Receiver.ContactPerson,
                Phone       = string.Join("-", new string[] { dOrder.Receiver.PhoneCountry, dOrder.Receiver.PhoneArea, dOrder.Receiver.Phone }.Where(s => !string.IsNullOrWhiteSpace(s))),
                PhoneArea   = dOrder.Receiver.PhoneArea,
                Province    = dOrder.Receiver.Province,
                ZipCode     = dOrder.Receiver.ZipCode,
            };
            #endregion

            #region Logistics
            ao.Logistics = dOrder.LogisticInfos.Where(l => l.SendOn.HasValue).Select(l => new AE.OrdeLogistic()
            {
                SendOn  = l.SendOn,
                TrackNO = l.TrackingNo,
                //LogisticsType = l.TypeCode.ToEnum<AE.LogisticsTypes>(),
                LogisticCode = l.TypeCode,
                OrderNO      = sOrder.OrderID
            }).ToList();
            #endregion

            #region Account
            ao.Account   = sOrder.Account;
            ao.AccountOf = new AE.Owner()
            {
                Account     = sOrder.Account,
                AccountType = AE.AccountTypes.Ali
            };
            #endregion

            #region buyer
            //某些订单,在订单列表里,是没有BuyerID 的,导至保存失败
            ao.BuyerID = dOrder.Customer.LoginID;
            ao.Buyer   = new AE.Buyer()
            {
                BuyerID     = dOrder.Customer.LoginID,
                CountryCode = dOrder.Customer.CountryCode,
                Email       = dOrder.Customer.Email,
                Name        = string.Format("{0} {1}", dOrder.Customer.FirstName, dOrder.Customer.LastName)
            };
            #endregion

            return(ao);
        }