Exemplo n.º 1
0
        /// <summary>
        /// 异步查询完成处理查询结果
        /// </summary>
        /// <param name="ar"></param>
        private void QueryCompleted(IAsyncResult ar)
        {
            HttpWebRequest  request        = null;
            HttpWebResponse response       = null;
            Stream          streamResponse = null;
            StreamReader    streamRead     = null;
            string          responseXml    = null;

            try
            {
                request        = (HttpWebRequest)ar.AsyncState;
                response       = (HttpWebResponse)request.EndGetResponse(ar);
                streamResponse = response.GetResponseStream();
                streamRead     = new StreamReader(streamResponse, Encoding.UTF8);
                responseXml    = streamRead.ReadToEnd();
            }
            catch (Exception ex)
            {
                //
            }
            finally
            {
                if (streamRead != null)
                {
                    streamRead.Close();
                }
                if (streamResponse != null)
                {
                    streamResponse.Close();
                }
            }
            //check sign

            YTBatchQueryResponse result = AnalysisResponseXml(responseXml);

            if (result != null && result.orders != null && result.orders.Count > 0)
            {
                foreach (YTOrder item in result.orders)
                {
                    //根据运单号获取订单号
                    int soSysNo = _SODA.GetSOSysNoByTrackingNumber(item.mailNo);
                    if (soSysNo <= 0)
                    {
                        continue;
                    }
                    if (item.orderStatus == YTOrderStatus.UNACCEPT ||
                        item.orderStatus == YTOrderStatus.NOT_SEND ||
                        item.orderStatus == YTOrderStatus.FAILED)
                    {
                        //物流派件不成功,订单更新为物流派件不成功
                        SOStatusChangeInfo soStatusChangeInfo = new SOStatusChangeInfo()
                        {
                            SOSysNo              = soSysNo,
                            OperatorType         = SOOperatorType.System,
                            OperatorSysNo        = 0,
                            Status               = SOStatus.ShippingReject,
                            ChangeTime           = DateTime.Now,
                            IsSendMailToCustomer = false,
                            Note = "物流派件不成功"
                        };
                        _SODA.UpdateSOStatus(soStatusChangeInfo);
                    }
                    if (item.orderStatus == YTOrderStatus.SIGNED)
                    {
                        //已收货,订单更新为已完成
                        SOStatusChangeInfo soStatusChangeInfo = new SOStatusChangeInfo()
                        {
                            SOSysNo              = soSysNo,
                            OperatorType         = SOOperatorType.System,
                            OperatorSysNo        = 0,
                            Status               = SOStatus.Complete,
                            ChangeTime           = DateTime.Now,
                            IsSendMailToCustomer = false,
                            Note = "物流已完成"
                        };
                        _SODA.UpdateSOStatus(soStatusChangeInfo);

                        //已收货,更新SO_CheckShipping表的LastChangeStatusDate字段,以便同步至WMS
                        _SODA.UpdateSOCheckShippingLastChangeStatusDate(soSysNo);

                        //已收货,检查并赠送优惠券
                        var soInfo = ObjectFactory <SOProcessor> .Instance.GetSOBySOSysNo(soSysNo);

                        ObjectFactory <IMKTBizInteract> .Instance.CheckAndGivingPromotionCodeForSO(soInfo);
                    }
                    if (item.steps != null && item.steps.Count > 0)
                    {
                        #region 更新SOLog
                        var routeList = EntityConverter <YTStep, SOLogisticsInfo> .Convert(item.steps, (s, t) =>
                        {
                            t.AcceptAddress = s.acceptAddress;
                            t.AcceptTime    = s.acceptTime;
                            t.Name          = s.name;
                            t.Status        = s.status;
                            t.Type          = ExpressType.YT;
                        });

                        string routeLogMsg = SerializationUtility.XmlSerialize(routeList);
                        var    logList     = _SOLogDA.GetSOLogBySOSysNoAndLogType(soSysNo, BizLogType.Sale_SO_ShippingInfo);
                        bool   bIsCreate   = logList == null || logList.Count == 0;
                        if (bIsCreate)
                        {
                            //创建
                            SOLogInfo soLog = new SOLogInfo()
                            {
                                SOSysNo       = soSysNo,
                                IP            = "::1",
                                OperationType = BizLogType.Sale_SO_ShippingInfo,
                                Note          = routeLogMsg,
                                UserSysNo     = 0,
                                CompanyCode   = "8601"
                            };
                            _SOLogDA.InsertSOLog(soLog);
                        }
                        else
                        {
                            //更新
                            SOLogInfo soLog = logList[0];
                            soLog.Note = routeLogMsg;
                            _SOLogDA.UpdateSOLogNoteBySysNo(soLog);
                        }
                        #endregion
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 异步查询完成处理查询结果
        /// </summary>
        /// <param name="ar"></param>
        private void QueryCompleted(IAsyncResult ar)
        {
            SFExpressQueryDelegate _SFExpressQuery = ar.AsyncState as SFExpressQueryDelegate;
            string responseXml = _SFExpressQuery.EndInvoke(ar);

            List <SFQueryResponseRouteResponse> result = AnalysisResponseXml(responseXml);

            if (result != null)
            {
                foreach (SFQueryResponseRouteResponse item in result)
                {
                    if (item.RouteList != null)
                    {
                        //根据运单号获取订单号
                        int soSysNo = _SODA.GetSOSysNoByTrackingNumber(item.TrackingNumber);
                        if (soSysNo <= 0)
                        {
                            continue;
                        }
                        if (item.RouteList.Exists(m => m.Code.Equals("70")))
                        {
                            //物流派件不成功,订单更新为物流派件不成功
                            SOStatusChangeInfo soStatusChangeInfo = new SOStatusChangeInfo()
                            {
                                SOSysNo              = soSysNo,
                                OperatorType         = SOOperatorType.System,
                                OperatorSysNo        = 0,
                                Status               = SOStatus.ShippingReject,
                                ChangeTime           = DateTime.Now,
                                IsSendMailToCustomer = false,
                                Note = "物流派件不成功"
                            };
                            _SODA.UpdateSOStatus(soStatusChangeInfo);
                        }
                        if (item.RouteList.Exists(m => m.Code.Equals("80")))
                        {
                            //已收货,订单更新为已完成
                            SOStatusChangeInfo soStatusChangeInfo = new SOStatusChangeInfo()
                            {
                                SOSysNo              = soSysNo,
                                OperatorType         = SOOperatorType.System,
                                OperatorSysNo        = 0,
                                Status               = SOStatus.Complete,
                                ChangeTime           = DateTime.Now,
                                IsSendMailToCustomer = false,
                                Note = "物流已完成"
                            };
                            _SODA.UpdateSOStatus(soStatusChangeInfo);

                            //已收货,更新SO_CheckShipping表的LastChangeStatusDate字段,以便同步至WMS
                            _SODA.UpdateSOCheckShippingLastChangeStatusDate(soSysNo);

                            //已收货,检查并赠送优惠券
                            var soInfo = ObjectFactory <SOProcessor> .Instance.GetSOBySOSysNo(soSysNo);

                            ObjectFactory <IMKTBizInteract> .Instance.CheckAndGivingPromotionCodeForSO(soInfo);
                        }
                        #region 更新SOLog
                        var routeList = EntityConverter <SFQueryResponseRoute, SOLogisticsInfo> .Convert(item.RouteList, (s, t) =>
                        {
                            t.Type = ExpressType.SF;
                        });

                        string routeLogMsg = SerializationUtility.XmlSerialize(routeList);
                        var    logList     = _SOLogDA.GetSOLogBySOSysNoAndLogType(soSysNo, BizLogType.Sale_SO_ShippingInfo);
                        bool   bIsCreate   = logList == null || logList.Count == 0;
                        if (bIsCreate)
                        {
                            //创建
                            SOLogInfo soLog = new SOLogInfo()
                            {
                                SOSysNo       = soSysNo,
                                IP            = "::1",
                                OperationType = BizLogType.Sale_SO_ShippingInfo,
                                Note          = routeLogMsg,
                                UserSysNo     = 0,
                                CompanyCode   = "8601"
                            };
                            _SOLogDA.InsertSOLog(soLog);
                        }
                        else
                        {
                            //更新
                            SOLogInfo soLog = logList[0];
                            soLog.Note = routeLogMsg;
                            _SOLogDA.UpdateSOLogNoteBySysNo(soLog);
                        }
                        #endregion
                    }
                }
            }
        }