Ejemplo n.º 1
0
        /// <summary>
        /// 查询订单-更新发货信息//每天晚上24点之后执行一次,一次同步所有发货信息
        /// </summary>
        public static void WMSNotifyQueryStockOut()
        {
            //基础配置
            OrderHelper    wmsStringHandler = new OrderHelper();
            DateTime       nowTime          = DateTime.Now;
            string         method           = MethodQuery;
            WMSNotifyQuery notifyQuery      = new WMSNotifyQuery(Owner);
            WMSReturnQuery resJsonArr       = null;
            List <DSMTMALL.DB.Model.M_OrderInfo> orderInfo = null;

            DSMTMALL.DB.Model.M_OrderInfo     orderInfoNow = null;
            SortedDictionary <string, string> dicQuery     = null;                                  // new SortedDictionary<string, string>();//每一订单推送后都必须要这个键值对初始化
            //string strWhere = "SuppliersID=101 AND ( OrderStatus=9 OR OrderStatus=1) AND PayStatus=2 ";//1.订单的商品来源要是海淘的,2.订单的状态要已推送订单,3.订单的支付状态是已付款的
            string strWhere = "SuppliersID=101 AND  OrderStatus=9 AND IsVerify=1 AND PayStatus=2 "; //1.订单的商品来源要是海淘的,2.订单的状态要已推送订单,3.订单的支付状态是已付款的 4.已校对的

            try
            {
                orderInfo = new DSMTMALL.DB.BLL.MY_Bll(DBEnum.Slave).GetModelList <DSMTMALL.DB.Model.M_OrderInfo>(strWhere, null);//获取所有要校对的订单列表
            }
            catch (Exception esql)
            {
                orderInfo = null;
                FileHelper.logger.Warn("获取要同步物流状态的订单列表信息出错,错误信息:" + esql.Message);
            }
            if (orderInfo != null || orderInfo.Count > 0)
            {
                for (int i = 0; i < orderInfo.Count; i++)//对符合条件的内容进行for循环
                {
                    string dicSignStr = string.Empty;
                    string resWMSVal  = string.Empty;
                    nowTime = DateTime.Now;
                    string param = string.Empty;
                    resJsonArr = null;
                    if (!string.IsNullOrEmpty(orderInfo[i].TPLOrderNo))                               //第三方系统推送回的订单号不为空的情况下执行订单校对
                    {
                        dicQuery         = new SortedDictionary <string, string>();                   //每一订单推送后都必须要这个键值对初始化
                        notifyQuery.Code = orderInfo[i].TPLOrderNo;
                        string wmsNotifyQueryStr = new JavaScriptSerializer().Serialize(notifyQuery); //将该笔订单信息JSON格式化
                        dicQuery.Add("appkey", AppKey);
                        dicQuery.Add("method", method);
                        dicQuery.Add("param", wmsNotifyQueryStr);
                        dicQuery.Add("v", V);
                        dicQuery.Add("timestamp", nowTime.ToString());
                        dicSignStr = wmsStringHandler.WMSStringHanlder(dicQuery, Appsecret);
                        param      = "appkey=" + AppKey + "&timestamp=" + nowTime + "&v=" + V + "&method=" + method + "&param=" + wmsNotifyQueryStr + "&sign=" + dicSignStr;
                        try
                        {
                            resWMSVal  = ToolHelper.Post(Url, param);
                            resJsonArr = new JavaScriptSerializer().Deserialize <WMSReturnQuery>(resWMSVal);
                            if (resJsonArr != null)         //返回数据反序列化成功
                            {
                                if (resJsonArr.Code == "0") //返回0-成功 ,并且订单物流状态为0已取消或者40已发货
                                {
                                    if (resJsonArr.Status == "40" || resJsonArr.Status == "10" || (resJsonArr.Status == "20" || resJsonArr.Status == "30") && !string.IsNullOrEmpty(resJsonArr.WhsStatus))
                                    {
                                        orderInfoNow = new DSMTMALL.DB.BLL.MY_Bll(DBEnum.Slave).GetModel <DSMTMALL.DB.Model.M_OrderInfo>(" OrderID=@_OrderID ", new { _OrderID = orderInfo[i].OrderID });//为了严谨再次查数据库从数据库取这个实体
                                        if (orderInfoNow != null)
                                        {
                                            if (resJsonArr.Status == "40")//对方已发货更新物流状态
                                            {
                                                orderInfoNow.Logistical       = string.IsNullOrEmpty(resJsonArr.Result.LogisticCompany) ? string.Empty : resJsonArr.Result.LogisticCompany;
                                                orderInfoNow.LogisticalNumber = string.IsNullOrEmpty(resJsonArr.Result.LogisiticNumber) ? string.Empty : resJsonArr.Result.LogisiticNumber;
                                                orderInfoNow.ShippingTime     = string.IsNullOrEmpty(resJsonArr.Result.StockOutDate) ? nowTime : Convert.ToDateTime(resJsonArr.Result.StockOutDate);
                                                if (new DSMTMALL.DB.BLL.MY_Bll(DBEnum.Master).UpdateModel <DSMTMALL.DB.Model.M_OrderInfo>("  OrderID=@_OrderID ",
                                                                                                                                          new
                                                {
                                                    _OrderID = orderInfo[i].OrderID,
                                                    Logistical = orderInfoNow.Logistical,
                                                    LogisticalNumber = orderInfoNow.LogisticalNumber,
                                                    ShippingTime = orderInfoNow.ShippingTime,
                                                    ShippingStatus = 1,
                                                    OrderStatus = 5,
                                                    Version = orderInfoNow.Version + 1
                                                })
                                                    )//更新数据,更新失败不做任何处理--如果成功则发送微信-发货成功
                                                {
                                                    WeChatAPI.SendMsg("商品发货提醒", "您的订单" + orderInfo[i].OrderSn + "已从仓库发出,请等待收货,物流单号为:" + orderInfoNow.LogisticalNumber, orderInfo[i].OpenID);
                                                }
                                            }
                                            else if (resJsonArr.Status == "10")//对方已取消发货
                                            {
                                                new DSMTMALL.DB.BLL.MY_Bll(DBEnum.Master).UpdateModel <DSMTMALL.DB.Model.M_OrderInfo>(" OrderID=@_OrderID ",
                                                                                                                                      new
                                                {
                                                    _OrderID    = orderInfo[i].OrderID,
                                                    OrderStatus = 7,
                                                    Postscript  = "海淘取消订单发货:" + resJsonArr.WhsStatus,                                                         //异常状态描述
                                                    Version     = orderInfoNow.Version + 1
                                                });                                                                                                           //更新数据,更新失败不做任何处理
                                            }
                                            else if ((resJsonArr.Status == "20" || resJsonArr.Status == "30") && !string.IsNullOrEmpty(resJsonArr.WhsStatus)) //对方订单待确认或已配送确认,并且订单异常状态描述不为空,代表有异常信息
                                            {
                                                if (resJsonArr.WhsStatus != "未推送到海关系统" || nowTime > orderInfo[i].PayTime.AddDays(1))                          //如果返回的错误信息不是	未推送到海关系统 或者 订单付款时间已经超过24小时
                                                {
                                                    new DSMTMALL.DB.BLL.MY_Bll(DBEnum.Master).UpdateModel <DSMTMALL.DB.Model.M_OrderInfo>(" OrderID=@_OrderID ",
                                                                                                                                          new
                                                    {
                                                        _OrderID    = orderInfo[i].OrderID,
                                                        OrderStatus = 7,
                                                        Postscript  = "海淘返回的订单状态存在异常,异常原因:" + resJsonArr.WhsStatus, //异常状态描述
                                                        Version     = orderInfoNow.Version + 1
                                                    });                                                             //更新数据,更新失败不做任何处理
                                                }
                                            }
                                        }
                                    }//海淘尚未推送订单给海关,暂不作任何处理
                                }
                                else
                                {
                                    FileHelper.logger.Warn(string.Format("{0}订单物流状态更新失败,失败原因:{1}", orderInfo[i].OrderSn, resWMSVal));
                                }
                            }
                        }
                        catch (Exception exmsg)
                        {
                            FileHelper.logger.Warn(string.Format("{0}订单物流状态更新失败,失败原因:{1}", orderInfo[i].OrderSn, exmsg.Message));
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 查询订单进行校队
        /// </summary>
        public static void WMSNotifyQuery()
        {
            //基础配置
            OrderHelper    wmsStringHandler  = new OrderHelper();
            DateTime       nowTime           = DateTime.Now;
            string         method            = MethodQuery;
            string         email             = Email;
            string         mailContent       = string.Empty;
            string         wmsNotifyQueryStr = string.Empty;
            WMSNotifyQuery notifyQuery       = new WMSNotifyQuery(Owner);
            List <DSMTMALL.DB.Model.M_OrderGoods> orderGoodsList = null;
            List <WMSStockOutRow> wmsStockOutRow           = null;
            WMSReturnQuery        resJsonArr               = null;
            List <DSMTMALL.DB.Model.M_OrderInfo> orderInfo = null;
            SortedDictionary <string, string>    dicQuery  = null;                                          // new SortedDictionary<string, string>();//每一订单推送后都必须要这个键值对初始化
            string strWhere = "SuppliersID=101 AND OrderStatus=9 AND PayStatus=2 AND IsVerify=0  LIMIT 50"; //1.订单的商品来源要是海淘的,2.订单的状态要已推送订单,3.订单的支付状态是已付款的 4.订单校对为0未校对

            try
            {
                orderInfo = new DSMTMALL.DB.BLL.MY_Bll(DBEnum.Slave).GetModelList <DSMTMALL.DB.Model.M_OrderInfo>(strWhere, null);//获取所有要校对的订单列表
            }
            catch (Exception esql)
            {
                orderInfo = null;
                FileHelper.logger.Warn(string.Format("获取要校对的订单列表信息出错" + esql.Message));
            }
            if (orderInfo != null && orderInfo.Count > 0)
            {
                for (int i = 0; i < orderInfo.Count; i++)//对符合条件的内容进行for循环
                {
                    string dicSignStr = string.Empty;
                    string resWMSVal  = string.Empty;
                    nowTime = DateTime.Now;
                    string param = string.Empty;
                    orderGoodsList    = null;
                    wmsStockOutRow    = null;
                    mailContent       = string.Empty;
                    wmsNotifyQueryStr = string.Empty;
                    resJsonArr        = null;
                    try
                    {
                        if (!string.IsNullOrEmpty(orderInfo[i].TPLOrderNo))                        //第三方系统推送回的订单号不为空的情况下执行订单校对
                        {
                            dicQuery          = new SortedDictionary <string, string>();           //每一订单推送后都必须要这个键值对初始化
                            notifyQuery.Code  = orderInfo[i].TPLOrderNo;
                            wmsNotifyQueryStr = new JavaScriptSerializer().Serialize(notifyQuery); //将该笔订单信息JSON格式化
                            dicQuery.Add("appkey", AppKey);
                            dicQuery.Add("method", method);
                            dicQuery.Add("param", wmsNotifyQueryStr);
                            dicQuery.Add("v", V);
                            dicQuery.Add("timestamp", nowTime.ToString());
                            dicSignStr = wmsStringHandler.WMSStringHanlder(dicQuery, Appsecret);
                            param      = "appkey=" + AppKey + "&timestamp=" + nowTime + "&v=" + V + "&method=" + method + "&param=" + wmsNotifyQueryStr + "&sign=" + dicSignStr;
                            try
                            {
                                resWMSVal = ToolHelper.Post(Url, param);
                            }
                            catch
                            {
                                FileHelper.logger.Warn(string.Format("{0}与海淘校对订单信息出错,错误信息:与海淘的订单校对接口连接出错", orderInfo[i].OrderSn));
                            }
                            resJsonArr = new JavaScriptSerializer().Deserialize <WMSReturnQuery>(resWMSVal);
                            if (resJsonArr != null)         //返回数据反序列化成功
                            {
                                if (resJsonArr.Code == "0") //返回0-成功
                                {
                                    wmsStockOutRow = resJsonArr.Result.Rows;
                                    orderGoodsList = new DSMTMALL.DB.BLL.MY_Bll(DBEnum.Slave).GetModelList <DSMTMALL.DB.Model.M_OrderGoods>(" OrderSn=@_OrderSn", new { _OrderSn = orderInfo[i].OrderSn }); //获取该订单商品列表
                                    if (orderGoodsList != null && wmsStockOutRow != null && orderGoodsList.Count > 0 && wmsStockOutRow.Count > 0)                                                           //该订单商品信息不为空
                                    {
                                        if (orderGoodsList.Count == wmsStockOutRow.Count)                                                                                                                   //商品信息品类等长
                                        {
                                            orderGoodsList.Sort((DSMTMALL.DB.Model.M_OrderGoods x, DSMTMALL.DB.Model.M_OrderGoods y) => x.GoodsSn.CompareTo(y.GoodsSn));
                                            wmsStockOutRow.Sort((WMSStockOutRow x, WMSStockOutRow y) => x.MerchId.CompareTo(y.MerchId));
                                            bool isSame = true;
                                            for (int j = 0; j < orderGoodsList.Count; j++)
                                            {   //对俩个按照商品编号排序后的商品信息集合进行校对商品编号与数量是否一致,
                                                if (orderGoodsList[j].GoodsSn != wmsStockOutRow[j].MerchId || Convert.ToDouble(orderGoodsList[j].BuyNumber) != Convert.ToDouble(wmsStockOutRow[j].Qty))
                                                {
                                                    isSame = false;
                                                    break;
                                                }
                                            }
                                            if (isSame)
                                            {
                                                if (new DSMTMALL.DB.BLL.MY_Bll(DBEnum.Master).UpdateModel <DSMTMALL.DB.Model.M_OrderInfo>(" OrderID=@_OrderID AND Version=@_Version ", new { _OrderID = orderInfo[i].OrderID, _Version = orderInfo[i].Version, IsVerify = 1, Version = orderInfo[i].Version + 1 }))
                                                {
                                                    FileHelper.logger.Info(string.Format("{0}校对成功,返回信息:{1}--物流公司:{2}/物流单号:{3}/发货时间:{4}", orderInfo[i].OrderSn, resJsonArr.Desc, resJsonArr.Result.LogisticCompany, resJsonArr.Result.LogisiticNumber, resJsonArr.Result.StockOutDate));
                                                }//校队失败必须做处理,==》改:不必做处理,因为会再次调API接口尝试校队订单信息
                                            }
                                            else
                                            {
                                                FileHelper.logger.Warn(string.Format("订单编号:{0}与海淘校对订单信息出错,错误信息:返回的商品编号与数量不一致{1}", orderInfo[i].OrderSn, resWMSVal));
                                                throw new Exception(ExceptionHelper.Exception1003);//1003与海淘校对订单出错
                                            }
                                        }
                                        else
                                        {
                                            FileHelper.logger.Warn(string.Format("订单编号:{0}与海淘校对订单信息出错,错误信息:返回的商品数量不一致{1}", orderInfo[i].OrderSn, resWMSVal));
                                            throw new Exception(ExceptionHelper.Exception1003);
                                        }
                                    }
                                    else//订单商品信息为空
                                    {
                                        FileHelper.logger.Warn(string.Format("订单编号:{0}与海淘校对订单信息出错,错误信息:返回的商品数据为空{1}", orderInfo[i].OrderSn, resWMSVal));
                                        throw new Exception(ExceptionHelper.Exception1003);
                                    }
                                }
                                else//返回1
                                {
                                    FileHelper.logger.Warn(string.Format("订单编号:{0}与海淘校对订单信息出,错误信息:{1}}", orderInfo[i].OrderSn, resJsonArr.Desc));
                                }
                            }
                            else
                            {
                                FileHelper.logger.Warn(string.Format("订单编号:{0},与海淘校对订单信息出错,错误信息:海淘返回信息反序列化出错", orderInfo[i].OrderSn));
                            }
                        }
                        else
                        {
                            FileHelper.logger.Warn(string.Format("订单编号:{0}与海淘校对订单信息出错,错误信息:该订单没有第三方系统后返回的订单编号", orderInfo[i].OrderSn));
                        }
                    }
                    catch (Exception e)
                    {
                        if (e.Message == ExceptionHelper.Exception1000)
                        {
                            break;//检测到接口返回数据出错,直接跳出循环体
                        }
                        else
                        {
                            new TryCatchErrHelper().HandlerError(orderInfo[i].OrderID, orderInfo[i].OrderSn, e.Message);
                        }
                    }
                }
            }
        }