示例#1
0
        public async Task <RpsData <RpsAddWatch> > UploadAdInfo(ParamUserBase param)
        {
            _context.BuyGoodHistories.Add(new BuyGoodHistory()
            {
                CreateDate = DateTime.Now,
                MallId     = 0,
                Num        = _configHelper.Config.WatchAddReward,
                Type       = BuyTypeEnum.广告赠送,
                UserId     = param.Id
            });

            var userGoods = await _context.UserGoods.SingleAsync(x => x.UserId == param.Id && x.GoodsType == MallGoodsTypeEnum.金币);

            userGoods.Num += _configHelper.Config.WatchAddReward;
            var result = await _context.SaveChangesAsync() > 0;

            if (result)
            {
                return(RpsData <RpsAddWatch> .Ok(new RpsAddWatch()
                {
                    Num = _configHelper.Config.WatchAddReward, Type = MallGoodsTypeEnum.金币
                }));
            }
            else
            {
                return(RpsData <RpsAddWatch> .Error("看广告赠送金币失败"));
            }
        }
示例#2
0
        public async Task <RpsData <RpsInvited> > GetInvitedUsers(ParamUserBase param)
        {
            if (param.GameType == GameTypeEnum.小程序)
            {
                var rpsInvited = new RpsInvited();

                var invitedUsers = await _context.InviteHistories.AsNoTracking().Where(x => x.UserId == param.Id).Join(
                    _context.Users.AsNoTracking(),
                    x => x.InvitedUserId, y => y.Id, (x, y) => new InvitedUser()
                {
                    Id       = y.Id,
                    GameType = (int)y.GameType,
                    Icon     = y.Icon,
                    NickName = y.NickName,
                    OpenId   = y.OpenId,
                    HaveGet  = x.IsGet,
                    OpenType = (int)y.OpenType,
                    UnionId  = y.UnionId
                }).ToListAsync();

                rpsInvited.InvitedUsers = invitedUsers;

                rpsInvited.HaveGetInviteReward = await _context.BuyGoodHistories.AnyAsync(x =>
                                                                                          x.UserId == param.Id && x.HaveGet && x.Type == BuyTypeEnum.邀请好友达标赠送);

                rpsInvited.HaveAchiedved = invitedUsers.Count >= _configHelper.Config.LimitInviteReward;
                return(RpsData <RpsInvited> .Ok(rpsInvited));
            }
            return(RpsData <RpsInvited> .Error("无权操作"));
        }
示例#3
0
        public async Task <RpsData <IEnumerable <RewardDataDto> > > GetInvitedReward(ParamGetInviteReward param)
        {
            var result = new List <RewardDataDto>();

            if (param.GetAchieveReaward)
            {
                var haveGetAchieveReward =
                    await _context.BuyGoodHistories.AnyAsync(x => !x.HaveGet && x.UserId == param.Id && x.Type == BuyTypeEnum.广告赠送);

                if (haveGetAchieveReward)
                {
                    var acheveInviteReward = await _context.BuyGoodHistories.Where(x => !x.HaveGet && x.UserId == param.Id && x.Type == BuyTypeEnum.广告赠送).ToListAsync();

                    var userGoods = await _context.UserGoods.Where(x => x.UserId == param.Id).ToListAsync();

                    foreach (var item in acheveInviteReward)
                    {
                        userGoods.Single(x => x.GoodsType == (MallGoodsTypeEnum)item.MallId).Num += item.Num;
                        item.HaveGet = true;
                        result.Add(new RewardDataDto()
                        {
                            GoodsType = (MallGoodsTypeEnum)item.MallId,
                            Num       = item.Num,
                            Type      = item.MallId > 0 ? MallTypeEnum.道具商城 : MallTypeEnum.金币商城
                        });
                    }
                }
            }
            else
            {
                var inviteHis = await _context.InviteHistories.SingleAsync(x =>
                                                                           x.HaveReward && !x.IsGet && x.UserId == param.Id && x.InvitedUserId == param.InvitedUserId);

                inviteHis.IsGet = true;
                if (!string.IsNullOrEmpty(inviteHis.Data))
                {
                    var rewardDataDto = JsonConvert.DeserializeObject <RewardDataDto>(inviteHis.Data);

                    if (rewardDataDto != null)
                    {
                        var userGoods = await _context.UserGoods.SingleAsync(x => x.UserId == param.Id && x.GoodsType == rewardDataDto.GoodsType);

                        userGoods.Num += rewardDataDto.Num;

                        result.Add(rewardDataDto);
                    }
                }
            }

            var flag = await _context.SaveChangesAsync() > 0;

            if (flag)
            {
                return(RpsData <IEnumerable <RewardDataDto> > .Ok(result));
            }
            else
            {
                return(RpsData <IEnumerable <RewardDataDto> > .Error("获取邀请奖励失败"));
            }
        }
