Beispiel #1
0
        public static async Task <bool> PushArticleMessage(string userId, int batchId, int articleid, string userName)
        {
            try
            {
                using (var client = new Tuhu.Service.Push.TemplatePushClient())
                {
                    var result = await client.PushByUserIDAndBatchIDAsync(new List <string> {
                        userId
                    }, batchId, new Service.Push.Models.Push.PushTemplateLog()
                    {
                        Replacement = Newtonsoft.Json.JsonConvert.SerializeObject(new Dictionary <string, string> {
                            { "{{push_title}}", "" },
                            { "{{iOS_Nickname}}", userName },
                            { "{{Android_Nickname}}", userName },
                            { "{{App_Nickname}}", userName },
                            { "{{articleid}}", $"{articleid}" },
                        }),
                        DeviceType = Service.Push.Models.Push.DeviceType.MessageBox
                    });

                    result.ThrowIfException(true);
                    return(result.Result);
                }
            }
            catch (Exception ex)
            {
                WebLog.LogException(ex);
            }
            return(false);
        }
        public static async Task PushOrderFinish(Guid userId, string productName, decimal money, string orderId)
        {
            List <string> target = new List <string> {
                userId.ToString()
            };


            using (var client = new Tuhu.Service.Push.TemplatePushClient())
            {
                var result = await client.PushByUserIDAndBatchIDAsync(target, 798, new Service.Push.Models.Push.PushTemplateLog()
                {
                    Replacement = Newtonsoft.Json.JsonConvert.SerializeObject(new Dictionary <string, string>()
                    {
                        { "{{keyword1.DATA}}", productName },
                        { "{{keyword2.DATA}}", string.Format("{0:f}", money) },
                        { "{{keyword3.DATA}}", orderId },
                        { "{{keyword4.DATA}}", "\"恭喜您拼团成功,我们正在火速为您安排发货~\"" },
                        { "{{orderid}}", orderId }
                    }),
                    DeviceType = Service.Push.Models.Push.DeviceType.WeChat
                });

                result.ThrowIfException(true);
            }
        }
        /// <summary>
        /// 发送优惠券
        /// </summary>
        /// <param name="fightGroupsIdentity"></param>
        /// <returns></returns>
        public static async Task <FightGroupsPacketsProvideResponse> CreateFightGroupsPacketByPromotion(Guid fightGroupsIdentity)
        {
            using (var client = CacheHelper.CreateCacheClient(FightGroupPacketsListRedisKey))
            {
                List <FightGroupsPacketsLogModel> list = null;
                var result = await client.GetOrSetAsync <List <FightGroupsPacketsLogModel> >(fightGroupsIdentity.ToString(), async() => await DalFightGroupsPacketsLog.GetFightGroupsPacketsList(fightGroupsIdentity), TimeSpan.FromDays(1));

                list = result?.Value;
                if (list == null)
                {
                    list = await DalFightGroupsPacketsLog.GetFightGroupsPacketsList(fightGroupsIdentity);
                }
                if (list?.Where(_ => _.UserId == null)?.Count() <= 0 && list?.Where(_ => _.PromotionPKID != null)?.Count() <= 0)
                {
                    using (var memberClient = new Tuhu.Service.Member.PromotionClient())
                    {
                        List <CreatePromotionModel> promotionModelList = new List <CreatePromotionModel>();
                        foreach (var item in list)
                        {
                            promotionModelList.Add(new CreatePromotionModel()
                            {
                                Author         = item.UserId.ToString(),
                                GetRuleGUID    = item.GetRuleGuid,
                                UserID         = item.UserId,
                                Channel        = "小程序分享红包",
                                DeviceID       = "",
                                Operation      = "小程序分享红包",
                                IssueChannle   = "小程序分享红包",
                                IssueChannleId = fightGroupsIdentity.ToString(),
                                Issuer         = "李维童"
                            });
                        }
                        var memberResult = await memberClient.CreatePromotionsNewAsync(promotionModelList);

                        if (memberResult.Result.IsSuccess)
                        {
                            for (int i = 0; i < list?.Count; i++)
                            {
                                if (memberResult?.Result?.promotionIds?.Count > i)
                                {
                                    list[i].PromotionPKID = memberResult?.Result?.promotionIds[i];
                                }
                            }
                            await DalFightGroupsPacketsLog.UpdateCreatePromotionPKID(list);

                            // 先注释掉,因为读写库原因,删掉之后,下次从数据库读取不到
                            //using (var reditClient = CacheHelper.CreateCacheClient(FightGroupPacketsListRedisKey))
                            //{
                            //    reditClient.Remove(list?.Where(_ => _.IsLeader == true)?.FirstOrDefault()?.UserId.ToString());
                            //    reditClient.Remove(fightGroupsIdentity.ToString());
                            //}


                            using (var pushClient = new Tuhu.Service.Push.TemplatePushClient())
                            {
                                foreach (var item in list)
                                {
                                    using (var userClient = new Tuhu.Service.UserAccount.UserAccountClient())
                                    {
                                        var userResult = await userClient.GetUserByIdAsync(item.UserId.Value);

                                        var pushResult = await pushClient.PushByUserIDAndBatchIDAsync(new List <string>() { item.UserId.Value.ToString() }, 1643, new Service.Push.Models.Push.PushTemplateLog()
                                        {
                                            Replacement = Newtonsoft.Json.JsonConvert.SerializeObject(new Dictionary <string, string>()
                                            {
                                                { "{{nickname}}", userResult.Result.Profile.NickName },
                                                { "{{packetgroupno}}", item.FightGroupsIdentity.ToString() }
                                            })
                                        });

                                        if (!pushResult.Success || !pushResult.Result)
                                        {
                                            Logger.ErrorException("拆红包推送失败", pushResult.Exception);
                                        }
                                    }
                                }
                            }

                            return(new FightGroupsPacketsProvideResponse()
                            {
                                IsSuccess = memberResult.Result.IsSuccess, Msg = "优惠券领取成功"
                            });
                        }
                        else
                        {
                            return(new FightGroupsPacketsProvideResponse()
                            {
                                IsSuccess = memberResult.Result.IsSuccess, Msg = memberResult?.Result?.ErrorMessage
                            });
                        }
                    }
                }
                else
                {
                    return new FightGroupsPacketsProvideResponse()
                           {
                               IsSuccess = false, Msg = string.Format("分享红包组没有拼组完成还差{0}个或者已经发放过", list?.Where(_ => _.UserId == null)?.Count())
                           }
                };
            }
        }