public async Task <OperationResult <BigBrandCanResponse> > SelectCanPackerAsync(Guid userId, string deviceId, string Channal, string hashKey, string phone, string refer, string openId = default(string)) { if (string.IsNullOrWhiteSpace(hashKey)) { return(OperationResult.FromResult(new BigBrandCanResponse() { Code = -1, Msg = "Hash不能为空" })); } 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 BigBrandCanResponse() { Code = -1, Msg = "Hash不匹配" })); } if (userId == Guid.Empty && string.IsNullOrEmpty(openId)) { return(OperationResult.FromResult(new BigBrandCanResponse() { Code = -1, Msg = "用户UserId和OpenId不能都为空" })); } BigBrandLogic bigBrand = new BigBrandLogic(hashKey, userId, phone, deviceId, Channal, openId); bigBrand.Refer = refer; var result = await bigBrand.IsSelectCanPackage(); if (GlobalConstant.HashKey_VehicleTypeCertificationRights.Contains(hashKey)) { bigBrand.GetRandomPageckagePKID(); } if (result.Result) { return(OperationResult.FromResult(new BigBrandCanResponse() { Code = 1, IsShare = bigBrand.IsShare, Item = string.Empty, Msg = "今天还有" + bigBrand.TimeCount + "次机会", Times = bigBrand.TimeCount, DefaultPool = bigBrand.DefaultPool, //只对 23338FF5 870F1F2E活动有效 ShareTimes = bigBrand.ShareTimes })); } else { if (!string.IsNullOrEmpty(result.ErrorMessage)) { return(OperationResult.FromError <BigBrandCanResponse>(result.ErrorCode, result.ErrorMessage)); } else { var model = new BigBrandCanResponse() { Code = 0, IsShare = bigBrand.IsShare, // Item = hashKey == "23338FF5" || hashKey == "870F1F2E" ? Newtonsoft.Json.JsonConvert.SerializeObject(bigBrand.GetRewardInfoLast(userId)) : "", Msg = "今天还有" + bigBrand.TimeCount ?? 0 + "次机会", Times = bigBrand.TimeCount, DefaultPool = bigBrand.DefaultPool, //只对 23338FF5 870F1F2E活动有效 ShareTimes = bigBrand.ShareTimes }; if (GlobalConstant.HashKey_VehicleTypeCertificationRights.Contains(hashKey)) { //bigBrand.PromotionCodes var package = bigBrand.GetRewardInfoLast(userId); model.Item = Newtonsoft.Json.JsonConvert.SerializeObject(package); if (package != null) { model.CouponRuleItems = await bigBrand.GetCouponRuleItems(package.PKID, package.DateTimeLog.Value); } if (package != null && bigBrand?.PromotionCodes?.Count() > 0) { using (var memberClient = new Tuhu.Service.Member.PromotionClient()) { var memberResult = await memberClient.FetchPromotionCodeByIDAsync(new Member.Request.FetchPromotionCodeRequest() { PKID = Convert.ToInt32(bigBrand.PromotionCodes[0]) }); if (memberResult.Success) { var couponRuleModel = model.CouponRuleItems?.FirstOrDefault(); couponRuleModel.CreateDateTime = Convert.ToDateTime(memberResult.Result.StartTime); couponRuleModel.ValiStartDate = Convert.ToDateTime(memberResult.Result.StartTime); couponRuleModel.ValiEndDate = Convert.ToDateTime(memberResult.Result.EndTime); couponRuleModel.Term = null; couponRuleModel.DateNumber = memberResult.Result.Status == 0 ? couponRuleModel.GetDateNumber() : -2; } } } } return(OperationResult.FromResult(model)); } } }
/// <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)); }