Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        public static string GetMessage(CreateOrderErrorCode code)
        {
            string result = string.Empty;

            switch (code)
            {
            case CreateOrderErrorCode.ActivityExpired:
                result = "活动已结束";
                break;

            case CreateOrderErrorCode.ActivityLimit:
                result = "活动太火爆,都抢光了~";
                break;

            case CreateOrderErrorCode.ActivityNotStart:
                result = "活动还未开始";
                break;

            case CreateOrderErrorCode.ActivitySatisfied:
                result = "满足活动条件";
                break;

            case CreateOrderErrorCode.ServerBusy:
                result = "活动太火爆了";
                break;

            case CreateOrderErrorCode.UserLimit:
                result = "您买的已经很多啦,下次再买吧~";
                break;

            case CreateOrderErrorCode.WaitingNext:
                result = "本期活动已结束,请等待后续活动开始";
                break;

            case CreateOrderErrorCode.ProductValidateFailed:
                result = "产品验证失败,请返回重试";
                break;

            default:
                result = "活动已结束";
                break;
            }

            return(result);
        }