示例#1
0
        /// <summary>
        /// 解析返回协议
        /// </summary>
        /// <param name="responseXml"></param>
        /// <returns></returns>
        private YTBatchQueryResponse AnalysisResponseXml(string responseXml)
        {
            YTBatchQueryResponse result = null;

            try
            {
                var t = SerializationUtility.XmlDeserialize <YTResponse>(responseXml);
                result = EntityConverter <YTResponse, YTBatchQueryResponse> .Convert(t);

                if (!t.success)
                {
                    Logger.WriteLog(string.Format("responseXml:{0},Code:{1},ErrMsg:{2}", responseXml, t.reason, t.reason), "圆通订单物流信息查询返回错误");
                    return(null);
                }
            }
            catch (Exception ex)
            { }

            if (result == null)
            {
                result = SerializationUtility.XmlDeserialize <YTBatchQueryResponse>(responseXml);
            }

            if (result == null)
            {
                Logger.WriteLog(string.Format("responseXml:{0}", responseXml), "圆通订单物流信息查询返回NULL");
                return(null);
            }
            if (result.orders == null ||
                result.orders.Count == 0)
            {
                Logger.WriteLog(string.Format("responseXml:{0}", responseXml), "圆通订单物流信息查询返回NULL");
                return(null);
            }
            return(result);
        }
示例#2
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
                    }
                }
            }
        }