示例#4
0
        public async Task <RpsData <RpsMyGoldCoinInfo> > MyGoldCoinInfo(ParamUserGoldCoin param)
        {
            var userCoins = await _context.UserGoods.AsNoTracking()
                            .Where(x => x.UserId == param.Id && x.GoodsType == MallGoodsTypeEnum.金币).Select(x => x.Num)
                            .SingleAsync();

            RpsMyGoldCoinInfo myGoldInfo = new RpsMyGoldCoinInfo()
            {
                GoldCoins = userCoins
            };

            if (param.ShowBuyCoinLogs)
            {
                myGoldInfo.BuyCoinList = await _context.BuyGoodHistories.AsNoTracking()
                                         .Where(x => x.UserId == param.Id && x.Type == BuyTypeEnum.购买).Join(
                    _context.Malls.AsNoTracking().Where(y => y.MallType == MallTypeEnum.金币商城), x => x.MallId,
                    y => y.Id, (x, y) => new RpsBuyGood()
                {
                    Id   = x.Id,
                    Name = y.Name,
                    Num  = x.Num,
                    Type = y.Type
                }).ToListAsync();
            }

            return(RpsData <RpsMyGoldCoinInfo> .Ok(myGoldInfo));
        }
示例#5
0
        public async Task <RpsData <bool> > UseGoods(ParamUseGoods param)
        {
            var userGood =
                await _context.UserGoods.SingleAsync(x => x.UserId == param.Id && x.GoodsType == param.Type && x.GoodsType != MallGoodsTypeEnum.金币);

            if (userGood.Num > 0)
            {
                userGood.Num -= 1;
                _context.GoodsUseHistories.Add(new GoodsUseHistory()
                {
                    CreateDateTime = DateTime.Now,
                    GoodsType      = userGood.GoodsType,
                    Num            = 1,
                    UserId         = userGood.UserId
                });
                var result = await _context.SaveChangesAsync() > 0;

                if (result)
                {
                    return(RpsData <bool> .Ok(true));
                }
                else
                {
                    return(RpsData <bool> .Error("保存出错"));
                }
            }
            return(RpsData <bool> .Error("数量不足,请先购买"));
        }
示例#6
0
        public async Task <RpsData <bool> > UploadGameScore(ParamUserScore param)
        {
            var entity = await _context.UserScores.AnyAsync(x => x.UserId == param.Id && x.Gate == param.Gate)
                ? await _context.UserScores.SingleAsync(x => x.UserId == param.Id && x.Gate == param.Gate)
                : _context.UserScores.Attach(new UserScore()
            {
                CreateDate = DateTime.Now,
                UserId     = param.Id,
                Gate       = param.Gate,
                Status     = ScoreStatusEnum.未通关,
                Score      = param.Score
            }).Entity;

            var gameGate = await _context.GameGates.SingleAsync(x => x.Gate == param.Gate);

            if (param.Score > entity.Score)
            {
                entity.Score = param.Score;
            }
            if (entity.Score >= gameGate.PassScore)
            {
                entity.Status = ScoreStatusEnum.通关;
            }


            await _context.SaveChangesAsync();

            return(RpsData <bool> .Ok(true));
        }
