Esempio n. 1
0
 /// <summary>
 /// 根据原优惠券,创建新优惠券,并且插入日志
 /// </summary>
 /// <param name="promotionId"></param>
 /// <param name="operation"></param>
 /// <returns></returns>
 private string CreateNewPromotionByOldPromotion(int promotionId, string operation = "部分取消")
 {
     if (promotionId > 0)
     {
         var oldPromotionCode = dbManager.Execute(connection => DalPromotionJob.FetchPromotionCodeByPromotionCode(connection, promotionId));
         oldPromotionCode.RuleName = oldPromotionCode.PromtionName;
         if (oldPromotionCode != null)
         {
             oldPromotionCode.Status      = 0;
             oldPromotionCode.CodeChannel = oldPromotionCode.CodeChannel + "(取消订单)";
             CreatePromotionModel createPromotionModel = new CreatePromotionModel()
             {
                 Author        = ThreadIdentity.Operator.Name,
                 Channel       = "取消订单",
                 Operation     = "原优惠券生成新优惠券",
                 PromotionPKID = oldPromotionCode.PkId
             };
             using (var client = new PromotionClient())
             {
                 var result = client.CopyPromotionCode(createPromotionModel);
                 if (result.Success)
                 {
                     new OprLogManager().AddOprLog <BizPromotionCode>("Order", oldPromotionCode.OrderId, operation + "原优惠券不释放,生成一张一样的优惠券,优惠券PKID:" + result.Result, null, null);
                 }
                 else
                 {
                     throw new Exception("根据原优惠券生成新优惠券失败,订单号:" + oldPromotionCode.OrderId);
                 }
             }
             //var newPromotionCode = dbManager.Execute(connection => DalPromotionJob.CreatePromotionCode(connection, oldPromotionCode));
             //new OprLogManager().AddOprLog<BizPromotionCode>("Order", oldPromotionCode.OrderId, operation + "原优惠券不释放,生成一张一样的优惠券,优惠券PKID:" + newPromotionCode, null, null);
         }
     }
     return(string.Empty);
 }
Esempio n. 2
0
        /// <summary>
        ///     创建优惠券
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static async Task <OperationResult <CreatePromotionCodeResult> > CreatePromotionNewAsync(
            CreatePromotionModel model)
        {
            using (var client = new PromotionClient())
            {
                var result = await client.CreatePromotionNewAsync(model);

                if (!result.Success)
                {
                    Logger.Error(
                        $"PromotionClient CreatePromotionNewAsync fail => ErrorCode ={result.ErrorCode} & ErrorMessage ={result.ErrorMessage} ");
                }

                return(result);
            }
        }
Esempio n. 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);
        }