コード例 #1
0
 /// <summary>
 /// 批量获取活动商品已售数量缓存数据
 /// </summary>
 /// <param name="activityId"></param>
 /// <param name="pidList"></param>
 /// <returns></returns>
 public async Task <OperationResult <IEnumerable <ActivityPidSoldNumModel> > > GetOrSetActivityProductSoldNumCacheAsync(string activityId, List <string> pidList)
 {
     if (string.IsNullOrEmpty(activityId) || !(pidList?.Count > 0))
     {
         return(OperationResult.FromError <IEnumerable <ActivityPidSoldNumModel> >("1", "传入参数错误"));
     }
     return(OperationResult.FromResult(await DiscountActivityInfoManager.GetOrSetActivityProductSoldNumCache(activityId, pidList)));
 }
コード例 #2
0
 /// <summary>
 /// 批量获取用户活动已购数量缓存数据
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="activityIdList"></param>
 /// <returns></returns>
 public async Task <OperationResult <IEnumerable <UserActivityBuyNumModel> > > GetOrSetUserActivityBuyNumCacheAsync(string userId, List <string> activityIdList)
 {
     if (string.IsNullOrEmpty(userId) || !(activityIdList?.Count > 0))
     {
         return(OperationResult.FromError <IEnumerable <UserActivityBuyNumModel> >("1", "传入参数错误"));
     }
     return(OperationResult.FromResult(await DiscountActivityInfoManager.GetOrSetUserActivityBuyNumCache(userId, activityIdList)));
 }
コード例 #3
0
 /// <summary>
 /// 取消订单时 修改订单折扣记录
 /// </summary>
 /// <param name="orderInfoList"></param>
 /// <returns></returns>
 public async Task <OperationResult <bool> > UpdateCancelOrderDiscountInfoAndSetCacheAsync(int orderId)
 {
     if (!(orderId > 0))
     {
         return(OperationResult.FromError <bool>("1", "未传入参数"));
     }
     return(await DiscountActivityInfoManager.UpdateCancelOrderDiscountInfoAndSetCache(orderId));
 }
コード例 #4
0
 /// <summary>
 /// 获取商品的打折活动信息和用户限购数
 /// </summary>
 /// <param name="pidList"></param>
 /// <param name="userId"></param>
 /// <returns></returns>
 public async Task <OperationResult <IEnumerable <ProductDiscountActivityInfo> > > GetProductAndUserDiscountInfoAsync(List <string> pidList, string userId)
 {
     if (!(pidList?.Count > 0))
     {
         return(OperationResult.FromError <IEnumerable <ProductDiscountActivityInfo> >("1", "未传入参数商品Pid"));
     }
     pidList = pidList.Distinct().ToList();
     return(await DiscountActivityInfoManager.GetProductAndUserDiscountInfoAsync(pidList, userId));
 }
コード例 #5
0
        /// <summary>
        /// 遍历每个活动组
        /// </summary>
        /// <returns></returns>
        private async Task ForEachActivityGroup()
        {
            foreach (var group in _productGroups)
            {
                var currentActivityId                = group.Key;
                var currentActivity                  = _activities.FirstOrDefault(s => string.Equals(s.ActivityId, currentActivityId));
                var currentActivityPids              = group.Select(g => g.Pid).ToList();
                var currentActivityRequestNum        = group.Sum(s => s.RequestNum);
                var currentActivityRequestTotalPrice = group.Sum(s => s.RequestNum * s.RequestPrice);
                var userBuyNum = await DiscountActivityInfoManager.GetOrSetUserActivityBuyNumCache(_userId, new List <string>() { currentActivityId });

                if (_isCreateOrder)
                {
                    await DiscountActivityInfoManager.IncreaseUserActivityBuyNumCache(_userId, currentActivityId, currentActivityRequestNum, TimeSpan.FromMinutes(1));
                }
                var currentActivityUserAlreadyBuyNum = userBuyNum?.FirstOrDefault()?.BuyNum ?? 0;

                if (currentActivity != null)
                {
                    var currentActivityRules = _activityDiscountRules.Where(s => string.Equals(currentActivityId, s.ActivityId)).ToList();
                    if (!currentActivityRules.Any())
                    {
                        _returnList.AddRange(group.Select(g => new ProductHitDiscountResponse()
                        {
                            DiscountPrice       = g.RequestPrice,
                            HasDiscountActivity = false,
                            DiscountRule        = null,
                            IsHit       = false,
                            Pid         = g.Pid,
                            FailCode    = nameof(ProductHitFailCode.NoneActivityDiscount),
                            FailMessage = ProductHitFailCode.NoneActivityDiscount,
                        }));
                        continue;
                    }
                    if (currentActivity.Is_PurchaseLimit == 1 && currentActivity.LimitQuantity < currentActivityUserAlreadyBuyNum + currentActivityRequestNum)//当前活动用户限购
                    {
                        _returnList.AddRange(group.Select(g => new ProductHitDiscountResponse()
                        {
                            DiscountPrice       = g.RequestPrice,
                            HasDiscountActivity = true,
                            DiscountRule        = null,
                            IsHit       = false,
                            Pid         = g.Pid,
                            FailCode    = nameof(ProductHitFailCode.UserBeLimited),
                            FailMessage = ProductHitFailCode.UserBeLimited,
                        }));
                        continue;
                    }
                    var productSoldNums = (await DiscountActivityInfoManager.GetOrSetActivityProductSoldNumCache(currentActivityId, currentActivityPids));
                    await ForEachActivityGroupProducts(group, productSoldNums, currentActivityRules,
                                                       currentActivity, currentActivityRequestNum, currentActivityRequestTotalPrice);
                }
            }
        }