示例#7
0
        /// <summary>
        /// 购买金币
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        private async Task <RpsData <RpsBuyGood> > BuyJbGoods(ParamBuyGoods param)
        {
            var userPay = _context.UserPayHistories.Add(new UserPayHistory()
            {
                CreateTime = DateTime.Now,
                MallId     = param.MallId,
                Name       = param.Name,
                Price      = param.Price,
                Status     = (int)PayStatusEnum.正在处理,
                UserId     = param.Id
            });
            await _context.SaveChangesAsync();

            userPay.Entity.Status = (int)PayStatusEnum.已处理;
            userPay.Property(x => x.Status).IsModified = true;
            var mall = await _context.Malls.AsNoTracking().SingleAsync(x => x.Id == param.MallId);

            var userGoods = await _context.UserGoods
                            .SingleAsync(x => x.UserId == param.Id && x.GoodsType == MallGoodsTypeEnum.金币);

            if (mall.LimitedNum != 0)
            {
                var countHis = await _context.BuyGoodHistories
                               .WhereIf(mall.LimitedPeriod > 1, x => x.CreateDate.Date >= DateTime.Today.AddDays(1 - mall.LimitedPeriod))
                               .WhereIf(mall.LimitedPeriod == 1, x => x.CreateDate.Date >= DateTime.Today)
                               .CountAsync(x => x.UserId == param.Id);

                if (mall.LimitedNum <= countHis)
                {
                    return(RpsData <RpsBuyGood> .Error("超过每日限购次数", 2));
                }
            }

            userGoods.Num += mall.Num + mall.RewardNum;

            var buyEntity = _context.BuyGoodHistories.Add(new BuyGoodHistory()
            {
                MallId     = param.MallId,
                CreateDate = DateTime.Now,
                Num        = userGoods.Num,
                Type       = BuyTypeEnum.购买,
                UserId     = param.Id
            }).Entity;
            bool result = await _context.SaveChangesAsync() > 0;

            if (result)
            {
                return(RpsData <RpsBuyGood> .Ok(new RpsBuyGood()
                {
                    Id = buyEntity.Id,
                    Name = mall.Name,
                    Num = userGoods.Num,
                    Type = mall.Type
                }));
            }
            else
            {
                return(RpsData <RpsBuyGood> .Error("购买失败"));
            }
        }
示例#8
0
        public async Task <RpsData <int[]> > GetUserPassGates(ParamUserBase param)
        {
            var result = await _context.UserScores.AsNoTracking().Where(x => x.UserId == param.Id && x.Status == ScoreStatusEnum.通关)
                         .Select(x => x.Gate)
                         .ToArrayAsync();

            return(RpsData <int[]> .Ok(result));
        }
示例#9
0
        public async Task <RpsData <RpsUser> > GetUserInfo(ParamUserInfo param)
        {
            var entity = param.Id > 0 ? await _context.Users.SingleAsync(x => x.Id == param.Id) :
                         await _context.Users.SingleAsync(x =>
                                                          x.OpenId == param.OpenId &&
                                                          x.GameType == param.GameType &&
                                                          x.OpenType == param.OpenType);

            return(RpsData <RpsUser> .Ok(entity.MapTo <RpsUser>()));
        }
