Exemple #1
0
        /// <summary>
        ///  验证 发送历史
        /// </summary>
        /// <param name="request"></param>
        /// <param name="user"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <int> CheckSendHistoryAsync(SendCouponRequest request, User user, CancellationToken cancellationToken)
        {
            var entity = await promotionSingleTaskUsersHistoryRepository.GetByPromotionTaskIdAndPhoneAsync(request.PromotionTaskId, user.MobileNumber, cancellationToken).ConfigureAwait(false);

            if (entity != null && entity.PromotionSingleTaskUsersHistoryId > 0 && !string.IsNullOrWhiteSpace(entity.PromotionCodeIDs))
            {
                return(entity.PromotionSingleTaskUsersHistoryId);
            }
            else
            {
                return(0);
            }
        }
Exemple #2
0
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="couponRuleList"></param>
        /// <param name="user"></param>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <bool> SendNoyificationAsync(List <PromotionTaskPromotionListModel> couponRuleList, User user, SendCouponRequest request, CancellationToken cancellationToken)
        {
            try
            {
                List <string> smsParam   = JsonConvert.DeserializeObject <List <string> >(request.SmsParam ?? "");
                string        msgUrl     = string.Empty;                         //追踪短信链接
                string        msgBatchs  = string.Empty;                         //追踪短信批次
                string        msgSubject = string.Empty;                         //追踪短信主题

                if (request.SmsId > 0 && smsParam.Any())                         //判断是否发送短信
                {
                    if (smsParam.FirstOrDefault().ToLower().Contains("tuhu.cn")) //发送追踪短信
                    {
                        msgUrl = smsParam[0];
                        smsParam.RemoveAt(0);
                        msgBatchs  = $"CouponTask_{request.PromotionTaskId}_{DateTime.Now.ToString("yyyyMMdd")}";
                        msgSubject = $"优惠券任务:{request.PromotionTaskId}";

                        var biSmsRequest = new BiSmsRequest()
                        {
                            PhoneNumber = user.MobileNumber,
                            MsgBatchs   = msgBatchs,
                            MsgSubject  = msgSubject,
                            MsgBody     = smsParam.ToArray(),
                            MsgUrl      = msgUrl,
                            RelatedUser = request.Creater,
                            TemplateId  = request.SmsId
                        };
                        await smsService.SendBiSmsAsync(biSmsRequest, cancellationToken).ConfigureAwait(false);
                    }
                    else //发送普通短信
                    {
                        var smsRequest = new SendTemplateSmsRequest()
                        {
                            Cellphone         = user.MobileNumber,
                            TemplateId        = request.SmsId,
                            TemplateArguments = smsParam.ToArray()
                        };
                        await smsService.SendSmsAsync(smsRequest).ConfigureAwait(false);
                    }
                }

                foreach (var couponRule in couponRuleList.Where(p => p.IsRemind == "1"))
                {
                    PushTemplateLog pushTemplateLog = new PushTemplateLog()
                    {
                        Replacement = JsonConvert.SerializeObject(
                            new Dictionary <string, string>
                        {
                            ["{{currenttime}}"]  = DateTime.Now.ToString("yyyy年MM月dd日 HH:mm"),
                            ["{{couponamount}}"] = couponRule.DiscountMoney.ToString(CultureInfo.InvariantCulture),
                            ["{{couponname}}"]   = couponRule.PromotionDescription
                        })
                    };
                    await pushService.PushByUserIDAndBatchIDAsync(new List <string> {
                        user.MobileNumber
                    }, 1509, pushTemplateLog).ConfigureAwait(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                logger.LogWarning("SendNoyificationAsync Exception", ex);
            }
            return(false);
        }
Exemple #3
0
        /// <summary>
        ///  批量发送优惠券并更新统计次数  ,记录已发日志
        /// </summary>
        /// <param name="couponRuleList"></param>
        /// <param name="user"></param>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <string> SendCouponsLogicAsync(List <PromotionTaskPromotionListModel> couponRuleList, User user, SendCouponRequest request, CancellationToken cancellationToken)
        {
            var result = new CreatePromotionCodeResult();
            PromotionSingleTaskUsersHistoryEntity entity = new PromotionSingleTaskUsersHistoryEntity()
            {
                PromotionTaskId = request.PromotionTaskId,
                UserCellPhone   = user.MobileNumber,
                SendState       = 0,
                OrderNo         = request.OrderID.ToString(),
                UserID          = user.UserId
            };
            var createPromotionList = new List <CreatePromotionModel>();

            try
            {
                #region 3.创建优惠券 [批量]
                foreach (var couponRule in couponRuleList)
                {
                    for (int i = 0; i < couponRule.Number; i++)
                    {
                        CreatePromotionModel createPromotionModel = new CreatePromotionModel()
                        {
                            Author           = couponRule.Creater,
                            MinMoney         = couponRule.MinMoney,
                            Discount         = couponRule.DiscountMoney,
                            DepartmentName   = couponRule.DepartmentName,
                            IntentionName    = couponRule.IntentionName,
                            BusinessLineName = couponRule.BusinessLineName,
                            Description      = couponRule.PromotionDescription,
                            UserID           = user.UserId,
                            Channel          = "PromotionTask",
                            StartTime        = couponRule.StartTime,
                            EndTime          = couponRule.EndTime,
                            RuleId           = couponRule.CouponRulesId,
                            GetRuleID        = couponRule.GetCouponRuleID,
                            Creater          = couponRule.Creater,
                            IssueChannleId   = request.PromotionTaskId.ToString(),
                            IssueChannle     = "优惠券任务塞券",
                            Issuer           = couponRule.Issuer,
                            //Type = couponRule.,//创建时会自动添加
                            TaskPromotionListId = couponRule.TaskPromotionListId,
                            BathID = request.OrderID,
                        };
                        createPromotionList.Add(createPromotionModel);
                    }
                }
                logger.Info($@"CouponTaskManager CreatePromotionsForYeWuAsync createPromotionList={JsonConvert.SerializeObject(createPromotionList)}");
                var createPromotionResult = await createPromotionService.CreatePromotionsForYeWuAsync(createPromotionList).ConfigureAwait(false);

                result                  = createPromotionResult?.Result;
                entity.IsSuccess        = result.IsSuccess ? 1 : 2;
                entity.Message          = result.ErrorMessage;
                entity.PromotionCodeIDs = result.promotionIds == null ? "" : string.Join(",", result.promotionIds);
                #endregion
            }
            catch (Exception ex)
            {
                logger.LogWarning("CouponTaskManager SendCouponsLogicAsync Exception", ex);
                entity.IsSuccess        = 2;
                entity.Message          = result.ErrorMessage;
                entity.PromotionCodeIDs = result.promotionIds == null ? "" : string.Join(",", result.promotionIds);
                return(entity.PromotionCodeIDs);
            }
            finally
            {
                await promotionSingleTaskUsersHistoryRepository.CreateAsync(entity, cancellationToken).ConfigureAwait(false);

                int successCount = result?.promotionIds?.Count() ?? 0;
                //记录到已发 日志表
                //增加塞券次数
                await promotionTaskRepository.UpdatePromotionTaskCountAsync(request.PromotionTaskId, successCount > 0? 1 : 0, (createPromotionList.Count() - successCount) > 0? 1 : 0, cancellationToken).ConfigureAwait(false);
            }
            return(entity.PromotionCodeIDs);
        }
Exemple #4
0
 /// <summary>
 ///  发券
 /// </summary>
 /// <param name="request"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public ValueTask <SendCouponResponse> SendCouponAsync(SendCouponRequest request, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }