private void PushMessage(int batchId, List <Guid> userList)
        {
            //var target = userList.Select(g => g.ToString("D")).ToList();
            var nickNameList = GetGroupBuyingUserName(userList);

            if (nickNameList.Any())
            {
                using (var client = new TemplatePushClient())
                {
                    foreach (var item in nickNameList)
                    {
                        var target = new List <string> {
                            item.Item1.ToString("D")
                        };
                        var nickName = item.Item2;
                        var result   =
                            client.PushByUserIDAndBatchID(target, batchId, new PushTemplateLog
                        {
                            Replacement = JsonConvert.SerializeObject(new Dictionary <string, string>
                            {
                                { "{{nickname}}", nickName }
                            })
                        });
                        if (!(result.Success && result.Result))
                        {
                            Logger.Warn(
                                $"向{item.Item1:d}/{item.Item2}用户推送信息{batchId}失败-->{result.Exception}");
                        }
                    }
                }
            }
        }
        private void PushMessage(Guid userId, Guid idKey, int batchId, string ProductName, decimal FinalPrice, string pid, int apId, string simpleDisplayName, decimal originalPrice)
        {
            var target = new List <string>()
            {
                userId.ToString("D")
            };
            var nickName = "";

            using (var client = new UserAccountClient())
            {
                var searchResule = client.GetUserById(userId);
                if (searchResule.Success)
                {
                    nickName = searchResule.Result?.Profile?.NickName ?? "";
                }
            }
            using (var client = new TemplatePushClient())
            {
                var result = client.PushByUserIDAndBatchID(target, batchId, new PushTemplateLog()
                {
                    Replacement = JsonConvert.SerializeObject(new Dictionary <string, string>()
                    {
                        ["{{IdKey}}"]             = idKey.ToString("D"),
                        ["{{Pid}}"]               = pid,
                        ["{{AcitvityProductId}}"] = apId.ToString(),
                        ["{{ProductName}}"]       = ProductName,
                        ["{{NickName}}"]          = nickName,
                        ["{{ProductBriefName}}"]  = simpleDisplayName,
                        ["{{Price}}"]             = originalPrice.ToString("#0.00"),
                        ["{{ActivityPrice}}"]     = FinalPrice.ToString("#0.00")
                    }),
                });
                if (result.Success && result.Result)
                {
                    Logger.Info($"砍价消息推送成功,用户{userId},产品名称{ProductName},IdKey是{idKey},模板Id是{batchId}");
                }
                else
                {
                    Logger.Warn($"砍价消息推送失败,用户{userId},产品名称{ProductName},IdKey是{idKey},模板Id是{batchId}");
                }
            }
        }
Exemple #3
0
        /// <summary>
        ///     推送消息
        /// </summary>
        /// <param name="cacheClient"></param>
        /// <param name="templatePushClient"></param>
        /// <param name="userId"></param>
        /// <param name="userClient"></param>
        private void PushMessage(
            int pushId
            , CacheClient cacheClient
            , UserClient userClient
            , TemplatePushClient templatePushClient
            , Guid userId
            , DateTime playtime)

        {
            var cacheKey = "/ActivityUserQuestionAnswerClear/" + userId.ToString("N");
            //判断redis里面今天是否已经推送过了
            var existsResult = cacheClient.Exists(cacheKey);

            //如果不存在
            if (!existsResult.Success)
            {
                var dateDiff = (DateTime.Now.Date.AddDays(1) - DateTime.Now).Add(TimeSpan.FromMinutes(5));
                //保存到cache中
                //今天不再推送
                var setResult = cacheClient.Set(cacheKey, 1, dateDiff);

                if (setResult.Success)
                {
                    //获取用户数据
                    var userInfo = userClient.FetchUserByUserId(userId.ToString());
                    if (userInfo != null && userInfo.Success && userInfo.Result != null)
                    {
                        templatePushClient.PushByUserIDAndBatchID(new List <string> {
                            userId.ToString()
                        }, pushId,
                                                                  new PushTemplateLog
                        {
                            Replacement = JsonConvert.SerializeObject(new Dictionary <string, string>
                            {
                                { "{{nickname}}", userInfo.Result.Nickname },
                                { "{{playtime}}", playtime.ToString("yyyy-MM-dd") },
                            })
                        });
                    }
                }
            }
        }