示例#10
0
        public async Task <RpsData <IEnumerable <RpsPoster> > > GetUserPoster(ParamUserBase param)
        {
            var parameters = new List <object>();

            parameters.Add(new SqlParameter("@UserId", param.Id));
            var result = await _context.SqlQueryAsync <RpsPoster>(@"SELECT  g.[Icon] ,p.[Gate], Count(p.[Gate]) as Count,
	                                                  (select count(Id) from [dbo].[Game_Posters] gp where gp.GateId=p.Gate and gp.UserId=@UserId) as GetCount
                                                  FROM [Game2048].[dbo].[Game_PosterGallery]  p
                                                  inner join [dbo].[Game_Gate] g on g.Gate=p.[Gate] group by g.[Icon],p.[Gate]", parameters);

            return(RpsData <IEnumerable <RpsPoster> > .Ok(result));
        }
示例#11
0
 public RpsData <string> GetInviteCode(ParamUserBase param)
 {
     if (param.GameType == GameTypeEnum.小程序)
     {
         InviteUserDto inviteUserDto = new InviteUserDto();
         inviteUserDto.UserId       = param.Id;
         inviteUserDto.DateTimeTick = DateTime.Now.Ticks;
         var str    = JsonConvert.SerializeObject(inviteUserDto);
         var result = SecurityHelper.EncryptAES(str, _configHelper.Config.WXCEncryptionKey);
         return(RpsData <string> .Ok(result));
     }
     return(RpsData <string> .Error("无权获取"));
 }
示例#12
0
        /// <summary>
        /// 购买道具
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        private async Task <RpsData <RpsBuyGood> > BuyDjGoods(ParamBuyGoods param)
        {
            var mall = await _context.Malls.AsNoTracking().SingleAsync(x => x.Id == param.MallId);

            var userGoods = await _context.UserGoods.AnyAsync(x => x.UserId == param.Id && x.GoodsType == mall.Type) ?
                            await _context.UserGoods
                            .SingleAsync(x => x.UserId == param.Id && x.GoodsType == mall.Type) :
                            _context.UserGoods.Add(new UserGood()
            {
                GoodsType = mall.Type, Num = 0, UserId = param.Id
            }).Entity;

            var userJB = await _context.UserGoods.AnyAsync(x => x.UserId == param.Id && x.GoodsType == MallGoodsTypeEnum.金币) ?
                         await _context.UserGoods.SingleAsync(x => x.UserId == param.Id && x.GoodsType == MallGoodsTypeEnum.金币)
                : _context.UserGoods.Add(new UserGood()
            {
                GoodsType = MallGoodsTypeEnum.金币, Num = 0, UserId = param.Id
            }).Entity;

            if (userJB.Num < mall.Price)
            {
                return(RpsData <RpsBuyGood> .Error("金币不够,请充值"));
            }

            userGoods.Num += mall.Num + mall.RewardNum;
            userJB.Num    -= mall.Price;
            var buyEntity = _context.BuyGoodHistories.Add(new BuyGoodHistory()
            {
                MallId     = param.MallId,
                Type       = BuyTypeEnum.购买,
                CreateDate = DateTime.Now,
                Num        = userGoods.Num,
                UserId     = param.Id
            }).Entity;
            bool result = await _context.SaveChangesAsync() > 0;

            if (result)
            {
                return(RpsData <RpsBuyGood> .Ok(new RpsBuyGood()
                {
                    Id = buyEntity.Id,
                    Name = mall.Name,
                    Num = userGoods.Num,
                    Type = mall.Type
                }));
            }
            else
            {
                return(RpsData <RpsBuyGood> .Error("购买失败"));
            }
        }
示例#13
0
        public async Task <RpsData <IEnumerable <RpsPosterDetail> > > GetUserPosterDetail(ParamUserPosterDetail param)
        {
            var result = await _context.PosterGalleries.AsNoTracking().Where(x => x.Gate == param.Gate).GroupJoin(
                _context.Posters.AsNoTracking().Where(x => x.UserId == param.Id), x => x.Id, y => y.PosterId, (x, y) =>
                new RpsPosterDetail()
            {
                Icon     = x.Icon,
                HaveIt   = y.Any(),
                Name     = x.Name,
                PosterId = x.Id
            }).ToListAsync();

            return(RpsData <IEnumerable <RpsPosterDetail> > .Ok(result));
        }
示例#14
0
        public async Task <RpsData <IEnumerable <RpsUserGood> > > GetUserGoods(ParamUserBase param)
        {
            var result = await _context.UserGoods.AsNoTracking().Where(x => x.UserId == param.Id)
                         .GroupJoin(_context.Malls.AsNoTracking().Where(x => x.Type != 0), x => x.GoodsType, y => y.Type, (x, y) => new RpsUserGood()
            {
                Id         = x.Id,
                GoodsType  = x.GoodsType,
                MallDetail = y.Select(z => new MallDetailDto()
                {
                    Name = z.Name, Price = z.Price, Type = z.Type
                }).FirstOrDefault(),
                Num = x.Num
            }).ToListAsync();

            return(RpsData <IEnumerable <RpsUserGood> > .Ok(result));
        }
示例#15
0
        public async Task <RpsData <IEnumerable <RpsSignList> > > GetSignList(ParamUserBase param)
        {
            var parampters = new List <object>();

            parampters.Add(new SqlParameter("@UserId", param.Id));
            IEnumerable <RpsSignList> result = await _context.SqlQueryAsync <RpsSignList>(@"
                 select b.Id SignHisId,b.IsGet IsGet,b.CreateDate as CreateDate,ROW_NUMBER() over(order by b.CreateDate) as Day  from [dbo].[Game_UserLoginInfo] a  
                               inner join 
                               [dbo].[Game_SignInHistory] b 
                               on a.UserId=b.UserId
                         where a.UserId=@UserId 
                        and a.SignInContinuousDays!=0 
                        and DATEDIFF(day,a.LatetestSignInDate,GETDATE())<=1
                        and b.CreateDate>DATEADD(day,-a.SignInContinuousDays,a.LatetestSignInDate)", parampters);

            return(RpsData <IEnumerable <RpsSignList> > .Ok(result));
        }
示例#16
0
        /// <summary>
        /// 预计特价商品不会太多,所以采用的子查询
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task <RpsData <IEnumerable <RpsMallDetail> > > GetMallDetails(ParamMallDetails param)
        {
            var result = await _context.Malls.AsNoTracking()
                         .WhereIf(param.Mode == 1, x => x.MallType == MallTypeEnum.道具商城)
                         .WhereIf(param.Mode == 2, x => x.MallType == MallTypeEnum.金币商城)
                         .Select(x =>

                                 new RpsMallDetail()
            {
                Id            = x.Id,
                Type          = x.Type,
                MallType      = x.MallType,
                Num           = x.Num,
                Name          = x.Name,
                RewardNum     = x.RewardNum,
                LimitedTime   = x.LimitedNum,
                LimitedPeriod = x.LimitedPeriod,
                Price         = x.Price,
                Descroption   = x.Description,
                Icon          = x.Icon
            }
                                 ).ToListAsync();

            var specialResult = result.Where(x => x.LimitedTime != 0);

            foreach (var item in specialResult)
            {
                var countHis = await _context.BuyGoodHistories
                               .WhereIf(item.LimitedPeriod > 1, x => x.CreateDate.Date >= DateTime.Today.AddDays(1 - item.LimitedPeriod))
                               .WhereIf(item.LimitedPeriod == 1, x => x.CreateDate.Date >= DateTime.Today)
                               .CountAsync(x => x.UserId == param.Id);

                if (countHis >= item.LimitedTime)
                {
                    item.CanBuy = false;
                }
            }



            return(RpsData <IEnumerable <RpsMallDetail> > .Ok(result));
        }
示例#17
0
        public async Task <RpsData <RpsRankingList> > GetRankingList(ParamRankingList param)
        {
            var parameters = new List <object>();

            parameters.Add(new SqlParameter("@UserId", param.Id));
            parameters.Add(new SqlParameter("@Gate", param.Gate));
            parameters.Add(new SqlParameter("@GameType", param.GameType));
            parameters.Add(new SqlParameter("@Take", param.Num));
            var rankinglist = await _context.SqlQueryAsync <BaseRanking>(@"select *from 
                                            (
                                            select u.Icon, u.NickName as Name,s.Score,
                                            ROW_NUMBER() OVER(order by s.Score desc) as Number 
                                            from  [dbo].[Game_UserTB] u
                                            inner join [dbo].[Game_UserScore] s on u.Id=s.UserId
                                            where u.GameType=@GameType and u.Status=0 and s.Gate=@Gate
                                             )
                                            temp where temp.Number<=@Take", parameters);

            var myrankinglist = await _context.SqlQueryAsync <BaseRanking>(@"select *from 
                                            (
                                            select u.Icon, u.NickName as Name,s.Score,u.Id,
                                            ROW_NUMBER() OVER(order by s.Score desc) as Number 
                                            from  [dbo].[Game_UserTB] u
                                            inner join [dbo].[Game_UserScore] s on u.Id=s.UserId
                                            where u.GameType=@GameType and u.Status=0 and s.Gate=@Gate
                                             )
                                            temp where temp.Id<=@UserId", parameters);


            var result = new RpsRankingList()
            {
                MyRanking = myrankinglist.FirstOrDefault(),
                OtherList = rankinglist
            };

            return(RpsData <RpsRankingList> .Ok(result));
        }
示例#18
0
        public async Task <RpsData <RpsUser> > AddOrUpdate(ParamUserInfo param)
        {
            var existEntity = param.Id > 0 ? await _context.Users.FirstOrDefaultAsync(x => x.Id == param.Id)
                : await _context.Users.FirstOrDefaultAsync(x =>
                                                           x.OpenId == param.OpenId &&
                                                           x.GameType == param.GameType &&
                                                           x.OpenType == param.OpenType);

            var entity = existEntity != null
                ? _context.Users.Attach(existEntity).Entity
                : _context.Users.Attach(new User()).Entity;


            //App段不提示用户登录直接默认一个用户,用户可以更改重新刷新信息
            if (param.OpenType == OpenTypeEnum.系统默认 && existEntity == null)
            {
                entity.OpenId   = Guid.NewGuid().ToString("N");
                entity.NickName = "游戏玩家";
                entity.Icon     = _configHelper.Config.DefaultUserIcon;
            }
            else
            {
                entity.OpenId   = param.OpenId;
                entity.NickName = param.NickName;
                entity.Icon     = param.Icon;
            }

            entity.GameType = param.GameType;
            entity.OpenType = param.OpenType;
            entity.UnionId  = param.UnionId;

            entity.UpdateDateTime = DateTime.Now;
            if (existEntity == null)
            {
                entity.CreateDateTime = DateTime.Now;
                entity.UserLoginInfo  = new UserLoginInfo()
                {
                    LatetestSignInDate = DateTime.MinValue, SignInContinuousDays = 0
                };

                if (!string.IsNullOrEmpty(param.Code) && param.GameType == GameTypeEnum.小程序)
                {
                    var haveUsed = await _context.InviteHistories.AsNoTracking().AnyAsync(x => x.Code == param.Code);

                    if (!haveUsed)
                    {
                        var inviteDto        = SecurityHelper.GetAES <InviteUserDto>(param.Code, _configHelper.Config.WXCEncryptionKey);
                        var haveInvitedCount = await _context.InviteHistories.AsNoTracking().CountAsync(x => x.UserId == inviteDto.UserId);

                        var inviteHis = new InviteHistory()
                        {
                            Code       = param.Code,
                            UserId     = inviteDto.UserId,
                            CreateDate = DateTime.Now
                        };

                        if (haveInvitedCount < _configHelper.Config.LimitInviteReward)
                        {
                            var inviteReward = await _context.InviteRewards.AsNoTracking()
                                               .WhereIf(haveInvitedCount != _configHelper.Config.LimitInviteReward - 1, x => x.AchieveInvite == false && x.Count == haveInvitedCount + 1)
                                               .WhereIf(haveInvitedCount == _configHelper.Config.LimitInviteReward - 1, x => x.AchieveInvite && x.Count == _configHelper.Config.LimitInviteReward)
                                               .ToListAsync();

                            if (inviteReward.Any(x => x.AchieveInvite))
                            {
                                var items = inviteReward.Where(x => x.AchieveInvite).Select(x => new RewardDataDto()
                                {
                                    GoodsType = x.GoodsType,
                                    Num       = x.Num,
                                    Type      = x.Type
                                }).ToList();
                                foreach (var reward in items)
                                {
                                    _context.BuyGoodHistories.Add(new BuyGoodHistory()
                                    {
                                        CreateDate = DateTime.Now,
                                        HaveGet    = false,
                                        MallId     = (int)reward.GoodsType,
                                        Num        = reward.Num,
                                        UserId     = inviteDto.UserId,
                                        Type       = reward.GoodsType > 0 ? BuyTypeEnum.购买 : BuyTypeEnum.邀请好友达标赠送
                                    });
                                }
                            }
                            if (inviteReward.Count != 0)
                            {
                                var item = inviteReward.Where(x => x.AchieveInvite == false).Select(x => new RewardDataDto()
                                {
                                    GoodsType = x.GoodsType,
                                    Num       = x.Num,
                                    Type      = x.Type
                                }).FirstOrDefault();
                                if (item != null)
                                {
                                    inviteHis.HaveReward = true;
                                    inviteHis.Data       = JsonConvert.SerializeObject(item);
                                }
                            }
                        }

                        entity.InviteHistory = inviteHis;
                    }
                }
            }

            bool result = await _context.SaveChangesAsync() > 0;

            if (result)
            {
                return(RpsData <RpsUser> .Ok(entity.MapTo <RpsUser>()));
            }
            else
            {
                return(RpsData <RpsUser> .Error("新增或修改失败"));
            }
        }
示例#19
0
        public async Task <RpsData <RpsSignIn> > UserSignIn(ParamUserBase param)
        {
            using (var tran = await _context.Database.BeginTransactionAsync())
            {
                try
                {
                    List <object> parameters = new List <object>();
                    parameters.Add(new SqlParameter("@UserId", param.Id));

                    var rows = await _context.Database.ExecuteSqlCommandAsync(@"UPDATE
                                    [dbo].[Game_UserLoginInfo]
                                SET
                                    [SignInContinuousDays] = 
                                    CASE WHEN CONVERT(varchar(100), [LatetestSignInDate],23) =CONVERT(varchar(100), DATEADD(day,-1,GETDATE()),23)  THEN ([SignInContinuousDays] + 1)%8
                                    ELSE 1 END,
									LatetestSignInDate=GETDATE()
                                WHERE
                                    [UserId] =@UserId and  CONVERT(varchar(100), [LatetestSignInDate],23)<CONVERT(varchar(100), GETDATE(),23)", parameters.ToArray());

                    var loginEntity = await _context.UserLoginInfos.SingleAsync(x => x.UserId == param.Id);

                    var reward = await _context.SignWeekRewards.AsNoTracking()
                                 .Where(x => x.Day == loginEntity.SignInContinuousDays - 1).Select(x => new SignWeekReward()
                    {
                        Day       = x.Day,
                        GoodsType = x.GoodsType,
                        Id        = x.Id,
                        Num       = x.Num,
                        Type      = x.Type
                    }).FirstAsync();

                    if (rows != 0)
                    {
                        if (reward.Type == MallTypeEnum.道具商城)
                        {
                            reward.Mall = await _context.Malls.AsNoTracking().SingleAsync(x => x.MallType == MallTypeEnum.道具商城 && x.Type == reward.GoodsType);
                        }


                        var jsonReward = new RewardDataDto()
                        {
                            GoodsType = reward.GoodsType,
                            Num       = reward.Num,
                            Type      = reward.Type
                        };

                        _context.SignInHistories.Add(new SignInHistory()
                        {
                            Data       = JsonConvert.SerializeObject(jsonReward),
                            UserId     = loginEntity.UserId,
                            CreateDate = DateTime.Now
                        });

                        var goodexist =
                            await _context.UserGoods.AnyAsync(x =>
                                                              x.UserId == param.Id && x.GoodsType == reward.GoodsType);

                        UserGood userGood = null;
                        if (!goodexist)
                        {
                            userGood = new UserGood()
                            {
                                Num = 0, GoodsType = reward.GoodsType, UserId = param.Id
                            };
                            userGood = _context.UserGoods.Attach(userGood).Entity;
                        }
                        else
                        {
                            userGood = await _context.UserGoods.SingleAsync(x => x.UserId == param.Id && x.GoodsType == reward.GoodsType);
                        }
                        userGood.Num += reward.Num;
                    }
                    bool result = await _context.SaveChangesAsync() > 0;

                    tran.Commit();
                    if (result)
                    {
                        return(RpsData <RpsSignIn> .Ok(new RpsSignIn()
                        {
                            Id = loginEntity.Id,
                            Type = (int)reward.Type,
                            GoodsType = reward.GoodsType,
                            Num = reward.Num,
                            MallDetail = reward.Mall != null ? new MallDetailDto()
                            {
                                Name = reward.Mall.Name,
                                Price = reward.Mall.Price,
                                Type = (MallGoodsTypeEnum)reward.Type
                            } : null
                        }));
                    }
                    else
                    {
                        return(RpsData <RpsSignIn> .Error("签到异常"));
                    }
                }
                catch
                {
                    tran.Rollback();
                    throw;
                }
            }
        }
示例#20
0
        public async Task <RpsData <RpsUserGetPoster> > GetPoster(ParamGetPoster param)
        {
            var posterLevel = await _context.PosterRewards.AsNoTracking().SingleAsync(x => x.Gate == param.Gate && x.Score == param.Score);


            var existPoster = await _context.Posters.AsNoTracking().Where(x => x.UserId == param.Id)
                              .AnyAsync(x => _context.PosterGalleries.AsNoTracking().Any(y =>
                                                                                         y.Gate == param.Gate && y.Id == x.PosterId && y.PosterLevel == posterLevel.PosterLevel));

            if (!existPoster)
            {
                var poseterGallery = await _context.PosterGalleries.Where(x =>
                                                                          x.Gate == param.Gate && x.PosterLevel == posterLevel.PosterLevel).Select(x => new PosterGallery()
                {
                    Id = x.Id, Icon = x.Icon
                }).SingleAsync();


                _context.Posters.Add(new Poster()
                {
                    CreateDateTime = DateTime.Now,
                    GateId         = posterLevel.Gate,
                    PosterId       = poseterGallery.Id,
                    UserId         = param.Id
                });
                _context.BuyGoodHistories.Add(new BuyGoodHistory()
                {
                    CreateDate = DateTime.Now,
                    HaveGet    = true,
                    MallId     = 0,
                    Num        = posterLevel.Num,
                    UserId     = param.Id,
                    Type       = BuyTypeEnum.解锁图鉴赠送
                });
                var userGoods = await _context.UserGoods.SingleAsync(x => x.UserId == param.Id && x.GoodsType == MallGoodsTypeEnum.金币);

                userGoods.Num += posterLevel.Num;

                bool flag = await _context.SaveChangesAsync() > 0;

                if (flag)
                {
                    return(RpsData <RpsUserGetPoster> .Ok(new RpsUserGetPoster()
                    {
                        Gate = param.Gate,
                        PosterId = poseterGallery.Id,
                        Icon = poseterGallery.Icon,
                        Reward = new RewardDataDto()
                        {
                            GoodsType = MallGoodsTypeEnum.金币,
                            Num = posterLevel.Num,
                            Type = MallTypeEnum.金币商城
                        }
                    }));
                }
                else
                {
                    return(RpsData <RpsUserGetPoster> .Error("解锁图鉴失败"));
                }
            }
            return(RpsData <RpsUserGetPoster> .Error("已解锁,无需再解锁", 2));
        }