コード例 #6
0
 /// <summary>
 /// 创建订单时记录订单打折信息
 /// </summary>
 /// <param name="orderInfoList"></param>
 /// <returns></returns>
 public async Task <OperationResult <bool> > SaveCreateOrderDiscountInfoAndSetCacheAsync(List <DiscountCreateOrderRequest> orderInfoList)
 {
     // 验证参数
     orderInfoList = orderInfoList?.Where(a =>
                                          !string.IsNullOrWhiteSpace(a.ActivityId) && !string.IsNullOrWhiteSpace(a.Pid) &&
                                          !string.IsNullOrWhiteSpace(a.UserId) && a.Num > 0)?.ToList();
     if (!(orderInfoList?.Count > 0))
     {
         return(OperationResult.FromError <bool>("1", "参数不正确"));
     }
     return(await DiscountActivityInfoManager.SaveCreateOrderDiscountInfoAndSetCache(orderInfoList));
 }
コード例 #7
0
        /// <summary>
        /// 修改活动的审核状态
        /// </summary>
        /// <param name="activityId"></param>
        /// <param name="auditUserName"></param>
        /// <param name="auditStatus"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        public static async Task <OperationResult <bool> > SetActivityAuditStatusAsync(string activityId, string auditUserName, int auditStatus, string remark)
        {
            bool result;

            result = await DalSalePromotionActivity.SetActivityAuditStatusAsync(activityId, auditUserName, auditStatus, remark);

            if (result && auditStatus == 2)
            {
                //审核活动, 自动上下架
                await DiscountActivityInfoManager.AuditShelveActivityProduct(activityId);
            }
            return(OperationResult.FromResult(result));;
        }
コード例 #8
0
 /// <summary>
 /// 获取时间段内商品的活动信息列表
 /// </summary>
 /// <param name="pidList"></param>
 /// <param name="startTime"></param>
 /// <param name="endTime"></param>
 /// <returns></returns>
 public async Task <OperationResult <IEnumerable <ProductActivityInfoForTag> > > GetProductDiscountInfoForTagAsync(List <string> pidList, DateTime startTime, DateTime endTime)
 {
     if (!(pidList?.Count > 0))
     {
         return(OperationResult.FromError <IEnumerable <ProductActivityInfoForTag> >("1", "请传入商品pid"));
     }
     if (startTime == null || startTime == new DateTime())
     {
         return(OperationResult.FromError <IEnumerable <ProductActivityInfoForTag> >("2", "请传入活动开始时间"));
     }
     if (endTime == null || endTime == new DateTime())
     {
         return(OperationResult.FromError <IEnumerable <ProductActivityInfoForTag> >("3", "请传入活动结束时间"));
     }
     if (startTime >= endTime)
     {
         return(OperationResult.FromError <IEnumerable <ProductActivityInfoForTag> >("4", "开始时间应小于结束时间"));
     }
     pidList = pidList?.Distinct().ToList();
     return(await DiscountActivityInfoManager.GetProductDiscountInfoForTagAsync(pidList, startTime, endTime));
 }
