Example #1
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("无权操作"));
        }
Example #2
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("看广告赠送金币失败"));
            }
        }
Example #3
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));
        }
Example #4
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));
        }
Example #5
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("无权获取"));
 }
Example #6
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));
        }
Example #7
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));
        }
Example #8
0
        public IHttpActionResult Logout(JObject request)
        {
            Logger.WriterLogger("Account.Logout, Params: " + request.ToString(), LoggerType.Info);

            ParamUserBase param = new ParamUserBase();

            try
            {
                param = request.ToObject <ParamUserBase>();
            }
            catch
            {
                //throw new CommonException(40100);
                return(base.JsonFaultResult(new CommonException(40100).GetMessage(), request.ToString()));
            }

            // 保存访问信息
            base.SaveVisitInfo(param.UserId, param.channel, param.platform, param.ver);

            string accessToken   = param.accessToken;
            string sessionKey    = "";
            string sessionSecret = "";

            // 验证令牌
            int accessTookenCode = VerifyAccessToken(accessToken, out sessionKey, out sessionSecret);

            if (accessTookenCode > 0)
            {
                return(base.JsonFaultResult(new CommonException(accessTookenCode).GetMessage(), request.ToString()));
            }

            string sessionId = param.UserId.ToSeesionId();

            CacheUserRemove(sessionId);

            StandardResult <string> okResult = new StandardResult <string>();

            okResult.code = 0;
            okResult.msg  = "成功登出";
            okResult.data = "";

            return(base.JsonActionResult(okResult));
        }
Example #9
0
 public static ParamUserBase GetUserBase(this ClaimsPrincipal source)
 {
     try
     {
         var userBase = new ParamUserBase();
         int userId   = 0;
         int openType = 0;
         int gameType = 0;
         userId = int.Parse(source.Claims.Single(x => x.Type == "Id").Value);
         int.TryParse(source.Claims.Single(x => x.Type == "OpenType").Value, out openType);
         int.TryParse(source.Claims.Single(x => x.Type == "GameType").Value, out gameType);
         userBase.OpenId   = source.Claims.Single(x => x.Type == "OpenId").Value;
         userBase.Id       = userId;
         userBase.OpenType = (OpenTypeEnum)openType;
         userBase.GameType = (GameTypeEnum)gameType;
         return(userBase);
     }
     catch
     {
         throw;
     }
 }
Example #10
0
 public async Task <RpsData <IEnumerable <RpsUserGood> > > GetUserGoods(ParamUserBase param)
 {
     return(await _gameRepository.GetUserGoods(param));
 }
Example #11
0
 public async Task <RpsData <RpsAddWatch> > UploadAdInfo(ParamUserBase param)
 {
     return(await _otherRepository.UploadAdInfo(param));
 }
Example #12
0
 public RpsData <string> GetInviteCode(ParamUserBase param)
 {
     return(_otherRepository.GetInviteCode(param));
 }
Example #13
0
 public async Task <RpsData <RpsSignIn> > UserSignIn(ParamUserBase param)
 {
     return(await _userReppository.UserSignIn(param));
 }
Example #14
0
 public async Task <RpsData <IEnumerable <RpsSignList> > > GetSignList(ParamUserBase param)
 {
     return(await _userReppository.GetSignList(param));
 }
Example #15
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;
                }
            }
        }
Example #16
0
 public async Task <RpsData <int[]> > GetUserPassGates(ParamUserBase param)
 {
     return(await _gameRepository.GetUserPassGates(param));
 }
Example #17
0
 public async Task <RpsData <IEnumerable <RpsPoster> > > GetUserPoster(ParamUserBase param)
 {
     return(await _otherRepository.GetUserPoster(param));
 }
Example #18
0
 public async Task <RpsData <RpsInvited> > GetInvitedUsers(ParamUserBase param)
 {
     return(await _otherRepository.GetInvitedUsers(param));
 }