Пример #1
0
        /// <summary>
        /// 发货后15天后未确认收货的订单自动确认收货
        /// </summary>
        public static void ComfirmTimePassOrder()
        {   //订单状态是5已发货物流状态是1付款中
            List <DSMTMALL.DB.Model.M_OrderInfo> orderInfoList = new DSMTMALL.DB.BLL.MY_Bll(DBEnum.Slave).GetModelList <DSMTMALL.DB.Model.M_OrderInfo>(" OrderStatus=5 AND ShippingStatus=1 ", null);
            DateTime nowTime = DateTime.Now;

            if (orderInfoList != null && orderInfoList.Count > 0)
            {
                foreach (var item in orderInfoList)
                {
                    if (item.ShippingTime.AddDays(15) <= nowTime)
                    {
                        if (new DSMTMALL.DB.BLL.MY_Bll(DBEnum.Master).UpdateModel <DSMTMALL.DB.Model.M_OrderInfo>(" OrderID=@_OrderID AND OrderStatus=5 AND ShippingStatus=1   ", new { _OrderID = item.OrderID, OrderStatus = 8, ShippingStatus = 2, ConfirmTime = nowTime }))
                        {
                            WeChatAPI.SendMsg("系统自动确认收货", "您的订单" + item.OrderSn + "由系统自动确认收货成功,感谢您的购买", item.OpenID);
                        }
                    }
                }
            }
        }
Пример #2
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));
                        }
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 调用XF系统接口进行交易退款状态同步查询
        /// </summary>
        public static void GetReBackPayAccStatusSync()
        {
            List <DSMTMALL.DB.Model.M_ReBackTrade> orderTradeList = new DSMTMALL.DB.BLL.MY_Bll(DBEnum.Slave).GetModelList <DSMTMALL.DB.Model.M_ReBackTrade>(" ComfirmStatus=10 ORDER BY CreateTime ASC LIMIT 50 ", null);

            if (orderTradeList != null && orderTradeList.Count > 0)
            {
                DSMT_TAE_ServiceSoapClient taeCilent = new DSMT_TAE_ServiceSoapClient();
                GetQueryTradeStatusEntity  queryTradeStatusEntity = null;
                VerifyHelper verifyHelper = new VerifyHelper();
                BackQueryTradeStatusEntity backQueryTradeStatusEntity = null;
                DateTime nowTime   = DateTime.Now;
                string   outOpenID = string.Empty;
                foreach (var item in orderTradeList)
                {
                    queryTradeStatusEntity     = new GetQueryTradeStatusEntity();                                                                //初始化
                    backQueryTradeStatusEntity = null;
                    if (!string.IsNullOrEmpty(item.TradeNo) && !string.IsNullOrEmpty(item.CpySysID) && item.CreateTime.AddMinutes(10) < nowTime) //判断流水号公司ID都存在的情况下调用XF接口,并且流水号的创建时间超时10分钟
                    {
                        if (item.CreateTime.AddMinutes(360) > nowTime)                                                                           //如果超过6个小时,XF系统还未同步完成,记录异常
                        {
                            queryTradeStatusEntity.CpySysID = item.CpySysID;
                            queryTradeStatusEntity.TradeNo  = item.ReBackTradeNo;
                            verifyHelper.EncryptPmtEntity(queryTradeStatusEntity);//加密加签
                            try
                            {
                                backQueryTradeStatusEntity = taeCilent.QueryTradeStatus(queryTradeStatusEntity); //调用XF接口
                            }
                            catch (Exception e)                                                                  //通讯异常
                            {
                                ToolHelper.WriteTxt(logPathErr, DateTime.Now + "退款流水号:" + item.ReBackTradeNo + "与XF系统退款状态同步查询出错,错误信息:" + e.Message, false);
                                continue;
                            }
                            if (verifyHelper.CheckPmtSign(ref backQueryTradeStatusEntity))//尝试解签,解签失败的话不执行任何代码
                            {
                                if (backQueryTradeStatusEntity.TradeType == "1")
                                {
                                    if (backQueryTradeStatusEntity.TradeStatus == "10" || backQueryTradeStatusEntity.TradeStatus == "20") //交易状态10-已完成20-已撤销(即失败)30-待同步40-交易信息不存在
                                    {
                                        if (new DSMTMALL.DB.BLL.MY_Bll(DBEnum.Master).UpdateReBackPayAccByXFPaymentToComfirm(ToolHelper.ConventToDecimal(backQueryTradeStatusEntity.TradeMoney, 999), item.ReBackTradeSysID, backQueryTradeStatusEntity.TradeStatus, out outOpenID))
                                        {
                                            WeChatAPI.SendMsg("退款资金到账通知", "您有一笔退款金额已通过原支付方式退还至您的账户,请注意查收", outOpenID);
                                        }
                                    }
                                    else if (backQueryTradeStatusEntity.TradeStatus == "40")
                                    {
                                        string resMsg = DateTime.Now + "退款流水号:" + item.ReBackTradeNo + "与XF系统退款状态同步查询出错,错误信息:XF系统该笔流水号信息不存在";
                                        new DSMTMALL.DB.BLL.MB_Bll(DBEnum.Master).RecordErrInfoNote("同步程序查询XF系统退款状态发现异常", resMsg);
                                        new TryCatchErrHelper().HandlerReBackTradeError(item.ReBackTradeSysID);
                                        ToolHelper.WriteTxt(logPathErr, resMsg, false);
                                    }//30就不做任何处理
                                }
                            }
                        }
                        else
                        {
                            new DSMTMALL.DB.BLL.MB_Bll(DBEnum.Master).RecordErrInfoNote("同步程序查询XF系统退款状态发现异常", "退款流水号:" + item.TradeNo + "与XF系统退款状态同步查询已过6个小时,XF系统仍未同步完成");
                            new TryCatchErrHelper().HandlerReBackTradeError(item.ReBackTradeSysID);
                        }
                    }
                }
            }
        }