コード例 #9
0
        /// <summary>
        /// 遍历活动组内的每个产品
        /// </summary>
        /// <param name="group"></param>
        /// <param name="productSoldNums"></param>
        /// <param name="currentActivityRules"></param>

        private async Task ForEachActivityGroupProducts(IGrouping <string, CompProduct> group, IEnumerable <ActivityPidSoldNumModel> productSoldNums,
                                                        List <SalePromotionActivityDiscount> currentActivityRules, SalePromotionActivityModel currentActivity,
                                                        int currentActivityRequestNum, decimal currentActivityRequestTotalPrice)
        {
            var effictiveCurrentActivityRequestNumAndPrice = GetEffictiveCurrentActivityRequestNumAndPrice(group, productSoldNums, currentActivityRules, currentActivity,
                                                                                                           currentActivityRequestNum, currentActivityRequestTotalPrice);

            currentActivityRequestNum        = effictiveCurrentActivityRequestNumAndPrice.Item1;
            currentActivityRequestTotalPrice = effictiveCurrentActivityRequestNumAndPrice.Item2;
            foreach (var product in group)
            {
                if (_isCreateOrder)
                {
                    await DiscountActivityInfoManager.IncreaseActivityProductSoldNumCache(currentActivity.ActivityId, product.Pid, product.RequestNum, TimeSpan.FromMinutes(1));
                }
                if (_verifyPayAndInstallMethod)
                {
                    if (product.Pid.StartsWith("TR", StringComparison.CurrentCultureIgnoreCase) && currentActivity.InstallMethod > 0 && product.RequestInstallMethod != currentActivity.InstallMethod)
                    {
                        _returnList.Add(new ProductHitDiscountResponse()
                        {
                            DiscountPrice       = product.RequestPrice,
                            HasDiscountActivity = true,
                            DiscountRule        = null,
                            IsHit       = false,
                            Pid         = product.Pid,
                            FailCode    = ProductHitFailCode.GetFailCodeAndDescriptionOfInstall(currentActivity.InstallMethod).Item1,
                            FailMessage = ProductHitFailCode.GetFailCodeAndDescriptionOfInstall(currentActivity.InstallMethod).Item2,
                        });
                        continue;
                    }
                    if (product.Pid.StartsWith("TR", StringComparison.CurrentCultureIgnoreCase) && currentActivity.PaymentMethod > 0 && product.RequestPaymentMethod != currentActivity.PaymentMethod)
                    {
                        _returnList.Add(new ProductHitDiscountResponse()
                        {
                            DiscountPrice       = product.RequestPrice,
                            HasDiscountActivity = true,
                            DiscountRule        = null,
                            IsHit       = false,
                            Pid         = product.Pid,
                            FailCode    = ProductHitFailCode.GetFailCodeAndDescriptionOfPay(currentActivity.PaymentMethod).Item1,
                            FailMessage = ProductHitFailCode.GetFailCodeAndDescriptionOfPay(currentActivity.PaymentMethod).Item2,
                        });
                        continue;
                    }
                }
                var currentProductSoldNum = productSoldNums.FirstOrDefault(s => string.Equals(s.Pid, product.Pid))?.SoldNum ?? 0;
                if (product.LimitQuantity < currentProductSoldNum + product.RequestNum)
                {
                    _returnList.Add(new ProductHitDiscountResponse()
                    {
                        DiscountPrice       = product.RequestPrice,
                        HasDiscountActivity = true,
                        DiscountRule        = null,
                        IsHit       = false,
                        Pid         = product.Pid,
                        FailCode    = nameof(ProductHitFailCode.NotEnoughStock),
                        FailMessage = ProductHitFailCode.NotEnoughStock,
                    });
                    continue;
                }
                var judgeHitResult = JudgeHitDiscount(product.Pid, product.RequestPrice, product.RequestNum, currentActivityRules,
                                                      currentActivityRequestNum, currentActivityRequestTotalPrice);
                var isHit = judgeHitResult.Item1;
                _returnList.Add(new ProductHitDiscountResponse()
                {
                    DiscountPrice       = judgeHitResult.Item2,
                    HasDiscountActivity = true,
                    DiscountRule        = judgeHitResult.Item3,
                    IsHit    = isHit,
                    Pid      = product.Pid,
                    FailCode = !isHit ? judgeHitResult.Item3.DiscountMethod == 1 ? nameof(ProductHitFailCode.NotEnoughMoney) :
                               nameof(ProductHitFailCode.NotEnoughNum) : string.Empty,
                    FailMessage = !isHit ? judgeHitResult.Item3.DiscountMethod == 1 ? ProductHitFailCode.NotEnoughMoney :
                                  ProductHitFailCode.NotEnoughNum : string.Empty,
                });
            }
        }