Пример #1
0
        public static async Task <FixedPriceActivityRoundConfig> GetRoundConfig(Guid activityId, DateTime time)
        {
            FixedPriceActivityRoundConfig result = null;
            var activityConfig = await ActivityCache.GetBaoYangActivityConfig(activityId);

            if (activityConfig != null && activityConfig.RoundConfigs != null && activityConfig.RoundConfigs.Any())
            {
                result = activityConfig.RoundConfigs.FirstOrDefault(o => time >= o.StartTime && time < o.EndTime);
            }

            return(result);
        }
Пример #2
0
        public static async Task <Tuple <CreateOrderErrorCode, int, int, FixedPriceActivityRoundConfig> > ValidateBaoyang(Guid activityId)
        {
            CreateOrderErrorCode result         = CreateOrderErrorCode.ActivitySatisfied;
            int userLimitCount                  = 0;
            int activityLimitCount              = 0;
            FixedPriceActivityRoundConfig round = null;

            try
            {
                var activity = await ActivityCache.GetBaoYangActivityConfig(activityId);

                if (activity != null)
                {
                    var now = DateTime.Now;
                    round = GetCurrentRoundConfig(activity, now);

                    if (now >= activity.EndTime)
                    {
                        result = CreateOrderErrorCode.ActivityExpired;
                    }
                    else if (now < activity.StartTime)
                    {
                        result = CreateOrderErrorCode.ActivityNotStart;
                    }
                    else if (round == null)
                    {
                        result = CreateOrderErrorCode.WaitingNext;
                    }
                    else
                    {
                        userLimitCount     = activity.ItemQuantityPerUser;
                        activityLimitCount = round.LimitedQuantity;
                    }
                }
                else
                {
                    result = CreateOrderErrorCode.ActivityExpired;
                }
            }
            catch (Exception ex)
            {
                LogManager.GetLogger("ActivityValidator").Error(ex);
                result = CreateOrderErrorCode.ServerBusy;
            }

            return(Tuple.Create(result, activityLimitCount, userLimitCount, round));
        }