/// <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="model"></param> /// <returns></returns> public async static Task <bool> AddBigBrandLog(BigBrandRewardLogModel model) { string sql = @"INSERT INTO SystemLog.dbo.BigBrandRewardLog ( CreateDateTime , LastUpdateDateTime , Refer , FKPKID , ChanceType , UserId , Phone , Status , Channel , DeviceSerialNumber , Remark,FKBigBrandPkid,PromotionCodePKIDs,UnionId ) VALUES ( GETDATE() , -- CreateDateTime - datetime GETDATE() , -- LastUpdateDateTime - datetime @Refer , -- Refer - varchar(3000) @FKPKID , -- FKPKID - int @ChanceType , -- ChanceType - int @UserId , -- UserId - uniqueidentifier @Phone , -- Phone - varchar(20) @Status , -- Status - bit @Channel , -- Channel - varchar(20) @DeviceSerialNumber , -- DeviceSerialNumber - varchar(100) @Remark, -- Remark - varchar(100) @FKBigBrandPkid,@PromotionCodePKIDs,@UnionId )"; using (var db = DbHelper.CreateDbHelper()) { SqlCommand cmd = new SqlCommand(sql); cmd.Parameters.AddWithValue("@Refer", model.Refer); cmd.Parameters.AddWithValue("@FKPKID", model.FKPKID); cmd.Parameters.AddWithValue("@ChanceType", model.ChanceType); cmd.Parameters.AddWithValue("@UserId", model.UserId); cmd.Parameters.AddWithValue("@Phone", model.Phone); cmd.Parameters.AddWithValue("@Status", model.Status); cmd.Parameters.AddWithValue("@Channel", model.Channel); cmd.Parameters.AddWithValue("@DeviceSerialNumber", model.DeviceSerialNumber); cmd.Parameters.AddWithValue("@Remark", model.Remark); cmd.Parameters.AddWithValue("@FKBigBrandPkid", model.FKBigBrandPkid); cmd.Parameters.AddWithValue("@PromotionCodePKIDs", model.PromotionCodePKIDs); cmd.Parameters.AddWithValue("@UnionId", model.UnionId); return(await db.ExecuteNonQueryAsync(cmd) > 0); } }
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); }