public async Task <OperationResult <List <BigBrandRewardLogModel> > > SelectShareListAsync(Guid userId,
                                                                                                   string hashKey, int chanceType)
        {
            if (string.IsNullOrWhiteSpace(hashKey))
            {
                return(OperationResult.FromError <List <BigBrandRewardLogModel> >("-1", "抽奖活动不存在"));
            }
            Regex regex = new Regex("^([0-9]|[a-z]|[A-Z]){7}([0-9]|[a-z]|[A-Z])$");

            if (!regex.IsMatch(hashKey))
            {
                return(OperationResult.FromError <List <BigBrandRewardLogModel> >("-1", "抽奖活动hashkey不匹配"));
            }

            if (userId == Guid.Empty)
            {
                return(OperationResult.FromError <List <BigBrandRewardLogModel> >("-1", "用户UserId不能都为空"));

                ;
            }
            BigBrandResponse result   = new BigBrandResponse();
            BigBrandLogic    bigBrand = new BigBrandLogic(hashKey, userId, string.Empty, string.Empty, string.Empty);

            return(OperationResult.FromResult(await bigBrand.GetShareLogList(chanceType)));
        }
        /// <summary>
        /// 问答抽奖
        /// </summary>
        /// <param name="userId">用户userId</param>
        /// <param name="deviceId">设备Id</param>
        /// <param name="Channal">渠道</param>
        /// <param name="hashKey">抽奖hashKey</param>
        /// <param name="phone">手机号</param>
        /// <param name="refer">url</param>
        /// <param name="grade">得分</param>
        /// <returns></returns>
        public async Task <OperationResult <BigBrandResponse> > GetAnswerPacketAsync(Guid userId, string deviceId, string Channal, string hashKey, string phone, string refer)
        {
            if (string.IsNullOrWhiteSpace(hashKey))
            {
                return(OperationResult.FromResult(new BigBrandResponse()
                {
                    Code = -1, Msg = "抽奖活动不存在"
                }));
            }

            Regex regex = new Regex("^([0-9]|[a-z]|[A-Z]){7}([0-9]|[a-z]|[A-Z])$");

            if (!regex.IsMatch(hashKey))
            {
                return(OperationResult.FromResult(new BigBrandResponse()
                {
                    Code = -1, Msg = "抽奖活动hashkey不匹配"
                }));
            }

            if (userId == null)
            {
                return(OperationResult.FromResult(new BigBrandResponse()
                {
                    Code = -1, Msg = "用户UserId不能为空"
                }));
            }

            BigBrandResponse result   = new BigBrandResponse();
            BigBrandLogic    bigBrand = new BigBrandLogic(hashKey, userId, phone, deviceId, Channal);

            bigBrand.Refer = refer;

            var isResult = await bigBrand.IsSelectCanPackage();

            if (!isResult.Result)
            {
                result.Code = 0;
                if (bigBrand.entity.BigBrandType == 2)
                {
                    result.Msg = "您的积分不足,无法抽奖哦";
                }
                else if (bigBrand.entity.BigBrandType == 3)
                {
                    result.Msg = "抱歉,只有指定用户才能参加此抽奖哦";
                }
                else
                {
                    result.Msg = "抽奖次数不足";
                }

                return(OperationResult.FromResult(result));
            }

            System.Diagnostics.Stopwatch watcher = new System.Diagnostics.Stopwatch();
            watcher.Restart();
            bigBrand._time = await QuesAnsManager.GetGrade(userId, hashKey);

            watcher.Stop();
            Logger.Info($"GetAnswerPacketAsync GetGrade times {watcher.ElapsedMilliseconds}");
            bigBrand._time += 1;
            watcher.Restart();
            var pageIndex = bigBrand.GetRandomPageckagePKID();

            watcher.Stop();
            Logger.Info($"GetAnswerPacketAsync GetRandomPageckagePKID times {watcher.ElapsedMilliseconds}");
            if (pageIndex <= 0)
            {
                result.Code = 0;
                result.Msg  = "对不起,您来晚了";
                return(OperationResult.FromResult(result));
            }
            watcher.Restart();
            var response = await bigBrand.CreatePageage(pageIndex);

            watcher.Stop();
            Logger.Info($"GetAnswerPacketAsync CreatePageage times {watcher.ElapsedMilliseconds}");
            if (!response.Success)
            {
                return(OperationResult.FromError <BigBrandResponse>(response.ErrorCode, response.ErrorMessage));
            }
            var page = response.Result;

            watcher.Restart();
            await bigBrand.AddPackageLog(page.PKID, page.PromotionCodePKIDs);

            watcher.Stop();
            Logger.Info($"GetAnswerPacketAsync AddPackageLog times {watcher.ElapsedMilliseconds}");
            bigBrand._time        -= 1;
            result.Code            = 1;
            result.PromptImg       = page.PromptImg;
            result.PromptMsg       = page.PromptMsg.Replace("{{allquestion}}", bigBrand?.entity?.AnsQuesConfig?.TipCount.ToString()).Replace("{{rightanswer}}", bigBrand?._time.ToString());
            result.PromptType      = page.PromptType;
            result.RedirectAPP     = page.RedirectAPP;
            result.RedirectBtnText = page.RedirectBtnText;
            result.RedirectH5      = page.RedirectH5;
            result.RedirectWXAPP   = page.RedirectWXAPP;
            result.RedirectHuaWei  = page.RedirectHuaWei;
            result.WxAppId         = page.WxAppId;
            result.RewardType      = page.RewardType;
            result.IsShare         = bigBrand.IsShare;
            result.TimeCount       = bigBrand.TimeCount;
            result.ShareTimes      = bigBrand.ShareTimes;
            result.Time            = bigBrand._time;
            result.RealTip         = bigBrand?.RealTip;
            if (GlobalConstant.HashKey_VehicleTypeCertificationRights.Contains(hashKey))
            {
                result.DefaultPool     = bigBrand.DefaultPool;
                result.CouponRuleItems = await bigBrand.GetCouponRuleItems(page.PKID, DateTime.Now);
            }
            produceer?.Send("notification.TaskActionQueue", new
            {
                UserId     = userId,
                ActionName = "2LuckyMoney",
                HashKey    = hashKey
            });
            return(OperationResult.FromResult(result));
        }
        /// <summary>
        /// 获取抽奖结果
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="deviceId"></param>
        /// <param name="Channal"></param>
        /// <param name="hashKey"></param>
        /// <param name="phone"></param>
        /// <param name="refer"></param>
        /// <param name="openId"></param>
        /// <returns></returns>
        public async Task <OperationResult <BigBrandResponse> > GetPacketAsync(Guid userId, string deviceId, string Channal, string hashKey, string phone, string refer, string openId = default(string))
        {
            if (string.IsNullOrWhiteSpace(hashKey))
            {
                return(OperationResult.FromResult(new BigBrandResponse()
                {
                    Code = -1, Msg = "抽奖活动不存在"
                }));
            }
            Regex regex = new Regex("^([0-9]|[a-z]|[A-Z]){7}([0-9]|[a-z]|[A-Z])$");

            if (!regex.IsMatch(hashKey))
            {
                return(OperationResult.FromResult(new BigBrandResponse()
                {
                    Code = -1, Msg = "抽奖活动hashkey不匹配"
                }));
            }

            if (userId == Guid.Empty && string.IsNullOrEmpty(openId))
            {
                return(OperationResult.FromResult(new BigBrandResponse()
                {
                    Code = -1, Msg = "用户UserId和OpenId不能都为空"
                }));
            }
            BigBrandResponse result = new BigBrandResponse();

            System.Diagnostics.Stopwatch watcher = new System.Diagnostics.Stopwatch();
            watcher.Start();
            BigBrandLogic bigBrand = new BigBrandLogic(hashKey, userId, phone, deviceId, Channal, openId);

            watcher.Stop();
            Logger.Info($"GetPacketAsync new BigBrandLogic times:{watcher.ElapsedMilliseconds}");
            bigBrand.Refer = refer;
            watcher.Restart();
            var isResult = await bigBrand.IsSelectCanPackage();

            watcher.Stop();
            Logger.Info($"GetPacketAsync IsSelectCanPackage times:{watcher.ElapsedMilliseconds}");
            if (!isResult.Result)
            {
                result.Code = 0;
                if (!string.IsNullOrEmpty(isResult.ErrorMessage))
                {
                    result.Code = int.Parse(isResult.ErrorCode);
                    result.Msg  = isResult.ErrorMessage;
                }
                else if (bigBrand.entity.BigBrandType == 2)
                {
                    result.Msg = "您的积分不足,无法抽奖哦";
                }
                else if (bigBrand.entity.BigBrandType == 3)
                {
                    result.Msg = "抱歉,只有指定用户才能参加此抽奖哦";
                }
                else
                {
                    result.Msg = "抽奖次数不足";
                }

                return(OperationResult.FromResult(result));
            }
            watcher.Restart();
            var pageIndex = bigBrand.GetRandomPageckagePKID();

            watcher.Stop();
            Logger.Info($"GetPacketAsync GetRandomPageckagePKID times:{watcher.ElapsedMilliseconds}");
            if (pageIndex <= 0)
            {
                result.Code = 0;
                result.Msg  = "对不起,您来晚了";
                return(OperationResult.FromResult(result));
            }
            watcher.Restart();
            var response = await bigBrand.CreatePageage(pageIndex);

            watcher.Stop();
            Logger.Info($"GetPacketAsync CreatePageage times:{watcher.ElapsedMilliseconds}");
            if (!response.Success)
            {
                return(OperationResult.FromResult(new BigBrandResponse()
                {
                    Code = -1, Msg = response.ErrorMessage
                }));
            }
            var page = response.Result;

            watcher.Restart();
            await bigBrand.AddPackageLog(page.PKID, page.PromotionCodePKIDs);

            watcher.Stop();
            Logger.Info($"GetPacketAsync AddPackageLog times:{watcher.ElapsedMilliseconds}");
            result.Code            = 1;
            result.PromptImg       = page.PromptImg;
            result.PromptMsg       = page.PromptMsg;
            result.PromptType      = page.PromptType;
            result.RedirectAPP     = page.RedirectAPP;
            result.RedirectBtnText = page.RedirectBtnText;
            result.RedirectH5      = page.RedirectH5;
            result.RedirectWXAPP   = page.RedirectWXAPP;
            result.RedirectHuaWei  = page.RedirectHuaWei;
            result.WxAppId         = page.WxAppId;
            result.RewardType      = page.RewardType;
            result.IsShare         = bigBrand.IsShare;
            result.TimeCount       = bigBrand.TimeCount;
            result.ShareTimes      = bigBrand.ShareTimes;
            result.Time            = bigBrand._time;
            result.RealTip         = bigBrand?.RealTip;
            try
            {
                var couponRulesItems = await bigBrand.GetCouponRuleItems(page.PKID, DateTime.Now);

                result.CouponRules = couponRulesItems?.ToList() ?? new List <CouponRule>();
                if (GlobalConstant.HashKey_VehicleTypeCertificationRights.Contains(hashKey))
                {
                    result.DefaultPool     = bigBrand.DefaultPool;
                    result.CouponRuleItems = couponRulesItems;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            produceer?.Send("notification.TaskActionQueue", new
            {
                UserId     = userId,
                ActionName = "2LuckyMoney",
                HashKey    = hashKey
            });
            return(OperationResult.FromResult(result));
        }