Exemple #4
0
        private void PushMessage(Guid packetGroupNo, string nickName, int count, Guid userId)
        {
            var templateLog = new PushTemplateLog
            {
                Replacement = JsonConvert.SerializeObject(new Dictionary <string, string>
                {
                    { "{{leftnumber}}", count.ToString() },
                    { "{{packetgroupno}}", packetGroupNo.ToString("D") },
                    { "{{nickname}}", nickName }
                })
            };

            var client  = new TemplatePushClient();
            int batchId = 1642;
            var target  = userId.ToString("D");

            try
            {
                var result =
                    client.PushByUserIDAndBatchID(new List <string> {
                    target.ToLower()
                }, batchId, templateLog);
                result.ThrowIfException(true);
                if (!(result.Success && result.Result))
                {
                    Logger.Warn(
                        $"向用户{JsonConvert.SerializeObject(target)}推送信息{JsonConvert.SerializeObject(templateLog)},推送失败",
                        result.Exception);
                }
            }
            catch (Exception ex)
            {
                Logger.Warn($"向用户{JsonConvert.SerializeObject(target)}推送信息{batchId}出现异常", ex);
            }
            finally
            {
                client.Dispose();
            }
        }
        public void Execute(IJobExecutionContext context)
        {
            Logger.Info("启动任务");

            //var testUser = "";
            //using (var cmd = new SqlCommand(@"SELECT  Value TotalDuration,
            //        Description MsgTitle
            //FROM    Gungnir..RuntimeSwitch WITH ( NOLOCK )
            //WHERE   SwitchName = N'OrderPushMessageJob';"))
            //{
            //    var swithcConfig = DbHelper.ExecuteSelect<MessagePushConfig>(cmd)?.FirstOrDefault();
            //    if (swithcConfig?.TotalDuration == null || swithcConfig.TotalDuration == 0)
            //    {
            //        Logger.Info("任务关闭");
            //        return;
            //    }
            //    testUser = swithcConfig.MsgTitle;
            //}

            using (var command = new SqlCommand(@"
SELECT  PKID ,
        EnID,
        MsgTitle,
        MsgContent,
        MsgLink,
        MsgDescription,
        TotalDuration,
        AheadHour
FROM    Configuration..tbl_MessagePush WITH(NOLOCK)
WHERE   EnID = 'pingjiatixing'; "))
            {
                var msgConfig = DbHelper.ExecuteSelect <MessagePushConfig>(command)?.First();

                using (var cmd = new SqlCommand(@"
SELECT TOP 500
        O.UserID ,
        O.OrderNo ,
        UserTel AS Phone ,
        O.PKID AS OrderID ,
        O.UserID Device_Tokens,
        ISNULL(O.OrderProducts, O.OrderNo) AS Products,
        O.OrderDatetime
FROM    Gungnir..tbl_Order AS O WITH ( NOLOCK )
WHERE   Status <> '7Canceled'
        AND CommentStatus = 1
        AND OrderDatetime >= '2016-4-25'
        AND O.OrderChannel != N'r天猫马牌'
        AND NOT EXISTS ( SELECT 1
                         FROM   SystemLog..tbl_OrderPushInfo AS OPI WITH ( NOLOCK )
                         WHERE  OrderID = O.PKID
                                AND MsgType = 'pingjiatixing' )
ORDER BY O.PKID DESC;"))
                {
                    try
                    {
                        var dt = DbHelper.ExecuteSelect <PushInfoModel>(true, cmd)?.ToList();
                        foreach (var d in dt)
                        {
                            var productName = d.Products;
                            if (!string.IsNullOrWhiteSpace(productName))
                            {
                                if (productName.Length > 30)
                                {
                                    productName = productName.Substring(0, 20) + "...";
                                }
                            }
                            else
                            {
                                productName = "";
                            }
                            using (var client = new TemplatePushClient())
                            {
                                //var userids = testUser == "all" ? new List<string>() { d.Device_Tokens } : testUser.Split(',').ToList();
                                var userids = new List <string>()
                                {
                                    d.Device_Tokens
                                };
                                var result = client.PushByUserIDAndBatchID(
                                    userids,
                                    450,
                                    new Service.Push.Models.Push.PushTemplateLog()
                                {
                                    Replacement = JsonConvert.SerializeObject(new Dictionary <string, string>
                                    {
                                        ["{{ios.orderid}}"]        = d.OrderNo,
                                        ["{{android.orderid}}"]    = d.OrderNo,
                                        ["{{messagebox.orderid}}"] = d.OrderNo,
                                        ["{{replace.orderid}}"]    = d.OrderNo,
                                        ["{{first.DATA}}"]         = $"您还有订单没有评价哦,评价就有机会获得最高100积分奖励,赶紧来吧!",
                                        ["{{keyword1.DATA}}"]      = productName,
                                        ["{{keyword2.DATA}}"]      = d.OrderDatetime.ToString("yyyy-MM-dd HH:mm"),

                                        ["{{remark.DATA}}"]    = $"点击赢取积分奖励",
                                        ["{{wxopen.orderid}}"] = d.OrderNo,
                                    }),
                                    DeviceType = Service.Push.Models.Push.DeviceType.iOS
                                });
                                if (result?.Result == null || !result.Success || !result.Result)
                                {
                                    Logger.Error($"推送失败{result.ErrorCode};{result.ErrorMessage}", result.Exception);
                                    //continue;
                                }
                                //if (testUser == "all")
                                InsetPushInfo(d.OrderID, msgConfig.EnID, "All");
                                //else
                                //{
                                //    return;
                                //}
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex.Message, ex);
                    }
                }
            }
            Logger.Info("结束任务");
        }
Exemple #6
0
        public void Execute(IJobExecutionContext context)
        {
            Logger.Info("启动任务");

            //var testUser = "";
            //using (var cmd = new SqlCommand(@"SELECT  Value TotalDuration,
            //        Description MsgTitle
            //FROM    Gungnir..RuntimeSwitch WITH ( NOLOCK )
            //WHERE   SwitchName = N'OrderPushJob';"))
            //{
            //    var swithcConfig = DbHelper.ExecuteSelect<MessagePushConfig>(cmd)?.FirstOrDefault();
            //    if (swithcConfig?.TotalDuration == null || swithcConfig.TotalDuration == 0)
            //    {
            //        Logger.Info("任务关闭");
            //        return;
            //    }
            //    testUser = swithcConfig.MsgTitle;
            //}

            #region 处理1
            using (var cmd = new SqlCommand(@"
SELECT  PKID,
        EnID,
        MsgTitle,
        MsgContent,
        MsgLink,
        MsgDescription,
        TotalDuration,
        AheadHour
FROM    Configuration..tbl_MessagePush WITH(NOLOCK) WHERE  EnID='fukuanchaoshitixing'"))
            {
                var msgConfig = DbHelper.ExecuteSelect <MessagePushConfig>(cmd)?.First();
                #region 数据处理
                using (var c = new SqlCommand(@"
SELECT  *
FROM    ( SELECT    O.UserID ,
                    O.OrderNo ,
                    UserTel AS Phone ,
                    O.PKID AS OrderID ,
                    O.UserID Device_Tokens,
                    ISNULL(O.OrderProducts, O.OrderNo) AS Products,
                    O.OrderDateTime
          FROM      Gungnir..tbl_Order AS O WITH ( NOLOCK )
          WHERE     Status <> '7Canceled'
                    AND OrderDatetime >= @StarTime
                    AND OrderDatetime <= @EndTime
                    AND PayStatus = '1Waiting'
                    AND PayMothed IN ( '5Alipay', 'aweixin', 'bWeiXin',
                                       'fXianShangZhiFu' )
                    AND O.OrderType <> N'6美容'
                    AND O.OrderChannel != N'r天猫马牌'
        ) AS T
WHERE   NOT EXISTS ( SELECT 1
                     FROM   SystemLog..tbl_OrderPushInfo AS OPI WITH ( NOLOCK )
                     WHERE  OrderID = T.OrderID
                            AND MsgType = 'fukuanchaoshitixing' );"))
                {
                    try
                    {
                        c.Parameters.AddWithValue("@StarTime", DateTime.Now.AddHours(-(msgConfig.TotalDuration.Value - msgConfig.AheadHour.Value)).ToString("yyyy-MM-dd HH:00:00"));
                        c.Parameters.AddWithValue("@EndTime", DateTime.Now.AddHours(-(msgConfig.TotalDuration.Value - msgConfig.AheadHour.Value)).ToString("yyyy-MM-dd HH:59:59"));

                        var dt = DbHelper.ExecuteSelect <PushInfoModel>(true, c)?.ToList();
                        foreach (var d in dt)
                        {
                            var productName = d.Products;
                            if (!string.IsNullOrWhiteSpace(productName))
                            {
                                if (productName.Length > 30)
                                {
                                    productName = productName.Substring(0, 20);
                                }
                            }
                            else
                            {
                                productName = "";
                            }

                            using (var client = new TemplatePushClient())
                            {
                                //var userids = testUser == "all" ? new List<string>() { d.Device_Tokens } : testUser.Split(',').ToList();
                                var userids = new List <string>()
                                {
                                    d.Device_Tokens
                                };
                                var result = client.PushByUserIDAndBatchID(
                                    userids,
                                    453,
                                    new Service.Push.Models.Push.PushTemplateLog()
                                {
                                    Replacement = JsonConvert.SerializeObject(new Dictionary <string, string>
                                    {
                                        ["{{ios.productname}}"]        = productName,
                                        ["{{ios.hour}}"]               = (msgConfig.AheadHour)?.ToString(),
                                        ["{{ios.orderid}}"]            = d.OrderNo,
                                        ["{{android.productname}}"]    = productName,
                                        ["{{android.hour}}"]           = (msgConfig.AheadHour)?.ToString(),
                                        ["{{android.orderid}}"]        = d.OrderNo,
                                        ["{{messagebox.productname}}"] = productName,
                                        ["{{messagebox.hour}}"]        = (msgConfig.AheadHour)?.ToString(),
                                        ["{{messagebox.orderid}}"]     = d.OrderNo,
                                        ["{{replace.orderid}}"]        = d.OrderNo,
                                        ["{{first.DATA}}"]             = $"您选购的【{productName}】未付款,再过{(msgConfig.AheadHour)?.ToString()}小时将会被取消订单,请抓紧付款哦!",
                                        ["{{OrderSn.DATA}}"]           = d.OrderNo,
                                        ["{{OrderStatus.DATA}}"]       = "即将到达付款期限",
                                        ["{{remark.DATA}}"]            = "点击查看订单详情",
                                        ["{{wxopen.orderid}}"]         = d.OrderNo,
                                    }),
                                    DeviceType = Service.Push.Models.Push.DeviceType.iOS
                                });
                                if (result?.Result == null || !result.Success || !result.Result)
                                {
                                    Logger.Error($"推送失败{result.ErrorCode};{result.ErrorMessage}", result.Exception);
                                    //continue;
                                }
                                //if (testUser == "all")
                                InsetPushInfo(d.OrderID, msgConfig.EnID, "All");
                                //else
                                //{
                                //    return;
                                //}
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex.Message, ex);
                    }
                }
                #endregion
            }
            #endregion
            Logger.Info("结束任务");
        }
        public void Execute(IJobExecutionContext context)
        {
            Logger.Info("启动任务");

            //var testUser = "";
            //using (var cmd = new SqlCommand(@"SELECT Value TotalDuration,
            //        Description MsgTitle
            //FROM    Gungnir..RuntimeSwitch WITH ( NOLOCK )
            //WHERE   SwitchName = N'InstallOrderPushJob';"))
            //{
            //    var swithcConfig = DbHelper.ExecuteSelect<MessagePushConfig>(cmd)?.FirstOrDefault();
            //    if (swithcConfig?.TotalDuration == null || swithcConfig.TotalDuration == 0)
            //    {
            //        Logger.Info("任务关闭");
            //        return;
            //    }
            //    testUser = swithcConfig.MsgTitle;
            //}

            #region 处理1
            using (var cmd = new SqlCommand("SELECT * FROM Configuration.. tbl_MessagePush WITH(NOLOCK) WHERE  EnID in('anzhuangchaoshiyifukuantixing','anzhuangchaoshiweifukuantixing')"))
            {
                var msgConfig = DbHelper.ExecuteSelect <MessagePushConfig>(cmd)?.ToList();

                foreach (var i in msgConfig)
                {
                    #region 数据处理
                    using (var c = new SqlCommand(@"
SELECT  *
FROM    ( SELECT    O.UserID ,
                    O.OrderNo ,
                    UserTel AS Phone ,
                    O.PKID AS OrderID ,
                    O.UserID Device_Tokens,
                    ISNULL(O.OrderProducts, O.OrderNo) AS Products,
                    O.OrderDatetime
          FROM      Gungnir..tbl_Order AS O WITH ( NOLOCK )
                    LEFT JOIN Gungnir.dbo.tbl_OrderDeliveryLog AS LG WITH ( NOLOCK ) ON O.PKID = LG.OrderID
          WHERE     Status <> '7Canceled'
                    AND ( LG.DeliveryStatus = '3Received'
                          OR LG.DeliveryStatus = '3.5Signed'
                        )
                    AND LG.DeliveryDatetime >= @StarTime
                    AND LG.DeliveryDatetime < @EndTime
                    AND PayStatus = @PayStatus
                    AND O.OrderType <> N'6美容'
                    AND O.OrderChannel != N'r天猫马牌'
                    AND InstallType = '1ShopInstall'
                    AND InstallShopID > 0
                    AND InstallStatus <> '2Installed'
                    AND InstallStatus <> '3NoInstall'
                    AND ( O.DeliveryStatus = '3Received'
                          OR O.DeliveryStatus = '3.5Signed'
                        )
        ) AS T
WHERE   NOT EXISTS ( SELECT 1
                     FROM   SystemLog..tbl_OrderPushInfo AS OPI WITH ( NOLOCK )
                     WHERE  OrderID = T.OrderID
                            AND MsgType = @MsgType );"))
                    #endregion
                    {
                        try
                        {
                            var MsgId = 0;
                            c.Parameters.AddWithValue("@StarTime", DateTime.Now.AddHours(-(i.TotalDuration.Value - i.AheadHour.Value)).ToString("yyyy-MM-dd"));
                            c.Parameters.AddWithValue("@EndTime", DateTime.Now.AddHours(-(i.TotalDuration.Value - i.AheadHour.Value)).AddDays(1).ToString("yyyy-MM-dd"));
                            if (i.EnID == "anzhuangchaoshiyifukuantixing")
                            {
                                c.Parameters.AddWithValue("@PayStatus", "2Paid");
                                MsgId = MsgId_YFK;
                            }
                            else
                            {
                                c.Parameters.AddWithValue("@PayStatus", "1Waiting");
                                MsgId = MsgId_WFK;
                            }
                            c.Parameters.AddWithValue("@MsgType", i.EnID);

                            var dt = DbHelper.ExecuteSelect <PushInfoModel>(true, c)?.ToList();
                            foreach (var d in dt)
                            {
                                var productName = d.Products;
                                if (!string.IsNullOrWhiteSpace(productName))
                                {
                                    if (productName.Length > 30)
                                    {
                                        productName = productName.Substring(0, 20);
                                    }
                                }
                                else
                                {
                                    productName = "";
                                }
                                //var userids = testUser == "all" ? new List<string>() { d.Device_Tokens } : testUser.Split(',').ToList();
                                var userids = new List <string>()
                                {
                                    d.Device_Tokens
                                };
                                using (var client = new TemplatePushClient())
                                {
                                    var replacementdict = new Dictionary <string, string>
                                    {
                                        ["{{ios.productname}}"]        = productName,
                                        ["{{ios.day}}"]                = (i.AheadHour / 24)?.ToString(),
                                        ["{{ios.orderid}}"]            = d.OrderNo,
                                        ["{{android.productname}}"]    = productName,
                                        ["{{android.day}}"]            = (i.AheadHour / 24)?.ToString(),
                                        ["{{android.orderid}}"]        = d.OrderNo,
                                        ["{{messagebox.productname}}"] = productName,
                                        ["{{messagebox.day}}"]         = (i.AheadHour / 24)?.ToString(),
                                        ["{{messagebox.orderid}}"]     = d.OrderNo,
                                        ["{{replace.orderid}}"]        = d.OrderNo
                                    };
                                    if (MsgId == MsgId_YFK)
                                    {
                                        replacementdict["{{first.DATA}}"] =
                                            $"您预约的【{productName}】未进行安装,再过{(i.AheadHour / 24)?.ToString()}天将会被取消订单,请抓紧去门店享受服务吧!";
                                        replacementdict["{{OrderSn.DATA}}"]     = d.OrderNo;
                                        replacementdict["{{OrderStatus.DATA}}"] = "即将到达安装期限";
                                        replacementdict["{{remark.DATA}}"]      = "点击查看订单详情";
                                        replacementdict["{{wxopen.orderid}}"]   = d.OrderNo;
                                    }
                                    if (MsgId == MsgId_WFK)
                                    {
                                        replacementdict["{{first.DATA}}"] =
                                            $"您预约的{productName}未进行安装,再过{(i.AheadHour / 24)?.ToString()}天将会被取消订单,请抓紧去门店享受服务吧!";
                                        replacementdict["{{OrderSn.DATA}}"]     = d.OrderNo;
                                        replacementdict["{{OrderStatus.DATA}}"] = "即将到达安装期限";
                                        replacementdict["{{remark.DATA}}"]      = "点击查看订单详情";
                                        replacementdict["{{wxopen.orderid}}"]   = d.OrderNo;
                                    }
                                    var result = client.PushByUserIDAndBatchID(
                                        userids,
                                        MsgId,
                                        new Service.Push.Models.Push.PushTemplateLog()
                                    {
                                        Replacement = JsonConvert.SerializeObject(replacementdict),
                                        DeviceType  = Service.Push.Models.Push.DeviceType.iOS
                                    });
                                    if (result?.Result == null || !result.Success || !result.Result)
                                    {
                                        Logger.Error($"推送失败{result.ErrorCode};{result.ErrorMessage}", result.Exception);
                                        //continue;
                                    }
                                    //if (testUser == "all")
                                    InsetPushInfo(d.OrderID, i.EnID, "All");
                                    //else
                                    //{
                                    //    return;
                                    //}
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex.Message, ex);
                        }
                    }
                }
            }
            #endregion
            Logger.Info("结束任务");
        }
        public void Execute(IJobExecutionContext context)
        {
            Logger.Info("启动任务");

            //var testUser = "";
            //using (var cmd = new SqlCommand(@"SELECT  Value TotalDuration,
            //        Description MsgTitle
            //FROM    Gungnir..RuntimeSwitch WITH ( NOLOCK )
            //WHERE   SwitchName = N'OrderPushDeliveryCodeJob';"))
            //{
            //    var swithcConfig = DbHelper.ExecuteSelect<MessagePushConfig>(cmd)?.FirstOrDefault();
            //    if (swithcConfig?.TotalDuration == null || swithcConfig.TotalDuration == 0)
            //    {
            //        Logger.Info("任务关闭");
            //        return;
            //    }
            //    testUser = swithcConfig.MsgTitle;
            //}

            #region 处理1
            using (var cmd = new SqlCommand("SELECT * FROM Configuration.. tbl_MessagePush WITH(NOLOCK) WHERE  EnID='fahuotixing'"))
            {
                try
                {
                    var msgConfig = DbHelper.ExecuteSelect <MessagePushConfig>(cmd)?.First();

                    #region 数据处理
                    using (var c = new SqlCommand(@"
SELECT  *
FROM    ( SELECT    O.OrderNo ,
                    O.PKID AS OrderID ,
                    O.UserID Device_Tokens,
                    O.UserTel AS Phone ,
                    ISNULL(O.OrderProducts, O.OrderNo) AS Products ,
                    LT.DeliveryCode,
                    O.OrderDatetime
          FROM      Gungnir..tbl_Order AS O WITH ( NOLOCK )
                    INNER JOIN WMSSERVER.WMS.dbo.LogisticTask AS LT WITH ( NOLOCK ) ON O.PKID = LT.OrderId
          WHERE     LT.TaskStatus = '3Sent'
                    AND Status = '2Shipped'
                    AND DeliveryStatus = '2Sent'
                    AND O.DeliveryType <> '4NoDelivery'
                    AND InstallType = '3NoInstall'
                    AND O.OrderType <> N'6美容'
                    AND O.OrderChannel != N'r天猫马牌'
                    AND O.OrderDatetime >= '2016-4-24' 
                    --AND LT.DeliveryCode <> ''
                    --AND LT.DeliveryCode IS NOT NULL
        ) AS T
WHERE   NOT EXISTS ( SELECT 1
                     FROM   SystemLog..tbl_OrderPushInfo AS OPI WITH ( NOLOCK )
                     WHERE  OrderID = T.OrderID
                            AND MsgType = 'fahuotixing' )
ORDER BY T.OrderID DESC; "))
                    {
                        try
                        {
                            var dt = DbHelper.ExecuteSelect <PushInfoModel>(true, c)?.ToList();
                            foreach (var d in dt)
                            {
                                var productName = d.Products;
                                if (!string.IsNullOrWhiteSpace(productName))
                                {
                                    if (productName.Length > 30)
                                    {
                                        productName = productName.Substring(0, 20) + "...";
                                    }
                                }
                                else
                                {
                                    productName = "";
                                }
                                string company       = "";
                                var    DeliveryInfos = SelectOrderDeliveryInfosByOrderId(Convert.ToInt32(d.OrderID), d.UserID);
                                if (DeliveryInfos != null && DeliveryInfos.Any())
                                {
                                    var m = DeliveryInfos.FirstOrDefault(
                                        x => !string.IsNullOrEmpty(x.DeliveryCode) &&
                                        x.DeliveryCode.Contains(d.DeliveryCode));
                                    if (m != null)
                                    {
                                        company = m.DeliveryCompany;
                                    }
                                }
                                using (var client = new TemplatePushClient())
                                {
                                    // var userids = testUser == "all" ? new List<string>() { d.Device_Tokens } : testUser.Split(',').ToList();
                                    var userids = new List <string>()
                                    {
                                        d.Device_Tokens
                                    };
                                    var replacementdict = new Dictionary <string, string>
                                    {
                                        ["{{ios.productname}}"]        = productName,
                                        ["{{ios.trackingno}}"]         = d.DeliveryCode,
                                        ["{{ios.orderid}}"]            = d.OrderNo,
                                        ["{{android.productname}}"]    = productName,
                                        ["{{android.trackingno}}"]     = d.DeliveryCode,
                                        ["{{android.orderid}}"]        = d.OrderNo,
                                        ["{{messagebox.productname}}"] = productName,
                                        ["{{messagebox.trackingno}}"]  = d.DeliveryCode,
                                        ["{{messagebox.orderid}}"]     = d.OrderNo,
                                        ["{{replace.orderid}}"]        = d.OrderNo,
                                        ["{{first.DATA}}"]             = $"亲,您购买的宝贝{productName}已经启程了,好想快点来到你身边",
                                        ["{{keyword1.DATA}}"]          = d.OrderNo,
                                        ["{{OrderStatus.DATA}}"]       = "订单已发货",
                                        ["{{OrderSn.DATA}}"]           = d.OrderNo,
                                        ["{{keyword2.DATA}}"]          = company,
                                        ["{{keyword3.DATA}}"]          = d.DeliveryCode,
                                        ["{{remark.DATA}}"]            = $"点击查看订单详情",
                                        ["{{wxopen.orderid}}"]         = d.OrderNo,
                                    };


                                    var result = client.PushByUserIDAndBatchID(
                                        userids,
                                        439,
                                        new Service.Push.Models.Push.PushTemplateLog()
                                    {
                                        Replacement = JsonConvert.SerializeObject(replacementdict),
                                        DeviceType  = Service.Push.Models.Push.DeviceType.iOS
                                    });
                                    if (result?.Result == null || !result.Success || !result.Result)
                                    {
                                        Logger.Error($"推送失败{result.ErrorCode};{result.ErrorMessage}", result.Exception);
                                        //continue;
                                    }
                                    //if (testUser == "all")
                                    InsetPushInfo(d.OrderID, msgConfig.EnID, "All");
                                    //else
                                    //{
                                    //    return;
                                    //}
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex.Message, ex);
                        }
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    Logger.Error(ex.Message, ex);
                }
            }
            #endregion
            Logger.Info("结束任务");
        }