/// <summary> /// 更新实物奖励地址 /// </summary> /// <param name="address"></param> /// <param name="tip"></param> /// <returns></returns> public async Task <bool> UpdateBigBrandRealLog(string address, Guid tip, string userName, string phone) { if (string.IsNullOrWhiteSpace(address)) { return(false); } return(await DalBigBrand.UpdateBigBrandRealLog(address, this.UserId, tip, userName, phone)); }
public async Task <List <BigBrandPackerModel> > GetSelectLoge() { using (var client = CacheHelper.CreateCacheClient("BigBrandLogic")) { var result = await client.GetOrSetAsync($"SelectPackage{this.entity.HashKeyValue}", () => DalBigBrand.GetSelectPackageDataTable(this.entity.PKID), TimeSpan.FromMinutes(5)); return(result.Value); } }
/// <summary> /// 添加分享日志 /// </summary> /// <returns></returns> public async Task <bool> AddShareLogWithChanceType(int chanceType = 2) { var listLoger = await GetBigBrandLogListByUserIdCache(this.entity.PKID, this.entity.PeriodType, this.UserId, this.UnionId); if (listLoger?.Where(_ => _.ChanceType == chanceType)?.Count() == 0) { for (int i = 0; i < this.entity.CompletedTimes; i++) { var model = new BigBrandRewardLogModel() { ChanceType = chanceType, Channel = this.Channel, CreateDateTime = DateTime.Now, DeviceSerialNumber = this.DeviceId, FKPKID = 0, Phone = this.Phone, Refer = this.Refer, Status = true, UserId = this.UserId, UnionId = this.UnionId, FKBigBrandPkid = this.entity.PKID }; await DalBigBrand.AddBigBrandLog(model); string key = BigBrandLogByUser + this.entity.PKID.ToString() + this.entity.PeriodType.ToString() + this.StartDateTime.ToString("yyyyMMddHHmmss") + this.EndDateTime.ToString("yyyyMMddHHmmss"); using (var client = CacheHelper.CreateCacheClient(key)) { listLoger.Add(model); if (this.UserId != Guid.Empty) { await client.SetAsync(this.UserId.ToString(), listLoger, TimeSpan.FromDays(30)); } else if (!string.IsNullOrEmpty(this.UnionId)) { await client.SetAsync(this.UnionId, listLoger, TimeSpan.FromDays(30)); } } } // DistributedCache.Upsert("BigBrandShareCount", this.ShareCount + 1); // 这个计数查出来 暂时没有用到 ,而且是慢查询,暂时注释掉 俊桥说是一个功能做了一半结果没有做了,之后可以用计数器来实现 //using (var redisClient = Tuhu.Nosql.CacheHelper.CreateCacheClient("BigBrandLogic")) //{ // var result = await redisClient.SetAsync("BigBrandShareCount",DalBigBrand.GetBigBrandShareCount(entity.PKID));//增加分享次数 //} return(true); } else { return(false); } }
/// <summary> /// 获取本抽奖中用户的领取以及分享记录 /// </summary> /// <param name="fkBigBrandPkid"></param> /// <param name="period"></param> /// <param name="periodType"></param> /// <param name="userId"></param> /// <returns></returns> private async Task <List <BigBrandRewardLogModel> > GetBigBrandLogListByUserIdCache(int fkBigBrandPkid, int periodType, Guid userId, string unionId) { List <BigBrandRewardLogModel> response = new List <BigBrandRewardLogModel>(); using (var client = CacheHelper.CreateCacheClient(BigBrandLogByUser + fkBigBrandPkid.ToString() + periodType + this.StartDateTime.ToString("yyyyMMddHHmmss") + this.EndDateTime.ToString("yyyyMMddHHmmss"))) { if (userId != Guid.Empty) { watcher.Restart(); var result = await client.GetOrSetAsync <List <BigBrandRewardLogModel> >(userId.ToString(), async() => await DalBigBrand.GetBigBrandLogListByUserId(fkBigBrandPkid, this.StartDateTime, this.EndDateTime, userId, unionId), TimeSpan.FromDays(30)); if (result.Success) { response = result?.Value; } watcher.Stop(); Logger.Info($"BigBrandLogic GetBigBrandLogListByUserIdCache GetCountFromRedisByUserId times:{watcher.ElapsedMilliseconds}"); } else if (!string.IsNullOrEmpty(unionId)) { watcher.Restart(); var result = await client.GetOrSetAsync <List <BigBrandRewardLogModel> >(unionId, async() => await DalBigBrand.GetBigBrandLogListByUserId(fkBigBrandPkid, this.StartDateTime, this.EndDateTime, userId, unionId), TimeSpan.FromDays(30)); if (result.Success) { response = result?.Value; } watcher.Stop(); Logger.Info($"BigBrandLogic GetBigBrandLogListByUserIdCache GetCountFromRedisByUnionId times:{watcher.ElapsedMilliseconds}"); } if (response == null || response?.Count <= 0) { watcher.Restart(); response = await DalBigBrand.GetBigBrandLogListByUserId(fkBigBrandPkid, this.StartDateTime, this.EndDateTime, userId, unionId); watcher.Stop(); Logger.Info($"BigBrandLogic GetBigBrandLogListByUserIdCache GetCountFromDatabase times:{watcher.ElapsedMilliseconds}"); } } return(response); }
private static async Task <BigBrandRewardListModel> GetEntity(string keyValue) { if (string.IsNullOrWhiteSpace(keyValue)) { return(null); } Regex regex = new Regex("^([0-9]|[a-z]|[A-Z]){7}([0-9]|[a-z]|[A-Z])$"); if (!regex.IsMatch(keyValue)) { return(null); } var listEntity = await DalBigBrand.GetBigBrandRewardListModel(keyValue); var styleEntity = DalBigBrand.GetBigBrandPageStyleList(listEntity.PKID); var timeEntity = DalBigBrand.GetBigBrandWheelList(listEntity.PKID); var poolEntity = DalBigBrand.GetBigBrandRewardPoolList(listEntity.PKID); var ansquesEntity = DalBigBrand.GetAnsQuesEntity(listEntity.PKID); var pageConfigEntity = DalBigBrand.GetBigBrandPageConfigModel(listEntity.PKID, 0); await Task.WhenAll(styleEntity, timeEntity, poolEntity, ansquesEntity); listEntity.ItemStyles = styleEntity.Result; listEntity.ItemTimes = timeEntity.Result; listEntity.AnsQuesConfig = ansquesEntity.Result; listEntity.PageConfig = pageConfigEntity.Result; var poolList = new List <BigBrandRewardPoolModel>(); var items = poolEntity?.Result; if (items != null) { foreach (var parent in items?.Where(_ => _.ParentPKID == null && _.Status == true)) { var entity = parent; var part = items.Where(_ => _.ParentPKID == entity.PKID && _.Status == true)?.ToList(); part.ForEach(_ => { _.PartItem = items?.Where(o => o.ParentPKID == _.PKID && o.Status == true)?.ToList(); }); entity.PartItem = part; poolList.Add(entity); } } listEntity.ItemPools = poolList; return(listEntity); }
public async Task <bool> AddShareLog(int times, int chanceType = 2) { var isExist = DalBigBrand.IsExistShareLog(this.UserId, this.entity.HashKeyValue, this.Channel); if (isExist) { return(false); } for (int i = 0; i < times; i++) { var model = new BigBrandRewardLogModel() { ChanceType = chanceType, Channel = this.Channel, CreateDateTime = DateTime.Now, DeviceSerialNumber = this.DeviceId, FKPKID = 0, Phone = this.Phone, Refer = this.Refer, Status = true, UserId = this.UserId, UnionId = this.UnionId, FKBigBrandPkid = this.entity.PKID }; await DalBigBrand.AddBigBrandLog(model); string key = BigBrandLogByUser + this.entity.PKID.ToString() + this.entity.PeriodType.ToString() + this.StartDateTime.ToString("yyyyMMddHHmmss") + this.EndDateTime.ToString("yyyyMMddHHmmss"); using (var client = CacheHelper.CreateCacheClient(key)) { if (this.UserId != Guid.Empty) { await client.RemoveAsync(this.UserId.ToString()); } else if (!string.IsNullOrEmpty(this.UnionId)) { await client.RemoveAsync(this.UnionId); } } } return(true); }
public async Task <bool> AddPackageLog(int fkpkid, string promotionCodePKIDs) { var model = new BigBrandRewardLogModel() { ChanceType = 1, Channel = this.Channel, CreateDateTime = DateTime.Now, DeviceSerialNumber = this.DeviceId, FKPKID = fkpkid, Phone = this.Phone, Refer = this.Refer, Status = true, UserId = this.UserId, UnionId = this.UnionId, FKBigBrandPkid = this.entity.PKID, PromotionCodePKIDs = promotionCodePKIDs }; var result = await DalBigBrand.AddBigBrandLog(model); if (result) { string key = BigBrandCountLogKey + this.entity.PKID + this.StartDateTime.ToString("yyyyMMddHHmmss") + this.EndDateTime.ToString("yyyyMMddHHmmss"); using (var counter = CacheHelper.CreateCounterClient(key, TimeSpan.FromDays(30))) { counter.Increment(fkpkid.ToString()); } string keyCache = BigBrandLogByUser + this.entity.PKID.ToString() + this.entity.PeriodType.ToString() + this.StartDateTime.ToString("yyyyMMddHHmmss") + this.EndDateTime.ToString("yyyyMMddHHmmss"); using (var client = CacheHelper.CreateCacheClient(keyCache)) { if (this.UserId != Guid.Empty) { await client.RemoveAsync(this.UserId.ToString()); } else if (!string.IsNullOrEmpty(this.UnionId)) { await client.RemoveAsync(this.UnionId); } } } return(result); }
private async Task <OperationResult <bool> > CreatePackageInfo(BigBrandRewardPoolModel page) { List <BigBrandRealLogModel> realList = new List <BigBrandRealLogModel>(); Guid tip = Guid.NewGuid(); if (page.PartItem == null) { throw new Exception("奖励礼包为空"); } foreach (var info in page.PartItem) { if (page.RewardType == 1) { //发放优惠券 if (this.UserId != Guid.Empty) { using (var client = new Tuhu.Service.Member.PromotionClient()) { var result = await client.CreatePromotionNewAsync(new CreatePromotionModel() { Author = this.UserId.ToString(), GetRuleGUID = Guid.Parse(info.CouponGuid), UserID = this.UserId, Channel = this.Channel + "大翻盘", DeviceID = this.DeviceId, Operation = "大翻盘抽奖", Referer = this.Refer, IssueChannle = "幸运大翻牌", IssueChannleId = this.entity.HashKeyValue, Issuer = string.IsNullOrWhiteSpace(this.entity.UpdateUserName) == true ? this.entity.CreateUserName : this.entity.UpdateUserName }); result.ThrowIfException(true); if (result.Result.IsSuccess) { page.PromotionCodePKIDs += result.Result?.PromotionId.ToString() + ","; } else { return(OperationResult.FromError <bool>(result.Result.ErrorCode.ToString(), result.Result.ErrorMessage)); } } } else if (!string.IsNullOrEmpty(this.UnionId)) //如果用户id为空,根据unionid发券 { using (var client = new Tuhu.Service.Member.ThirdPartyPromotionClient()) { var result = await client.InsertUserCardInfoAsync(new UserCardInfo() { Channel = this.Channel + "大翻盘", CreatedTime = DateTime.Now, DeviceID = this.DeviceId, EventTime = DateTime.Now, GetRuleId = Guid.Parse(info.CouponGuid), IssueChannle = "幸运大翻盘", UnionId = this.UnionId, OpenId = this.OpenId, IssueChannleId = this.entity.HashKeyValue, Issuer = string.IsNullOrWhiteSpace(this.entity.UpdateUserName) == true ? this.entity.CreateUserName : this.entity.UpdateUserName, UpdatedTime = DateTime.Now }); if (!result.Success) { return(OperationResult.FromError <bool>(result.ErrorCode.ToString(), result.ErrorMessage)); } } } } else if (page.RewardType == 2) { //积分抽奖 using (var client = new Tuhu.Service.Member.UserIntegralClient()) { ///规则guid var integralRuleId = new Guid("04E70162-9588-4329-BCED-E149E22D7DCE"); Service.Member.Models.UserIntegralDetailModel integralDetailModel = new Service.Member.Models.UserIntegralDetailModel(); integralDetailModel.TransactionIntegral = info.Integral.Value; integralDetailModel.TransactionChannel = "H5"; integralDetailModel.Versions = "1.0.0"; integralDetailModel.TransactionRemark = "大翻盘积分抽奖"; integralDetailModel.IntegralRuleID = integralRuleId; var result = await client.UserIntegralChangeByUserIDAsync(this.UserId, integralDetailModel, null, 0); result.ThrowIfException(true); } } else if (page.RewardType == 4) { this.RealTip = tip; BigBrandRealLogModel real = new BigBrandRealLogModel() { CreateDateTime = DateTime.Now, FKBigBrandID = this.entity.PKID, FKBigBrandPoolID = page.PKID, Prize = info.RealProductName, Tip = tip, UserId = this.UserId, LastUpdateDateTime = DateTime.Now }; realList.Add(real); } else if (page.RewardType == 5)//抽中的是微信红包,给用户发微信红包 { //using (var client = new Pay.PayClient()) //{ // var sendResponse = await client.Wx_SendRedBagAsync(new Pay.Models.WxSendRedBagRequest() // { // OpenId = this.OpenId, // Channel = this.Channel + "大翻盘", // ActName = "大翻盘抽奖", // Remark = this.entity.HashKeyValue, // Wishing = "新年大吉", // Money = (info.WxRedBagAmount ?? 0) * 100 // }); // sendResponse.ThrowIfException(true); //} //发红包改为发消息队列,从消息队列里慢慢发 TuhuNotification.SendNotification("notification.WxSendRedBag", new Pay.Models.WxSendRedBagRequest() { OpenId = this.OpenId, Channel = this.Channel + "大翻盘", ActName = "大翻盘抽奖", Remark = this.entity.HashKeyValue, Wishing = "新年大吉", Money = (info.WxRedBagAmount ?? 0) * 100 }); } else { //空奖 } } if (page.RewardType == 4) { //实物奖励 DalBigBrand.AddBigBrandRealLog(realList); } if (this.entity.BigBrandType == 1) { this.TimeCount -= 1; } if (this.entity.BigBrandType == 3) { this.TimeCount -= 1; await ActivityManager.UpdateLuckyWheelUserlotteryCountAsync(this.UserId, Guid.Empty, this.entity.HashKeyValue); } return(OperationResult.FromResult(true)); }
/// <summary> /// 获取最近领取礼包的信息 /// </summary> /// <param name="userId"></param> /// <param name="bigBrandPKID"></param> /// <returns></returns> public BigBrandRewardPoolModel GetRewardInfoLast(Guid userId) { return(DalBigBrand.GetRewardInfoLast(userId, this.entity.PKID)); }
/// <summary> /// 获取抽奖池内容 /// </summary> /// <returns></returns> private List <BigBrandPoolModel> CreatePool() { List <BigBrandPoolModel> list = new List <BigBrandPoolModel>(); //var dicResult = DalBigBrand.GetBigBrandLogList(entity.PKID, entity.Period.Value, entity.PeriodType); watcher.Restart(); var poolPKIDs = entity.ItemTimes?.Where(_ => _.TimeNumber == _time); if (poolPKIDs != null && poolPKIDs.Count() > 0) { entity.ItemPools = entity.ItemPools?.Where(_ => poolPKIDs.FirstOrDefault(o => o.FKPoolPKID == _.PKID) != null || _.IsDefault == true)?.ToList(); } watcher.Stop(); Logger.Info($"BigBrandLogic CreatePool StartFilter times:{watcher.ElapsedMilliseconds}"); string key = BigBrandCountLogKey + this.entity.PKID + this.StartDateTime.ToString("yyyyMMddHHmmss") + this.EndDateTime.ToString("yyyyMMddHHmmss"); using (var counter = CacheHelper.CreateCounterClient(key, TimeSpan.FromDays(30))) { Dictionary <int, int> noCacheDic = new Dictionary <int, int>(entity?.ItemPools?.Count() ?? 0); watcher.Restart(); foreach (var item in entity?.ItemPools?.Where(_ => _.IsDefault == false)) { foreach (var part in item?.PartItem) { int counterNumber = 0; var counterResult = counter.Count(part.PKID .ToString()); //RedisHelper.GetCounter(BigBrandCountLogKey +, part.PKID.ToString(), TimeSpan.FromDays(30), async () => await DalBigBrand.GetBigBrandLogList(entity.PKID, part.PKID, startDT, endDT)); if (counterResult.Value == 0 || !counterResult.Success) { noCacheDic[part.PKID] = part.Number ?? 0; //把数据库获取的改为批量获取,挪到循环外面去 //counterNumber = DalBigBrand.GetBigBrandLogList(entity.PKID, part.PKID, this.StartDateTime, this.EndDateTime); //counter.Increment(part.PKID.ToString(), counterNumber); } else { counterNumber = (int)counterResult.Value; var number = part.Number - counterNumber; if (number > 0) { list.Add(new BigBrandPoolModel() { Count = number.Value, PKID = part.PKID }); } } } } watcher.Stop(); Logger.Info($"BigBrandLogic CreatePool GetCountFromRedis times:{watcher.ElapsedMilliseconds}"); if (noCacheDic.Count > 0) { watcher.Restart(); var noCacheResult = DalBigBrand.GetBatchBigBrandLogList(entity.PKID, noCacheDic.Keys, this.StartDateTime, this.EndDateTime); foreach (var keyItem in noCacheDic.Keys) { var counterNumber = 0; noCacheResult.TryGetValue(keyItem, out counterNumber); if (counterNumber > 0) { counter.Increment(keyItem.ToString(), counterNumber); } var number = noCacheDic[keyItem] - counterNumber; if (number > 0) { list.Add(new BigBrandPoolModel() { Count = number, PKID = keyItem }); } } watcher.Stop(); Logger.Info($"BigBrandLogic CreatePool GetCountFromDatabase times:{watcher.ElapsedMilliseconds}"); } } return(list); }
/// <summary> /// 查询没有登记地址的实物奖励 /// </summary> /// <returns></returns> public async Task <IEnumerable <BigBrandRealLogModel> > IsNULLBigBrandRealByAddress() { return(await DalBigBrand.IsNULLBigBrandRealByAddress(this.UserId, this.entity.PKID)); }